Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <QtGui>
- #include "renderarea.h"
- #include "packager.h"
- #include "window.h"
- const int IdRole = Qt::UserRole;
- Window::Window()
- {
- renderArea = new RenderArea;
- algComboBox = new QComboBox;
- algComboBox->addItem(tr("NFDH"), 1);
- algComboBox->addItem(tr("FFDH"), 2);
- algComboBox->addItem(tr("BFDH"), 3);
- algComboBox->addItem(tr("KP01"), 4);
- algComboBox->addItem(tr("SF"), 5);
- algComboBox->addItem(tr("JOIN"), 6);
- algComboBox->addItem(tr("FCNR"), 7);
- algComboBox->addItem(tr("Sleator"), 8);
- algComboBox->addItem(tr("Burke"), 9);
- algLabel = new QLabel(tr("&Algorithm:"));
- algLabel->setBuddy(algComboBox);
- connect(algComboBox, SIGNAL(activated(int)),
- this, SLOT(algChanged()));
- inpFlag = new QRadioButton("Online input");
- connect(inpFlag, SIGNAL(toggled(bool)),
- this, SLOT(inpChanged()));
- paramSlider = new QSlider(Qt::Vertical);
- paramSlider->setTickInterval(10);
- connect(paramSlider, SIGNAL(sliderMoved(int)),
- this, SLOT(parChanged()));
- parLabel = new QLabel(tr("0"));
- parLabel->setBuddy(paramSlider);
- QGridLayout *mainLayout = new QGridLayout;
- mainLayout->setColumnStretch(0, 1);
- mainLayout->setColumnStretch(3, 1);
- mainLayout->addWidget(renderArea, 0, 0, 1, 4);
- mainLayout->addWidget(paramSlider, 0, 3);
- mainLayout->addWidget(parLabel, 1, 3);
- mainLayout->addWidget(algLabel, 2, 0, Qt::AlignRight);
- mainLayout->addWidget(algComboBox, 2, 1);
- mainLayout->addWidget(inpFlag, 2, 2);
- setLayout(mainLayout);
- setWindowTitle(tr("2D Strip Packing demo"));
- }
- void Window::algChanged()
- {
- int number = int(algComboBox->itemData(
- algComboBox->currentIndex(),
- IdRole).toInt());
- renderArea->setAlg(number);
- renderArea->update();
- }
- void Window::inpChanged()
- {
- bool checked = bool(inpFlag->isChecked());
- algComboBox->clear();
- if (checked) {
- algComboBox->addItem(tr("NFL"), 10);
- algComboBox->addItem(tr("FFL"), 11);
- algComboBox->addItem(tr("BFL"), 12);
- algComboBox->addItem(tr("BiNFL"), 13);
- algComboBox->addItem(tr("NFS"), 14);
- algComboBox->addItem(tr("FFS"), 15);
- algComboBox->addItem(tr("BFS"), 16);
- algComboBox->addItem(tr("HS"), 17);
- algComboBox->addItem(tr("Azar"), 18);
- algComboBox->addItem(tr("CA"), 19);
- algComboBox->addItem(tr("CPF"), 20);
- algComboBox->addItem(tr("CFF"), 21);
- algComboBox->addItem(tr("CC"), 22);
- algComboBox->addItem(tr("OF"), 23);
- renderArea->setAlg(10);
- } else {
- algComboBox->addItem(tr("NFDH"), 1);
- algComboBox->addItem(tr("FFDH"), 2);
- algComboBox->addItem(tr("BFDH"), 3);
- algComboBox->addItem(tr("KP01"), 4);
- algComboBox->addItem(tr("SF"), 5);
- algComboBox->addItem(tr("JOIN"), 6);
- algComboBox->addItem(tr("FCNR"), 7);
- algComboBox->addItem(tr("Sleator"), 8);
- algComboBox->addItem(tr("Burke"), 9);
- renderArea->setAlg(1);
- }
- renderArea->update();
- }
- void Window::parChanged()
- {
- QString text;
- text.setNum(paramSlider->value());
- qreal value = static_cast<qreal>(paramSlider->value())
- / static_cast<qreal>(100);
- parLabel->setText("0."+text);
- parLabel->update();
- renderArea->setParameter(value);
- renderArea->reuseAlg();
- renderArea->update();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement