summaryrefslogtreecommitdiffstats
path: root/examples/widgets/tools
diff options
context:
space:
mode:
authorQt Forward Merge Bot <qt_forward_merge_bot@qt-project.org>2018-03-18 01:00:11 +0100
committerQt Forward Merge Bot <qt_forward_merge_bot@qt-project.org>2018-03-18 01:00:11 +0100
commitd58f3c4878b78699bd23507352a2f55881d9b76f (patch)
tree577e5fe415ed1741a7a6938451ba54bbbdcf1490 /examples/widgets/tools
parent6c7fff8c91d68912797fa84360ab374b858f44c4 (diff)
parentf6f40014c417aa90d4c805719e70910f522047e4 (diff)
Merge remote-tracking branch 'origin/5.11' into dev
Diffstat (limited to 'examples/widgets/tools')
-rw-r--r--examples/widgets/tools/regularexpression/regularexpressiondialog.cpp57
-rw-r--r--examples/widgets/tools/regularexpression/regularexpressiondialog.h2
2 files changed, 35 insertions, 24 deletions
diff --git a/examples/widgets/tools/regularexpression/regularexpressiondialog.cpp b/examples/widgets/tools/regularexpression/regularexpressiondialog.cpp
index 67d0db4bed..8fbf143cbd 100644
--- a/examples/widgets/tools/regularexpression/regularexpressiondialog.cpp
+++ b/examples/widgets/tools/regularexpression/regularexpressiondialog.cpp
@@ -77,6 +77,13 @@
Q_DECLARE_METATYPE(QRegularExpression::MatchType)
+static QString rawStringLiteral(QString pattern)
+{
+ pattern.prepend(QLatin1String("R\"RX("));
+ pattern.append(QLatin1String(")RX\""));
+ return pattern;
+}
+
static QString patternToCode(QString pattern)
{
pattern.replace(QLatin1String("\\"), QLatin1String("\\\\"));
@@ -173,6 +180,29 @@ void PatternLineEdit::contextMenuEvent(QContextMenuEvent *event)
menu->popup(event->globalPos());
}
+class DisplayLineEdit : public QLineEdit
+{
+public:
+ explicit DisplayLineEdit(QWidget *parent = nullptr);
+};
+
+DisplayLineEdit::DisplayLineEdit(QWidget *parent) : QLineEdit(parent)
+{
+ setReadOnly(true);
+ QPalette disabledPalette = palette();
+ disabledPalette.setBrush(QPalette::Base, disabledPalette.brush(QPalette::Disabled, QPalette::Base));
+ setPalette(disabledPalette);
+
+#if QT_CONFIG(clipboard)
+ QAction *copyAction = new QAction(this);
+ copyAction->setText(RegularExpressionDialog::tr("Copy to clipboard"));
+ copyAction->setIcon(QIcon(QStringLiteral(":/images/copy.png")));
+ connect(copyAction, &QAction::triggered, this,
+ [this] () { QGuiApplication::clipboard()->setText(text()); });
+ addAction(copyAction, QLineEdit::TrailingPosition);
+#endif
+}
+
RegularExpressionDialog::RegularExpressionDialog(QWidget *parent)
: QDialog(parent)
{
@@ -230,6 +260,7 @@ void RegularExpressionDialog::refresh()
offsetSpinBox->setMaximum(qMax(0, text.length() - 1));
escapedPatternLineEdit->setText(patternToCode(pattern));
+ rawStringLiteralLineEdit->setText(rawStringLiteral(pattern));
setTextColor(patternLineEdit, subjectTextEdit->palette().color(QPalette::Text));
matchDetailsTreeWidget->clear();
@@ -322,15 +353,6 @@ void RegularExpressionDialog::refresh()
setUpdatesEnabled(true);
}
-void RegularExpressionDialog::copyEscapedPatternToClipboard()
-{
-#if QT_CONFIG(clipboard)
- QClipboard *clipboard = QGuiApplication::clipboard();
- if (clipboard)
- clipboard->setText(escapedPatternLineEdit->text());
-#endif
-}
-
void RegularExpressionDialog::setupUi()
{
QWidget *leftHalfContainer = setupLeftUi();
@@ -363,20 +385,9 @@ QWidget *RegularExpressionDialog::setupLeftUi()
patternLineEdit->setClearButtonEnabled(true);
layout->addRow(tr("&Pattern:"), patternLineEdit);
- escapedPatternLineEdit = new QLineEdit;
- escapedPatternLineEdit->setReadOnly(true);
- QPalette palette = escapedPatternLineEdit->palette();
- palette.setBrush(QPalette::Base, palette.brush(QPalette::Disabled, QPalette::Base));
- escapedPatternLineEdit->setPalette(palette);
-
-#if QT_CONFIG(clipboard)
- QAction *copyEscapedPatternAction = new QAction(this);
- copyEscapedPatternAction->setText(tr("Copy to clipboard"));
- copyEscapedPatternAction->setIcon(QIcon(QStringLiteral(":/images/copy.png")));
- connect(copyEscapedPatternAction, &QAction::triggered, this, &RegularExpressionDialog::copyEscapedPatternToClipboard);
- escapedPatternLineEdit->addAction(copyEscapedPatternAction, QLineEdit::TrailingPosition);
-#endif
-
+ rawStringLiteralLineEdit = new DisplayLineEdit;
+ layout->addRow(tr("&Raw string literal:"), rawStringLiteralLineEdit);
+ escapedPatternLineEdit = new DisplayLineEdit;
layout->addRow(tr("&Escaped pattern:"), escapedPatternLineEdit);
subjectTextEdit = new QPlainTextEdit;
diff --git a/examples/widgets/tools/regularexpression/regularexpressiondialog.h b/examples/widgets/tools/regularexpression/regularexpressiondialog.h
index f7d64085fc..ba5b38b5e3 100644
--- a/examples/widgets/tools/regularexpression/regularexpressiondialog.h
+++ b/examples/widgets/tools/regularexpression/regularexpressiondialog.h
@@ -74,13 +74,13 @@ public:
private:
void refresh();
- void copyEscapedPatternToClipboard();
void setupUi();
QWidget *setupLeftUi();
QWidget *setupRightUi();
void setResultUiEnabled(bool enabled);
QLineEdit *patternLineEdit;
+ QLineEdit *rawStringLiteralLineEdit;
QLineEdit *escapedPatternLineEdit;
QPlainTextEdit *subjectTextEdit;