WildReanimator

renderarea.cpp

Nov 23rd, 2012
557
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <QtGui>
  2.  
  3. #include "renderarea.h"
  4. #include "packager.h"
  5.  
  6. RenderArea::RenderArea(QWidget *parent)
  7.     : QWidget(parent)
  8. {
  9.     setBackgroundRole(QPalette::Base);
  10.     setAutoFillBackground(true);
  11.  
  12.     packager.init("d:\\2dsp\\config\\data.txt");
  13.     packager.SetAlgorithm(&nextFit);
  14.     packager.UseAlgorithm();
  15. }
  16.  
  17. QSize RenderArea::minimumSizeHint() const
  18. {
  19.     return QSize(STRIPW / 4, STRIPH / 4);
  20. }
  21. QSize RenderArea::sizeHint() const
  22. {
  23.     return QSize(STRIPW, STRIPH);
  24. }
  25.  
  26. void RenderArea::paintEvent(QPaintEvent * /* event */)
  27. {
  28.     QPainter painter(this);
  29.     painter.setPen(QPen(QBrush(Qt::lightGray, Qt::SolidPattern), 3.0, Qt::DotLine));
  30.  
  31.     painter.save();
  32.     painter.drawRect(10, 0, STRIPW, STRIPH - 10);
  33.     painter.restore();
  34.  
  35.     painter.setPen(QPen(Qt::black));
  36.  
  37.     int sumSpace = 0;
  38.     int minY = STRIPH;
  39.     for (int i = 0; i < packager.getSize(); i++) {
  40.         if (packager.rectangles[i].y() < minY) minY = packager.rectangles[i].y();
  41.         sumSpace += packager.rectangles[i].height() * packager.rectangles[i].width();
  42.         painter.setBrush(QBrush(QColor(255, 200, 100).lighter(120 - 8 * i),
  43.                                 Qt::SolidPattern));
  44.         painter.save();
  45.         painter.drawRect(packager.rectangles[i].translated(QPoint(10,-10)));
  46.         painter.restore();
  47.     }
  48.     qDebug("optimal = %d, obtained = %d", sumSpace / STRIPW, STRIPH - minY);
  49. }
  50.  
  51. void RenderArea::setAlg(int number)
  52. {
  53.     switch (number) {
  54.     case 1:  packager.SetAlgorithm(&nextFit);       break;
  55.     case 2:  packager.SetAlgorithm(&firstFit);      break;
  56.     case 3:  packager.SetAlgorithm(&bestFit);       break;
  57.     case 4:  packager.SetAlgorithm(&knapsack);      break;
  58.     case 5:  packager.SetAlgorithm(&splitFit);      break;
  59.     case 6:  packager.SetAlgorithm(&join);          break;
  60.     case 7:  packager.SetAlgorithm(&floorCeil);     break;
  61.     case 8:  packager.SetAlgorithm(&sleator);       break;
  62.     case 9:  packager.SetAlgorithm(&burke);         break;
  63.     case 10: packager.SetAlgorithm(&nextFitLevel);  break;
  64.     case 11: packager.SetAlgorithm(&firstFitLevel); break;
  65.     case 12: packager.SetAlgorithm(&bestFitLevel);  break;
  66.     case 13: packager.SetAlgorithm(&biLevel);       break;
  67.     case 14: packager.SetAlgorithm(&nextFitShelf);  break;
  68.     case 15: packager.SetAlgorithm(&firstFitShelf); break;
  69.     case 16: packager.SetAlgorithm(&bestFitShelf);  break;
  70.     case 17: packager.SetAlgorithm(&harmonicShelf); break;
  71.     case 18: packager.SetAlgorithm(&azar);          break;
  72.     case 19: packager.SetAlgorithm(&compression);   break;
  73.     case 20: packager.SetAlgorithm(&comprPartFit);  break;
  74.     case 21: packager.SetAlgorithm(&comprFullFit);  break;
  75.     case 22: packager.SetAlgorithm(&comprCombo);    break;
  76.     case 23: packager.SetAlgorithm(&onlineFit);     break;
  77.     default: break;
  78.     }
  79.     packager.UseAlgorithm();
  80. }
RAW Paste Data