summaryrefslogtreecommitdiffstats
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
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>
-rw-r--r--src/plugins/platforms/cocoa/qcocoafiledialoghelper.h5
-rw-r--r--src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm156
-rw-r--r--src/plugins/platforms/windows/qwindowsdialoghelpers.cpp140
-rw-r--r--src/plugins/platforms/windows/qwindowsdialoghelpers.h7
-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
15 files changed, 1042 insertions, 360 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoafiledialoghelper.h b/src/plugins/platforms/cocoa/qcocoafiledialoghelper.h
index c5c40c69a1..4204de22c9 100644
--- a/src/plugins/platforms/cocoa/qcocoafiledialoghelper.h
+++ b/src/plugins/platforms/cocoa/qcocoafiledialoghelper.h
@@ -62,7 +62,7 @@ public:
bool defaultNameFilterDisables() const;
void deleteNativeDialog_sys();
- bool show_sys(QWindow *parent);
+ bool show_sys(ShowFlags flags, Qt::WindowFlags windowFlags, QWindow *parent);
void hide_sys();
QPlatformFileDialogHelper::DialogCode dialogResultCode_sys();
void setDirectory_sys(const QString &directory);
@@ -70,12 +70,11 @@ 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;
public:
- bool showCocoaFilePanel();
+ bool showCocoaFilePanel(QWindow *parent);
bool hideCocoaFilePanel();
void createNSOpenSavePanelDelegate();
diff --git a/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm b/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm
index 820a5dcbd0..e7f6b8b54f 100644
--- a/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm
+++ b/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm
@@ -72,8 +72,11 @@ QT_FORWARD_DECLARE_CLASS(QStringList)
QT_FORWARD_DECLARE_CLASS(QWidget)
QT_FORWARD_DECLARE_CLASS(QAction)
QT_FORWARD_DECLARE_CLASS(QFileInfo)
+QT_FORWARD_DECLARE_CLASS(QWindow)
QT_USE_NAMESPACE
+typedef QSharedPointer<QFileDialogOptions> SharedPointerFileDialogOptions;
+
@class QT_MANGLE_NAMESPACE(QNSOpenSavePanelDelegate);
@interface QT_MANGLE_NAMESPACE(QNSOpenSavePanelDelegate)
@@ -92,14 +95,10 @@ QT_USE_NAMESPACE
QFileDialog *mFileDialog;
QCocoaFileDialogHelper *mHelper;
NSString *mCurrentDir;
- bool mConfirmOverwrite;
- int mReturnCode;
- QT_PREPEND_NAMESPACE(QFileDialog::AcceptMode) mAcceptMode;
- QT_PREPEND_NAMESPACE(QDir::Filters) *mQDirFilter;
- QT_PREPEND_NAMESPACE(QFileDialog::FileMode) mFileMode;
- QT_PREPEND_NAMESPACE(QFileDialog::Options) *mFileOptions;
+ int mReturnCode;
+ SharedPointerFileDialogOptions mOptions;
QString *mLastFilterCheckPath;
QString *mCurrentSelection;
QStringList *mQDirFilterEntryList;
@@ -112,7 +111,7 @@ QT_USE_NAMESPACE
- (void)filterChanged:(id)sender;
- (void)showModelessPanel;
- (BOOL)runApplicationModalPanel;
-- (void)showWindowModalSheet:(QWidget *)docWidget;
+- (void)showWindowModalSheet:(QWindow *)docWidget;
- (void)updateProperties;
- (QStringList)acceptableExtensionsForSave;
- (QString)removeExtensions:(const QString &)filter;
@@ -125,21 +124,16 @@ QT_USE_NAMESPACE
@implementation QT_MANGLE_NAMESPACE(QNSOpenSavePanelDelegate)
-- (id)initWithAcceptMode:(QT_PREPEND_NAMESPACE(QFileDialog::AcceptMode))acceptMode
- title:(const QString &)title
- hideNameFilterDetails:(bool)hideNameFilterDetails
- qDirFilter:(QT_PREPEND_NAMESPACE(QDir::Filters))qDirFilter
- fileOptions:(QT_PREPEND_NAMESPACE(QFileDialog::Options))fileOptions
- fileMode:(QT_PREPEND_NAMESPACE(QFileDialog::FileMode))fileMode
- selectFile:(const QString &)selectFile
- confirmOverwrite:(bool)confirm
+- (id)initWithAcceptMode:
+ (const QString &)selectFile
fileDialog:(QFileDialog *)fileDialog
+ options:(SharedPointerFileDialogOptions)options
helper:(QCocoaFileDialogHelper *)helper
{
self = [super init];
mFileDialog = fileDialog;
- mAcceptMode = acceptMode;
- if (mAcceptMode == QT_PREPEND_NAMESPACE(QFileDialog::AcceptOpen)){
+ mOptions = options;
+ if (mOptions->acceptMode() == QT_PREPEND_NAMESPACE(QFileDialogOptions::AcceptOpen)){
mOpenPanel = [NSOpenPanel openPanel];
mSavePanel = mOpenPanel;
} else {
@@ -149,15 +143,11 @@ QT_USE_NAMESPACE
[mSavePanel setLevel:NSModalPanelWindowLevel];
[mSavePanel setDelegate:self];
- mQDirFilter = new QT_PREPEND_NAMESPACE(QDir::Filters)(qDirFilter);
- mFileOptions = new QT_PREPEND_NAMESPACE(QFileDialog::Options)(fileOptions);
- mFileMode = fileMode;
- mConfirmOverwrite = confirm;
mReturnCode = -1;
mHelper = helper;
mLastFilterCheckPath = new QString;
mQDirFilterEntryList = new QStringList;
- mNameFilterDropDownList = new QStringList(mFileDialog->nameFilters());
+ mNameFilterDropDownList = new QStringList(mOptions->nameFilters());
QString selectedVisualNameFilter = mFileDialog->selectedNameFilter();
mSelectedNameFilter = new QStringList([self findStrippedFilterWithVisualFilterName:selectedVisualNameFilter]);
@@ -170,16 +160,17 @@ QT_USE_NAMESPACE
mCurrentSelection = new QString(sel.absoluteFilePath());
}
- [mSavePanel setTitle:qt_mac_QStringToNSString(title)];
- [self createPopUpButton:selectedVisualNameFilter hideDetails:hideNameFilterDetails];
+ [mSavePanel setTitle:qt_mac_QStringToNSString(options->windowTitle())];
+ [self createPopUpButton:selectedVisualNameFilter hideDetails:options->testOption(QFileDialogOptions::HideNameFilterDetails)];
[self createTextField];
[self createAccessory];
[mSavePanel setAccessoryView:mNameFilterDropDownList->size() > 1 ? mAccessoryView : nil];
- [mSavePanel setPrompt:[self strip:mFileDialog->labelText(QFileDialog::Accept)]];
- if (false) // ### fixme mPriv->fileNameLabelExplicitlySat)
- [mSavePanel setNameFieldLabel:[self strip:mFileDialog->labelText(QFileDialog::FileName)]];
+ if (mOptions->isLabelExplicitlySet(QFileDialogOptions::Accept))
+ [mSavePanel setPrompt:[self strip:options->labelText(QFileDialogOptions::Accept)]];
+ if (mOptions->isLabelExplicitlySet(QFileDialogOptions::FileName))
+ [mSavePanel setNameFieldLabel:[self strip:options->labelText(QFileDialogOptions::FileName)]];
[self updateProperties];
[mSavePanel retain];
@@ -188,8 +179,6 @@ QT_USE_NAMESPACE
- (void)dealloc
{
- delete mQDirFilter;
- delete mFileOptions;
delete mLastFilterCheckPath;
delete mQDirFilterEntryList;
delete mNameFilterDropDownList;
@@ -225,7 +214,7 @@ QT_USE_NAMESPACE
QFileInfo info(*mCurrentSelection);
NSString *filename = QT_PREPEND_NAMESPACE(qt_mac_QStringToNSString)(info.fileName());
NSString *filepath = QT_PREPEND_NAMESPACE(qt_mac_QStringToNSString)(info.filePath());
- bool selectable = (mAcceptMode == QFileDialog::AcceptSave)
+ bool selectable = (mOptions->acceptMode() == QFileDialogOptions::AcceptSave)
|| [self panel:nil shouldShowFilename:filepath];
[mOpenPanel
beginForDirectory:mCurrentDir
@@ -242,7 +231,7 @@ QT_USE_NAMESPACE
QFileInfo info(*mCurrentSelection);
NSString *filename = QT_PREPEND_NAMESPACE(qt_mac_QStringToNSString)(info.fileName());
NSString *filepath = QT_PREPEND_NAMESPACE(qt_mac_QStringToNSString)(info.filePath());
- bool selectable = (mAcceptMode == QFileDialog::AcceptSave)
+ bool selectable = (mOptions->acceptMode() == QFileDialogOptions::AcceptSave)
|| [self panel:nil shouldShowFilename:filepath];
mReturnCode = [mSavePanel
runModalForDirectory:mCurrentDir
@@ -257,13 +246,13 @@ QT_USE_NAMESPACE
return (mReturnCode == NSOKButton) ? QT_PREPEND_NAMESPACE(QPlatformDialogHelper::Accepted) : QT_PREPEND_NAMESPACE(QPlatformDialogHelper::Rejected);
}
-- (void)showWindowModalSheet:(QWidget *)docWidget
+- (void)showWindowModalSheet:(QWindow *)docWidget
{
Q_UNUSED(docWidget);
QFileInfo info(*mCurrentSelection);
NSString *filename = QT_PREPEND_NAMESPACE(qt_mac_QStringToNSString)(info.fileName());
NSString *filepath = QT_PREPEND_NAMESPACE(qt_mac_QStringToNSString)(info.filePath());
- bool selectable = (mAcceptMode == QFileDialog::AcceptSave)
+ bool selectable = (mOptions->acceptMode() == QFileDialogOptions::AcceptSave)
|| [self panel:nil shouldShowFilename:filepath];
[mSavePanel
beginSheetForDirectory:mCurrentDir
@@ -295,7 +284,7 @@ QT_USE_NAMESPACE
QString path = info.absolutePath();
if (path != *mLastFilterCheckPath){
*mLastFilterCheckPath = path;
- *mQDirFilterEntryList = info.dir().entryList(*mQDirFilter);
+ *mQDirFilterEntryList = info.dir().entryList(mOptions->filter());
}
// Check if the QDir filter accepts the file:
if (!mQDirFilterEntryList->contains(info.fileName()))
@@ -317,7 +306,7 @@ QT_USE_NAMESPACE
Q_UNUSED(sender);
if (!okFlag)
return filename;
- if (mConfirmOverwrite)
+ if (!mOptions->testOption(QFileDialogOptions::DontConfirmOverwrite))
return filename;
// User has clicked save, and no overwrite confirmation should occur.
@@ -376,20 +365,21 @@ QT_USE_NAMESPACE
// Call this functions if mFileMode, mFileOptions,
// mNameFilterDropDownList or mQDirFilter changes.
// The savepanel does not contain the neccessary functions for this.
- bool chooseFilesOnly = mFileMode == QT_PREPEND_NAMESPACE(QFileDialog::ExistingFile)
- || mFileMode == QT_PREPEND_NAMESPACE(QFileDialog::ExistingFiles);
- bool chooseDirsOnly = mFileMode == QT_PREPEND_NAMESPACE(QFileDialog::Directory)
- || mFileMode == QT_PREPEND_NAMESPACE(QFileDialog::DirectoryOnly)
- || *mFileOptions & QT_PREPEND_NAMESPACE(QFileDialog::ShowDirsOnly);
+ const QT_PREPEND_NAMESPACE(QFileDialogOptions::FileMode) fileMode = mOptions->fileMode();
+ bool chooseFilesOnly = fileMode == QT_PREPEND_NAMESPACE(QFileDialogOptions::ExistingFile)
+ || fileMode == QT_PREPEND_NAMESPACE(QFileDialogOptions::ExistingFiles);
+ bool chooseDirsOnly = fileMode == QT_PREPEND_NAMESPACE(QFileDialogOptions::Directory)
+ || fileMode == QT_PREPEND_NAMESPACE(QFileDialogOptions::DirectoryOnly)
+ || mOptions->testOption(QT_PREPEND_NAMESPACE(QFileDialogOptions::ShowDirsOnly));
[mOpenPanel setCanChooseFiles:!chooseDirsOnly];
[mOpenPanel setCanChooseDirectories:!chooseFilesOnly];
- [mSavePanel setCanCreateDirectories:!(*mFileOptions & QT_PREPEND_NAMESPACE(QFileDialog::ReadOnly))];
- [mOpenPanel setAllowsMultipleSelection:(mFileMode == QT_PREPEND_NAMESPACE(QFileDialog::ExistingFiles))];
- [mOpenPanel setResolvesAliases:!(*mFileOptions & QT_PREPEND_NAMESPACE(QFileDialog::DontResolveSymlinks))];
+ [mSavePanel setCanCreateDirectories:!(mOptions->testOption(QT_PREPEND_NAMESPACE(QFileDialogOptions::ReadOnly)))];
+ [mOpenPanel setAllowsMultipleSelection:(fileMode == QT_PREPEND_NAMESPACE(QFileDialogOptions::ExistingFiles))];
+ [mOpenPanel setResolvesAliases:!(mOptions->testOption(QT_PREPEND_NAMESPACE(QFileDialogOptions::DontResolveSymlinks)))];
QStringList ext = [self acceptableExtensionsForSave];
- const QString defaultSuffix = mFileDialog->defaultSuffix();
+ const QString defaultSuffix = mOptions->defaultSuffix();
if (!ext.isEmpty() && !defaultSuffix.isEmpty())
ext.prepend(defaultSuffix);
[mSavePanel setAllowedFileTypes:ext.isEmpty() ? nil : QT_PREPEND_NAMESPACE(qt_mac_QStringListToNSMutableArray(ext))];
@@ -473,7 +463,8 @@ QT_USE_NAMESPACE
[mTextField setSelectable:false];
[mTextField setBordered:false];
[mTextField setDrawsBackground:false];
- [mTextField setStringValue:[self strip:mFileDialog->labelText(QFileDialog::FileType)]];
+ if (mOptions->isLabelExplicitlySet(QFileDialogOptions::FileType))
+ [mTextField setStringValue:[self strip:mOptions->labelText(QFileDialogOptions::FileType)]];
}
- (void)createPopUpButton:(const QString &)selectedFilter hideDetails:(BOOL)hideDetails
@@ -538,15 +529,16 @@ QCocoaFileDialogHelper::~QCocoaFileDialogHelper()
void QCocoaFileDialogHelper::QNSOpenSavePanelDelegate_selectionChanged(const QString &newPath)
{
- qtFileDialog->metaObject()->invokeMethod(qtFileDialog, "currentChanged", Q_ARG(QString, newPath));
+ emit currentChanged(newPath);
}
void QCocoaFileDialogHelper::QNSOpenSavePanelDelegate_panelClosed(bool accepted)
{
- if (accepted)
- qtFileDialog->metaObject()->invokeMethod(qtFileDialog, "accept");
- else
- qtFileDialog->metaObject()->invokeMethod(qtFileDialog, "reject");
+ if (accepted) {
+ emit accept();
+ } else {
+ emit reject();
+ }
}
void QCocoaFileDialogHelper::QNSOpenSavePanelDelegate_directoryEntered(const QString &newDir)
@@ -557,7 +549,7 @@ void QCocoaFileDialogHelper::QNSOpenSavePanelDelegate_directoryEntered(const QSt
void QCocoaFileDialogHelper::QNSOpenSavePanelDelegate_filterSelected(int menuIndex)
{
- const QStringList filters = qtFileDialog->nameFilters();
+ const QStringList filters = options()->nameFilters();
emit filterSelected(menuIndex >= 0 && menuIndex < filters.size() ? filters.at(menuIndex) : QString());
}
@@ -593,29 +585,22 @@ QStringList QCocoaFileDialogHelper::selectedFiles_sys() const
return [delegate selectedFiles];
}
-void QCocoaFileDialogHelper::setNameFilters_sys(const QStringList &filters)
-{
- QT_MANGLE_NAMESPACE(QNSOpenSavePanelDelegate) *delegate = static_cast<QT_MANGLE_NAMESPACE(QNSOpenSavePanelDelegate) *>(mDelegate);
- bool hideDetails = qtFileDialog->testOption(QFileDialog::HideNameFilterDetails);
- [delegate setNameFilters:filters hideDetails:hideDetails];
-}
-
void QCocoaFileDialogHelper::setFilter_sys()
{
QT_MANGLE_NAMESPACE(QNSOpenSavePanelDelegate) *delegate = static_cast<QT_MANGLE_NAMESPACE(QNSOpenSavePanelDelegate) *>(mDelegate);
- *(delegate->mQDirFilter) = qtFileDialog->filter();
- delegate->mFileMode = qtFileDialog->fileMode();
- [delegate->mSavePanel setTitle:qt_mac_QStringToNSString(qtFileDialog->windowTitle())];
- [delegate->mSavePanel setPrompt:[delegate strip:qtFileDialog->labelText(QFileDialog::Accept)]];
- if (false) // ### fixme priv->fileNameLabelExplicitlySat)
- [delegate->mSavePanel setNameFieldLabel:[delegate strip:qtFileDialog->labelText(QFileDialog::FileName)]];
+ const SharedPointerFileDialogOptions &opts = options();
+ [delegate->mSavePanel setTitle:qt_mac_QStringToNSString(opts->windowTitle())];
+ if (opts->isLabelExplicitlySet(QFileDialogOptions::Accept))
+ [delegate->mSavePanel setPrompt:[delegate strip:opts->labelText(QFileDialogOptions::Accept)]];
+ if (opts->isLabelExplicitlySet(QFileDialogOptions::FileName))
+ [delegate->mSavePanel setNameFieldLabel:[delegate strip:opts->labelText(QFileDialogOptions::FileName)]];
[delegate updateProperties];
}
void QCocoaFileDialogHelper::selectNameFilter_sys(const QString &filter)
{
- const int index = qtFileDialog->nameFilters().indexOf(filter);
+ const int index = options()->nameFilters().indexOf(filter);
if (index != -1) {
QT_MANGLE_NAMESPACE(QNSOpenSavePanelDelegate) *delegate = static_cast<QT_MANGLE_NAMESPACE(QNSOpenSavePanelDelegate) *>(mDelegate);
[delegate->mPopUpButton selectItemAtIndex:index];
@@ -627,7 +612,7 @@ QString QCocoaFileDialogHelper::selectedNameFilter_sys() const
{
QT_MANGLE_NAMESPACE(QNSOpenSavePanelDelegate) *delegate = static_cast<QT_MANGLE_NAMESPACE(QNSOpenSavePanelDelegate) *>(mDelegate);
int index = [delegate->mPopUpButton indexOfSelectedItem];
- return index != -1 ? qtFileDialog->nameFilters().at(index) : QString();
+ return index != -1 ? options()->nameFilters().at(index) : QString();
}
void QCocoaFileDialogHelper::deleteNativeDialog_sys()
@@ -642,13 +627,13 @@ void QCocoaFileDialogHelper::hide_sys()
hideCocoaFilePanel();
}
-bool QCocoaFileDialogHelper::show_sys(QWindow * /* parent */)
+bool QCocoaFileDialogHelper::show_sys(ShowFlags /* flags */, Qt::WindowFlags windowFlags, QWindow *parent)
{
// Q_Q(QFileDialog);
if (!qtFileDialog->isHidden())
return false;
- if (qtFileDialog->windowFlags() & Qt::WindowStaysOnTopHint) {
+ if (windowFlags & Qt::WindowStaysOnTopHint) {
// The native file dialog tries all it can to stay
// on the NSModalPanel level. And it might also show
// its own "create directory" dialog that we cannot control.
@@ -656,38 +641,35 @@ bool QCocoaFileDialogHelper::show_sys(QWindow * /* parent */)
return false;
}
- return showCocoaFilePanel();
+ return showCocoaFilePanel(parent);
}
void QCocoaFileDialogHelper::createNSOpenSavePanelDelegate()
{
if (mDelegate)
return;
-
- bool selectDir = qtFileDialog->selectedFiles().isEmpty();
- QString selection(selectDir ? qtFileDialog->directory().absolutePath() : qtFileDialog->selectedFiles().value(0));
+ const SharedPointerFileDialogOptions &opts = options();
+ const QStringList selectedFiles = opts->initiallySelectedFiles();
+ const QString directory = opts->initialDirectory();
+ const bool selectDir = selectedFiles.isEmpty();
+ QString selection(selectDir ? directory : selectedFiles.front());
QT_MANGLE_NAMESPACE(QNSOpenSavePanelDelegate) *delegate = [[QT_MANGLE_NAMESPACE(QNSOpenSavePanelDelegate) alloc]
- initWithAcceptMode:qtFileDialog->acceptMode()
- title:qtFileDialog->windowTitle()
- hideNameFilterDetails:qtFileDialog->testOption(QFileDialog::HideNameFilterDetails)
- qDirFilter:qtFileDialog->filter()
- fileOptions:qtFileDialog->options()
- fileMode:qtFileDialog->fileMode()
- selectFile:selection
- confirmOverwrite:!qtFileDialog->testOption(QFileDialog::DontConfirmOverwrite)
- fileDialog:qtFileDialog
- helper:this];
+ initWithAcceptMode:
+ selection
+ fileDialog:qtFileDialog
+ options:opts
+ helper:this];
mDelegate = delegate;
}
-bool QCocoaFileDialogHelper::showCocoaFilePanel()
+bool QCocoaFileDialogHelper::showCocoaFilePanel(QWindow *parent)
{
// Q_Q(QFileDialog);
createNSOpenSavePanelDelegate();
QT_MANGLE_NAMESPACE(QNSOpenSavePanelDelegate) *delegate = static_cast<QT_MANGLE_NAMESPACE(QNSOpenSavePanelDelegate) *>(mDelegate);
if (qt_mac_is_macsheet(qtFileDialog))
- [delegate showWindowModalSheet:qtFileDialog->parentWidget()];
+ [delegate showWindowModalSheet:parent];
else
[delegate showModelessPanel];
return true;
@@ -717,7 +699,7 @@ void QCocoaFileDialogHelper::platformNativeDialogModalHelp()
// running (which is the case if e.g a top-most QEventLoop has been
// interrupted, and the second-most event loop has not yet been reactivated (regardless
// if [NSApp run] is still on the stack)), showing a native modal dialog will fail.
- QTimer::singleShot(1, qtFileDialog, SLOT(_q_platformRunNativeAppModalPanel()));
+ QTimer::singleShot(1, this, SIGNAL(launchNativeAppModalPanel()));
}
void QCocoaFileDialogHelper::_q_platformRunNativeAppModalPanel()
@@ -729,9 +711,9 @@ void QCocoaFileDialogHelper::_q_platformRunNativeAppModalPanel()
QT_MANGLE_NAMESPACE(QNSOpenSavePanelDelegate) *delegate = static_cast<QT_MANGLE_NAMESPACE(QNSOpenSavePanelDelegate) *>(mDelegate);
[delegate runApplicationModalPanel];
if (dialogResultCode_sys() == QPlatformDialogHelper::Accepted)
- qtFileDialog->metaObject()->invokeMethod(qtFileDialog, "accept");
+ emit accept();
else
- qtFileDialog->metaObject()->invokeMethod(qtFileDialog, "reject");
+ emit reject();
}
QPlatformDialogHelper::DialogCode QCocoaFileDialogHelper::dialogResultCode_sys()
diff --git a/src/plugins/platforms/windows/qwindowsdialoghelpers.cpp b/src/plugins/platforms/windows/qwindowsdialoghelpers.cpp
index 58352470a6..7a83baabb1 100644
--- a/src/plugins/platforms/windows/qwindowsdialoghelpers.cpp
+++ b/src/plugins/platforms/windows/qwindowsdialoghelpers.cpp
@@ -416,8 +416,7 @@ protected:
*/
template <class BaseClass>
-QWindowsDialogHelperBase<BaseClass>::QWindowsDialogHelperBase(QDialog *dialog) :
- m_dialog(dialog),
+QWindowsDialogHelperBase<BaseClass>::QWindowsDialogHelperBase() :
m_nativeDialog(0),
m_ownerWindow(0)
{
@@ -437,11 +436,8 @@ template <class BaseClass>
QWindowsNativeDialogBase *QWindowsDialogHelperBase<BaseClass>::ensureNativeDialog()
{
// Create dialog and apply common settings.
- if (!m_nativeDialog) {
+ if (!m_nativeDialog)
m_nativeDialog = createNativeDialog();
- if (m_nativeDialog)
- m_nativeDialog->setWindowTitle(m_dialog->windowTitle());
- }
return m_nativeDialog;
}
@@ -487,9 +483,11 @@ void QWindowsDialogThread::run()
}
template <class BaseClass>
-bool QWindowsDialogHelperBase<BaseClass>::show_sys(QWindow *parent)
+bool QWindowsDialogHelperBase<BaseClass>::show_sys(QPlatformDialogHelper::ShowFlags flags,
+ Qt::WindowFlags,
+ QWindow *parent)
{
- const bool modal = m_dialog->isModal();
+ const bool modal = flags & QPlatformDialogHelper::ShowModal;
if (parent) {
m_ownerWindow = QWindowsWindow::handleOf(parent);
} else {
@@ -523,7 +521,8 @@ void QWindowsDialogHelperBase<BaseClass>::platformNativeDialogModalHelp()
if (QWindowsContext::verboseDialogs)
qDebug("%s" , __FUNCTION__);
if (QWindowsNativeDialogBase *nd =nativeDialog())
- nd->metaObject()->invokeMethod(m_dialog, "_q_platformRunNativeAppModalPanel",
+ nd->metaObject()->invokeMethod(this,
+ "emitLaunchNativeAppModalPanel",
Qt::QueuedConnection);
}
@@ -650,10 +649,10 @@ class QWindowsNativeFileDialogBase : public QWindowsNativeDialogBase
public:
~QWindowsNativeFileDialogBase();
- inline static QWindowsNativeFileDialogBase *create(QFileDialog::AcceptMode am);
+ inline static QWindowsNativeFileDialogBase *create(QFileDialogOptions::AcceptMode am);
virtual void setWindowTitle(const QString &title);
- inline void setMode(QFileDialog::FileMode mode, QFileDialog::Options options);
+ inline void setMode(QFileDialogOptions::FileMode mode, QFileDialogOptions::FileDialogOptions options);
inline void setDirectory(const QString &directory);
inline QString directory() const;
virtual void exec(HWND owner = 0);
@@ -662,6 +661,8 @@ public:
inline QString selectedNameFilter() const;
bool hideFiltersDetails() const { return m_hideFiltersDetails; }
void setHideFiltersDetails(bool h) { m_hideFiltersDetails = h; }
+ void setDefaultSuffix(const QString &s);
+ inline void setLabelText(QFileDialogOptions::DialogLabel l, const QString &text);
virtual QPlatformDialogHelper::DialogCode result() const
{ return fileResult(); }
@@ -785,25 +786,25 @@ void QWindowsNativeFileDialogBase::exec(HWND owner)
}
}
-void QWindowsNativeFileDialogBase::setMode(QFileDialog::FileMode mode, QFileDialog::Options options)
+void QWindowsNativeFileDialogBase::setMode(QFileDialogOptions::FileMode mode, QFileDialogOptions::FileDialogOptions options)
{
DWORD flags = FOS_PATHMUSTEXIST | FOS_FORCESHOWHIDDEN;
- if (options & QFileDialog::DontResolveSymlinks)
+ if (options & QFileDialogOptions::DontResolveSymlinks)
flags |= FOS_NODEREFERENCELINKS;
switch (mode) {
- case QFileDialog::AnyFile:
+ case QFileDialogOptions::AnyFile:
flags |= FOS_NOREADONLYRETURN;
- if (!(options & QFileDialog::DontConfirmOverwrite))
+ if (!(options & QFileDialogOptions::DontConfirmOverwrite))
flags |= FOS_OVERWRITEPROMPT;
break;
- case QFileDialog::ExistingFile:
+ case QFileDialogOptions::ExistingFile:
flags |= FOS_FILEMUSTEXIST;
break;
- case QFileDialog::Directory:
- case QFileDialog::DirectoryOnly:
+ case QFileDialogOptions::Directory:
+ case QFileDialogOptions::DirectoryOnly:
flags |= FOS_PICKFOLDERS | FOS_FILEMUSTEXIST;
break;
- case QFileDialog::ExistingFiles:
+ case QFileDialogOptions::ExistingFiles:
flags |= FOS_FILEMUSTEXIST | FOS_ALLOWMULTISELECT;
break;
}
@@ -905,6 +906,31 @@ void QWindowsNativeFileDialogBase::setNameFilters(const QStringList &filters)
m_fileDialog->SetFileTypes(size, comFilterSpec.data());
}
+void QWindowsNativeFileDialogBase::setDefaultSuffix(const QString &s)
+{
+ wchar_t *wSuffix = const_cast<wchar_t *>(reinterpret_cast<const wchar_t *>(s.utf16()));
+ m_fileDialog->SetDefaultExtension(wSuffix);
+}
+
+void QWindowsNativeFileDialogBase::setLabelText(QFileDialogOptions::DialogLabel l, const QString &text)
+{
+ wchar_t *wText = const_cast<wchar_t *>(reinterpret_cast<const wchar_t *>(text.utf16()));
+ switch (l) {
+ break;
+ case QFileDialogOptions::FileName:
+ m_fileDialog->SetFileNameLabel(wText);
+ break;
+ case QFileDialogOptions::Accept:
+ m_fileDialog->SetOkButtonLabel(wText);
+ break;
+ case QFileDialogOptions::LookIn:
+ case QFileDialogOptions::Reject:
+ case QFileDialogOptions::FileType:
+ case QFileDialogOptions::DialogLabelCount:
+ break;
+ }
+}
+
void QWindowsNativeFileDialogBase::selectNameFilter(const QString &filter)
{
const int index = m_nameFilters.indexOf(filter);
@@ -1052,10 +1078,10 @@ QStringList QWindowsNativeOpenFileDialog::selectedFiles() const
QFileDialog::AcceptMode.
*/
-QWindowsNativeFileDialogBase *QWindowsNativeFileDialogBase::create(QFileDialog::AcceptMode am)
+QWindowsNativeFileDialogBase *QWindowsNativeFileDialogBase::create(QFileDialogOptions::AcceptMode am)
{
QWindowsNativeFileDialogBase *result = 0;
- if (am == QFileDialog::AcceptOpen) {
+ if (am == QFileDialogOptions::AcceptOpen) {
result = new QWindowsNativeOpenFileDialog;
if (!result->init(CLSID_FileOpenDialog, IID_IFileOpenDialog)) {
delete result;
@@ -1081,10 +1107,7 @@ QWindowsNativeFileDialogBase *QWindowsNativeFileDialogBase::create(QFileDialog::
class QWindowsFileDialogHelper : public QWindowsDialogHelperBase<QPlatformFileDialogHelper>
{
public:
- explicit QWindowsFileDialogHelper(QDialog *dialog) :
- QWindowsDialogHelperBase<QPlatformFileDialogHelper>(dialog),
- m_fileDialog(qobject_cast<QFileDialog *>(dialog))
- { Q_ASSERT(m_fileDialog); }
+ QWindowsFileDialogHelper() {}
virtual bool defaultNameFilterDisables() const
{ return true; }
@@ -1101,18 +1124,16 @@ private:
virtual QWindowsNativeDialogBase *createNativeDialog();
inline QWindowsNativeFileDialogBase *nativeFileDialog() const
{ return static_cast<QWindowsNativeFileDialogBase *>(nativeDialog()); }
-
- QFileDialog *m_fileDialog;
};
QWindowsNativeDialogBase *QWindowsFileDialogHelper::createNativeDialog()
{
- QWindowsNativeFileDialogBase *result = QWindowsNativeFileDialogBase::create(m_fileDialog->acceptMode());
+ QWindowsNativeFileDialogBase *result = QWindowsNativeFileDialogBase::create(options()->acceptMode());
if (!result)
return 0;
- QObject::connect(result, SIGNAL(accepted()), m_fileDialog, SLOT(accept()),
+ QObject::connect(result, SIGNAL(accepted()), this, SIGNAL(accept()),
Qt::QueuedConnection);
- QObject::connect(result, SIGNAL(rejected()), m_fileDialog, SLOT(reject()),
+ QObject::connect(result, SIGNAL(rejected()), this, SIGNAL(reject()),
Qt::QueuedConnection);
QObject::connect(result, SIGNAL(directoryEntered(QString)),
this, SIGNAL(directoryEntered(QString)),
@@ -1125,18 +1146,26 @@ QWindowsNativeDialogBase *QWindowsFileDialogHelper::createNativeDialog()
Qt::QueuedConnection);
// Apply settings.
- result->setMode(m_fileDialog->fileMode(), m_fileDialog->options());
- const QDir directory = m_fileDialog->directory();
- if (directory.exists())
- result->setDirectory(directory.absolutePath());
- result->setHideFiltersDetails(m_fileDialog->testOption(QFileDialog::HideNameFilterDetails));
- const QStringList nameFilters = m_fileDialog->nameFilters();
- if (!nameFilters.isEmpty()) {
+ const QSharedPointer<QFileDialogOptions> &opts = options();
+ result->setWindowTitle(opts->windowTitle());
+ result->setMode(opts->fileMode(), opts->options());
+ result->setHideFiltersDetails(opts->testOption(QFileDialogOptions::HideNameFilterDetails));
+ const QStringList nameFilters = opts->nameFilters();
+ if (!nameFilters.isEmpty())
result->setNameFilters(nameFilters);
- const QString selectedNameFilter = m_fileDialog->selectedNameFilter();
- if (!selectedNameFilter.isEmpty())
- result->selectNameFilter(selectedNameFilter);
- }
+ if (opts->isLabelExplicitlySet(QFileDialogOptions::FileName))
+ result->setLabelText(QFileDialogOptions::FileName, opts->labelText(QFileDialogOptions::FileName));
+ if (opts->isLabelExplicitlySet(QFileDialogOptions::Accept))
+ result->setLabelText(QFileDialogOptions::Accept, opts->labelText(QFileDialogOptions::Accept));
+ const QString initialDirectory = opts->initialDirectory();
+ if (!initialDirectory.isEmpty())
+ result->setDirectory(initialDirectory);
+ const QString initialNameFilter = opts->initiallySelectedNameFilter();
+ if (!initialNameFilter.isEmpty())
+ result->selectNameFilter(initialNameFilter);
+ const QString defaultSuffix = opts->defaultSuffix();
+ if (!defaultSuffix.isEmpty())
+ result->setDefaultSuffix(defaultSuffix);
return result;
}
@@ -1218,6 +1247,8 @@ class QWindowsNativeColorDialog : public QWindowsNativeDialogBase
{
Q_OBJECT
public:
+ enum { CustomColorCount = 16 };
+
explicit QWindowsNativeColorDialog(const SharedPointerColor &color);
virtual void setWindowTitle(const QString &) {}
@@ -1228,7 +1259,7 @@ public slots:
virtual void close() {}
private:
- COLORREF m_customColors[16];
+ COLORREF m_customColors[CustomColorCount];
QPlatformDialogHelper::DialogCode m_code;
SharedPointerColor m_color;
};
@@ -1256,6 +1287,11 @@ void QWindowsNativeColorDialog::exec(HWND owner)
chooseColor.lStructSize = sizeof(chooseColor);
chooseColor.hwndOwner = owner;
chooseColor.lpCustColors = m_customColors;
+ QRgb *qCustomColors = QColorDialogOptions::customColors();
+ const int customColorCount = qMin(QColorDialogOptions::customColorCount(),
+ int(CustomColorCount));
+ for (int c= 0; c < customColorCount; ++c)
+ m_customColors[c] = qColorToCOLORREF(QColor(qCustomColors[c]));
chooseColor.rgbResult = qColorToCOLORREF(*m_color);
chooseColor.Flags = CC_FULLOPEN | CC_RGBINIT;
static ChooseColorWType chooseColorW = 0;
@@ -1272,6 +1308,8 @@ void QWindowsNativeColorDialog::exec(HWND owner)
}
if (m_code == QPlatformDialogHelper::Accepted) {
*m_color = COLORREFToQColor(chooseColor.rgbResult);
+ for (int c= 0; c < customColorCount; ++c)
+ qCustomColors[c] = COLORREFToQColor(m_customColors[c]).rgb();
emit accepted();
if (QWindowsContext::verboseDialogs)
qDebug() << '<' << __FUNCTION__ << m_color;
@@ -1295,8 +1333,7 @@ void QWindowsNativeColorDialog::exec(HWND owner)
class QWindowsColorDialogHelper : public QWindowsDialogHelperBase<QPlatformColorDialogHelper>
{
public:
- QWindowsColorDialogHelper(QDialog *dialog) :
- QWindowsDialogHelperBase<QPlatformColorDialogHelper>(dialog), m_currentColor(new QColor) { }
+ QWindowsColorDialogHelper() {}
virtual bool supportsNonModalDialog()
{ return false; }
@@ -1307,11 +1344,18 @@ public:
private:
inline QWindowsNativeColorDialog *nativeFileDialog() const
{ return static_cast<QWindowsNativeColorDialog *>(nativeDialog()); }
- virtual QWindowsNativeDialogBase *createNativeDialog()
- { return new QWindowsNativeColorDialog(m_currentColor); }
+ virtual QWindowsNativeDialogBase *createNativeDialog();
+
SharedPointerColor m_currentColor;
};
+QWindowsNativeDialogBase *QWindowsColorDialogHelper::createNativeDialog()
+{
+ QWindowsNativeColorDialog *nativeDialog = new QWindowsNativeColorDialog(m_currentColor);
+ nativeDialog->setWindowTitle(options()->windowTitle());
+ return nativeDialog;
+}
+
namespace QWindowsDialogs {
// QWindowsDialogHelperBase creation functions
@@ -1342,10 +1386,10 @@ QPlatformDialogHelper *createHelper(QDialog *dialog)
switch (QWindowsDialogs::dialogType(dialog)) {
case QWindowsDialogs::FileDialog:
- return new QWindowsFileDialogHelper(dialog);
+ return new QWindowsFileDialogHelper();
case QWindowsDialogs::ColorDialog:
#ifdef USE_NATIVE_COLOR_DIALOG
- return new QWindowsColorDialogHelper(dialog);
+ return new QWindowsColorDialogHelper();
#endif
case QWindowsDialogs::FontDialog:
case QWindowsDialogs::UnknownType:
diff --git a/src/plugins/platforms/windows/qwindowsdialoghelpers.h b/src/plugins/platforms/windows/qwindowsdialoghelpers.h
index 96c03bbaec..a4fa8c4a3a 100644
--- a/src/plugins/platforms/windows/qwindowsdialoghelpers.h
+++ b/src/plugins/platforms/windows/qwindowsdialoghelpers.h
@@ -73,7 +73,9 @@ public:
virtual void platformNativeDialogModalHelp();
virtual void _q_platformRunNativeAppModalPanel();
virtual void deleteNativeDialog_sys();
- virtual bool show_sys(QWindow *parent);
+ virtual bool show_sys(QPlatformDialogHelper::ShowFlags flags,
+ Qt::WindowFlags windowFlags,
+ QWindow *parent);
virtual void hide_sys();
virtual QVariant styleHint(QPlatformDialogHelper::StyleHint) const;
@@ -82,14 +84,13 @@ public:
virtual bool supportsNonModalDialog() const { return true; }
protected:
- explicit QWindowsDialogHelperBase(QDialog *dialog);
+ QWindowsDialogHelperBase();
QWindowsNativeDialogBase *nativeDialog() const;
private:
virtual QWindowsNativeDialogBase *createNativeDialog() = 0;
inline QWindowsNativeDialogBase *ensureNativeDialog();
- QDialog *m_dialog;
QWindowsNativeDialogBase *m_nativeDialog;
HWND m_ownerWindow;
};
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