WildReanimator

window.cpp

Nov 23rd, 2012
673
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. #include "window.h"
  6.  
  7. const int IdRole = Qt::UserRole;
  8.  
  9. Window::Window()
  10. {
  11.     renderArea = new RenderArea;
  12.  
  13.     algComboBox = new QComboBox;
  14.     algComboBox->addItem(tr("NFDH"),    1);
  15.     algComboBox->addItem(tr("FFDH"),    2);
  16.     algComboBox->addItem(tr("BFDH"),    3);
  17.     algComboBox->addItem(tr("KP01"),    4);
  18.     algComboBox->addItem(tr("SF"),      5);
  19.     algComboBox->addItem(tr("JOIN"),    6);
  20.     algComboBox->addItem(tr("FCNR"),    7);
  21.     algComboBox->addItem(tr("Sleator"), 8);
  22.     algComboBox->addItem(tr("Burke"),   9);
  23.  
  24.     algLabel = new QLabel(tr("&Algorithm:"));
  25.     algLabel->setBuddy(algComboBox);
  26.  
  27.     connect(algComboBox, SIGNAL(activated(int)),
  28.             this, SLOT(algChanged()));
  29.  
  30.     inpFlag = new QRadioButton("Online input");
  31.  
  32.     connect(inpFlag, SIGNAL(toggled(bool)),
  33.             this, SLOT(inpChanged()));
  34.  
  35.     paramSlider = new QSlider(Qt::Vertical);
  36.     paramSlider->setTickInterval(10);
  37.  
  38.     connect(paramSlider, SIGNAL(sliderMoved(int)),
  39.             this, SLOT(parChanged()));
  40.  
  41.     parLabel = new QLabel(tr("0"));
  42.     parLabel->setBuddy(paramSlider);
  43.  
  44.     QGridLayout *mainLayout = new QGridLayout;
  45.     mainLayout->setColumnStretch(0, 1);
  46.     mainLayout->setColumnStretch(3, 1);
  47.     mainLayout->addWidget(renderArea, 0, 0, 1, 4);
  48.     mainLayout->addWidget(paramSlider, 0, 3);
  49.     mainLayout->addWidget(parLabel, 1, 3);
  50.     mainLayout->addWidget(algLabel, 2, 0, Qt::AlignRight);
  51.     mainLayout->addWidget(algComboBox, 2, 1);
  52.     mainLayout->addWidget(inpFlag, 2, 2);
  53.  
  54.     setLayout(mainLayout);
  55.     setWindowTitle(tr("2D Strip Packing demo"));
  56. }
  57.  
  58. void Window::algChanged()
  59. {
  60.     int number = int(algComboBox->itemData(
  61.                          algComboBox->currentIndex(),
  62.                          IdRole).toInt());
  63.     renderArea->setAlg(number);
  64.     renderArea->update();
  65. }
  66.  
  67. void Window::inpChanged()
  68. {
  69.     bool checked = bool(inpFlag->isChecked());
  70.  
  71.     algComboBox->clear();
  72.     if (checked) {
  73.         algComboBox->addItem(tr("NFL"),     10);
  74.         algComboBox->addItem(tr("FFL"),     11);
  75.         algComboBox->addItem(tr("BFL"),     12);
  76.         algComboBox->addItem(tr("BiNFL"),   13);
  77.         algComboBox->addItem(tr("NFS"),     14);
  78.         algComboBox->addItem(tr("FFS"),     15);
  79.         algComboBox->addItem(tr("BFS"),     16);
  80.         algComboBox->addItem(tr("HS"),      17);
  81.         algComboBox->addItem(tr("Azar"),    18);
  82.         algComboBox->addItem(tr("CA"),      19);
  83.         algComboBox->addItem(tr("CPF"),     20);
  84.         algComboBox->addItem(tr("CFF"),     21);
  85.         algComboBox->addItem(tr("CC"),      22);
  86.         algComboBox->addItem(tr("OF"),      23);
  87.         renderArea->setAlg(10);
  88.     } else {
  89.         algComboBox->addItem(tr("NFDH"),    1);
  90.         algComboBox->addItem(tr("FFDH"),    2);
  91.         algComboBox->addItem(tr("BFDH"),    3);
  92.         algComboBox->addItem(tr("KP01"),    4);
  93.         algComboBox->addItem(tr("SF"),      5);
  94.         algComboBox->addItem(tr("JOIN"),    6);
  95.         algComboBox->addItem(tr("FCNR"),    7);
  96.         algComboBox->addItem(tr("Sleator"), 8);
  97.         algComboBox->addItem(tr("Burke"),   9);
  98.         renderArea->setAlg(1);
  99.     }
  100.     renderArea->update();
  101. }
  102.  
  103. void Window::parChanged()
  104. {
  105.     QString text;
  106.     text.setNum(paramSlider->value());
  107.     qreal value =   static_cast<qreal>(paramSlider->value())
  108.                   / static_cast<qreal>(100);
  109.  
  110.     parLabel->setText("0."+text);
  111.     parLabel->update();
  112.  
  113.     renderArea->setParameter(value);
  114.     renderArea->reuseAlg();
  115.     renderArea->update();
  116. }
RAW Paste Data