TDE graphics utilities
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 
 

142 rindas
3.8 KiB

  1. At 100% zoom: kpMainWindow::drawTransparentBackground() accounts for
  2. about 75% of kpView::paintEvent()'s time. Bottleneck is
  3. QPainter::fillRect(). QPainter::drawPixmap() seems much faster. For
  4. 800x600, renderer goes from 10ms to 1ms.
  5. --- kpmainwindow.cpp 2004-08-05 02:10:38.000000000 +1000
  6. +++ kpmainwindow.cpp 2004-09-29 11:24:45.000000000 +1000
  7. @@ -838,12 +838,116 @@
  8. }
  9. +#if 1
  10. +// (indexed by [isPreview][parity])
  11. +static QPixmap *checkerBoardCache [2][2] = {{0, 0}, {0, 0}};
  12. +
  13. +
  14. +static int checkerBoardCellSize (bool isPreview)
  15. +{
  16. + return !isPreview ? 16 : 10;
  17. +}
  18. +
  19. +
  20. +// public
  21. +static QPixmap *createCheckerBoardCache (bool isPreview, bool parity)
  22. +{
  23. + int cellSize = checkerBoardCellSize (isPreview);
  24. + const int rep = 2; // must be multiple of 2
  25. +
  26. + QPixmap *newPixmap = new QPixmap (cellSize * rep, cellSize * rep);
  27. + QPainter painter (newPixmap);
  28. +
  29. + int parityAsInt = parity ? 1 : 0;
  30. + for (int y = 0; y < rep; y++)
  31. + {
  32. + for (int x = 0; x < rep; x++)
  33. + {
  34. + QColor col;
  35. +
  36. + if ((parityAsInt + x + y) % 2)
  37. + {
  38. + if (!isPreview)
  39. + col = QColor (213, 213, 213);
  40. + else
  41. + col = QColor (224, 224, 224);
  42. + }
  43. + else
  44. + col = Qt::white;
  45. +
  46. + painter.fillRect (x * cellSize, y * cellSize,
  47. + cellSize, cellSize,
  48. + col);
  49. + }
  50. + }
  51. +
  52. + painter.end ();
  53. + return newPixmap;
  54. +}
  55. +
  56. +void kpMainWindow::drawTransparentBackground (QPainter *painter,
  57. + int /*viewWidth*/, int /*viewHeight*/,
  58. + const QRect &rect,
  59. + bool isPreview)
  60. +{
  61. +#if DEBUG_KP_MAIN_WINDOW && 1 || 1
  62. + kdDebug () << "\tkpMainWindow::drawTransparentBackground(rect="
  63. + << rect << ")" << endl;
  64. + QTime totalTimer; totalTimer.start ();
  65. +#endif
  66. +
  67. + int cellSize = checkerBoardCellSize (isPreview);
  68. +
  69. +
  70. + int starty = rect.y ();
  71. + if (starty % cellSize)
  72. + starty -= (starty % cellSize);
  73. +
  74. + int startx = rect.x ();
  75. + if (startx % cellSize)
  76. + startx -= (startx % cellSize);
  77. +
  78. +
  79. + int parity = ((startx / cellSize + starty / cellSize) % 2) ? 1 : 0;
  80. +
  81. + if (!checkerBoardCache [isPreview][parity])
  82. + {
  83. + checkerBoardCache [isPreview][parity] = createCheckerBoardCache (isPreview, parity);
  84. + }
  85. +
  86. + QPixmap *tilePixmap = checkerBoardCache [isPreview][parity];
  87. + for (int y = starty; y <= rect.bottom (); y += tilePixmap->height ())
  88. + {
  89. + for (int x = startx; x <= rect.right (); x += tilePixmap->width ())
  90. + {
  91. + painter->drawPixmap (x - rect.x (), y - rect.y (), *tilePixmap);
  92. + }
  93. + }
  94. +
  95. +#if DEBUG_KP_MAIN_WINDOW && 1 || 1
  96. +{
  97. + const int totalTimerElapsed = totalTimer.elapsed ();
  98. + kdDebug () << "\t\ttotal=" << totalTimerElapsed << endl;
  99. +}
  100. +#endif
  101. +}
  102. +
  103. +
  104. +#else
  105. +
  106. // public
  107. void kpMainWindow::drawTransparentBackground (QPainter *painter,
  108. int /*viewWidth*/, int /*viewHeight*/,
  109. const QRect &rect,
  110. bool isPreview)
  111. {
  112. +#if DEBUG_KP_MAIN_WINDOW && 1
  113. + kdDebug () << "\tkpMainWindow::drawTransparentBackground(rect="
  114. + << rect << ")" << endl;
  115. + QTime totalTimer; totalTimer.start ();
  116. +#endif
  117. +
  118. +
  119. const int cellSize = !isPreview ? 16 : 10;
  120. int starty = rect.y ();
  121. @@ -877,8 +982,15 @@
  122. }
  123. }
  124. painter->restore ();
  125. -}
  126. +#if DEBUG_KP_MAIN_WINDOW && 1 || 1
  127. +{
  128. + const int totalTimerElapsed = totalTimer.elapsed ();
  129. + kdDebug () << "\t\ttotal=" << totalTimerElapsed << endl;
  130. +}
  131. +#endif
  132. +}
  133. +#endif
  134. // private slot
  135. void kpMainWindow::slotUpdateCaption ()