diff options
Diffstat (limited to 'src/gui')
96 files changed, 1877 insertions, 703 deletions
diff --git a/src/gui/dialogs/dialogs.pri b/src/gui/dialogs/dialogs.pri index 63f64a2..4e1b9a7 100644 --- a/src/gui/dialogs/dialogs.pri +++ b/src/gui/dialogs/dialogs.pri @@ -50,7 +50,8 @@ HEADERS += \ } win32 { - HEADERS += dialogs/qwizard_win_p.h + HEADERS += dialogs/qwizard_win_p.h \ + dialogs/qfiledialog_win_p.h SOURCES += dialogs/qdialogsbinarycompat_win.cpp \ dialogs/qfiledialog_win.cpp \ dialogs/qpagesetupdialog_win.cpp \ diff --git a/src/gui/dialogs/qfiledialog_win.cpp b/src/gui/dialogs/qfiledialog_win.cpp index 5a7ace9..3120938 100644 --- a/src/gui/dialogs/qfiledialog_win.cpp +++ b/src/gui/dialogs/qfiledialog_win.cpp @@ -53,53 +53,27 @@ #include <qdir.h> #include <qstringlist.h> #include <qlibrary.h> +#include "qfiledialog_win_p.h" #ifndef QT_NO_THREAD # include <private/qmutexpool_p.h> #endif -#include <shlobj.h> -//At some point we can hope that mingw will support that interface -#if !defined(Q_WS_WINCE) && !defined(Q_CC_MINGW) -#include <shobjidl.h> -#endif - -#include <objbase.h> - -#if defined(__IFileDialog_INTERFACE_DEFINED__) \ - && defined(__IFileOpenDialog_INTERFACE_DEFINED__) -#define USE_COMMON_ITEM_DIALOG -#endif - #ifdef Q_WS_WINCE +#include <shlobj.h> #include <commdlg.h> -# ifndef BFFM_SETSELECTION -# define BFFM_SETSELECTION (WM_USER + 102) -# endif -// Windows Mobile has a broken definition for BROWSEINFO -// Only compile fix -typedef struct qt_priv_browseinfo { - HWND hwndOwner; - LPCITEMIDLIST pidlRoot; - LPWSTR pszDisplayName; - LPCWSTR lpszTitle; - UINT ulFlags; - BFFCALLBACK lpfn; - LPARAM lParam; - int iImage; -} qt_BROWSEINFO; bool qt_priv_ptr_valid = false; +#else +//we have to declare them here because they're not present for all SDK/compilers +static const IID QT_IID_IFileOpenDialog = {0xd57c7288, 0xd4ad, 0x4768, {0xbe, 0x02, 0x9d, 0x96, 0x95, 0x32, 0xd9, 0x60} }; +static const IID QT_IID_IShellItem = {0x43826d1e, 0xe718, 0x42ee, {0xbc, 0x55, 0xa1, 0xe2, 0x61, 0xc3, 0x7b, 0xfe} }; +static const CLSID QT_CLSID_FileOpenDialog = {0xdc1c5a9c, 0xe88a, 0x4dde, {0xa5, 0xa1, 0x60, 0xf8, 0x2a, 0x20, 0xae, 0xf7} }; #endif -// Don't remove the lines below! -// -// resolving the W methods manually is needed, because Windows 95 doesn't include -// these methods in Shell32.lib (not even stubs!), so you'd get an unresolved symbol -// when Qt calls getExistingDirectory(), etc. -typedef LPITEMIDLIST (WINAPI *PtrSHBrowseForFolder)(BROWSEINFO*); +typedef qt_LPITEMIDLIST (WINAPI *PtrSHBrowseForFolder)(qt_BROWSEINFO*); static PtrSHBrowseForFolder ptrSHBrowseForFolder = 0; -typedef BOOL (WINAPI *PtrSHGetPathFromIDList)(LPITEMIDLIST,LPWSTR); +typedef BOOL (WINAPI *PtrSHGetPathFromIDList)(qt_LPITEMIDLIST, LPWSTR); static PtrSHGetPathFromIDList ptrSHGetPathFromIDList = 0; typedef HRESULT (WINAPI *PtrSHGetMalloc)(LPMALLOC *); static PtrSHGetMalloc ptrSHGetMalloc = 0; @@ -132,7 +106,7 @@ static void qt_win_resolve_libs() ptrSHGetMalloc = (PtrSHGetMalloc) lib.resolve("SHGetMalloc"); #else // CE stores them in a different lib and does not use unicode version - HINSTANCE handle = LoadLibraryW(L"Ceshell"); + HINSTANCE handle = LoadLibrary(L"Ceshell"); ptrSHBrowseForFolder = (PtrSHBrowseForFolder)GetProcAddress(handle, L"SHBrowseForFolder"); ptrSHGetPathFromIDList = (PtrSHGetPathFromIDList)GetProcAddress(handle, L"SHGetPathFromIDList"); ptrSHGetMalloc = (PtrSHGetMalloc)GetProcAddress(handle, L"SHGetMalloc"); @@ -421,7 +395,7 @@ QString qt_win_get_save_file_name(const QFileDialogArgs &args, } -#if defined(USE_COMMON_ITEM_DIALOG) +#ifndef Q_WS_WINCE typedef HRESULT (WINAPI *PtrSHCreateItemFromParsingName)(PCWSTR pszPath, IBindCtx *pbc, REFIID riid, void **ppv); static PtrSHCreateItemFromParsingName pSHCreateItemFromParsingName = 0; @@ -469,7 +443,7 @@ static bool qt_win_set_IFileDialogOptions(IFileDialog *pfd, // Add the filters to the file dialog. if (numFilters) { wchar_t *szData = (wchar_t*)winfilters.utf16(); - COMDLG_FILTERSPEC *filterSpec = new COMDLG_FILTERSPEC[numFilters]; + qt_COMDLG_FILTERSPEC *filterSpec = new qt_COMDLG_FILTERSPEC[numFilters]; for(int i = 0; i<numFilters; i++) { filterSpec[i].pszName = szData+offsets[i*2]; filterSpec[i].pszSpec = szData+offsets[(i*2)+1]; @@ -481,9 +455,8 @@ static bool qt_win_set_IFileDialogOptions(IFileDialog *pfd, tInitDir = QDir::toNativeSeparators(initialDirectory); if (!tInitDir.isEmpty()) { IShellItem *psiDefaultFolder; - hr = pSHCreateItemFromParsingName((wchar_t*)tInitDir.utf16(), - NULL, - IID_PPV_ARGS(&psiDefaultFolder)); + hr = pSHCreateItemFromParsingName((wchar_t*)tInitDir.utf16(), NULL, QT_IID_IShellItem, + reinterpret_cast<void**>(&psiDefaultFolder)); if (SUCCEEDED(hr)) { hr = pfd->SetFolder(psiDefaultFolder); @@ -522,7 +495,7 @@ static bool qt_win_set_IFileDialogOptions(IFileDialog *pfd, return SUCCEEDED(hr); } -QStringList qt_win_CID_get_open_file_names(const QFileDialogArgs &args, +static QStringList qt_win_CID_get_open_file_names(const QFileDialogArgs &args, QString *initialDirectory, const QStringList &filterList, QString *selectedFilter, @@ -535,10 +508,8 @@ QStringList qt_win_CID_get_open_file_names(const QFileDialogArgs &args, QApplicationPrivate::enterModal(&modal_widget); // Multiple selection is allowed only in IFileOpenDialog. IFileOpenDialog *pfd = 0; - HRESULT hr = CoCreateInstance(CLSID_FileOpenDialog, - NULL, - CLSCTX_INPROC_SERVER, - IID_PPV_ARGS(&pfd)); + HRESULT hr = CoCreateInstance(QT_CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER, QT_IID_IFileOpenDialog, + reinterpret_cast<void**>(&pfd)); if (SUCCEEDED(hr)) { qt_win_set_IFileDialogOptions(pfd, args.selection, @@ -643,7 +614,7 @@ QStringList qt_win_get_open_file_names(const QFileDialogArgs &args, // multiple files belonging to different folders from these search results, the // GetOpenFileName() will return only one folder name for all the files. To retrieve // the correct path for all selected files, we have to use Common Item Dialog interfaces. -#if defined(USE_COMMON_ITEM_DIALOG) +#ifndef Q_WS_WINCE if (QSysInfo::WindowsVersion >= QSysInfo::WV_VISTA && QSysInfo::WindowsVersion < QSysInfo::WV_NT_based) return qt_win_CID_get_open_file_names(args, initialDirectory, filterLst, selectedFilter, idx); #endif @@ -716,7 +687,7 @@ static int __stdcall winGetExistDirCallbackProc(HWND hwnd, qt_win_resolve_libs(); if (ptrSHGetPathFromIDList) { wchar_t path[MAX_PATH]; - ptrSHGetPathFromIDList(LPITEMIDLIST(lParam), path); + ptrSHGetPathFromIDList(qt_LPITEMIDLIST(lParam), path); QString tmpStr = QString::fromWCharArray(path); if (!tmpStr.isEmpty()) SendMessage(hwnd, BFFM_ENABLEOK, 1, 1); @@ -728,11 +699,6 @@ static int __stdcall winGetExistDirCallbackProc(HWND hwnd, return 0; } -#ifndef BIF_NEWDIALOGSTYLE -#define BIF_NEWDIALOGSTYLE 0x0040 // Use the new dialog layout with the ability to resize -#endif - - QString qt_win_get_existing_directory(const QFileDialogArgs &args) { QString currentDir = QDir::currentPath(); @@ -757,11 +723,7 @@ QString qt_win_get_existing_directory(const QFileDialogArgs &args) path[0] = 0; tTitle = args.caption; -#if !defined(Q_WS_WINCE) - BROWSEINFO bi; -#else qt_BROWSEINFO bi; -#endif Q_ASSERT(!parent ||parent->testAttribute(Qt::WA_WState_Created)); bi.hwndOwner = (parent ? parent->winId() : 0); @@ -775,7 +737,7 @@ QString qt_win_get_existing_directory(const QFileDialogArgs &args) qt_win_resolve_libs(); if (ptrSHBrowseForFolder) { - LPITEMIDLIST pItemIDList = ptrSHBrowseForFolder((BROWSEINFO*)&bi); + qt_LPITEMIDLIST pItemIDList = ptrSHBrowseForFolder(&bi); if (pItemIDList) { ptrSHGetPathFromIDList(pItemIDList, path); IMalloc *pMalloc; diff --git a/src/gui/dialogs/qfiledialog_win_p.h b/src/gui/dialogs/qfiledialog_win_p.h new file mode 100644 index 0000000..527ab3f --- /dev/null +++ b/src/gui/dialogs/qfiledialog_win_p.h @@ -0,0 +1,243 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtGui module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <objbase.h> +#ifndef QFILEDIAG_WIN_P_H +#define QFILEDIAG_WIN_P_H + +//these are the interface declarations needed for the file dialog on Vista and up + +//At some point we can hope that all compilers/sdk will support that interface +//and we won't have to declare it ourselves + +//declarations +#define FOS_OVERWRITEPROMPT 0x2 +#define FOS_STRICTFILETYPES 0x4 +#define FOS_NOCHANGEDIR 0x8 +#define FOS_PICKFOLDERS 0x20 +#define FOS_FORCEFILESYSTEM 0x40 +#define FOS_ALLNONSTORAGEITEMS 0x80 +#define FOS_NOVALIDATE 0x100 +#define FOS_ALLOWMULTISELECT 0x200 +#define FOS_PATHMUSTEXIST 0x800 +#define FOS_FILEMUSTEXIST 0x1000 +#define FOS_CREATEPROMPT 0x2000 +#define FOS_SHAREAWARE 0x4000 +#define FOS_NOREADONLYRETURN 0x8000 +#define FOS_NOTESTFILECREATE 0x10000 +#define FOS_HIDEMRUPLACES 0x20000 +#define FOS_HIDEPINNEDPLACES 0x40000 +#define FOS_NODEREFERENCELINKS 0x100000 +#define FOS_DONTADDTORECENT 0x2000000 +#define FOS_FORCESHOWHIDDEN 0x10000000 +#define FOS_DEFAULTNOMINIMODE 0x20000000 +#define FOS_FORCEPREVIEWPANEON 0x40000000 + +typedef int GETPROPERTYSTOREFLAGS; +#define GPS_DEFAULT 0x00000000 +#define GPS_HANDLERPROPERTIESONLY 0x00000001 +#define GPS_READWRITE 0x00000002 +#define GPS_TEMPORARY 0x00000004 +#define GPS_FASTPROPERTIESONLY 0x00000008 +#define GPS_OPENSLOWITEM 0x00000010 +#define GPS_DELAYCREATION 0x00000020 +#define GPS_BESTEFFORT 0x00000040 +#define GPS_MASK_VALID 0x0000007F + +typedef int (CALLBACK* BFFCALLBACK)(HWND hwnd, UINT uMsg, LPARAM lParam, LPARAM lpData); +// message from browser +#define BFFM_INITIALIZED 1 +#define BFFM_SELCHANGED 2 +#define BFFM_ENABLEOK (WM_USER + 101) +#define BFFM_SETSELECTION (WM_USER + 103) +#define BFFM_SETSTATUSTEXT (WM_USER + 104) + +// Browsing for directory. +#define BIF_RETURNONLYFSDIRS 0x0001 +#define BIF_DONTGOBELOWDOMAIN 0x0002 +#define BIF_STATUSTEXT 0x0004 +#define BIF_RETURNFSANCESTORS 0x0008 +#define BIF_EDITBOX 0x0010 +#define BIF_VALIDATE 0x0020 +#define BIF_NEWDIALOGSTYLE 0x0040 +#define BIF_BROWSEINCLUDEURLS 0x0080 +#define BIF_UAHINT 0x0100 +#define BIF_NONEWFOLDERBUTTON 0x0200 +#define BIF_NOTRANSLATETARGETS 0x0400 +#define BIF_BROWSEFORCOMPUTER 0x1000 +#define BIF_BROWSEFORPRINTER 0x2000 +#define BIF_BROWSEINCLUDEFILES 0x4000 +#define BIF_SHAREABLE 0x8000 + +//the enums +typedef enum { + SIATTRIBFLAGS_AND = 0x1, + SIATTRIBFLAGS_OR = 0x2, + SIATTRIBFLAGS_APPCOMPAT = 0x3, + SIATTRIBFLAGS_MASK = 0x3 +} SIATTRIBFLAGS; +typedef enum { + SIGDN_NORMALDISPLAY = 0x00000000, + SIGDN_PARENTRELATIVEPARSING = 0x80018001, + SIGDN_PARENTRELATIVEFORADDRESSBAR = 0x8001c001, + SIGDN_DESKTOPABSOLUTEPARSING = 0x80028000, + SIGDN_PARENTRELATIVEEDITING = 0x80031001, + SIGDN_DESKTOPABSOLUTEEDITING = 0x8004c000, + SIGDN_FILESYSPATH = 0x80058000, + SIGDN_URL = 0x80068000 +} SIGDN; +typedef enum { + FDAP_BOTTOM = 0x00000000, + FDAP_TOP = 0x00000001 +} FDAP; +typedef enum { + FDESVR_DEFAULT = 0x00000000, + FDESVR_ACCEPT = 0x00000001, + FDESVR_REFUSE = 0x00000002 +} FDE_SHAREVIOLATION_RESPONSE; +typedef FDE_SHAREVIOLATION_RESPONSE FDE_OVERWRITE_RESPONSE; + +//the structs +typedef struct { + LPCWSTR pszName; + LPCWSTR pszSpec; +} qt_COMDLG_FILTERSPEC; +typedef struct { + GUID fmtid; + DWORD pid; +} qt_PROPERTYKEY; + +typedef struct { + USHORT cb; + BYTE abID[1]; +} qt_SHITEMID, *qt_LPSHITEMID; +typedef struct { + qt_SHITEMID mkid; +} qt_ITEMIDLIST, *qt_LPITEMIDLIST; +typedef const qt_ITEMIDLIST *qt_LPCITEMIDLIST; +typedef struct { + HWND hwndOwner; + qt_LPCITEMIDLIST pidlRoot; + LPWSTR pszDisplayName; + LPCWSTR lpszTitle; + UINT ulFlags; + BFFCALLBACK lpfn; + LPARAM lParam; + int iImage; +} qt_BROWSEINFO; + +DECLARE_INTERFACE(IFileDialogEvents); +DECLARE_INTERFACE_(IShellItem, IUnknown) +{ + STDMETHOD(BindToHandler)(THIS_ IBindCtx *pbc, REFGUID bhid, REFIID riid, void **ppv) PURE; + STDMETHOD(GetParent)(THIS_ IShellItem **ppsi) PURE; + STDMETHOD(GetDisplayName)(THIS_ SIGDN sigdnName, LPWSTR *ppszName) PURE; + STDMETHOD(GetAttributes)(THIS_ ULONG sfgaoMask, ULONG *psfgaoAttribs) PURE; + STDMETHOD(Compare)(THIS_ IShellItem *psi, DWORD hint, int *piOrder) PURE; +}; +DECLARE_INTERFACE_(IShellItemFilter, IUnknown) +{ + STDMETHOD(IncludeItem)(THIS_ IShellItem *psi) PURE; + STDMETHOD(GetEnumFlagsForItem)(THIS_ IShellItem *psi, DWORD *pgrfFlags) PURE; +}; +DECLARE_INTERFACE_(IEnumShellItems, IUnknown) +{ + STDMETHOD(Next)(THIS_ ULONG celt, IShellItem **rgelt, ULONG *pceltFetched) PURE; + STDMETHOD(Skip)(THIS_ ULONG celt) PURE; + STDMETHOD(Reset)(THIS_) PURE; + STDMETHOD(Clone)(THIS_ IEnumShellItems **ppenum) PURE; +}; +DECLARE_INTERFACE_(IShellItemArray, IUnknown) +{ + STDMETHOD(BindToHandler)(THIS_ IBindCtx *pbc, REFGUID rbhid, REFIID riid, void **ppvOut) PURE; + STDMETHOD(GetPropertyStore)(THIS_ GETPROPERTYSTOREFLAGS flags, REFIID riid, void **ppv) PURE; + STDMETHOD(GetPropertyDescriptionList)(THIS_ const qt_PROPERTYKEY *keyType, REFIID riid, void **ppv) PURE; + STDMETHOD(GetAttributes)(THIS_ SIATTRIBFLAGS dwAttribFlags, ULONG sfgaoMask, ULONG *psfgaoAttribs) PURE; + STDMETHOD(GetCount)(THIS_ DWORD *pdwNumItems) PURE; + STDMETHOD(GetItemAt)(THIS_ DWORD dwIndex, IShellItem **ppsi) PURE; + STDMETHOD(EnumItems)(THIS_ IEnumShellItems **ppenumShellItems) PURE; +}; +DECLARE_INTERFACE_(IModalWindow, IUnknown) +{ + STDMETHOD(Show)(THIS_ HWND hwndParent) PURE; +}; +DECLARE_INTERFACE_(IFileDialog, IModalWindow) +{ + STDMETHOD(SetFileTypes)(THIS_ UINT cFileTypes, const qt_COMDLG_FILTERSPEC *rgFilterSpec) PURE; + STDMETHOD(SetFileTypeIndex)(THIS_ UINT iFileType) PURE; + STDMETHOD(GetFileTypeIndex)(THIS_ UINT *piFileType) PURE; + STDMETHOD(Advise)(THIS_ IFileDialogEvents *pfde, DWORD *pdwCookie) PURE; + STDMETHOD(Unadvise)(THIS_ DWORD dwCookie) PURE; + STDMETHOD(SetOptions)(THIS_ DWORD fos) PURE; + STDMETHOD(GetOptions)(THIS_ DWORD *pfos) PURE; + STDMETHOD(SetDefaultFolder)(THIS_ IShellItem *psi) PURE; + STDMETHOD(SetFolder)(THIS_ IShellItem *psi) PURE; + STDMETHOD(GetFolder)(THIS_ IShellItem **ppsi) PURE; + STDMETHOD(GetCurrentSelection)(THIS_ IShellItem **ppsi) PURE; + STDMETHOD(SetFileName)(THIS_ LPCWSTR pszName) PURE; + STDMETHOD(GetFileName)(THIS_ LPWSTR *pszName) PURE; + STDMETHOD(SetTitle)(THIS_ LPCWSTR pszTitle) PURE; + STDMETHOD(SetOkButtonLabel)(THIS_ LPCWSTR pszText) PURE; + STDMETHOD(SetFileNameLabel)(THIS_ LPCWSTR pszLabel) PURE; + STDMETHOD(GetResult)(THIS_ IShellItem **ppsi) PURE; + STDMETHOD(AddPlace)(THIS_ IShellItem *psi, FDAP fdap) PURE; + STDMETHOD(SetDefaultExtension)(THIS_ LPCWSTR pszDefaultExtension) PURE; + STDMETHOD(Close)(THIS_ HRESULT hr) PURE; + STDMETHOD(SetClientGuid)(THIS_ REFGUID guid) PURE; + STDMETHOD(ClearClientData)(THIS_) PURE; + STDMETHOD(SetFilter)(THIS_ IShellItemFilter *pFilter) PURE; +}; +DECLARE_INTERFACE_(IFileDialogEvents, IUnknown) +{ + STDMETHOD(OnFileOk)(THIS_ IFileDialog *pfd) PURE; + STDMETHOD(OnFolderChanging)(THIS_ IFileDialog *pfd, IShellItem *psiFolder) PURE; + STDMETHOD(OnFolderChange)(THIS_ IFileDialog *pfd) PURE; + STDMETHOD(OnSelectionChange)(THIS_ IFileDialog *pfd) PURE; + STDMETHOD(OnShareViolation)(THIS_ IFileDialog *pfd, IShellItem *psi, FDE_SHAREVIOLATION_RESPONSE *pResponse) PURE; + STDMETHOD(OnTypeChange)(THIS_ IFileDialog *pfd) PURE; + STDMETHOD(OnOverwrite)(THIS_ IFileDialog *pfd, IShellItem *psi, FDE_OVERWRITE_RESPONSE *pResponse) PURE; +}; +DECLARE_INTERFACE_(IFileOpenDialog, IFileDialog) +{ + STDMETHOD(GetResults)(THIS_ IShellItemArray **ppenum) PURE; + STDMETHOD(GetSelectedItems)(THIS_ IShellItemArray **ppsai) PURE; +}; +#endif
\ No newline at end of file diff --git a/src/gui/dialogs/qfileinfogatherer.cpp b/src/gui/dialogs/qfileinfogatherer.cpp index 1f61957..c75cdfd 100644 --- a/src/gui/dialogs/qfileinfogatherer.cpp +++ b/src/gui/dialogs/qfileinfogatherer.cpp @@ -354,6 +354,7 @@ void QFileInfoGatherer::getFileInfos(const QString &path, const QStringList &fil } if (!updatedFiles.isEmpty()) emit updates(path, updatedFiles); + emit directoryLoaded(path); } void QFileInfoGatherer::fetch(const QFileInfo &fileInfo, QTime &base, bool &firstTime, QList<QPair<QString, QFileInfo> > &updatedFiles, const QString &path) { diff --git a/src/gui/dialogs/qfileinfogatherer_p.h b/src/gui/dialogs/qfileinfogatherer_p.h index 0242178..b8b58a2 100644 --- a/src/gui/dialogs/qfileinfogatherer_p.h +++ b/src/gui/dialogs/qfileinfogatherer_p.h @@ -155,6 +155,7 @@ Q_SIGNALS: void updates(const QString &directory, const QList<QPair<QString, QFileInfo> > &updates); void newListOfFiles(const QString &directory, const QStringList &listOfFiles) const; void nameResolved(const QString &fileName, const QString &resolvedName) const; + void directoryLoaded(const QString &path); public: QFileInfoGatherer(QObject *parent = 0); diff --git a/src/gui/dialogs/qfilesystemmodel.cpp b/src/gui/dialogs/qfilesystemmodel.cpp index 6fd947c..0e1837b 100644 --- a/src/gui/dialogs/qfilesystemmodel.cpp +++ b/src/gui/dialogs/qfilesystemmodel.cpp @@ -150,6 +150,14 @@ QT_BEGIN_NAMESPACE */ /*! + \since 4.7 + \fn void QFileSystemModel::directoryLoaded(const QString &path) + + This signal is emitted when the gatherer thread has finished to load the \a path. + +*/ + +/*! \fn bool QFileSystemModel::remove(const QModelIndex &index) const Removes the model item \a index from the file system model and \bold{deletes the @@ -673,7 +681,7 @@ QVariant QFileSystemModel::data(const QModelIndex &index, int role) const case Qt::EditRole: case Qt::DisplayRole: switch (index.column()) { - case 0: return d->name(index); + case 0: return d->displayName(index); case 1: return d->size(index); case 2: return d->type(index); case 3: return d->time(index); @@ -789,13 +797,25 @@ QString QFileSystemModelPrivate::name(const QModelIndex &index) const if (resolvedSymLinks.contains(fullPath)) return resolvedSymLinks[fullPath]; } - // ### TODO it would be nice to grab the volume name if dirNode->parent == root return dirNode->fileName; } /*! \internal */ +QString QFileSystemModelPrivate::displayName(const QModelIndex &index) const +{ +#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) + QFileSystemNode *dirNode = node(index); + if (!dirNode->volumeName.isNull()) + return dirNode->volumeName + QLatin1String(" (") + name(index) + QLatin1Char(')'); +#endif + return name(index); +} + +/*! + \internal +*/ QIcon QFileSystemModelPrivate::icon(const QModelIndex &index) const { if (!index.isValid()) @@ -1640,6 +1660,18 @@ QFileSystemModelPrivate::QFileSystemNode* QFileSystemModelPrivate::addNode(QFile #ifndef QT_NO_FILESYSTEMWATCHER node->populate(info); #endif +#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) + //The parentNode is "" so we are listing the drives + if (parentNode->fileName.isEmpty()) { + wchar_t name[MAX_PATH + 1]; + //GetVolumeInformation requires to add trailing backslash + const QString nodeName = fileName + QLatin1String("\\"); + BOOL success = ::GetVolumeInformation((wchar_t *)(nodeName.utf16()), + name, MAX_PATH + 1, NULL, 0, NULL, NULL, 0); + if (success && name[0]) + node->volumeName = QString::fromWCharArray(name); + } +#endif parentNode->children.insert(fileName, node); return node; } @@ -1869,6 +1901,8 @@ void QFileSystemModelPrivate::init() q, SLOT(_q_fileSystemChanged(QString,QList<QPair<QString,QFileInfo> >))); q->connect(&fileInfoGatherer, SIGNAL(nameResolved(QString,QString)), q, SLOT(_q_resolvedName(QString,QString))); + q->connect(&fileInfoGatherer, SIGNAL(directoryLoaded(QString)), + q, SIGNAL(directoryLoaded(QString))); q->connect(&delayedSortTimer, SIGNAL(timeout()), q, SLOT(_q_performDelayedSort()), Qt::QueuedConnection); } diff --git a/src/gui/dialogs/qfilesystemmodel.h b/src/gui/dialogs/qfilesystemmodel.h index 4dcfe26..d8178c7 100644 --- a/src/gui/dialogs/qfilesystemmodel.h +++ b/src/gui/dialogs/qfilesystemmodel.h @@ -70,6 +70,7 @@ class Q_GUI_EXPORT QFileSystemModel : public QAbstractItemModel Q_SIGNALS: void rootPathChanged(const QString &newPath); void fileRenamed(const QString &path, const QString &oldName, const QString &newName); + void directoryLoaded(const QString &path); public: enum Roles { diff --git a/src/gui/dialogs/qfilesystemmodel_p.h b/src/gui/dialogs/qfilesystemmodel_p.h index 6c85a7c..03e0bfb 100644 --- a/src/gui/dialogs/qfilesystemmodel_p.h +++ b/src/gui/dialogs/qfilesystemmodel_p.h @@ -97,6 +97,9 @@ public: } QString fileName; +#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) + QString volumeName; +#endif inline qint64 size() const { if (info && !info->isDir()) return info->size(); return 0; } inline QString type() const { if (info) return info->displayType; return QLatin1String(""); } @@ -278,6 +281,7 @@ public: QIcon icon(const QModelIndex &index) const; QString name(const QModelIndex &index) const; + QString displayName(const QModelIndex &index) const; QString filePath(const QModelIndex &index) const; QString size(const QModelIndex &index) const; static QString size(qint64 bytes); diff --git a/src/gui/dialogs/qprintdialog_win.cpp b/src/gui/dialogs/qprintdialog_win.cpp index 5ccd33d..fa0c99f 100644 --- a/src/gui/dialogs/qprintdialog_win.cpp +++ b/src/gui/dialogs/qprintdialog_win.cpp @@ -52,7 +52,7 @@ #include <private/qprintengine_win_p.h> #include <private/qprinter_p.h> -#if defined(Q_CC_MINGW) && !defined(PD_NOCURRENTPAGE) +#if !defined(PD_NOCURRENTPAGE) #define PD_NOCURRENTPAGE 0x00800000 #define PD_RESULT_PRINT 1 #define PD_RESULT_APPLY 2 diff --git a/src/gui/embedded/qscreen_qws.cpp b/src/gui/embedded/qscreen_qws.cpp index 8eb8123..65a3fb5 100644 --- a/src/gui/embedded/qscreen_qws.cpp +++ b/src/gui/embedded/qscreen_qws.cpp @@ -39,6 +39,7 @@ ** ****************************************************************************/ +#include "qplatformdefs.h" #include "qscreen_qws.h" #include "qcolormap.h" @@ -3223,13 +3224,13 @@ QScreen * qt_probe_bus() return qt_dodriver("unaccel.so",0,0); } - DIR * dirptr=opendir("/proc/bus/pci"); + QT_DIR *dirptr = QT_OPENDIR("/proc/bus/pci"); if(!dirptr) return qt_dodriver("unaccel.so",0,0); - DIR * dirptr2; - dirent * cards; + QT_DIR * dirptr2; + QT_DIRENT *cards; - dirent * busses=readdir(dirptr); + QT_DIRENT *busses = QT_READDIR(dirptr); while(busses) { if(busses->d_name[0]!='.') { @@ -3237,9 +3238,9 @@ QScreen * qt_probe_bus() strcpy(buf,"/proc/bus/pci/"); qstrcpy(buf+14,busses->d_name); int p=strlen(buf); - dirptr2=opendir(buf); + dirptr2 = QT_OPENDIR(buf); if(dirptr2) { - cards=readdir(dirptr2); + cards = QT_READDIR(dirptr2); while(cards) { if(cards->d_name[0]!='.') { buf[p]='/'; @@ -3248,14 +3249,14 @@ QScreen * qt_probe_bus() if(ret) return ret; } - cards=readdir(dirptr2); + cards = QT_READDIR(dirptr2); } - closedir(dirptr2); + QT_CLOSEDIR(dirptr2); } } - busses=readdir(dirptr); + busses = QT_READDIR(dirptr); } - closedir(dirptr); + QT_CLOSEDIR(dirptr); return qt_dodriver("unaccel.so",0,0); } diff --git a/src/gui/graphicsview/qgraphicsscene.cpp b/src/gui/graphicsview/qgraphicsscene.cpp index 54d47fa..478669e 100644 --- a/src/gui/graphicsview/qgraphicsscene.cpp +++ b/src/gui/graphicsview/qgraphicsscene.cpp @@ -4234,6 +4234,8 @@ static void _q_paintItem(QGraphicsItem *item, QPainter *painter, widgetItem->paintWindowFrame(painter, option, widget); if (painterStateProtection) painter->restore(); + } else if (widgetItem->autoFillBackground()) { + painter->fillRect(option->exposedRect, widgetItem->palette().window()); } widgetItem->paint(painter, option, widget); diff --git a/src/gui/graphicsview/qgraphicswidget.cpp b/src/gui/graphicsview/qgraphicswidget.cpp index 5e01785..87416b4 100644 --- a/src/gui/graphicsview/qgraphicswidget.cpp +++ b/src/gui/graphicsview/qgraphicswidget.cpp @@ -967,6 +967,36 @@ void QGraphicsWidget::setPalette(const QPalette &palette) } /*! + \property QGraphicsWidget::autoFillBackground + \brief whether the widget background is filled automatically + \since 4.7 + + If enabled, this property will cause Qt to fill the background of the + widget before invoking the paint() method. The color used is defined by the + QPalette::Window color role from the widget's \l{QPalette}{palette}. + + In addition, Windows are always filled with QPalette::Window, unless the + WA_OpaquePaintEvent or WA_NoSystemBackground attributes are set. + + By default, this property is false. + + \sa Qt::WA_OpaquePaintEvent, Qt::WA_NoSystemBackground, +*/ +bool QGraphicsWidget::autoFillBackground() const +{ + Q_D(const QGraphicsWidget); + return d->autoFillBackground; +} +void QGraphicsWidget::setAutoFillBackground(bool enabled) +{ + Q_D(QGraphicsWidget); + if (d->autoFillBackground != enabled) { + d->autoFillBackground = enabled; + update(); + } +} + +/*! If this widget is currently managed by a layout, this function notifies the layout that the widget's size hints have changed and the layout may need to resize and reposition the widget accordingly. diff --git a/src/gui/graphicsview/qgraphicswidget.h b/src/gui/graphicsview/qgraphicswidget.h index f1d382b..4bea5be 100644 --- a/src/gui/graphicsview/qgraphicswidget.h +++ b/src/gui/graphicsview/qgraphicswidget.h @@ -82,6 +82,7 @@ class Q_GUI_EXPORT QGraphicsWidget : public QGraphicsObject, public QGraphicsLay Q_PROPERTY(Qt::WindowFlags windowFlags READ windowFlags WRITE setWindowFlags) Q_PROPERTY(QString windowTitle READ windowTitle WRITE setWindowTitle) Q_PROPERTY(QRectF geometry READ geometry WRITE setGeometry) + Q_PROPERTY(bool autoFillBackground READ autoFillBackground WRITE setAutoFillBackground) public: QGraphicsWidget(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0); ~QGraphicsWidget(); @@ -103,6 +104,9 @@ public: QPalette palette() const; void setPalette(const QPalette &palette); + bool autoFillBackground() const; + void setAutoFillBackground(bool enabled); + void resize(const QSizeF &size); inline void resize(qreal w, qreal h) { resize(QSizeF(w, h)); } QSizeF size() const; diff --git a/src/gui/graphicsview/qgraphicswidget_p.h b/src/gui/graphicsview/qgraphicswidget_p.h index 2c5b3bf..3ab8737 100644 --- a/src/gui/graphicsview/qgraphicswidget_p.h +++ b/src/gui/graphicsview/qgraphicswidget_p.h @@ -80,6 +80,7 @@ public: inSetGeometry(0), polished(0), inSetPos(0), + autoFillBackground(0), focusPolicy(Qt::NoFocus), focusNext(0), focusPrev(0), @@ -172,6 +173,7 @@ public: quint32 inSetGeometry : 1; quint32 polished: 1; quint32 inSetPos : 1; + quint32 autoFillBackground : 1; // Focus Qt::FocusPolicy focusPolicy; diff --git a/src/gui/image/qimage.cpp b/src/gui/image/qimage.cpp index 4f5efa1..6bcf72b 100644 --- a/src/gui/image/qimage.cpp +++ b/src/gui/image/qimage.cpp @@ -1835,7 +1835,7 @@ void QImage::setColor(int i, QRgb c) qAlpha() to access the pixels. \sa bytesPerLine(), bits(), {QImage#Pixel Manipulation}{Pixel - Manipulation} + Manipulation}, constScanLine() */ uchar *QImage::scanLine(int i) { @@ -1865,6 +1865,28 @@ const uchar *QImage::scanLine(int i) const /*! + Returns a pointer to the pixel data at the scanline with index \a + i. The first scanline is at index 0. + + The scanline data is aligned on a 32-bit boundary. + + Note that QImage uses \l{Implicit Data Sharing} {implicit data + sharing}, but this function does \e not perform a deep copy of the + shared pixel data, because the returned data is const. + + \sa scanLine(), constBits() + \since 4.7 +*/ +const uchar *QImage::constScanLine(int i) const +{ + if (!d) + return 0; + + Q_ASSERT(i >= 0 && i < height()); + return d->data + i * d->bytes_per_line; +} + +/*! Returns a pointer to the first pixel data. This is equivalent to scanLine(0). @@ -1873,7 +1895,7 @@ const uchar *QImage::scanLine(int i) const data, thus ensuring that this QImage is the only one using the current return value. - \sa scanLine(), byteCount() + \sa scanLine(), byteCount(), constBits() */ uchar *QImage::bits() { @@ -1901,6 +1923,20 @@ const uchar *QImage::bits() const } +/*! + Returns a pointer to the first pixel data. + + Note that QImage uses \l{Implicit Data Sharing} {implicit data + sharing}, but this function does \e not perform a deep copy of the + shared pixel data, because the returned data is const. + + \sa bits(), constScanLine() + \since 4.7 +*/ +const uchar *QImage::constBits() const +{ + return d ? d->data : 0; +} /*! \fn void QImage::reset() diff --git a/src/gui/image/qimage.h b/src/gui/image/qimage.h index ac973a1..dd13782 100644 --- a/src/gui/image/qimage.h +++ b/src/gui/image/qimage.h @@ -182,6 +182,7 @@ public: uchar *bits(); const uchar *bits() const; + const uchar *constBits() const; #ifdef QT_DEPRECATED QT_DEPRECATED int numBytes() const; #endif @@ -189,6 +190,7 @@ public: uchar *scanLine(int); const uchar *scanLine(int) const; + const uchar *constScanLine(int) const; int bytesPerLine() const; bool valid(int x, int y) const; diff --git a/src/gui/image/qpicture.cpp b/src/gui/image/qpicture.cpp index fb70e36..3220a67 100644 --- a/src/gui/image/qpicture.cpp +++ b/src/gui/image/qpicture.cpp @@ -440,36 +440,6 @@ bool QPicture::play(QPainter *painter) return true; // no end-command } - -// -// QFakeDevice is used to create fonts with a custom DPI -// -class QFakeDevice : public QPaintDevice -{ -public: - QFakeDevice() { dpi_x = qt_defaultDpiX(); dpi_y = qt_defaultDpiY(); } - void setDpiX(int dpi) { dpi_x = dpi; } - void setDpiY(int dpi) { dpi_y = dpi; } - QPaintEngine *paintEngine() const { return 0; } - int metric(PaintDeviceMetric m) const - { - switch(m) { - case PdmPhysicalDpiX: - case PdmDpiX: - return dpi_x; - case PdmPhysicalDpiY: - case PdmDpiY: - return dpi_y; - default: - return QPaintDevice::metric(m); - } - } - -private: - int dpi_x; - int dpi_y; -}; - /*! \internal Iterates over the internal picture data and draws the picture using @@ -679,30 +649,29 @@ bool QPicture::exec(QPainter *painter, QDataStream &s, int nrecords) if (d->formatMajor >= 9) { s >> dbl; - QFont fnt(font); - if (dbl != 1.0) { - QFakeDevice fake; - fake.setDpiX(qRound(dbl*qt_defaultDpiX())); - fake.setDpiY(qRound(dbl*qt_defaultDpiY())); - fnt = QFont(font, &fake); - } + QFont fnt(font, painter->device()); + + qreal scale = painter->device()->logicalDpiY() / (dbl*qt_defaultDpiY()); + painter->save(); + painter->scale(1/scale, 1/scale); qreal justificationWidth; s >> justificationWidth; int flags = Qt::TextSingleLine | Qt::TextDontClip | Qt::TextForceLeftToRight; - QSizeF size(1, 1); + QSizeF size(scale, scale); if (justificationWidth > 0) { - size.setWidth(justificationWidth); + size.setWidth(justificationWidth*scale); flags |= Qt::TextJustificationForced; flags |= Qt::AlignJustify; } QFontMetrics fm(fnt); - QPointF pt(p.x(), p.y() - fm.ascent()); + QPointF pt(p.x()*scale, p.y()*scale - fm.ascent()); qt_format_text(fnt, QRectF(pt, size), flags, /*opt*/0, str, /*brect=*/0, /*tabstops=*/0, /*...*/0, /*tabarraylen=*/0, painter); + painter->restore(); } else { qt_format_text(font, QRectF(p, QSizeF(1, 1)), Qt::TextSingleLine | Qt::TextDontClip, /*opt*/0, str, /*brect=*/0, /*tabstops=*/0, /*...*/0, /*tabarraylen=*/0, painter); diff --git a/src/gui/image/qpixmap.cpp b/src/gui/image/qpixmap.cpp index f823fdc..fe03c93 100644 --- a/src/gui/image/qpixmap.cpp +++ b/src/gui/image/qpixmap.cpp @@ -1084,6 +1084,9 @@ QPixmap QPixmap::grabWidget(QWidget * widget, const QRect &rect) if (widget->testAttribute(Qt::WA_PendingResizeEvent) || !widget->testAttribute(Qt::WA_WState_Created)) sendResizeEvents(widget); + widget->d_func()->prepareToRender(QRegion(), + QWidget::DrawWindowBackground | QWidget::DrawChildren | QWidget::IgnoreMask); + QRect r(rect); if (r.width() < 0) r.setWidth(widget->width() - rect.x()); @@ -1094,8 +1097,8 @@ QPixmap QPixmap::grabWidget(QWidget * widget, const QRect &rect) return QPixmap(); QPixmap res(r.size()); - widget->render(&res, QPoint(), r, - QWidget::DrawWindowBackground | QWidget::DrawChildren | QWidget::IgnoreMask); + widget->d_func()->render(&res, QPoint(), r, QWidget::DrawWindowBackground + | QWidget::DrawChildren | QWidget::IgnoreMask, true); return res; } @@ -1376,10 +1379,26 @@ void QPixmap::deref() */ /*! - \fn bool QPixmap::convertFromImage(const QImage &image, Qt::ImageConversionFlags flags) + Replaces this pixmap's data with the given \a image using the specified + \a flags to control the conversion. The \a flags argument is a + bitwise-OR of the \l{Qt::ImageConversionFlags}. Passing 0 for \a + flags sets all the default options. - Use the static fromImage() function instead. + Note: this function was part of Qt 3 support in Qt 4.6 and earlier. + It has been promoted to official API status in 4.7 to support updating + the pixmap's image without creating a new QPixmap as fromImage() would. + + \sa fromImage() + \since 4.7 */ +bool QPixmap::convertFromImage(const QImage &image, Qt::ImageConversionFlags flags) +{ + if (image.isNull() || !data) + *this = QPixmap::fromImage(image, flags); + else + data->fromImage(image, flags); + return !isNull(); +} /*! \fn QPixmap QPixmap::xForm(const QMatrix &matrix) const diff --git a/src/gui/image/qpixmap.h b/src/gui/image/qpixmap.h index 46363f0..180af3b 100644 --- a/src/gui/image/qpixmap.h +++ b/src/gui/image/qpixmap.h @@ -141,6 +141,8 @@ public: bool save(const QString& fileName, const char* format = 0, int quality = -1) const; bool save(QIODevice* device, const char* format = 0, int quality = -1) const; + bool convertFromImage(const QImage &img, Qt::ImageConversionFlags flags = Qt::AutoColor); + #if defined(Q_WS_WIN) enum HBitmapFormat { NoAlpha, @@ -224,8 +226,6 @@ public: QT3_SUPPORT QPixmap &operator=(const QImage &); inline QT3_SUPPORT QImage convertToImage() const { return toImage(); } QT3_SUPPORT bool convertFromImage(const QImage &, ColorMode mode); - QT3_SUPPORT bool convertFromImage(const QImage &img, Qt::ImageConversionFlags flags = Qt::AutoColor) - { (*this) = fromImage(img, flags); return !isNull(); } inline QT3_SUPPORT operator QImage() const { return toImage(); } inline QT3_SUPPORT QPixmap xForm(const QMatrix &matrix) const { return transformed(QTransform(matrix)); } inline QT3_SUPPORT bool selfMask() const { return false; } diff --git a/src/gui/inputmethod/qwininputcontext_p.h b/src/gui/inputmethod/qwininputcontext_p.h index 08cc3d2..d5bedf4 100644 --- a/src/gui/inputmethod/qwininputcontext_p.h +++ b/src/gui/inputmethod/qwininputcontext_p.h @@ -56,7 +56,7 @@ #include "QtGui/qinputcontext.h" #include "QtCore/qt_windows.h" -#if defined(Q_CC_MINGW) && !defined(IMR_RECONVERTSTRING) +#if !defined(IMR_RECONVERTSTRING) typedef struct tagRECONVERTSTRING { DWORD dwSize; DWORD dwVersion; diff --git a/src/gui/itemviews/qdirmodel.cpp b/src/gui/itemviews/qdirmodel.cpp index ea608c1..378a238 100644 --- a/src/gui/itemviews/qdirmodel.cpp +++ b/src/gui/itemviews/qdirmodel.cpp @@ -185,12 +185,12 @@ void QDirModelPrivate::invalidate() /*! \class QDirModel - + \obsolete \brief The QDirModel class provides a data model for the local filesystem. \ingroup model-view - \note The usage of QDirModel is not recommended anymore. The + The usage of QDirModel is not recommended anymore. The QFileSystemModel class is a more performant alternative. This class provides access to the local filesystem, providing functions diff --git a/src/gui/itemviews/qfileiconprovider.cpp b/src/gui/itemviews/qfileiconprovider.cpp index fcc61e5..f321ab3 100644 --- a/src/gui/itemviews/qfileiconprovider.cpp +++ b/src/gui/itemviews/qfileiconprovider.cpp @@ -73,7 +73,7 @@ QT_BEGIN_NAMESPACE /*! \class QFileIconProvider - \brief The QFileIconProvider class provides file icons for the QDirModel class. + \brief The QFileIconProvider class provides file icons for the QDirModel and the QFileSystemModel classes. */ /*! diff --git a/src/gui/itemviews/qsortfilterproxymodel.cpp b/src/gui/itemviews/qsortfilterproxymodel.cpp index 41c984e..e73013c 100644 --- a/src/gui/itemviews/qsortfilterproxymodel.cpp +++ b/src/gui/itemviews/qsortfilterproxymodel.cpp @@ -270,6 +270,11 @@ void QSortFilterProxyModelPrivate::clear_mapping() qDeleteAll(source_index_mapping); source_index_mapping.clear(); + if (dynamic_sortfilter && update_source_sort_column()) { + //update_source_sort_column might have created wrong mapping so we have to clear it again + qDeleteAll(source_index_mapping); + source_index_mapping.clear(); + } // update the persistent indexes update_persistent_indexes(source_indexes); @@ -1208,11 +1213,6 @@ void QSortFilterProxyModelPrivate::_q_sourceLayoutAboutToBeChanged() void QSortFilterProxyModelPrivate::_q_sourceLayoutChanged() { Q_Q(QSortFilterProxyModel); - if (saved_persistent_indexes.isEmpty()) { - clear_mapping(); - emit q->layoutChanged(); - return; - } qDeleteAll(source_index_mapping); source_index_mapping.clear(); @@ -1220,7 +1220,11 @@ void QSortFilterProxyModelPrivate::_q_sourceLayoutChanged() update_persistent_indexes(saved_persistent_indexes); saved_persistent_indexes.clear(); - update_source_sort_column(); + if (dynamic_sortfilter && update_source_sort_column()) { + //update_source_sort_column might have created wrong mapping so we have to clear it again + qDeleteAll(source_index_mapping); + source_index_mapping.clear(); + } emit q->layoutChanged(); } @@ -1481,7 +1485,6 @@ QSortFilterProxyModel::QSortFilterProxyModel(QObject *parent) d->filter_column = 0; d->filter_role = Qt::DisplayRole; d->dynamic_sortfilter = false; - connect(this, SIGNAL(modelReset()), this, SLOT(invalidate())); } /*! diff --git a/src/gui/kernel/kernel.pri b/src/gui/kernel/kernel.pri index 0993b86..6fd45ad 100644 --- a/src/gui/kernel/kernel.pri +++ b/src/gui/kernel/kernel.pri @@ -206,6 +206,7 @@ embedded { OBJECTIVE_HEADERS += \ qcocoawindow_mac_p.h \ + qcocoapanel_mac_p.h \ qcocoawindowdelegate_mac_p.h \ qcocoaview_mac_p.h \ qcocoaapplication_mac_p.h \ diff --git a/src/gui/kernel/qaction.h b/src/gui/kernel/qaction.h index 4341367..538b04f 100644 --- a/src/gui/kernel/qaction.h +++ b/src/gui/kernel/qaction.h @@ -246,6 +246,9 @@ private: friend class QMenuBar; friend class QShortcutMap; friend class QToolButton; +#ifdef Q_WS_MAC + friend void qt_mac_clear_status_text(QAction *action); +#endif }; QT_BEGIN_INCLUDE_NAMESPACE diff --git a/src/gui/kernel/qapplication.cpp b/src/gui/kernel/qapplication.cpp index 4fe3900..b9ea540 100644 --- a/src/gui/kernel/qapplication.cpp +++ b/src/gui/kernel/qapplication.cpp @@ -925,7 +925,7 @@ void QApplicationPrivate::initialize() // Set up which span functions should be used in raster engine... qInitDrawhelperAsm(); - + #if !defined(Q_WS_X11) && !defined(Q_WS_QWS) // initialize the graphics system - on X11 this is initialized inside // qt_init() in qapplication_x11.cpp because of several reasons. diff --git a/src/gui/kernel/qapplication_mac.mm b/src/gui/kernel/qapplication_mac.mm index e8b821af..3fba833 100644 --- a/src/gui/kernel/qapplication_mac.mm +++ b/src/gui/kernel/qapplication_mac.mm @@ -1258,10 +1258,6 @@ void qt_init(QApplicationPrivate *priv, int) [cocoaApp setMenu:[qtMenuLoader menu]]; [newDelegate setMenuLoader:qtMenuLoader]; [qtMenuLoader release]; - - NSAppleEventManager *eventManager = [NSAppleEventManager sharedAppleEventManager]; - [eventManager setEventHandler:newDelegate andSelector:@selector(getUrl:withReplyEvent:) - forEventClass:kInternetEventClass andEventID:kAEGetURL]; } #endif // Register for Carbon tablet proximity events on the event monitor target. @@ -1361,12 +1357,39 @@ void QApplication::setMainWidget(QWidget *mainWidget) /***************************************************************************** QApplication cursor stack *****************************************************************************/ +#ifdef QT_MAC_USE_COCOA +void QApplicationPrivate::disableUsageOfCursorRects(bool disable) +{ + // In Cocoa there are two competing ways of setting the cursor; either + // by using cursor rects (see qcocoaview_mac.mm), or by pushing/popping + // the cursor manually. When we use override cursors, it makes most sense + // to use the latter. But then we need to tell cocoa to stop using the + // first approach so it doesn't change the cursor back when hovering over + // a cursor rect: + QWidgetList topLevels = qApp->topLevelWidgets(); + for (int i=0; i<topLevels.size(); ++i) { + if (NSWindow *window = qt_mac_window_for(topLevels.at(i))) + disable ? [window disableCursorRects] : [window enableCursorRects]; + } +} + +void QApplicationPrivate::updateOverrideCursor() +{ + // Sometimes Cocoa forgets that we have set a Cursor + // manually. In those cases, remind it again: + if (QCursor *override = qApp->overrideCursor()) + [static_cast<NSCursor *>(qt_mac_nsCursorForQCursor(*override)) set]; +} +#endif + void QApplication::setOverrideCursor(const QCursor &cursor) { qApp->d_func()->cursor_list.prepend(cursor); #ifdef QT_MAC_USE_COCOA QMacCocoaAutoReleasePool pool; + if (qApp->d_func()->cursor_list.size() == 1) + qApp->d_func()->disableUsageOfCursorRects(true); [static_cast<NSCursor *>(qt_mac_nsCursorForQCursor(cursor)) push]; #else if (qApp && qApp->activeWindow()) @@ -1383,6 +1406,8 @@ void QApplication::restoreOverrideCursor() #ifdef QT_MAC_USE_COCOA QMacCocoaAutoReleasePool pool; [NSCursor pop]; + if (qApp->d_func()->cursor_list.isEmpty()) + qApp->d_func()->disableUsageOfCursorRects(false); #else if (qApp && qApp->activeWindow()) { const QCursor def(Qt::ArrowCursor); @@ -2455,6 +2480,28 @@ QApplicationPrivate::globalEventProcessor(EventHandlerCallRef er, EventRef event #endif } +#ifdef QT_MAC_USE_COCOA +void QApplicationPrivate::qt_initAfterNSAppStarted() +{ + setupAppleEvents(); + updateOverrideCursor(); +} + +void QApplicationPrivate::setupAppleEvents() +{ + // This function is called from the event dispatcher when NSApplication has + // finished initialization, which appears to be just after [NSApplication run] has + // started to execute. By setting up our apple events handlers this late, we override + // the ones set up by NSApplication. + QT_MANGLE_NAMESPACE(QCocoaApplicationDelegate) *newDelegate = [QT_MANGLE_NAMESPACE(QCocoaApplicationDelegate) sharedDelegate]; + NSAppleEventManager *eventManager = [NSAppleEventManager sharedAppleEventManager]; + [eventManager setEventHandler:newDelegate andSelector:@selector(appleEventQuit:withReplyEvent:) + forEventClass:kCoreEventClass andEventID:kAEQuitApplication]; + [eventManager setEventHandler:newDelegate andSelector:@selector(getUrl:withReplyEvent:) + forEventClass:kInternetEventClass andEventID:kAEGetURL]; +} +#endif + // In Carbon this is your one stop for apple events. // In Cocoa, it ISN'T. This is the catch-all Apple Event handler that exists // for the time between instantiating the NSApplication, but before the @@ -3002,7 +3049,7 @@ void onApplicationWindowChangedActivation(QWidget *widget, bool activated) } QMenuBar::macUpdateMenuBar(); - + QApplicationPrivate::updateOverrideCursor(); #else Q_UNUSED(widget); Q_UNUSED(activated); diff --git a/src/gui/kernel/qapplication_p.h b/src/gui/kernel/qapplication_p.h index 9c001ab..59565d4 100644 --- a/src/gui/kernel/qapplication_p.h +++ b/src/gui/kernel/qapplication_p.h @@ -457,6 +457,12 @@ public: static OSStatus globalEventProcessor(EventHandlerCallRef, EventRef, void *); static OSStatus globalAppleEventProcessor(const AppleEvent *, AppleEvent *, long); static OSStatus tabletProximityCallback(EventHandlerCallRef, EventRef, void *); +#ifdef QT_MAC_USE_COCOA + static void qt_initAfterNSAppStarted(); + static void setupAppleEvents(); + static void updateOverrideCursor(); + static void disableUsageOfCursorRects(bool disable); +#endif static bool qt_mac_apply_settings(); #endif diff --git a/src/gui/kernel/qapplication_s60.cpp b/src/gui/kernel/qapplication_s60.cpp index 6caac9f..20b8030 100644 --- a/src/gui/kernel/qapplication_s60.cpp +++ b/src/gui/kernel/qapplication_s60.cpp @@ -63,7 +63,7 @@ #include "private/qsoftkeymanager_p.h" #include "apgwgnam.h" // For CApaWindowGroupName -#include <MdaAudioTonePlayer.h> // For CMdaAudioToneUtility +#include <mdaaudiotoneplayer.h> // For CMdaAudioToneUtility #if defined(Q_WS_S60) # if !defined(QT_NO_IM) diff --git a/src/gui/kernel/qapplication_x11.cpp b/src/gui/kernel/qapplication_x11.cpp index 2a1f655..667db39 100644 --- a/src/gui/kernel/qapplication_x11.cpp +++ b/src/gui/kernel/qapplication_x11.cpp @@ -614,6 +614,11 @@ static int (*original_xio_errhandler)(Display *dpy); static int qt_x_errhandler(Display *dpy, XErrorEvent *err) { + if (X11->display != dpy) { + // only handle X errors for our display + return 0; + } + switch (err->error_code) { case BadAtom: if (err->request_code == 20 /* X_GetProperty */ diff --git a/src/gui/kernel/qcocoaapplicationdelegate_mac.mm b/src/gui/kernel/qcocoaapplicationdelegate_mac.mm index 47a8026..ab71a05 100644 --- a/src/gui/kernel/qcocoaapplicationdelegate_mac.mm +++ b/src/gui/kernel/qcocoaapplicationdelegate_mac.mm @@ -317,5 +317,12 @@ static void cleanupCocoaApplicationDelegate() qt_sendSpontaneousEvent(qAppInstance(), &qtEvent); } +- (void)appleEventQuit:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent +{ + Q_UNUSED(event); + Q_UNUSED(replyEvent); + [NSApp terminate:self]; +} + @end #endif diff --git a/src/gui/kernel/qcocoapanel_mac.mm b/src/gui/kernel/qcocoapanel_mac.mm index e535aac..3012093 100644 --- a/src/gui/kernel/qcocoapanel_mac.mm +++ b/src/gui/kernel/qcocoapanel_mac.mm @@ -46,6 +46,7 @@ #import <private/qcocoawindowdelegate_mac_p.h> #import <private/qcocoaview_mac_p.h> #import <private/qcocoawindowcustomthemeframe_mac_p.h> +#import <private/qcocoaapplication_mac_p.h> #include <QtGui/QWidget> diff --git a/src/gui/kernel/qcocoapanel_mac_p.h b/src/gui/kernel/qcocoapanel_mac_p.h index fc83bd8..3678f81 100644 --- a/src/gui/kernel/qcocoapanel_mac_p.h +++ b/src/gui/kernel/qcocoapanel_mac_p.h @@ -54,10 +54,16 @@ #ifdef QT_MAC_USE_COCOA #import <Cocoa/Cocoa.h> +QT_FORWARD_DECLARE_CLASS(QStringList); + @interface QT_MANGLE_NAMESPACE(QCocoaPanel) : NSPanel { bool leftButtonIsRightButton; + QStringList *currentCustomDragTypes; } + (Class)frameViewClassForStyleMask:(NSUInteger)styleMask; +- (void)registerDragTypes; + @end #endif + diff --git a/src/gui/kernel/qcocoasharedwindowmethods_mac_p.h b/src/gui/kernel/qcocoasharedwindowmethods_mac_p.h index 1a265d0..2117551 100644 --- a/src/gui/kernel/qcocoasharedwindowmethods_mac_p.h +++ b/src/gui/kernel/qcocoasharedwindowmethods_mac_p.h @@ -54,8 +54,32 @@ QT_BEGIN_NAMESPACE extern Qt::MouseButton cocoaButton2QtButton(NSInteger buttonNum); // qcocoaview.mm extern QPointer<QWidget> qt_button_down; //qapplication_mac.cpp +extern const QStringList& qEnabledDraggedTypes(); // qmime_mac.cpp +extern bool qt_blockCocoaSettingModalWindowLevel; // qeventdispatcher_mac_p.h + +Q_GLOBAL_STATIC(QPointer<QWidget>, currentDragTarget); + QT_END_NAMESPACE +- (id)initWithContentRect:(NSRect)contentRect + styleMask:(NSUInteger)windowStyle + backing:(NSBackingStoreType)bufferingType + defer:(BOOL)deferCreation +{ + self = [super initWithContentRect:contentRect styleMask:windowStyle + backing:bufferingType defer:deferCreation]; + if (self) { + currentCustomDragTypes = 0; + } + return self; +} + +- (void)dealloc +{ + delete currentCustomDragTypes; + [super dealloc]; +} + - (BOOL)canBecomeKeyWindow { QWidget *widget = [self QT_MANGLE_NAMESPACE(qt_qwidget)]; @@ -65,6 +89,39 @@ QT_END_NAMESPACE return !(isPopup || isToolTip); } +- (BOOL)canBecomeMainWindow +{ + QWidget *widget = [self QT_MANGLE_NAMESPACE(qt_qwidget)]; + + bool isToolTip = (widget->windowType() == Qt::ToolTip); + bool isPopup = (widget->windowType() == Qt::Popup); + return !(isPopup || isToolTip); +} + +- (void)orderWindow:(NSWindowOrderingMode)orderingMode relativeTo:(NSInteger)otherWindowNumber +{ + if (qt_blockCocoaSettingModalWindowLevel) { + // To avoid windows popping in front while restoring modal sessions + // in the event dispatcher, we block cocoa from ordering this window + // to front. The result of not doing this can be seen if executing + // a native color dialog on top of another executing dialog. + return; + } + [super orderWindow:orderingMode relativeTo:otherWindowNumber]; +} + +- (void)setLevel:(NSInteger)windowLevel +{ + if (qt_blockCocoaSettingModalWindowLevel) { + // To avoid windows popping in front while restoring modal sessions + // in the event dispatcher, we block cocoa from ordering this window + // to front. The result of not doing this can be seen if executing + // a native color dialog on top of another executing dialog. + return; + } + [super setLevel:windowLevel]; +} + - (void)toggleToolbarShown:(id)sender { macSendToolbarChangeEvent([self QT_MANGLE_NAMESPACE(qt_qwidget)]); @@ -103,6 +160,23 @@ QT_END_NAMESPACE qt_dispatchTabletProximityEvent(tabletEvent); } +- (void)qtDispatcherToQAction:(id)sender +{ + // If this window is modal, the menu bar will be modally shaddowed. + // In that case, since the window will be in the first responder chain, + // we can still catch the trigger here and forward it to the menu bar. + // This is needed as a single modal dialog on Qt should be able to access + // the application menu (e.g. quit). + [[NSApp QT_MANGLE_NAMESPACE(qt_qcocoamenuLoader)] qtDispatcherToQAction:sender]; +} + +- (void)terminate:(id)sender +{ + // This function is called from the quit item in the menubar when this window + // is in the first responder chain (see also qtDispatcherToQAction above) + [NSApp terminate:sender]; +} + - (void)sendEvent:(NSEvent *)event { QWidget *widget = [[QT_MANGLE_NAMESPACE(QCocoaWindowDelegate) sharedDelegate] qt_qwidgetForWindow:self]; @@ -185,3 +259,112 @@ QT_END_NAMESPACE return [super frameViewClassForStyleMask:styleMask]; } +-(void)registerDragTypes +{ + // Calling registerForDraggedTypes below is slow, so only do + // it once for each window, or when the custom types change. + QMacCocoaAutoReleasePool pool; + const QStringList& customTypes = qEnabledDraggedTypes(); + if (currentCustomDragTypes == 0 || *currentCustomDragTypes != customTypes) { + if (currentCustomDragTypes == 0) + currentCustomDragTypes = new QStringList(); + *currentCustomDragTypes = customTypes; + const NSString* mimeTypeGeneric = @"com.trolltech.qt.MimeTypeName"; + NSMutableArray *supportedTypes = [NSMutableArray arrayWithObjects:NSColorPboardType, + NSFilenamesPboardType, NSStringPboardType, + NSFilenamesPboardType, NSPostScriptPboardType, NSTIFFPboardType, + NSRTFPboardType, NSTabularTextPboardType, NSFontPboardType, + NSRulerPboardType, NSFileContentsPboardType, NSColorPboardType, + NSRTFDPboardType, NSHTMLPboardType, NSPICTPboardType, + NSURLPboardType, NSPDFPboardType, NSVCardPboardType, + NSFilesPromisePboardType, NSInkTextPboardType, + NSMultipleTextSelectionPboardType, mimeTypeGeneric, nil]; + // Add custom types supported by the application. + for (int i = 0; i < customTypes.size(); i++) { + [supportedTypes addObject:reinterpret_cast<const NSString *>(QCFString::toCFStringRef(customTypes[i]))]; + } + [self registerForDraggedTypes:supportedTypes]; + } +} + +- (QWidget *)dragTargetHitTest:(id <NSDraggingInfo>)sender +{ + // Do a hittest to find the NSView under the + // mouse, and return the corresponding QWidget: + NSPoint windowPoint = [sender draggingLocation]; + NSView *candidateView = [[self contentView] hitTest:windowPoint]; + if (![candidateView isKindOfClass:[QT_MANGLE_NAMESPACE(QCocoaView) class]]) + return 0; + return [static_cast<QT_MANGLE_NAMESPACE(QCocoaView) *>(candidateView) qt_qwidget]; +} + +- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender +{ + // The user dragged something into the window. Send a draggingEntered message + // to the QWidget under the mouse. As the drag moves over the window, and over + // different widgets, we will handle enter and leave events from within + // draggingUpdated below. The reason why we handle this ourselves rather than + // subscribing for drag events directly in QCocoaView is that calling + // registerForDraggedTypes on the views will severly degrade initialization time + // for an application that uses a lot of drag subscribing widgets. + + QWidget *target = [self dragTargetHitTest:sender]; + if (!target) + return [super draggingEntered:sender]; + if (target->testAttribute(Qt::WA_DropSiteRegistered) == false) + return NSDragOperationNone; + + *currentDragTarget() = target; + return [reinterpret_cast<NSView *>((*currentDragTarget())->winId()) draggingEntered:sender]; + } + +- (NSDragOperation)draggingUpdated:(id < NSDraggingInfo >)sender +{ + QWidget *target = [self dragTargetHitTest:sender]; + if (!target) + return [super draggingUpdated:sender]; + + if (target == *currentDragTarget()) { + // The drag continues to move over the widget that we have sendt + // a draggingEntered message to. So just update the view: + return [reinterpret_cast<NSView *>((*currentDragTarget())->winId()) draggingUpdated:sender]; + } else { + // The widget under the mouse has changed. + // So we need to fake enter/leave events: + if (*currentDragTarget()) + [reinterpret_cast<NSView *>((*currentDragTarget())->winId()) draggingExited:sender]; + if (target->testAttribute(Qt::WA_DropSiteRegistered) == false) { + *currentDragTarget() = 0; + return NSDragOperationNone; + } + *currentDragTarget() = target; + return [reinterpret_cast<NSView *>((*currentDragTarget())->winId()) draggingEntered:sender]; + } +} + +- (void)draggingExited:(id < NSDraggingInfo >)sender +{ + QWidget *target = [self dragTargetHitTest:sender]; + if (!target) + return [super draggingExited:sender]; + + if (*currentDragTarget()) { + [reinterpret_cast<NSView *>((*currentDragTarget())->winId()) draggingExited:sender]; + *currentDragTarget() = 0; + } +} + +- (BOOL)performDragOperation:(id < NSDraggingInfo >)sender +{ + QWidget *target = [self dragTargetHitTest:sender]; + if (!target) + return [super performDragOperation:sender]; + + BOOL dropResult = NO; + if (*currentDragTarget()) { + dropResult = [reinterpret_cast<NSView *>((*currentDragTarget())->winId()) performDragOperation:sender]; + *currentDragTarget() = 0; + } + return dropResult; +} + diff --git a/src/gui/kernel/qcocoaview_mac.mm b/src/gui/kernel/qcocoaview_mac.mm index d255604..8c5d166 100644 --- a/src/gui/kernel/qcocoaview_mac.mm +++ b/src/gui/kernel/qcocoaview_mac.mm @@ -81,7 +81,6 @@ Q_GLOBAL_STATIC(DnDParams, qMacDnDParams); extern void qt_mac_update_cursor_at_global_pos(const QPoint &globalPos); // qcursor_mac.mm extern bool qt_sendSpontaneousEvent(QObject *, QEvent *); // qapplication.cpp extern OSViewRef qt_mac_nativeview_for(const QWidget *w); // qwidget_mac.mm -extern const QStringList& qEnabledDraggedTypes(); // qmime_mac.cpp extern QPointer<QWidget> qt_mouseover; //qapplication_mac.mm extern QPointer<QWidget> qt_button_down; //qapplication_mac.cpp @@ -212,7 +211,6 @@ extern "C" { composingText = new QString(); composing = false; sendKeyEvents = true; - currentCustomTypes = 0; [self setHidden:YES]; return self; } @@ -227,36 +225,12 @@ extern "C" { object:self]; } --(void)registerDragTypes -{ - QMacCocoaAutoReleasePool pool; - // Calling registerForDraggedTypes is slow, so only do it once for each widget - // or when the custom types change. - const QStringList& customTypes = qEnabledDraggedTypes(); - if (currentCustomTypes == 0 || *currentCustomTypes != customTypes) { - if (currentCustomTypes == 0) - currentCustomTypes = new QStringList(); - *currentCustomTypes = customTypes; - const NSString* mimeTypeGeneric = @"com.trolltech.qt.MimeTypeName"; - NSMutableArray *supportedTypes = [NSMutableArray arrayWithObjects:NSColorPboardType, - NSFilenamesPboardType, NSStringPboardType, - NSFilenamesPboardType, NSPostScriptPboardType, NSTIFFPboardType, - NSRTFPboardType, NSTabularTextPboardType, NSFontPboardType, - NSRulerPboardType, NSFileContentsPboardType, NSColorPboardType, - NSRTFDPboardType, NSHTMLPboardType, NSPICTPboardType, - NSURLPboardType, NSPDFPboardType, NSVCardPboardType, - NSFilesPromisePboardType, NSInkTextPboardType, - NSMultipleTextSelectionPboardType, mimeTypeGeneric, nil]; - // Add custom types supported by the application. - for (int i = 0; i < customTypes.size(); i++) { - [supportedTypes addObject:reinterpret_cast<const NSString *>(QCFString::toCFStringRef(customTypes[i]))]; - } - [self registerForDraggedTypes:supportedTypes]; - } -} - - (void)resetCursorRects { + // [NSView addCursorRect] is slow, so bail out early if we can: + if (NSIsEmptyRect([self visibleRect])) + return; + QWidget *cursorWidget = qwidget; if (cursorWidget->testAttribute(Qt::WA_TransparentForMouseEvents)) @@ -300,15 +274,9 @@ extern "C" { - (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender { - if (qwidget->testAttribute(Qt::WA_DropSiteRegistered) == false) - return NSDragOperationNone; + // NB: This function is called from QCoocaWindow/QCocoaPanel rather than directly + // from Cocoa. They modify the drag target, and might fake enter/leave events. NSPoint windowPoint = [sender draggingLocation]; - if (qwidget->testAttribute(Qt::WA_TransparentForMouseEvents)) { - // pass the drag enter event to the view underneath. - NSView *candidateView = [[[self window] contentView] hitTest:windowPoint]; - if (candidateView && candidateView != self) - return [candidateView draggingEntered:sender]; - } dragEnterSequence = [sender draggingSequenceNumber]; [self addDropData:sender]; QMimeData *mimeData = dropData; @@ -361,13 +329,9 @@ extern "C" { } - (NSDragOperation)draggingUpdated:(id < NSDraggingInfo >)sender { + // NB: This function is called from QCoocaWindow/QCocoaPanel rather than directly + // from Cocoa. They modify the drag target, and might fake enter/leave events. NSPoint windowPoint = [sender draggingLocation]; - if (qwidget->testAttribute(Qt::WA_TransparentForMouseEvents)) { - // pass the drag move event to the view underneath. - NSView *candidateView = [[[self window] contentView] hitTest:windowPoint]; - if (candidateView && candidateView != self) - return [candidateView draggingUpdated:sender]; - } // in cases like QFocusFrame, the view under the mouse might // not have received the drag enter. Generate a synthetic // drag enter event for that view. @@ -417,14 +381,10 @@ extern "C" { - (void)draggingExited:(id < NSDraggingInfo >)sender { + // NB: This function is called from QCoocaWindow/QCocoaPanel rather than directly + // from Cocoa. They modify the drag target, and might fake enter/leave events. + Q_UNUSED(sender); dragEnterSequence = -1; - if (qwidget->testAttribute(Qt::WA_TransparentForMouseEvents)) { - // try sending the leave event to the last view which accepted drag enter. - DnDParams *dndParams = [QT_MANGLE_NAMESPACE(QCocoaView) currentMouseEvent]; - NSView *candidateView = [[[self window] contentView] hitTest:dndParams->activeDragEnterPos]; - if (candidateView && candidateView != self) - return [candidateView draggingExited:sender]; - } // drag enter event was rejected, so ignore the move event. if (dropData) { QDragLeaveEvent de; @@ -435,14 +395,10 @@ extern "C" { - (BOOL)performDragOperation:(id <NSDraggingInfo>)sender { + // NB: This function is called from QCoocaWindow/QCocoaPanel rather than directly + // from Cocoa. They modify the drag target, and might fake enter/leave events. NSPoint windowPoint = [sender draggingLocation]; dragEnterSequence = -1; - if (qwidget->testAttribute(Qt::WA_TransparentForMouseEvents)) { - // pass the drop event to the view underneath. - NSView *candidateView = [[[self window] contentView] hitTest:windowPoint]; - if (candidateView && candidateView != self) - return [candidateView performDragOperation:sender]; - } [self addDropData:sender]; NSPoint globalPoint = [[sender draggingDestinationWindow] convertBaseToScreen:windowPoint]; @@ -472,8 +428,6 @@ extern "C" { { delete composingText; [[NSNotificationCenter defaultCenter] removeObserver:self]; - delete currentCustomTypes; - [self unregisterDraggedTypes]; [super dealloc]; } @@ -615,6 +569,10 @@ extern "C" { - (void)updateTrackingAreas { + // [NSView addTrackingArea] is slow, so bail out early if we can: + if (NSIsEmptyRect([self visibleRect])) + return; + QMacCocoaAutoReleasePool pool; if (NSArray *trackingArray = [self trackingAreas]) { NSUInteger size = [trackingArray count]; diff --git a/src/gui/kernel/qcocoaview_mac_p.h b/src/gui/kernel/qcocoaview_mac_p.h index 797b4d5..4bb10c5 100644 --- a/src/gui/kernel/qcocoaview_mac_p.h +++ b/src/gui/kernel/qcocoaview_mac_p.h @@ -87,7 +87,6 @@ Q_GUI_EXPORT int composingLength; bool sendKeyEvents; QString *composingText; - QStringList *currentCustomTypes; NSInteger dragEnterSequence; } - (id)initWithQWidget:(QWidget *)widget widgetPrivate:(QWidgetPrivate *)widgetprivate; @@ -97,7 +96,6 @@ Q_GUI_EXPORT - (NSDragOperation)draggingUpdated:(id < NSDraggingInfo >)sender; - (void)draggingExited:(id < NSDraggingInfo >)sender; - (BOOL)performDragOperation:(id <NSDraggingInfo>)sender; -- (void)registerDragTypes; - (void)removeDropData; - (void)addDropData:(id <NSDraggingInfo>)sender; - (void)setSupportedActions:(NSDragOperation)actions; diff --git a/src/gui/kernel/qcocoawindow_mac.mm b/src/gui/kernel/qcocoawindow_mac.mm index a644dfe..f1b642b 100644 --- a/src/gui/kernel/qcocoawindow_mac.mm +++ b/src/gui/kernel/qcocoawindow_mac.mm @@ -46,6 +46,7 @@ #import <private/qcocoaview_mac_p.h> #import <private/qt_cocoa_helpers_mac_p.h> #import <private/qcocoawindowcustomthemeframe_mac_p.h> +#import <private/qcocoaapplication_mac_p.h> #include <QtGui/QWidget> diff --git a/src/gui/kernel/qcocoawindow_mac_p.h b/src/gui/kernel/qcocoawindow_mac_p.h index c0d8252..403a1a5 100644 --- a/src/gui/kernel/qcocoawindow_mac_p.h +++ b/src/gui/kernel/qcocoawindow_mac_p.h @@ -70,9 +70,12 @@ QT_FORWARD_DECLARE_CLASS(QStringList); @interface QT_MANGLE_NAMESPACE(QCocoaWindow) : NSWindow { bool leftButtonIsRightButton; + QStringList *currentCustomDragTypes; } + (Class)frameViewClassForStyleMask:(NSUInteger)styleMask; +- (void)registerDragTypes; + @end #endif diff --git a/src/gui/kernel/qdnd_s60.cpp b/src/gui/kernel/qdnd_s60.cpp index 24f0090..1aa30af 100644 --- a/src/gui/kernel/qdnd_s60.cpp +++ b/src/gui/kernel/qdnd_s60.cpp @@ -52,7 +52,7 @@ #include "qdnd_p.h" #include "qt_s60_p.h" -#include <COECNTRL.H> +#include <coecntrl.h> // pointer cursor #include <w32std.h> #include <gdi.h> diff --git a/src/gui/kernel/qeventdispatcher_mac.mm b/src/gui/kernel/qeventdispatcher_mac.mm index c7c7caf..c7d042d 100644 --- a/src/gui/kernel/qeventdispatcher_mac.mm +++ b/src/gui/kernel/qeventdispatcher_mac.mm @@ -90,11 +90,16 @@ #ifndef QT_NO_THREAD # include "qmutex.h" +#endif QT_BEGIN_NAMESPACE QT_USE_NAMESPACE -#endif + +/***************************************************************************** + Internal variables and functions + *****************************************************************************/ +bool qt_blockCocoaSettingModalWindowLevel = false; /***************************************************************************** Externals @@ -540,6 +545,12 @@ bool QEventDispatcherMac::processEvents(QEventLoop::ProcessEventsFlags flags) { Q_D(QEventDispatcherMac); d->interrupt = false; + +#ifdef QT_MAC_USE_COCOA + bool interruptLater = false; + QtMacInterruptDispatcherHelp::cancelInterruptLater(); +#endif + // In case we end up recursing while we now process events, make sure // that we send remaining posted Qt events before this call returns: wakeUp(); @@ -554,25 +565,25 @@ bool QEventDispatcherMac::processEvents(QEventLoop::ProcessEventsFlags flags) QMacCocoaAutoReleasePool pool; NSEvent* event = 0; - // If Qt is used as a plugin, or just added into a native cocoa - // application, we should not run or stop NSApplication; - // This will be done from outside Qt. - // And if processEvents is called manually (rather than from QEventLoop), we - // cannot enter a tight loop and block the call, but instead return after one flush: - bool canExec_3rdParty = d->nsAppRunCalledByQt || ![NSApp isRunning]; - bool canExec_Qt = flags & QEventLoop::DialogExec || flags & QEventLoop::EventLoopExec; + // If Qt is used as a plugin, or as an extension in a native cocoa + // application, we should not run or stop NSApplication; This will be + // done from the application itself. And if processEvents is called + // manually (rather than from a QEventLoop), we cannot enter a tight + // loop and block this call, but instead we need to return after one flush: + const bool canExec_3rdParty = d->nsAppRunCalledByQt || ![NSApp isRunning]; + const bool canExec_Qt = flags & QEventLoop::DialogExec || flags & QEventLoop::EventLoopExec; if (canExec_Qt && canExec_3rdParty) { // We can use exec-mode, meaning that we can stay in a tight loop until - // interrupted. This is mostly an optimization, but it also allow us - // to use [NSApp run], which is the recommended way of running applications - // in cocoa. [NSApp run] should be called at least once for any cocoa app. + // interrupted. This is mostly an optimization, but it allow us to use + // [NSApp run], which is the normal code path for cocoa applications. if (NSModalSession session = d->currentModalSession()) { QBoolBlocker execGuard(d->currentExecIsNSAppRun, false); while ([NSApp runModalSession:session] == NSRunContinuesResponse && !d->interrupt) qt_mac_waitForMoreModalSessionEvents(); + if (!d->interrupt && session == d->currentModalSessionCached) { - // INVARIANT: Someone called e.g. [NSApp stopModal:] from outside the event + // Someone called [NSApp stopModal:] from outside the event // dispatcher (e.g to stop a native dialog). But that call wrongly stopped // 'session' as well. As a result, we need to restart all internal sessions: d->temporarilyStopAllModalSessions(); @@ -583,54 +594,63 @@ bool QEventDispatcherMac::processEvents(QEventLoop::ProcessEventsFlags flags) [NSApp run]; } retVal = true; - } else do { - // INVARIANT: We cannot block the thread (and run in a tight loop). + } else { + // We cannot block the thread (and run in a tight loop). // Instead we will process all current pending events and return. - bool mustRelease = false; - - if (!(flags & QEventLoop::ExcludeUserInputEvents) && !d->queuedUserInputEvents.isEmpty()) { - // Process a pending user input event - mustRelease = true; - event = static_cast<NSEvent *>(d->queuedUserInputEvents.takeFirst()); - } else { - if (NSModalSession session = d->currentModalSession()) { - if (flags & QEventLoop::WaitForMoreEvents) - qt_mac_waitForMoreModalSessionEvents(); - NSInteger status = [NSApp runModalSession:session]; - if (status != NSRunContinuesResponse && session == d->currentModalSessionCached) { - // INVARIANT: Someone called e.g. [NSApp stopModal:] from outside the event - // dispatcher (e.g to stop a native dialog). But that call wrongly stopped - // 'session' as well. As a result, we need to restart all internal sessions: - d->temporarilyStopAllModalSessions(); - } - retVal = true; - break; + d->ensureNSAppInitialized(); + do { + bool releaseEvent = false; + + if (!(flags & QEventLoop::ExcludeUserInputEvents) + && !d->queuedUserInputEvents.isEmpty()) { + // Process a pending user input event + releaseEvent = true; + event = static_cast<NSEvent *>(d->queuedUserInputEvents.takeFirst()); } else { - event = [NSApp nextEventMatchingMask:NSAnyEventMask - untilDate:nil - inMode:NSDefaultRunLoopMode - dequeue: YES]; - - if (event != nil) { - if (flags & QEventLoop::ExcludeUserInputEvents) { - if (IsMouseOrKeyEvent(event)) { - // retain event here? - [event retain]; - d->queuedUserInputEvents.append(event); - continue; + if (NSModalSession session = d->currentModalSession()) { + if (flags & QEventLoop::WaitForMoreEvents) + qt_mac_waitForMoreModalSessionEvents(); + NSInteger status = [NSApp runModalSession:session]; + if (status != NSRunContinuesResponse && session == d->currentModalSessionCached) { + // INVARIANT: Someone called [NSApp stopModal:] from outside the event + // dispatcher (e.g to stop a native dialog). But that call wrongly stopped + // 'session' as well. As a result, we need to restart all internal sessions: + d->temporarilyStopAllModalSessions(); + } + retVal = true; + break; + } else { + event = [NSApp nextEventMatchingMask:NSAnyEventMask + untilDate:nil + inMode:NSDefaultRunLoopMode + dequeue: YES]; + + if (event != nil) { + if (flags & QEventLoop::ExcludeUserInputEvents) { + if (IsMouseOrKeyEvent(event)) { + [event retain]; + d->queuedUserInputEvents.append(event); + continue; + } } } } } - } - if (event) { - if (!filterEvent(event) && qt_mac_send_event(flags, event, 0)) - retVal = true; - if (mustRelease) - [event release]; - } - } while(!d->interrupt && event != nil); - + if (event) { + if (!filterEvent(event) && qt_mac_send_event(flags, event, 0)) + retVal = true; + if (releaseEvent) + [event release]; + } + } while (!d->interrupt && event != nil); + + // Since the window that holds modality might have changed while processing + // events, we we need to interrupt when we return back the previous process + // event recursion to ensure that we spin the correct modal session. + // We do the interruptLater at the end of the function to ensure that we don't + // disturb the 'wait for more events' below (as deleteLater will post an event): + interruptLater = true; + } #else do { EventRef event; @@ -682,25 +702,19 @@ bool QEventDispatcherMac::processEvents(QEventLoop::ProcessEventsFlags flags) } } + // If we're interrupted, we need to interrupt the _current_ + // recursion as well to check if it is still supposed to be + // executing. This way we wind down the stack until we land + // on a recursion that again calls processEvents (typically + // from QEventLoop), and set interrupt to false: + if (d->interrupt) + interrupt(); + #ifdef QT_MAC_USE_COCOA - // In case we _now_ process events using [NSApp run], we need to stop it to - // ensure that: - // 1. the QEventLoop that called us is still executing, or - // 2. we have a modal session that needs to be spun instead. - // In case this is a plain call to processEvents (perhaps from a loop) - // from the application (rather than from a QEventLoop), we delay the - // interrupting until we/ actually enter a lower loop level (hence the - // deffered delete of the object below): - QtMacInterruptDispatcherHelp::interruptLater(); + if (interruptLater) + QtMacInterruptDispatcherHelp::interruptLater(); #endif - if (d->interrupt) { - // We should continue to leave all recursion to processEvents until - // processEvents is called again (e.g. from a QEventLoop that - // was not yet told to quit: - interrupt(); - } - return retVal; } @@ -729,39 +743,60 @@ void QEventDispatcherMac::flush() *****************************************************************************/ MacTimerHash QEventDispatcherMacPrivate::macTimerHash; bool QEventDispatcherMacPrivate::blockSendPostedEvents = false; +bool QEventDispatcherMacPrivate::interrupt = false; #ifdef QT_MAC_USE_COCOA QStack<QCocoaModalSessionInfo> QEventDispatcherMacPrivate::cocoaModalSessionStack; bool QEventDispatcherMacPrivate::currentExecIsNSAppRun = false; +bool QEventDispatcherMacPrivate::modalSessionsTemporarilyStopped = false; bool QEventDispatcherMacPrivate::nsAppRunCalledByQt = false; +bool QEventDispatcherMacPrivate::cleanupModalSessionsNeeded = false; NSModalSession QEventDispatcherMacPrivate::currentModalSessionCached = 0; -int QEventDispatcherMacPrivate::activeModalSessionCount() +void QEventDispatcherMacPrivate::ensureNSAppInitialized() { - // Returns the number of modal sessions created - // (and not just pushed onto the stack, pending to be created) - int count = 0; - for (int i=cocoaModalSessionStack.size()-1; i>=0; --i) { - QCocoaModalSessionInfo &info = cocoaModalSessionStack[i]; - if (info.session) - ++count; - } - return count; + // Some elements in Cocoa require NSApplication to be running before + // they get fully initialized, in particular the menu bar. This + // function is intended for cases where a dialog is told to execute before + // QApplication::exec is called, or the application spins the events loop + // manually rather than calling QApplication:exec. + // The function makes sure that NSApplication starts running, but stops + // it again as soon as the send posted events callback is called. That way + // we let Cocoa finish the initialization it seems to need. We'll only + // apply this trick at most once for any application, and we avoid doing it + // for the common case where main just starts QApplication::exec. + if (nsAppRunCalledByQt || [NSApp isRunning]) + return; + nsAppRunCalledByQt = true; + QBoolBlocker block1(interrupt, true); + QBoolBlocker block2(currentExecIsNSAppRun, true); + [NSApp run]; } void QEventDispatcherMacPrivate::temporarilyStopAllModalSessions() { - // Stop all created modal session, and as such, make then - // pending again. The next call to currentModalSession will - // recreate the session on top again: + // Flush, and Stop, all created modal session, and as + // such, make them pending again. The next call to + // currentModalSession will recreate them again. The + // reason to stop all session like this is that otherwise + // a call [NSApp stop] would not stop NSApp, but rather + // the current modal session. So if we need to stop NSApp + // we need to stop all the modal session first. To avoid changing + // the stacking order of the windows while doing so, we put + // up a block that is used in QCocoaWindow and QCocoaPanel: + QBoolBlocker block1(blockSendPostedEvents, true); + QBoolBlocker block2(qt_blockCocoaSettingModalWindowLevel, true); + int stackSize = cocoaModalSessionStack.size(); for (int i=stackSize-1; i>=0; --i) { QCocoaModalSessionInfo &info = cocoaModalSessionStack[i]; if (info.session) { + [NSApp runModalSession:info.session]; [NSApp endModalSession:info.session]; info.session = 0; } } + modalSessionsTemporarilyStopped = true; currentModalSessionCached = 0; } @@ -775,23 +810,6 @@ NSModalSession QEventDispatcherMacPrivate::currentModalSession() if (cocoaModalSessionStack.isEmpty()) return 0; - // Since this code will end up calling our Qt event handler - // (also from beginModalSessionForWindow), we need to block - // that to avoid side effects of events beeing delivered: - QBoolBlocker block(blockSendPostedEvents, true); - - if (![NSApp isRunning]) { - // Sadly, we need to introduce this little event flush - // to stop dialogs from blinking/poping in front if a - // modal session restart was needed: - while (NSEvent *event = [NSApp nextEventMatchingMask:0 - untilDate:nil - inMode:NSDefaultRunLoopMode - dequeue: YES]) { - qt_mac_send_event(0, event, 0); - } - } - int sessionCount = cocoaModalSessionStack.size(); for (int i=0; i<sessionCount; ++i) { QCocoaModalSessionInfo &info = cocoaModalSessionStack[i]; @@ -804,11 +822,28 @@ NSModalSession QEventDispatcherMacPrivate::currentModalSession() NSWindow *window = qt_mac_window_for(info.widget); if (!window) continue; + + ensureNSAppInitialized(); + QBoolBlocker block1(blockSendPostedEvents, true); info.session = [NSApp beginModalSessionForWindow:window]; } currentModalSessionCached = info.session; } + if (modalSessionsTemporarilyStopped && currentModalSessionCached) { + // After a call to temporarilyStopAllModalSessions, cocoa have + // now posted events to restore ended modal session windows to + // the correct window level. Those events will be processed + // _after_ our new calls to beginModalSessionForWindow have + // taken effect, which will end up stacking the windows wrong on + // screen. To work around this, we block cocoa from changing the + // stacking order of the windows, and flush out the pending events + // (the block is used in QCocoaWindow and QCocoaPanel): + QBoolBlocker block1(blockSendPostedEvents, true); + QBoolBlocker block2(qt_blockCocoaSettingModalWindowLevel, true); + [NSApp runModalSession:currentModalSessionCached]; + } + modalSessionsTemporarilyStopped = false; return currentModalSessionCached; } @@ -844,6 +879,34 @@ void QEventDispatcherMacPrivate::updateChildrenWorksWhenModal() } } +void QEventDispatcherMacPrivate::cleanupModalSessions() +{ + // Go through the list of modal sessions, and end those + // that no longer has a widget assosiated; no widget means + // the the session has logically ended. The reason we wait like + // this to actually end the sessions for real (rather than at the + // point they were marked as stopped), is that ending a session + // when no other session runs below it on the stack will make cocoa + // drop some events on the floor. + QMacCocoaAutoReleasePool pool; + int stackSize = cocoaModalSessionStack.size(); + + for (int i=stackSize-1; i>=0; --i) { + QCocoaModalSessionInfo &info = cocoaModalSessionStack[i]; + if (info.widget) { + currentModalSessionCached = info.session; + break; + } + cocoaModalSessionStack.remove(i); + currentModalSessionCached = 0; + if (info.session) + [NSApp endModalSession:info.session]; + } + + updateChildrenWorksWhenModal(); + cleanupModalSessionsNeeded = false; +} + void QEventDispatcherMacPrivate::beginModalSession(QWidget *widget) { // Add a new, empty (null), NSModalSession to the stack. @@ -852,7 +915,7 @@ void QEventDispatcherMacPrivate::beginModalSession(QWidget *widget) // is non-zero, and the session pointer is zero (it will become active upon a call to // currentModalSession). A QCocoaModalSessionInfo is considered pending to be stopped if // the widget pointer is zero, and the session pointer is non-zero (it will be fully - // stopped in endModalSession(). + // stopped in cleanupModalSessions()). QCocoaModalSessionInfo info = {widget, 0}; cocoaModalSessionStack.push(info); updateChildrenWorksWhenModal(); @@ -869,38 +932,21 @@ void QEventDispatcherMacPrivate::endModalSession(QWidget *widget) int stackSize = cocoaModalSessionStack.size(); for (int i=stackSize-1; i>=0; --i) { QCocoaModalSessionInfo &info = cocoaModalSessionStack[i]; - if (info.widget == widget) + if (info.widget == widget) { info.widget = 0; - } - - // Now we stop, and remove, all sessions marked as pending - // to be stopped on _top_ of the stack, if any: - bool needToInterruptEventDispatcher = false; - bool needToUpdateChildrenWorksWhenModal = false; - - for (int i=stackSize-1; i>=0; --i) { - QCocoaModalSessionInfo &info = cocoaModalSessionStack[i]; - if (info.widget) - break; - cocoaModalSessionStack.remove(i); - needToUpdateChildrenWorksWhenModal = true; - currentModalSessionCached = 0; - if (info.session) { - [NSApp endModalSession:info.session]; - needToInterruptEventDispatcher = true; + if (i == stackSize-1) { + // The top sessions ended. Interrupt the event dispatcher + // to start spinning the correct session immidiatly: + cleanupModalSessionsNeeded = true; + QEventDispatcherMac::instance()->interrupt(); + } } } - - if (needToUpdateChildrenWorksWhenModal) - updateChildrenWorksWhenModal(); - if (needToInterruptEventDispatcher) - QEventDispatcherMac::instance()->interrupt(); } #endif QEventDispatcherMacPrivate::QEventDispatcherMacPrivate() - : interrupt(false) { } @@ -959,13 +1005,39 @@ Boolean QEventDispatcherMacPrivate::postedEventSourceEqualCallback(const void *i inline static void processPostedEvents(QEventDispatcherMacPrivate *const d, const bool blockSendPostedEvents) { - if (blockSendPostedEvents || d->interrupt) { + if (blockSendPostedEvents) { + // We're told to not send posted events (because the event dispatcher + // is currently working on setting up the correct session to run). But + // we still need to make sure that we don't fall asleep until pending events + // are sendt, so we just signal this need, and return: CFRunLoopSourceSignal(d->postedEventsSource); - } else { - if (!d->threadData->canWait || (d->serialNumber != d->lastSerial)) { - d->lastSerial = d->serialNumber; - QApplicationPrivate::sendPostedEvents(0, 0, d->threadData); + return; + } + +#ifdef QT_MAC_USE_COCOA + if (d->cleanupModalSessionsNeeded) + d->cleanupModalSessions(); +#endif + + if (d->interrupt) { +#ifdef QT_MAC_USE_COCOA + if (d->currentExecIsNSAppRun) { + // The event dispatcher has been interrupted. But since + // [NSApplication run] is running the event loop, we + // delayed stopping it until now (to let cocoa process + // pending cocoa events first). + if (d->currentModalSessionCached) + d->temporarilyStopAllModalSessions(); + [NSApp stop:NSApp]; + d->cancelWaitForMoreEvents(); } +#endif + return; + } + + if (!d->threadData->canWait || (d->serialNumber != d->lastSerial)) { + d->lastSerial = d->serialNumber; + QApplicationPrivate::sendPostedEvents(0, 0, d->threadData); } } @@ -975,6 +1047,9 @@ void QEventDispatcherMacPrivate::firstLoopEntry(CFRunLoopObserverRef ref, { Q_UNUSED(ref); Q_UNUSED(activity); +#ifdef QT_MAC_USE_COCOA + QApplicationPrivate::qt_initAfterNSAppStarted(); +#endif processPostedEvents(static_cast<QEventDispatcherMacPrivate *>(info), blockSendPostedEvents); } @@ -983,6 +1058,19 @@ void QEventDispatcherMacPrivate::postedEventsSourcePerformCallback(void *info) processPostedEvents(static_cast<QEventDispatcherMacPrivate *>(info), blockSendPostedEvents); } +#ifdef QT_MAC_USE_COCOA +void QEventDispatcherMacPrivate::cancelWaitForMoreEvents() +{ + // In case the event dispatcher is waiting for more + // events somewhere, we post a dummy event to wake it up: + QMacCocoaAutoReleasePool pool; + static const short NSAppShouldStopForQt = SHRT_MAX; + [NSApp postEvent:[NSEvent otherEventWithType:NSApplicationDefined location:NSZeroPoint + modifierFlags:0 timestamp:0. windowNumber:0 context:0 + subtype:NSAppShouldStopForQt data1:0 data2:0] atStart:NO]; +} +#endif + void QEventDispatcherMac::interrupt() { Q_D(QEventDispatcherMac); @@ -992,20 +1080,14 @@ void QEventDispatcherMac::interrupt() #ifndef QT_MAC_USE_COCOA CFRunLoopStop(mainRunLoop()); #else - QMacCocoaAutoReleasePool pool; - // In case we wait for more events inside - // processEvents (or NSApp run), post a dummy to wake it up: - static const short NSAppShouldStopForQt = SHRT_MAX; - [NSApp postEvent:[NSEvent otherEventWithType:NSApplicationDefined location:NSZeroPoint - modifierFlags:0 timestamp:0. windowNumber:0 context:0 - subtype:NSAppShouldStopForQt data1:0 data2:0] atStart:NO]; - - if (d->activeModalSessionCount() == 0) { - // We should only stop NSApp if we actually started it (and - // not some 3rd party application, e.g. if we are a plugin). - if (d->nsAppRunCalledByQt) - [NSApp stop:NSApp]; - } + // We do nothing more here than setting d->interrupt = true, and + // poke the event loop if it is sleeping. Actually stopping + // NSApp, or the current modal session, is done inside the send + // posted events callback. We do this to ensure that all current pending + // cocoa events gets delivered before we stop. Otherwise, if we now stop + // the last event loop recursion, cocoa will just drop pending posted + // events on the floor before we get a chance to reestablish a new session. + d->cancelWaitForMoreEvents(); #endif } @@ -1046,17 +1128,18 @@ QEventDispatcherMac::~QEventDispatcherMac() CFRelease(d->firstTimeObserver); } -///////////////////////////////////////////////////////////////////////////// - #ifdef QT_MAC_USE_COCOA QtMacInterruptDispatcherHelp* QtMacInterruptDispatcherHelp::instance = 0; QtMacInterruptDispatcherHelp::QtMacInterruptDispatcherHelp() : cancelled(false) { - // This is the whole point of encapsulation this code - // inside a class; we can make the code (inside destructor) - // execute on lower loop level: + // The whole point of this class is that we enable a way to interrupt + // the event dispatcher when returning back to a lower recursion level + // than where interruptLater was called. This is needed to detect if + // [NSApp run] should still be running at the recursion level it is at. + // Since the interrupt is canceled if processEvents is called before + // this object gets deleted, we also avoid interrupting unnecessary. deleteLater(); } @@ -1064,34 +1147,26 @@ QtMacInterruptDispatcherHelp::~QtMacInterruptDispatcherHelp() { if (cancelled) return; - instance = 0; - - if (QEventDispatcherMacPrivate::currentExecIsNSAppRun) { - int activeCount = QEventDispatcherMacPrivate::activeModalSessionCount(); - if (activeCount > 0) { - // The problem we now have hit: [NSApp stop] will not stop NSApp - // if a session is active; it will stop the session instead. - // So to stop NSApp, we need to temporarily stop all the - // sessions, then stop NSApp, then restart the session on top again. - // We need to do this to ensure that we're not stuck inside - // [NSApp run] when we really should be running a modal session: - QEventDispatcherMacPrivate::temporarilyStopAllModalSessions(); - } - } - // Always interrupt once more in case the modal session stack changed - // while processEvents was called manually from within the application: QEventDispatcherMac::instance()->interrupt(); } -void QtMacInterruptDispatcherHelp::interruptLater() { - if (instance) { - instance->cancelled = true; - delete instance; - } +void QtMacInterruptDispatcherHelp::cancelInterruptLater() +{ + if (!instance) + return; + instance->cancelled = true; + delete instance; + instance = 0; +} + +void QtMacInterruptDispatcherHelp::interruptLater() +{ + cancelInterruptLater(); instance = new QtMacInterruptDispatcherHelp; } #endif QT_END_NAMESPACE + diff --git a/src/gui/kernel/qeventdispatcher_mac_p.h b/src/gui/kernel/qeventdispatcher_mac_p.h index a335f16..e932532 100644 --- a/src/gui/kernel/qeventdispatcher_mac_p.h +++ b/src/gui/kernel/qeventdispatcher_mac_p.h @@ -174,13 +174,17 @@ public: static QStack<QCocoaModalSessionInfo> cocoaModalSessionStack; static bool currentExecIsNSAppRun; static bool nsAppRunCalledByQt; + static bool cleanupModalSessionsNeeded; + static bool modalSessionsTemporarilyStopped; static NSModalSession currentModalSessionCached; - static void updateChildrenWorksWhenModal(); static NSModalSession currentModalSession(); - static int activeModalSessionCount(); + static void updateChildrenWorksWhenModal(); static void temporarilyStopAllModalSessions(); static void beginModalSession(QWidget *widget); static void endModalSession(QWidget *widget); + static void cancelWaitForMoreEvents(); + static void cleanupModalSessions(); + static void ensureNSAppInitialized(); #endif MacSocketHash macSockets; @@ -190,7 +194,7 @@ public: CFRunLoopObserverRef firstTimeObserver; QAtomicInt serialNumber; int lastSerial; - bool interrupt; + static bool interrupt; private: static Boolean postedEventSourceEqualCallback(const void *info1, const void *info2); static void postedEventsSourcePerformCallback(void *info); @@ -211,6 +215,7 @@ class QtMacInterruptDispatcherHelp : public QObject public: static void interruptLater(); + static void cancelInterruptLater(); }; #endif diff --git a/src/gui/kernel/qguieventdispatcher_glib.cpp b/src/gui/kernel/qguieventdispatcher_glib.cpp index 7b30741..ac2b5f7 100644 --- a/src/gui/kernel/qguieventdispatcher_glib.cpp +++ b/src/gui/kernel/qguieventdispatcher_glib.cpp @@ -216,4 +216,9 @@ void QGuiEventDispatcherGlib::startingUp() g_source_add_poll(&d->x11EventSource->source, &d->x11EventSource->pollfd); } +void QGuiEventDispatcherGlib::flush() +{ + XFlush(X11->display); +} + QT_END_NAMESPACE diff --git a/src/gui/kernel/qguieventdispatcher_glib_p.h b/src/gui/kernel/qguieventdispatcher_glib_p.h index ff778cc..758650b 100644 --- a/src/gui/kernel/qguieventdispatcher_glib_p.h +++ b/src/gui/kernel/qguieventdispatcher_glib_p.h @@ -71,6 +71,7 @@ public: bool processEvents(QEventLoop::ProcessEventsFlags flags); void startingUp(); + void flush(); }; QT_END_NAMESPACE diff --git a/src/gui/kernel/qkeysequence.cpp b/src/gui/kernel/qkeysequence.cpp index 2a13546..99bf971 100644 --- a/src/gui/kernel/qkeysequence.cpp +++ b/src/gui/kernel/qkeysequence.cpp @@ -861,6 +861,8 @@ QKeySequence::QKeySequence() Up to four key codes may be entered by separating them with commas, e.g. "Alt+X,Ctrl+S,Q". + \a key should be in NativeText format. + This constructor is typically used with \link QObject::tr() tr \endlink(), so that shortcut keys can be replaced in translations: @@ -877,6 +879,16 @@ QKeySequence::QKeySequence(const QString &key) } /*! + \since 4.x + Creates a key sequence from the \a key string based on \a format. +*/ +QKeySequence::QKeySequence(const QString &key, QKeySequence::SequenceFormat format) +{ + d = new QKeySequencePrivate(); + assign(key, format); +} + +/*! Constructs a key sequence with up to 4 keys \a k1, \a k2, \a k3 and \a k4. @@ -1055,9 +1067,24 @@ QKeySequence QKeySequence::mnemonic(const QString &text) contain up to four key codes, provided they are separated by a comma; for example, "Alt+X,Ctrl+S,Z". The return value is the number of key codes added. + \a keys should be in NativeText format. */ int QKeySequence::assign(const QString &ks) { + return assign(ks, NativeText); +} + +/*! + \fn int QKeySequence::assign(const QString &keys, QKeySequence::SequenceFormat format) + \since 4.x + + Adds the given \a keys to the key sequence (based on \a format). + \a keys may contain up to four key codes, provided they are + separated by a comma; for example, "Alt+X,Ctrl+S,Z". The return + value is the number of key codes added. +*/ +int QKeySequence::assign(const QString &ks, QKeySequence::SequenceFormat format) +{ QString keyseq = ks; QString part; int n = 0; @@ -1086,7 +1113,7 @@ int QKeySequence::assign(const QString &ks) } part = keyseq.left(-1 == p ? keyseq.length() : p - diff); keyseq = keyseq.right(-1 == p ? 0 : keyseq.length() - (p + 1)); - d->key[n] = decodeString(part); + d->key[n] = QKeySequencePrivate::decodeString(part, format); ++n; } return n; @@ -1557,12 +1584,7 @@ QString QKeySequence::toString(SequenceFormat format) const */ QKeySequence QKeySequence::fromString(const QString &str, SequenceFormat format) { - QStringList sl = str.split(QLatin1String(", ")); - int keys[4] = {0, 0, 0, 0}; - int total = qMin(sl.count(), 4); - for (int i = 0; i < total; ++i) - keys[i] = QKeySequencePrivate::decodeString(sl[i], format); - return QKeySequence(keys[0], keys[1], keys[2], keys[3]); + return QKeySequence(str, format); } /***************************************************************************** diff --git a/src/gui/kernel/qkeysequence.h b/src/gui/kernel/qkeysequence.h index 1409e28..5a973e3 100644 --- a/src/gui/kernel/qkeysequence.h +++ b/src/gui/kernel/qkeysequence.h @@ -141,8 +141,14 @@ public: Quit }; + enum SequenceFormat { + NativeText, + PortableText + }; + QKeySequence(); QKeySequence(const QString &key); + QKeySequence(const QString &key, SequenceFormat format); QKeySequence(int k1, int k2 = 0, int k3 = 0, int k4 = 0); QKeySequence(const QKeySequence &ks); QKeySequence(StandardKey key); @@ -160,11 +166,6 @@ public: #endif }; - enum SequenceFormat { - NativeText, - PortableText - }; - QString toString(SequenceFormat format = PortableText) const; static QKeySequence fromString(const QString &str, SequenceFormat format = PortableText); @@ -194,6 +195,7 @@ private: static int decodeString(const QString &ks); static QString encodeString(int key); int assign(const QString &str); + int assign(const QString &str, SequenceFormat format); void setKey(int key, int index); QKeySequencePrivate *d; diff --git a/src/gui/kernel/qmime_mac.cpp b/src/gui/kernel/qmime_mac.cpp index 071f80d..c6fd184 100644 --- a/src/gui/kernel/qmime_mac.cpp +++ b/src/gui/kernel/qmime_mac.cpp @@ -154,6 +154,7 @@ CFStringRef qt_mac_mime_typeUTI = CFSTR("com.pasteboard.trolltech.marker"); \i public.url - converts to "text/uri-list" \i public.file-url - converts to "text/uri-list" \i public.tiff - converts to "application/x-qt-image" + \i public.vcard - converts to "text/plain" \i com.apple.traditional-mac-plain-text - converts to "text/plain" \i com.apple.pict - converts to "application/x-qt-image" \endlist @@ -909,6 +910,61 @@ QList<QByteArray> QMacPasteboardMimeUrl::convertFromMime(const QString &mime, QV return ret; } +class QMacPasteboardMimeVCard : public QMacPasteboardMime +{ +public: + QMacPasteboardMimeVCard() : QMacPasteboardMime(MIME_ALL){ } + QString convertorName(); + + QString flavorFor(const QString &mime); + QString mimeFor(QString flav); + bool canConvert(const QString &mime, QString flav); + QVariant convertToMime(const QString &mime, QList<QByteArray> data, QString flav); + QList<QByteArray> convertFromMime(const QString &mime, QVariant data, QString flav); +}; + +QString QMacPasteboardMimeVCard::convertorName() +{ + return QString("VCard"); +} + +bool QMacPasteboardMimeVCard::canConvert(const QString &mime, QString flav) +{ + return mimeFor(flav) == mime; +} + +QString QMacPasteboardMimeVCard::flavorFor(const QString &mime) +{ + if(mime.startsWith(QLatin1String("text/plain"))) + return QLatin1String("public.vcard"); + return QString(); +} + +QString QMacPasteboardMimeVCard::mimeFor(QString flav) +{ + if (flav == QLatin1String("public.vcard")) + return QLatin1String("text/plain"); + return QString(); +} + +QVariant QMacPasteboardMimeVCard::convertToMime(const QString &mime, QList<QByteArray> data, QString) +{ + QByteArray cards; + if (mime == QLatin1String("text/plain")) { + for (int i=0; i<data.size(); ++i) + cards += data[i]; + } + return QVariant(cards); +} + +QList<QByteArray> QMacPasteboardMimeVCard::convertFromMime(const QString &mime, QVariant data, QString) +{ + QList<QByteArray> ret; + if (mime == QLatin1String("text/plain")) + ret.append(data.toString().toUtf8()); + return ret; +} + #ifdef QT3_SUPPORT class QMacPasteboardMimeQt3Any : public QMacPasteboardMime { private: @@ -1116,6 +1172,7 @@ void QMacPasteboardMime::initialize() new QMacPasteboardMimeFileUri; new QMacPasteboardMimeUrl; new QMacPasteboardMimeTypeName; + new QMacPasteboardMimeVCard; //make sure our "non-standard" types are always last! --Sam new QMacPasteboardMimeAny; #ifdef QT3_SUPPORT diff --git a/src/gui/kernel/qnsthemeframe_mac_p.h b/src/gui/kernel/qnsthemeframe_mac_p.h index 77a6963..d061b1b 100644 --- a/src/gui/kernel/qnsthemeframe_mac_p.h +++ b/src/gui/kernel/qnsthemeframe_mac_p.h @@ -157,7 +157,7 @@ - (void)resetCursorRects; - (char)shouldBeTreatedAsInkEvent:fp8; - (char)_shouldBeTreatedAsInkEventInInactiveWindow:fp8; -- hitTest:(struct _NSPoint)fp8; +//- hitTest:(struct _NSPoint)fp8; // collides with hittest in qcocoasharedwindowmethods_mac_p.h - (NSRect)_leftGroupRect; - (NSRect)_rightGroupRect; - (void)_updateWidgets; diff --git a/src/gui/kernel/qsound_s60.cpp b/src/gui/kernel/qsound_s60.cpp index 1832b85..df2830b 100644 --- a/src/gui/kernel/qsound_s60.cpp +++ b/src/gui/kernel/qsound_s60.cpp @@ -51,7 +51,7 @@ #include <private/qcore_symbian_p.h> #include <e32std.h> -#include <MdaAudioSamplePlayer.h> +#include <mdaaudiosampleplayer.h> QT_BEGIN_NAMESPACE diff --git a/src/gui/kernel/qt_cocoa_helpers_mac.mm b/src/gui/kernel/qt_cocoa_helpers_mac.mm index e06a810..377e5a0 100644 --- a/src/gui/kernel/qt_cocoa_helpers_mac.mm +++ b/src/gui/kernel/qt_cocoa_helpers_mac.mm @@ -1281,6 +1281,21 @@ void qt_cocoaChangeOverrideCursor(const QCursor &cursor) } #endif +@implementation DebugNSApplication { +} +- (void)sendEvent:(NSEvent *)event +{ + NSLog(@"NSAppDebug: sendEvent: %@", event); + return [super sendEvent:event]; +} + +- (BOOL)sendAction:(SEL)anAction to:(id)aTarget from:(id)sender +{ + NSLog(@"NSAppDebug: sendAction: %s to %@ from %@", anAction, aTarget, sender); + return [super sendAction:anAction to:aTarget from:sender]; +} +@end + QMacCocoaAutoReleasePool::QMacCocoaAutoReleasePool() { #ifndef QT_MAC_USE_COCOA diff --git a/src/gui/kernel/qt_cocoa_helpers_mac_p.h b/src/gui/kernel/qt_cocoa_helpers_mac_p.h index 6f0c4ce..ace8255 100644 --- a/src/gui/kernel/qt_cocoa_helpers_mac_p.h +++ b/src/gui/kernel/qt_cocoa_helpers_mac_p.h @@ -181,6 +181,10 @@ inline QString qt_mac_NSStringToQString(const NSString *nsstr) inline NSString *qt_mac_QStringToNSString(const QString &qstr) { return [reinterpret_cast<const NSString *>(QCFString::toCFStringRef(qstr)) autorelease]; } + +@interface DebugNSApplication : NSApplication {} +@end + #endif QT_END_NAMESPACE diff --git a/src/gui/kernel/qt_x11_p.h b/src/gui/kernel/qt_x11_p.h index d110084..b2ce754 100644 --- a/src/gui/kernel/qt_x11_p.h +++ b/src/gui/kernel/qt_x11_p.h @@ -331,7 +331,7 @@ struct QXdndDropTransaction class QMimeData; struct QX11Data; -extern QX11Data *qt_x11Data; +extern Q_GUI_EXPORT QX11Data *qt_x11Data; enum DesktopEnvironment { DE_UNKNOWN, diff --git a/src/gui/kernel/qwidget.cpp b/src/gui/kernel/qwidget.cpp index ffad38b..e678220 100644 --- a/src/gui/kernel/qwidget.cpp +++ b/src/gui/kernel/qwidget.cpp @@ -4851,90 +4851,7 @@ void QWidget::unsetCursor() void QWidget::render(QPaintDevice *target, const QPoint &targetOffset, const QRegion &sourceRegion, RenderFlags renderFlags) { - Q_D(QWidget); - if (!target) { - qWarning("QWidget::render: null pointer to paint device"); - return; - } - - const bool inRenderWithPainter = d->extra && d->extra->inRenderWithPainter; - QRegion paintRegion = !inRenderWithPainter ? d->prepareToRender(sourceRegion, renderFlags) - : sourceRegion; - if (paintRegion.isEmpty()) - return; - -#ifndef Q_WS_MAC - QPainter *oldSharedPainter = inRenderWithPainter ? d->sharedPainter() : 0; - - // Use the target's shared painter if set (typically set when doing - // "other->render(widget);" in the widget's paintEvent. - if (target->devType() == QInternal::Widget) { - QWidgetPrivate *targetPrivate = static_cast<QWidget *>(target)->d_func(); - if (targetPrivate->extra && targetPrivate->extra->inRenderWithPainter) { - QPainter *targetPainter = targetPrivate->sharedPainter(); - if (targetPainter && targetPainter->isActive()) - d->setSharedPainter(targetPainter); - } - } -#endif - - // Use the target's redirected device if set and adjust offset and paint - // region accordingly. This is typically the case when people call render - // from the paintEvent. - QPoint offset = targetOffset; - offset -= paintRegion.boundingRect().topLeft(); - QPoint redirectionOffset; - QPaintDevice *redirected = 0; - - if (target->devType() == QInternal::Widget) - redirected = static_cast<QWidget *>(target)->d_func()->redirected(&redirectionOffset); - if (!redirected) - redirected = QPainter::redirected(target, &redirectionOffset); - - if (redirected) { - target = redirected; - offset -= redirectionOffset; - } - - if (!inRenderWithPainter) { // Clip handled by shared painter (in qpainter.cpp). - if (QPaintEngine *targetEngine = target->paintEngine()) { - const QRegion targetSystemClip = targetEngine->systemClip(); - if (!targetSystemClip.isEmpty()) - paintRegion &= targetSystemClip.translated(-offset); - } - } - - // Set backingstore flags. - int flags = QWidgetPrivate::DrawPaintOnScreen | QWidgetPrivate::DrawInvisible; - if (renderFlags & DrawWindowBackground) - flags |= QWidgetPrivate::DrawAsRoot; - - if (renderFlags & DrawChildren) - flags |= QWidgetPrivate::DrawRecursive; - else - flags |= QWidgetPrivate::DontSubtractOpaqueChildren; - -#ifdef Q_WS_QWS - flags |= QWidgetPrivate::DontSetCompositionMode; -#endif - - if (target->devType() == QInternal::Printer) { - QPainter p(target); - d->render_helper(&p, targetOffset, paintRegion, renderFlags); - return; - } - -#ifndef Q_WS_MAC - // Render via backingstore. - d->drawWidget(target, paintRegion, offset, flags, d->sharedPainter()); - - // Restore shared painter. - if (oldSharedPainter) - d->setSharedPainter(oldSharedPainter); -#else - // Render via backingstore (no shared painter). - d->drawWidget(target, paintRegion, offset, flags, 0); -#endif + d_func()->render(target, targetOffset, sourceRegion, renderFlags, false); } /*! @@ -5380,6 +5297,97 @@ void QWidgetPrivate::drawWidget(QPaintDevice *pdev, const QRegion &rgn, const QP } } +void QWidgetPrivate::render(QPaintDevice *target, const QPoint &targetOffset, + const QRegion &sourceRegion, QWidget::RenderFlags renderFlags, + bool readyToRender) +{ + Q_Q(QWidget); + if (!target) { + qWarning("QWidget::render: null pointer to paint device"); + return; + } + + const bool inRenderWithPainter = extra && extra->inRenderWithPainter; + QRegion paintRegion = !inRenderWithPainter && !readyToRender + ? prepareToRender(sourceRegion, renderFlags) + : sourceRegion; + if (paintRegion.isEmpty()) + return; + +#ifndef Q_WS_MAC + QPainter *oldSharedPainter = inRenderWithPainter ? sharedPainter() : 0; + + // Use the target's shared painter if set (typically set when doing + // "other->render(widget);" in the widget's paintEvent. + if (target->devType() == QInternal::Widget) { + QWidgetPrivate *targetPrivate = static_cast<QWidget *>(target)->d_func(); + if (targetPrivate->extra && targetPrivate->extra->inRenderWithPainter) { + QPainter *targetPainter = targetPrivate->sharedPainter(); + if (targetPainter && targetPainter->isActive()) + setSharedPainter(targetPainter); + } + } +#endif + + // Use the target's redirected device if set and adjust offset and paint + // region accordingly. This is typically the case when people call render + // from the paintEvent. + QPoint offset = targetOffset; + offset -= paintRegion.boundingRect().topLeft(); + QPoint redirectionOffset; + QPaintDevice *redirected = 0; + + if (target->devType() == QInternal::Widget) + redirected = static_cast<QWidget *>(target)->d_func()->redirected(&redirectionOffset); + if (!redirected) + redirected = QPainter::redirected(target, &redirectionOffset); + + if (redirected) { + target = redirected; + offset -= redirectionOffset; + } + + if (!inRenderWithPainter) { // Clip handled by shared painter (in qpainter.cpp). + if (QPaintEngine *targetEngine = target->paintEngine()) { + const QRegion targetSystemClip = targetEngine->systemClip(); + if (!targetSystemClip.isEmpty()) + paintRegion &= targetSystemClip.translated(-offset); + } + } + + // Set backingstore flags. + int flags = DrawPaintOnScreen | DrawInvisible; + if (renderFlags & QWidget::DrawWindowBackground) + flags |= DrawAsRoot; + + if (renderFlags & QWidget::DrawChildren) + flags |= DrawRecursive; + else + flags |= DontSubtractOpaqueChildren; + +#ifdef Q_WS_QWS + flags |= DontSetCompositionMode; +#endif + + if (target->devType() == QInternal::Printer) { + QPainter p(target); + render_helper(&p, targetOffset, paintRegion, renderFlags); + return; + } + +#ifndef Q_WS_MAC + // Render via backingstore. + drawWidget(target, paintRegion, offset, flags, sharedPainter()); + + // Restore shared painter. + if (oldSharedPainter) + setSharedPainter(oldSharedPainter); +#else + // Render via backingstore (no shared painter). + drawWidget(target, paintRegion, offset, flags, 0); +#endif +} + void QWidgetPrivate::paintSiblingsRecursive(QPaintDevice *pdev, const QObjectList& siblings, int index, const QRegion &rgn, const QPoint &offset, int flags #ifdef Q_BACKINGSTORE_SUBSURFACES diff --git a/src/gui/kernel/qwidget_mac.mm b/src/gui/kernel/qwidget_mac.mm index 78c1562..43b945e 100644 --- a/src/gui/kernel/qwidget_mac.mm +++ b/src/gui/kernel/qwidget_mac.mm @@ -1898,13 +1898,15 @@ void QWidgetPrivate::determineWindowClass() wclass = kDocumentWindowClass; else if(popup || (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_5 && type == Qt::SplashScreen)) wclass = kModalWindowClass; - else if(q->testAttribute(Qt::WA_ShowModal) || type == Qt::Dialog) + else if(type == Qt::Dialog) wclass = kMovableModalWindowClass; else if(type == Qt::ToolTip) wclass = kHelpWindowClass; else if(type == Qt::Tool || (QSysInfo::MacintoshVersion < QSysInfo::MV_10_5 && type == Qt::SplashScreen)) wclass = kFloatingWindowClass; + else if(q->testAttribute(Qt::WA_ShowModal)) + wclass = kMovableModalWindowClass; else wclass = kDocumentWindowClass; @@ -2008,8 +2010,6 @@ void QWidgetPrivate::determineWindowClass() for(int i = 0; tmp_wattr && known_attribs[i].name; i++) { if((tmp_wattr & known_attribs[i].tag) == known_attribs[i].tag) { tmp_wattr ^= known_attribs[i].tag; - qDebug("Qt: internal: * %s %s", known_attribs[i].name, - (GetAvailableWindowAttributes(wclass) & known_attribs[i].tag) ? "" : "(*)"); } } if(tmp_wattr) @@ -2204,6 +2204,41 @@ void QWidgetPrivate::finishCreateWindow_sys_Carbon(OSWindowRef windowRef) applyMaxAndMinSizeOnWindow(); } #else // QT_MAC_USE_COCOA + +void QWidgetPrivate::setWindowLevel() +{ + Q_Q(QWidget); + const QWidget * const windowParent = q->window()->parentWidget(); + const QWidget * const primaryWindow = windowParent ? windowParent->window() : 0; + NSInteger winLevel = -1; + + if (q->windowType() == Qt::Popup) { + winLevel = NSPopUpMenuWindowLevel; + // Popup should be in at least the same level as its parent. + if (primaryWindow) { + OSWindowRef parentRef = qt_mac_window_for(primaryWindow); + winLevel = qMax([parentRef level], winLevel); + } + } else if (q->windowType() == Qt::Tool) { + winLevel = NSFloatingWindowLevel; + } else if (q->windowType() == Qt::Dialog) { + // Correct modality level (NSModalPanelWindowLevel) will be + // set by cocoa when creating a modal session later. + winLevel = NSNormalWindowLevel; + } + + // StayOnTop window should appear above Tool windows. + if (data.window_flags & Qt::WindowStaysOnTopHint) + winLevel = NSPopUpMenuWindowLevel; + // Tooltips should appear above StayOnTop windows. + if (q->windowType() == Qt::ToolTip) + winLevel = NSScreenSaverWindowLevel; + // All other types are Normal level. + if (winLevel == -1) + winLevel = NSNormalWindowLevel; + [qt_mac_window_for(q) setLevel:winLevel]; +} + void QWidgetPrivate::finishCreateWindow_sys_Cocoa(void * /*NSWindow * */ voidWindowRef) { Q_Q(QWidget); @@ -2276,6 +2311,10 @@ void QWidgetPrivate::finishCreateWindow_sys_Cocoa(void * /*NSWindow * */ voidWin q->setAttribute(Qt::WA_WState_WindowOpacitySet, false); } + if (qApp->overrideCursor()) + [windowRef disableCursorRects]; + + setWindowLevel(); macUpdateHideOnSuspend(); macUpdateOpaqueSizeGrip(); macUpdateIgnoreMouseEvents(); @@ -2706,6 +2745,35 @@ void QWidgetPrivate::transferChildren() } } +#ifdef QT_MAC_USE_COCOA +void QWidgetPrivate::setSubWindowStacking(bool set) +{ + Q_Q(QWidget); + if (!q->isWindow() || !q->testAttribute(Qt::WA_WState_Created)) + return; + + if (QWidget *parent = q->parentWidget()) { + if (parent->testAttribute(Qt::WA_WState_Created)) { + if (set) + [qt_mac_window_for(parent) addChildWindow:qt_mac_window_for(q) ordered:NSWindowAbove]; + else + [qt_mac_window_for(parent) removeChildWindow:qt_mac_window_for(q)]; + } + } + + QList<QWidget *> widgets = q->findChildren<QWidget *>(); + for (int i=0; i<widgets.size(); ++i) { + QWidget *child = widgets.at(i); + if (child->isWindow() && child->testAttribute(Qt::WA_WState_Created)) { + if (set) + [qt_mac_window_for(q) addChildWindow:qt_mac_window_for(child) ordered:NSWindowAbove]; + else + [qt_mac_window_for(q) removeChildWindow:qt_mac_window_for(child)]; + } + } +} +#endif + void QWidgetPrivate::setParent_sys(QWidget *parent, Qt::WindowFlags f) { Q_Q(QWidget); @@ -2860,7 +2928,6 @@ void QWidgetPrivate::setParent_sys(QWidget *parent, Qt::WindowFlags f) current = current->parentWidget(); } } - invalidateBuffer(q->rect()); qt_event_request_window_change(q); } @@ -3322,13 +3389,23 @@ void QWidgetPrivate::show_sys() #else // sync the opacity value back (in case of a fade). [window setAlphaValue:q->windowOpacity()]; - [window makeKeyAndOrderFront:window]; - - // If this window is app modal, we need to start spinning - // a modal session for it. Interrupting - // the event dispatcher will make this happend: - if (data.window_modality == Qt::ApplicationModal) - QEventDispatcherMac::instance()->interrupt(); + setSubWindowStacking(true); + + QWidget *top = 0; + if (QApplicationPrivate::tryModalHelper(q, &top)) { + [window makeKeyAndOrderFront:window]; + // If this window is app modal, we need to start spinning + // a modal session for it. Interrupting + // the event dispatcher will make this happend: + if (data.window_modality == Qt::ApplicationModal) + QEventDispatcherMac::instance()->interrupt(); + } else { + // The window is modally shaddowed, so we need to make + // sure that we don't pop in front of the modal window: + [window orderFront:window]; + if (NSWindow *modalWin = qt_mac_window_for(top)) + [modalWin orderFront:window]; + } #endif if (q->windowType() == Qt::Popup) { if (q->focusWidget()) @@ -3347,8 +3424,6 @@ void QWidgetPrivate::show_sys() } else if (!q->testAttribute(Qt::WA_ShowWithoutActivating)) { #ifndef QT_MAC_USE_COCOA qt_event_request_activate(q); -#else - [qt_mac_window_for(q) makeKeyWindow]; #endif } } else if(topData()->embedded || !q->parentWidget() || q->parentWidget()->isVisible()) { @@ -3391,6 +3466,9 @@ void QWidgetPrivate::hide_sys() QMacCocoaAutoReleasePool pool; if(q->isWindow()) { +#ifdef QT_MAC_USE_COCOA + setSubWindowStacking(false); +#endif OSWindowRef window = qt_mac_window_for(q); if(qt_mac_is_macsheet(q)) { #ifndef QT_MAC_USE_COCOA @@ -3456,12 +3534,15 @@ void QWidgetPrivate::hide_sys() } #endif } - if(q->isActiveWindow() && !(q->windowType() == Qt::Popup)) { +#ifndef QT_MAC_USE_COCOA + // If the window we now hide was the active window, we need + // to find, and activate another window on screen. NB: Cocoa takes care of this + // logic for us (and distinquishes between main windows and key windows) + if (q->isActiveWindow() && !(q->windowType() == Qt::Popup)) { QWidget *w = 0; if(q->parentWidget()) w = q->parentWidget()->window(); if(!w || (!w->isVisible() && !w->isMinimized())) { -#ifndef QT_MAC_USE_COCOA for (WindowPtr wp = GetFrontWindowOfClass(kMovableModalWindowClass, true); wp; wp = GetNextWindowOfClass(wp, kMovableModalWindowClass, true)) { if((w = qt_mac_find_window(wp))) @@ -3481,24 +3562,12 @@ void QWidgetPrivate::hide_sys() break; } } -#else - NSArray *windows = [NSApp windows]; - NSUInteger totalWindows = [windows count]; - for (NSUInteger i = 0; i < totalWindows; ++i) { - OSWindowRef wp = [windows objectAtIndex:i]; - if ((w = qt_mac_find_window(wp))) - break; - } -#endif } if(w && w->isVisible() && !w->isMinimized()) { -#ifndef QT_MAC_USE_COCOA - qt_event_request_activate(w); -#else - [qt_mac_window_for(w) makeKeyWindow]; -#endif + qt_event_request_activate(w); } } +#endif } else { invalidateBuffer(q->rect()); #ifndef QT_MAC_USE_COCOA @@ -4586,9 +4655,12 @@ void QWidgetPrivate::registerDropSite(bool on) #ifndef QT_MAC_USE_COCOA SetControlDragTrackingEnabled(qt_mac_nativeview_for(q), on); #else - NSView *view = qt_mac_nativeview_for(q); - if (on && [view isKindOfClass:[QT_MANGLE_NAMESPACE(QCocoaView) class]]) { - [static_cast<QT_MANGLE_NAMESPACE(QCocoaView) *>(view) registerDragTypes]; + NSWindow *win = qt_mac_window_for(q); + if (on) { + if ([win isKindOfClass:[QT_MANGLE_NAMESPACE(QCocoaWindow) class]]) + [static_cast<QT_MANGLE_NAMESPACE(QCocoaWindow) *>(win) registerDragTypes]; + else if ([win isKindOfClass:[QT_MANGLE_NAMESPACE(QCocoaPanel) class]]) + [static_cast<QT_MANGLE_NAMESPACE(QCocoaPanel) *>(win) registerDragTypes]; } #endif } @@ -4742,7 +4814,7 @@ void QWidgetPrivate::setModal_sys() bool alreadySheet = [windowRef styleMask] & NSDocModalWindowMask; if (windowParent && q->windowModality() == Qt::WindowModal){ - // Window should be window-modal, which implies a sheet. + // INVARIANT: Window should be window-modal (which implies a sheet). if (!alreadySheet) { // NB: the following call will call setModal_sys recursivly: recreateMacWindow(); @@ -4759,47 +4831,19 @@ void QWidgetPrivate::setModal_sys() [static_cast<NSPanel *>(windowRef) setWorksWhenModal:YES]; } } else { - // Window shold not be window-modal, and as such, not a sheet. + // INVARIANT: Window shold _not_ be window-modal (and as such, not a sheet). if (alreadySheet){ // NB: the following call will call setModal_sys recursivly: recreateMacWindow(); windowRef = qt_mac_window_for(q); } - if (q->windowModality() == Qt::ApplicationModal) { - [windowRef setLevel:NSModalPanelWindowLevel]; - } else if (primaryWindow && primaryWindow->windowModality() == Qt::ApplicationModal) { - // INVARIANT: Our window is a dialog that has a dialog parent that is - // application modal, or . This means that q is supposed to be on top of this - // dialog and not be modally shaddowed: - [windowRef setLevel:NSModalPanelWindowLevel]; + if (q->windowModality() == Qt::NonModal + && primaryWindow && primaryWindow->windowModality() == Qt::ApplicationModal) { + // INVARIANT: Our window has a parent that is application modal. + // This means that q is supposed to be on top of this window and + // not be modally shaddowed: if ([windowRef isKindOfClass:[NSPanel class]]) [static_cast<NSPanel *>(windowRef) setWorksWhenModal:YES]; - } else { - // INVARIANT: q should not be modal. - NSInteger winLevel = -1; - if (q->windowType() == Qt::Popup) { - winLevel = NSPopUpMenuWindowLevel; - // Popup should be in at least the same level as its parent. - if (primaryWindow) { - OSWindowRef parentRef = qt_mac_window_for(primaryWindow); - winLevel = qMax([parentRef level], winLevel); - } - } else if (q->windowType() == Qt::Tool) { - winLevel = NSFloatingWindowLevel; - } else if (q->windowType() == Qt::Dialog) { - winLevel = NSModalPanelWindowLevel; - } - - // StayOnTop window should appear above Tool windows. - if (data.window_flags & Qt::WindowStaysOnTopHint) - winLevel = NSPopUpMenuWindowLevel; - // Tooltips should appear above StayOnTop windows. - if (q->windowType() == Qt::ToolTip) - winLevel = NSScreenSaverWindowLevel; - // All other types are Normal level. - if (winLevel == -1) - winLevel = NSNormalWindowLevel; - [windowRef setLevel:winLevel]; } } diff --git a/src/gui/kernel/qwidget_p.h b/src/gui/kernel/qwidget_p.h index b1eb3c3..ff8f276 100644 --- a/src/gui/kernel/qwidget_p.h +++ b/src/gui/kernel/qwidget_p.h @@ -158,6 +158,7 @@ struct QTLWExtra { quint32 newCounterValueLo; #endif #elif defined(Q_WS_WIN) // <--------------------------------------------------------- WIN + uint hotkeyRegistered: 1; // Hot key from the STARTUPINFO has been registered. HICON winIconBig; // internal big Windows icon HICON winIconSmall; // internal small Windows icon #elif defined(Q_WS_MAC) // <--------------------------------------------------------- MAC @@ -384,6 +385,8 @@ public: QRegion prepareToRender(const QRegion ®ion, QWidget::RenderFlags renderFlags); void render_helper(QPainter *painter, const QPoint &targetOffset, const QRegion &sourceRegion, QWidget::RenderFlags renderFlags); + void render(QPaintDevice *target, const QPoint &targetOffset, const QRegion &sourceRegion, + QWidget::RenderFlags renderFlags, bool readyToRender); void drawWidget(QPaintDevice *pdev, const QRegion &rgn, const QPoint &offset, int flags, QPainter *sharedPainter = 0, QWidgetBackingStore *backingStore = 0); @@ -760,6 +763,8 @@ public: void initWindowPtr(); void finishCreateWindow_sys_Carbon(OSWindowRef windowRef); #else + void setSubWindowStacking(bool set); + void setWindowLevel(); void finishCreateWindow_sys_Cocoa(void * /*NSWindow * */ windowRef); void syncCocoaMask(); void finishCocoaMaskSetup(); diff --git a/src/gui/kernel/qwidget_win.cpp b/src/gui/kernel/qwidget_win.cpp index 10522ed..a57aacc 100644 --- a/src/gui/kernel/qwidget_win.cpp +++ b/src/gui/kernel/qwidget_win.cpp @@ -1094,6 +1094,21 @@ void QWidgetPrivate::show_sys() return; } + if (data.window_flags & Qt::Window) { + QTLWExtra *extra = topData(); + if (!extra->hotkeyRegistered) { + // Try to set the hotkey using information from STARTUPINFO + STARTUPINFO startupInfo; + GetStartupInfo(&startupInfo); + // If STARTF_USEHOTKEY is set, hStdInput is the virtual keycode + if (startupInfo.dwFlags & 0x00000200) { + WPARAM hotKey = (WPARAM)startupInfo.hStdInput; + SendMessage(data.winid, WM_SETHOTKEY, hotKey, 0); + } + extra->hotkeyRegistered = 1; + } + } + int sm = SW_SHOWNORMAL; bool fakedMaximize = false; if (q->isWindow()) { @@ -1687,6 +1702,7 @@ void QWidgetPrivate::deleteSysExtra() void QWidgetPrivate::createTLSysExtra() { + extra->topextra->hotkeyRegistered = 0; extra->topextra->savedFlags = 0; extra->topextra->winIconBig = 0; extra->topextra->winIconSmall = 0; diff --git a/src/gui/mac/qt_menu.nib/classes.nib b/src/gui/mac/qt_menu.nib/classes.nib index fed50a3..0031e0e 100644 --- a/src/gui/mac/qt_menu.nib/classes.nib +++ b/src/gui/mac/qt_menu.nib/classes.nib @@ -5,14 +5,6 @@ <key>IBClasses</key> <array> <dict> - <key>CLASS</key> - <string>FirstResponder</string> - <key>LANGUAGE</key> - <string>ObjC</string> - <key>SUPERCLASS</key> - <string>NSObject</string> - </dict> - <dict> <key>ACTIONS</key> <dict> <key>hide</key> @@ -52,6 +44,14 @@ <key>SUPERCLASS</key> <string>NSResponder</string> </dict> + <dict> + <key>CLASS</key> + <string>FirstResponder</string> + <key>LANGUAGE</key> + <string>ObjC</string> + <key>SUPERCLASS</key> + <string>NSObject</string> + </dict> </array> <key>IBVersion</key> <string>1</string> diff --git a/src/gui/mac/qt_menu.nib/info.nib b/src/gui/mac/qt_menu.nib/info.nib index 768cb8b..02e5cca 100644 --- a/src/gui/mac/qt_menu.nib/info.nib +++ b/src/gui/mac/qt_menu.nib/info.nib @@ -3,7 +3,7 @@ <plist version="1.0"> <dict> <key>IBFramework Version</key> - <string>670</string> + <string>672</string> <key>IBOldestOS</key> <integer>5</integer> <key>IBOpenObjects</key> @@ -11,7 +11,7 @@ <integer>57</integer> </array> <key>IBSystem Version</key> - <string>9G55</string> + <string>9L31a</string> <key>targetFramework</key> <string>IBCocoaFramework</string> </dict> diff --git a/src/gui/mac/qt_menu.nib/keyedobjects.nib b/src/gui/mac/qt_menu.nib/keyedobjects.nib Binary files differindex 18a6648..3edb0ed 100644 --- a/src/gui/mac/qt_menu.nib/keyedobjects.nib +++ b/src/gui/mac/qt_menu.nib/keyedobjects.nib diff --git a/src/gui/math3d/qmatrix4x4.h b/src/gui/math3d/qmatrix4x4.h index f9902d7..0671fa8 100644 --- a/src/gui/math3d/qmatrix4x4.h +++ b/src/gui/math3d/qmatrix4x4.h @@ -208,6 +208,8 @@ private: friend class QGraphicsRotation; }; +Q_DECLARE_TYPEINFO(QMatrix4x4, Q_MOVABLE_TYPE); + inline QMatrix4x4::QMatrix4x4 (qreal m11, qreal m12, qreal m13, qreal m14, qreal m21, qreal m22, qreal m23, qreal m24, diff --git a/src/gui/math3d/qquaternion.h b/src/gui/math3d/qquaternion.h index a446f28..16aa5d0 100644 --- a/src/gui/math3d/qquaternion.h +++ b/src/gui/math3d/qquaternion.h @@ -136,6 +136,8 @@ private: qreal wp, xp, yp, zp; }; +Q_DECLARE_TYPEINFO(QQuaternion, Q_MOVABLE_TYPE); + inline QQuaternion::QQuaternion() : wp(1.0f), xp(0.0f), yp(0.0f), zp(0.0f) {} inline QQuaternion::QQuaternion(qreal aScalar, qreal xpos, qreal ypos, qreal zpos) : wp(aScalar), xp(xpos), yp(ypos), zp(zpos) {} diff --git a/src/gui/math3d/qvector2d.h b/src/gui/math3d/qvector2d.h index d76f35a..c92c5e0 100644 --- a/src/gui/math3d/qvector2d.h +++ b/src/gui/math3d/qvector2d.h @@ -126,6 +126,8 @@ private: friend class QVector4D; }; +Q_DECLARE_TYPEINFO(QVector2D, Q_MOVABLE_TYPE); + inline QVector2D::QVector2D() : xp(0.0f), yp(0.0f) {} inline QVector2D::QVector2D(float xpos, float ypos, int) : xp(xpos), yp(ypos) {} diff --git a/src/gui/math3d/qvector3d.h b/src/gui/math3d/qvector3d.h index 80c7152..2fdd1d3 100644 --- a/src/gui/math3d/qvector3d.h +++ b/src/gui/math3d/qvector3d.h @@ -141,6 +141,8 @@ private: #endif }; +Q_DECLARE_TYPEINFO(QVector3D, Q_MOVABLE_TYPE); + inline QVector3D::QVector3D() : xp(0.0f), yp(0.0f), zp(0.0f) {} inline QVector3D::QVector3D(qreal xpos, qreal ypos, qreal zpos) : xp(xpos), yp(ypos), zp(zpos) {} diff --git a/src/gui/math3d/qvector4d.h b/src/gui/math3d/qvector4d.h index 4af2961..a383fbb 100644 --- a/src/gui/math3d/qvector4d.h +++ b/src/gui/math3d/qvector4d.h @@ -138,6 +138,8 @@ private: #endif }; +Q_DECLARE_TYPEINFO(QVector4D, Q_MOVABLE_TYPE); + inline QVector4D::QVector4D() : xp(0.0f), yp(0.0f), zp(0.0f), wp(0.0f) {} inline QVector4D::QVector4D(qreal xpos, qreal ypos, qreal zpos, qreal wpos) : xp(xpos), yp(ypos), zp(zpos), wp(wpos) {} diff --git a/src/gui/painting/qbrush.cpp b/src/gui/painting/qbrush.cpp index 1a83b1d..a82d0f9 100644 --- a/src/gui/painting/qbrush.cpp +++ b/src/gui/painting/qbrush.cpp @@ -912,7 +912,7 @@ void QBrush::setTransform(const QTransform &matrix) otherwise returns false. Two brushes are different if they have different styles, colors or - pixmaps. + transforms or different pixmaps or gradients depending on the style. \sa operator==() */ @@ -924,7 +924,7 @@ void QBrush::setTransform(const QTransform &matrix) otherwise returns false. Two brushes are equal if they have equal styles, colors and - pixmaps. + transforms and equal pixmaps or gradients depending on the style. \sa operator!=() */ @@ -933,26 +933,26 @@ bool QBrush::operator==(const QBrush &b) const { if (b.d == d) return true; - if (b.d->style == d->style && b.d->color == d->color) { - switch (d->style) { - case Qt::TexturePattern: { - QPixmap &us = (static_cast<QTexturedBrushData *>(d.data()))->pixmap(); - QPixmap &them = (static_cast<QTexturedBrushData *>(b.d.data()))->pixmap(); + if (b.d->style != d->style || b.d->color != d->color || b.d->transform != d->transform) + return false; + switch (d->style) { + case Qt::TexturePattern: + { + const QPixmap &us = (static_cast<QTexturedBrushData *>(d.data()))->pixmap(); + const QPixmap &them = (static_cast<QTexturedBrushData *>(b.d.data()))->pixmap(); return ((us.isNull() && them.isNull()) || us.cacheKey() == them.cacheKey()); } - case Qt::LinearGradientPattern: - case Qt::RadialGradientPattern: - case Qt::ConicalGradientPattern: - { - QGradientBrushData *d1 = static_cast<QGradientBrushData *>(d.data()); - QGradientBrushData *d2 = static_cast<QGradientBrushData *>(b.d.data()); - return d1->gradient == d2->gradient; - } - default: - return true; + case Qt::LinearGradientPattern: + case Qt::RadialGradientPattern: + case Qt::ConicalGradientPattern: + { + const QGradientBrushData *d1 = static_cast<QGradientBrushData *>(d.data()); + const QGradientBrushData *d2 = static_cast<QGradientBrushData *>(b.d.data()); + return d1->gradient == d2->gradient; } + default: + return true; } - return false; } /*! diff --git a/src/gui/painting/qdatabuffer_p.h b/src/gui/painting/qdatabuffer_p.h index a7834ea..bc5f1ef 100644 --- a/src/gui/painting/qdatabuffer_p.h +++ b/src/gui/painting/qdatabuffer_p.h @@ -81,7 +81,9 @@ public: inline Type &at(int i) { Q_ASSERT(i >= 0 && i < siz); return buffer[i]; } inline const Type &at(int i) const { Q_ASSERT(i >= 0 && i < siz); return buffer[i]; } + inline Type &last() { Q_ASSERT(!isEmpty()); return buffer[siz-1]; } inline const Type &last() const { Q_ASSERT(!isEmpty()); return buffer[siz-1]; } + inline Type &first() { Q_ASSERT(!isEmpty()); return buffer[0]; } inline const Type &first() const { Q_ASSERT(!isEmpty()); return buffer[0]; } inline void add(const Type &t) { @@ -90,6 +92,11 @@ public: ++siz; } + inline void pop_back() { + Q_ASSERT(siz > 0); + --siz; + } + inline void resize(int size) { reserve(size); siz = size; diff --git a/src/gui/painting/qemulationpaintengine.cpp b/src/gui/painting/qemulationpaintengine.cpp index f2f0c73..fd42736 100644 --- a/src/gui/painting/qemulationpaintengine.cpp +++ b/src/gui/painting/qemulationpaintengine.cpp @@ -172,6 +172,36 @@ void QEmulationPaintEngine::drawTextItem(const QPointF &p, const QTextItem &text QRectF rect(p.x(), p.y() - ti.ascent.toReal(), ti.width.toReal(), (ti.ascent + ti.descent + 1).toReal()); fillBGRect(rect); } + + QPainterState *s = state(); + Qt::BrushStyle style = qbrush_style(s->pen.brush()); + if (style >= Qt::LinearGradientPattern && style <= Qt::ConicalGradientPattern) + { + QPen savedPen = s->pen; + QGradient g = *s->pen.brush().gradient(); + + if (g.coordinateMode() > QGradient::LogicalMode) { + QTransform mat = s->pen.brush().transform(); + if (g.coordinateMode() == QGradient::StretchToDeviceMode) { + mat.scale(real_engine->painter()->device()->width(), real_engine->painter()->device()->height()); + } else if (g.coordinateMode() == QGradient::ObjectBoundingMode) { + const QTextItemInt &ti = static_cast<const QTextItemInt &>(textItem); + QRectF r(p.x(), p.y() - ti.ascent.toReal(), ti.width.toReal(), (ti.ascent + ti.descent + 1).toReal()); + mat.translate(r.x(), r.y()); + mat.scale(r.width(), r.height()); + } + g.setCoordinateMode(QGradient::LogicalMode); + QBrush brush(g); + brush.setTransform(mat); + s->pen.setBrush(brush); + penChanged(); + real_engine->drawTextItem(p, textItem); + s->pen = savedPen; + penChanged(); + return; + } + } + real_engine->drawTextItem(p, textItem); } diff --git a/src/gui/painting/qpainterpath.cpp b/src/gui/painting/qpainterpath.cpp index fba3595..f78de34 100644 --- a/src/gui/painting/qpainterpath.cpp +++ b/src/gui/painting/qpainterpath.cpp @@ -1257,6 +1257,8 @@ Qt::FillRule QPainterPath::fillRule() const void QPainterPath::setFillRule(Qt::FillRule fillRule) { ensureData(); + if (d_func()->fillRule == fillRule) + return; detach(); d_func()->fillRule = fillRule; diff --git a/src/gui/statemachine/qguistatemachine.cpp b/src/gui/statemachine/qguistatemachine.cpp index 70f152d..63ad94e 100644 --- a/src/gui/statemachine/qguistatemachine.cpp +++ b/src/gui/statemachine/qguistatemachine.cpp @@ -469,12 +469,6 @@ static QEvent *cloneEvent(QEvent *e) case QEvent::UngrabKeyboard: return new QEvent(*e); -#ifdef QT_MAC_USE_COCOA - case QEvent::CocoaRequestModal: - Q_ASSERT_X(false, "cloneEvent()", "not implemented"); - break; -#endif - case QEvent::TouchBegin: case QEvent::TouchUpdate: case QEvent::TouchEnd: diff --git a/src/gui/styles/qcommonstyle.cpp b/src/gui/styles/qcommonstyle.cpp index 74d3ec3..3132dd1 100644 --- a/src/gui/styles/qcommonstyle.cpp +++ b/src/gui/styles/qcommonstyle.cpp @@ -5662,10 +5662,16 @@ QIcon QCommonStyle::standardIconImplementation(StandardPixmap standardIcon, cons OSType iconType = 0; switch (standardIcon) { case QStyle::SP_MessageBoxQuestion: + iconType = kQuestionMarkIcon; + break; case QStyle::SP_MessageBoxInformation: + iconType = kAlertNoteIcon; + break; case QStyle::SP_MessageBoxWarning: + iconType = kAlertCautionIcon; + break; case QStyle::SP_MessageBoxCritical: - iconType = kGenericApplicationIcon; + iconType = kAlertStopIcon; break; case SP_DesktopIcon: iconType = kDesktopIcon; diff --git a/src/gui/styles/qmacstyle_mac.mm b/src/gui/styles/qmacstyle_mac.mm index aab16cb..a077cf0 100644 --- a/src/gui/styles/qmacstyle_mac.mm +++ b/src/gui/styles/qmacstyle_mac.mm @@ -3146,6 +3146,18 @@ void QMacStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPai break; case PE_PanelLineEdit: QWindowsStyle::drawPrimitive(pe, opt, p, w); + // Draw the focus frame for widgets other than QLineEdit (e.g. for line edits in Webkit). + // Focus frame is drawn outside the rectangle passed in the option-rect. + if (const QStyleOptionFrame *panel = qstyleoption_cast<const QStyleOptionFrame *>(opt)) { + if ((opt->state & State_HasFocus) && !qobject_cast<const QLineEdit*>(w)) { + int vmargin = pixelMetric(QStyle::PM_FocusFrameVMargin); + int hmargin = pixelMetric(QStyle::PM_FocusFrameHMargin); + QStyleOptionFrame focusFrame = *panel; + focusFrame.rect = panel->rect.adjusted(-hmargin, -vmargin, hmargin, vmargin); + drawControl(CE_FocusFrame, &focusFrame, p, w); + } + } + break; case PE_FrameTabWidget: if (const QStyleOptionTabWidgetFrame *twf @@ -3169,7 +3181,6 @@ void QMacStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPai p->drawLine(opt->rect.topLeft(), opt->rect.bottomLeft()); } break; case PE_FrameStatusBarItem: - QCommonStyle::drawPrimitive(pe, opt, p, w); break; case PE_IndicatorTabClose: { bool hover = (opt->state & State_MouseOver); diff --git a/src/gui/styles/qs60style_s60.cpp b/src/gui/styles/qs60style_s60.cpp index 872bc2b..6d9ba05 100644 --- a/src/gui/styles/qs60style_s60.cpp +++ b/src/gui/styles/qs60style_s60.cpp @@ -58,8 +58,8 @@ #include <aknsskininstance.h> #include <aknsbasicbackgroundcontrolcontext.h> #include <avkon.mbg> -#include <AknFontAccess.h> -#include <AknLayoutFont.h> +#include <aknfontaccess.h> +#include <aknlayoutfont.h> #include <aknutils.h> #include <aknnavi.h> #include <gulicon.h> diff --git a/src/gui/styles/qstylesheetstyle.cpp b/src/gui/styles/qstylesheetstyle.cpp index 498313b..9002172 100644 --- a/src/gui/styles/qstylesheetstyle.cpp +++ b/src/gui/styles/qstylesheetstyle.cpp @@ -1065,7 +1065,7 @@ QRect QRenderRule::boxRect(const QRect& cr, int flags) const r.adjust(-p[LeftEdge], -p[TopEdge], p[RightEdge], p[BottomEdge]); } } - if (!hasNativeBorder() && (flags & Border)) { + if (hasBorder() && (flags & Border)) { const int *b = border()->borders; r.adjust(-b[LeftEdge], -b[TopEdge], b[RightEdge], b[BottomEdge]); } @@ -1350,6 +1350,12 @@ void QRenderRule::configurePalette(QPalette *p, QPalette::ColorRole fr, QPalette if (br != QPalette::NoRole) p->setBrush(br, bg->brush); p->setBrush(QPalette::Window, bg->brush); + if (bg->brush.style() == Qt::SolidPattern) { + p->setBrush(QPalette::Light, bg->brush.color().lighter(115)); + p->setBrush(QPalette::Midlight, bg->brush.color().lighter(107)); + p->setBrush(QPalette::Dark, bg->brush.color().darker(150)); + p->setBrush(QPalette::Shadow, bg->brush.color().darker(300)); + } } if (!hasPalette()) diff --git a/src/gui/text/qfontdatabase_s60.cpp b/src/gui/text/qfontdatabase_s60.cpp index f8de08f..3ae6fe9 100644 --- a/src/gui/text/qfontdatabase_s60.cpp +++ b/src/gui/text/qfontdatabase_s60.cpp @@ -50,7 +50,7 @@ #include "qendian.h" #include <private/qcore_symbian_p.h> #if defined(QT_NO_FREETYPE) -#include <OPENFONT.H> +#include <openfont.h> #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS #include <graphics/openfontrasterizer.h> // COpenFontRasterizer has moved to a new header file #endif // SYMBIAN_ENABLE_SPLIT_HEADERS diff --git a/src/gui/text/qfontdatabase_win.cpp b/src/gui/text/qfontdatabase_win.cpp index 05c8f08..b30a6c3 100644 --- a/src/gui/text/qfontdatabase_win.cpp +++ b/src/gui/text/qfontdatabase_win.cpp @@ -1101,7 +1101,6 @@ static void registerFont(QFontDatabasePrivate::ApplicationFont *fnt) if (AddFontResource((LPCWSTR)fnt->fileName.utf16()) == 0) return; #else - // supported from 2000 on, so no need to deal with the *A variant PtrAddFontResourceExW ptrAddFontResourceExW = (PtrAddFontResourceExW)QLibrary::resolve(QLatin1String("gdi32"), "AddFontResourceExW"); if (!ptrAddFontResourceExW diff --git a/src/gui/text/qfontengine_s60_p.h b/src/gui/text/qfontengine_s60_p.h index 78f8a9a..5834cc4 100644 --- a/src/gui/text/qfontengine_s60_p.h +++ b/src/gui/text/qfontengine_s60_p.h @@ -56,7 +56,7 @@ #include "qconfig.h" #include "qfontengine_p.h" #include "qsize.h" -#include <OPENFONT.H> +#include <openfont.h> class CFont; diff --git a/src/gui/text/qtextdocument.cpp b/src/gui/text/qtextdocument.cpp index 21f3189..b8c9b94 100644 --- a/src/gui/text/qtextdocument.cpp +++ b/src/gui/text/qtextdocument.cpp @@ -61,6 +61,7 @@ #include <qapplication.h> #include "qtextcontrol_p.h" #include "private/qtextedit_p.h" +#include "private/qdataurl_p.h" #include "qtextdocument_p.h" #include <private/qprinter_p.h> @@ -1924,6 +1925,10 @@ QVariant QTextDocument::loadResource(int type, const QUrl &name) } #endif + // handle data: URLs + if (r.isNull() && name.scheme() == QLatin1String("data")) + r = qDecodeDataUrl(name).second; + // if resource was not loaded try to load it here if (!doc && r.isNull() && name.isRelative()) { QUrl currentURL = d->url; diff --git a/src/gui/util/qcompleter.cpp b/src/gui/util/qcompleter.cpp index cefdb27..b7be967 100644 --- a/src/gui/util/qcompleter.cpp +++ b/src/gui/util/qcompleter.cpp @@ -62,7 +62,7 @@ \snippet doc/src/snippets/code/src_gui_util_qcompleter.cpp 0 - A QDirModel can be used to provide auto completion of file names. + A QFileSystemModel can be used to provide auto completion of file names. For example: \snippet doc/src/snippets/code/src_gui_util_qcompleter.cpp 1 @@ -120,7 +120,7 @@ completion is then performed one level at a time. Let's take the example of a user typing in a file system path. - The model is a (hierarchical) QDirModel. The completion + The model is a (hierarchical) QFileSystemModel. The completion occurs for every element in the path. For example, if the current text is \c C:\Wind, QCompleter might suggest \c Windows to complete the current path element. Similarly, if the current text @@ -130,12 +130,12 @@ split the path into a list of strings that are matched at each level. For \c C:\Windows\Sy, it needs to be split as "C:", "Windows" and "Sy". The default implementation of splitPath(), splits the completionPrefix - using QDir::separator() if the model is a QDirModel. + using QDir::separator() if the model is a QFileSystemModel. To provide completions, QCompleter needs to know the path from an index. This is provided by pathFromIndex(). The default implementation of pathFromIndex(), returns the data for the \l{Qt::EditRole}{edit role} - for list models and the absolute file path if the mode is a QDirModel. + for list models and the absolute file path if the mode is a QFileSystemModel. \sa QAbstractItemModel, QLineEdit, QComboBox, {Completer Example} */ @@ -147,6 +147,7 @@ #include "QtGui/qscrollbar.h" #include "QtGui/qstringlistmodel.h" #include "QtGui/qdirmodel.h" +#include "QtGui/qfilesystemmodel.h" #include "QtGui/qheaderview.h" #include "QtGui/qlistview.h" #include "QtGui/qapplication.h" @@ -470,9 +471,13 @@ QMatchData QCompletionEngine::filterHistory() QAbstractItemModel *source = c->proxy->sourceModel(); if (curParts.count() <= 1 || c->proxy->showAll || !source) return QMatchData(); - bool dirModel = false; + bool isDirModel = false; + bool isFsModel = false; #ifndef QT_NO_DIRMODEL - dirModel = (qobject_cast<QDirModel *>(source) != 0); + isDirModel = (qobject_cast<QDirModel *>(source) != 0); +#endif +#ifndef QT_NO_FILESYSTEMMODEL + isFsModel = (qobject_cast<QFileSystemModel *>(source) != 0); #endif QVector<int> v; QIndexMapper im(v); @@ -482,7 +487,7 @@ QMatchData QCompletionEngine::filterHistory() QString str = source->index(i, c->column).data().toString(); if (str.startsWith(c->prefix, c->cs) #if (!defined(Q_OS_WIN) || defined(Q_OS_WINCE)) && !defined(Q_OS_SYMBIAN) - && (!dirModel || QDir::toNativeSeparators(str) != QDir::separator()) + && ((!isFsModel && !isDirModel) || QDir::toNativeSeparators(str) != QDir::separator()) #endif ) m.indices.append(i); @@ -838,6 +843,13 @@ void QCompleterPrivate::_q_complete(QModelIndex index, bool highlighted) completion += QDir::separator(); } #endif +#ifndef QT_NO_FILESYSTEMMODEL + // add a trailing separator in inline + if (mode == QCompleter::InlineCompletion) { + if (qobject_cast<QFileSystemModel *>(proxy->sourceModel()) && QFileInfo(completion).isDir()) + completion += QDir::separator(); + } +#endif } if (highlighted) { @@ -891,6 +903,14 @@ void QCompleterPrivate::showPopup(const QRect& rect) popup->show(); } +void QCompleterPrivate::_q_fileSystemModelDirectoryLoaded(const QString &path) +{ + Q_Q(QCompleter); + //the path given by QFileSystemModel does not end with / + if (q->completionPrefix() != path + QLatin1Char('/')) + q->complete(); +} + /*! Constructs a completer object with the given \a parent. */ @@ -971,7 +991,7 @@ QWidget *QCompleter::widget() const be list model or a tree model. If a model has been already previously set and it has the QCompleter as its parent, it is deleted. - For convenience, if \a model is a QDirModel, QCompleter switches its + For convenience, if \a model is a QFileSystemModel, QCompleter switches its caseSensitivity to Qt::CaseInsensitive on Windows and Qt::CaseSensitive on other platforms. @@ -995,6 +1015,18 @@ void QCompleter::setModel(QAbstractItemModel *model) #endif } #endif // QT_NO_DIRMODEL +#ifndef QT_NO_FILESYSTEMMODEL + QFileSystemModel *fsModel = qobject_cast<QFileSystemModel *>(model); + if (fsModel) { +#if (defined(Q_OS_WIN) && !defined(Q_OS_WINCE)) || defined(Q_OS_SYMBIAN) + setCaseSensitivity(Qt::CaseInsensitive); +#else + setCaseSensitivity(Qt::CaseSensitive); +#endif + setCompletionRole(QFileSystemModel::FileNameRole); + connect(fsModel, SIGNAL(directoryLoaded(QString)), this, SLOT(_q_fileSystemModelDirectoryLoaded(QString))); + } +#endif // QT_NO_FILESYSTEMMODEL } /*! @@ -1626,10 +1658,11 @@ QAbstractItemModel *QCompleter::completionModel() const The default implementation returns the \l{Qt::EditRole}{edit role} of the item for list models. It returns the absolute file path if the model is a - QDirModel. + QFileSystemModel. \sa splitPath() */ + QString QCompleter::pathFromIndex(const QModelIndex& index) const { Q_D(const QCompleter); @@ -1639,16 +1672,25 @@ QString QCompleter::pathFromIndex(const QModelIndex& index) const QAbstractItemModel *sourceModel = d->proxy->sourceModel(); if (!sourceModel) return QString(); + bool isDirModel = false; + bool isFsModel = false; #ifndef QT_NO_DIRMODEL - QDirModel *dirModel = qobject_cast<QDirModel *>(sourceModel); - if (!dirModel) + isDirModel = qobject_cast<QDirModel *>(d->proxy->sourceModel()) != 0; +#endif +#ifndef QT_NO_FILESYSTEMMODEL + isFsModel = qobject_cast<QFileSystemModel *>(d->proxy->sourceModel()) != 0; #endif + if (!isDirModel && !isFsModel) return sourceModel->data(index, d->role).toString(); QModelIndex idx = index; QStringList list; do { - QString t = sourceModel->data(idx, Qt::EditRole).toString(); + QString t; + if (isDirModel) + t = sourceModel->data(idx, Qt::EditRole).toString(); + else + t = sourceModel->data(idx, QFileSystemModel::FileNameRole).toString(); list.prepend(t); QModelIndex parent = idx.parent(); idx = parent.sibling(parent.row(), index.column()); @@ -1668,7 +1710,7 @@ QString QCompleter::pathFromIndex(const QModelIndex& index) const in the model(). The default implementation of splitPath() splits a file system path based on - QDir::separator() when the sourceModel() is a QDirModel. + QDir::separator() when the sourceModel() is a QFileSystemModel. When used with list models, the first item in the returned list is used for matching. @@ -1678,12 +1720,19 @@ QString QCompleter::pathFromIndex(const QModelIndex& index) const QStringList QCompleter::splitPath(const QString& path) const { bool isDirModel = false; + bool isFsModel = false; #ifndef QT_NO_DIRMODEL Q_D(const QCompleter); isDirModel = qobject_cast<QDirModel *>(d->proxy->sourceModel()) != 0; #endif +#ifndef QT_NO_FILESYSTEMMODEL +#ifdef QT_NO_DIRMODEL + Q_D(const QCompleter); +#endif + isFsModel = qobject_cast<QFileSystemModel *>(d->proxy->sourceModel()) != 0; +#endif - if (!isDirModel || path.isEmpty()) + if ((!isDirModel && !isFsModel) || path.isEmpty()) return QStringList(completionPrefix()); QString pathCopy = QDir::toNativeSeparators(path); diff --git a/src/gui/util/qcompleter.h b/src/gui/util/qcompleter.h index 5123a40..0cef9be 100644 --- a/src/gui/util/qcompleter.h +++ b/src/gui/util/qcompleter.h @@ -159,6 +159,7 @@ private: Q_PRIVATE_SLOT(d_func(), void _q_complete(QModelIndex)) Q_PRIVATE_SLOT(d_func(), void _q_completionSelected(const QItemSelection&)) Q_PRIVATE_SLOT(d_func(), void _q_autoResizePopup()) + Q_PRIVATE_SLOT(d_func(), void _q_fileSystemModelDirectoryLoaded(const QString&)) }; #endif // QT_NO_COMPLETER diff --git a/src/gui/util/qcompleter_p.h b/src/gui/util/qcompleter_p.h index 44be4c0..8f00793 100644 --- a/src/gui/util/qcompleter_p.h +++ b/src/gui/util/qcompleter_p.h @@ -98,6 +98,7 @@ public: void _q_complete(QModelIndex, bool = false); void _q_completionSelected(const QItemSelection&); void _q_autoResizePopup(); + void _q_fileSystemModelDirectoryLoaded(const QString &path); void setCurrentIndex(QModelIndex, bool = true); }; diff --git a/src/gui/util/qdesktopservices_win.cpp b/src/gui/util/qdesktopservices_win.cpp index 9f3b6e1..aab7e16 100644 --- a/src/gui/util/qdesktopservices_win.cpp +++ b/src/gui/util/qdesktopservices_win.cpp @@ -59,7 +59,7 @@ # endif #endif -#if defined(Q_CC_MINGW) && !defined(CSIDL_MYMUSIC) +#ifndef CSIDL_MYMUSIC #define CSIDL_MYMUSIC 13 #define CSIDL_MYVIDEO 14 #endif @@ -97,19 +97,19 @@ static bool launchWebBrowser(const QUrl &url) if (url.scheme() == QLatin1String("mailto")) { //Retrieve the commandline for the default mail client //the default key used below is the command line for the mailto: shell command - DWORD bufferSize = 2 * MAX_PATH; + DWORD bufferSize = sizeof(wchar_t) * MAX_PATH; long returnValue = -1; QString command; HKEY handle; LONG res; - wchar_t keyValue[2 * MAX_PATH] = {0}; + wchar_t keyValue[MAX_PATH] = {0}; QString keyName(QLatin1String("mailto")); //Check if user has set preference, otherwise use default. - res = RegOpenKeyExW(HKEY_CURRENT_USER, - L"Software\\Microsoft\\Windows\\Shell\\Associations\\UrlAssociations\\mailto\\UserChoice", - 0, KEY_READ, &handle); + res = RegOpenKeyEx(HKEY_CURRENT_USER, + L"Software\\Microsoft\\Windows\\Shell\\Associations\\UrlAssociations\\mailto\\UserChoice", + 0, KEY_READ, &handle); if (res == ERROR_SUCCESS) { returnValue = RegQueryValueEx(handle, L"Progid", 0, 0, reinterpret_cast<unsigned char*>(keyValue), &bufferSize); if (!returnValue) @@ -121,8 +121,8 @@ static bool launchWebBrowser(const QUrl &url) if (res != ERROR_SUCCESS) return false; - bufferSize = 2 * MAX_PATH; - returnValue = RegQueryValueExW(handle, L"", 0, 0, reinterpret_cast<unsigned char*>(keyValue), &bufferSize); + bufferSize = sizeof(wchar_t) * MAX_PATH; + returnValue = RegQueryValueEx(handle, L"", 0, 0, reinterpret_cast<unsigned char*>(keyValue), &bufferSize); if (!returnValue) command = QString::fromRawData((QChar*)keyValue, bufferSize); RegCloseKey(handle); diff --git a/src/gui/util/qsystemtrayicon_win.cpp b/src/gui/util/qsystemtrayicon_win.cpp index 6db158e..092909f 100644 --- a/src/gui/util/qsystemtrayicon_win.cpp +++ b/src/gui/util/qsystemtrayicon_win.cpp @@ -53,7 +53,6 @@ #include <qt_windows.h> #include <commctrl.h> -#include <shlwapi.h> #include <QBitmap> #include <QLibrary> #include <QApplication> diff --git a/src/gui/widgets/qcocoamenu_mac.mm b/src/gui/widgets/qcocoamenu_mac.mm index a7e0b79..ce85919 100644 --- a/src/gui/widgets/qcocoamenu_mac.mm +++ b/src/gui/widgets/qcocoamenu_mac.mm @@ -46,6 +46,7 @@ #import <private/qcocoamenuloader_mac_p.h> #include <private/qt_cocoa_helpers_mac_p.h> #include <private/qapplication_p.h> +#include <private/qaction_p.h> #include <QtGui/QMenu> @@ -70,6 +71,7 @@ QT_USE_NAMESPACE self = [super init]; if (self) { qmenu = menu; + previousAction = 0; [self setAutoenablesItems:NO]; [self setDelegate:self]; } @@ -81,13 +83,20 @@ QT_USE_NAMESPACE Q_UNUSED(menu); if (!item) { - // ### According to the docs everything will be highlighted. Not sure what we should do in - // Qt, so just return. + if (previousAction) { + qt_mac_clear_status_text(previousAction); + previousAction = 0; + } return; } - if (QAction *action = reinterpret_cast<QAction *>([item tag])) + if (QAction *action = reinterpret_cast<QAction *>([item tag])) { + QMenu *qtmenu = static_cast<QT_MANGLE_NAMESPACE(QCocoaMenu) *>(menu)->qmenu; + previousAction = action; action->activate(QAction::Hover); + qt_mac_menu_emit_hovered(qtmenu, action); + action->showStatusText(0); // 0 widget -> action's parent + } } - (void)menuWillOpen:(NSMenu*)menu; @@ -100,9 +109,13 @@ QT_USE_NAMESPACE qt_mac_menu_collapseSeparators(menu, qtmenu->separatorsCollapsible()); } -- (void)menuWillClose:(NSMenu*)menu; +- (void)menuDidClose:(NSMenu*)menu; { qt_mac_emit_menuSignals(((QT_MANGLE_NAMESPACE(QCocoaMenu) *)menu)->qmenu, false); + if (previousAction) { + qt_mac_clear_status_text(previousAction); + previousAction = 0; + } } - (BOOL)hasShortcut:(NSMenu *)menu forKey:(NSString *)key forModifiers:(NSUInteger)modifier @@ -194,6 +207,18 @@ void qt_mac_emit_menuSignals(QMenu *menu, bool show) } qt_mac_menus_open_count += delta; } + +void qt_mac_clear_status_text(QAction *action) +{ + action->d_func()->showStatusText(0, QString()); +} + +void qt_mac_menu_emit_hovered(QMenu *menu, QAction *action) +{ + emit menu->hovered(action); +} + + QT_END_NAMESPACE #endif diff --git a/src/gui/widgets/qcocoamenu_mac_p.h b/src/gui/widgets/qcocoamenu_mac_p.h index 9f50c40..d6ac8c5 100644 --- a/src/gui/widgets/qcocoamenu_mac_p.h +++ b/src/gui/widgets/qcocoamenu_mac_p.h @@ -55,13 +55,14 @@ #import <Cocoa/Cocoa.h> QT_FORWARD_DECLARE_CLASS(QMenu) +QT_FORWARD_DECLARE_CLASS(QAction) #if MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_5 @protocol NSMenuDelegate <NSObject> - (void)menu:(NSMenu*)menu willHighlightItem:(NSMenuItem*)item; - (void)menuWillOpen:(NSMenu*)menu; -- (void)menuWillClose:(NSMenu*)menu; +- (void)menuDidClose:(NSMenu*)menu; - (BOOL)hasShortcut:(NSMenu *)menu forKey:(NSString *)key forModifiers:(NSUInteger)modifier whichItem:(NSMenuItem**)outItem; @end @@ -71,6 +72,7 @@ QT_FORWARD_DECLARE_CLASS(QMenu) @interface QT_MANGLE_NAMESPACE(QCocoaMenu) : NSMenu <NSMenuDelegate> { QMenu *qmenu; + QAction *previousAction; } - (id)initWithQMenu:(QMenu*)menu; - (BOOL)menuHasKeyEquivalent:(NSMenu *)menu forEvent:(NSEvent *)event target:(id *)target action:(SEL *)action; diff --git a/src/gui/widgets/qcombobox.cpp b/src/gui/widgets/qcombobox.cpp index 72f32dc..be20a38 100644 --- a/src/gui/widgets/qcombobox.cpp +++ b/src/gui/widgets/qcombobox.cpp @@ -1268,7 +1268,8 @@ QComboBox::~QComboBox() By default, this property has a value of 10. - \note This property is ignored for non-editable comboboxes in Mac style. + \note This property is ignored for non-editable comboboxes in styles that returns + false for QStyle::SH_ComboBox_Popup such as the Mac style or the Gtk+ Style. */ int QComboBox::maxVisibleItems() const { @@ -2348,7 +2349,7 @@ void QComboBox::showPopup() toCheck.push(idx); #endif ++count; - if (!usePopup && count > d->maxVisibleItems) { + if (!usePopup && count >= d->maxVisibleItems) { toCheck.clear(); break; } diff --git a/src/gui/widgets/qfocusframe.cpp b/src/gui/widgets/qfocusframe.cpp index d9cd5bb..4f20bce0 100644 --- a/src/gui/widgets/qfocusframe.cpp +++ b/src/gui/widgets/qfocusframe.cpp @@ -53,11 +53,14 @@ class QFocusFramePrivate : public QWidgetPrivate { Q_DECLARE_PUBLIC(QFocusFrame) QWidget *widget; - + QWidget *frameParent; + bool showFrameAboveWidget; public: QFocusFramePrivate() { widget = 0; + frameParent = 0; sendChildEvents = false; + showFrameAboveWidget = false; } void updateSize(); void update(); @@ -66,10 +69,10 @@ public: void QFocusFramePrivate::update() { Q_Q(QFocusFrame); - q->setParent(widget->parentWidget()); + q->setParent(frameParent); updateSize(); if (q->parentWidget()->rect().intersects(q->geometry())) { - if (q->style()->styleHint(QStyle::SH_FocusFrame_AboveWidget, 0, q)) + if (showFrameAboveWidget) q->raise(); else q->stackUnder(widget); @@ -84,7 +87,10 @@ void QFocusFramePrivate::updateSize() Q_Q(QFocusFrame); int vmargin = q->style()->pixelMetric(QStyle::PM_FocusFrameVMargin), hmargin = q->style()->pixelMetric(QStyle::PM_FocusFrameHMargin); - QRect geom(widget->x()-hmargin, widget->y()-vmargin, + QPoint pos(widget->x(), widget->y()); + if (q->parentWidget() != widget->parentWidget()) + pos = widget->parentWidget()->mapTo(q->parentWidget(), pos); + QRect geom(pos.x()-hmargin, pos.y()-vmargin, widget->width()+(hmargin*2), widget->height()+(vmargin*2)); if(q->geometry() == geom) return; @@ -176,14 +182,52 @@ void QFocusFrame::setWidget(QWidget *widget) { Q_D(QFocusFrame); - if(widget == d->widget) - return; - if(d->widget) - d->widget->removeEventFilter(this); - if(widget && !widget->isWindow() && widget->parentWidget()->windowType() != Qt::SubWindow) { + if (style()->styleHint(QStyle::SH_FocusFrame_AboveWidget, 0, this)) + d->showFrameAboveWidget = true; + else + d->showFrameAboveWidget = false; + + if (widget == d->widget) + return; + if (d->widget) { + // Remove event filters from the widget hierarchy. + QWidget *p = d->widget; + do { + p->removeEventFilter(this); + if (!d->showFrameAboveWidget || p == d->frameParent) + break; + p = p->parentWidget(); + }while (p); + } + if (widget && !widget->isWindow() && widget->parentWidget()->windowType() != Qt::SubWindow) { d->widget = widget; - widget->installEventFilter(this); + d->widget->installEventFilter(this); + QWidget *p = widget->parentWidget(); + QWidget *prev = 0; + if (d->showFrameAboveWidget) { + // Find the right parent for the focus frame. + while (p) { + // Traverse the hirerarchy of the 'widget' for setting event filter. + // During this if come across toolbar or a top level, use that + // as the parent for the focus frame. If we find a scroll area + // use its viewport as the parent. + bool isScrollArea = false; + if (p->isWindow() || p->inherits("QToolBar") || (isScrollArea = p->inherits("QAbstractScrollArea"))) { + d->frameParent = p; + // The previous one in the hierarchy will be the viewport. + if (prev && isScrollArea) + d->frameParent = prev; + break; + } else { + p->installEventFilter(this); + prev = p; + p = p->parentWidget(); + } + } + } else { + d->frameParent = p; + } d->update(); } else { d->widget = 0; @@ -210,9 +254,15 @@ QFocusFrame::widget() const void QFocusFrame::paintEvent(QPaintEvent *) { + Q_D(QFocusFrame); QStylePainter p(this); QStyleOption option; initStyleOption(&option); + int vmargin = style()->pixelMetric(QStyle::PM_FocusFrameVMargin); + int hmargin = style()->pixelMetric(QStyle::PM_FocusFrameHMargin); + QWidgetPrivate *wd = qt_widget_private(d->widget); + QRect rect = wd->clipRect().adjusted(0, 0, hmargin*2, vmargin*2); + p.setClipRect(rect); p.drawControl(QStyle::CE_FocusFrame, option); } @@ -233,7 +283,13 @@ QFocusFrame::eventFilter(QObject *o, QEvent *e) hide(); break; case QEvent::ParentChange: - d->update(); + if (d->showFrameAboveWidget) { + QWidget *w = d->widget; + setWidget(0); + setWidget(w); + } else { + d->update(); + } break; case QEvent::Show: d->update(); @@ -254,6 +310,19 @@ QFocusFrame::eventFilter(QObject *o, QEvent *e) default: break; } + } else if (d->showFrameAboveWidget) { + // Handle changes in the parent widgets we are monitoring. + switch(e->type()) { + case QEvent::Move: + case QEvent::Resize: + d->updateSize(); + break; + case QEvent::ZOrderChange: + raise(); + break; + default: + break; + } } return false; } diff --git a/src/gui/widgets/qlabel.cpp b/src/gui/widgets/qlabel.cpp index 8428ad7..c779312 100644 --- a/src/gui/widgets/qlabel.cpp +++ b/src/gui/widgets/qlabel.cpp @@ -781,6 +781,95 @@ Qt::TextInteractionFlags QLabel::textInteractionFlags() const return d->textInteractionFlags; } +/*! + Selects text from position \a start and for \a length characters. + + \sa selectedText() + + \bold{Note:} The textInteractionFlags set on the label need to include + either TextSelectableByMouse or TextSelectableByKeyboard. + + \since 4.7 +*/ +void QLabel::setSelection(int start, int length) +{ + Q_D(QLabel); + if (d->control) { + d->ensureTextPopulated(); + QTextCursor cursor = d->control->textCursor(); + cursor.setPosition(start); + cursor.setPosition(start + length, QTextCursor::KeepAnchor); + d->control->setTextCursor(cursor); + } +} + +/*! + \property QLabel::hasSelectedText + \brief whether there is any text selected + + hasSelectedText() returns true if some or all of the text has been + selected by the user; otherwise returns false. + + By default, this property is false. + + \sa selectedText() + + \bold{Note:} The textInteractionFlags set on the label need to include + either TextSelectableByMouse or TextSelectableByKeyboard. + + \since 4.7 +*/ +bool QLabel::hasSelectedText() const +{ + Q_D(const QLabel); + if (d->control) + return d->control->textCursor().hasSelection(); + return false; +} + +/*! + \property QLabel::selectedText + \brief the selected text + + If there is no selected text this property's value is + an empty string. + + By default, this property contains an empty string. + + \sa hasSelectedText() + + \bold{Note:} The textInteractionFlags set on the label need to include + either TextSelectableByMouse or TextSelectableByKeyboard. + + \since 4.7 +*/ +QString QLabel::selectedText() const +{ + Q_D(const QLabel); + if (d->control) + return d->control->textCursor().selectedText(); + return QString(); +} + +/*! + selectionStart() returns the index of the first selected character in the + label or -1 if no text is selected. + + \sa selectedText() + + \bold{Note:} The textInteractionFlags set on the label need to include + either TextSelectableByMouse or TextSelectableByKeyboard. + + \since 4.7 +*/ +int QLabel::selectionStart() const +{ + Q_D(const QLabel); + if (d->control && d->control->textCursor().hasSelection()) + return d->control->textCursor().selectionStart(); + return -1; +} + /*!\reimp */ QSize QLabel::sizeHint() const diff --git a/src/gui/widgets/qlabel.h b/src/gui/widgets/qlabel.h index d916078..54babb1 100644 --- a/src/gui/widgets/qlabel.h +++ b/src/gui/widgets/qlabel.h @@ -65,6 +65,8 @@ class Q_GUI_EXPORT QLabel : public QFrame Q_PROPERTY(int indent READ indent WRITE setIndent) Q_PROPERTY(bool openExternalLinks READ openExternalLinks WRITE setOpenExternalLinks) Q_PROPERTY(Qt::TextInteractionFlags textInteractionFlags READ textInteractionFlags WRITE setTextInteractionFlags) + Q_PROPERTY(bool hasSelectedText READ hasSelectedText) + Q_PROPERTY(QString selectedText READ selectedText) public: explicit QLabel(QWidget *parent=0, Qt::WindowFlags f=0); @@ -111,6 +113,11 @@ public: void setTextInteractionFlags(Qt::TextInteractionFlags flags); Qt::TextInteractionFlags textInteractionFlags() const; + void setSelection(int, int); + bool hasSelectedText() const; + QString selectedText() const; + int selectionStart() const; + public Q_SLOTS: void setText(const QString &); void setPixmap(const QPixmap &); diff --git a/src/gui/widgets/qmenu.h b/src/gui/widgets/qmenu.h index 5a6a5c7..28bd859 100644 --- a/src/gui/widgets/qmenu.h +++ b/src/gui/widgets/qmenu.h @@ -415,6 +415,7 @@ private: friend OSStatus qt_mac_menu_event(EventHandlerCallRef, EventRef, void *); friend bool qt_mac_activate_action(OSMenuRef, uint, QAction::ActionEvent, bool); friend void qt_mac_emit_menuSignals(QMenu *, bool); + friend void qt_mac_menu_emit_hovered(QMenu *menu, QAction *action); #endif }; diff --git a/src/gui/widgets/qmenu_mac.mm b/src/gui/widgets/qmenu_mac.mm index 7e4bbb5..658a020 100644 --- a/src/gui/widgets/qmenu_mac.mm +++ b/src/gui/widgets/qmenu_mac.mm @@ -247,7 +247,7 @@ bool qt_mac_activate_action(MenuRef menu, uint command, QAction::ActionEvent act //now walk up firing for each "caused" widget (like in the platform independent menu) QWidget *caused = 0; - if (GetMenuItemProperty(menu, 0, kMenuCreatorQt, kMenuPropertyCausedQWidget, sizeof(caused), 0, &caused) == noErr) { + if (action_e == QAction::Hover && GetMenuItemProperty(menu, 0, kMenuCreatorQt, kMenuPropertyCausedQWidget, sizeof(caused), 0, &caused) == noErr) { MenuRef caused_menu = 0; if (QMenu *qmenu2 = qobject_cast<QMenu*>(caused)) caused_menu = qmenu2->macMenu(); @@ -260,25 +260,17 @@ bool qt_mac_activate_action(MenuRef menu, uint command, QAction::ActionEvent act QWidget *widget = 0; GetMenuItemProperty(caused_menu, 0, kMenuCreatorQt, kMenuPropertyQWidget, sizeof(widget), 0, &widget); if (QMenu *qmenu = qobject_cast<QMenu*>(widget)) { - if (action_e == QAction::Trigger) { - emit qmenu->triggered(action->action); - } else if (action_e == QAction::Hover) { - action->action->showStatusText(widget); - emit qmenu->hovered(action->action); - } + action->action->showStatusText(widget); + emit qmenu->hovered(action->action); } else if (QMenuBar *qmenubar = qobject_cast<QMenuBar*>(widget)) { - if (action_e == QAction::Trigger) { - emit qmenubar->triggered(action->action); - } else if (action_e == QAction::Hover) { - action->action->showStatusText(widget); - emit qmenubar->hovered(action->action); - } + action->action->showStatusText(widget); + emit qmenubar->hovered(action->action); break; //nothing more.. } //walk up if (GetMenuItemProperty(caused_menu, 0, kMenuCreatorQt, kMenuPropertyCausedQWidget, - sizeof(caused), 0, &caused) != noErr) + sizeof(caused), 0, &caused) != noErr) break; if (QMenu *qmenu2 = qobject_cast<QMenu*>(caused)) caused_menu = qmenu2->macMenu(); @@ -649,7 +641,7 @@ static NSMenuItem *createNSMenuItem(const QString &title) NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:qt_mac_QStringToNSString(title) action:@selector(qtDispatcherToQAction:) keyEquivalent:@""]; - [item setTarget:getMenuLoader()]; + [item setTarget:nil]; return item; } #endif @@ -749,32 +741,6 @@ bool qt_mac_menubar_is_open() return qt_mac_menus_open_count > 0; } -void qt_mac_clear_menubar() -{ - if (QApplication::testAttribute(Qt::AA_MacPluginApplication)) - return; - -#ifndef QT_MAC_USE_COCOA - MenuRef clear_menu = 0; - if (CreateNewMenu(0, 0, &clear_menu) == noErr) { - SetRootMenu(clear_menu); - ReleaseMenu(clear_menu); - } else { - qWarning("QMenu: Internal error at %s:%d", __FILE__, __LINE__); - } - ClearMenuBar(); - qt_mac_command_set_enabled(0, kHICommandPreferences, false); - InvalMenuBar(); -#else - QMacCocoaAutoReleasePool pool; - QT_MANGLE_NAMESPACE(QCocoaMenuLoader) *loader = getMenuLoader(); - NSMenu *menu = [loader menu]; - [loader ensureAppMenuInMenu:menu]; - [NSApp setMainMenu:menu]; -#endif -} - - QMacMenuAction::~QMacMenuAction() { #ifdef QT_MAC_USE_COCOA @@ -1130,7 +1096,7 @@ QMenuPrivate::QMacMenuPrivate::addAction(QMacMenuAction *action, QMacMenuAction action->menu = merge; [cmd retain]; [cmd setAction:@selector(qtDispatcherToQAction:)]; - [cmd setTarget:getMenuLoader()]; + [cmd setTarget:nil]; [action->menuItem release]; action->menuItem = cmd; QMenuMergeList *list = QMenuPrivate::mergeMenuItemsHash.value(merge); @@ -1936,43 +1902,53 @@ static bool qt_mac_is_ancestor(QWidget* possibleAncestor, QWidget *child) Returns true if the entries of menuBar should be disabled, based on the modality type of modalWidget. */ -static bool qt_mac_should_disable_menu(QMenuBar *menuBar, QWidget *modalWidget) +static bool qt_mac_should_disable_menu(QMenuBar *menuBar) { - if (modalWidget == 0 || menuBar == 0) + QWidget *modalWidget = qApp->activeModalWidget(); + if (!modalWidget) + return false; + + if (menuBar && menuBar == menubars()->value(modalWidget)) + // The menu bar is owned by the modal widget. + // In that case we should enable it: return false; - // If there is an application modal window on - // screen, the entries of the menubar should be disabled: + // When there is an application modal window on screen, the entries of + // the menubar should be disabled. The exception in Qt is that if the + // modal window is the only window on screen, then we enable the menu bar. QWidget *w = modalWidget; + QWidgetList topLevelWidgets = QApplication::topLevelWidgets(); while (w) { - if (w->isVisible() && w->windowModality() == Qt::ApplicationModal) - return true; + if (w->isVisible() && w->windowModality() == Qt::ApplicationModal) { + for (int i=0; i<topLevelWidgets.size(); ++i) { + QWidget *top = topLevelWidgets.at(i); + if (w != top && [qt_mac_window_for(top) isVisible]) { + // INVARIANT: we found another visible window + // on screen other than our modalWidget. We therefore + // disable the menu bar to follow normal modality logic: + return true; + } + } + // INVARIANT: We have only one window on screen that happends + // to be application modal. We choose to enable the menu bar + // in that case to e.g. enable the quit menu item. + return false; + } w = w->parentWidget(); } // INVARIANT: modalWidget is window modal. Disable menu entries - // if the menu bar belongs to an ancestor of modalWidget: - return qt_mac_is_ancestor(menuBar->parentWidget(), modalWidget); + // if the menu bar belongs to an ancestor of modalWidget. If menuBar + // is nil, we understand it as the default menu bar set by the nib: + return menuBar ? qt_mac_is_ancestor(menuBar->parentWidget(), modalWidget) : false; } -/*! - \internal - - This function will update the current menu bar and set it as the - active menu bar in the Menu Manager. - - \warning This function is not portable. - - \sa QMenu::macMenu(), QMenuBar::macMenu() -*/ -bool QMenuBar::macUpdateMenuBar() +static QWidget *findWindowThatShouldDisplayMenubar() { - cancelAllMenuTracking(); - QMenuBar *mb = 0; - //find a menu bar QWidget *w = qApp->activeWindow(); - if (!w) { + // We have no active window on screen. Try to + // find a window from the list of top levels: QWidgetList tlws = QApplication::topLevelWidgets(); for(int i = 0; i < tlws.size(); ++i) { QWidget *tlw = tlws.at(i); @@ -1983,6 +1959,12 @@ bool QMenuBar::macUpdateMenuBar() } } } + return w; +} + +static QMenuBar *findMenubarForWindow(QWidget *w) +{ + QMenuBar *mb = 0; if (w) { mb = menubars()->value(w); #ifndef QT_NO_MAINWINDOW @@ -1996,11 +1978,65 @@ bool QMenuBar::macUpdateMenuBar() while(w && !mb) mb = menubars()->value((w = w->parentWidget())); } - if (!mb) + + if (!mb) { + // We could not find a menu bar for the window. Lets + // check if we have a global (parentless) menu bar instead: mb = fallback; - //now set it + } + + return mb; +} + +void qt_mac_clear_menubar() +{ + if (QApplication::testAttribute(Qt::AA_MacPluginApplication)) + return; + +#ifndef QT_MAC_USE_COCOA + MenuRef clear_menu = 0; + if (CreateNewMenu(0, 0, &clear_menu) == noErr) { + SetRootMenu(clear_menu); + ReleaseMenu(clear_menu); + } else { + qWarning("QMenu: Internal error at %s:%d", __FILE__, __LINE__); + } + ClearMenuBar(); + qt_mac_command_set_enabled(0, kHICommandPreferences, false); + InvalMenuBar(); +#else + QMacCocoaAutoReleasePool pool; + QT_MANGLE_NAMESPACE(QCocoaMenuLoader) *loader = getMenuLoader(); + NSMenu *menu = [loader menu]; + [loader ensureAppMenuInMenu:menu]; + [NSApp setMainMenu:menu]; + const bool modal = qt_mac_should_disable_menu(0); + if (qt_mac_current_menubar.qmenubar || modal != qt_mac_current_menubar.modal) + qt_mac_set_modal_state(menu, modal); + qt_mac_current_menubar.qmenubar = 0; + qt_mac_current_menubar.modal = modal; +#endif +} + +/*! + \internal + + This function will update the current menu bar and set it as the + active menu bar in the Menu Manager. + + \warning This function is not portable. + + \sa QMenu::macMenu(), QMenuBar::macMenu() +*/ +bool QMenuBar::macUpdateMenuBar() +{ bool ret = false; + cancelAllMenuTracking(); + QWidget *w = findWindowThatShouldDisplayMenubar(); + QMenuBar *mb = findMenubarForWindow(w); + if (mb && mb->isNativeMenuBar()) { + bool modal = QApplicationPrivate::modalState(); #ifdef QT_MAC_USE_COCOA QMacCocoaAutoReleasePool pool; #endif @@ -2030,16 +2066,18 @@ bool QMenuBar::macUpdateMenuBar() } } #endif - QWidget *modalWidget = qApp->activeModalWidget(); - if (mb != menubars()->value(modalWidget)) { - qt_mac_set_modal_state(menu, qt_mac_should_disable_menu(mb, modalWidget)); - } + // Check if menu is modally shaddowed and should be disabled: + modal = qt_mac_should_disable_menu(mb); + if (mb != qt_mac_current_menubar.qmenubar || modal != qt_mac_current_menubar.modal) + qt_mac_set_modal_state(menu, modal); } qt_mac_current_menubar.qmenubar = mb; - qt_mac_current_menubar.modal = QApplicationPrivate::modalState(); + qt_mac_current_menubar.modal = modal; ret = true; } else if (qt_mac_current_menubar.qmenubar && qt_mac_current_menubar.qmenubar->isNativeMenuBar()) { - const bool modal = QApplicationPrivate::modalState(); + // INVARIANT: The currently active menu bar (if any) is not native. But we do have a + // native menu bar from before. So we need to decide whether or not is should be enabled: + const bool modal = qt_mac_should_disable_menu(qt_mac_current_menubar.qmenubar); if (modal != qt_mac_current_menubar.modal) { ret = true; if (OSMenuRef menu = qt_mac_current_menubar.qmenubar->macMenu()) { @@ -2051,14 +2089,12 @@ bool QMenuBar::macUpdateMenuBar() [NSApp setMainMenu:menu]; syncMenuBarItemsVisiblity(qt_mac_current_menubar.qmenubar->d_func()->mac_menubar); #endif - QWidget *modalWidget = qApp->activeModalWidget(); - if (qt_mac_current_menubar.qmenubar != menubars()->value(modalWidget)) { - qt_mac_set_modal_state(menu, qt_mac_should_disable_menu(mb, modalWidget)); - } + qt_mac_set_modal_state(menu, modal); } qt_mac_current_menubar.modal = modal; } } + if(!ret) qt_mac_clear_menubar(); return ret; diff --git a/src/gui/widgets/qplaintextedit.cpp b/src/gui/widgets/qplaintextedit.cpp index ab598d9..02ffe13 100644 --- a/src/gui/widgets/qplaintextedit.cpp +++ b/src/gui/widgets/qplaintextedit.cpp @@ -911,6 +911,7 @@ void QPlainTextEditPrivate::pageUpDown(QTextCursor::MoveOperation op, QTextCurso setTopBlock(block.blockNumber(), line); if (moveCursor) { + cursor.setVisualNavigation(true); // move using movePosition to keep the cursor's x lastY += verticalOffset(); bool moved = false; diff --git a/src/gui/widgets/qtabbar.cpp b/src/gui/widgets/qtabbar.cpp index 22e8255..7559311 100644 --- a/src/gui/widgets/qtabbar.cpp +++ b/src/gui/widgets/qtabbar.cpp @@ -1947,7 +1947,8 @@ void QTabBar::changeEvent(QEvent *event) { Q_D(QTabBar); if (event->type() == QEvent::StyleChange) { - d->elideMode = Qt::TextElideMode(style()->styleHint(QStyle::SH_TabBar_ElideMode, 0, this)); + if (!d->elideModeSetByUser) + d->elideMode = Qt::TextElideMode(style()->styleHint(QStyle::SH_TabBar_ElideMode, 0, this)); if (!d->useScrollButtonsSetByUser) d->useScrollButtons = !style()->styleHint(QStyle::SH_TabBar_PreferNoArrows, 0, this); d->refresh(); @@ -1980,6 +1981,7 @@ void QTabBar::setElideMode(Qt::TextElideMode mode) { Q_D(QTabBar); d->elideMode = mode; + d->elideModeSetByUser = true; d->refresh(); } diff --git a/src/gui/widgets/qtabbar_p.h b/src/gui/widgets/qtabbar_p.h index 7588035..83636e6 100644 --- a/src/gui/widgets/qtabbar_p.h +++ b/src/gui/widgets/qtabbar_p.h @@ -75,7 +75,7 @@ class QTabBarPrivate : public QWidgetPrivate public: QTabBarPrivate() :currentIndex(-1), pressedIndex(-1), shape(QTabBar::RoundedNorth), layoutDirty(false), - drawBase(true), scrollOffset(0), useScrollButtonsSetByUser(false) , expanding(true), closeButtonOnTabs(false), + drawBase(true), scrollOffset(0), elideModeSetByUser(false), useScrollButtonsSetByUser(false), expanding(true), closeButtonOnTabs(false), selectionBehaviorOnRemove(QTabBar::SelectRightTab), paintWithOffsets(true), movable(false), dragInProgress(false), documentMode(false), movingTab(0) #ifdef Q_WS_MAC @@ -186,6 +186,7 @@ public: void makeVisible(int index); QSize iconSize; Qt::TextElideMode elideMode; + bool elideModeSetByUser; bool useScrollButtons; bool useScrollButtonsSetByUser; diff --git a/src/gui/widgets/qtoolbar.cpp b/src/gui/widgets/qtoolbar.cpp index 53050ac..7782448 100644 --- a/src/gui/widgets/qtoolbar.cpp +++ b/src/gui/widgets/qtoolbar.cpp @@ -534,6 +534,14 @@ void QToolBarPrivate::plug(const QRect &r) /*! + \fn void QToolBar::visibilityChanged(bool visible) + \since 4.7 + + This signal is emitted when the toolbar becomes \a visible (or + invisible). This happens when the widget is hidden or shown. +*/ + +/*! Constructs a QToolBar with the given \a parent. */ QToolBar::QToolBar(QWidget *parent) @@ -1123,6 +1131,7 @@ bool QToolBar::event(QEvent *event) // fallthrough intended case QEvent::Show: d->toggleViewAction->setChecked(event->type() == QEvent::Show); + emit visibilityChanged(event->type() == QEvent::Show); #if defined(Q_WS_MAC) if (toolbarInUnifiedToolBar(this)) { // I can static_cast because I did the qobject_cast in the if above, therefore diff --git a/src/gui/widgets/qtoolbar.h b/src/gui/widgets/qtoolbar.h index 90f20dd..b733477 100644 --- a/src/gui/widgets/qtoolbar.h +++ b/src/gui/widgets/qtoolbar.h @@ -143,6 +143,7 @@ Q_SIGNALS: void iconSizeChanged(const QSize &iconSize); void toolButtonStyleChanged(Qt::ToolButtonStyle toolButtonStyle); void topLevelChanged(bool topLevel); + void visibilityChanged(bool visible); protected: void actionEvent(QActionEvent *event); diff --git a/src/gui/widgets/qvalidator.cpp b/src/gui/widgets/qvalidator.cpp index a5276d3..0b5cc5a 100644 --- a/src/gui/widgets/qvalidator.cpp +++ b/src/gui/widgets/qvalidator.cpp @@ -400,8 +400,10 @@ QValidator::State QIntValidator::validate(QString & input, int&) const qlonglong entered = QLocalePrivate::bytearrayToLongLong(buff.constData(), 10, &ok, &overflow); if (overflow || !ok) return Invalid; - if (entered >= b && entered <= t) - return Acceptable; + if (entered >= b && entered <= t) { + locale().toInt(input, &ok); + return ok ? Acceptable : Intermediate; + } if (entered >= 0) { // the -entered < b condition is necessary to allow people to type @@ -412,6 +414,20 @@ QValidator::State QIntValidator::validate(QString & input, int&) const } } +/*! \reimp */ +void QIntValidator::fixup(QString &input) const +{ + QByteArray buff; + if (!locale().d()->validateChars(input, QLocalePrivate::IntegerMode, &buff)) { + QLocale cl(QLocale::C); + if (!cl.d()->validateChars(input, QLocalePrivate::IntegerMode, &buff)) + return; + } + bool ok, overflow; + qlonglong entered = QLocalePrivate::bytearrayToLongLong(buff.constData(), 10, &ok, &overflow); + if (ok && !overflow) + input = locale().toString(entered); +} /*! Sets the range of the validator to only accept integers between \a diff --git a/src/gui/widgets/qvalidator.h b/src/gui/widgets/qvalidator.h index 30afbd6..e996a01 100644 --- a/src/gui/widgets/qvalidator.h +++ b/src/gui/widgets/qvalidator.h @@ -105,6 +105,7 @@ public: ~QIntValidator(); QValidator::State validate(QString &, int &) const; + void fixup(QString &input) const; void setBottom(int); void setTop(int); |