Decouple QPlatformTheme from QDialog.
- Use an enumeration for the dialog type. - Implemented on Windows and Mac Reviewed-by: Morten Johan Sorvig <morten.sorvig@nokia.com> Change-Id: I213748a08168efbabc2ac0106308e97ff19d19c0 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@nokia.com>bb10
parent
b3dda7c5bf
commit
692a1babe5
|
|
@ -83,15 +83,15 @@ QPlatformMenuBar *QPlatformTheme::createPlatformMenuBar(QMenuBar *menuBar) const
|
|||
return 0;
|
||||
}
|
||||
|
||||
bool QPlatformTheme::usePlatformNativeDialog(const QDialog *dialog) const
|
||||
bool QPlatformTheme::usePlatformNativeDialog(DialogType type) const
|
||||
{
|
||||
Q_UNUSED(dialog);
|
||||
Q_UNUSED(type);
|
||||
return false;
|
||||
}
|
||||
|
||||
QPlatformDialogHelper *QPlatformTheme::createPlatformDialogHelper(QDialog *dialog) const
|
||||
QPlatformDialogHelper *QPlatformTheme::createPlatformDialogHelper(DialogType type) const
|
||||
{
|
||||
Q_UNUSED(dialog);
|
||||
Q_UNUSED(type);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -54,7 +54,6 @@ class QMenuBar;
|
|||
class QPlatformMenu;
|
||||
class QPlatformMenuBar;
|
||||
class QPlatformDialogHelper;
|
||||
class QDialog;
|
||||
class QVariant;
|
||||
|
||||
class Q_GUI_EXPORT QPlatformTheme
|
||||
|
|
@ -66,11 +65,17 @@ public:
|
|||
MaximumScrollBarDragDistance
|
||||
};
|
||||
|
||||
enum DialogType {
|
||||
FileDialog,
|
||||
ColorDialog,
|
||||
FontDialog
|
||||
};
|
||||
|
||||
virtual QPlatformMenu *createPlatformMenu(QMenu *menu = 0) const;
|
||||
virtual QPlatformMenuBar *createPlatformMenuBar(QMenuBar *menuBar = 0) const;
|
||||
|
||||
virtual bool usePlatformNativeDialog(const QDialog *dialog = 0) const;
|
||||
virtual QPlatformDialogHelper *createPlatformDialogHelper(QDialog *dialog = 0) const;
|
||||
virtual bool usePlatformNativeDialog(DialogType type) const;
|
||||
virtual QPlatformDialogHelper *createPlatformDialogHelper(DialogType type) const;
|
||||
|
||||
virtual QVariant themeHint(ThemeHint hint) const;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ class QFileDialogPrivate;
|
|||
class QCocoaFileDialogHelper : public QPlatformFileDialogHelper
|
||||
{
|
||||
public:
|
||||
QCocoaFileDialogHelper(QFileDialog *dialog);
|
||||
QCocoaFileDialogHelper();
|
||||
virtual ~QCocoaFileDialogHelper();
|
||||
|
||||
void platformNativeDialogModalHelp();
|
||||
|
|
@ -84,7 +84,6 @@ public:
|
|||
void QNSOpenSavePanelDelegate_filterSelected(int menuIndex);
|
||||
|
||||
private:
|
||||
QFileDialog *qtFileDialog;
|
||||
void *mDelegate;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -92,7 +92,6 @@ typedef QSharedPointer<QFileDialogOptions> SharedPointerFileDialogOptions;
|
|||
NSView *mAccessoryView;
|
||||
NSPopUpButton *mPopUpButton;
|
||||
NSTextField *mTextField;
|
||||
QFileDialog *mFileDialog;
|
||||
QCocoaFileDialogHelper *mHelper;
|
||||
NSString *mCurrentDir;
|
||||
|
||||
|
|
@ -126,12 +125,10 @@ typedef QSharedPointer<QFileDialogOptions> SharedPointerFileDialogOptions;
|
|||
|
||||
- (id)initWithAcceptMode:
|
||||
(const QString &)selectFile
|
||||
fileDialog:(QFileDialog *)fileDialog
|
||||
options:(SharedPointerFileDialogOptions)options
|
||||
helper:(QCocoaFileDialogHelper *)helper
|
||||
{
|
||||
self = [super init];
|
||||
mFileDialog = fileDialog;
|
||||
mOptions = options;
|
||||
if (mOptions->acceptMode() == QT_PREPEND_NAMESPACE(QFileDialogOptions::AcceptOpen)){
|
||||
mOpenPanel = [NSOpenPanel openPanel];
|
||||
|
|
@ -149,7 +146,7 @@ typedef QSharedPointer<QFileDialogOptions> SharedPointerFileDialogOptions;
|
|||
mLastFilterCheckPath = new QString;
|
||||
mQDirFilterEntryList = new QStringList;
|
||||
mNameFilterDropDownList = new QStringList(mOptions->nameFilters());
|
||||
QString selectedVisualNameFilter = mFileDialog->selectedNameFilter();
|
||||
QString selectedVisualNameFilter = mOptions->initiallySelectedNameFilter();
|
||||
mSelectedNameFilter = new QStringList([self findStrippedFilterWithVisualFilterName:selectedVisualNameFilter]);
|
||||
|
||||
QFileInfo sel(selectFile);
|
||||
|
|
@ -518,8 +515,8 @@ static bool qt_mac_is_macsheet(const QWidget *w)
|
|||
return w->parentWidget() && (modality == Qt::WindowModal || w->windowType() == Qt::Sheet);
|
||||
}
|
||||
|
||||
QCocoaFileDialogHelper::QCocoaFileDialogHelper(QFileDialog *dialog) :
|
||||
qtFileDialog(dialog), mDelegate(0)
|
||||
QCocoaFileDialogHelper::QCocoaFileDialogHelper()
|
||||
:mDelegate(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -624,16 +621,12 @@ void QCocoaFileDialogHelper::deleteNativeDialog_sys()
|
|||
|
||||
void QCocoaFileDialogHelper::hide_sys()
|
||||
{
|
||||
if (!qtFileDialog->isHidden())
|
||||
hideCocoaFilePanel();
|
||||
hideCocoaFilePanel();
|
||||
}
|
||||
|
||||
bool QCocoaFileDialogHelper::show_sys(ShowFlags /* flags */, Qt::WindowFlags windowFlags, QWindow *parent)
|
||||
{
|
||||
// Q_Q(QFileDialog);
|
||||
if (!qtFileDialog->isHidden())
|
||||
return false;
|
||||
|
||||
if (windowFlags & Qt::WindowStaysOnTopHint) {
|
||||
// The native file dialog tries all it can to stay
|
||||
// on the NSModalPanel level. And it might also show
|
||||
|
|
@ -657,7 +650,6 @@ void QCocoaFileDialogHelper::createNSOpenSavePanelDelegate()
|
|||
QT_MANGLE_NAMESPACE(QNSOpenSavePanelDelegate) *delegate = [[QT_MANGLE_NAMESPACE(QNSOpenSavePanelDelegate) alloc]
|
||||
initWithAcceptMode:
|
||||
selection
|
||||
fileDialog:qtFileDialog
|
||||
options:opts
|
||||
helper:this];
|
||||
|
||||
|
|
@ -669,7 +661,7 @@ 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))
|
||||
if (0 /*qt_mac_is_macsheet(qtFileDialog)*/) // ### sheet support.
|
||||
[delegate showWindowModalSheet:parent];
|
||||
else
|
||||
[delegate showModelessPanel];
|
||||
|
|
|
|||
|
|
@ -57,8 +57,8 @@ public:
|
|||
QPlatformMenu *createPlatformMenu(QMenu *menu = 0) const;
|
||||
QPlatformMenuBar *createPlatformMenuBar(QMenuBar *menuBar = 0) const;
|
||||
|
||||
bool usePlatformNativeDialog(const QDialog *dialog = 0) const;
|
||||
QPlatformDialogHelper *createPlatformDialogHelper(QDialog *dialog = 0) const;
|
||||
bool usePlatformNativeDialog(DialogType dialogType) const;
|
||||
QPlatformDialogHelper *createPlatformDialogHelper(DialogType dialogType) const;
|
||||
};
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
|
|
|||
|
|
@ -68,24 +68,17 @@ QPlatformMenuBar *QCocoaTheme::createPlatformMenuBar(QMenuBar *menuBar) const
|
|||
}
|
||||
|
||||
|
||||
bool QCocoaTheme::usePlatformNativeDialog(const QDialog *dialog) const
|
||||
bool QCocoaTheme::usePlatformNativeDialog(DialogType dialogType) const
|
||||
{
|
||||
Q_UNUSED(dialog);
|
||||
return true;
|
||||
#if 0
|
||||
QFileDialog *fileDialog = qobject_cast<QFileDialog*>(dialog);
|
||||
if (fileDialog) {
|
||||
if (dialogType == QPlatformTheme::FileDialog)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
QPlatformDialogHelper * QCocoaTheme::createPlatformDialogHelper(QDialog *dialog) const
|
||||
QPlatformDialogHelper * QCocoaTheme::createPlatformDialogHelper(DialogType dialogType) const
|
||||
{
|
||||
QFileDialog *fileDialog = qobject_cast<QFileDialog*>(dialog);
|
||||
if (fileDialog) {
|
||||
return new QCocoaFileDialogHelper(fileDialog);
|
||||
if (dialogType == QPlatformTheme::FileDialog) {
|
||||
return new QCocoaFileDialogHelper();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -341,17 +341,6 @@ void eatMouseMove()
|
|||
qDebug("%s triggered=%d" , __FUNCTION__, msg.message == WM_MOUSEMOVE);
|
||||
}
|
||||
|
||||
Type dialogType(const QDialog *dialog)
|
||||
{
|
||||
if (qobject_cast<const QFileDialog *>(dialog))
|
||||
return FileDialog;
|
||||
if (qobject_cast<const QFontDialog *>(dialog))
|
||||
return FontDialog;
|
||||
if (qobject_cast<const QColorDialog *>(dialog))
|
||||
return ColorDialog;
|
||||
return UnknownType;
|
||||
}
|
||||
|
||||
} // namespace QWindowsDialogs
|
||||
|
||||
/*!
|
||||
|
|
@ -1359,40 +1348,36 @@ QWindowsNativeDialogBase *QWindowsColorDialogHelper::createNativeDialog()
|
|||
namespace QWindowsDialogs {
|
||||
|
||||
// QWindowsDialogHelperBase creation functions
|
||||
bool useHelper(const QDialog *dialog)
|
||||
bool useHelper(QPlatformTheme::DialogType type)
|
||||
{
|
||||
if (dialog) {
|
||||
switch (QWindowsDialogs::dialogType(dialog)) {
|
||||
case QWindowsDialogs::FileDialog:
|
||||
return true;
|
||||
case QWindowsDialogs::ColorDialog:
|
||||
switch (type) {
|
||||
case QPlatformTheme::FileDialog:
|
||||
return true;
|
||||
break;
|
||||
case QPlatformTheme::ColorDialog:
|
||||
#ifdef USE_NATIVE_COLOR_DIALOG
|
||||
return true;
|
||||
return true;
|
||||
#else
|
||||
break;
|
||||
#endif
|
||||
case QWindowsDialogs::FontDialog:
|
||||
case QWindowsDialogs::UnknownType:
|
||||
break;
|
||||
}
|
||||
case QPlatformTheme::FontDialog:
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
QPlatformDialogHelper *createHelper(QDialog *dialog)
|
||||
QPlatformDialogHelper *createHelper(QPlatformTheme::DialogType type)
|
||||
{
|
||||
if (QWindowsContext::verboseDialogs)
|
||||
qDebug("%s %p %s" , __FUNCTION__, dialog, dialog->metaObject()->className());
|
||||
if (!dialog)
|
||||
return 0;
|
||||
|
||||
switch (QWindowsDialogs::dialogType(dialog)) {
|
||||
case QWindowsDialogs::FileDialog:
|
||||
switch (type) {
|
||||
case QPlatformTheme::FileDialog:
|
||||
return new QWindowsFileDialogHelper();
|
||||
case QWindowsDialogs::ColorDialog:
|
||||
case QPlatformTheme::ColorDialog:
|
||||
#ifdef USE_NATIVE_COLOR_DIALOG
|
||||
return new QWindowsColorDialogHelper();
|
||||
#else
|
||||
break;
|
||||
#endif
|
||||
case QWindowsDialogs::FontDialog:
|
||||
case QWindowsDialogs::UnknownType:
|
||||
case QPlatformTheme::FontDialog:
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -46,6 +46,7 @@
|
|||
|
||||
#include "qtwindows_additional.h"
|
||||
#include <QtWidgets/qplatformdialoghelper_qpa.h>
|
||||
#include <QtGui/QPlatformTheme>
|
||||
#include <QtCore/QStringList>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
|
@ -56,13 +57,10 @@ class QWindowsNativeDialogBase;
|
|||
|
||||
namespace QWindowsDialogs
|
||||
{
|
||||
enum Type { UnknownType, ColorDialog, FontDialog, FileDialog };
|
||||
|
||||
Type dialogType(const QDialog *dialog);
|
||||
void eatMouseMove();
|
||||
|
||||
bool useHelper(const QDialog *dialog = 0);
|
||||
QPlatformDialogHelper *createHelper(QDialog *dialog = 0);
|
||||
bool useHelper(QPlatformTheme::DialogType type);
|
||||
QPlatformDialogHelper *createHelper(QPlatformTheme::DialogType type);
|
||||
} // namespace QWindowsDialogs
|
||||
|
||||
template <class BaseClass>
|
||||
|
|
|
|||
|
|
@ -81,14 +81,14 @@ QVariant QWindowsTheme::themeHint(ThemeHint hint) const
|
|||
return QVariant();
|
||||
}
|
||||
|
||||
bool QWindowsTheme::usePlatformNativeDialog(const QDialog *dialog) const
|
||||
bool QWindowsTheme::usePlatformNativeDialog(DialogType type) const
|
||||
{
|
||||
return QWindowsDialogs::useHelper(dialog);
|
||||
return QWindowsDialogs::useHelper(type);
|
||||
}
|
||||
|
||||
QPlatformDialogHelper *QWindowsTheme::createPlatformDialogHelper(QDialog *dialog) const
|
||||
QPlatformDialogHelper *QWindowsTheme::createPlatformDialogHelper(DialogType type) const
|
||||
{
|
||||
return QWindowsDialogs::createHelper(dialog);
|
||||
return QWindowsDialogs::createHelper(type);
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
|
|
|||
|
|
@ -51,8 +51,8 @@ class QWindowsTheme : public QPlatformTheme
|
|||
public:
|
||||
QWindowsTheme();
|
||||
|
||||
virtual bool usePlatformNativeDialog(const QDialog *dialog = 0) const;
|
||||
virtual QPlatformDialogHelper *createPlatformDialogHelper(QDialog *dialog = 0) const;
|
||||
virtual bool usePlatformNativeDialog(DialogType type) const;
|
||||
virtual QPlatformDialogHelper *createPlatformDialogHelper(DialogType type) const;
|
||||
virtual QVariant themeHint(ThemeHint) const;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -39,8 +39,9 @@
|
|||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "qdialog.h"
|
||||
|
||||
#include "qcolordialog.h"
|
||||
#include "qfontdialog.h"
|
||||
#include "qfiledialog.h"
|
||||
|
||||
#include "qevent.h"
|
||||
#include "qdesktopwidget.h"
|
||||
|
|
@ -59,22 +60,36 @@
|
|||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
static inline int themeDialogType(const QDialog *dialog)
|
||||
{
|
||||
if (qobject_cast<const QFileDialog *>(dialog))
|
||||
return QPlatformTheme::FileDialog;
|
||||
if (qobject_cast<const QColorDialog *>(dialog))
|
||||
return QPlatformTheme::ColorDialog;
|
||||
if (qobject_cast<const QFontDialog *>(dialog))
|
||||
return QPlatformTheme::FontDialog;
|
||||
return -1;
|
||||
}
|
||||
|
||||
QPlatformDialogHelper *QDialogPrivate::platformHelper() const
|
||||
{
|
||||
// Delayed creation of the platform, ensuring that
|
||||
// that qobject_cast<> on the dialog works in the plugin.
|
||||
if (!m_platformHelperCreated) {
|
||||
QDialogPrivate *ncThis = const_cast<QDialogPrivate *>(this);
|
||||
m_platformHelperCreated = true;
|
||||
QDialogPrivate *ncThis = const_cast<QDialogPrivate *>(this);
|
||||
QDialog *dialog = ncThis->q_func();
|
||||
m_platformHelper = QGuiApplicationPrivate::platformTheme()
|
||||
->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);
|
||||
const int type = themeDialogType(dialog);
|
||||
if (type >= 0) {
|
||||
m_platformHelper = QGuiApplicationPrivate::platformTheme()
|
||||
->createPlatformDialogHelper(static_cast<QPlatformTheme::DialogType>(type));
|
||||
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;
|
||||
|
|
|
|||
Loading…
Reference in New Issue