diff options
author | Kai Koehne <kai.koehne@digia.com> | 2013-04-10 12:14:13 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-04-19 02:30:52 +0200 |
commit | e34dccc9e563966caafb113bd8cacb70cf5d57fd (patch) | |
tree | 29016b88171ab6ea7d54bb1491259819b1529406 /src/widgets/dialogs | |
parent | 6e73061c58236c2300f471dffea2e2606158fbac (diff) |
Allow using Ctrl+C to copy selected text from DetailedText in QMessageBox
Task-number: QTBUG-21895
Change-Id: Ib28f064295493595263945bc72907bf95d2cb909
Reviewed-by: Stephen Kelly <stephen.kelly@kdab.com>
Diffstat (limited to 'src/widgets/dialogs')
-rw-r--r-- | src/widgets/dialogs/qmessagebox.cpp | 40 |
1 files changed, 38 insertions, 2 deletions
diff --git a/src/widgets/dialogs/qmessagebox.cpp b/src/widgets/dialogs/qmessagebox.cpp index a485a55609..e08b321289 100644 --- a/src/widgets/dialogs/qmessagebox.cpp +++ b/src/widgets/dialogs/qmessagebox.cpp @@ -90,6 +90,7 @@ enum DetailButtonLabel { ShowLabel = 0, HideLabel = 1 }; #ifndef QT_NO_TEXTEDIT class QMessageBoxDetailsText : public QWidget { + Q_OBJECT public: class TextEdit : public QTextEdit { @@ -109,6 +110,7 @@ public: QMessageBoxDetailsText(QWidget *parent=0) : QWidget(parent) + , copyAvailable(false) { QVBoxLayout *layout = new QVBoxLayout; layout->setMargin(0); @@ -122,10 +124,29 @@ public: textEdit->setReadOnly(true); layout->addWidget(textEdit); setLayout(layout); + + connect(textEdit, SIGNAL(copyAvailable(bool)), + this, SLOT(textCopyAvailable(bool))); } void setText(const QString &text) { textEdit->setPlainText(text); } QString text() const { return textEdit->toPlainText(); } + + bool copy() + { + if (!copyAvailable) + return false; + textEdit->copy(); + return true; + } + +private slots: + void textCopyAvailable(bool available) + { + copyAvailable = available; + } + private: + bool copyAvailable; TextEdit *textEdit; }; #endif // QT_NO_TEXTEDIT @@ -1362,7 +1383,19 @@ void QMessageBox::keyPressEvent(QKeyEvent *e) return; } -#if defined (Q_OS_WIN) && !defined(QT_NO_CLIPBOARD) && !defined(QT_NO_SHORTCUT) + +#if !defined(QT_NO_CLIPBOARD) && !defined(QT_NO_SHORTCUT) + +#if !defined(QT_NO_TEXTEDIT) + if (e == QKeySequence::Copy) { + if (d->detailsText->isVisible() && d->detailsText->copy()) { + e->setAccepted(true); + return; + } + } +#endif // !QT_NO_TEXTEDIT + +#if defined(Q_OS_WIN) if (e == QKeySequence::Copy) { QString separator = QString::fromLatin1("---------------------------\n"); QString textToCopy = separator; @@ -1383,7 +1416,9 @@ void QMessageBox::keyPressEvent(QKeyEvent *e) QApplication::clipboard()->setText(textToCopy); return; } -#endif //QT_NO_SHORTCUT QT_NO_CLIPBOARD Q_OS_WIN +#endif // Q_OS_WIN + +#endif // !QT_NO_CLIPBOARD && !QT_NO_SHORTCUT #ifndef QT_NO_SHORTCUT if (!(e->modifiers() & Qt::AltModifier)) { @@ -2634,5 +2669,6 @@ QPixmap QMessageBox::standardIcon(Icon icon) QT_END_NAMESPACE #include "moc_qmessagebox.cpp" +#include "qmessagebox.moc" #endif // QT_NO_MESSAGEBOX |