browser.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #include "browser.h"
  2. Browser::Browser(): PictureFlow()
  3. {
  4. setWindowTitle("PictureFlow");
  5. }
  6. void Browser::keyPressEvent(QKeyEvent* event)
  7. {
  8. if(event->key() == Qt::Key_Escape || event->key() == Qt::Key_Enter ||
  9. event->key() == Qt::Key_Return)
  10. {
  11. event->accept();
  12. close();
  13. }
  14. // checking the speed of rendering
  15. if(event->key() == Qt::Key_F10)
  16. if(event->modifiers() == Qt::AltModifier)
  17. {
  18. qDebug("benchmarking.... please wait");
  19. const int blit_count = 10;
  20. QTime stopwatch;
  21. stopwatch.start();
  22. for(int i = 0; i < blit_count; i++)
  23. {
  24. render(); repaint(); QApplication::flush(); QApplication::syncX();
  25. render(); repaint(); QApplication::flush(); QApplication::syncX();
  26. render(); repaint(); QApplication::flush(); QApplication::syncX();
  27. render(); repaint(); QApplication::flush(); QApplication::syncX();
  28. render(); repaint(); QApplication::flush(); QApplication::syncX();
  29. render(); repaint(); QApplication::flush(); QApplication::syncX();
  30. render(); repaint(); QApplication::flush(); QApplication::syncX();
  31. render(); repaint(); QApplication::flush(); QApplication::syncX();
  32. render(); repaint(); QApplication::flush(); QApplication::syncX();
  33. render(); repaint(); QApplication::flush(); QApplication::syncX();
  34. }
  35. QString msg;
  36. int elapsed = stopwatch.elapsed();
  37. if( elapsed > 0 )
  38. msg = QString("FPS: %1").arg( blit_count*10*1000.0/elapsed );
  39. else
  40. msg = QString("Too fast. Increase blit_count");
  41. setWindowTitle( msg );
  42. event->accept();
  43. return;
  44. }
  45. PictureFlow::keyPressEvent(event);
  46. }
  47. void Browser::operator=(Browser* inBrowser)
  48. {
  49. *this = inBrowser;
  50. }