pdfViewerDialog::pdfViewerDialog(bool useViewer, const QString& curViewerPath, QWidget* parent) : cancelAcceptDialogBase(parent), useViewer_(new QGroupBox(tr("Use viewer to display saved pdf patterns"))), dialogLayout_(new QVBoxLayout), groupLayout_(new QVBoxLayout), currentPath_(new QLineEdit), choosePath_(new QPushButton(tr("Choose new pdf viewer"))) { useViewer_->setCheckable(true); useViewer_->setChecked(useViewer); currentPath_->setText(curViewerPath); connect(choosePath_, SIGNAL(clicked()), this, SLOT(updateViewerPath())); groupLayout_->addWidget(currentPath_); groupLayout_->addWidget(choosePath_); useViewer_->setLayout(groupLayout_); dialogLayout_->addWidget(useViewer_); dialogLayout_->addWidget(cancelAcceptWidget()); setLayout(dialogLayout_); setWindowTitle(tr("Set pdf viewer")); }
rareColorsDialog::rareColorsDialog(const QHash<QRgb, int>& colorCounts) : cancelAcceptDialogBase(NULL), colorCounts_(colorCounts) { minCountLeftLabel_ = new QLabel(tr("Replace checked colors that occur ")); minCountRightLabel_ = new QLabel(tr(" or fewer times.")); minCountBox_ = new QSpinBox; const int rangeMax = 100; minCountBox_->setRange(1, rangeMax); // make the box a fixed width; otherwise it grows with the width of the // dialog (and I don't trust sizePolicy()s that I've never been able to // get to do what I expect) const QFontMetrics fontMetrics(font()); minCountBox_->setFixedWidth(fontMetrics.width(::itoqs(rangeMax)) + 30); connect(minCountBox_, SIGNAL(valueChanged(int )), this, SLOT(processNewMin(int ))); minCountLayout_ = new QHBoxLayout; minCountLayout_->addWidget(minCountLeftLabel_); minCountLayout_->addWidget(minCountBox_); minCountLayout_->addWidget(minCountRightLabel_); scroll_ = new QScrollArea; // Qt tells me to use stylesheets to style widgets (instead of palettes), // but if you change one style property of a complex widget, you have to // change _every_ property of the widget. Huh? // http://doc.trolltech.com/4.7-snapshot/stylesheet-customizing.html //Note: With complex widgets such as QComboBox and QScrollBar, if one //property or sub-control is customized, all the other properties or //sub-controls must be customized as well. // scroll_->setStyleSheet("QWidget { background-color: white; }"); scroll_->viewport()->setStyleSheet("background-color: white;"); // make the scroll as wide as the widest possible row const QString testString(::itoqs(rangeMax) + " squares (255, 255, 255) --> (255, 255, 255)"); // PM_IndicatorWidth is the width of a checkbox const int maxWidth = fontMetrics.width(testString) + scroll_->style()->pixelMetric(QStyle::PM_IndicatorWidth) + ::scrollbarWidth() + ICON_SIZE + 35; scroll_->setMinimumWidth(maxWidth); scroll_->setMinimumHeight(200); scrollWidget_ = NULL; colorsLayout_ = NULL; noReplacementColorsLabel_ = NULL; noRareColorsLabel_ = NULL; selectAllLabel_ = new QLabel(tr("<a href=\"check\">Check all boxes</a>"), this); selectAllLabel_->setTextFormat(Qt::RichText); connect(selectAllLabel_, SIGNAL(linkActivated(const QString& )), this, SLOT(checkUncheckCheckboxes(const QString& ))); selectNoneLabel_ = new QLabel(tr("<a href=\"uncheck\">Uncheck all boxes</a>"), this); selectNoneLabel_->setTextFormat(Qt::RichText); connect(selectNoneLabel_, SIGNAL(linkActivated(const QString& )), this, SLOT(checkUncheckCheckboxes(const QString & ))); mainLayout_ = new QVBoxLayout; mainLayout_->addLayout(minCountLayout_); mainLayout_->addWidget(scroll_); mainLayout_->addWidget(selectAllLabel_); mainLayout_->addWidget(selectNoneLabel_); mainLayout_->addWidget(cancelAcceptWidget()); setLayout(mainLayout_); minCountBox_->setValue(5); setWindowTitle(tr("Replace rare colors")); }
void colorDialog::constructorHelper(bool useSquareColors, flossType type) { setAttribute(Qt::WA_DeleteOnClose); // left right buttons and label leftRightColorPatch_ = new QLabel; QPixmap colorPatch(2*LR_BOX + 2*LR_BORDER, LR_BOX + 2*LR_BORDER); colorPatch.fill(QColor(180, 180, 180)); QPainter painter; painter.begin(&colorPatch); painter.fillRect(LR_BORDER, LR_BORDER, 2*LR_BOX, LR_BOX, inputColor_.qc()); painter.drawRect(LR_BORDER, LR_BORDER, 2*LR_BOX, LR_BOX); painter.drawLine(LR_BORDER + LR_BOX, LR_BORDER, LR_BORDER + LR_BOX, LR_BORDER + LR_BOX); painter.end(); leftRightColorPatch_->setPixmap(colorPatch); leftButton_ = new QPushButton(QIcon(":leftArrow.png"), "", this); leftButton_->setEnabled(false); connect(leftButton_, SIGNAL(clicked()), this, SLOT(processLeftClick())); rightButton_ = new QPushButton(QIcon(":rightArrow.png"), "", this); rightButton_->setEnabled(false); connect(rightButton_, SIGNAL(clicked()), this, SLOT(processRightClick())); leftRightLayout_ = new QHBoxLayout; leftRightHolder_ = new QWidget; leftRightHolder_->setLayout(leftRightLayout_); dialogLayout_->addWidget(leftRightHolder_); leftRightLayout_->setAlignment(Qt::AlignHCenter); leftRightLayout_->addWidget(leftButton_); leftRightLayout_->addWidget(leftRightColorPatch_); leftRightLayout_->addWidget(rightButton_); // choice box modeChoiceBox_ = new QComboBox; if (useSquareColors) { modeChoiceBox_->addItem(tr("Choose a square color"), QVariant::fromValue(CD_SQUARE)); } modeChoiceBox_->addItem(tr("Choose a color list color"), QVariant::fromValue(CD_LIST)); if (type == flossDMC || type == flossVariable) { modeChoiceBox_->addItem(tr("Choose a DMC floss by color"), QVariant::fromValue(CD_DMC_COLOR)); modeChoiceBox_->addItem(tr("Choose a DMC floss by color/number"), QVariant::fromValue(CD_DMC_FLOSS)); } if (type == flossAnchor || type == flossVariable) { modeChoiceBox_->addItem(tr("Choose an Anchor floss by color"), QVariant::fromValue(CD_ANCHOR_COLOR)); modeChoiceBox_->addItem(tr("Choose an Anchor floss by color/number"), QVariant::fromValue(CD_ANCHOR_FLOSS)); } modeChoiceBox_->addItem(tr("Choose a color from an image"), QVariant::fromValue(CD_IMAGE)); if (type == flossVariable) { modeChoiceBox_->addItem(tr("Choose a new color"), QVariant::fromValue(CD_NEW)); } connect(modeChoiceBox_, SIGNAL(activated(int )), this, SLOT(processModeChange(int ))); buttonsLayout_ = new QHBoxLayout; buttonsLayout_->setSpacing(9); dialogLayout_->addLayout(buttonsLayout_); buttonsLayout_->addWidget(modeChoiceBox_); buttonsLayout_->addWidget(cancelAcceptWidget()); move(200, 50); }
patternMetadata::patternMetadata(int pdfWidth, int titleFontSize, int patternByFontSize, int photoByFontSize, QWidget* parent) : cancelAcceptDialogBase(parent), widgetLayout_(new QVBoxLayout), metadataBox_(new QGroupBox(tr("Pattern information (all fields are optional, all text will be centered in the pdf)"))), metadataLayout_(new QVBoxLayout), titleLabel_(new QLabel(tr("<u><b>Pattern title</b></u> (only the first line will be used):"))), titleEdit_(new fixedWidthTextEdit(pdfWidth, 1, this)), titleSettingsKey_("pattern_title"), titleFontSize_(titleFontSize), linesToKeep_(4), patternByLabel_(new QLabel(tr("<u><b>Pattern information</b></u> (only the first four lines will be used):"))), patternByEdit_(new fixedWidthTextEdit(pdfWidth, linesToKeep_, this)), patternBySettingsKey_("pattern_by"), patternByFontSize_(patternByFontSize), patternByLicenseLayout_(new QHBoxLayout), patternByLicenseButton_(new QPushButton(tr("Insert"))), patternByLicenses_(new QComboBox), photoByLabel_(new QLabel(tr("<u><b>Photo information</b></u> (only the first four lines will be used):"))), photoByEdit_(new fixedWidthTextEdit(pdfWidth, linesToKeep_, this)), photoBySettingsKey_("photo_by"), photoByFontSize_(photoByFontSize), photoByLicenseLayout_(new QHBoxLayout), photoByLicenseButton_(new QPushButton(tr("Insert"))), photoByLicenses_(new QComboBox), clearMetadataButton_(new QPushButton(tr("Clear all information"))), symbolSizeBox_(new QGroupBox(tr("Pdf symbol size"))), symbolSizeLayout_(new QVBoxLayout), symbolSizeTitleLayout_(new QHBoxLayout), symbolSizeTitle_(new QLabel("Set the pdf symbol size (from " + QString::number(MIN_SYMBOL_SIZE) + " to " + QString::number(MAX_SYMBOL_SIZE) + "): ")), symbolSizeSpinBox_(new QSpinBox), symbolSizeKey_("pdf_symbol_size"), symbolPreviewLayout_(new QHBoxLayout), symbolPreview_(new QLabel) { // TODO this won't quite be right since the textEdit has mystery margins const int inputFieldWidth = pdfWidth + ::scrollbarWidth(); const QFont applicationFont = QApplication::font(); #ifdef Q_OS_LINUX // Qt-linux bug (4.6.3) for QFontMetrics.lineSpacing()? const int linesFudge = 2; #else const int linesFudge = 1; #endif // title metadataLayout_->addWidget(titleLabel_); QFont titleFont = applicationFont; titleFont.setBold(true); titleFont.setPointSize(titleFontSize_); titleEdit_->setFont(titleFont); titleEdit_->setFixedWidth(inputFieldWidth); // TODO these fudges are probably not portable or lasting (then again, // what are the correct QT magic incantations to compute all of the // paddings, margins, frames, etc, and how often will they change?) const int lineHeightFudge = 8; const int comboBoxWidthFudge = 100; titleEdit_->setFixedHeight(linesFudge*QFontMetrics(titleFont).lineSpacing() + lineHeightFudge); metadataLayout_->addWidget(titleEdit_); metadataLayout_->addSpacing(20); // patternBy metadataLayout_->addWidget(patternByLabel_); QFont patternByFont = applicationFont; patternByFont.setPointSize(patternByFontSize_); patternByEdit_->setFont(patternByFont); patternByEdit_->setFixedWidth(inputFieldWidth); patternByEdit_-> setFixedHeight(linesFudge*linesToKeep_*QFontMetrics(patternByFont).lineSpacing() + lineHeightFudge); connect(patternByLicenseButton_, SIGNAL(clicked()), this, SLOT(insertPatternByLicense())); // unfortunately patternByLicenseButton_ doesn't know its width yet, // so we have to just approximate patternByLicenses_->setFixedWidth(inputFieldWidth - comboBoxWidthFudge); loadLicenses(patternByLicenses_, patternByFont, false); metadataLayout_->addWidget(patternByEdit_); patternByLicenseLayout_->addWidget(patternByLicenseButton_, 0, Qt::AlignLeft); patternByLicenseLayout_->addWidget(patternByLicenses_, 1, Qt::AlignLeft); metadataLayout_->addLayout(patternByLicenseLayout_); metadataLayout_->addSpacing(20); // photoBy metadataLayout_->addWidget(photoByLabel_); QFont photoByFont = applicationFont; photoByFont.setPointSize(photoByFontSize_); photoByEdit_->setFont(photoByFont); photoByEdit_->setFixedWidth(inputFieldWidth); photoByEdit_-> setFixedHeight(linesFudge*linesToKeep_*QFontMetrics(photoByFont).lineSpacing() + lineHeightFudge); connect(photoByLicenseButton_, SIGNAL(clicked()), this, SLOT(insertPhotoByLicense())); // unfortunately photobyLicenseButton_ doesn't know its width yet, // so we have to just approximate photoByLicenses_->setFixedWidth(inputFieldWidth - comboBoxWidthFudge); loadLicenses(photoByLicenses_, photoByFont, true); metadataLayout_->addWidget(photoByEdit_); photoByLicenseLayout_->addWidget(photoByLicenseButton_, 0, Qt::AlignLeft); photoByLicenseLayout_->addWidget(photoByLicenses_, 1, Qt::AlignLeft); metadataLayout_->addLayout(photoByLicenseLayout_); connect(clearMetadataButton_, SIGNAL(clicked()), this, SLOT(clearMetadata())); metadataLayout_->addWidget(clearMetadataButton_); metadataBox_->setLayout(metadataLayout_); widgetLayout_->addWidget(metadataBox_); setLayout(widgetLayout_); // load any saved fields const QSettings settings("cstitch", "cstitch"); loadSettings(settings, titleSettingsKey_, titleEdit_); loadSettings(settings, patternBySettingsKey_, patternByEdit_); loadSettings(settings, photoBySettingsKey_, photoByEdit_); constructSymbolPreview(settings); widgetLayout_->addWidget(cancelAcceptWidget()); titleEdit_->setFocus(); setWindowTitle(tr("Pattern information")); }