diff options
author | David Boddie <dboddie@trolltech.com> | 2010-03-30 14:56:41 (GMT) |
---|---|---|
committer | David Boddie <dboddie@trolltech.com> | 2010-03-30 14:56:41 (GMT) |
commit | 87f66d52e362de003a9f2cdaafbfbe3ba4e5fbc3 (patch) | |
tree | f8b8c24056d54e19937dea1b0301af558597726a /src/gui/dialogs | |
parent | 09ce407aaa4a00013a606bf0011faf6cbc654c72 (diff) | |
parent | 00f7426f3906361fb5addb36e428648eee5e2983 (diff) | |
download | Qt-87f66d52e362de003a9f2cdaafbfbe3ba4e5fbc3.zip Qt-87f66d52e362de003a9f2cdaafbfbe3ba4e5fbc3.tar.gz Qt-87f66d52e362de003a9f2cdaafbfbe3ba4e5fbc3.tar.bz2 |
Merge branch '4.7' of git@scm.dev.nokia.troll.no:qt/oslo-staging-2 into 4.7
Conflicts:
doc/src/modules.qdoc
mkspecs/common/symbian/symbian.conf
src/gui/graphicsview/qgraphicswidget.h
src/s60installs/bwins/QtGuiu.def
src/s60installs/eabi/QtGuiu.def
Diffstat (limited to 'src/gui/dialogs')
26 files changed, 1000 insertions, 632 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/qabstractprintdialog.cpp b/src/gui/dialogs/qabstractprintdialog.cpp index 4523433..25d9ebb 100644 --- a/src/gui/dialogs/qabstractprintdialog.cpp +++ b/src/gui/dialogs/qabstractprintdialog.cpp @@ -76,6 +76,7 @@ class QPrintDialogPrivate : public QAbstractPrintDialogPrivate \value AllPages All pages should be printed. \value Selection Only the selection should be printed. \value PageRange The specified page range should be printed. + \value CurrentPage Only the currently visible page should be printed. \sa QPrinter::PrintRange */ @@ -89,7 +90,9 @@ class QPrintDialogPrivate : public QAbstractPrintDialogPrivate \value PrintToFile The print to file option is enabled. \value PrintSelection The print selection option is enabled. \value PrintPageRange The page range selection option is enabled. - \value PrintCollateCopies + \value PrintShowPageSize Show the page size + margins page only if this is enabled. + \value PrintCollateCopies The collate copies option is enabled + \value PrintCurrentPage The print current page option is enabled This value is obsolete and does nothing since Qt 4.5: @@ -97,8 +100,6 @@ class QPrintDialogPrivate : public QAbstractPrintDialogPrivate would create a sheet by default the dialog was given a parent. This is no longer supported in Qt 4.5. If you want to use sheets, use QPrintDialog::open() instead. - - \value PrintShowPageSize Show the page size + margins page only if this is enabled. */ /*! diff --git a/src/gui/dialogs/qabstractprintdialog.h b/src/gui/dialogs/qabstractprintdialog.h index 4d867f6..82e3df8 100644 --- a/src/gui/dialogs/qabstractprintdialog.h +++ b/src/gui/dialogs/qabstractprintdialog.h @@ -65,7 +65,8 @@ public: enum PrintRange { AllPages, Selection, - PageRange + PageRange, + CurrentPage }; enum PrintDialogOption { @@ -75,7 +76,8 @@ public: PrintPageRange = 0x0004, PrintShowPageSize = 0x0008, PrintCollateCopies = 0x0010, - DontUseSheet = 0x0020 + DontUseSheet = 0x0020, + PrintCurrentPage = 0x0040 }; Q_DECLARE_FLAGS(PrintDialogOptions, PrintDialogOption) diff --git a/src/gui/dialogs/qdialog.cpp b/src/gui/dialogs/qdialog.cpp index 25ba016..3f8cc72 100644 --- a/src/gui/dialogs/qdialog.cpp +++ b/src/gui/dialogs/qdialog.cpp @@ -641,13 +641,14 @@ void QDialog::contextMenuEvent(QContextMenuEvent *e) while (w && w->whatsThis().size() == 0 && !w->testAttribute(Qt::WA_CustomWhatsThis)) w = w->isWindow() ? 0 : w->parentWidget(); if (w) { - QMenu p(this); - QAction *wt = p.addAction(tr("What's This?")); - if (p.exec(e->globalPos()) == wt) { + QWeakPointer<QMenu> p = new QMenu(this); + QAction *wt = p.data()->addAction(tr("What's This?")); + if (p.data()->exec(e->globalPos()) == wt) { QHelpEvent e(QEvent::WhatsThis, w->rect().center(), w->mapToGlobal(w->rect().center())); QApplication::sendEvent(w, &e); } + delete p.data(); } #endif } diff --git a/src/gui/dialogs/qerrormessage.cpp b/src/gui/dialogs/qerrormessage.cpp index 0bca811..7be7481 100644 --- a/src/gui/dialogs/qerrormessage.cpp +++ b/src/gui/dialogs/qerrormessage.cpp @@ -70,10 +70,10 @@ extern bool qt_wince_is_high_dpi(); //defined in qguifunctions_wince.cpp #if defined(QT_SOFTKEYS_ENABLED) #include <qaction.h> +#endif #ifdef Q_WS_S60 #include "private/qt_s60_p.h" #endif -#endif QT_BEGIN_NAMESPACE diff --git a/src/gui/dialogs/qfiledialog.cpp b/src/gui/dialogs/qfiledialog.cpp index 089e04a..ef2b223 100644 --- a/src/gui/dialogs/qfiledialog.cpp +++ b/src/gui/dialogs/qfiledialog.cpp @@ -228,7 +228,8 @@ Q_GUI_EXPORT _qt_filedialog_save_filename_hook qt_filedialog_save_filename_hook \value ReadOnly Indicates that the model is readonly. - \value HideNameFilterDetails Indicates if the is hidden or not. + \value HideNameFilterDetails Indicates if the file name filter details are + hidden or not. \value DontUseSheet In previous versions of Qt, the static functions would create a sheet by default if the static function diff --git a/src/gui/dialogs/qfiledialog_mac.mm b/src/gui/dialogs/qfiledialog_mac.mm index 67daced..14a5f15 100644 --- a/src/gui/dialogs/qfiledialog_mac.mm +++ b/src/gui/dialogs/qfiledialog_mac.mm @@ -295,10 +295,14 @@ QT_USE_NAMESPACE if (!mQDirFilterEntryList->contains(info.fileName())) return NO; - // Always accept directories regardless of their names: + // Always accept directories regardless of their names (unless it is a bundle): BOOL isDir; - if ([[NSFileManager defaultManager] fileExistsAtPath:filename isDirectory:&isDir] && isDir) - return YES; + if ([[NSFileManager defaultManager] fileExistsAtPath:filename isDirectory:&isDir] && isDir) { + if ([mSavePanel treatsFilePackagesAsDirectories] == NO) { + if ([[NSWorkspace sharedWorkspace] isFilePackageAtPath:filename] == NO) + return YES; + } + } // No filter means accept everything if (mSelectedNameFilter->isEmpty()) @@ -725,6 +729,7 @@ Boolean QFileDialogPrivate::qt_mac_filedialog_filter_proc(AEDesc *theItem, void NavFileOrFolderInfo *theInfo = static_cast<NavFileOrFolderInfo *>(info); QString file; + QString path; const QtMacFilterName &fn = fileDialogPrivate->filterInfo.filters.at(fileDialogPrivate->filterInfo.currentSelection); if (theItem->descriptorType == typeFSRef) { @@ -732,10 +737,12 @@ Boolean QFileDialogPrivate::qt_mac_filedialog_filter_proc(AEDesc *theItem, void AEGetDescData(theItem, &ref, sizeof(ref)); UInt8 str_buffer[1024]; FSRefMakePath(&ref, str_buffer, 1024); - file = QString::fromUtf8(reinterpret_cast<const char *>(str_buffer)); - int slsh = file.lastIndexOf(QLatin1Char('/')); + path = QString::fromUtf8(reinterpret_cast<const char *>(str_buffer)); + int slsh = path.lastIndexOf(QLatin1Char('/')); if (slsh != -1) - file = file.right(file.length() - slsh - 1); + file = path.right(path.length() - slsh - 1); + else + file = path; } QStringList reg = fn.regexp.split(QLatin1String(";")); for (QStringList::const_iterator it = reg.constBegin(); it != reg.constEnd(); ++it) { @@ -747,7 +754,13 @@ Boolean QFileDialogPrivate::qt_mac_filedialog_filter_proc(AEDesc *theItem, void if (rg.exactMatch(file)) return true; } - return (theInfo->isFolder && !file.endsWith(QLatin1String(".app"))); + + if (theInfo->isFolder) { + if ([[NSWorkspace sharedWorkspace] isFilePackageAtPath:qt_mac_QStringToNSString(path)]) + return false; + return true; + } + return false; } void QFileDialogPrivate::qt_mac_filedialog_event_proc(const NavEventCallbackMessage msg, diff --git a/src/gui/dialogs/qfiledialog_win.cpp b/src/gui/dialogs/qfiledialog_win.cpp index 5a7ace9..afeed8e 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, @@ -612,6 +583,63 @@ QStringList qt_win_CID_get_open_file_names(const QFileDialogArgs &args, return result; } +QString qt_win_CID_get_existing_directory(const QFileDialogArgs &args) +{ + QString result; + QDialog modal_widget; + modal_widget.setAttribute(Qt::WA_NoChildEventsForParent, true); + modal_widget.setParent(args.parent, Qt::Window); + QApplicationPrivate::enterModal(&modal_widget); + + IFileOpenDialog *pfd = 0; + 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, + args.directory, args.caption, + QStringList(), QFileDialog::ExistingFiles, + args.options); + + // Set the FOS_PICKFOLDERS flag + DWORD newOptions; + hr = pfd->GetOptions(&newOptions); + newOptions |= FOS_PICKFOLDERS; + if (SUCCEEDED(hr) && SUCCEEDED((hr = pfd->SetOptions(newOptions)))) { + QWidget *parentWindow = args.parent; + if (parentWindow) + parentWindow = parentWindow->window(); + else + parentWindow = QApplication::activeWindow(); + + // Show the file dialog. + hr = pfd->Show(parentWindow ? parentWindow->winId() : 0); + if (SUCCEEDED(hr)) { + // Retrieve the result + IShellItem *psi = 0; + hr = pfd->GetResult(&psi); + if (SUCCEEDED(hr)) { + // Retrieve the file name from shell item. + wchar_t *pszPath; + hr = psi->GetDisplayName(SIGDN_FILESYSPATH, &pszPath); + if (SUCCEEDED(hr)) { + result = QString::fromWCharArray(pszPath); + CoTaskMemFree(pszPath); + } + psi->Release(); // Free the current item. + } + } + } + } + QApplicationPrivate::leaveModal(&modal_widget); + + qt_win_eatMouseMove(); + + if (pfd) + pfd->Release(); + return result; +} + #endif QStringList qt_win_get_open_file_names(const QFileDialogArgs &args, @@ -643,7 +671,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 +744,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,13 +756,13 @@ 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) { +#ifndef Q_WS_WINCE + if (QSysInfo::WindowsVersion >= QSysInfo::WV_VISTA && QSysInfo::WindowsVersion < QSysInfo::WV_NT_based) + return qt_win_CID_get_existing_directory(args); +#endif + QString currentDir = QDir::currentPath(); QString result; QWidget *parent = args.parent; @@ -757,11 +785,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 +799,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..7079925 --- /dev/null +++ b/src/gui/dialogs/qfiledialog_win_p.h @@ -0,0 +1,243 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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 (QT_WIN_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..3b279ae 100644 --- a/src/gui/dialogs/qfileinfogatherer.cpp +++ b/src/gui/dialogs/qfileinfogatherer.cpp @@ -216,41 +216,10 @@ void QFileInfoGatherer::run() } } -/* - QFileInfo::permissions is different depending upon your platform. - - "normalize this" so they can mean the same to us. -*/ -QFile::Permissions QFileInfoGatherer::translatePermissions(const QFileInfo &fileInfo) const { - QFile::Permissions permissions = fileInfo.permissions(); -#ifdef Q_OS_WIN - return permissions; -#else - QFile::Permissions p = permissions; - p &= ~(QFile::ReadUser|QFile::WriteUser|QFile::ExeUser); - if ( permissions & QFile::ReadOther - || (fileInfo.ownerId() == userId && permissions & QFile::ReadOwner) - || (fileInfo.groupId() == groupId && permissions & QFile::ReadGroup)) - p |= QFile::ReadUser; - - if ( permissions & QFile::WriteOther - || (fileInfo.ownerId() == userId && permissions & QFile::WriteOwner) - || (fileInfo.groupId() == groupId && permissions & QFile::WriteGroup)) - p |= QFile::WriteUser; - - if ( permissions & QFile::ExeOther - || (fileInfo.ownerId() == userId && permissions & QFile::ExeOwner) - || (fileInfo.groupId() == groupId && permissions & QFile::ExeGroup)) - p |= QFile::ExeUser; - return p; -#endif -} - QExtendedInformation QFileInfoGatherer::getInfo(const QFileInfo &fileInfo) const { QExtendedInformation info(fileInfo); info.icon = m_iconProvider->icon(fileInfo); - info.setPermissions(translatePermissions(fileInfo)); info.displayType = m_iconProvider->type(fileInfo); #ifndef QT_NO_FILESYSTEMWATCHER // ### Not ready to listen all modifications @@ -328,7 +297,8 @@ void QFileInfoGatherer::getFileInfos(const QString &path, const QStringList &fil return; } - QTime base = QTime::currentTime(); + QElapsedTimer base; + base.start(); QFileInfo fileInfo; bool firstTime = true; QList<QPair<QString, QFileInfo> > updatedFiles; @@ -354,11 +324,13 @@ 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) { +void QFileInfoGatherer::fetch(const QFileInfo &fileInfo, QElapsedTimer &base, bool &firstTime, QList<QPair<QString, QFileInfo> > &updatedFiles, const QString &path) { updatedFiles.append(QPair<QString, QFileInfo>(fileInfo.fileName(), fileInfo)); - QTime current = QTime::currentTime(); + QElapsedTimer current; + current.start(); if ((firstTime && updatedFiles.count() > 100) || base.msecsTo(current) > 1000) { emit updates(path, updatedFiles); updatedFiles.clear(); diff --git a/src/gui/dialogs/qfileinfogatherer_p.h b/src/gui/dialogs/qfileinfogatherer_p.h index 0242178..5abcd94 100644 --- a/src/gui/dialogs/qfileinfogatherer_p.h +++ b/src/gui/dialogs/qfileinfogatherer_p.h @@ -60,9 +60,10 @@ #include <qfileiconprovider.h> #include <qfsfileengine.h> #include <qpair.h> -#include <qdatetime.h> #include <qstack.h> +#include <qdatetime.h> #include <qdir.h> +#include <qelapsedtimer.h> QT_BEGIN_NAMESPACE @@ -88,11 +89,7 @@ public: return fe.caseSensitive(); } QFile::Permissions permissions() const { - return mPermissions; - } - - void setPermissions (QFile::Permissions permissions) { - mPermissions = permissions; + return mFileInfo.permissions(); } Type type() const { @@ -140,7 +137,6 @@ public: private : QFileInfo mFileInfo; - QFile::Permissions mPermissions; }; class QFileIconProvider; @@ -155,6 +151,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); @@ -178,9 +175,8 @@ protected: void getFileInfos(const QString &path, const QStringList &files); private: - void fetch(const QFileInfo &info, QTime &base, bool &firstTime, QList<QPair<QString, QFileInfo> > &updatedFiles, const QString &path); + void fetch(const QFileInfo &info, QElapsedTimer &base, bool &firstTime, QList<QPair<QString, QFileInfo> > &updatedFiles, const QString &path); QString translateDriveName(const QFileInfo &drive) const; - QFile::Permissions translatePermissions(const QFileInfo &fileInfo) const; QMutex mutex; QWaitCondition condition; diff --git a/src/gui/dialogs/qfilesystemmodel.cpp b/src/gui/dialogs/qfilesystemmodel.cpp index 3757ad7..aba69b7 100644 --- a/src/gui/dialogs/qfilesystemmodel.cpp +++ b/src/gui/dialogs/qfilesystemmodel.cpp @@ -51,6 +51,9 @@ #ifdef Q_OS_WIN #include <qt_windows.h> #endif +#ifdef Q_OS_WIN32 +#include <QtCore/QVarLengthArray> +#endif QT_BEGIN_NAMESPACE @@ -150,6 +153,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 @@ -270,53 +281,38 @@ QFileSystemModelPrivate::QFileSystemNode *QFileSystemModelPrivate::node(const QM return indexNode; } -#ifdef Q_OS_WIN +#ifdef Q_OS_WIN32 static QString qt_GetLongPathName(const QString &strShortPath) { - QString longPath; - int i = 0; - if (strShortPath == QLatin1String(".") - || (strShortPath.startsWith(QLatin1String("//"))) - || (strShortPath.startsWith(QLatin1String("\\\\")))) // unc + if (strShortPath.isEmpty() + || strShortPath == QLatin1String(".") || strShortPath == QLatin1String("..")) return strShortPath; - QString::const_iterator it = strShortPath.constBegin(); - QString::const_iterator constEnd = strShortPath.constEnd(); - do { - bool isSep = (*it == QLatin1Char('\\') || *it == QLatin1Char('/')); - if (isSep || it == constEnd) { - QString section = (it == constEnd ? strShortPath : strShortPath.left(i)); - // FindFirstFile does not handle volumes ("C:"), so we have to catch that ourselves. - if (section.endsWith(QLatin1Char(':'))) { - longPath.append(section.toUpper()); - } else { - HANDLE h; -#ifndef Q_OS_WINCE - //We add the extend length prefix to handle long path - QString longSection = QLatin1String("\\\\?\\")+QDir::toNativeSeparators(section); -#else - QString longSection = QDir::toNativeSeparators(section); -#endif - WIN32_FIND_DATA findData; - h = ::FindFirstFile((wchar_t*)longSection.utf16(), &findData); - if (h != INVALID_HANDLE_VALUE) { - longPath.append(QString::fromWCharArray(findData.cFileName)); - ::FindClose(h); - } else { - longPath.append(section); - break; - } - } - if (it != constEnd) - longPath.append(*it); - else - break; - } - ++it; - if (isSep && it == constEnd) // break out if the last character is a separator - break; - ++i; - } while (true); - return longPath; + if (strShortPath.length() == 2 && strShortPath.endsWith(QLatin1Char(':'))) + return strShortPath.toUpper(); + const QString absPath = QDir(strShortPath).absolutePath(); + if (absPath.startsWith(QLatin1String("//")) + || absPath.startsWith(QLatin1String("\\\\"))) // unc + return QDir::fromNativeSeparators(absPath); + if (absPath.startsWith(QLatin1Char('/'))) + return QString(); + const QString inputString = QLatin1String("\\\\?\\") + QDir::toNativeSeparators(absPath); + QVarLengthArray<TCHAR, MAX_PATH> buffer(MAX_PATH); + DWORD result = ::GetLongPathName((wchar_t*)inputString.utf16(), + buffer.data(), + buffer.size()); + if (result > DWORD(buffer.size())) { + buffer.resize(result); + result = ::GetLongPathName((wchar_t*)inputString.utf16(), + buffer.data(), + buffer.size()); + } + if (result > 4) { + QString longPath = QString::fromWCharArray(buffer.data() + 4); // ignoring prefix + longPath[0] = longPath.at(0).toUpper(); // capital drive letters + return QDir::fromNativeSeparators(longPath); + } else { + return QDir::fromNativeSeparators(strShortPath); + } } #endif @@ -334,7 +330,7 @@ QFileSystemModelPrivate::QFileSystemNode *QFileSystemModelPrivate::node(const QS // Construct the nodes up to the new root path if they need to be built QString absolutePath; -#ifdef Q_OS_WIN +#ifdef Q_OS_WIN32 QString longPath = qt_GetLongPathName(path); #else QString longPath = path; @@ -673,7 +669,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 +785,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()) @@ -1337,7 +1345,11 @@ QModelIndex QFileSystemModel::setRootPath(const QString &newPath) { Q_D(QFileSystemModel); #ifdef Q_OS_WIN - QString longNewPath = QDir::fromNativeSeparators(qt_GetLongPathName(newPath)); +#ifdef Q_OS_WIN32 + QString longNewPath = qt_GetLongPathName(newPath); +#else + QString longNewPath = QDir::fromNativeSeparators(newPath); +#endif #else QString longNewPath = newPath; #endif @@ -1650,6 +1662,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; } @@ -1879,7 +1903,16 @@ 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); + + QHash<int, QByteArray> roles = q->roleNames(); + roles.insertMulti(QFileSystemModel::FileIconRole, "fileIcon"); // == Qt::decoration + roles.insert(QFileSystemModel::FilePathRole, "filePath"); + roles.insert(QFileSystemModel::FileNameRole, "fileName"); + roles.insert(QFileSystemModel::FilePermissions, "filePermissions"); + q->setRoleNames(roles); } /*! 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/qfontdialog.cpp b/src/gui/dialogs/qfontdialog.cpp index a4bf15d..b159fa7 100644 --- a/src/gui/dialogs/qfontdialog.cpp +++ b/src/gui/dialogs/qfontdialog.cpp @@ -174,6 +174,11 @@ void QFontDialogPrivate::init() { Q_Q(QFontDialog); +#ifdef Q_WS_MAC + nativeDialogInUse = false; + delegate = 0; +#endif + q->setSizeGripEnabled(true); q->setWindowTitle(QFontDialog::tr("Select Font")); @@ -329,10 +334,6 @@ void QFontDialogPrivate::init() familyList->setFocus(); retranslateStrings(); - -#ifdef Q_WS_MAC - delegate = 0; -#endif } /*! @@ -345,8 +346,7 @@ QFontDialog::~QFontDialog() #ifdef Q_WS_MAC Q_D(QFontDialog); if (d->delegate) { - QFontDialogPrivate::closeCocoaFontPanel(d->delegate); - QFontDialogPrivate::sharedFontPanelAvailable = true; + d->closeCocoaFontPanel(); return; } #endif @@ -428,14 +428,6 @@ QFont QFontDialog::getFont(bool *ok, QWidget *parent) QFont QFontDialogPrivate::getFont(bool *ok, const QFont &initial, QWidget *parent, const QString &title, QFontDialog::FontDialogOptions options) { -#ifdef Q_WS_MAC - if (!(options & QFontDialog::DontUseNativeDialog) - && QFontDialogPrivate::sharedFontPanelAvailable) { - return QFontDialogPrivate::execCocoaFontPanel(ok, initial, parent, - title.isEmpty() ? QFontDialog::tr("Select Font") : title, options); - } -#endif - QFontDialog dlg(parent); dlg.setOptions(options); dlg.setCurrentFont(initial); @@ -988,13 +980,10 @@ void QFontDialog::open(QObject *receiver, const char *member) */ void QFontDialog::setVisible(bool visible) { - Q_D(QFontDialog); - if (visible) { - if (testAttribute(Qt::WA_WState_ExplicitShowHide) && !testAttribute(Qt::WA_WState_Hidden)) - return; - } else if (testAttribute(Qt::WA_WState_ExplicitShowHide) && testAttribute(Qt::WA_WState_Hidden)) + if (testAttribute(Qt::WA_WState_ExplicitShowHide) && testAttribute(Qt::WA_WState_Hidden) != visible) return; #ifdef Q_WS_MAC + Q_D(QFontDialog); if (d->canBeNativeDialog()){ if (d->setVisible_sys(visible)){ d->nativeDialogInUse = true; diff --git a/src/gui/dialogs/qfontdialog_mac.mm b/src/gui/dialogs/qfontdialog_mac.mm index 67d32b8..919790b 100644 --- a/src/gui/dialogs/qfontdialog_mac.mm +++ b/src/gui/dialogs/qfontdialog_mac.mm @@ -58,6 +58,14 @@ typedef float CGFloat; // Should only not be defined on 32-bit platforms #endif +QT_BEGIN_NAMESPACE + +extern void macStartInterceptNSPanelCtor(); +extern void macStopInterceptNSPanelCtor(); +extern NSButton *macCreateButton(const char *text, NSView *superview); +extern bool qt_mac_is_macsheet(const QWidget *w); // qwidget_mac.mm + +QT_END_NAMESPACE QT_USE_NAMESPACE // should a priori be kept in sync with qcolordialog_mac.mm @@ -95,7 +103,8 @@ const int StyleMask = NSTitledWindowMask | NSClosableWindowMask | NSResizableWin BOOL mPanelHackedWithButtons; CGFloat mDialogExtraWidth; CGFloat mDialogExtraHeight; - NSModalSession mModalSession; + int mReturnCode; + BOOL mAppModal; } - (id)initWithFontPanel:(NSFontPanel *)panel stolenContentView:(NSView *)stolenContentView @@ -104,9 +113,11 @@ const int StyleMask = NSTitledWindowMask | NSClosableWindowMask | NSResizableWin priv:(QFontDialogPrivate *)priv extraWidth:(CGFloat)extraWidth extraHeight:(CGFloat)extraHeight; +- (void)showModelessPanel; +- (void)showWindowModalSheet:(QWidget *)docWidget; +- (void)runApplicationModalPanel; - (void)changeFont:(id)sender; - (void)changeAttributes:(id)sender; -- (void)setModalSession:(NSModalSession)session; - (BOOL)windowShouldClose:(id)window; - (NSSize)windowWillResize:(NSWindow *)window toSize:(NSSize)proposedFrameSize; - (void)relayout; @@ -163,7 +174,8 @@ static QFont qfontForCocoaFont(NSFont *cocoaFont, const QFont &resolveFont) mPanelHackedWithButtons = (okButton != 0); mDialogExtraWidth = extraWidth; mDialogExtraHeight = extraHeight; - mModalSession = 0; + mReturnCode = -1; + mAppModal = false; if (mPanelHackedWithButtons) { [self relayout]; @@ -174,6 +186,20 @@ static QFont qfontForCocoaFont(NSFont *cocoaFont, const QFont &resolveFont) [cancelButton setAction:@selector(onCancelClicked)]; [cancelButton setTarget:self]; } + +#ifdef QT_MAC_USE_COCOA + // Stack the native dialog in front of its parent, if any: + QFontDialog *q = mPriv->fontDialog(); + if (!qt_mac_is_macsheet(q)) { + if (QWidget *parent = q->parentWidget()) { + if (parent->isWindow()) { + [qt_mac_window_for(parent) + addChildWindow:[mStolenContentView window] ordered:NSWindowAbove]; + } + } + } +#endif + mQtFont = new QFont(); return self; } @@ -184,6 +210,50 @@ static QFont qfontForCocoaFont(NSFont *cocoaFont, const QFont &resolveFont) [super dealloc]; } +- (void)showModelessPanel +{ + mAppModal = false; + NSWindow *ourPanel = [mStolenContentView window]; + [ourPanel makeKeyAndOrderFront:self]; +} + +- (void)runApplicationModalPanel +{ + QBoolBlocker nativeDialogOnTop(QApplicationPrivate::native_modal_dialog_active); + mAppModal = true; + NSWindow *ourPanel = [mStolenContentView window]; + [NSApp runModalForWindow:ourPanel]; + QAbstractEventDispatcher::instance()->interrupt(); + + if (mReturnCode == NSOKButton) + mPriv->fontDialog()->accept(); + else + mPriv->fontDialog()->reject(); +} + +- (void)showWindowModalSheet:(QWidget *)docWidget +{ +#ifdef QT_MAC_USE_COCOA + NSWindow *window = qt_mac_window_for(docWidget); +#else + WindowRef hiwindowRef = qt_mac_window_for(docWidget); + NSWindow *window = [[NSWindow alloc] initWithWindowRef:hiwindowRef]; + CFRetain(hiwindowRef); +#endif + + mAppModal = false; + NSWindow *ourPanel = [mStolenContentView window]; + [NSApp beginSheet:ourPanel + modalForWindow:window + modalDelegate:0 + didEndSelector:0 + contextInfo:0 ]; + +#ifndef QT_MAC_USE_COCOA + CFRelease(hiwindowRef); +#endif +} + - (void)changeFont:(id)sender { NSFont *dummyFont = [NSFont userFontOfSize:12.0]; @@ -216,12 +286,6 @@ static QFont qfontForCocoaFont(NSFont *cocoaFont, const QFont &resolveFont) mPriv->updateSampleFont(*mQtFont); } -- (void)setModalSession:(NSModalSession)session -{ - Q_ASSERT(!mModalSession); - mModalSession = session; -} - - (BOOL)windowShouldClose:(id)window { Q_UNUSED(window); @@ -282,9 +346,8 @@ static QFont qfontForCocoaFont(NSFont *cocoaFont, const QFont &resolveFont) NSSize cancelSizeHint = [mCancelButton frame].size; const CGFloat ButtonWidth = qMin(qMax(ButtonMinWidth, - qMax(okSizeHint.width, cancelSizeHint.width)), - CGFloat((frameSize.width - 2.0 * ButtonSideMargin - - ButtonSpacing) * 0.5)); + qMax(okSizeHint.width, cancelSizeHint.width)), + CGFloat((frameSize.width - 2.0 * ButtonSideMargin - ButtonSpacing) * 0.5)); const CGFloat ButtonHeight = qMax(ButtonMinHeight, qMax(okSizeHint.height, cancelSizeHint.height)); @@ -317,14 +380,12 @@ static QFont qfontForCocoaFont(NSFont *cocoaFont, const QFont &resolveFont) NSFontManager *fontManager = [NSFontManager sharedFontManager]; [self setQtFont:qfontForCocoaFont([fontManager convertFont:[fontManager selectedFont]], *mQtFont)]; - [[mStolenContentView window] close]; [self finishOffWithCode:NSOKButton]; } - (void)onCancelClicked { Q_ASSERT(mPanelHackedWithButtons); - [[mStolenContentView window] close]; [self finishOffWithCode:NSCancelButton]; } @@ -368,20 +429,26 @@ static QFont qfontForCocoaFont(NSFont *cocoaFont, const QFont &resolveFont) - (void)finishOffWithCode:(NSInteger)code { - if (mPriv) { - if (mModalSession) { - [NSApp endModalSession:mModalSession]; - mModalSession = 0; +#ifdef QT_MAC_USE_COCOA + QFontDialog *q = mPriv->fontDialog(); + if (QWidget *parent = q->parentWidget()) { + if (parent->isWindow()) { + [qt_mac_window_for(parent) removeChildWindow:[mStolenContentView window]]; } - // Hack alert! - // Since this code path was never intended to be followed when starting from exec - // we need to force the dialog to communicate the new font, otherwise the signal - // won't get emitted. - if(code == NSOKButton) - mPriv->sampleEdit->setFont([self qtFont]); - mPriv->done((code == NSOKButton) ? QDialog::Accepted : QDialog::Rejected); - } else { + } +#endif + + if(code == NSOKButton) + mPriv->sampleEdit->setFont([self qtFont]); + + if (mAppModal) { + mReturnCode = code; [NSApp stopModalWithCode:code]; + } else { + if (code == NSOKButton) + mPriv->fontDialog()->accept(); + else + mPriv->fontDialog()->reject(); } } @@ -408,206 +475,16 @@ static QFont qfontForCocoaFont(NSFont *cocoaFont, const QFont &resolveFont) QT_BEGIN_NAMESPACE -extern void macStartInterceptNSPanelCtor(); -extern void macStopInterceptNSPanelCtor(); -extern NSButton *macCreateButton(const char *text, NSView *superview); - -void *QFontDialogPrivate::openCocoaFontPanel(const QFont &initial, - QWidget *parent, const QString &title, QFontDialog::FontDialogOptions options, - QFontDialogPrivate *priv) -{ - Q_UNUSED(parent); // we would use the parent if only NSFontPanel could be a sheet - QMacCocoaAutoReleasePool pool; - - /* - The standard Cocoa font panel has no OK or Cancel button and - is created as a utility window. For strange reasons (which seem - to stem from the fact that the font panel is based on a NIB - file), the approach we use for the color panel doesn't work for - the font panel (and, inversely, the approach we use here doesn't - quite work for color panel, and crashed last time I tried). So - instead, we take the following steps: - - 1. Constructs a plain NSPanel that looks the way we want it - to look. Specifically, if the NoButtons option is off, we - construct a panel without the NSUtilityWindowMask flag - and with buttons (OK and Cancel). - - 2. Steal the content view from the shared NSFontPanel and - put it inside our new NSPanel's content view, together - with the OK and Cancel buttons. - - 3. Lay out the original content view and the buttons when - the font panel is shown and whenever it is resized. - - 4. Clean up after ourselves. - - PS. Some customization is also done in QCocoaApplication - validModesForFontPanel:. - */ - - Qt::WindowModality modality = Qt::ApplicationModal; - if (priv) - modality = priv->fontDialog()->windowModality(); - - bool needButtons = !(options & QFontDialog::NoButtons); - // don't need our own panel if the title bar isn't visible anyway (in a sheet) - bool needOwnPanel = (needButtons && modality != Qt::WindowModal); - - bool sharedFontPanelExisted = [NSFontPanel sharedFontPanelExists]; - NSFontPanel *sharedFontPanel = [NSFontPanel sharedFontPanel]; - [sharedFontPanel setHidesOnDeactivate:false]; - - // hack to ensure that QCocoaApplication's validModesForFontPanel: - // implementation is honored - if (!sharedFontPanelExisted && needOwnPanel) { - [sharedFontPanel makeKeyAndOrderFront:sharedFontPanel]; - [sharedFontPanel close]; - } - - NSPanel *ourPanel = 0; - NSView *stolenContentView = 0; - NSButton *okButton = 0; - NSButton *cancelButton = 0; - - CGFloat dialogExtraWidth = 0.0; - CGFloat dialogExtraHeight = 0.0; - - if (!needOwnPanel) { - // we can reuse the NSFontPanel unchanged - ourPanel = sharedFontPanel; - } else { - // compute dialogExtra{Width,Height} - dialogExtraWidth = 2.0 * DialogSideMargin; - dialogExtraHeight = DialogTopMargin + ButtonTopMargin + ButtonMinHeight - + ButtonBottomMargin; - - // compute initial contents rectangle - NSRect contentRect = [sharedFontPanel contentRectForFrameRect:[sharedFontPanel frame]]; - contentRect.size.width += dialogExtraWidth; - contentRect.size.height += dialogExtraHeight; - - // create the new panel - ourPanel = [[NSPanel alloc] initWithContentRect:contentRect - styleMask:StyleMask - backing:NSBackingStoreBuffered - defer:YES]; - [ourPanel setReleasedWhenClosed:YES]; - } - - stolenContentView = [sharedFontPanel contentView]; - - if (needButtons) { - // steal the font panel's contents view - [stolenContentView retain]; - [sharedFontPanel setContentView:0]; - - // create a new content view and add the stolen one as a subview - NSRect frameRect = { { 0.0, 0.0 }, { 0.0, 0.0 } }; - NSView *ourContentView = [[NSView alloc] initWithFrame:frameRect]; - [ourContentView addSubview:stolenContentView]; - - // create OK and Cancel buttons and add these as subviews - okButton = macCreateButton("&OK", ourContentView); - cancelButton = macCreateButton("Cancel", ourContentView); - - [ourPanel setContentView:ourContentView]; - [ourPanel setDefaultButtonCell:[okButton cell]]; - } - - // create a delegate and set it - QCocoaFontPanelDelegate *delegate = - [[QCocoaFontPanelDelegate alloc] initWithFontPanel:sharedFontPanel - stolenContentView:stolenContentView - okButton:okButton - cancelButton:cancelButton - priv:priv - extraWidth:dialogExtraWidth - extraHeight:dialogExtraHeight]; - [ourPanel setDelegate:delegate]; - [[NSFontManager sharedFontManager] setDelegate:delegate]; -#ifdef QT_MAC_USE_COCOA - [[NSFontManager sharedFontManager] setTarget:delegate]; -#endif - setFont(delegate, initial); - - // hack to get correct initial layout - NSRect frameRect = [ourPanel frame]; - frameRect.size.width += 1.0; - [ourPanel setFrame:frameRect display:NO]; - frameRect.size.width -= 1.0; - frameRect.size = [delegate windowWillResize:ourPanel toSize:frameRect.size]; - [ourPanel setFrame:frameRect display:NO]; - [ourPanel center]; - - [ourPanel setTitle:(NSString*)(CFStringRef)QCFString(title)]; - - if (priv) { - switch (modality) { - case Qt::WindowModal: - if (parent) { -#ifndef QT_MAC_USE_COCOA - WindowRef hiwindowRef = qt_mac_window_for(parent); - NSWindow *window = - [[NSWindow alloc] initWithWindowRef:hiwindowRef]; - // Cocoa docs say I should retain the Carbon ref. - CFRetain(hiwindowRef); -#else - NSWindow *window = qt_mac_window_for(parent); -#endif - [NSApp beginSheet:ourPanel - modalForWindow:window - modalDelegate:0 - didEndSelector:0 - contextInfo:0]; -#ifndef QT_MAC_USE_COCOA - [window release]; -#endif - break; - } - // fallthrough - case Qt::ApplicationModal: - [delegate setModalSession:[NSApp beginModalSessionForWindow:ourPanel]]; - break; - default: - [ourPanel makeKeyAndOrderFront:ourPanel]; - } - } - return delegate; -} - -void QFontDialogPrivate::closeCocoaFontPanel(void *delegate) +void QFontDialogPrivate::closeCocoaFontPanel() { QMacCocoaAutoReleasePool pool; QCocoaFontPanelDelegate *theDelegate = static_cast<QCocoaFontPanelDelegate *>(delegate); NSWindow *ourPanel = [theDelegate actualPanel]; [ourPanel close]; [theDelegate cleanUpAfterMyself]; - [theDelegate autorelease]; -} - -QFont QFontDialogPrivate::execCocoaFontPanel(bool *ok, const QFont &initial, - QWidget *parent, const QString &title, QFontDialog::FontDialogOptions options) -{ - QMacCocoaAutoReleasePool pool; - QCocoaFontPanelDelegate *delegate = - static_cast<QCocoaFontPanelDelegate *>( - openCocoaFontPanel(initial, parent, title, options)); - NSWindow *ourPanel = [delegate actualPanel]; - [ourPanel retain]; - int rval = [NSApp runModalForWindow:ourPanel]; - QFont font([delegate qtFont]); - [ourPanel release]; - [delegate cleanUpAfterMyself]; - [delegate release]; - bool isOk = ((options & QFontDialog::NoButtons) || rval == NSOKButton); - if (ok) - *ok = isOk; - if (isOk) { - return font; - } else { - return initial; - } + [theDelegate release]; + this->delegate = 0; + sharedFontPanelAvailable = true; } void QFontDialogPrivate::setFont(void *delegate, const QFont &font) @@ -645,10 +522,13 @@ void QFontDialogPrivate::setFont(void *delegate, const QFont &font) [static_cast<QCocoaFontPanelDelegate *>(delegate) setQtFont:font]; } -void *QFontDialogPrivate::_q_constructNativePanel() +void QFontDialogPrivate::createNSFontPanelDelegate() { - QMacCocoaAutoReleasePool pool; + if (delegate) + return; + sharedFontPanelAvailable = false; + QMacCocoaAutoReleasePool pool; bool sharedFontPanelExisted = [NSFontPanel sharedFontPanelExists]; NSFontPanel *sharedFontPanel = [NSFontPanel sharedFontPanel]; [sharedFontPanel setHidesOnDeactivate:false]; @@ -670,8 +550,7 @@ void *QFontDialogPrivate::_q_constructNativePanel() // compute dialogExtra{Width,Height} dialogExtraWidth = 2.0 * DialogSideMargin; - dialogExtraHeight = DialogTopMargin + ButtonTopMargin + ButtonMinHeight - + ButtonBottomMargin; + dialogExtraHeight = DialogTopMargin + ButtonTopMargin + ButtonMinHeight + ButtonBottomMargin; // compute initial contents rectangle NSRect contentRect = [sharedFontPanel contentRectForFrameRect:[sharedFontPanel frame]]; @@ -684,7 +563,6 @@ void *QFontDialogPrivate::_q_constructNativePanel() backing:NSBackingStoreBuffered defer:YES]; [ourPanel setReleasedWhenClosed:YES]; - stolenContentView = [sharedFontPanel contentView]; // steal the font panel's contents view @@ -704,21 +582,23 @@ void *QFontDialogPrivate::_q_constructNativePanel() [ourPanel setContentView:ourContentView]; [ourPanel setDefaultButtonCell:[okButton cell]]; } - // create a delegate and set it - QCocoaFontPanelDelegate *delegate = - [[QCocoaFontPanelDelegate alloc] initWithFontPanel:sharedFontPanel + + // create the delegate and set it + QCocoaFontPanelDelegate *del = [[QCocoaFontPanelDelegate alloc] initWithFontPanel:sharedFontPanel stolenContentView:stolenContentView okButton:okButton cancelButton:cancelButton priv:this extraWidth:dialogExtraWidth extraHeight:dialogExtraHeight]; - [ourPanel setDelegate:delegate]; - [[NSFontManager sharedFontManager] setDelegate:delegate]; + delegate = del; + [ourPanel setDelegate:del]; + + [[NSFontManager sharedFontManager] setDelegate:del]; #ifdef QT_MAC_USE_COCOA - [[NSFontManager sharedFontManager] setTarget:delegate]; + [[NSFontManager sharedFontManager] setTarget:del]; #endif - setFont(delegate, QApplication::font()); + setFont(del, q_func()->currentFont()); { // hack to get correct initial layout @@ -726,15 +606,12 @@ void *QFontDialogPrivate::_q_constructNativePanel() frameRect.size.width += 1.0; [ourPanel setFrame:frameRect display:NO]; frameRect.size.width -= 1.0; - frameRect.size = [delegate windowWillResize:ourPanel toSize:frameRect.size]; + frameRect.size = [del windowWillResize:ourPanel toSize:frameRect.size]; [ourPanel setFrame:frameRect display:NO]; [ourPanel center]; } NSString *title = @"Select font"; [ourPanel setTitle:title]; - - [delegate setModalSession:[NSApp beginModalSessionForWindow:ourPanel]]; - return delegate; } void QFontDialogPrivate::mac_nativeDialogModalHelp() @@ -759,29 +636,47 @@ void QFontDialogPrivate::mac_nativeDialogModalHelp() // and "adding" the buttons. void QFontDialogPrivate::_q_macRunNativeAppModalPanel() { - QBoolBlocker nativeDialogOnTop(QApplicationPrivate::native_modal_dialog_active); + createNSFontPanelDelegate(); + QCocoaFontPanelDelegate *del = static_cast<QCocoaFontPanelDelegate *>(delegate); + [del runApplicationModalPanel]; +} + +bool QFontDialogPrivate::showCocoaFontPanel() +{ + if (!sharedFontPanelAvailable) + return false; + Q_Q(QFontDialog); - QCocoaFontPanelDelegate *delegate = (QCocoaFontPanelDelegate *)_q_constructNativePanel(); - NSWindow *ourPanel = [delegate actualPanel]; - [ourPanel retain]; - int rval = [NSApp runModalForWindow:ourPanel]; - QAbstractEventDispatcher::instance()->interrupt(); - [ourPanel release]; - [delegate cleanUpAfterMyself]; - [delegate release]; - bool isOk = (rval == NSOKButton); - if(isOk) - rescode = QDialog::Accepted; + QMacCocoaAutoReleasePool pool; + createNSFontPanelDelegate(); + QCocoaFontPanelDelegate *del = static_cast<QCocoaFontPanelDelegate *>(delegate); + if (qt_mac_is_macsheet(q)) + [del showWindowModalSheet:q->parentWidget()]; else - rescode = QDialog::Rejected; + [del showModelessPanel]; + return true; } +bool QFontDialogPrivate::hideCocoaFontPanel() +{ + if (!delegate){ + // Nothing to do. We return false to leave the question + // open regarding whether or not to go native: + return false; + } else { + closeCocoaFontPanel(); + // Even when we hide it, we are still using a + // native dialog, so return true: + return true; + } +} bool QFontDialogPrivate::setVisible_sys(bool visible) { Q_Q(QFontDialog); if (!visible == q->isHidden()) return false; - return visible; + + return visible ? showCocoaFontPanel() : hideCocoaFontPanel(); } QT_END_NAMESPACE diff --git a/src/gui/dialogs/qfontdialog_p.h b/src/gui/dialogs/qfontdialog_p.h index 7654a80..8676be3 100644 --- a/src/gui/dialogs/qfontdialog_p.h +++ b/src/gui/dialogs/qfontdialog_p.h @@ -139,25 +139,21 @@ public: QByteArray memberToDisconnectOnClose; #ifdef Q_WS_MAC - static void *openCocoaFontPanel(const QFont &initial, - QWidget *parent, const QString &title, - QFontDialog::FontDialogOptions options, - QFontDialogPrivate *priv = 0); - static void closeCocoaFontPanel(void *delegate); - static QFont execCocoaFontPanel(bool *ok, const QFont &initial, QWidget *parent, - const QString &title, QFontDialog::FontDialogOptions options); static void setFont(void *delegate, const QFont &font); inline void done(int result) { q_func()->done(result); } inline QFontDialog *fontDialog() { return q_func(); } void *delegate; + void closeCocoaFontPanel(); bool nativeDialogInUse; bool canBeNativeDialog(); bool setVisible_sys(bool visible); - void *_q_constructNativePanel(); + void createNSFontPanelDelegate(); void _q_macRunNativeAppModalPanel(); void mac_nativeDialogModalHelp(); + bool showCocoaFontPanel(); + bool hideCocoaFontPanel(); static bool sharedFontPanelAvailable; #endif diff --git a/src/gui/dialogs/qmessagebox.cpp b/src/gui/dialogs/qmessagebox.cpp index ccc925c..fe25b0f 100644 --- a/src/gui/dialogs/qmessagebox.cpp +++ b/src/gui/dialogs/qmessagebox.cpp @@ -96,8 +96,8 @@ public: { #ifndef QT_NO_CONTEXTMENU QMenu *menu = createStandardContextMenu(); - menu->exec(e->globalPos()); - delete menu; + menu->setAttribute(Qt::WA_DeleteOnClose); + menu->popup(e->globalPos()); #else Q_UNUSED(e); #endif @@ -122,14 +122,44 @@ public: } void setText(const QString &text) { textEdit->setPlainText(text); } QString text() const { return textEdit->toPlainText(); } - QString label(DetailButtonLabel label) - { return label == ShowLabel ? QMessageBox::tr("Show Details...") - : QMessageBox::tr("Hide Details..."); } private: TextEdit *textEdit; }; #endif // QT_NO_TEXTEDIT +class DetailButton : public QPushButton +{ +public: + DetailButton(QWidget *parent) : QPushButton(label(ShowLabel), parent) + { + setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + } + + QString label(DetailButtonLabel label) const + { return label == ShowLabel ? QMessageBox::tr("Show Details...") : QMessageBox::tr("Hide Details..."); } + + void setLabel(DetailButtonLabel lbl) + { setText(label(lbl)); } + + QSize sizeHint() const + { + ensurePolished(); + QStyleOptionButton opt; + initStyleOption(&opt); + const QFontMetrics fm = fontMetrics(); + opt.text = label(ShowLabel); + QSize sz = fm.size(Qt::TextShowMnemonic, opt.text); + QSize ret = style()->sizeFromContents(QStyle::CT_PushButton, &opt, sz, this). + expandedTo(QApplication::globalStrut()); + opt.text = label(HideLabel); + sz = fm.size(Qt::TextShowMnemonic, opt.text); + ret.expandedTo(style()->sizeFromContents(QStyle::CT_PushButton, &opt, sz, this). + expandedTo(QApplication::globalStrut())); + return ret; + } +}; + + class QMessageBoxPrivate : public QDialogPrivate { Q_DECLARE_PUBLIC(QMessageBox) @@ -185,7 +215,7 @@ public: QAbstractButton *escapeButton; QPushButton *defaultButton; QAbstractButton *clickedButton; - QPushButton *detailsButton; + DetailButton *detailsButton; #ifndef QT_NO_TEXTEDIT QMessageBoxDetailsText *detailsText; #endif @@ -435,7 +465,7 @@ void QMessageBoxPrivate::_q_buttonClicked(QAbstractButton *button) Q_Q(QMessageBox); #ifndef QT_NO_TEXTEDIT if (detailsButton && detailsText && button == detailsButton) { - detailsButton->setText(detailsText->isHidden() ? detailsText->label(HideLabel) : detailsText->label(ShowLabel)); + detailsButton->setLabel(detailsText->isHidden() ? HideLabel : ShowLabel); detailsText->setHidden(!detailsText->isHidden()); updateSize(); } else @@ -1905,7 +1935,7 @@ void QMessageBoxPrivate::retranslateStrings() { #ifndef QT_NO_TEXTEDIT if (detailsButton) - detailsButton->setText(detailsText->isHidden() ? detailsText->label(HideLabel) : detailsText->label(ShowLabel)); + detailsButton->setLabel(detailsText->isHidden() ? HideLabel : ShowLabel); #endif } @@ -2413,11 +2443,8 @@ void QMessageBox::setDetailedText(const QString &text) grid->addWidget(d->detailsText, grid->rowCount(), 0, 1, grid->columnCount()); d->detailsText->hide(); } - if (!d->detailsButton) { - d->detailsButton = new QPushButton(d->detailsText->label(ShowLabel), this); - QPushButton hideDetails(d->detailsText->label(HideLabel)); - d->detailsButton->setFixedSize(d->detailsButton->sizeHint().expandedTo(hideDetails.sizeHint())); - } + if (!d->detailsButton) + d->detailsButton = new DetailButton(this); d->detailsText->setText(text); } #endif // QT_NO_TEXTEDIT diff --git a/src/gui/dialogs/qprintdialog_qws.cpp b/src/gui/dialogs/qprintdialog_qws.cpp index 6b531a2..b071427 100644 --- a/src/gui/dialogs/qprintdialog_qws.cpp +++ b/src/gui/dialogs/qprintdialog_qws.cpp @@ -163,7 +163,7 @@ void QPrintDialogPrivate::_q_okClicked() printer->setPaperSize(pageSize); printer->setPageOrder(pageOrder2); printer->setColorMode(colorMode2); - printer->setNumCopies(numCopies); + printer->setCopyCount(numCopies); switch ((rangeCombo->itemData(rangeCombo->currentIndex())).toInt()){ case (int)QPrintDialog::AllPages: @@ -178,6 +178,10 @@ void QPrintDialogPrivate::_q_okClicked() q->setPrintRange(QPrintDialog::PageRange); q->setFromTo(firstPage->value(), lastPage->value()); break; + case (int)QPrintDialog::CurrentPage: + q->setPrintRange(QPrintDialog::CurrentPage); + q->setFromTo(0, 0); + break; } q->accept(); } @@ -375,6 +379,7 @@ void QPrintDialogPrivate::setupOptions() rangeCombo->addItem(QPrintDialog::tr("Print all"), QPrintDialog::AllPages); rangeCombo->addItem(QPrintDialog::tr("Print selection"), QPrintDialog::Selection); rangeCombo->addItem(QPrintDialog::tr("Print range"), QPrintDialog::PageRange); + rangeCombo->addItem(QPrintDialog::tr("Print current page"), QPrintDialog::CurrentPage); QObject::connect(rangeCombo, SIGNAL(activated(int)), q, SLOT(_q_printRangeSelected(int))); @@ -479,8 +484,8 @@ void QPrintDialogPrivate::setPrinter(QPrinter *p, bool pickUpSettings) printGray->setChecked(true); // number of copies - copies->setValue(p->numCopies()); - _q_setNumCopies(p->numCopies()); + copies->setValue(p->copyCount()); + _q_setNumCopies(p->copyCount()); } if (p) { @@ -490,6 +495,9 @@ void QPrintDialogPrivate::setPrinter(QPrinter *p, bool pickUpSettings) if (!q->isOptionEnabled(QPrintDialog::PrintPageRange) && rangeCombo->findData(QPrintDialog::PageRange) > 0) rangeCombo->removeItem(rangeCombo->findData(QPrintDialog::PageRange)); + if (!q->isOptionEnabled(QPrintDialog::PrintCurrentPage) + && rangeCombo->findData(QPrintDialog::CurrentPage) > 0) + rangeCombo->removeItem(rangeCombo->findData(QPrintDialog::CurrentPage)); switch (q->printRange()) { case QPrintDialog::AllPages: @@ -501,6 +509,9 @@ void QPrintDialogPrivate::setPrinter(QPrinter *p, bool pickUpSettings) case QPrintDialog::PageRange: rangeCombo->setCurrentIndex((int)(QPrintDialog::PageRange)); break; + case QPrintDialog::CurrentPage: + rangeCombo->setCurrentIndex((int)(QPrintDialog::CurrentPage)); + break; } } diff --git a/src/gui/dialogs/qprintdialog_unix.cpp b/src/gui/dialogs/qprintdialog_unix.cpp index 00dc3e6..9b4d6e8 100644 --- a/src/gui/dialogs/qprintdialog_unix.cpp +++ b/src/gui/dialogs/qprintdialog_unix.cpp @@ -72,8 +72,6 @@ QT_BEGIN_NAMESPACE -extern int qt_printerRealNumCopies(QPaintEngine *); - class QOptionTreeItem; class QPPDOptionsModel; @@ -442,7 +440,7 @@ void QPrintDialogPrivate::applyPrinterProperties(QPrinter *p) case QPrinter::DuplexShortSide: options.duplexShort->setChecked(true); break; } - options.copies->setValue(qt_printerRealNumCopies(p->paintEngine())); + options.copies->setValue(p->copyCount()); options.collate->setChecked(p->collateCopies()); options.reverse->setChecked(p->pageOrder() == QPrinter::LastPageFirst); top->d->applyPrinterProperties(p); @@ -507,13 +505,16 @@ void QPrintDialogPrivate::setupPrinter() } else if (options.printSelection->isChecked()) { p->setPrintRange(QPrinter::Selection); p->setFromTo(0,0); + } else if (options.printCurrentPage->isChecked()) { + p->setPrintRange(QPrinter::CurrentPage); + p->setFromTo(0,0); } else if (options.printRange->isChecked()) { p->setPrintRange(QPrinter::PageRange); p->setFromTo(options.from->value(), qMax(options.from->value(), options.to->value())); } // copies - p->setNumCopies(options.copies->value()); + p->setCopyCount(options.copies->value()); p->setCollateCopies(options.collate->isChecked()); top->d->setupPrinter(); @@ -523,10 +524,12 @@ void QPrintDialogPrivate::updateWidgets() { Q_Q(QPrintDialog); options.gbPrintRange->setVisible(q->isOptionEnabled(QPrintDialog::PrintPageRange) || - q->isOptionEnabled(QPrintDialog::PrintSelection)); + q->isOptionEnabled(QPrintDialog::PrintSelection) || + q->isOptionEnabled(QPrintDialog::PrintCurrentPage)); options.printRange->setEnabled(q->isOptionEnabled(QPrintDialog::PrintPageRange)); options.printSelection->setVisible(q->isOptionEnabled(QPrintDialog::PrintSelection)); + options.printCurrentPage->setVisible(q->isOptionEnabled(QPrintDialog::PrintCurrentPage)); options.collate->setVisible(q->isOptionEnabled(QPrintDialog::PrintCollateCopies)); switch (q->printRange()) { @@ -539,6 +542,10 @@ void QPrintDialogPrivate::updateWidgets() case QPrintDialog::PageRange: options.printRange->setChecked(true); break; + case QPrintDialog::CurrentPage: + if (q->isOptionEnabled(QPrintDialog::PrintCurrentPage)) + options.printCurrentPage->setChecked(true); + break; default: break; } @@ -699,9 +706,7 @@ QUnixPrintWidgetPrivate::QUnixPrintWidgetPrivate(QUnixPrintWidget *p) #ifndef QT_NO_FILESYSTEMMODEL QFileSystemModel *fsm = new QFileSystemModel(widget.filename); fsm->setRootPath(QDir::homePath()); -#if !defined(QT_NO_FSCOMPLETER) && !defined(QT_NO_FILEDIALOG) - widget.filename->setCompleter(new QFSCompleter(fsm, widget.filename)); -#endif + widget.filename->setCompleter(new QCompleter(fsm, widget.filename)); #endif _q_printerChanged(currentPrinterIndex); diff --git a/src/gui/dialogs/qprintdialog_win.cpp b/src/gui/dialogs/qprintdialog_win.cpp index 5ccd33d..38c8759 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 @@ -128,17 +128,20 @@ static void qt_win_setup_PRINTDLGEX(PRINTDLGEX *pd, QWidget *parent, if (pd->nMinPage==0 && pd->nMaxPage==0) pd->Flags |= PD_NOPAGENUMS; - // we don't have a 'current page' notion in the QPrinter API yet. - // Neither do we support more than one page range, so limit those - // options - pd->Flags |= PD_NOCURRENTPAGE; + // Disable Current Page option if not required as default is Enabled + if (!pdlg->isOptionEnabled(QPrintDialog::PrintCurrentPage)) + pd->Flags |= PD_NOCURRENTPAGE; + + // Default to showing the General tab first pd->nStartPage = START_PAGE_GENERAL; + + // We don't support more than one page range in the QPrinter API yet. pd->nPageRanges = 1; pd->nMaxPageRanges = 1; if (d->ep->printToFile) pd->Flags |= PD_PRINTTOFILE; - Q_ASSERT(parent != 0 && parent->testAttribute(Qt::WA_WState_Created)); + Q_ASSERT(parent); pd->hwndOwner = parent->window()->winId(); pd->lpPageRanges[0].nFromPage = qMax(pdlg->fromPage(), pdlg->minPage()); pd->lpPageRanges[0].nToPage = (pdlg->toPage() > 0) ? qMin(pdlg->toPage(), pdlg->maxPage()) : 1; @@ -153,7 +156,10 @@ static void qt_win_read_back_PRINTDLGEX(PRINTDLGEX *pd, QPrintDialog *pdlg, QPri } else if (pd->Flags & PD_PAGENUMS) { pdlg->setPrintRange(QPrintDialog::PageRange); pdlg->setFromTo(pd->lpPageRanges[0].nFromPage, pd->lpPageRanges[0].nToPage); - } else { + } else if (pd->Flags & PD_CURRENTPAGE) { + pdlg->setPrintRange(QPrintDialog::CurrentPage); + pdlg->setFromTo(0, 0); + } else { // PD_ALLPAGES pdlg->setPrintRange(QPrintDialog::AllPages); pdlg->setFromTo(0, 0); } diff --git a/src/gui/dialogs/qprintsettingsoutput.ui b/src/gui/dialogs/qprintsettingsoutput.ui index fc57e86..be91679 100644 --- a/src/gui/dialogs/qprintsettingsoutput.ui +++ b/src/gui/dialogs/qprintsettingsoutput.ui @@ -1,121 +1,114 @@ -<ui version="4.0" > +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> <class>QPrintSettingsOutput</class> - <widget class="QWidget" name="QPrintSettingsOutput" > - <property name="geometry" > + <widget class="QWidget" name="QPrintSettingsOutput"> + <property name="geometry"> <rect> <x>0</x> <y>0</y> - <width>416</width> - <height>166</height> + <width>426</width> + <height>171</height> </rect> </property> - <property name="windowTitle" > + <property name="windowTitle"> <string>Form</string> </property> - <layout class="QHBoxLayout" name="horizontalLayout_2" > - <property name="margin" > + <layout class="QHBoxLayout" name="horizontalLayout_2"> + <property name="margin"> <number>0</number> </property> <item> - <widget class="QTabWidget" name="tabs" > - <property name="currentIndex" > + <widget class="QTabWidget" name="tabs"> + <property name="currentIndex"> <number>0</number> </property> - <widget class="QWidget" name="copiesTab" > - <property name="geometry" > - <rect> - <x>0</x> - <y>0</y> - <width>412</width> - <height>139</height> - </rect> - </property> - <attribute name="title" > + <widget class="QWidget" name="copiesTab"> + <attribute name="title"> <string>Copies</string> </attribute> - <layout class="QHBoxLayout" name="horizontalLayout" > + <layout class="QHBoxLayout" name="horizontalLayout"> <item> - <widget class="QGroupBox" name="gbPrintRange" > - <property name="sizePolicy" > - <sizepolicy vsizetype="Minimum" hsizetype="Preferred" > + <widget class="QGroupBox" name="gbPrintRange"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Minimum"> <horstretch>0</horstretch> <verstretch>0</verstretch> </sizepolicy> </property> - <property name="title" > + <property name="title"> <string>Print range</string> </property> - <layout class="QVBoxLayout" name="_3" > - <property name="spacing" > + <layout class="QVBoxLayout" name="_3"> + <property name="spacing"> <number>4</number> </property> - <property name="margin" > + <property name="margin"> <number>6</number> </property> <item> - <widget class="QRadioButton" name="printAll" > - <property name="text" > + <widget class="QRadioButton" name="printAll"> + <property name="text"> <string>Print all</string> </property> - <property name="checked" > + <property name="checked"> <bool>true</bool> </property> </widget> </item> <item> - <layout class="QHBoxLayout" name="_4" > - <property name="spacing" > + <layout class="QHBoxLayout" name="_4"> + <property name="spacing"> <number>6</number> </property> - <property name="margin" > + <property name="margin"> <number>0</number> </property> <item> - <widget class="QRadioButton" name="printRange" > - <property name="text" > + <widget class="QRadioButton" name="printRange"> + <property name="text"> <string>Pages from</string> </property> </widget> </item> <item> - <widget class="QSpinBox" name="from" > - <property name="enabled" > + <widget class="QSpinBox" name="from"> + <property name="enabled"> <bool>false</bool> </property> - <property name="minimum" > + <property name="minimum"> <number>1</number> </property> - <property name="maximum" > + <property name="maximum"> <number>999</number> </property> </widget> </item> <item> - <widget class="QLabel" name="label_3" > - <property name="text" > + <widget class="QLabel" name="label_3"> + <property name="text"> <string>to</string> </property> </widget> </item> <item> - <widget class="QSpinBox" name="to" > - <property name="enabled" > + <widget class="QSpinBox" name="to"> + <property name="enabled"> <bool>false</bool> </property> - <property name="minimum" > + <property name="minimum"> <number>1</number> </property> - <property name="maximum" > + <property name="maximum"> <number>999</number> </property> </widget> </item> <item> <spacer> - <property name="orientation" > + <property name="orientation"> <enum>Qt::Horizontal</enum> </property> - <property name="sizeHint" stdset="0" > + <property name="sizeHint" stdset="0"> <size> <width>0</width> <height>20</height> @@ -126,18 +119,25 @@ </layout> </item> <item> - <widget class="QRadioButton" name="printSelection" > - <property name="text" > + <widget class="QRadioButton" name="printCurrentPage"> + <property name="text"> + <string>Current Page</string> + </property> + </widget> + </item> + <item> + <widget class="QRadioButton" name="printSelection"> + <property name="text"> <string>Selection</string> </property> </widget> </item> <item> - <spacer name="verticalSpacer" > - <property name="orientation" > + <spacer name="verticalSpacer"> + <property name="orientation"> <enum>Qt::Vertical</enum> </property> - <property name="sizeHint" stdset="0" > + <property name="sizeHint" stdset="0"> <size> <width>1</width> <height>1</height> @@ -149,37 +149,37 @@ </widget> </item> <item> - <widget class="QGroupBox" name="groupBox" > - <property name="title" > + <widget class="QGroupBox" name="groupBox"> + <property name="title"> <string>Output Settings</string> </property> - <layout class="QGridLayout" name="gridLayout" > - <item row="0" column="0" > - <widget class="QLabel" name="label" > - <property name="text" > + <layout class="QGridLayout" name="gridLayout"> + <item row="0" column="0"> + <widget class="QLabel" name="label"> + <property name="text"> <string>Copies:</string> </property> - <property name="buddy" > + <property name="buddy"> <cstring>copies</cstring> </property> </widget> </item> - <item row="0" column="1" colspan="2" > - <widget class="QSpinBox" name="copies" > - <property name="minimum" > + <item row="0" column="1" colspan="2"> + <widget class="QSpinBox" name="copies"> + <property name="minimum"> <number>1</number> </property> - <property name="maximum" > + <property name="maximum"> <number>999</number> </property> </widget> </item> - <item row="0" column="3" > - <spacer name="horizontalSpacer" > - <property name="orientation" > + <item row="0" column="3"> + <spacer name="horizontalSpacer"> + <property name="orientation"> <enum>Qt::Horizontal</enum> </property> - <property name="sizeHint" stdset="0" > + <property name="sizeHint" stdset="0"> <size> <width>91</width> <height>20</height> @@ -187,36 +187,36 @@ </property> </spacer> </item> - <item row="1" column="0" colspan="2" > - <widget class="QCheckBox" name="collate" > - <property name="text" > + <item row="1" column="0" colspan="2"> + <widget class="QCheckBox" name="collate"> + <property name="text"> <string>Collate</string> </property> </widget> </item> - <item rowspan="2" row="1" column="2" colspan="2" > - <widget class="QLabel" name="outputIcon" > - <property name="sizePolicy" > - <sizepolicy vsizetype="Ignored" hsizetype="Ignored" > + <item row="1" column="2" rowspan="2" colspan="2"> + <widget class="QLabel" name="outputIcon"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Ignored" vsizetype="Ignored"> <horstretch>0</horstretch> <verstretch>0</verstretch> </sizepolicy> </property> </widget> </item> - <item row="2" column="0" colspan="2" > - <widget class="QCheckBox" name="reverse" > - <property name="text" > + <item row="2" column="0" colspan="2"> + <widget class="QCheckBox" name="reverse"> + <property name="text"> <string>Reverse</string> </property> </widget> </item> - <item row="3" column="0" colspan="4" > - <spacer name="verticalSpacer_2" > - <property name="orientation" > + <item row="3" column="0" colspan="4"> + <spacer name="verticalSpacer_2"> + <property name="orientation"> <enum>Qt::Vertical</enum> </property> - <property name="sizeHint" stdset="0" > + <property name="sizeHint" stdset="0"> <size> <width>0</width> <height>1</height> @@ -229,31 +229,23 @@ </item> </layout> </widget> - <widget class="QWidget" name="optionsTab" > - <property name="geometry" > - <rect> - <x>0</x> - <y>0</y> - <width>412</width> - <height>139</height> - </rect> - </property> - <attribute name="title" > + <widget class="QWidget" name="optionsTab"> + <attribute name="title"> <string>Options</string> </attribute> - <layout class="QGridLayout" name="gridLayout_2" > - <item row="0" column="1" > - <widget class="QGroupBox" name="colorMode" > - <property name="title" > + <layout class="QGridLayout" name="gridLayout_2"> + <item row="0" column="1"> + <widget class="QGroupBox" name="colorMode"> + <property name="title"> <string>Color Mode</string> </property> - <layout class="QGridLayout" name="gridLayout_4" > - <item row="2" column="0" > - <spacer name="verticalSpacer_6" > - <property name="orientation" > + <layout class="QGridLayout" name="gridLayout_4"> + <item row="2" column="0"> + <spacer name="verticalSpacer_6"> + <property name="orientation"> <enum>Qt::Vertical</enum> </property> - <property name="sizeHint" stdset="0" > + <property name="sizeHint" stdset="0"> <size> <width>1</width> <height>0</height> @@ -261,19 +253,19 @@ </property> </spacer> </item> - <item row="0" column="0" > - <widget class="QRadioButton" name="color" > - <property name="text" > + <item row="0" column="0"> + <widget class="QRadioButton" name="color"> + <property name="text"> <string>Color</string> </property> </widget> </item> - <item rowspan="3" row="0" column="1" > - <widget class="QLabel" name="colorIcon" /> + <item row="0" column="1" rowspan="3"> + <widget class="QLabel" name="colorIcon"/> </item> - <item row="1" column="0" > - <widget class="QRadioButton" name="grayscale" > - <property name="text" > + <item row="1" column="0"> + <widget class="QRadioButton" name="grayscale"> + <property name="text"> <string>Grayscale</string> </property> </widget> @@ -281,42 +273,42 @@ </layout> </widget> </item> - <item row="0" column="0" > - <widget class="QGroupBox" name="duplex" > - <property name="title" > + <item row="0" column="0"> + <widget class="QGroupBox" name="duplex"> + <property name="title"> <string>Duplex Printing</string> </property> - <layout class="QVBoxLayout" name="verticalLayout" > + <layout class="QVBoxLayout" name="verticalLayout"> <item> - <widget class="QRadioButton" name="noDuplex" > - <property name="text" > + <widget class="QRadioButton" name="noDuplex"> + <property name="text"> <string>None</string> </property> - <property name="checked" > + <property name="checked"> <bool>true</bool> </property> </widget> </item> <item> - <widget class="QRadioButton" name="duplexLong" > - <property name="text" > + <widget class="QRadioButton" name="duplexLong"> + <property name="text"> <string>Long side</string> </property> </widget> </item> <item> - <widget class="QRadioButton" name="duplexShort" > - <property name="text" > + <widget class="QRadioButton" name="duplexShort"> + <property name="text"> <string>Short side</string> </property> </widget> </item> <item> - <spacer name="verticalSpacer_42" > - <property name="orientation" > + <spacer name="verticalSpacer_42"> + <property name="orientation"> <enum>Qt::Vertical</enum> </property> - <property name="sizeHint" stdset="0" > + <property name="sizeHint" stdset="0"> <size> <width>1</width> <height>0</height> @@ -341,11 +333,11 @@ <receiver>from</receiver> <slot>setEnabled(bool)</slot> <hints> - <hint type="sourcelabel" > + <hint type="sourcelabel"> <x>76</x> <y>59</y> </hint> - <hint type="destinationlabel" > + <hint type="destinationlabel"> <x>122</x> <y>57</y> </hint> @@ -357,11 +349,11 @@ <receiver>to</receiver> <slot>setEnabled(bool)</slot> <hints> - <hint type="sourcelabel" > + <hint type="sourcelabel"> <x>69</x> <y>67</y> </hint> - <hint type="destinationlabel" > + <hint type="destinationlabel"> <x>215</x> <y>67</y> </hint> diff --git a/src/gui/dialogs/qprogressdialog.cpp b/src/gui/dialogs/qprogressdialog.cpp index 4fffdba..a2d7b23 100644 --- a/src/gui/dialogs/qprogressdialog.cpp +++ b/src/gui/dialogs/qprogressdialog.cpp @@ -46,7 +46,6 @@ #include "qshortcut.h" #include "qpainter.h" #include "qdrawutil.h" -#include "qdatetime.h" #include "qlabel.h" #include "qprogressbar.h" #include "qapplication.h" @@ -54,6 +53,7 @@ #include "qpushbutton.h" #include "qcursor.h" #include "qtimer.h" +#include "qelapsedtimer.h" #include <private/qdialog_p.h> #include <limits.h> @@ -103,7 +103,7 @@ public: QTimer *forceTimer; bool shown_once; bool cancellation_flag; - QTime starttime; + QElapsedTimer starttime; #ifndef QT_NO_CURSOR QCursor parentCursor; #endif diff --git a/src/gui/dialogs/qwizard.cpp b/src/gui/dialogs/qwizard.cpp index a58057d..8607529 100644 --- a/src/gui/dialogs/qwizard.cpp +++ b/src/gui/dialogs/qwizard.cpp @@ -218,8 +218,8 @@ public: : topLevelMarginLeft(-1), topLevelMarginRight(-1), topLevelMarginTop(-1), topLevelMarginBottom(-1), childMarginLeft(-1), childMarginRight(-1), childMarginTop(-1), childMarginBottom(-1), hspacing(-1), vspacing(-1), - wizStyle(QWizard::ClassicStyle), header(false), watermark(false), title(false), - subTitle(false), extension(false) {} + wizStyle(QWizard::ClassicStyle), header(false), watermark(false), title(false), + subTitle(false), extension(false), sideWidget(false) {} int topLevelMarginLeft; int topLevelMarginRight; @@ -238,6 +238,7 @@ public: bool title; bool subTitle; bool extension; + bool sideWidget; bool operator==(const QWizardLayoutInfo &other); inline bool operator!=(const QWizardLayoutInfo &other) { return !operator==(other); } @@ -261,7 +262,8 @@ bool QWizardLayoutInfo::operator==(const QWizardLayoutInfo &other) && watermark == other.watermark && title == other.title && subTitle == other.subTitle - && extension == other.extension; + && extension == other.extension + && sideWidget == other.sideWidget; } class QWizardHeader : public QWidget @@ -425,6 +427,40 @@ public: : QWizardHeader(Ruler, parent) {} }; +class QWatermarkLabel : public QLabel +{ +public: + QWatermarkLabel(QWidget *parent, QWidget *sideWidget) : QLabel(parent), m_sideWidget(sideWidget) { + m_layout = new QVBoxLayout(this); + if (m_sideWidget) + m_layout->addWidget(m_sideWidget); + } + + QSize minimumSizeHint() const { + if (!pixmap() && !pixmap()->isNull()) + return pixmap()->size(); + return QFrame::minimumSizeHint(); + } + + void setSideWidget(QWidget *widget) { + if (m_sideWidget == widget) + return; + if (m_sideWidget) { + m_layout->removeWidget(m_sideWidget); + m_sideWidget->hide(); + } + m_sideWidget = widget; + if (m_sideWidget) + m_layout->addWidget(m_sideWidget); + } + QWidget *sideWidget() const { + return m_sideWidget; + } +private: + QVBoxLayout *m_layout; + QWidget *m_sideWidget; +}; + class QWizardPagePrivate : public QWidgetPrivate { Q_DECLARE_PUBLIC(QWizardPage) @@ -501,6 +537,7 @@ public: inline QWizardPrivate() : start(-1) + , startSetByUser(false) , current(-1) , canContinue(false) , canFinish(false) @@ -513,6 +550,7 @@ public: , placeholderWidget2(0) , headerWidget(0) , watermarkLabel(0) + , sideWidget(0) , titleLabel(0) , subTitleLabel(0) , bottomRuler(0) @@ -581,6 +619,7 @@ public: QList<int> history; QSet<int> initialized; // ### remove and move bit to QWizardPage? int start; + bool startSetByUser; int current; bool canContinue; bool canFinish; @@ -612,7 +651,8 @@ public: QWidget *placeholderWidget1; QWidget *placeholderWidget2; QWizardHeader *headerWidget; - QLabel *watermarkLabel; + QWatermarkLabel *watermarkLabel; + QWidget *sideWidget; QFrame *pageFrame; QLabel *titleLabel; QLabel *subTitleLabel; @@ -907,11 +947,12 @@ QWizardLayoutInfo QWizardPrivate::layoutInfoForCurrentPage() info.header = (info.wizStyle == QWizard::ClassicStyle || info.wizStyle == QWizard::ModernStyle) && !(opts & QWizard::IgnoreSubTitles) && !subTitleText.isEmpty(); + info.sideWidget = sideWidget; info.watermark = (info.wizStyle != QWizard::MacStyle) && (info.wizStyle != QWizard::AeroStyle) && !watermarkPixmap.isNull(); info.title = !info.header && !titleText.isEmpty(); info.subTitle = !(opts & QWizard::IgnoreSubTitles) && !info.header && !subTitleText.isEmpty(); - info.extension = info.watermark && (opts & QWizard::ExtendedWatermarkPixmap); + info.extension = (info.watermark || info.sideWidget) && (opts & QWizard::ExtendedWatermarkPixmap); return info; } @@ -954,7 +995,7 @@ void QWizardPrivate::recreateLayout(const QWizardLayoutInfo &info) int numColumns; if (mac) { numColumns = 3; - } else if (info.watermark) { + } else if (info.watermark || info.sideWidget) { numColumns = 2; } else { numColumns = 1; @@ -1096,8 +1137,8 @@ void QWizardPrivate::recreateLayout(const QWizardLayoutInfo &info) pageFrame->setContentsMargins(hMargin, vMargin, hMargin, vMargin); } - if (info.watermark && !watermarkLabel) { - watermarkLabel = new QLabel(antiFlickerWidget); + if ((info.watermark || info.sideWidget) && !watermarkLabel) { + watermarkLabel = new QWatermarkLabel(antiFlickerWidget, sideWidget); watermarkLabel->setBackgroundRole(QPalette::Base); watermarkLabel->setMinimumHeight(1); watermarkLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); @@ -1173,7 +1214,7 @@ void QWizardPrivate::recreateLayout(const QWizardLayoutInfo &info) mainLayout->addLayout(buttonLayout, row++, buttonStartColumn, 1, buttonNumColumns); - if (info.watermark) { + if (info.watermark || info.sideWidget) { if (info.extension) watermarkEndRow = row; mainLayout->addWidget(watermarkLabel, watermarkStartRow, 0, @@ -1193,7 +1234,7 @@ void QWizardPrivate::recreateLayout(const QWizardLayoutInfo &info) if (bottomRuler) bottomRuler->setVisible(classic || modern); if (watermarkLabel) - watermarkLabel->setVisible(info.watermark); + watermarkLabel->setVisible(info.watermark || info.sideWidget); layoutInfo = info; } @@ -1233,10 +1274,17 @@ void QWizardPrivate::updateLayout() titleFmt, subTitleFmt); } - if (info.watermark) { - Q_ASSERT(page); - watermarkLabel->setPixmap(page->pixmap(QWizard::WatermarkPixmap)); + if (info.watermark || info.sideWidget) { + QPixmap pix; + if (info.watermark) { + if (page) + pix = page->pixmap(QWizard::WatermarkPixmap); + else + pix = q->pixmap(QWizard::WatermarkPixmap); + } + watermarkLabel->setPixmap(pix); // in case there is no watermark and we show the side widget we need to clear the watermark } + if (info.title) { Q_ASSERT(page); titleLabel->setTextFormat(titleFmt); @@ -1267,7 +1315,7 @@ void QWizardPrivate::updateMinMaxSizes(const QWizardLayoutInfo &info) minimumSize.setWidth(headerWidget->maximumWidth()); maximumSize.setWidth(headerWidget->maximumWidth()); } - if (info.watermark) { + if (info.watermark && !info.sideWidget) { minimumSize.setHeight(mainLayout->totalSizeHint().height()); maximumSize.setHeight(mainLayout->totalSizeHint().height()); } @@ -2149,7 +2197,7 @@ QWizard::~QWizard() The ID is guaranteed to be larger than any other ID in the QWizard so far. - \sa setPage(), page() + \sa setPage(), page(), pageAdded() */ int QWizard::addPage(QWizardPage *page) { @@ -2166,7 +2214,10 @@ int QWizard::addPage(QWizardPage *page) Adds the given \a page to the wizard with the given \a id. - \sa addPage(), page() + \note Adding a page may influence the value of the startId property + in case it was not set explicitly. + + \sa addPage(), page(), pageAdded() */ void QWizard::setPage(int theid, QWizardPage *page) { @@ -2210,12 +2261,19 @@ void QWizard::setPage(int theid, QWizardPage *page) // hide new page and reset layout to old status page->hide(); d->pageVBoxLayout->setEnabled(pageVBoxLayoutEnabled); + + if (!d->startSetByUser && d->pageMap.constBegin().key() == theid) + d->start = theid; + emit pageAdded(theid); } /*! Removes the page with the given \a id. cleanupPage() will be called if necessary. + + \note Removing a page may influence the value of the startId property. + \since 4.5 - \sa addPage(), setPage() + \sa addPage(), setPage(), pageRemoved(), startId() */ void QWizard::removePage(int id) { @@ -2223,8 +2281,24 @@ void QWizard::removePage(int id) QWizardPage *removedPage = 0; - if (d->start == id) - d->start = -1; + // update startItem accordingly + if (d->pageMap.count() > 0) { // only if we have any pages + if (d->start == id) { + const int firstId = d->pageMap.constBegin().key(); + if (firstId == id) { + if (d->pageMap.count() > 1) + d->start = (++d->pageMap.constBegin()).key(); // secondId + else + d->start = -1; // removing the last page + } else { // startSetByUser has to be "true" here + d->start = firstId; + } + d->startSetByUser = false; + } + } + + if (d->pageMap.contains(id)) + emit pageRemoved(id); if (!d->history.contains(id)) { // Case 1: removing a page not in the history @@ -2334,21 +2408,27 @@ QList<int> QWizard::pageIds() const void QWizard::setStartId(int theid) { Q_D(QWizard); - if (!d->pageMap.contains(theid)) { - qWarning("QWizard::setStartId: Invalid page ID %d", theid); + int newStart = theid; + if (theid == -1) + newStart = d->pageMap.count() ? d->pageMap.constBegin().key() : -1; + + if (d->start == newStart) { + d->startSetByUser = theid != -1; return; } - d->start = theid; + + if (!d->pageMap.contains(newStart)) { + qWarning("QWizard::setStartId: Invalid page ID %d", newStart); + return; + } + d->start = newStart; + d->startSetByUser = theid != -1; } int QWizard::startId() const { Q_D(const QWizard); - if (d->start != -1) - return d->start; - if (!d->pageMap.isEmpty()) - return d->pageMap.constBegin().key(); - return -1; + return d->start; } /*! @@ -2825,6 +2905,55 @@ void QWizard::setDefaultProperty(const char *className, const char *property, } /*! + \since 4.7 + + Sets the given \a widget to be shown on the left side of the wizard. + For styles which use the WatermarkPixmap (ClassicStyle and ModernStyle) + the side widget is displayed on top of the watermark, for other styles + or when the watermark is not provided the side widget is displayed + on the left side of the wizard. + + Passing 0 shows no side widget. + + When the \a widget is not 0 the wizard reparents it. + + Any previous side widget is hidden. + + You may call setSideWidget() with the same widget at different + times. + + All widgets set here will be deleted by the wizard when it is + destroyed unless you separately reparent the widget after setting + some other side widget (or 0). + + By default, no side widget is present. +*/ +void QWizard::setSideWidget(QWidget *widget) +{ + Q_D(QWizard); + + d->sideWidget = widget; + if (d->watermarkLabel) { + d->watermarkLabel->setSideWidget(widget); + d->updateLayout(); + } +} + +/*! + \since 4.7 + + Returns the widget on the left side of the wizard or 0. + + By default, no side widget is present. +*/ +QWidget *QWizard::sideWidget() const +{ + Q_D(const QWizard); + + return d->sideWidget; +} + +/*! \reimp */ void QWizard::setVisible(bool visible) @@ -2878,6 +3007,28 @@ QSize QWizard::sizeHint() const */ /*! + \fn void QWizard::pageAdded(int id) + + \since 4.7 + + This signal is emitted whenever a page is added to the + wizard. The page's \a id is passed as parameter. + + \sa addPage(), setPage(), startId() +*/ + +/*! + \fn void QWizard::pageRemoved(int id) + + \since 4.7 + + This signal is emitted whenever a page is removed from the + wizard. The page's \a id is passed as parameter. + + \sa removePage(), startId() +*/ + +/*! \fn void QWizard::helpRequested() This signal is emitted when the user clicks the \gui Help button. diff --git a/src/gui/dialogs/qwizard.h b/src/gui/dialogs/qwizard.h index 58b13fe..b146147 100644 --- a/src/gui/dialogs/qwizard.h +++ b/src/gui/dialogs/qwizard.h @@ -165,6 +165,9 @@ public: void setPixmap(WizardPixmap which, const QPixmap &pixmap); QPixmap pixmap(WizardPixmap which) const; + void setSideWidget(QWidget *widget); + QWidget *sideWidget() const; + void setDefaultProperty(const char *className, const char *property, const char *changedSignal); @@ -175,6 +178,8 @@ Q_SIGNALS: void currentIdChanged(int id); void helpRequested(); void customButtonClicked(int which); + void pageAdded(int id); + void pageRemoved(int id); public Q_SLOTS: void back(); diff --git a/src/gui/dialogs/qwizard_win_p.h b/src/gui/dialogs/qwizard_win_p.h index fe01587..5f3b6c2 100644 --- a/src/gui/dialogs/qwizard_win_p.h +++ b/src/gui/dialogs/qwizard_win_p.h @@ -82,7 +82,6 @@ class QWizard; class QVistaHelper : public QObject { - Q_OBJECT public: QVistaHelper(QWizard *wizard); ~QVistaHelper(); |