void tst_QFormLayout::insertRow_QString_QLayout() { QFormLayout layout; QHBoxLayout fld1, fld2, fld3; layout.insertRow(-5, "&Name:", &fld1); QLabel *label1 = qobject_cast<QLabel *>(layout.itemAt(0, QFormLayout::LabelRole)->widget()); QVERIFY(label1 != 0); QVERIFY(label1->buddy() == 0); QCOMPARE(layout.rowCount(), 1); layout.insertRow(0, "&Email:", &fld2); QLabel *label2 = qobject_cast<QLabel *>(layout.itemAt(0, QFormLayout::LabelRole)->widget()); QVERIFY(label2 != 0); QVERIFY(label2->buddy() == 0); QCOMPARE(layout.rowCount(), 2); layout.insertRow(5, "&Age:", &fld3); QLabel *label3 = qobject_cast<QLabel *>(layout.itemAt(2, QFormLayout::LabelRole)->widget()); QVERIFY(label3 != 0); QVERIFY(label3->buddy() == 0); QCOMPARE(layout.rowCount(), 3); }
void MeanSquaredErrorOp::operator()(const imagein::Image* image, const std::map<const imagein::Image*, std::string>& imgList) { QDialog* dialog = new QDialog(); dialog->setWindowTitle(qApp->translate("Operations", "Compare to...")); dialog->setMinimumWidth(180); QFormLayout* layout = new QFormLayout(); dialog->setLayout(layout); QString currentImgName = QString(imgList.find(image)->second.c_str()); ImageListBox* imageBox = new ImageListBox(dialog, image, imgList); layout->insertRow(0, qApp->translate("Operations", "Compare %1 to : ").arg(currentImgName), imageBox); QDialogButtonBox* buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel, Qt::Horizontal, dialog); layout->insertRow(1, buttonBox); QObject::connect(buttonBox, SIGNAL(accepted()), dialog, SLOT(accept())); QObject::connect(buttonBox, SIGNAL(rejected()), dialog, SLOT(reject())); QDialog::DialogCode code = static_cast<QDialog::DialogCode>(dialog->exec()); if(code!=QDialog::Accepted) { return; } const Image* sndImg = imageBox->currentImage(); unsigned int maxWidth = min(image->getWidth(), sndImg->getWidth()); unsigned int maxHeight = min(image->getHeight(), sndImg->getHeight()); unsigned int maxChannel = min(image->getNbChannels(), sndImg->getNbChannels()); double mse = 0, me = 0; for(unsigned int c = 0; c < maxChannel; ++c) { for(unsigned int j = 0; j < maxHeight; ++j) { for(unsigned int i = 0; i < maxWidth; ++i) { int deviation = image->getPixel(i, j, c) - sndImg->getPixel(i, j, c); mse += deviation*deviation; me += abs(deviation); } } } mse = mse / static_cast<double>(maxChannel * maxWidth * maxHeight); me = me / static_cast<double>(maxChannel * maxWidth * maxHeight); QString text = qApp->translate("MeanSquareErrorOp", "Mean squarred error : %1 (mean error : %2)"); text = text.arg(mse, 0, 'f', 2); text = text.arg(me, 0, 'f', 2); this->outText(text.toStdString()); outText("-------------------------------------------"); }
dmz::V8Value dmz::JsModuleUiV8QtBasic::_form_layout_insert_row (const v8::Arguments &Args) { v8::HandleScope scope; V8Value result = v8::Undefined (); JsModuleUiV8QtBasic *self = _to_self (Args); if (self) { QFormLayout *form = self->v8_to_qobject<QFormLayout> (Args.This ()); if (form) { QLayout *layout = 0; QWidget *widget = 0; int row = v8_to_int32 (Args[0]); if (Args.Length () == 2) { layout = self->v8_to_qobject<QLayout> (Args[1]); widget = self->_to_qwidget (Args[1]); if (layout) { form->addRow (layout); } else if (widget) { form->addRow (widget); } } else if (Args.Length () == 3) { String text = v8_to_string (Args[1]); widget = self->_to_qwidget (Args[1]); QWidget *field = self->_to_qwidget (Args[2]); layout = self->v8_to_qobject<QLayout> (Args[2]); if (widget) { if (field) { form->insertRow (row, widget, field); } else if (layout) { form->insertRow (row, widget, layout); } } else if (text) { if (field) { form->insertRow (row, text.get_buffer (), field); } else if (layout) { form->insertRow (row, text.get_buffer (), layout); } } } } } return scope.Close (result); }
void tst_QFormLayout::getPosition() { QWidget *w = new QWidget; QFormLayout *fl = new QFormLayout(w); QList<QLabel*> labels; QList<QLineEdit*> fields; for (int i = 0; i < 5; ++i) { labels.append(new QLabel(QString("Label %1").arg(i+1))); fields.append(new QLineEdit); fl->addRow(labels[i], fields[i]); } //a field { int row; QFormLayout::ItemRole role; fl->getWidgetPosition(fields[3], &row, &role); QCOMPARE(row, 3); QCOMPARE(role, QFormLayout::FieldRole); int old_row = row; QFormLayout::ItemRole old_role = role; fl->getItemPosition(3*2 + 1, &row, &role); QCOMPARE(row, old_row); QCOMPARE(role, old_role); } //a label { int row; QFormLayout::ItemRole role; fl->getWidgetPosition(labels[2], &row, &role); QCOMPARE(row, 2); QCOMPARE(role, QFormLayout::LabelRole); int old_row = row; QFormLayout::ItemRole old_role = role; fl->getItemPosition(2*2, &row, &role); QCOMPARE(row, old_row); QCOMPARE(role, old_role); } //a layout that's been inserted { QVBoxLayout *vbl = new QVBoxLayout; fl->insertRow(2, "Label 1.5", vbl); int row; QFormLayout::ItemRole role; fl->getLayoutPosition(vbl, &row, &role); QCOMPARE(row, 2); QCOMPARE(role, QFormLayout::FieldRole); int old_row = row; QFormLayout::ItemRole old_role = role; fl->getItemPosition(labels.count()*2 + 1, &row, &role); QCOMPARE(row, old_row); QCOMPARE(role, old_role); } delete w; }
QblDesktopWizardPage_Intro::QblDesktopWizardPage_Intro(QWidget *parent) : QWizardPage(parent){ this->setTitle("Welcome to Qabel"); this->setSubTitle("Please choose how you want to configure your program!"); this->rbtnNewUser = new QRadioButton("Create a new user identity"); this->rbtnAddDevice = new QRadioButton("Add existing configuration to a new device"); this->rbtnLogin = new QRadioButton("Login to an existing account"); this->rbtnNewUser->setChecked(true); QFormLayout *layout = new QFormLayout; layout->insertRow(0, rbtnAddDevice); layout->insertRow(0, rbtnLogin); layout->insertRow(0, rbtnNewUser); this->registerField("rbtnLogin", rbtnLogin); this->registerField("rbtnNewUser", rbtnNewUser); setLayout(layout); return; }
void BookmarksManager::updateEditBox(BookmarkItem* item) { setUpdatesEnabled(false); m_blockDescriptionChangedSignal = true; bool editable = bookmarkEditable(item); bool showAddressAndKeyword = item && item->isUrl(); bool clearBox = !item; if (clearBox) { ui->title->clear(); ui->address->clear(); ui->keyword->clear(); ui->description->clear(); ui->title->setReadOnly(true); ui->address->setReadOnly(true); ui->keyword->setReadOnly(true); ui->description->setReadOnly(true); } else { ui->title->setText(item->title()); ui->address->setText(item->url().toEncoded()); ui->keyword->setText(item->keyword()); ui->description->setPlainText(item->description()); } ui->title->setReadOnly(!editable); ui->address->setReadOnly(!editable); ui->keyword->setReadOnly(!editable); ui->description->setReadOnly(!editable); ui->labelAddress->setVisible(showAddressAndKeyword); ui->address->setVisible(showAddressAndKeyword); ui->labelKeyword->setVisible(showAddressAndKeyword); ui->keyword->setVisible(showAddressAndKeyword); // Without removing widgets from layout, there is unwanted extra spacing QFormLayout* l = static_cast<QFormLayout*>(ui->editBox->layout()); if (showAddressAndKeyword) { // Show Address + Keyword l->insertRow(1, ui->labelAddress, ui->address); l->insertRow(2, ui->labelKeyword, ui->keyword); } else { // Hide Address + Keyword l->removeWidget(ui->labelAddress); l->removeWidget(ui->labelKeyword); l->removeWidget(ui->address); l->removeWidget(ui->keyword); } m_blockDescriptionChangedSignal = false; // Prevent flickering QTimer::singleShot(10, this, SLOT(enableUpdates())); }
void tst_QFormLayout::insertRow_QWidget_QLayout() { QFormLayout layout; QLabel lbl1, lbl2, lbl3, lbl4; QHBoxLayout fld1, fld2, fld3, fld4; layout.insertRow(0, &lbl1, &fld1); QCOMPARE(layout.rowCount(), 1); { int row = -1; QFormLayout::ItemRole role = QFormLayout::ItemRole(-123); layout.getWidgetPosition(&lbl1, &row, &role); QCOMPARE(row, 0); QCOMPARE(int(role), int(QFormLayout::LabelRole)); } { int row = -1; QFormLayout::ItemRole role = QFormLayout::ItemRole(-123); layout.getLayoutPosition(&fld1, &row, &role); QCOMPARE(row, 0); QCOMPARE(int(role), int(QFormLayout::FieldRole)); } // check that negative values append layout.insertRow(-2, &lbl2, &fld2); QCOMPARE(layout.rowCount(), 2); QVERIFY(layout.itemAt(0, QFormLayout::LabelRole)->widget() == &lbl1); QVERIFY(layout.itemAt(1, QFormLayout::LabelRole)->widget() == &lbl2); // check that too large values append layout.insertRow(100, &lbl3, &fld3); QCOMPARE(layout.rowCount(), 3); QVERIFY(layout.itemAt(0, QFormLayout::LabelRole)->widget() == &lbl1); QVERIFY(layout.itemAt(1, QFormLayout::LabelRole)->widget() == &lbl2); QVERIFY(layout.itemAt(2, QFormLayout::LabelRole)->widget() == &lbl3); QVERIFY(layout.itemAt(0, QFormLayout::FieldRole)->layout() == &fld1); QVERIFY(layout.itemAt(1, QFormLayout::FieldRole)->layout() == &fld2); QVERIFY(layout.itemAt(2, QFormLayout::FieldRole)->layout() == &fld3); }
void ImgParam::fillDialog(QDialog* dialog, const ImageWindow* currentWnd, const vector<const ImageWindow*>& wndList) { QString currentImgName = currentWnd->windowTitle(); map<const Image*,string> imgList; for(vector<const ImageWindow*>::const_iterator it = wndList.begin(); it != wndList.end(); ++it) { if((*it)->isStandard()) { const StandardImageWindow* stdImgWnd = dynamic_cast<const StandardImageWindow*>(*it); imgList.insert(pair<const Image*, string>(stdImgWnd->getImage(), stdImgWnd->windowTitle().toStdString())); } } QWidget *widget = new QWidget(); QFormLayout* layout = new QFormLayout(); _imgListBox = new ImageListBox(widget, NULL, imgList); layout->insertRow(1, QString(this->_name.c_str()) + " : ", _imgListBox); widget->setLayout(layout); dialog->layout()->addWidget(widget); }
void tst_QFormLayout::rowCount() { QWidget *w = new QWidget; QFormLayout *fl = new QFormLayout(w); fl->addRow(tr("Label 1"), new QLineEdit); fl->addRow(tr("Label 2"), new QLineEdit); fl->addRow(tr("Label 3"), new QLineEdit); QCOMPARE(fl->rowCount(), 3); fl->addRow(new QWidget); fl->addRow(new QHBoxLayout); QCOMPARE(fl->rowCount(), 5); fl->insertRow(1, tr("Label 0.5"), new QLineEdit); QCOMPARE(fl->rowCount(), 6); //TODO: remove items delete w; }
HelpView::HelpView(bool makeControls, QWidget *parent) : CMainWindow(parent) { address_box = new QComboBox; address_box->setEditable(true); helpContent = new SHelpContentViewWidget; helpContent->setSource(QUrl("qthelp://Serpkov_Nikita.com.Depot.2.0/doc/index.html")); QLayout *main = new QVBoxLayout; QFormLayout *layout = new QFormLayout; layout->insertRow(0, "URL: ", address_box); main->addItem(layout); main->addWidget(helpContent); QWidget *central = new QWidget(this); central->setLayout(main); setCentralWidget(central); setWindowTitle(tr("Assistant")); connect(helpContent, SIGNAL(urlChanged(QUrl)), this, SLOT(urlChanged(QUrl))); }
void ClassResultOp::operator()(const imagein::Image* img, const std::map<const imagein::Image*, std::string>&) { QDialog* dialog = new QDialog(QApplication::activeWindow()); QVBoxLayout* layout = new QVBoxLayout(dialog); QFormLayout* formLayout = new QFormLayout(); QSpinBox* innerBox = new QSpinBox(); QSpinBox* borderBox = new QSpinBox(); innerBox->setRange(0, img->getWidth()); borderBox->setRange(0, img->getWidth()); innerBox->setSuffix(" px"); borderBox->setSuffix(" px"); innerBox->setValue(8); borderBox->setValue(2); formLayout->insertRow(0, qApp->translate("ClassResult", "Critère de zone intérieure : "), innerBox); formLayout->insertRow(1, qApp->translate("ClassResult", "Critère de zone frontière : "), borderBox); layout->addWidget(new QLabel(qApp->translate("ClassResult", "<b>Critère de zones (relatifs aux zones totales) : </b>"))); layout->addLayout(formLayout); layout->addWidget(new QLabel(qApp->translate("ClassResult", "<b>Select the image's classes zones : </b>"))); ImageZoneSelector* zoneSelector = new ImageZoneSelector(dialog, img); layout->addWidget(zoneSelector); QDialogButtonBox* buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel, Qt::Horizontal, dialog); layout->addWidget(buttonBox); QObject::connect(buttonBox, SIGNAL(accepted()), dialog, SLOT(accept())); QObject::connect(buttonBox, SIGNAL(rejected()), dialog, SLOT(reject())); QDialog::DialogCode code = static_cast<QDialog::DialogCode>(dialog->exec()); if(code!=QDialog::Accepted) return; string returnval; int param1 = 2; int param2 = 8; vector<Rectangle> selection = zoneSelector->getSelections(); int K = selection.size(); int* classes = new int[K]; outText(qApp->translate("ClassResult", "Voici les résultats du classement : \n").toStdString()); outText(qApp->translate("ClassResult", "\nNombre de classes = %1 ").arg(K).toStdString()); for(int i = 0; i < K; ++i) { Histogram histo = img->getHistogram(0, selection.at(i)); classes[i] = (uint8_t) (std::max_element(histo.begin(), histo.end()) - histo.begin()); outText(qApp->translate("ClassResult", "Valeur de la classe %1 = %2").arg(i+1).arg(classes[i]).toStdString()); } //Zone frontire double *tauxF = new double[K]; double *tauxI = new double[K]; for(int i = 0; i < K; ++i){ tauxF[i] = 0.; tauxI[i] = 0.; } for(int n = 0; n < K; ++n) { Rectangle zone = selection.at(n); for(unsigned int j = zone.top(); j < zone.bottom(); ++j) { for(unsigned int i = zone.left(); i < zone.right(); ++i) { if(img->getPixelAt(i, j) == classes[n]) { if( i >= zone.left() + param2 && i < zone.right() - param2 && j >= zone.top() + param2 && j < zone.bottom() - param2 ) { tauxI[n]++; } if( i < zone.left() + param1 || i >= zone.right() - param1 || j < zone.top() + param1 || j >= zone.bottom() - param1 ) { tauxF[n]++; } } } } } for(int n = 0; n < K; ++n) { Rectangle zone = selection.at(n); const double areaI = (zone.h - 2*param2) * (zone.w - 2*param2); const double areaF = (zone.h * zone.w) - (zone.h - 2*param1) * (zone.w - 2*param1); tauxI[n] = tauxI[n] * 100. / areaI; tauxF[n] = tauxF[n] * 100. / areaF; } for(int n = 0; n < K; ++n) { outText(qApp->translate("ClassResult", "Le taux de bon classement en zone intérieure %1 vaut: %2\%").arg(n+1).arg(tauxI[n], 0, 'f', 2).toStdString()); } for(int n = 0; n < K; ++n) { outText(qApp->translate("ClassResult", "Le taux de bon classement en zone frontière %1 vaut: %2\%").arg(n+1).arg(tauxF[n], 0, 'f', 2).toStdString()); } double tauxGI = 0., tauxGF = 0.; for(int i = 0; i < K; ++i){ tauxGI += tauxI[i]; tauxGF += tauxF[i]; } tauxGI /= K; tauxGF /= K; outText(qApp->translate("ClassResult", "Le taux de bon classement en zone intérieure globale vaut: %1\%").arg(tauxGI, 0, 'f', 2).toStdString()); outText(qApp->translate("ClassResult", "Le taux de bon classement en zone frontière globale vaut: %1\%").arg(tauxGF, 0, 'f', 2).toStdString()); outText(returnval); }
ResizeGrp::ResizeGrp(QWidget *parent) : QWidget(parent) { resize = new QGroupBox(tr("Resize")); QVBoxLayout* layout = new QVBoxLayout(this); setLayout(layout); layout->addWidget(resize); widthEdit = new QSpinBox(); widthEdit->setRange(1, 100); widthEdit->setValue(100); widthEdit->setButtonSymbols(QAbstractSpinBox::NoButtons); heightEdit = new QSpinBox(); heightEdit->setRange(1, 100); heightEdit->setValue(100); heightEdit->setButtonSymbols(QAbstractSpinBox::NoButtons); xOffset = new QSpinBox(); xOffset->setValue(0); yOffset = new QSpinBox(); yOffset->setValue(0); percent = new QCheckBox(tr("Interpret Percent")); fixedProportion = new QCheckBox(tr("Keep Ratio")); onlySmaller = new QCheckBox(tr("Resize smaller img only")); onlyGreater = new QCheckBox(tr("Resize greater img only")); connect(percent, SIGNAL(stateChanged(int)), this, SLOT(isPercent(int))); percent->setCheckState(Qt::Checked); connect(fixedProportion, SIGNAL(stateChanged(int)), this, SLOT(fixedPropo(int))); fixedProportion->setCheckState(Qt::Checked); connect(widthEdit, SIGNAL(valueChanged(int)), this, SLOT(keepRatio(int))); connect(heightEdit, SIGNAL(valueChanged(int)), this, SLOT(keepRatio(int))); filterType << "Auto" << "Lanczos" << "Mitchell"; filterBox = new QComboBox; filterBox->addItems(filterType); filterBox->setSizeAdjustPolicy(QComboBox::AdjustToContents); filterBox->setCurrentIndex(0); QFormLayout *lineLayout = new QFormLayout; lineLayout->insertRow(0, tr("Width"), widthEdit); lineLayout->insertRow(1, tr("Height"), heightEdit); lineLayout->insertRow(2, tr("X offset"), xOffset); lineLayout->insertRow(3, tr("Y offset"), yOffset); lineLayout->insertRow(4, tr("Resize Filter"), filterBox); resizeGrid = new QGridLayout; resizeGrid->addLayout(lineLayout, 0, 0, 5, 2); resizeGrid->addWidget(percent, 0, 2, 1, 1); resizeGrid->addWidget(fixedProportion, 1, 2, 1, 1); resizeGrid->addWidget(onlySmaller, 2, 2, 1, 1); resizeGrid->addWidget(onlyGreater, 3, 2, 1, 1); resize->setLayout(resizeGrid); resize->adjustSize(); }
void HadamardOp::operator()(const imagein::Image* img, const std::map<const imagein::Image*, std::string>&) { QDialog* dialog = new QDialog(QApplication::activeWindow()); dialog->setWindowTitle(qApp->translate("Operations", "8x8 transforms")); QFormLayout* layout = new QFormLayout(dialog); QComboBox* transformBox = new QComboBox(dialog); transformBox->addItems(QStringList() << "Hadamard" << "Haar" << "Cosinus (DCT)"); layout->insertRow(0, qApp->translate("Hadamard", "Transform : "), transformBox); QLabel* title = new QLabel(qApp->translate("Transforms", "<b>Select the coefficients to keep : </b>")); title->setAlignment(Qt::AlignCenter); layout->insertRow(1, title); QHBoxLayout* buttonLayout = new QHBoxLayout(); QPushButton* selectAllButton = new QPushButton(qApp->translate("Transforms", "Clear selection")); QPushButton* selectNoneButton = new QPushButton(qApp->translate("Transforms", "Invert selection")); buttonLayout->addWidget(selectAllButton); buttonLayout->addWidget(selectNoneButton); layout->insertRow(2, buttonLayout); QWidget* coefWidget = new QWidget(dialog); QGridLayout* coefLayout = new QGridLayout(coefWidget); QCheckBox* checkBoxes[8][8]; for(int i = 0; i < 8; ++i) { QLabel* labeli = new QLabel(QString("%1").arg(i)); QLabel* labelj = new QLabel(QString("%1").arg(i)); labeli->setAlignment(Qt::AlignCenter); labelj->setAlignment(Qt::AlignCenter); coefLayout->addWidget(labeli, 0, i + 1); coefLayout->addWidget(labelj, i + 1, 0); } for(int j = 0; j < 8; ++j) { for(int i = 0; i < 8; ++i) { checkBoxes[j][i] = new QCheckBox(coefWidget); coefLayout->addWidget(checkBoxes[j][i], j + 1, i + 1); checkBoxes[j][i]->setChecked(true); QObject::connect(selectAllButton, SIGNAL(clicked(bool)), checkBoxes[j][i], SLOT(setChecked(bool))); QObject::connect(selectNoneButton, SIGNAL(clicked()), checkBoxes[j][i], SLOT(toggle())); } } layout->insertRow(3, coefWidget); QDialogButtonBox* buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel, Qt::Horizontal, dialog); layout->insertRow(4, buttonBox); QObject::connect(buttonBox, SIGNAL(accepted()), dialog, SLOT(accept())); QObject::connect(buttonBox, SIGNAL(rejected()), dialog, SLOT(reject())); QDialog::DialogCode code = static_cast<QDialog::DialogCode>(dialog->exec()); if(code!=QDialog::Accepted) return; GrayscaleImage_t<bool>* selection = new GrayscaleImage_t<bool>(8, 8); for(int j = 0; j < 8; ++j) { for(int i = 0; i < 8; ++i) { selection->setPixelAt(i, j, checkBoxes[j][i]->isChecked()); } } // GrayscaleImage* im = Converter<GrayscaleImage>::convert(*img); string s; Image_t<double> *resImg; Image* invImg; if(transformBox->currentIndex() == 0) { s = Transforms::Hadamard(img, &resImg, &invImg, selection); outDoubleImage(resImg, qApp->translate("Transforms", "Hadamard transform").toStdString(), true, true, 256., true); outImage(invImg, qApp->translate("Transforms", "Hadamard reconstruction").toStdString()); } else if(transformBox->currentIndex() == 1) { s = Transforms::Haar(img, &resImg, &invImg, selection); outDoubleImage(resImg, qApp->translate("Transforms", "Haar transform").toStdString(), true, true, 256., true); outImage(invImg, qApp->translate("Transforms", "Haar reconstruction").toStdString()); } else if(transformBox->currentIndex() == 2) { s = Transforms::cosinus(img, &resImg, &invImg, selection); outDoubleImage(resImg, qApp->translate("Transforms", "cosinus transform").toStdString(), true, true, 256., true); outImage(invImg, qApp->translate("Transforms", "cosinus reconstruction").toStdString()); } outText(s); }
void RandomImgOp::operator()(const imagein::Image*, const std::map<const imagein::Image*, std::string>&) { QDialog* dialog = new QDialog(qApp->activeWindow()); dialog->setWindowTitle(qApp->translate("RandomImgOp", "Parameters")); dialog->setMinimumWidth(180); QFormLayout* layout = new QFormLayout(dialog); QGroupBox* radioGroup = new QGroupBox(qApp->translate("RandomImgOp", "Image type"), dialog); QRadioButton* intButton = new QRadioButton(qApp->translate("RandomImgOp", "8-bit integer")); QRadioButton* floatButton = new QRadioButton(qApp->translate("RandomImgOp", "Floating point")); QHBoxLayout* radioLayout = new QHBoxLayout(radioGroup); radioLayout->addWidget(intButton); radioLayout->addWidget(floatButton); intButton->setChecked(true); layout->insertRow(0, radioGroup); QSpinBox* widthBox = new QSpinBox(dialog); widthBox->setRange(0, 65536); widthBox->setValue(512); layout->insertRow(1, qApp->translate("RandomImgOp", "Width : "), widthBox); QSpinBox* heightBox = new QSpinBox(dialog); heightBox->setRange(0, 65536); heightBox->setValue(512); layout->insertRow(2, qApp->translate("RandomImgOp", "Height : "), heightBox); QSpinBox* channelBox = new QSpinBox(dialog); channelBox->setRange(1, 4); channelBox->setValue(3); layout->insertRow(3, qApp->translate("RandomImgOp", "Number of channels : "), channelBox); QWidget* intRangeWidget = new QWidget(dialog); QHBoxLayout* intRangeLayout = new QHBoxLayout(intRangeWidget); QSpinBox* intMinBox = new QSpinBox(dialog); QSpinBox* intMaxBox = new QSpinBox(dialog); intMinBox->setRange(0, 255); intMaxBox->setRange(0, 255); intMinBox->setValue(0); intMaxBox->setValue(255); intRangeLayout->addWidget(new QLabel(qApp->translate("RandomImgOp", "Range : "))); intRangeLayout->addWidget(intMinBox); intRangeLayout->addWidget(new QLabel(qApp->translate("RandomImgOp", " to "))); intRangeLayout->addWidget(intMaxBox); layout->insertRow(4, intRangeWidget); QWidget* floatRangeWidget = new QWidget(dialog); QHBoxLayout* floatRangeLayout = new QHBoxLayout(floatRangeWidget); QDoubleSpinBox* floatMinBox = new QDoubleSpinBox(dialog); QDoubleSpinBox* floatMaxBox = new QDoubleSpinBox(dialog); floatMinBox->setValue(0.0); floatMaxBox->setValue(1.0); floatMinBox->setRange(-65536, 65536); floatMaxBox->setRange(-65536, 65536); floatRangeLayout->addWidget(new QLabel(qApp->translate("RandomImgOp", "Range : "))); floatRangeLayout->addWidget(floatMinBox); floatRangeLayout->addWidget(new QLabel(qApp->translate("RandomImgOp", " to "))); floatRangeLayout->addWidget(floatMaxBox); layout->insertRow(5, floatRangeWidget); floatRangeWidget->hide(); layout->setSizeConstraint(QLayout::SetFixedSize); QObject::connect(intButton, SIGNAL(toggled(bool)), intRangeWidget, SLOT(setVisible(bool))); QObject::connect(floatButton, SIGNAL(toggled(bool)), floatRangeWidget, SLOT(setVisible(bool))); QPushButton *okButton = new QPushButton(qApp->translate("Operations", "Validate"), dialog); okButton->setDefault(true); layout->addWidget(okButton); QObject::connect(okButton, SIGNAL(clicked()), dialog, SLOT(accept())); QDialog::DialogCode code = static_cast<QDialog::DialogCode>(dialog->exec()); if(code!=QDialog::Accepted) { return; } if(intButton->isChecked()) { Image* resImg = new Image(widthBox->value(), heightBox->value(), channelBox->value()); RandomLib::Random random; for(unsigned int c = 0; c < resImg->getNbChannels(); ++c) { for(unsigned int j = 0; j < resImg->getHeight(); ++j) { for(unsigned int i = 0; i < resImg->getWidth(); ++i) { Image::depth_t value = random.IntegerC<Image::depth_t>(intMinBox->value(), intMaxBox->value()); // Image::depth_t value = 256. * (rand() / (RAND_MAX + 1.));; resImg->setPixel(i, j, c, value); } } } this->outImage(resImg, qApp->translate("Operations", "Random image").toStdString()); } else if(floatButton->isChecked()) { Image_t<double>* resImg = new Image_t<double>(widthBox->value(), heightBox->value(), channelBox->value()); RandomLib::Random random; for(unsigned int c = 0; c < resImg->getNbChannels(); ++c) { for(unsigned int j = 0; j < resImg->getHeight(); ++j) { for(unsigned int i = 0; i < resImg->getWidth(); ++i) { double min = floatMinBox->value(); double max = floatMaxBox->value(); // double width = max - min; // double value = min + (double)rand() * width / RAND_MAX; double value = random.FixedN<double>(); value = value*(max-min) + min; resImg->setPixel(i, j, c, value); } } } this->outDoubleImage(resImg, qApp->translate("Operations", "Random image").toStdString(), true); } }