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>
This commit is contained in:
parent
6e73061c58
commit
e34dccc9e5
@ -90,6 +90,7 @@ enum DetailButtonLabel { ShowLabel = 0, HideLabel = 1 };
|
|||||||
#ifndef QT_NO_TEXTEDIT
|
#ifndef QT_NO_TEXTEDIT
|
||||||
class QMessageBoxDetailsText : public QWidget
|
class QMessageBoxDetailsText : public QWidget
|
||||||
{
|
{
|
||||||
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
class TextEdit : public QTextEdit
|
class TextEdit : public QTextEdit
|
||||||
{
|
{
|
||||||
@ -109,6 +110,7 @@ public:
|
|||||||
|
|
||||||
QMessageBoxDetailsText(QWidget *parent=0)
|
QMessageBoxDetailsText(QWidget *parent=0)
|
||||||
: QWidget(parent)
|
: QWidget(parent)
|
||||||
|
, copyAvailable(false)
|
||||||
{
|
{
|
||||||
QVBoxLayout *layout = new QVBoxLayout;
|
QVBoxLayout *layout = new QVBoxLayout;
|
||||||
layout->setMargin(0);
|
layout->setMargin(0);
|
||||||
@ -122,10 +124,29 @@ public:
|
|||||||
textEdit->setReadOnly(true);
|
textEdit->setReadOnly(true);
|
||||||
layout->addWidget(textEdit);
|
layout->addWidget(textEdit);
|
||||||
setLayout(layout);
|
setLayout(layout);
|
||||||
|
|
||||||
|
connect(textEdit, SIGNAL(copyAvailable(bool)),
|
||||||
|
this, SLOT(textCopyAvailable(bool)));
|
||||||
}
|
}
|
||||||
void setText(const QString &text) { textEdit->setPlainText(text); }
|
void setText(const QString &text) { textEdit->setPlainText(text); }
|
||||||
QString text() const { return textEdit->toPlainText(); }
|
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:
|
private:
|
||||||
|
bool copyAvailable;
|
||||||
TextEdit *textEdit;
|
TextEdit *textEdit;
|
||||||
};
|
};
|
||||||
#endif // QT_NO_TEXTEDIT
|
#endif // QT_NO_TEXTEDIT
|
||||||
@ -1362,7 +1383,19 @@ void QMessageBox::keyPressEvent(QKeyEvent *e)
|
|||||||
return;
|
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) {
|
if (e == QKeySequence::Copy) {
|
||||||
QString separator = QString::fromLatin1("---------------------------\n");
|
QString separator = QString::fromLatin1("---------------------------\n");
|
||||||
QString textToCopy = separator;
|
QString textToCopy = separator;
|
||||||
@ -1383,7 +1416,9 @@ void QMessageBox::keyPressEvent(QKeyEvent *e)
|
|||||||
QApplication::clipboard()->setText(textToCopy);
|
QApplication::clipboard()->setText(textToCopy);
|
||||||
return;
|
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
|
#ifndef QT_NO_SHORTCUT
|
||||||
if (!(e->modifiers() & Qt::AltModifier)) {
|
if (!(e->modifiers() & Qt::AltModifier)) {
|
||||||
@ -2634,5 +2669,6 @@ QPixmap QMessageBox::standardIcon(Icon icon)
|
|||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
#include "moc_qmessagebox.cpp"
|
#include "moc_qmessagebox.cpp"
|
||||||
|
#include "qmessagebox.moc"
|
||||||
|
|
||||||
#endif // QT_NO_MESSAGEBOX
|
#endif // QT_NO_MESSAGEBOX
|
||||||
|
Loading…
Reference in New Issue
Block a user