diff options
Diffstat (limited to 'examples/widgets')
7 files changed, 79 insertions, 51 deletions
diff --git a/examples/widgets/desktop/systray/window.cpp b/examples/widgets/desktop/systray/window.cpp index 5e98996ff3..05944c92a7 100644 --- a/examples/widgets/desktop/systray/window.cpp +++ b/examples/widgets/desktop/systray/window.cpp @@ -160,10 +160,16 @@ void Window::iconActivated(QSystemTrayIcon::ActivationReason reason) void Window::showMessage() { showIconCheckBox->setChecked(true); - QSystemTrayIcon::MessageIcon icon = QSystemTrayIcon::MessageIcon( + QSystemTrayIcon::MessageIcon msgIcon = QSystemTrayIcon::MessageIcon( typeComboBox->itemData(typeComboBox->currentIndex()).toInt()); - trayIcon->showMessage(titleEdit->text(), bodyEdit->toPlainText(), icon, + if (msgIcon == QSystemTrayIcon::NoIcon) { + QIcon icon(iconComboBox->itemIcon(iconComboBox->currentIndex())); + trayIcon->showMessage(titleEdit->text(), bodyEdit->toPlainText(), icon, durationSpinBox->value() * 1000); + } else { + trayIcon->showMessage(titleEdit->text(), bodyEdit->toPlainText(), msgIcon, + durationSpinBox->value() * 1000); + } } //! [5] @@ -215,6 +221,8 @@ void Window::createMessageGroupBox() typeComboBox->addItem(style()->standardIcon( QStyle::SP_MessageBoxCritical), tr("Critical"), QSystemTrayIcon::Critical); + typeComboBox->addItem(QIcon(), tr("Custom icon"), + QSystemTrayIcon::NoIcon); typeComboBox->setCurrentIndex(1); durationLabel = new QLabel(tr("Duration:")); diff --git a/examples/widgets/mac/qmacnativewidget/main.mm b/examples/widgets/mac/qmacnativewidget/main.mm index ad1e28fdd9..a7c4fe1a21 100644 --- a/examples/widgets/mac/qmacnativewidget/main.mm +++ b/examples/widgets/mac/qmacnativewidget/main.mm @@ -119,12 +119,11 @@ QApplication *qtApp = 0; QVBoxLayout *vlayout = new QVBoxLayout(); vlayout->addLayout(hlayout); - //RedWidget * redWidget = new RedWidget; - //vlayout->addWidget(redWidget); + RedWidget *redWidget = new RedWidget; + vlayout->addWidget(redWidget); nativeWidget->setLayout(vlayout); - // show() must be called on nativeWiget to get the widgets int he correct state. nativeWidget->show(); diff --git a/examples/widgets/painting/fontsampler/mainwindow.cpp b/examples/widgets/painting/fontsampler/mainwindow.cpp index 88b23d5cfb..192ffbd369 100644 --- a/examples/widgets/painting/fontsampler/mainwindow.cpp +++ b/examples/widgets/painting/fontsampler/mainwindow.cpp @@ -212,9 +212,9 @@ QMap<QString, StyleItems> MainWindow::currentPageMap() return pageMap; } -#if defined(QT_PRINTSUPPORT_LIB) && QT_CONFIG(printdialog) void MainWindow::on_printAction_triggered() { +#if defined(QT_PRINTSUPPORT_LIB) && QT_CONFIG(printdialog) pageMap = currentPageMap(); if (pageMap.count() == 0) @@ -231,10 +231,12 @@ void MainWindow::on_printAction_triggered() printer.setFromTo(1, pageMap.keys().count()); printDocument(&printer); +#endif } void MainWindow::printDocument(QPrinter *printer) { +#if defined(QT_PRINTSUPPORT_LIB) && QT_CONFIG(printdialog) printer->setFromTo(1, pageMap.count()); QProgressDialog progress(tr("Preparing font samples..."), tr("&Cancel"), @@ -263,10 +265,12 @@ void MainWindow::printDocument(QPrinter *printer) } painter.end(); +#endif } void MainWindow::on_printPreviewAction_triggered() { +#if defined(QT_PRINTSUPPORT_LIB) && QT_CONFIG(printdialog) pageMap = currentPageMap(); if (pageMap.count() == 0) @@ -277,10 +281,12 @@ void MainWindow::on_printPreviewAction_triggered() connect(&preview, SIGNAL(paintRequested(QPrinter*)), this, SLOT(printDocument(QPrinter*))); preview.exec(); +#endif } void MainWindow::printPage(int index, QPainter *painter, QPrinter *printer) { +#if defined(QT_PRINTSUPPORT_LIB) && QT_CONFIG(printdialog) QString family = pageMap.keys()[index]; StyleItems items = pageMap[family]; @@ -343,5 +349,5 @@ void MainWindow::printPage(int index, QPainter *painter, QPrinter *printer) } painter->restore(); -} #endif +} diff --git a/examples/widgets/painting/fontsampler/mainwindow.h b/examples/widgets/painting/fontsampler/mainwindow.h index 21e76f1a62..8f59e1021b 100644 --- a/examples/widgets/painting/fontsampler/mainwindow.h +++ b/examples/widgets/painting/fontsampler/mainwindow.h @@ -78,13 +78,10 @@ public slots: void on_clearAction_triggered(); void on_markAction_triggered(); void on_unmarkAction_triggered(); - -#if defined(QT_PRINTSUPPORT_LIB) && QT_CONFIG(printdialog) void on_printAction_triggered(); void on_printPreviewAction_triggered(); void printDocument(QPrinter *printer); void printPage(int index, QPainter *painter, QPrinter *printer); -#endif void showFont(QTreeWidgetItem *item); void updateStyles(QTreeWidgetItem *item, int column); diff --git a/examples/widgets/tools/regularexpression/regularexpressiondialog.cpp b/examples/widgets/tools/regularexpression/regularexpressiondialog.cpp index 7a67c763d8..371e2bda4b 100644 --- a/examples/widgets/tools/regularexpression/regularexpressiondialog.cpp +++ b/examples/widgets/tools/regularexpression/regularexpressiondialog.cpp @@ -109,6 +109,19 @@ RegularExpressionDialog::RegularExpressionDialog(QWidget *parent) refresh(); } +void RegularExpressionDialog::setResultUiEnabled(bool enabled) +{ + matchDetailsTreeWidget->setEnabled(enabled); + namedGroupsTreeWidget->setEnabled(enabled); +} + +static void setTextColor(QWidget *widget, const QColor &color) +{ + QPalette palette = widget->palette(); + palette.setColor(QPalette::Text, color); + widget->setPalette(palette); +} + void RegularExpressionDialog::refresh() { setUpdatesEnabled(false); @@ -125,7 +138,30 @@ void RegularExpressionDialog::refresh() escaped.append(QLatin1Char('"')); escapedPatternLineEdit->setText(escaped); + setTextColor(patternLineEdit, subjectTextEdit->palette().color(QPalette::Text)); + matchDetailsTreeWidget->clear(); + namedGroupsTreeWidget->clear(); + regexpStatusLabel->setText(QString()); + + if (pattern.isEmpty()) { + setResultUiEnabled(false); + setUpdatesEnabled(true); + return; + } + QRegularExpression rx(pattern); + if (!rx.isValid()) { + setTextColor(patternLineEdit, Qt::red); + regexpStatusLabel->setText(tr("Invalid: syntax error at position %1 (%2)") + .arg(rx.patternErrorOffset()) + .arg(rx.errorString())); + setResultUiEnabled(false); + setUpdatesEnabled(true); + return; + } + + setResultUiEnabled(true); + QRegularExpression::MatchType matchType = matchTypeComboBox->currentData().value<QRegularExpression::MatchType>(); QRegularExpression::PatternOptions patternOptions = QRegularExpression::NoPatternOption; QRegularExpression::MatchOptions matchOptions = QRegularExpression::NoMatchOption; @@ -156,60 +192,40 @@ void RegularExpressionDialog::refresh() rx.setPatternOptions(patternOptions); - QPalette palette = patternLineEdit->palette(); - if (rx.isValid()) - palette.setColor(QPalette::Text, subjectTextEdit->palette().color(QPalette::Text)); - else - palette.setColor(QPalette::Text, Qt::red); - patternLineEdit->setPalette(palette); - - matchDetailsTreeWidget->clear(); - matchDetailsTreeWidget->setEnabled(rx.isValid()); + const int capturingGroupsCount = rx.captureCount() + 1; - if (rx.isValid()) { - const int capturingGroupsCount = rx.captureCount() + 1; + QRegularExpressionMatchIterator iterator = rx.globalMatch(text, offsetSpinBox->value(), matchType, matchOptions); + int i = 0; - QRegularExpressionMatchIterator iterator = rx.globalMatch(text, offsetSpinBox->value(), matchType, matchOptions); - int i = 0; + while (iterator.hasNext()) { + QRegularExpressionMatch match = iterator.next(); - while (iterator.hasNext()) { - QRegularExpressionMatch match = iterator.next(); + QTreeWidgetItem *matchDetailTopItem = new QTreeWidgetItem(matchDetailsTreeWidget); + matchDetailTopItem->setText(0, QString::number(i)); - QTreeWidgetItem *matchDetailTopItem = new QTreeWidgetItem(matchDetailsTreeWidget); - matchDetailTopItem->setText(0, QString::number(i)); - - for (int captureGroupIndex = 0; captureGroupIndex < capturingGroupsCount; ++captureGroupIndex) { - QTreeWidgetItem *matchDetailItem = new QTreeWidgetItem(matchDetailTopItem); - matchDetailItem->setText(1, QString::number(captureGroupIndex)); - matchDetailItem->setText(2, match.captured(captureGroupIndex)); - } - - ++i; + for (int captureGroupIndex = 0; captureGroupIndex < capturingGroupsCount; ++captureGroupIndex) { + QTreeWidgetItem *matchDetailItem = new QTreeWidgetItem(matchDetailTopItem); + matchDetailItem->setText(1, QString::number(captureGroupIndex)); + matchDetailItem->setText(2, match.captured(captureGroupIndex)); } + + ++i; } matchDetailsTreeWidget->expandAll(); - namedGroupsTreeWidget->clear(); - namedGroupsTreeWidget->setEnabled(rx.isValid()); - - if (rx.isValid()) { - regexpStatusLabel->setText(tr("Valid")); + regexpStatusLabel->setText(tr("Valid")); - const QStringList namedCaptureGroups = rx.namedCaptureGroups(); - for (int i = 0; i < namedCaptureGroups.size(); ++i) { - const QString currentNamedCaptureGroup = namedCaptureGroups.at(i); + const QStringList namedCaptureGroups = rx.namedCaptureGroups(); + for (int i = 0; i < namedCaptureGroups.size(); ++i) { + const QString currentNamedCaptureGroup = namedCaptureGroups.at(i); - QTreeWidgetItem *namedGroupItem = new QTreeWidgetItem(namedGroupsTreeWidget); - namedGroupItem->setText(0, QString::number(i)); - namedGroupItem->setText(1, currentNamedCaptureGroup.isNull() ? tr("<no name>") : currentNamedCaptureGroup); - } - } else { - regexpStatusLabel->setText(tr("Invalid: syntax error at position %1 (%2)") - .arg(rx.patternErrorOffset()) - .arg(rx.errorString())); + QTreeWidgetItem *namedGroupItem = new QTreeWidgetItem(namedGroupsTreeWidget); + namedGroupItem->setText(0, QString::number(i)); + namedGroupItem->setText(1, currentNamedCaptureGroup.isNull() ? tr("<no name>") : currentNamedCaptureGroup); } + setUpdatesEnabled(true); } diff --git a/examples/widgets/tools/regularexpression/regularexpressiondialog.h b/examples/widgets/tools/regularexpression/regularexpressiondialog.h index e75abc83e8..f7d64085fc 100644 --- a/examples/widgets/tools/regularexpression/regularexpressiondialog.h +++ b/examples/widgets/tools/regularexpression/regularexpressiondialog.h @@ -78,6 +78,7 @@ private: void setupUi(); QWidget *setupLeftUi(); QWidget *setupRightUi(); + void setResultUiEnabled(bool enabled); QLineEdit *patternLineEdit; QLineEdit *escapedPatternLineEdit; diff --git a/examples/widgets/widgets/tablet/tabletcanvas.cpp b/examples/widgets/widgets/tablet/tabletcanvas.cpp index ba797500e9..03e05e42f6 100644 --- a/examples/widgets/widgets/tablet/tabletcanvas.cpp +++ b/examples/widgets/widgets/tablet/tabletcanvas.cpp @@ -67,6 +67,7 @@ TabletCanvas::TabletCanvas() resize(500, 500); initPixmap(); setAutoFillBackground(true); + setAttribute(Qt::WA_TabletTracking); } void TabletCanvas::initPixmap() |