summaryrefslogtreecommitdiffstats
path: root/src/widgets/dialogs
diff options
context:
space:
mode:
Diffstat (limited to 'src/widgets/dialogs')
-rw-r--r--src/widgets/dialogs/qcolordialog.cpp100
-rw-r--r--src/widgets/dialogs/qcolordialog.h3
-rw-r--r--src/widgets/dialogs/qcolordialog_p.h5
-rw-r--r--src/widgets/dialogs/qdialog.cpp24
-rw-r--r--src/widgets/dialogs/qdialog_p.h3
-rw-r--r--src/widgets/dialogs/qfiledialog.cpp33
-rw-r--r--src/widgets/dialogs/qfiledialog_p.h2
-rw-r--r--src/widgets/dialogs/qmessagebox.cpp66
-rw-r--r--src/widgets/dialogs/qmessagebox.h1
-rw-r--r--src/widgets/dialogs/qwizard.cpp41
10 files changed, 201 insertions, 77 deletions
diff --git a/src/widgets/dialogs/qcolordialog.cpp b/src/widgets/dialogs/qcolordialog.cpp
index 8956842493..4c5fb18766 100644
--- a/src/widgets/dialogs/qcolordialog.cpp
+++ b/src/widgets/dialogs/qcolordialog.cpp
@@ -427,6 +427,30 @@ void QWellArray::keyPressEvent(QKeyEvent* e)
//////////// QWellArray END
+// Event filter to be installed on the dialog while in color-picking mode.
+class QColorPickingEventFilter : public QObject {
+public:
+ explicit QColorPickingEventFilter(QColorDialogPrivate *dp, QObject *parent = 0) : QObject(parent), m_dp(dp) {}
+
+ bool eventFilter(QObject *, QEvent *event) Q_DECL_OVERRIDE
+ {
+ switch (event->type()) {
+ case QEvent::MouseMove:
+ return m_dp->handleColorPickingMouseMove(static_cast<QMouseEvent *>(event));
+ case QEvent::MouseButtonRelease:
+ return m_dp->handleColorPickingMouseButtonRelease(static_cast<QMouseEvent *>(event));
+ case QEvent::KeyPress:
+ return m_dp->handleColorPickingKeyPress(static_cast<QKeyEvent *>(event));
+ default:
+ break;
+ }
+ return false;
+ }
+
+private:
+ QColorDialogPrivate *m_dp;
+};
+
/*!
Returns the number of custom colors supported by QColorDialog. All
color dialogs share the same custom colors.
@@ -1518,7 +1542,9 @@ void QColorDialogPrivate::_q_newStandard(int r, int c)
void QColorDialogPrivate::_q_pickScreenColor()
{
Q_Q(QColorDialog);
- screenColorPicking = true;
+ if (!colorPickingEventFilter)
+ colorPickingEventFilter = new QColorPickingEventFilter(this);
+ q->installEventFilter(colorPickingEventFilter);
// If user pushes Escape, the last color before picking will be restored.
beforeScreenColorPicking = cs->currentColor();
/*For some reason, q->grabMouse(Qt::CrossCursor) doesn't change
@@ -1548,7 +1574,7 @@ void QColorDialogPrivate::_q_pickScreenColor()
void QColorDialogPrivate::releaseColorPicking()
{
Q_Q(QColorDialog);
- screenColorPicking = false;
+ q->removeEventFilter(colorPickingEventFilter);
q->releaseMouse();
q->releaseKeyboard();
#ifndef QT_NO_CURSOR
@@ -1570,7 +1596,7 @@ void QColorDialogPrivate::init(const QColor &initial)
// default: use the native dialog if possible. Can be overridden in setOptions()
nativeDialogInUse = (platformColorDialogHelper() != 0);
- screenColorPicking = false;
+ colorPickingEventFilter = 0;
nextCust = 0;
if (!nativeDialogInUse)
@@ -2121,55 +2147,41 @@ void QColorDialog::changeEvent(QEvent *e)
QDialog::changeEvent(e);
}
-/*!
- \reimp
-*/
-void QColorDialog::mouseMoveEvent(QMouseEvent *e)
+bool QColorDialogPrivate::handleColorPickingMouseMove(QMouseEvent *e)
{
- Q_D(QColorDialog);
- if (d->screenColorPicking) {
- setCurrentColor(d->grabScreenColor(e->globalPos()));
- d->lblScreenColorInfo->setText(QColorDialog::tr("Cursor at %1, %2, color: %3\nPress ESC to cancel")
- .arg(e->globalPos().x())
- .arg(e->globalPos().y())
- .arg(currentColor().name()));
- return;
- }
- QDialog::mouseMoveEvent(e);
+ Q_Q(QColorDialog);
+ const QPoint globalPos = e->globalPos();
+ const QColor color = grabScreenColor(globalPos);
+ q->setCurrentColor(color);
+ lblScreenColorInfo->setText(QColorDialog::tr("Cursor at %1, %2, color: %3\nPress ESC to cancel")
+ .arg(globalPos.x()).arg(globalPos.y()).arg(color.name()));
+ return true;
}
-/*!
- \reimp
-*/
-void QColorDialog::mouseReleaseEvent(QMouseEvent *e)
+bool QColorDialogPrivate::handleColorPickingMouseButtonRelease(QMouseEvent *e)
{
- Q_D(QColorDialog);
- if (d->screenColorPicking) {
- setCurrentColor(d->grabScreenColor(e->globalPos()));
- d->releaseColorPicking();
- return;
- }
- QDialog::mouseReleaseEvent(e);
+ Q_Q(QColorDialog);
+ q->setCurrentColor(grabScreenColor(e->globalPos()));
+ releaseColorPicking();
+ return true;
}
-/*!
- \reimp
-*/
-void QColorDialog::keyPressEvent(QKeyEvent *e)
+bool QColorDialogPrivate::handleColorPickingKeyPress(QKeyEvent *e)
{
- Q_D(QColorDialog);
- if (d->screenColorPicking) {
- if (e->key() == Qt::Key_Escape) {
- d->releaseColorPicking();
- d->setCurrentColor(d->beforeScreenColorPicking);
- } else if (e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter) {
- setCurrentColor(d->grabScreenColor(QCursor::pos()));
- d->releaseColorPicking();
- }
- e->accept();
- return;
+ Q_Q(QColorDialog);
+ switch (e->key()) {
+ case Qt::Key_Escape:
+ releaseColorPicking();
+ q->setCurrentColor(beforeScreenColorPicking);
+ break;
+ case Qt::Key_Return:
+ case Qt::Key_Enter:
+ q->setCurrentColor(grabScreenColor(QCursor::pos()));
+ releaseColorPicking();
+ break;
}
- QDialog::keyPressEvent(e);
+ e->accept();
+ return true;
}
/*!
diff --git a/src/widgets/dialogs/qcolordialog.h b/src/widgets/dialogs/qcolordialog.h
index c7a1d6f400..c74ee6720a 100644
--- a/src/widgets/dialogs/qcolordialog.h
+++ b/src/widgets/dialogs/qcolordialog.h
@@ -112,9 +112,6 @@ Q_SIGNALS:
protected:
void changeEvent(QEvent *event);
- virtual void mouseMoveEvent(QMouseEvent *);
- virtual void mouseReleaseEvent(QMouseEvent *);
- virtual void keyPressEvent(QKeyEvent *);
void done(int result);
private:
diff --git a/src/widgets/dialogs/qcolordialog_p.h b/src/widgets/dialogs/qcolordialog_p.h
index 08199cc7c1..f58a9200db 100644
--- a/src/widgets/dialogs/qcolordialog_p.h
+++ b/src/widgets/dialogs/qcolordialog_p.h
@@ -70,6 +70,7 @@ class QLabel;
class QVBoxLayout;
class QPushButton;
class QWellArray;
+class QColorPickingEventFilter;
class QColorDialogPrivate : public QDialogPrivate
{
@@ -105,6 +106,9 @@ public:
void _q_newStandard(int, int);
void _q_pickScreenColor();
void releaseColorPicking();
+ bool handleColorPickingMouseMove(QMouseEvent *e);
+ bool handleColorPickingMouseButtonRelease(QMouseEvent *e);
+ bool handleColorPickingKeyPress(QKeyEvent *e);
QWellArray *custom;
QWellArray *standard;
@@ -125,6 +129,7 @@ public:
int nextCust;
bool smallDisplay;
bool screenColorPicking;
+ QColorPickingEventFilter *colorPickingEventFilter;
QRgb beforeScreenColorPicking;
QSharedPointer<QColorDialogOptions> options;
diff --git a/src/widgets/dialogs/qdialog.cpp b/src/widgets/dialogs/qdialog.cpp
index af352e45c6..d498b077fc 100644
--- a/src/widgets/dialogs/qdialog.cpp
+++ b/src/widgets/dialogs/qdialog.cpp
@@ -52,6 +52,8 @@
#include "qwhatsthis.h"
#include "qmenu.h"
#include "qcursor.h"
+#include "qmessagebox.h"
+#include "qerrormessage.h"
#include <qpa/qplatformtheme.h>
#include "private/qdialog_p.h"
#include "private/qguiapplication_p.h"
@@ -75,6 +77,14 @@ static inline int themeDialogType(const QDialog *dialog)
if (qobject_cast<const QFontDialog *>(dialog))
return QPlatformTheme::FontDialog;
#endif
+#ifndef QT_NO_MESSAGEBOX
+ if (qobject_cast<const QMessageBox *>(dialog))
+ return QPlatformTheme::MessageDialog;
+#endif
+#ifndef QT_NO_ERRORMESSAGE
+ if (qobject_cast<const QErrorMessage *>(dialog))
+ return QPlatformTheme::MessageDialog;
+#endif
return -1;
}
@@ -100,6 +110,17 @@ QPlatformDialogHelper *QDialogPrivate::platformHelper() const
return m_platformHelper;
}
+bool QDialogPrivate::canBeNativeDialog() const
+{
+ QDialogPrivate *ncThis = const_cast<QDialogPrivate *>(this);
+ QDialog *dialog = ncThis->q_func();
+ const int type = themeDialogType(dialog);
+ if (type >= 0)
+ return QGuiApplicationPrivate::platformTheme()
+ ->usePlatformNativeDialog(static_cast<QPlatformTheme::DialogType>(type));
+ return false;
+}
+
QWindow *QDialogPrivate::parentWindow() const
{
if (const QWidget *parent = q_func()->nativeParentWidget())
@@ -697,6 +718,9 @@ void QDialog::closeEvent(QCloseEvent *e)
void QDialog::setVisible(bool visible)
{
Q_D(QDialog);
+ if (!testAttribute(Qt::WA_DontShowOnScreen) && d->canBeNativeDialog() && d->setNativeDialogVisible(visible))
+ return;
+
if (visible) {
if (testAttribute(Qt::WA_WState_ExplicitShowHide) && !testAttribute(Qt::WA_WState_Hidden))
return;
diff --git a/src/widgets/dialogs/qdialog_p.h b/src/widgets/dialogs/qdialog_p.h
index 5064efa35d..8db1b2a27c 100644
--- a/src/widgets/dialogs/qdialog_p.h
+++ b/src/widgets/dialogs/qdialog_p.h
@@ -64,7 +64,7 @@ QT_BEGIN_NAMESPACE
class QSizeGrip;
-class QDialogPrivate : public QWidgetPrivate
+class Q_WIDGETS_EXPORT QDialogPrivate : public QWidgetPrivate
{
Q_DECLARE_PUBLIC(QDialog)
public:
@@ -113,6 +113,7 @@ public:
bool nativeDialogInUse;
QPlatformDialogHelper *platformHelper() const;
+ virtual bool canBeNativeDialog() const;
private:
virtual void initHelper(QPlatformDialogHelper *) {}
diff --git a/src/widgets/dialogs/qfiledialog.cpp b/src/widgets/dialogs/qfiledialog.cpp
index 11ad7c7a5d..1c3a793234 100644
--- a/src/widgets/dialogs/qfiledialog.cpp
+++ b/src/widgets/dialogs/qfiledialog.cpp
@@ -184,6 +184,13 @@ Q_WIDGETS_EXPORT _qt_filedialog_save_file_url_hook qt_filedialog_save_file_url_h
The \l{dialogs/standarddialogs}{Standard Dialogs} example shows
how to use QFileDialog as well as other built-in Qt dialogs.
+ By default, a platform-native file dialog will be used if the platform has
+ one. In that case, the widgets which would otherwise be used to construct the
+ dialog will not be instantiated, so related accessors such as layout() and
+ itemDelegate() will return null. You can set the \l DontUseNativeDialog option to
+ ensure that the widget-based implementation will be used instead of the
+ native dialog.
+
\sa QDir, QFileInfo, QFile, QColorDialog, QFontDialog, {Standard Dialogs Example},
{Application Example}
*/
@@ -243,7 +250,8 @@ Q_WIDGETS_EXPORT _qt_filedialog_save_file_url_hook qt_filedialog_save_file_url_h
\value DontUseNativeDialog Don't use the native file dialog. By
default, the native file dialog is used unless you use a subclass
- of QFileDialog that contains the Q_OBJECT macro.
+ of QFileDialog that contains the Q_OBJECT macro, or the platform
+ does not have a native dialog of the type that you require.
\value ReadOnly Indicates that the model is readonly.
@@ -620,7 +628,8 @@ void QFileDialogPrivate::helperPrepareShow(QPlatformDialogHelper *)
QUrl::fromLocalFile(directory.absolutePath()) :
QUrl());
options->setInitiallySelectedNameFilter(q->selectedNameFilter());
- options->setInitiallySelectedFiles(userSelectedFiles());
+ if (options->initiallySelectedFiles().isEmpty())
+ options->setInitiallySelectedFiles(userSelectedFiles());
}
void QFileDialogPrivate::helperDone(QDialog::DialogCode code, QPlatformDialogHelper *)
@@ -755,9 +764,9 @@ void QFileDialogPrivate::emitFilesSelected(const QStringList &files)
emit q->fileSelected(files.first());
}
-bool QFileDialogPrivate::canBeNativeDialog()
+bool QFileDialogPrivate::canBeNativeDialog() const
{
- Q_Q(QFileDialog);
+ Q_Q(const QFileDialog);
if (nativeDialogInUse)
return true;
if (q->testAttribute(Qt::WA_DontShowOnScreen))
@@ -1045,10 +1054,13 @@ void QFileDialog::selectFile(const QString &filename)
return;
if (!d->usingWidgets()) {
- d->selectFile_sys(QUrl::fromLocalFile(filename));
- QList<QUrl> i;
- i << QUrl(filename);
- d->options->setInitiallySelectedFiles(i);
+ QUrl url = QUrl::fromLocalFile(filename);
+ if (QFileInfo(filename).isRelative()) {
+ QDir dir(d->options->initialDirectory().toLocalFile());
+ url = QUrl::fromLocalFile(dir.absoluteFilePath(filename));
+ }
+ d->selectFile_sys(url);
+ d->options->setInitiallySelectedFiles(QList<QUrl>() << url);
return;
}
@@ -1675,11 +1687,8 @@ void QFileDialog::setAcceptMode(QFileDialog::AcceptMode mode)
d->options->setAcceptMode(static_cast<QFileDialogOptions::AcceptMode>(mode));
// clear WA_DontShowOnScreen so that d->canBeNativeDialog() doesn't return false incorrectly
setAttribute(Qt::WA_DontShowOnScreen, false);
- if (!d->usingWidgets()) {
- // we need to recreate the native dialog when changing the AcceptMode
- d->deletePlatformHelper();
+ if (!d->usingWidgets())
return;
- }
QDialogButtonBox::StandardButton button = (mode == AcceptOpen ? QDialogButtonBox::Open : QDialogButtonBox::Save);
d->qFileDialogUi->buttonBox->setStandardButtons(button | QDialogButtonBox::Cancel);
d->qFileDialogUi->buttonBox->button(button)->setEnabled(false);
diff --git a/src/widgets/dialogs/qfiledialog_p.h b/src/widgets/dialogs/qfiledialog_p.h
index 36336bdbf6..faa721572c 100644
--- a/src/widgets/dialogs/qfiledialog_p.h
+++ b/src/widgets/dialogs/qfiledialog_p.h
@@ -251,7 +251,7 @@ public:
// setVisible_sys returns true if it ends up showing a native
// dialog. Returning false means that a non-native dialog must be
// used instead.
- bool canBeNativeDialog();
+ bool canBeNativeDialog() const;
inline bool usingWidgets() const;
void setDirectory_sys(const QUrl &directory);
diff --git a/src/widgets/dialogs/qmessagebox.cpp b/src/widgets/dialogs/qmessagebox.cpp
index 13aaca2f48..1b64b0ba67 100644
--- a/src/widgets/dialogs/qmessagebox.cpp
+++ b/src/widgets/dialogs/qmessagebox.cpp
@@ -193,7 +193,6 @@ public:
}
};
-
class QMessageBoxPrivate : public QDialogPrivate
{
Q_DECLARE_PUBLIC(QMessageBox)
@@ -204,11 +203,13 @@ public:
detailsText(0),
#endif
compatMode(false), autoAddOkButton(true),
- detectedEscapeButton(0), informativeLabel(0) { }
+ detectedEscapeButton(0), informativeLabel(0),
+ options(new QMessageDialogOptions) { }
void init(const QString &title = QString(), const QString &text = QString());
void setupLayout();
void _q_buttonClicked(QAbstractButton *);
+ void _q_clicked(QMessageDialogOptions::StandardButton button, QMessageDialogOptions::ButtonRole role);
QAbstractButton *findButton(int button0, int button1, int button2, int flags);
void addOldButtons(int button0, int button1, int button2);
@@ -224,7 +225,6 @@ public:
#ifdef Q_OS_WINCE
void hideSpecial();
#endif
-
static int showOldMessageBox(QWidget *parent, QMessageBox::Icon icon,
const QString &title, const QString &text,
int button0, int button1, int button2);
@@ -262,6 +262,11 @@ public:
QPointer<QObject> receiverToDisconnectOnClose;
QByteArray memberToDisconnectOnClose;
QByteArray signalToDisconnectOnClose;
+ QSharedPointer<QMessageDialogOptions> options;
+private:
+ void initHelper(QPlatformDialogHelper *);
+ void helperPrepareShow(QPlatformDialogHelper *);
+ void helperDone(QDialog::DialogCode, QPlatformDialogHelper *);
};
void QMessageBoxPrivate::init(const QString &title, const QString &text)
@@ -519,6 +524,13 @@ void QMessageBoxPrivate::_q_buttonClicked(QAbstractButton *button)
}
}
+void QMessageBoxPrivate::_q_clicked(QMessageDialogOptions::StandardButton button, QMessageDialogOptions::ButtonRole role)
+{
+ Q_UNUSED(role);
+ Q_Q(QMessageBox);
+ q->done(button);
+}
+
/*!
\class QMessageBox
@@ -2682,6 +2694,54 @@ QPixmap QMessageBoxPrivate::standardIcon(QMessageBox::Icon icon, QMessageBox *mb
return QPixmap();
}
+void QMessageBoxPrivate::initHelper(QPlatformDialogHelper *h)
+{
+ Q_Q(QMessageBox);
+ QObject::connect(h, SIGNAL(clicked(QMessageDialogOptions::StandardButton, QMessageDialogOptions::ButtonRole)),
+ q, SLOT(_q_clicked(QMessageDialogOptions::StandardButton, QMessageDialogOptions::ButtonRole)));
+ static_cast<QPlatformMessageDialogHelper *>(h)->setOptions(options);
+}
+
+static QMessageDialogOptions::Icon helperIcon(QMessageBox::Icon i)
+{
+ switch (i) {
+ case QMessageBox::NoIcon:
+ return QMessageDialogOptions::NoIcon;
+ case QMessageBox::Information:
+ return QMessageDialogOptions::Information;
+ case QMessageBox::Warning:
+ return QMessageDialogOptions::Warning;
+ case QMessageBox::Critical:
+ return QMessageDialogOptions::Critical;
+ case QMessageBox::Question:
+ return QMessageDialogOptions::Question;
+ }
+ return QMessageDialogOptions::NoIcon;
+}
+
+static QMessageDialogOptions::StandardButtons helperStandardButtons(QMessageBox * q)
+{
+ QMessageDialogOptions::StandardButtons buttons(int(q->standardButtons()));
+ return buttons;
+}
+
+void QMessageBoxPrivate::helperPrepareShow(QPlatformDialogHelper *)
+{
+ Q_Q(QMessageBox);
+ options->setWindowTitle(q->windowTitle());
+ options->setText(q->text());
+ options->setInformativeText(q->informativeText());
+ options->setDetailedText(q->detailedText());
+ options->setIcon(helperIcon(q->icon()));
+ options->setStandardButtons(helperStandardButtons(q));
+}
+
+void QMessageBoxPrivate::helperDone(QDialog::DialogCode code, QPlatformDialogHelper *)
+{
+ Q_Q(QMessageBox);
+ clickedButton = q->button(QMessageBox::StandardButton(code));
+}
+
/*!
\obsolete
diff --git a/src/widgets/dialogs/qmessagebox.h b/src/widgets/dialogs/qmessagebox.h
index 58be13426c..c5598a8f1d 100644
--- a/src/widgets/dialogs/qmessagebox.h
+++ b/src/widgets/dialogs/qmessagebox.h
@@ -309,6 +309,7 @@ protected:
private:
Q_PRIVATE_SLOT(d_func(), void _q_buttonClicked(QAbstractButton *))
+ Q_PRIVATE_SLOT(d_func(), void _q_clicked(QMessageDialogOptions::StandardButton, QMessageDialogOptions::ButtonRole))
Q_DISABLE_COPY(QMessageBox)
Q_DECLARE_PRIVATE(QMessageBox)
diff --git a/src/widgets/dialogs/qwizard.cpp b/src/widgets/dialogs/qwizard.cpp
index 02ad5a3be5..a667f299e8 100644
--- a/src/widgets/dialogs/qwizard.cpp
+++ b/src/widgets/dialogs/qwizard.cpp
@@ -1345,6 +1345,33 @@ void QWizardPrivate::updateCurrentPage()
updateButtonTexts();
}
+static QString object_name_for_button(QWizard::WizardButton which)
+{
+ switch (which) {
+ case QWizard::CommitButton:
+ return QLatin1String("qt_wizard_") + QLatin1String("commit");
+ case QWizard::FinishButton:
+ return QLatin1String("qt_wizard_") + QLatin1String("finish");
+ case QWizard::CancelButton:
+ return QLatin1String("qt_wizard_") + QLatin1String("cancel");
+ case QWizard::BackButton:
+ case QWizard::NextButton:
+ case QWizard::HelpButton:
+ case QWizard::CustomButton1:
+ case QWizard::CustomButton2:
+ case QWizard::CustomButton3:
+ // Make navigation buttons detectable as passive interactor in designer
+ return QLatin1String("__qt__passive_wizardbutton") + QString::number(which);
+ case QWizard::Stretch:
+ case QWizard::NoButton:
+ //case QWizard::NStandardButtons:
+ //case QWizard::NButtons:
+ ;
+ }
+ Q_UNREACHABLE();
+ return QString();
+}
+
bool QWizardPrivate::ensureButton(QWizard::WizardButton which) const
{
Q_Q(const QWizard);
@@ -1356,19 +1383,7 @@ bool QWizardPrivate::ensureButton(QWizard::WizardButton which) const
QStyle *style = q->style();
if (style != QApplication::style()) // Propagate style
pushButton->setStyle(style);
- // Make navigation buttons detectable as passive interactor in designer
- switch (which) {
- case QWizard::CommitButton:
- case QWizard::FinishButton:
- case QWizard::CancelButton:
- break;
- default: {
- QString objectName = QLatin1String("__qt__passive_wizardbutton");
- objectName += QString::number(which);
- pushButton->setObjectName(objectName);
- }
- break;
- }
+ pushButton->setObjectName(object_name_for_button(which));
#ifdef Q_OS_MACX
pushButton->setAutoDefault(false);
#endif