summaryrefslogtreecommitdiffstats
path: root/src/widgets
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@nokia.com>2011-11-23 12:04:01 +0100
committerQt by Nokia <qt-info@nokia.com>2011-12-14 21:49:33 +0100
commit56c4ddfdf62ff6b71ce3df680bdaca01012e13f4 (patch)
tree5777f621303392efa9852f982e52a09a9e44e7e0 /src/widgets
parentf86007175d7d9d592e9cf6499704ad4f17944ce4 (diff)
QPlatformDialogHelpers: Reduce dependency on QDialog.
For each QDialog-derived class, introduce a Q[X]Options class containing the options of the dialog. An instance is shared between the QDialog (or dialog desktop component) and the helper. Change-Id: Ibabf508a4b9eaea25615638a47a4c1b8f93c019e Reviewed-by: Morten Johan Sørvig <morten.sorvig@nokia.com>
Diffstat (limited to 'src/widgets')
-rw-r--r--src/widgets/dialogs/qcolordialog.cpp106
-rw-r--r--src/widgets/dialogs/qcolordialog_p.h8
-rw-r--r--src/widgets/dialogs/qdialog.cpp25
-rw-r--r--src/widgets/dialogs/qdialog.h2
-rw-r--r--src/widgets/dialogs/qdialog_p.h3
-rw-r--r--src/widgets/dialogs/qfiledialog.cpp239
-rw-r--r--src/widgets/dialogs/qfiledialog_p.h32
-rw-r--r--src/widgets/dialogs/qfontdialog.cpp20
-rw-r--r--src/widgets/dialogs/qfontdialog_p.h6
-rw-r--r--src/widgets/kernel/qplatformdialoghelper_qpa.cpp466
-rw-r--r--src/widgets/kernel/qplatformdialoghelper_qpa.h187
11 files changed, 875 insertions, 219 deletions
diff --git a/src/widgets/dialogs/qcolordialog.cpp b/src/widgets/dialogs/qcolordialog.cpp
index 1803cba01d..d0a926e0cb 100644
--- a/src/widgets/dialogs/qcolordialog.cpp
+++ b/src/widgets/dialogs/qcolordialog.cpp
@@ -425,34 +425,13 @@ void QWellArray::keyPressEvent(QKeyEvent* e)
//////////// QWellArray END
-static bool initrgb = false;
-static QRgb stdrgb[6*8];
-static QRgb cusrgb[2*8];
-static bool customSet = false;
-
-
-static void initRGB()
-{
- if (initrgb)
- return;
- initrgb = true;
- int i = 0;
- for (int g = 0; g < 4; g++)
- for (int r = 0; r < 4; r++)
- for (int b = 0; b < 3; b++)
- stdrgb[i++] = qRgb(r * 255 / 3, g * 255 / 3, b * 255 / 2);
-
- for (i = 0; i < 2*8; i++)
- cusrgb[i] = 0xffffffff;
-}
-
/*!
Returns the number of custom colors supported by QColorDialog. All
color dialogs share the same custom colors.
*/
int QColorDialog::customCount()
{
- return 2 * 8;
+ return QColorDialogOptions::customColorCount();
}
/*!
@@ -462,10 +441,7 @@ int QColorDialog::customCount()
*/
QRgb QColorDialog::customColor(int index)
{
- if (uint(index) >= uint(customCount()))
- return qRgb(255, 255, 255);
- initRGB();
- return cusrgb[index];
+ return QColorDialogOptions::customColor(index);
}
/*!
@@ -477,11 +453,7 @@ QRgb QColorDialog::customColor(int index)
*/
void QColorDialog::setCustomColor(int index, QRgb color)
{
- if (uint(index) >= uint(customCount()))
- return;
- initRGB();
- customSet = true;
- cusrgb[index] = color;
+ QColorDialogOptions::setCustomColor(index, color);
}
/*!
@@ -494,10 +466,7 @@ void QColorDialog::setCustomColor(int index, QRgb color)
void QColorDialog::setStandardColor(int index, QRgb color)
{
- if (uint(index) >= uint(6 * 8))
- return;
- initRGB();
- stdrgb[index] = color;
+ QColorDialogOptions::setStandardColor(index, color);
}
static inline void rgb2hsv(QRgb rgb, int &h, int &s, int &v)
@@ -1421,9 +1390,10 @@ bool QColorDialogPrivate::selectColor(const QColor &col)
int i = 0, j = 0;
// Check standard colors
if (standard) {
+ const QRgb *standardColors = QColorDialogOptions::standardColors();
for (i = 0; i < 6; i++) {
for (j = 0; j < 8; j++) {
- if (color == stdrgb[i + j*6]) {
+ if (color == standardColors[i + j*6]) {
_q_newStandard(i, j);
standard->setCurrent(i, j);
standard->setSelected(i, j);
@@ -1435,9 +1405,10 @@ bool QColorDialogPrivate::selectColor(const QColor &col)
}
// Check custom colors
if (custom) {
+ const QRgb *customColors = QColorDialogOptions::customColors();
for (i = 0; i < 2; i++) {
for (j = 0; j < 8; j++) {
- if (color == cusrgb[i + j*2]) {
+ if (color == customColors[i + j*2]) {
_q_newCustom(i, j);
custom->setCurrent(i, j);
custom->setSelected(i, j);
@@ -1461,8 +1432,8 @@ void QColorDialogPrivate::_q_newColorTypedIn(QRgb rgb)
void QColorDialogPrivate::_q_newCustom(int r, int c)
{
- int i = r+2*c;
- setCurrentColor(cusrgb[i]);
+ const int i = r + 2 * c;
+ setCurrentColor(QColorDialogOptions::customColor(i));
nextCust = i;
if (standard)
standard->setSelected(-1,-1);
@@ -1470,7 +1441,7 @@ void QColorDialogPrivate::_q_newCustom(int r, int c)
void QColorDialogPrivate::_q_newStandard(int r, int c)
{
- setCurrentColor(stdrgb[r+c*6]);
+ setCurrentColor(QColorDialogOptions::standardColor(r + c * 6));
if (custom)
custom->setSelected(-1,-1);
}
@@ -1509,21 +1480,6 @@ void QColorDialogPrivate::init(const QColor &initial)
topLay->addLayout(leftLay);
}
- initRGB();
-
-#ifndef QT_NO_SETTINGS
- if (!customSet) {
- QSettings settings(QSettings::UserScope, QLatin1String("Trolltech"));
- for (int i = 0; i < 2*8; ++i) {
- QVariant v = settings.value(QLatin1String("Qt/customColors/") + QString::number(i));
- if (v.isValid()) {
- QRgb rgb = v.toUInt();
- cusrgb[i] = rgb;
- }
- }
- }
-#endif
-
#if defined(QT_SMALL_COLORDIALOG)
# if defined(Q_WS_S60)
const bool nonTouchUI = !S60->hasTouchscreen;
@@ -1533,7 +1489,7 @@ void QColorDialogPrivate::init(const QColor &initial)
#endif
if (!smallDisplay) {
- standard = new QColorWell(q, 6, 8, stdrgb);
+ standard = new QColorWell(q, 6, 8, QColorDialogOptions::standardColors());
lblBasicColors = new QLabel(q);
#ifndef QT_NO_SHORTCUT
lblBasicColors->setBuddy(standard);
@@ -1546,7 +1502,7 @@ void QColorDialogPrivate::init(const QColor &initial)
leftLay->addStretch();
#endif
- custom = new QColorWell(q, 2, 8, cusrgb);
+ custom = new QColorWell(q, 2, 8, QColorDialogOptions::customColors());
custom->setAcceptDrops(true);
q->connect(custom, SIGNAL(selected(int,int)), SLOT(_q_newCustom(int,int)));
@@ -1657,22 +1613,22 @@ void QColorDialogPrivate::initHelper(QPlatformDialogHelper *h)
QColorDialog *d = q_func();
QObject::connect(h, SIGNAL(currentColorChanged(QColor)), d, SIGNAL(currentColorChanged(QColor)));
QObject::connect(h, SIGNAL(colorSelected(QColor)), d, SIGNAL(colorSelected(QColor)));
+ static_cast<QPlatformColorDialogHelper *>(h)->setOptions(options);
+}
+
+void QColorDialogPrivate::helperPrepareShow(QPlatformDialogHelper *)
+{
+ options->setWindowTitle(q_func()->windowTitle());
}
void QColorDialogPrivate::_q_addCustom()
{
- cusrgb[nextCust] = cs->currentColor();
+ QColorDialogOptions::setCustomColor(nextCust, cs->currentColor());
if (custom)
custom->update();
nextCust = (nextCust+1) % 16;
}
-void QColorDialogPrivate::_q_platformRunNativeAppModalPanel()
-{
- if (nativeDialogInUse)
- platformHelper()->_q_platformRunNativeAppModalPanel();
-}
-
void QColorDialogPrivate::retranslateStrings()
{
if (!smallDisplay) {
@@ -1800,8 +1756,7 @@ QColor QColorDialog::selectedColor() const
void QColorDialog::setOption(ColorDialogOption option, bool on)
{
Q_D(QColorDialog);
- if (!(d->opts & option) != !on)
- setOptions(d->opts ^ option);
+ d->options->setOption(static_cast<QColorDialogOptions::ColorDialogOption>(option), on);
}
/*!
@@ -1815,7 +1770,7 @@ void QColorDialog::setOption(ColorDialogOption option, bool on)
bool QColorDialog::testOption(ColorDialogOption option) const
{
Q_D(const QColorDialog);
- return (d->opts & option) != 0;
+ return d->options->testOption(static_cast<QColorDialogOptions::ColorDialogOption>(option));
}
/*!
@@ -1834,11 +1789,10 @@ void QColorDialog::setOptions(ColorDialogOptions options)
{
Q_D(QColorDialog);
- ColorDialogOptions changed = (options ^ d->opts);
- if (!changed)
+ if (QColorDialog::options() == options)
return;
- d->opts = options;
+ d->options->setOptions(QColorDialogOptions::ColorDialogOptions(int(options)));
d->buttons->setVisible(!(options & NoButtons));
d->showAlpha(options & ShowAlphaChannel);
}
@@ -1846,7 +1800,7 @@ void QColorDialog::setOptions(ColorDialogOptions options)
QColorDialog::ColorDialogOptions QColorDialog::options() const
{
Q_D(const QColorDialog);
- return d->opts;
+ return QColorDialog::ColorDialogOptions(int(d->options->options()));
}
/*!
@@ -1922,7 +1876,7 @@ void QColorDialog::setVisible(bool visible)
}
#else
- if (!(d->opts & DontUseNativeDialog))
+ if (!(options() & DontUseNativeDialog))
d->setNativeDialogVisible(visible);
if (d->nativeDialogInUse) {
@@ -2026,14 +1980,6 @@ QColorDialog::~QColorDialog()
QColorDialogPrivate::sharedColorPanelAvailable = true;
}
#endif
-
-#ifndef QT_NO_SETTINGS
- if (!customSet) {
- QSettings settings(QSettings::UserScope, QLatin1String("Trolltech"));
- for (int i = 0; i < 2*8; ++i)
- settings.setValue(QLatin1String("Qt/customColors/") + QString::number(i), cusrgb[i]);
- }
-#endif
}
/*!
diff --git a/src/widgets/dialogs/qcolordialog_p.h b/src/widgets/dialogs/qcolordialog_p.h
index 39d7192b1d..42176fe214 100644
--- a/src/widgets/dialogs/qcolordialog_p.h
+++ b/src/widgets/dialogs/qcolordialog_p.h
@@ -56,6 +56,7 @@
#include "private/qdialog_p.h"
#include "qcolordialog.h"
+#include "qsharedpointer.h"
#ifndef QT_NO_COLORDIALOG
@@ -75,6 +76,8 @@ class QColorDialogPrivate : public QDialogPrivate
Q_DECLARE_PUBLIC(QColorDialog)
public:
+ QColorDialogPrivate() : options(new QColorDialogOptions) {}
+
QPlatformColorDialogHelper *platformColorDialogHelper() const
{ return static_cast<QPlatformColorDialogHelper *>(platformHelper()); }
@@ -92,7 +95,6 @@ public:
void retranslateStrings();
void _q_addCustom();
- void _q_platformRunNativeAppModalPanel();
void _q_newHsv(int h, int s, int v);
void _q_newColorTypedIn(QRgb rgb);
@@ -115,7 +117,8 @@ public:
QColor selectedQColor;
int nextCust;
bool smallDisplay;
- QColorDialog::ColorDialogOptions opts;
+ QSharedPointer<QColorDialogOptions> options;
+
QPointer<QObject> receiverToDisconnectOnClose;
QByteArray memberToDisconnectOnClose;
@@ -138,6 +141,7 @@ public:
#endif
private:
virtual void initHelper(QPlatformDialogHelper *h);
+ virtual void helperPrepareShow(QPlatformDialogHelper *h);
};
#endif // QT_NO_COLORDIALOG
diff --git a/src/widgets/dialogs/qdialog.cpp b/src/widgets/dialogs/qdialog.cpp
index 363d3bf592..4170530ff7 100644
--- a/src/widgets/dialogs/qdialog.cpp
+++ b/src/widgets/dialogs/qdialog.cpp
@@ -66,10 +66,16 @@ QPlatformDialogHelper *QDialogPrivate::platformHelper() const
if (!m_platformHelperCreated) {
QDialogPrivate *ncThis = const_cast<QDialogPrivate *>(this);
m_platformHelperCreated = true;
+ QDialog *dialog = ncThis->q_func();
m_platformHelper = QGuiApplicationPrivate::platformTheme()
- ->createPlatformDialogHelper(ncThis->q_func());
- if (m_platformHelper)
+ ->createPlatformDialogHelper(dialog);
+ if (m_platformHelper) {
+ QObject::connect(m_platformHelper, SIGNAL(accept()), dialog, SLOT(accept()));
+ QObject::connect(m_platformHelper, SIGNAL(reject()), dialog, SLOT(reject()));
+ QObject::connect(m_platformHelper, SIGNAL(launchNativeAppModalPanel()),
+ dialog, SLOT(_q_platformRunNativeAppModalPanel()));
ncThis->initHelper(m_platformHelper);
+ }
}
return m_platformHelper;
}
@@ -85,7 +91,11 @@ bool QDialogPrivate::setNativeDialogVisible(bool visible)
{
if (QPlatformDialogHelper *helper = platformHelper()) {
if (visible) {
- nativeDialogInUse = helper->show_sys(parentWindow());
+ helperPrepareShow(helper);
+ QPlatformDialogHelper::ShowFlags flags(0);
+ if (q_func()->isModal())
+ flags |= QPlatformDialogHelper::ShowModal;
+ nativeDialogInUse = helper->show_sys(flags, q_func()->windowFlags(), parentWindow());
} else {
helper->hide_sys();
}
@@ -93,6 +103,13 @@ bool QDialogPrivate::setNativeDialogVisible(bool visible)
return nativeDialogInUse;
}
+void QDialogPrivate::_q_platformRunNativeAppModalPanel()
+{
+ if (nativeDialogInUse)
+ platformHelper()->_q_platformRunNativeAppModalPanel();
+}
+
+
QVariant QDialogPrivate::styleHint(QPlatformDialogHelper::StyleHint hint) const
{
if (const QPlatformDialogHelper *helper = platformHelper())
@@ -505,6 +522,8 @@ int QDialog::exec()
int res = result();
if (deleteOnClose)
delete this;
+ if (d->nativeDialogInUse)
+ d->helperDone(static_cast<QDialog::DialogCode>(res), d->platformHelper());
return res;
}
diff --git a/src/widgets/dialogs/qdialog.h b/src/widgets/dialogs/qdialog.h
index d4171ece47..18f65274e5 100644
--- a/src/widgets/dialogs/qdialog.h
+++ b/src/widgets/dialogs/qdialog.h
@@ -118,7 +118,7 @@ protected:
private:
Q_DECLARE_PRIVATE(QDialog)
Q_DISABLE_COPY(QDialog)
-
+ Q_PRIVATE_SLOT(d_func(), void _q_platformRunNativeAppModalPanel())
#ifdef Q_WS_WINCE_WM
Q_PRIVATE_SLOT(d_func(), void _q_doneAction())
diff --git a/src/widgets/dialogs/qdialog_p.h b/src/widgets/dialogs/qdialog_p.h
index 3d90686b6d..83964a1b99 100644
--- a/src/widgets/dialogs/qdialog_p.h
+++ b/src/widgets/dialogs/qdialog_p.h
@@ -79,6 +79,7 @@ public:
nativeDialogInUse(false), m_platformHelper(0), m_platformHelperCreated(false)
{}
~QDialogPrivate() { delete m_platformHelper; }
+ void _q_platformRunNativeAppModalPanel();
QWindow *parentWindow() const;
bool setNativeDialogVisible(bool visible);
@@ -115,6 +116,8 @@ public:
private:
virtual void initHelper(QPlatformDialogHelper *) {}
+ virtual void helperPrepareShow(QPlatformDialogHelper *) {}
+ virtual void helperDone(QDialog::DialogCode, QPlatformDialogHelper *) {}
mutable QPlatformDialogHelper *m_platformHelper;
mutable bool m_platformHelperCreated;
diff --git a/src/widgets/dialogs/qfiledialog.cpp b/src/widgets/dialogs/qfiledialog.cpp
index 19f474e503..c3561cc62a 100644
--- a/src/widgets/dialogs/qfiledialog.cpp
+++ b/src/widgets/dialogs/qfiledialog.cpp
@@ -507,16 +507,14 @@ QFileDialogPrivate::QFileDialogPrivate()
proxyModel(0),
#endif
model(0),
- fileMode(QFileDialog::AnyFile),
- acceptMode(QFileDialog::AcceptOpen),
currentHistoryLocation(-1),
renameAction(0),
deleteAction(0),
showHiddenAction(0),
useDefaultCaption(true),
defaultFileTypes(true),
- fileNameLabelExplicitlySat(false),
- qFileDialogUi(0)
+ qFileDialogUi(0),
+ options(new QFileDialogOptions)
{
}
@@ -524,12 +522,49 @@ QFileDialogPrivate::~QFileDialogPrivate()
{
}
+void QFileDialogPrivate::initHelper(QPlatformDialogHelper *h)
+{
+ QFileDialog *d = q_func();
+ QObject::connect(h, SIGNAL(fileSelected(QString)), d, SIGNAL(fileSelected(QString)));
+ QObject::connect(h, SIGNAL(filesSelected(QStringList)), d, SIGNAL(filesSelected(QStringList)));
+ QObject::connect(h, SIGNAL(currentChanged(QString)), d, SIGNAL(currentChanged(QString)));
+ QObject::connect(h, SIGNAL(directoryEntered(QString)), d, SIGNAL(directoryEntered(QString)));
+ QObject::connect(h, SIGNAL(filterSelected(QString)), d, SIGNAL(filterSelected(QString)));
+ static_cast<QPlatformFileDialogHelper *>(h)->setOptions(options);
+}
+
+void QFileDialogPrivate::helperPrepareShow(QPlatformDialogHelper *)
+{
+ Q_Q(QFileDialog);
+ options->setWindowTitle(q->windowTitle());
+ options->setViewMode(static_cast<QFileDialogOptions::ViewMode>(q->viewMode()));
+ options->setHistory(q->history());
+ options->setSidebarUrls(qFileDialogUi->sidebar->urls());
+ const QDir directory = q->directory();
+ options->setInitialDirectory(directory.exists() ?
+ directory.absolutePath() :
+ QString());
+ options->setInitiallySelectedNameFilter(q->selectedNameFilter());
+ options->setInitiallySelectedFiles(q->selectedFiles());
+}
+
+void QFileDialogPrivate::helperDone(QDialog::DialogCode code, QPlatformDialogHelper *)
+{
+ if (code == QDialog::Accepted) {
+ Q_Q(QFileDialog);
+ q->setViewMode(static_cast<QFileDialog::ViewMode>(options->viewMode()));
+ q->setSidebarUrls(options->sidebarUrls());
+ q->setHistory(options->history());
+ }
+}
+
void QFileDialogPrivate::retranslateWindowTitle()
{
Q_Q(QFileDialog);
if (!useDefaultCaption || setWindowTitle != q->windowTitle())
return;
- if (acceptMode == QFileDialog::AcceptOpen) {
+ if (q->acceptMode() == QFileDialog::AcceptOpen) {
+ const QFileDialog::FileMode fileMode = q->fileMode();
if (fileMode == QFileDialog::DirectoryOnly || fileMode == QFileDialog::Directory)
q->setWindowTitle(QFileDialog::tr("Find Directory"));
else
@@ -545,6 +580,46 @@ void QFileDialogPrivate::setLastVisitedDirectory(const QString &dir)
*lastVisitedDir() = dir;
}
+void QFileDialogPrivate::updateFileNameLabel()
+{
+ if (!options->isLabelExplicitlySet(QFileDialogOptions::FileName)) {
+ switch (q_func()->fileMode()) {
+ case QFileDialog::DirectoryOnly:
+ case QFileDialog::Directory:
+ setLabelTextControl(QFileDialog::FileName, QFileDialog::tr("Directory:"));
+ break;
+ default:
+ setLabelTextControl(QFileDialog::FileName, QFileDialog::tr("File &name:"));
+ break;
+ }
+ }
+}
+
+void QFileDialogPrivate::updateOkButtonText(bool saveAsOnFolder)
+{
+ Q_Q(QFileDialog);
+ // 'Save as' at a folder: Temporarily change to "Open".
+ if (saveAsOnFolder) {
+ setLabelTextControl(QFileDialog::Accept, QFileDialog::tr("&Open"));
+ } else if (options->isLabelExplicitlySet(QFileDialogOptions::Accept)) {
+ setLabelTextControl(QFileDialog::Accept, options->labelText(QFileDialogOptions::Accept));
+ return;
+ } else {
+ switch (q->fileMode()) {
+ case QFileDialog::DirectoryOnly:
+ case QFileDialog::Directory:
+ setLabelTextControl(QFileDialog::Accept, QFileDialog::tr("&Choose"));
+ break;
+ default:
+ setLabelTextControl(QFileDialog::Accept,
+ q->acceptMode() == QFileDialog::AcceptOpen ?
+ QFileDialog::tr("&Open") :
+ QFileDialog::tr("&Save"));
+ break;
+ }
+ }
+}
+
void QFileDialogPrivate::retranslateStrings()
{
Q_Q(QFileDialog);
@@ -569,15 +644,7 @@ void QFileDialogPrivate::retranslateStrings()
showHiddenAction->setText(QFileDialog::tr("Show &hidden files"));
newFolderAction->setText(QFileDialog::tr("&New Folder"));
qFileDialogUi->retranslateUi(q);
-
- if (!fileNameLabelExplicitlySat){
- if (fileMode == QFileDialog::DirectoryOnly || fileMode == QFileDialog::Directory) {
- q->setLabelText(QFileDialog::FileName, QFileDialog::tr("Directory:"));
- } else {
- q->setLabelText(QFileDialog::FileName, QFileDialog::tr("File &name:"));
- }
- fileNameLabelExplicitlySat = false;
- }
+ updateFileNameLabel();
}
void QFileDialogPrivate::emitFilesSelected(const QStringList &files)
@@ -595,7 +662,7 @@ bool QFileDialogPrivate::canBeNativeDialog()
return true;
if (q->testAttribute(Qt::WA_DontShowOnScreen))
return false;
- if (opts & QFileDialog::DontUseNativeDialog)
+ if (q->options() & QFileDialog::DontUseNativeDialog)
return false;
QLatin1String staticName(QFileDialog::staticMetaObject.className());
@@ -612,9 +679,9 @@ bool QFileDialogPrivate::canBeNativeDialog()
*/
void QFileDialog::setOption(Option option, bool on)
{
- Q_D(QFileDialog);
- if (!(d->opts & option) != !on)
- setOptions(d->opts ^ option);
+ const QFileDialog::Options previousOptions = options();
+ if (!(previousOptions & option) != !on)
+ setOptions(previousOptions ^ option);
}
/*!
@@ -628,7 +695,7 @@ void QFileDialog::setOption(Option option, bool on)
bool QFileDialog::testOption(Option option) const
{
Q_D(const QFileDialog);
- return (d->opts & option) != 0;
+ return d->options->testOption(static_cast<QFileDialogOptions::FileDialogOption>(option));
}
/*!
@@ -648,11 +715,11 @@ void QFileDialog::setOptions(Options options)
{
Q_D(QFileDialog);
- Options changed = (options ^ d->opts);
+ Options changed = (options ^ QFileDialog::options());
if (!changed)
return;
- d->opts = options;
+ d->options->setOptions(QFileDialogOptions::FileDialogOptions(int(options)));
if (changed & DontResolveSymlinks)
d->model->setResolveSymlinks(!(options & DontResolveSymlinks));
if (changed & ReadOnly) {
@@ -663,7 +730,7 @@ void QFileDialog::setOptions(Options options)
d->deleteAction->setEnabled(!ro);
}
if (changed & HideNameFilterDetails)
- setNameFilters(d->nameFilters);
+ setNameFilters(d->options->nameFilters());
if (changed & ShowDirsOnly)
setFilter((options & ShowDirsOnly) ? filter() & ~QDir::Files : filter() | QDir::Files);
@@ -672,7 +739,7 @@ void QFileDialog::setOptions(Options options)
QFileDialog::Options QFileDialog::options() const
{
Q_D(const QFileDialog);
- return d->opts;
+ return QFileDialog::Options(int(d->options->options()));
}
/*!
@@ -942,6 +1009,7 @@ QStringList QFileDialogPrivate::addDefaultSuffixToFiles(const QStringList filesT
QString name = toInternal(filesToFix.at(i));
QFileInfo info(name);
// if the filename has no suffix, add the default suffix
+ const QString defaultSuffix = options->defaultSuffix();
if (!defaultSuffix.isEmpty() && !info.isDir() && name.lastIndexOf(QLatin1Char('.')) == -1)
name += QLatin1Char('.') + defaultSuffix;
if (info.isAbsolute()) {
@@ -981,8 +1049,8 @@ QStringList QFileDialog::selectedFiles() const
if (files.isEmpty() && !d->lineEdit()->text().isEmpty())
files = d->typedFiles();
-
- if (files.isEmpty() && !(d->fileMode == ExistingFile || d->fileMode == ExistingFiles))
+ const FileMode fm = fileMode();
+ if (files.isEmpty() && !(fm == ExistingFile || fm == ExistingFiles))
files.append(d->rootIndex().data(QFileSystemModel::FilePathRole).toString());
return files;
}
@@ -1095,12 +1163,7 @@ void QFileDialog::setNameFilters(const QStringList &filters)
for (int i = 0; i < filters.count(); ++i) {
cleanedFilters << filters[i].simplified();
}
- d->nameFilters = cleanedFilters;
-
- if (d->nativeDialogInUse){
- d->setNameFilters_sys(cleanedFilters);
- return;
- }
+ d->options->setNameFilters(cleanedFilters);
d->qFileDialogUi->fileTypeCombo->clear();
if (cleanedFilters.isEmpty())
@@ -1132,7 +1195,7 @@ void QFileDialog::setFilters(const QStringList &filters)
*/
QStringList QFileDialog::nameFilters() const
{
- return d_func()->nameFilters;
+ return d_func()->options->nameFilters();
}
/*!
@@ -1236,6 +1299,7 @@ void QFileDialog::setFilter(QDir::Filters filters)
{
Q_D(QFileDialog);
d->model->setFilter(filters);
+ d->options->setFilter(filters);
if (d->nativeDialogInUse){
d->setFilter_sys();
return;
@@ -1286,7 +1350,7 @@ QFileDialog::ViewMode QFileDialog::viewMode() const
void QFileDialog::setFileMode(QFileDialog::FileMode mode)
{
Q_D(QFileDialog);
- d->fileMode = mode;
+ d->options->setFileMode(static_cast<QFileDialogOptions::FileMode>(mode));
d->retranslateWindowTitle();
// keep ShowDirsOnly option in sync with fileMode (BTW, DirectoryOnly is obsolete)
@@ -1303,24 +1367,13 @@ void QFileDialog::setFileMode(QFileDialog::FileMode mode)
// set filter
d->model->setFilter(d->filterForMode(filter()));
// setup file type for directory
- QString buttonText = (d->acceptMode == AcceptOpen ? tr("&Open") : tr("&Save"));
if (mode == DirectoryOnly || mode == Directory) {
d->qFileDialogUi->fileTypeCombo->clear();
d->qFileDialogUi->fileTypeCombo->addItem(tr("Directories"));
d->qFileDialogUi->fileTypeCombo->setEnabled(false);
-
- if (!d->fileNameLabelExplicitlySat){
- setLabelText(FileName, tr("Directory:"));
- d->fileNameLabelExplicitlySat = false;
- }
- buttonText = tr("&Choose");
- } else {
- if (!d->fileNameLabelExplicitlySat){
- setLabelText(FileName, tr("File &name:"));
- d->fileNameLabelExplicitlySat = false;
- }
}
- setLabelText(Accept, buttonText);
+ d->updateFileNameLabel();
+ d->updateOkButtonText();
if (d->nativeDialogInUse){
d->setFilter_sys();
return;
@@ -1333,7 +1386,7 @@ void QFileDialog::setFileMode(QFileDialog::FileMode mode)
QFileDialog::FileMode QFileDialog::fileMode() const
{
Q_D(const QFileDialog);
- return d->fileMode;
+ return static_cast<FileMode>(d->options->fileMode());
}
/*!
@@ -1349,16 +1402,11 @@ QFileDialog::FileMode QFileDialog::fileMode() const
void QFileDialog::setAcceptMode(QFileDialog::AcceptMode mode)
{
Q_D(QFileDialog);
- d->acceptMode = mode;
- bool directoryMode = (d->fileMode == Directory || d->fileMode == DirectoryOnly);
+ d->options->setAcceptMode(static_cast<QFileDialogOptions::AcceptMode>(mode));
QDialogButtonBox::StandardButton button = (mode == AcceptOpen ? QDialogButtonBox::Open : QDialogButtonBox::Save);
d->qFileDialogUi->buttonBox->setStandardButtons(button | QDialogButtonBox::Cancel);
d->qFileDialogUi->buttonBox->button(button)->setEnabled(false);
d->_q_updateOkButton();
- if (mode == AcceptOpen && directoryMode)
- setLabelText(Accept, tr("&Choose"));
- else
- setLabelText(Accept, (mode == AcceptOpen ? tr("&Open") : tr("&Save")));
if (mode == AcceptSave) {
d->qFileDialogUi->lookInCombo->setEditable(false);
}
@@ -1415,7 +1463,7 @@ QModelIndex QFileDialogPrivate::select(const QModelIndex &index) const {
QFileDialog::AcceptMode QFileDialog::acceptMode() const
{
Q_D(const QFileDialog);
- return d->acceptMode;
+ return static_cast<AcceptMode>(d->options->acceptMode());
}
/*!
@@ -1490,13 +1538,13 @@ bool QFileDialog::confirmOverwrite() const
void QFileDialog::setDefaultSuffix(const QString &suffix)
{
Q_D(QFileDialog);
- d->defaultSuffix = suffix;
+ d->options->setDefaultSuffix(suffix);
}
QString QFileDialog::defaultSuffix() const
{
Q_D(const QFileDialog);
- return d->defaultSuffix;
+ return d->options->defaultSuffix();
}
/*!
@@ -1587,42 +1635,46 @@ QFileIconProvider *QFileDialog::iconProvider() const
return d->model->iconProvider();
}
-/*!
- Sets the \a text shown in the filedialog in the specified \a label.
-*/
-void QFileDialog::setLabelText(DialogLabel label, const QString &text)
+void QFileDialogPrivate::setLabelTextControl(QFileDialog::DialogLabel label, const QString &text)
{
- Q_D(QFileDialog);
- QPushButton *button;
switch (label) {
- case LookIn:
- d->qFileDialogUi->lookInLabel->setText(text);
+ case QFileDialog::LookIn:
+ qFileDialogUi->lookInLabel->setText(text);
break;
- case FileName:
- d->qFileDialogUi->fileNameLabel->setText(text);
- d->fileNameLabelExplicitlySat = true;
+ case QFileDialog::FileName:
+ qFileDialogUi->fileNameLabel->setText(text);
break;
- case FileType:
- d->qFileDialogUi->fileTypeLabel->setText(text);
+ case QFileDialog::FileType:
+ qFileDialogUi->fileTypeLabel->setText(text);
break;
- case Accept:
- d->acceptLabel = text;
- if (acceptMode() == AcceptOpen)
- button = d->qFileDialogUi->buttonBox->button(QDialogButtonBox::Open);
- else
- button = d->qFileDialogUi->buttonBox->button(QDialogButtonBox::Save);
- if (button)
- button->setText(text);
+ case QFileDialog::Accept:
+ if (q_func()->acceptMode() == QFileDialog::AcceptOpen) {
+ if (QPushButton *button = qFileDialogUi->buttonBox->button(QDialogButtonBox::Open))
+ button->setText(text);
+ } else {
+ if (QPushButton *button = qFileDialogUi->buttonBox->button(QDialogButtonBox::Save))
+ button->setText(text);
+ }
break;
- case Reject:
- button = d->qFileDialogUi->buttonBox->button(QDialogButtonBox::Cancel);
- if (button)
+ case QFileDialog::Reject:
+ if (QPushButton *button = qFileDialogUi->buttonBox->button(QDialogButtonBox::Cancel))
button->setText(text);
break;
}
}
/*!
+ Sets the \a text shown in the filedialog in the specified \a label.
+*/
+
+void QFileDialog::setLabelText(DialogLabel label, const QString &text)
+{
+ Q_D(QFileDialog);
+ d->options->setLabelText(static_cast<QFileDialogOptions::DialogLabel>(label), text);
+ d->setLabelTextControl(label, text);
+}
+
+/*!
Returns the text shown in the filedialog in the specified \a label.
*/
QString QFileDialog::labelText(DialogLabel label) const
@@ -2136,7 +2188,7 @@ void QFileDialog::accept()
return;
}
- switch (d->fileMode) {
+ switch (fileMode()) {
case DirectoryOnly:
case Directory: {
QString fn = files.first();
@@ -2235,7 +2287,7 @@ void QFileDialogPrivate::init(const QString &directory, const QString &nameFilte
createWidgets();
createMenuActions();
retranslateStrings();
- q->setFileMode(fileMode);
+ q->setFileMode(QFileDialog::AnyFile);
#ifndef QT_NO_SETTINGS
QSettings settings(QSettings::UserScope, QLatin1String("Trolltech"));
@@ -2271,6 +2323,7 @@ void QFileDialogPrivate::createWidgets()
{
Q_Q(QFileDialog);
model = new QFileSystemModel(q);
+ options->setFilter(model->filter());
model->setObjectName(QLatin1String("qt_filesystem_model"));
if (QPlatformFileDialogHelper *helper = platformFileDialogHelper())
model->setNameFilterDisables(helper->defaultNameFilterDisables());
@@ -2849,10 +2902,11 @@ void QFileDialogPrivate::_q_autoCompleteFileName(const QString &text)
void QFileDialogPrivate::_q_updateOkButton()
{
Q_Q(QFileDialog);
- QPushButton *button = qFileDialogUi->buttonBox->button((acceptMode == QFileDialog::AcceptOpen)
+ QPushButton *button = qFileDialogUi->buttonBox->button((q->acceptMode() == QFileDialog::AcceptOpen)
? QDialogButtonBox::Open : QDialogButtonBox::Save);
if (!button)
return;
+ const QFileDialog::FileMode fileMode = q->fileMode();
bool enableButton = true;
bool isOpenDirectory = false;
@@ -2862,8 +2916,7 @@ void QFileDialogPrivate::_q_updateOkButton()
if (lineEditText.startsWith(QLatin1String("//")) || lineEditText.startsWith(QLatin1Char('\\'))) {
button->setEnabled(true);
- if (acceptMode == QFileDialog::AcceptSave)
- button->setText(acceptLabel);
+ updateOkButtonText();
return;
}
@@ -2937,8 +2990,7 @@ void QFileDialogPrivate::_q_updateOkButton()
}
button->setEnabled(enableButton);
- if (acceptMode == QFileDialog::AcceptSave)
- button->setText(isOpenDirectory ? QFileDialog::tr("&Open") : acceptLabel);
+ updateOkButtonText(isOpenDirectory);
}
/*!
@@ -2963,6 +3015,7 @@ void QFileDialogPrivate::_q_enterDirectory(const QModelIndex &index)
QModelIndex sourceIndex = index.model() == proxyModel ? mapToSource(index) : index;
QString path = sourceIndex.data(QFileSystemModel::FilePathRole).toString();
if (path.isEmpty() || model->isDir(sourceIndex)) {
+ const QFileDialog::FileMode fileMode = q->fileMode();
q->setDirectory(path);
emit q->directoryEntered(path);
if (fileMode == QFileDialog::Directory
@@ -3031,14 +3084,16 @@ QStringList QFileDialogPrivate::qt_clean_filter_list(const QString &filter)
*/
void QFileDialogPrivate::_q_useNameFilter(int index)
{
+ QStringList nameFilters = options->nameFilters();
if (index == nameFilters.size()) {
QAbstractItemModel *comboModel = qFileDialogUi->fileTypeCombo->model();
nameFilters.append(comboModel->index(comboModel->rowCount() - 1, 0).data().toString());
+ options->setNameFilters(nameFilters);
}
QString nameFilter = nameFilters.at(index);
QStringList newNameFilters = qt_clean_filter_list(nameFilter);
- if (acceptMode == QFileDialog::AcceptSave) {
+ if (q_func()->acceptMode() == QFileDialog::AcceptSave) {
QString newNameFilterExtension;
if (newNameFilters.count() > 0)
newNameFilterExtension = QFileInfo(newNameFilters.at(0)).suffix();
@@ -3065,6 +3120,7 @@ void QFileDialogPrivate::_q_useNameFilter(int index)
*/
void QFileDialogPrivate::_q_selectionChanged()
{
+ const QFileDialog::FileMode fileMode = q_func()->fileMode();
QModelIndexList indexes = qFileDialogUi->listView->selectionModel()->selectedRows();
bool stripDirs = (fileMode != QFileDialog::DirectoryOnly && fileMode != QFileDialog::Directory);
@@ -3120,18 +3176,13 @@ void QFileDialogPrivate::_q_rowsInserted(const QModelIndex &parent)
void QFileDialogPrivate::_q_fileRenamed(const QString &path, const QString oldName, const QString newName)
{
+ const QFileDialog::FileMode fileMode = q_func()->fileMode();
if (fileMode == QFileDialog::Directory || fileMode == QFileDialog::DirectoryOnly) {
if (path == rootPath() && lineEdit()->text() == oldName)
lineEdit()->setText(newName);
}
}
-void QFileDialogPrivate::_q_platformRunNativeAppModalPanel()
-{
- if (nativeDialogInUse)
- platformHelper()->_q_platformRunNativeAppModalPanel();
-}
-
/*!
\internal
diff --git a/src/widgets/dialogs/qfiledialog_p.h b/src/widgets/dialogs/qfiledialog_p.h
index 1780fff72c..cdafcf6058 100644
--- a/src/widgets/dialogs/qfiledialog_p.h
+++ b/src/widgets/dialogs/qfiledialog_p.h
@@ -130,6 +130,9 @@ public:
QStringList typedFiles() const;
QStringList addDefaultSuffixToFiles(const QStringList filesToFix) const;
bool removeDirectory(const QString &path);
+ void setLabelTextControl(QFileDialog::DialogLabel label, const QString &text);
+ inline void updateFileNameLabel();
+ void updateOkButtonText(bool saveAsOnFolder = false);
inline QModelIndex mapToSource(const QModelIndex &index) const;
inline QModelIndex mapFromSource(const QModelIndex &index) const;
@@ -170,6 +173,7 @@ public:
QDir::Filters filterForMode(QDir::Filters filters) const
{
+ const QFileDialog::FileMode fileMode = q_func()->fileMode();
if (fileMode == QFileDialog::DirectoryOnly) {
filters |= QDir::Drives | QDir::AllDirs | QDir::Dirs;
filters &= ~QDir::Files;
@@ -224,7 +228,6 @@ public:
void _q_autoCompleteFileName(const QString &);
void _q_rowsInserted(const QModelIndex & parent);
void _q_fileRenamed(const QString &path, const QString oldName, const QString newName);
- void _q_platformRunNativeAppModalPanel();
static QStringList qt_clean_filter_list(const QString &filter);
static const char *qt_file_dialog_filter_reg_exp;
@@ -242,10 +245,6 @@ public:
QFSCompleter *completer;
#endif //QT_NO_FSCOMPLETER
- QFileDialog::FileMode fileMode;
- QFileDialog::AcceptMode acceptMode;
- bool confirmOverwrite;
- QString defaultSuffix;
QString setWindowTitle;
QStringList currentHistory;
@@ -258,8 +257,6 @@ public:
bool useDefaultCaption;
bool defaultFileTypes;
- bool fileNameLabelExplicitlySat;
- QStringList nameFilters;
// setVisible_sys returns true if it ends up showing a native
// dialog. Returning false means that a non-native dialog must be
@@ -273,7 +270,6 @@ public:
void selectFile_sys(const QString &filename);
QStringList selectedFiles_sys() const;
void setFilter_sys();
- void setNameFilters_sys(const QStringList &filters);
void selectNameFilter_sys(const QString &filter);
QString selectedNameFilter_sys() const;
//////////////////////////////////////////////
@@ -286,12 +282,14 @@ public:
QByteArray memberToDisconnectOnClose;
QByteArray signalToDisconnectOnClose;
- QFileDialog::Options opts;
+ QSharedPointer<QFileDialogOptions> options;
~QFileDialogPrivate();
private:
virtual void initHelper(QPlatformDialogHelper *);
+ virtual void helperPrepareShow(QPlatformDialogHelper *);
+ virtual void helperDone(QDialog::DialogCode, QPlatformDialogHelper *);
Q_DISABLE_COPY(QFileDialogPrivate)
};
@@ -348,16 +346,6 @@ private:
QFileDialogPrivate *d_ptr;
};
-void QFileDialogPrivate::initHelper(QPlatformDialogHelper *h)
-{
- QFileDialog *d = q_func();
- QObject::connect(h, SIGNAL(fileSelected(QString)), d, SIGNAL(fileSelected(QString)));
- QObject::connect(h, SIGNAL(filesSelected(QStringList)), d, SIGNAL(filesSelected(QStringList)));
- QObject::connect(h, SIGNAL(currentChanged(QString)), d, SIGNAL(currentChanged(QString)));
- QObject::connect(h, SIGNAL(directoryEntered(QString)), d, SIGNAL(directoryEntered(QString)));
- QObject::connect(h, SIGNAL(filterSelected(QString)), d, SIGNAL(filterSelected(QString)));
-}
-
inline QModelIndex QFileDialogPrivate::mapToSource(const QModelIndex &index) const {
#ifdef QT_NO_PROXYMODEL
return index;
@@ -427,12 +415,6 @@ inline void QFileDialogPrivate::setFilter_sys()
helper->setFilter_sys();
}
-inline void QFileDialogPrivate::setNameFilters_sys(const QStringList &filters)
-{
- if (QPlatformFileDialogHelper *helper = platformFileDialogHelper())
- helper->setNameFilters_sys(filters);
-}
-
inline void QFileDialogPrivate::selectNameFilter_sys(const QString &filter)
{
if (QPlatformFileDialogHelper *helper = platformFileDialogHelper())
diff --git a/src/widgets/dialogs/qfontdialog.cpp b/src/widgets/dialogs/qfontdialog.cpp
index 1935a5aa73..3cc33dad9b 100644
--- a/src/widgets/dialogs/qfontdialog.cpp
+++ b/src/widgets/dialogs/qfontdialog.cpp
@@ -495,6 +495,12 @@ void QFontDialogPrivate::initHelper(QPlatformDialogHelper *h)
QFontDialog *d = q_func();
QObject::connect(h, SIGNAL(currentFontChanged(QFont)), d, SIGNAL(currentFontChanged(QFont)));
QObject::connect(h, SIGNAL(fontSelected(QFont)), d, SIGNAL(fontSelected(QFont)));
+ static_cast<QPlatformFontDialogHelper *>(h)->setOptions(options);
+}
+
+void QFontDialogPrivate::helperPrepareShow(QPlatformDialogHelper *)
+{
+ options->setWindowTitle(q_func()->windowTitle());
}
/*
@@ -888,8 +894,7 @@ QFont QFontDialog::selectedFont() const
void QFontDialog::setOption(FontDialogOption option, bool on)
{
Q_D(QFontDialog);
- if (!(d->opts & option) != !on)
- setOptions(d->opts ^ option);
+ d->options->setOption(static_cast<QFontDialogOptions::FontDialogOption>(option), on);
}
/*!
@@ -901,7 +906,7 @@ void QFontDialog::setOption(FontDialogOption option, bool on)
bool QFontDialog::testOption(FontDialogOption option) const
{
Q_D(const QFontDialog);
- return (d->opts & option) != 0;
+ return d->options->testOption(static_cast<QFontDialogOptions::FontDialogOption>(option));
}
/*!
@@ -921,18 +926,17 @@ void QFontDialog::setOptions(FontDialogOptions options)
{
Q_D(QFontDialog);
- FontDialogOptions changed = (options ^ d->opts);
- if (!changed)
+ if (QFontDialog::options() == options)
return;
- d->opts = options;
+ d->options->setOptions(QFontDialogOptions::FontDialogOptions(int(options)));
d->buttonBox->setVisible(!(options & NoButtons));
}
QFontDialog::FontDialogOptions QFontDialog::options() const
{
Q_D(const QFontDialog);
- return d->opts;
+ return QFontDialog::FontDialogOptions(int(d->options->options()));
}
#ifdef Q_WS_MAC
@@ -1043,7 +1047,7 @@ bool QFontDialogPrivate::canBeNativeDialog()
return true;
if (q->testAttribute(Qt::WA_DontShowOnScreen))
return false;
- if (opts & QFontDialog::DontUseNativeDialog)
+ if (options->options() & QFontDialog::DontUseNativeDialog)
return false;
QLatin1String staticName(QFontDialog::staticMetaObject.className());
diff --git a/src/widgets/dialogs/qfontdialog_p.h b/src/widgets/dialogs/qfontdialog_p.h
index ef4e933624..8762ef2b07 100644
--- a/src/widgets/dialogs/qfontdialog_p.h
+++ b/src/widgets/dialogs/qfontdialog_p.h
@@ -58,6 +58,7 @@
#include "qfontdatabase.h"
#include "qfontdialog.h"
#include "qplatformdialoghelper_qpa.h"
+#include "qsharedpointer.h"
#ifndef QT_NO_FONTDIALOG
@@ -78,7 +79,7 @@ class QFontDialogPrivate : public QDialogPrivate
public:
inline QFontDialogPrivate()
- : writingSystem(QFontDatabase::Any)
+ : writingSystem(QFontDatabase::Any), options(new QFontDialogOptions)
{ }
QPlatformFontDialogHelper *platformFontDialogHelper() const
@@ -138,7 +139,7 @@ public:
int size;
bool smoothScalable;
QFont selectedFont;
- QFontDialog::FontDialogOptions opts;
+ QSharedPointer<QFontDialogOptions> options;
QPointer<QObject> receiverToDisconnectOnClose;
QByteArray memberToDisconnectOnClose;
@@ -163,6 +164,7 @@ public:
private:
virtual void initHelper(QPlatformDialogHelper *);
+ virtual void helperPrepareShow(QPlatformDialogHelper *);
};
#endif // QT_NO_FONTDIALOG
diff --git a/src/widgets/kernel/qplatformdialoghelper_qpa.cpp b/src/widgets/kernel/qplatformdialoghelper_qpa.cpp
index daf864ff30..f2ece1d617 100644
--- a/src/widgets/kernel/qplatformdialoghelper_qpa.cpp
+++ b/src/widgets/kernel/qplatformdialoghelper_qpa.cpp
@@ -42,6 +42,11 @@
#include "qplatformdialoghelper_qpa.h"
#include <QtCore/QVariant>
+#include <QtCore/QSharedData>
+#include <QtCore/QSettings>
+#include <QtCore/QHash>
+#include <QtCore/QUrl>
+#include <QtGui/QColor>
QT_BEGIN_NAMESPACE
@@ -87,4 +92,465 @@ QVariant QPlatformDialogHelper::defaultStyleHint(QPlatformDialogHelper::StyleHi
return QVariant();
}
+void QPlatformDialogHelper::emitLaunchNativeAppModalPanel()
+{
+ emit launchNativeAppModalPanel();
+}
+
+// Font dialog
+
+class QFontDialogOptionsPrivate : public QSharedData
+{
+public:
+ QFontDialogOptionsPrivate() : options(0) {}
+
+ QFontDialogOptions::FontDialogOptions options;
+ QString windowTitle;
+};
+
+QFontDialogOptions::QFontDialogOptions() : d(new QFontDialogOptionsPrivate)
+{
+}
+
+QFontDialogOptions::QFontDialogOptions(const QFontDialogOptions &rhs) : d(rhs.d)
+{
+}
+
+QFontDialogOptions &QFontDialogOptions::operator=(const QFontDialogOptions &rhs)
+{
+ if (this != &rhs)
+ d = rhs.d;
+ return *this;
+}
+
+QFontDialogOptions::~QFontDialogOptions()
+{
+}
+
+QString QFontDialogOptions::windowTitle() const
+{
+ return d->windowTitle;
+}
+
+void QFontDialogOptions::setWindowTitle(const QString &title)
+{
+ d->windowTitle = title;
+}
+
+void QFontDialogOptions::setOption(QFontDialogOptions::FontDialogOption option, bool on)
+{
+ if (!(d->options & option) != !on)
+ setOptions(d->options ^ option);
+}
+
+bool QFontDialogOptions::testOption(QFontDialogOptions::FontDialogOption option) const
+{
+ return d->options & option;
+}
+
+void QFontDialogOptions::setOptions(FontDialogOptions options)
+{
+ if (options != d->options)
+ d->options = options;
+}
+
+QFontDialogOptions::FontDialogOptions QFontDialogOptions::options() const
+{
+ return d->options;
+}
+
+const QSharedPointer<QFontDialogOptions> &QPlatformFontDialogHelper::options() const
+{
+ return m_options;
+}
+
+void QPlatformFontDialogHelper::setOptions(const QSharedPointer<QFontDialogOptions> &options)
+{
+ m_options = options;
+}
+
+// Color dialog
+
+class QColorDialogStaticData
+{
+public:
+ enum { CustomColorCount = 16, StandardColorCount = 6 * 8 };
+
+ QColorDialogStaticData();
+ inline void readSettings();
+ inline void writeSettings() const;
+
+ QRgb customRgb[CustomColorCount];
+ QRgb standardRgb[StandardColorCount];
+ bool customSet;
+};
+
+QColorDialogStaticData::QColorDialogStaticData() : customSet(false)
+{
+ int i = 0;
+ for (int g = 0; g < 4; ++g)
+ for (int r = 0; r < 4; ++r)
+ for (int b = 0; b < 3; ++b)
+ standardRgb[i++] = qRgb(r * 255 / 3, g * 255 / 3, b * 255 / 2);
+ qFill(customRgb, customRgb + CustomColorCount, 0xffffffff);
+ readSettings();
+}
+
+void QColorDialogStaticData::readSettings()
+{
+#ifndef QT_NO_SETTINGS
+ const QSettings settings(QSettings::UserScope, QStringLiteral("Trolltech"));
+ for (int i = 0; i < int(CustomColorCount); ++i) {
+ const QVariant v = settings.value(QStringLiteral("Qt/customColors/") + QString::number(i));
+ if (v.isValid())
+ customRgb[i] = v.toUInt();
+ }
+#endif
+}
+
+void QColorDialogStaticData::writeSettings() const
+{
+#ifndef QT_NO_SETTINGS
+ if (!customSet) {
+ QSettings settings(QSettings::UserScope, QStringLiteral("Trolltech"));
+ for (int i = 0; i < int(CustomColorCount); ++i)
+ settings.setValue(QStringLiteral("Qt/customColors/") + QString::number(i), customRgb[i]);
+ }
+#endif
+}
+
+Q_GLOBAL_STATIC(QColorDialogStaticData, qColorDialogStaticData)
+
+class QColorDialogOptionsPrivate : public QSharedData
+{
+public:
+ QColorDialogOptionsPrivate() : options(0) {}
+ // Write out settings around destruction of dialogs
+ ~QColorDialogOptionsPrivate() { qColorDialogStaticData()->writeSettings(); }
+
+ QColorDialogOptions::ColorDialogOptions options;
+ QString windowTitle;
+};
+
+QColorDialogOptions::QColorDialogOptions() : d(new QColorDialogOptionsPrivate)
+{
+}
+
+QColorDialogOptions::QColorDialogOptions(const QColorDialogOptions &rhs) : d(rhs.d)
+{
+}
+
+QColorDialogOptions &QColorDialogOptions::operator=(const QColorDialogOptions &rhs)
+{
+ if (this != &rhs)
+ d = rhs.d;
+ return *this;
+}
+
+QColorDialogOptions::~QColorDialogOptions()
+{
+}
+
+QString QColorDialogOptions::windowTitle() const
+{
+ return d->windowTitle;
+}
+
+void QColorDialogOptions::setWindowTitle(const QString &title)
+{
+ d->windowTitle = title;
+}
+
+void QColorDialogOptions::setOption(QColorDialogOptions::ColorDialogOption option, bool on)
+{
+ if (!(d->options & option) != !on)
+ setOptions(d->options ^ option);
+}
+
+bool QColorDialogOptions::testOption(QColorDialogOptions::ColorDialogOption option) const
+{
+ return d->options & option;
+}
+
+void QColorDialogOptions::setOptions(ColorDialogOptions options)
+{
+ if (options != d->options)
+ d->options = options;
+}
+
+QColorDialogOptions::ColorDialogOptions QColorDialogOptions::options() const
+{
+ return d->options;
+}
+
+int QColorDialogOptions::customColorCount()
+{
+ return QColorDialogStaticData::CustomColorCount;
+}
+
+QRgb QColorDialogOptions::customColor(int index)
+{
+ if (uint(index) >= uint(QColorDialogStaticData::CustomColorCount))
+ return qRgb(255, 255, 255);
+ return qColorDialogStaticData()->customRgb[index];
+}
+
+QRgb *QColorDialogOptions::customColors()
+{
+ return qColorDialogStaticData()->customRgb;
+}
+
+void QColorDialogOptions::setCustomColor(int index, QRgb color)
+{
+ if (uint(index) >= uint(QColorDialogStaticData::CustomColorCount))
+ return;
+ qColorDialogStaticData()->customSet;
+ qColorDialogStaticData()->customRgb[index] = color;
+}
+
+QRgb *QColorDialogOptions::standardColors()
+{
+ return qColorDialogStaticData()->standardRgb;
+}
+
+QRgb QColorDialogOptions::standardColor(int index)
+{
+ if (uint(index) >= uint(QColorDialogStaticData::StandardColorCount))
+ return qRgb(255, 255, 255);
+ return qColorDialogStaticData()->standardRgb[index];
+}
+
+void QColorDialogOptions::setStandardColor(int index, QRgb color)
+{
+ if (uint(index) >= uint(QColorDialogStaticData::StandardColorCount))
+ return;
+ qColorDialogStaticData()->standardRgb[index] = color;
+}
+
+const QSharedPointer<QColorDialogOptions> &QPlatformColorDialogHelper::options() const
+{
+ return m_options;
+}
+
+void QPlatformColorDialogHelper::setOptions(const QSharedPointer<QColorDialogOptions> &options)
+{
+ m_options = options;
+}
+
+// File dialog
+
+class QFileDialogOptionsPrivate : public QSharedData
+{
+public:
+ QFileDialogOptionsPrivate() : options(0),
+ viewMode(QFileDialogOptions::Detail),
+ fileMode(QFileDialogOptions::AnyFile),
+ acceptMode(QFileDialogOptions::AcceptOpen),
+ filters(QDir::AllEntries | QDir::NoDotAndDotDot | QDir::AllDirs)
+ {}
+
+ QFileDialogOptions::FileDialogOptions options;
+ QString windowTitle;
+
+ QFileDialogOptions::ViewMode viewMode;
+ QFileDialogOptions::FileMode fileMode;
+ QFileDialogOptions::AcceptMode acceptMode;
+ QString labels[QFileDialogOptions::DialogLabelCount];
+ QDir::Filters filters;
+ QList<QUrl> sidebarUrls;
+ QStringList nameFilters;
+ QString defaultSuffix;
+ QStringList history;
+ QString initialDirectory;
+ QString initiallySelectedNameFilter;
+ QStringList initiallySelectedFiles;
+};
+
+QFileDialogOptions::QFileDialogOptions() : d(new QFileDialogOptionsPrivate)
+{
+}
+
+QFileDialogOptions::QFileDialogOptions(const QFileDialogOptions &rhs) : d(rhs.d)
+{
+}
+
+QFileDialogOptions &QFileDialogOptions::operator=(const QFileDialogOptions &rhs)
+{
+ if (this != &rhs)
+ d = rhs.d;
+ return *this;
+}
+
+QFileDialogOptions::~QFileDialogOptions()
+{
+}
+
+QString QFileDialogOptions::windowTitle() const
+{
+ return d->windowTitle;
+}
+
+void QFileDialogOptions::setWindowTitle(const QString &title)
+{
+ d->windowTitle = title;
+}
+
+void QFileDialogOptions::setOption(QFileDialogOptions::FileDialogOption option, bool on)
+{
+ if (!(d->options & option) != !on)
+ setOptions(d->options ^ option);
+}
+
+bool QFileDialogOptions::testOption(QFileDialogOptions::FileDialogOption option) const
+{
+ return d->options & option;
+}
+
+void QFileDialogOptions::setOptions(FileDialogOptions options)
+{
+ if (options != d->options)
+ d->options = options;
+}
+
+QFileDialogOptions::FileDialogOptions QFileDialogOptions::options() const
+{
+ return d->options;
+}
+
+QDir::Filters QFileDialogOptions::filter() const
+{
+ return d->filters;
+}
+
+void QFileDialogOptions::setFilter(QDir::Filters filters)
+{
+ d->filters = filters;
+}
+
+void QFileDialogOptions::setViewMode(QFileDialogOptions::ViewMode mode)
+{
+ d->viewMode = mode;
+}
+
+QFileDialogOptions::ViewMode QFileDialogOptions::viewMode() const
+{
+ return d->viewMode;
+}
+
+void QFileDialogOptions::setFileMode(QFileDialogOptions::FileMode mode)
+{
+ d->fileMode = mode;
+}
+
+QFileDialogOptions::FileMode QFileDialogOptions::fileMode() const
+{
+ return d->fileMode;
+}
+
+void QFileDialogOptions::setAcceptMode(QFileDialogOptions::AcceptMode mode)
+{
+ d->acceptMode = mode;
+}
+
+QFileDialogOptions::AcceptMode QFileDialogOptions::acceptMode() const
+{
+ return d->acceptMode;
+}
+
+void QFileDialogOptions::setSidebarUrls(const QList<QUrl> &urls)
+{
+ d->sidebarUrls = urls;
+}
+
+QList<QUrl> QFileDialogOptions::sidebarUrls() const
+{
+ return d->sidebarUrls;
+}
+
+void QFileDialogOptions::setNameFilters(const QStringList &filters)
+{
+ d->nameFilters = filters;
+}
+
+QStringList QFileDialogOptions::nameFilters() const
+{
+ return d->nameFilters;
+}
+
+void QFileDialogOptions::setDefaultSuffix(const QString &suffix)
+{
+ d->defaultSuffix = suffix;
+}
+
+QString QFileDialogOptions::defaultSuffix() const
+{
+ return d->defaultSuffix;
+}
+
+void QFileDialogOptions::setHistory(const QStringList &paths)
+{
+ d->history = paths;
+}
+
+QStringList QFileDialogOptions::history() const
+{
+ return d->history;
+}
+
+void QFileDialogOptions::setLabelText(QFileDialogOptions::DialogLabel label, const QString &text)
+{
+ if (label >= 0 && label < DialogLabelCount)
+ d->labels[label] = text;
+}
+
+QString QFileDialogOptions::labelText(QFileDialogOptions::DialogLabel label) const
+{
+ return (label >= 0 && label < DialogLabelCount) ? d->labels[label] : QString();
+}
+
+bool QFileDialogOptions::isLabelExplicitlySet(DialogLabel label)
+{
+ return label >= 0 && label < DialogLabelCount && !d->labels[label].isEmpty();
+}
+
+QString QFileDialogOptions::initialDirectory() const
+{
+ return d->initialDirectory;
+}
+
+void QFileDialogOptions::setInitialDirectory(const QString &directory)
+{
+ d->initialDirectory = directory;
+}
+
+QString QFileDialogOptions::initiallySelectedNameFilter() const
+{
+ return d->initiallySelectedNameFilter;
+}
+
+void QFileDialogOptions::setInitiallySelectedNameFilter(const QString &filter)
+{
+ d->initiallySelectedNameFilter = filter;
+}
+
+QStringList QFileDialogOptions::initiallySelectedFiles() const
+{
+ return d->initiallySelectedFiles;
+}
+
+void QFileDialogOptions::setInitiallySelectedFiles(const QStringList &files)
+{
+ d->initiallySelectedFiles = files;
+}
+
+const QSharedPointer<QFileDialogOptions> &QPlatformFileDialogHelper::options() const
+{
+ return m_options;
+}
+
+void QPlatformFileDialogHelper::setOptions(const QSharedPointer<QFileDialogOptions> &options)
+{
+ m_options = options;
+}
+
QT_END_NAMESPACE
diff --git a/src/widgets/kernel/qplatformdialoghelper_qpa.h b/src/widgets/kernel/qplatformdialoghelper_qpa.h
index 970de611bc..e607d3e810 100644
--- a/src/widgets/kernel/qplatformdialoghelper_qpa.h
+++ b/src/widgets/kernel/qplatformdialoghelper_qpa.h
@@ -42,8 +42,13 @@
#ifndef QPLATFORMDIALOGHELPER_H
#define QPLATFORMDIALOGHELPER_H
-#include <qglobal.h>
-#include <qobject.h>
+#include <QtCore/QtGlobal>
+#include <QtCore/QObject>
+#include <QtCore/QList>
+#include <QtCore/QSharedDataPointer>
+#include <QtCore/QSharedPointer>
+#include <QtCore/QDir>
+#include <QtGui/QRgb>
QT_BEGIN_HEADER
@@ -56,6 +61,10 @@ class QColor;
class QFont;
class QWindow;
class QVariant;
+class QUrl;
+class QColorDialogOptionsPrivate;
+class QFontDialogOptionsPrivate;
+class QFileDialogOptionsPrivate;
class Q_WIDGETS_EXPORT QPlatformDialogHelper : public QObject
{
@@ -65,6 +74,11 @@ public:
SnapToDefaultButton
};
enum DialogCode { Rejected, Accepted };
+ enum ShowFlag {
+ ShowModal = 0x00000001
+ };
+
+ Q_DECLARE_FLAGS(ShowFlags, ShowFlag)
QPlatformDialogHelper();
virtual ~QPlatformDialogHelper();
@@ -75,24 +89,104 @@ public:
virtual void _q_platformRunNativeAppModalPanel() = 0;
virtual void deleteNativeDialog_sys() = 0;
- virtual bool show_sys(QWindow *parent) = 0;
+ virtual bool show_sys(ShowFlags showFlags,
+ Qt::WindowFlags windowFlags,
+ QWindow *parent) = 0;
virtual void hide_sys() = 0;
virtual DialogCode dialogResultCode_sys() = 0;
static QVariant defaultStyleHint(QPlatformDialogHelper::StyleHint hint);
+
+Q_SIGNALS:
+ void launchNativeAppModalPanel();
+ void accept();
+ void reject();
+
+protected Q_SLOTS:
+ void emitLaunchNativeAppModalPanel();
+};
+
+class Q_WIDGETS_EXPORT QColorDialogOptions
+{
+public:
+ enum ColorDialogOption {
+ ShowAlphaChannel = 0x00000001,
+ NoButtons = 0x00000002,
+ DontUseNativeDialog = 0x00000004
+ };
+
+ Q_DECLARE_FLAGS(ColorDialogOptions, ColorDialogOption)
+
+ QColorDialogOptions();
+ QColorDialogOptions(const QColorDialogOptions &rhs);
+ QColorDialogOptions &operator=(const QColorDialogOptions &rhs);
+ ~QColorDialogOptions();
+
+ QString windowTitle() const;
+ void setWindowTitle(const QString &);
+
+ void setOption(ColorDialogOption option, bool on = true);
+ bool testOption(ColorDialogOption option) const;
+ void setOptions(ColorDialogOptions options);
+ ColorDialogOptions options() const;
+
+ static int customColorCount();
+ static QRgb customColor(int index);
+ static QRgb *customColors();
+ static void setCustomColor(int index, QRgb color);
+
+ static QRgb *standardColors();
+ static QRgb standardColor(int index);
+ static void setStandardColor(int index, QRgb color);
+
+private:
+ QSharedDataPointer<QColorDialogOptionsPrivate> d;
};
class Q_WIDGETS_EXPORT QPlatformColorDialogHelper : public QPlatformDialogHelper
{
Q_OBJECT
public:
+ const QSharedPointer<QColorDialogOptions> &options() const;
+ void setOptions(const QSharedPointer<QColorDialogOptions> &options);
+
virtual void setCurrentColor_sys(const QColor &) = 0;
virtual QColor currentColor_sys() const = 0;
Q_SIGNALS:
void currentColorChanged(const QColor &color);
void colorSelected(const QColor &color);
+
+private:
+ QSharedPointer<QColorDialogOptions> m_options;
+};
+
+class Q_WIDGETS_EXPORT QFontDialogOptions
+{
+public:
+ enum FontDialogOption {
+ NoButtons = 0x00000001,
+ DontUseNativeDialog = 0x00000002
+ };
+
+ Q_DECLARE_FLAGS(FontDialogOptions, FontDialogOption)
+
+ QFontDialogOptions();
+ QFontDialogOptions(const QFontDialogOptions &rhs);
+ QFontDialogOptions &operator=(const QFontDialogOptions &rhs);
+ ~QFontDialogOptions();
+
+ QString windowTitle() const;
+ void setWindowTitle(const QString &);
+
+ void setOption(FontDialogOption option, bool on = true);
+ bool testOption(FontDialogOption option) const;
+ void setOptions(FontDialogOptions options);
+ FontDialogOptions options() const;
+
+private:
+ QSharedDataPointer<QFontDialogOptionsPrivate> d;
};
class Q_WIDGETS_EXPORT QPlatformFontDialogHelper : public QPlatformDialogHelper
@@ -102,9 +196,89 @@ public:
virtual void setCurrentFont_sys(const QFont &) = 0;
virtual QFont currentFont_sys() const = 0;
+ const QSharedPointer<QFontDialogOptions> &options() const;
+ void setOptions(const QSharedPointer<QFontDialogOptions> &options);
+
Q_SIGNALS:
void currentFontChanged(const QFont &font);
void fontSelected(const QFont &font);
+
+private:
+ QSharedPointer<QFontDialogOptions> m_options;
+};
+
+class Q_WIDGETS_EXPORT QFileDialogOptions
+{
+public:
+ enum ViewMode { Detail, List };
+ enum FileMode { AnyFile, ExistingFile, Directory, ExistingFiles, DirectoryOnly };
+ enum AcceptMode { AcceptOpen, AcceptSave };
+ enum DialogLabel { LookIn, FileName, FileType, Accept, Reject, DialogLabelCount };
+
+ enum FileDialogOption
+ {
+ ShowDirsOnly = 0x00000001,
+ DontResolveSymlinks = 0x00000002,
+ DontConfirmOverwrite = 0x00000004,
+ DontUseSheet = 0x00000008,
+ DontUseNativeDialog = 0x00000010,
+ ReadOnly = 0x00000020,
+ HideNameFilterDetails = 0x00000040
+ };
+ Q_DECLARE_FLAGS(FileDialogOptions, FileDialogOption)
+
+ QFileDialogOptions();
+ QFileDialogOptions(const QFileDialogOptions &rhs);
+ QFileDialogOptions &operator=(const QFileDialogOptions &rhs);
+ ~QFileDialogOptions();
+
+ QString windowTitle() const;
+ void setWindowTitle(const QString &);
+
+ void setOption(FileDialogOption option, bool on = true);
+ bool testOption(FileDialogOption option) const;
+ void setOptions(FileDialogOptions options);
+ FileDialogOptions options() const;
+
+ QDir::Filters filter() const;
+ void setFilter(QDir::Filters filters);
+
+ void setViewMode(ViewMode mode);
+ ViewMode viewMode() const;
+
+ void setFileMode(FileMode mode);
+ FileMode fileMode() const;
+
+ void setAcceptMode(AcceptMode mode);
+ AcceptMode acceptMode() const;
+
+ void setSidebarUrls(const QList<QUrl> &urls);
+ QList<QUrl> sidebarUrls() const;
+
+ void setNameFilters(const QStringList &filters);
+ QStringList nameFilters() const;
+
+ void setDefaultSuffix(const QString &suffix);
+ QString defaultSuffix() const;
+
+ void setHistory(const QStringList &paths);
+ QStringList history() const;
+
+ void setLabelText(DialogLabel label, const QString &text);
+ QString labelText(DialogLabel label) const;
+ bool isLabelExplicitlySet(DialogLabel label);
+
+ QString initialDirectory() const;
+ void setInitialDirectory(const QString &);
+
+ QString initiallySelectedNameFilter() const;
+ void setInitiallySelectedNameFilter(const QString &);
+
+ QStringList initiallySelectedFiles() const;
+ void setInitiallySelectedFiles(const QStringList &);
+
+private:
+ QSharedDataPointer<QFileDialogOptionsPrivate> d;
};
class Q_WIDGETS_EXPORT QPlatformFileDialogHelper : public QPlatformDialogHelper
@@ -117,16 +291,21 @@ public:
virtual void selectFile_sys(const QString &filename) = 0;
virtual QStringList selectedFiles_sys() const = 0;
virtual void setFilter_sys() = 0;
- virtual void setNameFilters_sys(const QStringList &filters) = 0;
virtual void selectNameFilter_sys(const QString &filter) = 0;
virtual QString selectedNameFilter_sys() const = 0;
+ const QSharedPointer<QFileDialogOptions> &options() const;
+ void setOptions(const QSharedPointer<QFileDialogOptions> &options);
+
Q_SIGNALS:
void fileSelected(const QString &file);
void filesSelected(const QStringList &files);
void currentChanged(const QString &path);
void directoryEntered(const QString &directory);
void filterSelected(const QString &filter);
+
+private:
+ QSharedPointer<QFileDialogOptions> m_options;
};
QT_END_NAMESPACE