diff options
author | Alexis Menard <alexis.menard@nokia.com> | 2009-05-12 12:45:32 (GMT) |
---|---|---|
committer | Alexis Menard <alexis.menard@nokia.com> | 2009-05-12 12:45:32 (GMT) |
commit | 1898c46452beae9e28cf9be7851099b4b4d2779e (patch) | |
tree | 00477e689bf1bd867fb3428476029b47817a9db8 /src/gui | |
parent | f15b8a83e2e51955776a3f07cb85ebfc342dd8ef (diff) | |
parent | 4d5a5149b716c67f031a3a40e23370f90542c92f (diff) | |
download | Qt-1898c46452beae9e28cf9be7851099b4b4d2779e.zip Qt-1898c46452beae9e28cf9be7851099b4b4d2779e.tar.gz Qt-1898c46452beae9e28cf9be7851099b4b4d2779e.tar.bz2 |
Merge branch '4.5' of git@scm.dev.nokia.troll.no:qt/qt into kinetic-statemachine
Conflicts:
src/gui/graphicsview/qgraphicsitem.cpp
Diffstat (limited to 'src/gui')
182 files changed, 5467 insertions, 3614 deletions
diff --git a/src/gui/accessible/qaccessible_mac.mm b/src/gui/accessible/qaccessible_mac.mm index b6412c2..68efb8f 100644 --- a/src/gui/accessible/qaccessible_mac.mm +++ b/src/gui/accessible/qaccessible_mac.mm @@ -72,55 +72,36 @@ typedef NSString * const QAXRoleType; #define QAXApplicationRole NSAccessibilityApplicationRole #define QAXButtonRole NSAccessibilityButtonRole #define QAXCancelAction NSAccessibilityCancelAction -#define QAXCancelAction NSAccessibilityCancelAction #define QAXCheckBoxRole NSAccessibilityCheckBoxRole #define QAXChildrenAttribute NSAccessibilityChildrenAttribute -#define QAXChildrenAttribute NSAccessibilityChildrenAttribute -#define QAXChildrenAttribute NSAccessibilityChildrenAttribute #define QAXCloseButtonAttribute NSAccessibilityCloseButtonAttribute #define QAXCloseButtonAttribute NSAccessibilityCloseButtonAttribute #define QAXColumnRole NSAccessibilityColumnRole #define QAXConfirmAction NSAccessibilityConfirmAction -#define QAXConfirmAction NSAccessibilityConfirmAction #define QAXContentsAttribute NSAccessibilityContentsAttribute -#define QAXContentsAttribute NSAccessibilityContentsAttribute -#define QAXDecrementAction NSAccessibilityDecrementAction #define QAXDecrementAction NSAccessibilityDecrementAction #define QAXDecrementArrowSubrole NSAccessibilityDecrementArrowSubrole #define QAXDecrementPageSubrole NSAccessibilityDecrementPageSubrole #define QAXDescriptionAttribute NSAccessibilityDescriptionAttribute -#define QAXDescriptionAttribute NSAccessibilityDescriptionAttribute -#define QAXDescriptionAttribute NSAccessibilityDescriptionAttribute -#define QAXDescriptionAttribute NSAccessibilityDescriptionAttribute -#define QAXEnabledAttribute NSAccessibilityEnabledAttribute #define QAXEnabledAttribute NSAccessibilityEnabledAttribute #define QAXExpandedAttribute NSAccessibilityExpandedAttribute #define QAXFocusedAttribute NSAccessibilityFocusedAttribute -#define QAXFocusedAttribute NSAccessibilityFocusedAttribute -#define QAXFocusedAttribute NSAccessibilityFocusedAttribute #define QAXFocusedUIElementChangedNotification NSAccessibilityFocusedUIElementChangedNotification #define QAXFocusedWindowChangedNotification NSAccessibilityFocusedWindowChangedNotification #define QAXGroupRole NSAccessibilityGroupRole #define QAXGrowAreaAttribute NSAccessibilityGrowAreaAttribute -#define QAXGrowAreaAttribute NSAccessibilityGrowAreaAttribute #define QAXGrowAreaRole NSAccessibilityGrowAreaRole #define QAXHelpAttribute NSAccessibilityHelpAttribute -#define QAXHelpAttribute NSAccessibilityHelpAttribute -#define QAXHelpAttribute NSAccessibilityHelpAttribute #define QAXHorizontalOrientationValue NSAccessibilityHorizontalOrientationValue #define QAXHorizontalScrollBarAttribute NSAccessibilityHorizontalScrollBarAttribute -#define QAXHorizontalScrollBarAttribute NSAccessibilityHorizontalScrollBarAttribute -#define QAXIncrementAction NSAccessibilityIncrementAction #define QAXIncrementAction NSAccessibilityIncrementAction #define QAXIncrementArrowSubrole NSAccessibilityIncrementArrowSubrole #define QAXIncrementPageSubrole NSAccessibilityIncrementPageSubrole #define QAXIncrementorRole NSAccessibilityIncrementorRole #define QAXLinkedUIElementsAttribute NSAccessibilityLinkedUIElementsAttribute -#define QAXLinkedUIElementsAttribute NSAccessibilityLinkedUIElementsAttribute #define QAXListRole NSAccessibilityListRole #define QAXMainAttribute NSAccessibilityMainAttribute #define QAXMaxValueAttribute NSAccessibilityMaxValueAttribute -#define QAXMaxValueAttribute NSAccessibilityMaxValueAttribute #define QAXMenuBarRole NSAccessibilityMenuBarRole #define QAXMenuButtonRole NSAccessibilityMenuButtonRole #define QAXMenuClosedNotification NSAccessibilityMenuClosedNotification @@ -128,151 +109,90 @@ typedef NSString * const QAXRoleType; #define QAXMenuOpenedNotification NSAccessibilityMenuOpenedNotification #define QAXMenuRole NSAccessibilityMenuRole #define QAXMinValueAttribute NSAccessibilityMinValueAttribute -#define QAXMinValueAttribute NSAccessibilityMinValueAttribute #define QAXMinimizeButtonAttribute NSAccessibilityMinimizeButtonAttribute -#define QAXMinimizeButtonAttribute NSAccessibilityMinimizeButtonAttribute -#define QAXMinimizedAttribute NSAccessibilityMinimizedAttribute #define QAXMinimizedAttribute NSAccessibilityMinimizedAttribute #define QAXNextContentsAttribute NSAccessibilityNextContentsAttribute -#define QAXNextContentsAttribute NSAccessibilityNextContentsAttribute -#define QAXOrientationAttribute NSAccessibilityOrientationAttribute -#define QAXOrientationAttribute NSAccessibilityOrientationAttribute #define QAXOrientationAttribute NSAccessibilityOrientationAttribute #define QAXParentAttribute NSAccessibilityParentAttribute #define QAXPickAction NSAccessibilityPickAction -#define QAXPickAction NSAccessibilityPickAction #define QAXPopUpButtonRole NSAccessibilityPopUpButtonRole #define QAXPositionAttribute NSAccessibilityPositionAttribute -#define QAXPositionAttribute NSAccessibilityPositionAttribute -#define QAXPressAction NSAccessibilityPressAction #define QAXPressAction NSAccessibilityPressAction #define QAXPreviousContentsAttribute NSAccessibilityPreviousContentsAttribute -#define QAXPreviousContentsAttribute NSAccessibilityPreviousContentsAttribute -#define QAXPreviousContentsAttribute NSAccessibilityPreviousContentsAttribute #define QAXProgressIndicatorRole NSAccessibilityProgressIndicatorRole #define QAXRadioButtonRole NSAccessibilityRadioButtonRole #define QAXRoleAttribute NSAccessibilityRoleAttribute -#define QAXRoleAttribute NSAccessibilityRoleAttribute #define QAXRoleDescriptionAttribute NSAccessibilityRoleDescriptionAttribute #define QAXRowRole NSAccessibilityRowRole #define QAXRowsAttribute NSAccessibilityRowsAttribute -#define QAXRowsAttribute NSAccessibilityRowsAttribute -#define QAXScrollAreaRole NSAccessibilityScrollAreaRole -#define QAXScrollAreaRole NSAccessibilityScrollAreaRole #define QAXScrollAreaRole NSAccessibilityScrollAreaRole #define QAXScrollBarRole NSAccessibilityScrollBarRole #define QAXSelectedAttribute NSAccessibilitySelectedAttribute #define QAXSelectedChildrenAttribute NSAccessibilitySelectedChildrenAttribute #define QAXSelectedRowsAttribute NSAccessibilitySelectedRowsAttribute -#define QAXSelectedRowsAttribute NSAccessibilitySelectedRowsAttribute -#define QAXSizeAttribute NSAccessibilitySizeAttribute #define QAXSizeAttribute NSAccessibilitySizeAttribute #define QAXSliderRole NSAccessibilitySliderRole #define QAXSplitGroupRole NSAccessibilitySplitGroupRole #define QAXSplitterRole NSAccessibilitySplitterRole -#define QAXSplitterRole NSAccessibilitySplitterRole -#define QAXSplitterRole NSAccessibilitySplitterRole -#define QAXSplittersAttribute NSAccessibilitySplittersAttribute #define QAXSplittersAttribute NSAccessibilitySplittersAttribute #define QAXStaticTextRole NSAccessibilityStaticTextRole -#define QAXStaticTextRole NSAccessibilityStaticTextRole -#define QAXSubroleAttribute NSAccessibilitySubroleAttribute #define QAXSubroleAttribute NSAccessibilitySubroleAttribute #define QAXSubroleAttribute NSAccessibilitySubroleAttribute #define QAXTabGroupRole NSAccessibilityTabGroupRole -#define QAXTabGroupRole NSAccessibilityTabGroupRole #define QAXTableRole NSAccessibilityTableRole #define QAXTabsAttribute NSAccessibilityTabsAttribute -#define QAXTabsAttribute NSAccessibilityTabsAttribute #define QAXTextFieldRole NSAccessibilityTextFieldRole -#define QAXTextFieldRole NSAccessibilityTextFieldRole -#define QAXTitleAttribute NSAccessibilityTitleAttribute -#define QAXTitleAttribute NSAccessibilityTitleAttribute #define QAXTitleAttribute NSAccessibilityTitleAttribute -#define QAXTitleAttribute NSAccessibilityTitleAttribute -#define QAXTitleUIElementAttribute NSAccessibilityTitleUIElementAttribute #define QAXTitleUIElementAttribute NSAccessibilityTitleUIElementAttribute #define QAXToolbarButtonAttribute NSAccessibilityToolbarButtonAttribute -#define QAXToolbarButtonAttribute NSAccessibilityToolbarButtonAttribute #define QAXToolbarRole NSAccessibilityToolbarRole #define QAXTopLevelUIElementAttribute NSAccessibilityTopLevelUIElementAttribute -#define QAXTopLevelUIElementAttribute NSAccessibilityTopLevelUIElementAttribute -#define QAXTopLevelUIElementAttribute NSAccessibilityTopLevelUIElementAttribute -#define QAXUnknownRole NSAccessibilityUnknownRole #define QAXUnknownRole NSAccessibilityUnknownRole #define QAXValueAttribute NSAccessibilityValueAttribute -#define QAXValueAttribute NSAccessibilityValueAttribute -#define QAXValueAttribute NSAccessibilityValueAttribute -#define QAXValueAttribute NSAccessibilityValueAttribute #define QAXValueChangedNotification NSAccessibilityValueChangedNotification #define QAXValueIndicatorRole NSAccessibilityValueIndicatorRole #define QAXVerticalOrientationValue NSAccessibilityVerticalOrientationValue #define QAXVerticalScrollBarAttribute NSAccessibilityVerticalScrollBarAttribute -#define QAXVerticalScrollBarAttribute NSAccessibilityVerticalScrollBarAttribute #define QAXVisibleRowsAttribute NSAccessibilityVisibleRowsAttribute -#define QAXVisibleRowsAttribute NSAccessibilityVisibleRowsAttribute -#define QAXWindowAttribute NSAccessibilityWindowAttribute -#define QAXWindowAttribute NSAccessibilityWindowAttribute #define QAXWindowAttribute NSAccessibilityWindowAttribute #define QAXWindowCreatedNotification NSAccessibilityWindowCreatedNotification #define QAXWindowMovedNotification NSAccessibilityWindowMovedNotification #define QAXWindowRole NSAccessibilityWindowRole #define QAXZoomButtonAttribute NSAccessibilityZoomButtonAttribute -#define QAXZoomButtonAttribute NSAccessibilityZoomButtonAttribute #else typedef CFStringRef const QAXRoleType; #define QAXApplicationRole kAXApplicationRole #define QAXButtonRole kAXButtonRole #define QAXCancelAction kAXCancelAction -#define QAXCancelAction kAXCancelAction #define QAXCheckBoxRole kAXCheckBoxRole #define QAXChildrenAttribute kAXChildrenAttribute -#define QAXChildrenAttribute kAXChildrenAttribute -#define QAXChildrenAttribute kAXChildrenAttribute -#define QAXCloseButtonAttribute kAXCloseButtonAttribute #define QAXCloseButtonAttribute kAXCloseButtonAttribute #define QAXColumnRole kAXColumnRole #define QAXConfirmAction kAXConfirmAction -#define QAXConfirmAction kAXConfirmAction #define QAXContentsAttribute kAXContentsAttribute -#define QAXContentsAttribute kAXContentsAttribute -#define QAXDecrementAction kAXDecrementAction #define QAXDecrementAction kAXDecrementAction #define QAXDecrementArrowSubrole kAXDecrementArrowSubrole #define QAXDecrementPageSubrole kAXDecrementPageSubrole #define QAXDescriptionAttribute kAXDescriptionAttribute -#define QAXDescriptionAttribute kAXDescriptionAttribute -#define QAXDescriptionAttribute kAXDescriptionAttribute -#define QAXDescriptionAttribute kAXDescriptionAttribute -#define QAXEnabledAttribute kAXEnabledAttribute #define QAXEnabledAttribute kAXEnabledAttribute #define QAXExpandedAttribute kAXExpandedAttribute #define QAXFocusedAttribute kAXFocusedAttribute -#define QAXFocusedAttribute kAXFocusedAttribute -#define QAXFocusedAttribute kAXFocusedAttribute #define QAXFocusedUIElementChangedNotification kAXFocusedUIElementChangedNotification #define QAXFocusedWindowChangedNotification kAXFocusedWindowChangedNotification #define QAXGroupRole kAXGroupRole #define QAXGrowAreaAttribute kAXGrowAreaAttribute -#define QAXGrowAreaAttribute kAXGrowAreaAttribute #define QAXGrowAreaRole kAXGrowAreaRole #define QAXHelpAttribute kAXHelpAttribute -#define QAXHelpAttribute kAXHelpAttribute -#define QAXHelpAttribute kAXHelpAttribute #define QAXHorizontalOrientationValue kAXHorizontalOrientationValue #define QAXHorizontalScrollBarAttribute kAXHorizontalScrollBarAttribute -#define QAXHorizontalScrollBarAttribute kAXHorizontalScrollBarAttribute -#define QAXIncrementAction kAXIncrementAction #define QAXIncrementAction kAXIncrementAction #define QAXIncrementArrowSubrole kAXIncrementArrowSubrole #define QAXIncrementPageSubrole kAXIncrementPageSubrole #define QAXIncrementorRole kAXIncrementorRole #define QAXLinkedUIElementsAttribute kAXLinkedUIElementsAttribute -#define QAXLinkedUIElementsAttribute kAXLinkedUIElementsAttribute #define QAXListRole kAXListRole #define QAXMainAttribute kAXMainAttribute #define QAXMaxValueAttribute kAXMaxValueAttribute -#define QAXMaxValueAttribute kAXMaxValueAttribute #define QAXMenuBarRole kAXMenuBarRole #define QAXMenuButtonRole kAXMenuButtonRole #define QAXMenuClosedNotification kAXMenuClosedNotification @@ -280,97 +200,55 @@ typedef CFStringRef const QAXRoleType; #define QAXMenuOpenedNotification kAXMenuOpenedNotification #define QAXMenuRole kAXMenuRole #define QAXMinValueAttribute kAXMinValueAttribute -#define QAXMinValueAttribute kAXMinValueAttribute #define QAXMinimizeButtonAttribute kAXMinimizeButtonAttribute -#define QAXMinimizeButtonAttribute kAXMinimizeButtonAttribute -#define QAXMinimizedAttribute kAXMinimizedAttribute #define QAXMinimizedAttribute kAXMinimizedAttribute #define QAXNextContentsAttribute kAXNextContentsAttribute -#define QAXNextContentsAttribute kAXNextContentsAttribute -#define QAXOrientationAttribute kAXOrientationAttribute -#define QAXOrientationAttribute kAXOrientationAttribute #define QAXOrientationAttribute kAXOrientationAttribute #define QAXParentAttribute kAXParentAttribute #define QAXPickAction kAXPickAction -#define QAXPickAction kAXPickAction #define QAXPopUpButtonRole kAXPopUpButtonRole #define QAXPositionAttribute kAXPositionAttribute -#define QAXPositionAttribute kAXPositionAttribute -#define QAXPressAction kAXPressAction #define QAXPressAction kAXPressAction #define QAXPreviousContentsAttribute kAXPreviousContentsAttribute -#define QAXPreviousContentsAttribute kAXPreviousContentsAttribute -#define QAXPreviousContentsAttribute kAXPreviousContentsAttribute #define QAXProgressIndicatorRole kAXProgressIndicatorRole #define QAXRadioButtonRole kAXRadioButtonRole #define QAXRoleAttribute kAXRoleAttribute -#define QAXRoleAttribute kAXRoleAttribute #define QAXRoleDescriptionAttribute kAXRoleDescriptionAttribute #define QAXRowRole kAXRowRole #define QAXRowsAttribute kAXRowsAttribute -#define QAXRowsAttribute kAXRowsAttribute -#define QAXScrollAreaRole kAXScrollAreaRole -#define QAXScrollAreaRole kAXScrollAreaRole #define QAXScrollAreaRole kAXScrollAreaRole #define QAXScrollBarRole kAXScrollBarRole #define QAXSelectedAttribute kAXSelectedAttribute #define QAXSelectedChildrenAttribute kAXSelectedChildrenAttribute #define QAXSelectedRowsAttribute kAXSelectedRowsAttribute -#define QAXSelectedRowsAttribute kAXSelectedRowsAttribute -#define QAXSizeAttribute kAXSizeAttribute #define QAXSizeAttribute kAXSizeAttribute #define QAXSliderRole kAXSliderRole #define QAXSplitGroupRole kAXSplitGroupRole #define QAXSplitterRole kAXSplitterRole -#define QAXSplitterRole kAXSplitterRole -#define QAXSplitterRole kAXSplitterRole -#define QAXSplittersAttribute kAXSplittersAttribute #define QAXSplittersAttribute kAXSplittersAttribute #define QAXStaticTextRole kAXStaticTextRole -#define QAXStaticTextRole kAXStaticTextRole -#define QAXSubroleAttribute kAXSubroleAttribute #define QAXSubroleAttribute kAXSubroleAttribute -#define QAXSubroleAttribute kAXSubroleAttribute -#define QAXTabGroupRole kAXTabGroupRole #define QAXTabGroupRole kAXTabGroupRole #define QAXTableRole kAXTableRole #define QAXTabsAttribute kAXTabsAttribute -#define QAXTabsAttribute kAXTabsAttribute -#define QAXTextFieldRole kAXTextFieldRole #define QAXTextFieldRole kAXTextFieldRole #define QAXTitleAttribute kAXTitleAttribute -#define QAXTitleAttribute kAXTitleAttribute -#define QAXTitleAttribute kAXTitleAttribute -#define QAXTitleAttribute kAXTitleAttribute #define QAXTitleUIElementAttribute kAXTitleUIElementAttribute -#define QAXTitleUIElementAttribute kAXTitleUIElementAttribute -#define QAXToolbarButtonAttribute kAXToolbarButtonAttribute #define QAXToolbarButtonAttribute kAXToolbarButtonAttribute #define QAXToolbarRole kAXToolbarRole #define QAXTopLevelUIElementAttribute kAXTopLevelUIElementAttribute -#define QAXTopLevelUIElementAttribute kAXTopLevelUIElementAttribute -#define QAXTopLevelUIElementAttribute kAXTopLevelUIElementAttribute #define QAXUnknownRole kAXUnknownRole -#define QAXUnknownRole kAXUnknownRole -#define QAXValueAttribute kAXValueAttribute -#define QAXValueAttribute kAXValueAttribute -#define QAXValueAttribute kAXValueAttribute #define QAXValueAttribute kAXValueAttribute #define QAXValueChangedNotification kAXValueChangedNotification #define QAXValueIndicatorRole kAXValueIndicatorRole #define QAXVerticalOrientationValue kAXVerticalOrientationValue #define QAXVerticalScrollBarAttribute kAXVerticalScrollBarAttribute -#define QAXVerticalScrollBarAttribute kAXVerticalScrollBarAttribute -#define QAXVisibleRowsAttribute kAXVisibleRowsAttribute #define QAXVisibleRowsAttribute kAXVisibleRowsAttribute #define QAXWindowAttribute kAXWindowAttribute -#define QAXWindowAttribute kAXWindowAttribute -#define QAXWindowAttribute kAXWindowAttribute #define QAXWindowCreatedNotification kAXWindowCreatedNotification #define QAXWindowMovedNotification kAXWindowMovedNotification #define QAXWindowRole kAXWindowRole #define QAXZoomButtonAttribute kAXZoomButtonAttribute -#define QAXZoomButtonAttribute kAXZoomButtonAttribute #endif diff --git a/src/gui/accessible/qaccessiblewidget.cpp b/src/gui/accessible/qaccessiblewidget.cpp index 4b2b2ab..753ac57 100644 --- a/src/gui/accessible/qaccessiblewidget.cpp +++ b/src/gui/accessible/qaccessiblewidget.cpp @@ -131,9 +131,16 @@ QString Q_GUI_EXPORT qt_accHotKey(const QString &text) int fa = 0; QChar ac; while ((fa = text.indexOf(QLatin1Char('&'), fa)) != -1) { - if (fa == text.length() - 1 || text.at(fa+1) != QLatin1Char('&')) { - ac = text.at(fa+1); - break; + ++fa; + if (fa < text.length()) { + // ignore "&&" + if (text.at(fa) == QLatin1Char('&')) { + ++fa; + continue; + } else { + ac = text.at(fa); + break; + } } } if (ac.isNull()) diff --git a/src/gui/dialogs/qabstractprintdialog.cpp b/src/gui/dialogs/qabstractprintdialog.cpp index 0dc16c9..5ed8852 100644 --- a/src/gui/dialogs/qabstractprintdialog.cpp +++ b/src/gui/dialogs/qabstractprintdialog.cpp @@ -400,7 +400,7 @@ void QAbstractPrintDialogPrivate::setPrinter(QPrinter *newPrinter) QAbstractPrintDialog::setEnabledOptions() and QAbstractPrintDialog::addEnabledOption() have no effect. - In Qt 4.4, it was possible to use the satic functions to show a sheet on + In Qt 4.4, it was possible to use the static functions to show a sheet on Mac OS X. This is no longer supported in Qt 4.5. If you want this functionality, use QPrintDialog::open(). diff --git a/src/gui/dialogs/qcolordialog.cpp b/src/gui/dialogs/qcolordialog.cpp index b744dca..3aa04f6 100644 --- a/src/gui/dialogs/qcolordialog.cpp +++ b/src/gui/dialogs/qcolordialog.cpp @@ -1523,10 +1523,10 @@ static const Qt::WindowFlags DefaultWindowFlags = If you require a modeless dialog, use the QColorDialog constructor. \endomit - The static getColor() function shows the dialog, and allows the - user to specify a color. The getRgba() function does the same, but - also allows the user to specify a color with an alpha channel - (transparency) value. + The static getColor() function shows the dialog, and allows the user to + specify a color. This function can also be used to let users choose a + color with a level of transparency: pass the ShowAlphaChannel option as + an additional argument. The user can store customCount() different custom colors. The custom colors are shared by all color dialogs, and remembered diff --git a/src/gui/dialogs/qfiledialog.cpp b/src/gui/dialogs/qfiledialog.cpp index 9a03f2d..eeb2743 100644 --- a/src/gui/dialogs/qfiledialog.cpp +++ b/src/gui/dialogs/qfiledialog.cpp @@ -96,9 +96,8 @@ Q_GUI_EXPORT _qt_filedialog_save_filename_hook qt_filedialog_save_filename_hook order to select one or many files or a directory. The easiest way to create a QFileDialog is to use the static - functions. On Windows, these static functions will call the native - Windows file dialog, and on Mac OS X these static function will call - the native Mac OS X file dialog. + functions. On Windows, Mac OS X, KDE and GNOME, these static functions will + call the native file dialog when possible. \snippet doc/src/snippets/code/src_gui_dialogs_qfiledialog.cpp 0 @@ -216,7 +215,7 @@ Q_GUI_EXPORT _qt_filedialog_save_filename_hook qt_filedialog_save_filename_hook are resolved. \value DontConfirmOverwrite Don't ask for confirmation if an existing file is selected. By default confirmation is requested. - \value DontUseNativeDialog Don't use the native file dialog. By default on Mac OS X and Windows, + \value DontUseNativeDialog Don't use the native file dialog. By default on Mac OS X, the native file dialog is used unless you use a subclass of QFileDialog that contains the Q_OBJECT macro. \value ReadOnly Indicates that the model is readonly. @@ -693,7 +692,10 @@ void QFileDialog::setVisible(bool visible) */ void QFileDialogPrivate::_q_goToUrl(const QUrl &url) { - QModelIndex idx = model->index(url.toLocalFile()); + //The shortcut in the side bar may have a parent that is not fetched yet (e.g. an hidden file) + //so we force the fetching + QFileSystemModelPrivate::QFileSystemNode *node = model->d_func()->node(url.toLocalFile(), true); + QModelIndex idx = model->d_func()->index(node); _q_enterDirectory(idx); } @@ -780,6 +782,13 @@ void QFileDialog::selectFile(const QString &filename) if (QFileInfo(filename).isAbsolute()) { QString current = d->rootPath(); text.remove(current); + if (text.at(0) == QDir::separator() +#ifdef Q_OS_WIN + //On Windows both cases can happen + || text.at(0) == QLatin1Char('/') +#endif + ) + text = text.remove(0,1); } if (!isVisible() || !d->lineEdit()->hasFocus()) d->lineEdit()->setText(text); @@ -950,25 +959,29 @@ void QFileDialog::setNameFilters(const QStringList &filters) { Q_D(QFileDialog); d->defaultFileTypes = (filters == QStringList(QFileDialog::tr("All Files (*)"))); - d->nameFilters = filters; + QStringList cleanedFilters; + for (int i = 0; i < filters.count(); ++i) { + cleanedFilters << filters[i].simplified(); + } + d->nameFilters = cleanedFilters; if (d->nativeDialogInUse){ - d->setNameFilters_sys(filters); + d->setNameFilters_sys(cleanedFilters); return; } d->qFileDialogUi->fileTypeCombo->clear(); - if (filters.isEmpty()) + if (cleanedFilters.isEmpty()) return; if (testOption(HideNameFilterDetails)) { QStringList strippedFilters; - for (int i = 0; i < filters.count(); ++i) { - strippedFilters.append(filters[i].mid(0, filters[i].indexOf(QLatin1String(" (")))); + for (int i = 0; i < cleanedFilters.count(); ++i) { + strippedFilters.append(cleanedFilters[i].mid(0, cleanedFilters[i].indexOf(QLatin1String(" (")))); } d->qFileDialogUi->fileTypeCombo->addItems(strippedFilters); } else { - d->qFileDialogUi->fileTypeCombo->addItems(filters); + d->qFileDialogUi->fileTypeCombo->addItems(cleanedFilters); } d->_q_useNameFilter(0); } @@ -1426,6 +1439,8 @@ void QFileDialog::setIconProvider(QFileIconProvider *provider) { Q_D(QFileDialog); d->model->setIconProvider(provider); + //It forces the refresh of all entries in the side bar, then we can get new icons + d->qFileDialogUi->sidebar->setUrls(d->qFileDialogUi->sidebar->urls()); } /*! @@ -1522,52 +1537,51 @@ extern QString qt_win_get_existing_directory(const QFileDialogArgs &args); #endif /*! - This is a convenience static function that returns an existing file - selected by the user. If the user presses Cancel, it returns a null - string. + This is a convenience static function that returns an existing file + selected by the user. If the user presses Cancel, it returns a null string. - \snippet doc/src/snippets/code/src_gui_dialogs_qfiledialog.cpp 8 + \snippet doc/src/snippets/code/src_gui_dialogs_qfiledialog.cpp 8 - The function creates a modal file dialog with the given \a parent widget. - If the parent is not 0, the dialog will be shown centered over the - parent widget. + The function creates a modal file dialog with the given \a parent widget. + If \a parent is not 0, the dialog will be shown centered over the parent + widget. - The file dialog's working directory will be set to \a dir. If \a - dir includes a file name, the file will be selected. Only files - that match the given \a filter are shown. The filter selected is - set to \a selectedFilter. The parameters \a dir, \a - selectedFilter, and \a filter may be empty strings. If you want - multiple filters, separate them with ';;', for example: + The file dialog's working directory will be set to \a dir. If \a dir + includes a file name, the file will be selected. Only files that match the + given \a filter are shown. The filter selected is set to \a selectedFilter. + The parameters \a dir, \a selectedFilter, and \a filter may be empty + strings. If you want multiple filters, separate them with ';;', for + example: - \code + \code "Images (*.png *.xpm *.jpg);;Text files (*.txt);;XML files (*.xml)" - \endcode + \endcode - The \a options argument holds various - options about how to run the dialog, see the QFileDialog::Option enum for - more information on the flags you can pass. + The \a options argument holds various options about how to run the dialog, + see the QFileDialog::Option enum for more information on the flags you can + pass. - The dialog's caption is set to \a caption. If \a caption is not - specified then a default caption will be used. + The dialog's caption is set to \a caption. If \a caption is not specified + then a default caption will be used. - Under Windows and Mac OS X, this static function will use the native - file dialog and not a QFileDialog. + On Windows and Mac OS X, this static function will use the native file + dialog and not a QFileDialog. - Note that on Windows the dialog will spin a blocking modal event loop - that will not dispatch any QTimers, and if parent is not 0 then it will - position the dialog just under the parent's title bar. + On Windows the dialog will spin a blocking modal event loop that will not + dispatch any QTimers, and if \a parent is not 0 then it will position the + dialog just below the parent's title bar. - Under Unix/X11, the normal behavior of the file dialog is to resolve - and follow symlinks. For example, if \c{/usr/tmp} is a symlink to - \c{/var/tmp}, the file dialog will change to \c{/var/tmp} after - entering \c{/usr/tmp}. If \a options includes DontResolveSymlinks, - the file dialog will treat symlinks as regular directories. + On Unix/X11, the normal behavior of the file dialog is to resolve and + follow symlinks. For example, if \c{/usr/tmp} is a symlink to \c{/var/tmp}, + the file dialog will change to \c{/var/tmp} after entering \c{/usr/tmp}. If + \a options includes DontResolveSymlinks, the file dialog will treat + symlinks as regular directories. - \warning Do not delete \a parent during the execution of the dialog. - If you want to do this, you should create the dialog - yourself using one of the QFileDialog constructors. + \warning Do not delete \a parent during the execution of the dialog. If you + want to do this, you should create the dialog yourself using one of the + QFileDialog constructors. - \sa getOpenFileNames(), getSaveFileName(), getExistingDirectory() + \sa getOpenFileNames(), getSaveFileName(), getExistingDirectory() */ QString QFileDialog::getOpenFileName(QWidget *parent, const QString &caption, @@ -1582,7 +1596,12 @@ QString QFileDialog::getOpenFileName(QWidget *parent, args.parent = parent; args.caption = caption; args.directory = QFileDialogPrivate::workingDirectory(dir); - args.selection = QFileDialogPrivate::initialSelection(dir); + //If workingDirectory returned a different path than the initial one, + //it means that the initial path was invalid. There is no point to try select a file + if (args.directory != QFileInfo(dir).path()) + args.selection = QString(); + else + args.selection = QFileDialogPrivate::initialSelection(dir); args.filter = filter; args.mode = ExistingFile; args.options = options; @@ -1605,54 +1624,53 @@ QString QFileDialog::getOpenFileName(QWidget *parent, } /*! - This is a convenience static function that will return one or more - existing files selected by the user. + This is a convenience static function that will return one or more existing + files selected by the user. - \snippet doc/src/snippets/code/src_gui_dialogs_qfiledialog.cpp 9 + \snippet doc/src/snippets/code/src_gui_dialogs_qfiledialog.cpp 9 - This function creates a modal file dialog with the given \a parent - widget. If the parent is not 0, the dialog will be shown centered - over the parent widget. + This function creates a modal file dialog with the given \a parent widget. + If \a parent is not 0, the dialog will be shown centered over the parent + widget. - The file dialog's working directory will be set to \a dir. If \a - dir includes a file name, the file will be selected. The filter - is set to \a filter so that only those files which match the filter - are shown. The filter selected is set to \a selectedFilter. The parameters - \a dir, \a selectedFilter and \a filter may be empty strings. If you - need multiple filters, separate them with ';;', for instance: + The file dialog's working directory will be set to \a dir. If \a dir + includes a file name, the file will be selected. The filter is set to + \a filter so that only those files which match the filter are shown. The + filter selected is set to \a selectedFilter. The parameters \a dir, + \a selectedFilter and \a filter may be empty strings. If you need multiple + filters, separate them with ';;', for instance: - \code + \code "Images (*.png *.xpm *.jpg);;Text files (*.txt);;XML files (*.xml)" - \endcode + \endcode - The dialog's caption is set to \a caption. If \a caption is not - specified then a default caption will be used. + The dialog's caption is set to \a caption. If \a caption is not specified + then a default caption will be used. - Under Windows and Mac OS X, this static function will use the native - file dialog and not a QFileDialog. On Mac OS X, the \a dir argument - is ignored, the native dialog always displays the last visited directory. + On Windows and Mac OS X, this static function will use the native file + dialog and not a QFileDialog. - Note that on Windows the dialog will spin a blocking modal event loop - that will not dispatch any QTimers, and if parent is not 0 then it will - position the dialog just under the parent's title bar. + On Windows the dialog will spin a blocking modal event loop that will not + dispatch any QTimers, and if \a parent is not 0 then it will position the + dialog just below the parent's title bar. - Under Unix/X11, the normal behavior of the file dialog is to resolve - and follow symlinks. For example, if \c{/usr/tmp} is a symlink to - \c{/var/tmp}, the file dialog will change to \c{/var/tmp} after - entering \c{/usr/tmp}. The \a options argument holds various - options about how to run the dialog, see the QFileDialog::Option enum for - more information on the flags you can pass. + On Unix/X11, the normal behavior of the file dialog is to resolve and + follow symlinks. For example, if \c{/usr/tmp} is a symlink to \c{/var/tmp}, + the file dialog will change to \c{/var/tmp} after entering \c{/usr/tmp}. + The \a options argument holds various options about how to run the dialog, + see the QFileDialog::Option enum for more information on the flags you can + pass. - Note that if you want to iterate over the list of files, you should - iterate over a copy. For example: + \note If you want to iterate over the list of files, you should iterate + over a copy. For example: \snippet doc/src/snippets/code/src_gui_dialogs_qfiledialog.cpp 10 - \warning Do not delete \a parent during the execution of the dialog. - If you want to do this, you should create the dialog - yourself using one of the QFileDialog constructors. + \warning Do not delete \a parent during the execution of the dialog. If you + want to do this, you should create the dialog yourself using one of the + QFileDialog constructors. - \sa getOpenFileName(), getSaveFileName(), getExistingDirectory() + \sa getOpenFileName(), getSaveFileName(), getExistingDirectory() */ QStringList QFileDialog::getOpenFileNames(QWidget *parent, const QString &caption, @@ -1667,7 +1685,12 @@ QStringList QFileDialog::getOpenFileNames(QWidget *parent, args.parent = parent; args.caption = caption; args.directory = QFileDialogPrivate::workingDirectory(dir); - args.selection = QFileDialogPrivate::initialSelection(dir); + //If workingDirectory returned a different path than the initial one, + //it means that the initial path was invalid. There is no point to try select a file + if (args.directory != QFileInfo(dir).path()) + args.selection = QString(); + else + args.selection = QFileDialogPrivate::initialSelection(dir); args.filter = filter; args.mode = ExistingFiles; args.options = options; @@ -1691,54 +1714,54 @@ QStringList QFileDialog::getOpenFileNames(QWidget *parent, } /*! - This is a convenience static function that will return a file name - selected by the user. The file does not have to exist. + This is a convenience static function that will return a file name selected + by the user. The file does not have to exist. - It creates a modal file dialog with the given \a parent widget. If the - parent is not 0, the dialog will be shown centered over the parent - widget. + It creates a modal file dialog with the given \a parent widget. If + \a parent is not 0, the dialog will be shown centered over the parent + widget. - \snippet doc/src/snippets/code/src_gui_dialogs_qfiledialog.cpp 11 + \snippet doc/src/snippets/code/src_gui_dialogs_qfiledialog.cpp 11 - The file dialog's working directory will be set to \a dir. If \a - dir includes a file name, the file will be selected. Only files that - match the \a filter are shown. The filter selected is set to - \a selectedFilter. The parameters \a dir, \a selectedFilter, and - \a filter may be empty strings. Multiple filters are separated with ';;'. - For instance: + The file dialog's working directory will be set to \a dir. If \a dir + includes a file name, the file will be selected. Only files that match the + \a filter are shown. The filter selected is set to \a selectedFilter. The + parameters \a dir, \a selectedFilter, and \a filter may be empty strings. + Multiple filters are separated with ';;'. For instance: - \code + \code "Images (*.png *.xpm *.jpg);;Text files (*.txt);;XML files (*.xml)" - \endcode + \endcode - The \a options argument holds various - options about how to run the dialog, see the QFileDialog::Option enum for - more information on the flags you can pass. + The \a options argument holds various options about how to run the dialog, + see the QFileDialog::Option enum for more information on the flags you can + pass. - The default filter can be chosen by setting \a selectedFilter to the desired value. + The default filter can be chosen by setting \a selectedFilter to the + desired value. - The dialog's caption is set to \a caption. If \a caption is not - specified then a default caption will be used. + The dialog's caption is set to \a caption. If \a caption is not specified, + a default caption will be used. - Under Windows and Mac OS X, this static function will use the native - file dialog and not a QFileDialog. + On Windows and Mac OS X, this static function will use the native file + dialog and not a QFileDialog. - Note that on Windows the dialog will spin a blocking modal event loop - that will not dispatch any QTimers, and if parent is not 0 then it will - position the dialog just under the parent's title bar. - On Mac OS X, the filter argument is ignored. + On Windows the dialog will spin a blocking modal event loop that will not + dispatch any QTimers, and if \a parent is not 0 then it will position the + dialog just below the parent's title bar. On Mac OS X, with its native file + dialog, the filter argument is ignored. - Under Unix/X11, the normal behavior of the file dialog is to resolve - and follow symlinks. For example, if \c{/usr/tmp} is a symlink to - \c{/var/tmp}, the file dialog will change to \c{/var/tmp} after - entering \c{/usr/tmp}. If \a options includes DontResolveSymlinks, - the file dialog will treat symlinks as regular directories. + On Unix/X11, the normal behavior of the file dialog is to resolve and + follow symlinks. For example, if \c{/usr/tmp} is a symlink to \c{/var/tmp}, + the file dialog will change to \c{/var/tmp} after entering \c{/usr/tmp}. If + \a options includes DontResolveSymlinks the file dialog will treat symlinks + as regular directories. - \warning Do not delete \a parent during the execution of the dialog. - If you want to do this, you should create the dialog - yourself using one of the QFileDialog constructors. + \warning Do not delete \a parent during the execution of the dialog. If you + want to do this, you should create the dialog yourself using one of the + QFileDialog constructors. - \sa getOpenFileName(), getOpenFileNames(), getExistingDirectory() + \sa getOpenFileName(), getOpenFileNames(), getExistingDirectory() */ QString QFileDialog::getSaveFileName(QWidget *parent, const QString &caption, @@ -1753,7 +1776,12 @@ QString QFileDialog::getSaveFileName(QWidget *parent, args.parent = parent; args.caption = caption; args.directory = QFileDialogPrivate::workingDirectory(dir); - args.selection = QFileDialogPrivate::initialSelection(dir); + //If workingDirectory returned a different path than the initial one, + //it means that the initial path was invalid. There is no point to try select a file + if (args.directory != QFileInfo(dir).path()) + args.selection = QString(); + else + args.selection = QFileDialogPrivate::initialSelection(dir); args.filter = filter; args.mode = AnyFile; args.options = options; @@ -1779,46 +1807,43 @@ QString QFileDialog::getSaveFileName(QWidget *parent, } /*! - This is a convenience static function that will return an existing - directory selected by the user. + This is a convenience static function that will return an existing + directory selected by the user. - \snippet doc/src/snippets/code/src_gui_dialogs_qfiledialog.cpp 12 + \snippet doc/src/snippets/code/src_gui_dialogs_qfiledialog.cpp 12 - This function creates a modal file dialog with the given \a parent - widget. If the parent is not 0, the dialog will be shown centered over - the parent widget. + This function creates a modal file dialog with the given \a parent widget. + If \a parent is not 0, the dialog will be shown centered over the parent + widget. - The dialog's working directory is set to \a dir, and the caption is - set to \a caption. Either of these may be an empty string in which case - the current directory and a default caption will be used - respectively. + The dialog's working directory is set to \a dir, and the caption is set to + \a caption. Either of these may be an empty string in which case the + current directory and a default caption will be used respectively. - The \a options argument holds various - options about how to run the dialog, see the QFileDialog::Option enum for - more information on the flags you can pass. Note that \l{QFileDialog::}{ShowDirsOnly} - must be set to ensure a native file dialog. + The \a options argument holds various options about how to run the dialog, + see the QFileDialog::Option enum for more information on the flags you can + pass. To ensure a native file dialog, \l{QFileDialog::}{ShowDirsOnly} must + be set. - Under Windows and Mac OS X, this static function will use the native - file dialog and not a QFileDialog. On Mac OS X, the \a dir argument - is ignored, the native dialog always displays the last visited directory. - On Windows CE, if the device has no native file dialog, a QFileDialog - will be used. + On Windows and Mac OS X, this static function will use the native file + dialog and not a QFileDialog. On Windows CE, if the device has no native + file dialog, a QFileDialog will be used. - Under Unix/X11, the normal behavior of the file dialog is to resolve - and follow symlinks. For example, if \c{/usr/tmp} is a symlink to - \c{/var/tmp}, the file dialog will change to \c{/var/tmp} after - entering \c{/usr/tmp}. If \a options includes DontResolveSymlinks, - the file dialog will treat symlinks as regular directories. + On Unix/X11, the normal behavior of the file dialog is to resolve and + follow symlinks. For example, if \c{/usr/tmp} is a symlink to \c{/var/tmp}, + the file dialog will change to \c{/var/tmp} after entering \c{/usr/tmp}. If + \a options includes DontResolveSymlinks, the file dialog will treat + symlinks as regular directories. - Note that on Windows the dialog will spin a blocking modal event loop - that will not dispatch any QTimers, and if parent is not 0 then it will - position the dialog just under the parent's title bar. + On Windows the dialog will spin a blocking modal event loop that will not + dispatch any QTimers, and if \a parent is not 0 then it will position the + dialog just below the parent's title bar. - \warning Do not delete \a parent during the execution of the dialog. - If you want to do this, you should create the dialog - yourself using one of the QFileDialog constructors. + \warning Do not delete \a parent during the execution of the dialog. If you + want to do this, you should create the dialog yourself using one of the + QFileDialog constructors. - \sa getOpenFileName(), getOpenFileNames(), getSaveFileName() + \sa getOpenFileName(), getOpenFileNames(), getSaveFileName() */ QString QFileDialog::getExistingDirectory(QWidget *parent, const QString &caption, @@ -2239,12 +2264,21 @@ void QFileDialog::setProxyModel(QAbstractProxyModel *proxyModel) proxyModel->setSourceModel(d->model); d->qFileDialogUi->listView->setModel(d->proxyModel); d->qFileDialogUi->treeView->setModel(d->proxyModel); +#ifndef QT_NO_COMPLETER + d->completer->setModel(d->proxyModel); + d->completer->proxyModel = d->proxyModel; +#endif connect(d->proxyModel, SIGNAL(rowsInserted(const QModelIndex &, int, int)), this, SLOT(_q_rowsInserted(const QModelIndex &))); } else { d->proxyModel = 0; d->qFileDialogUi->listView->setModel(d->model); d->qFileDialogUi->treeView->setModel(d->model); +#ifndef QT_NO_COMPLETER + d->completer->setModel(d->model); + d->completer->sourceModel = d->model; + d->completer->proxyModel = 0; +#endif connect(d->model, SIGNAL(rowsInserted(const QModelIndex &, int, int)), this, SLOT(_q_rowsInserted(const QModelIndex &))); } @@ -2757,8 +2791,9 @@ void QFileDialogPrivate::_q_enterDirectory(const QModelIndex &index) { Q_Q(QFileDialog); // My Computer or a directory - QString path = index.data(QFileSystemModel::FilePathRole).toString(); - if (path.isEmpty() || model->isDir(index)) { + QModelIndex sourceIndex = index.model() == proxyModel ? mapToSource(index) : index; + QString path = sourceIndex.data(QFileSystemModel::FilePathRole).toString(); + if (path.isEmpty() || model->isDir(sourceIndex)) { q->setDirectory(path); emit q->directoryEntered(path); if (fileMode == QFileDialog::Directory @@ -3132,7 +3167,11 @@ void QFileDialogLineEdit::keyPressEvent(QKeyEvent *e) QString QFSCompletor::pathFromIndex(const QModelIndex &index) const { - const QFileSystemModel *dirModel = static_cast<const QFileSystemModel *>(model()); + const QFileSystemModel *dirModel; + if (proxyModel) + dirModel = qobject_cast<const QFileSystemModel *>(proxyModel->sourceModel()); + else + dirModel = sourceModel; QString currentLocation = dirModel->rootPath(); QString path = index.data(QFileSystemModel::FilePathRole).toString(); if (!currentLocation.isEmpty() && path.startsWith(currentLocation)) { @@ -3178,7 +3217,11 @@ QStringList QFSCompletor::splitPath(const QString &path) const bool startsFromRoot = path[0] == sep[0]; #endif if (parts.count() == 1 || (parts.count() > 1 && !startsFromRoot)) { - const QFileSystemModel *dirModel = static_cast<const QFileSystemModel *>(model()); + const QFileSystemModel *dirModel; + if (proxyModel) + dirModel = qobject_cast<const QFileSystemModel *>(proxyModel->sourceModel()); + else + dirModel = sourceModel; QString currentLocation = QDir::toNativeSeparators(dirModel->rootPath()); if (currentLocation.contains(sep) && path != currentLocation) { QStringList currentLocationList = splitPath(currentLocation); diff --git a/src/gui/dialogs/qfiledialog_mac.mm b/src/gui/dialogs/qfiledialog_mac.mm index 4c13d01..90af9fc 100644 --- a/src/gui/dialogs/qfiledialog_mac.mm +++ b/src/gui/dialogs/qfiledialog_mac.mm @@ -278,7 +278,7 @@ QT_USE_NAMESPACE { Q_UNUSED(sender); QString qtFileName = QT_PREPEND_NAMESPACE(qt_mac_NSStringToQString)(filename); - QFileInfo info(qtFileName); + QFileInfo info(qtFileName.normalized(QT_PREPEND_NAMESPACE(QString::NormalizationForm_C))); QString path = info.absolutePath(); if (path != *mLastFilterCheckPath){ *mLastFilterCheckPath = path; diff --git a/src/gui/dialogs/qfiledialog_p.h b/src/gui/dialogs/qfiledialog_p.h index 8cb2cb0..ab4199e 100644 --- a/src/gui/dialogs/qfiledialog_p.h +++ b/src/gui/dialogs/qfiledialog_p.h @@ -91,6 +91,26 @@ class QCompleter; class QHBoxLayout; class Ui_QFileDialog; +#ifndef QT_NO_COMPLETER +/*! + QCompleter that can deal with QFileSystemModel + */ +class QFSCompletor : public QCompleter { +public: + QFSCompletor(QFileSystemModel *model, QObject *parent = 0) : QCompleter(model, parent), proxyModel(0), sourceModel(model) + { +#ifdef Q_OS_WIN + setCaseSensitivity(Qt::CaseInsensitive); +#endif + } + QString pathFromIndex(const QModelIndex &index) const; + QStringList splitPath(const QString& path) const; + + QAbstractProxyModel *proxyModel; + QFileSystemModel *sourceModel; +}; +#endif // QT_NO_COMPLETER + struct QFileDialogArgs { QFileDialogArgs() : parent(0), mode(QFileDialog::AnyFile) {} @@ -255,7 +275,7 @@ public: // data QStringList watching; QFileSystemModel *model; - QCompleter *completer; + QFSCompletor *completer; QFileDialog::FileMode fileMode; QFileDialog::AcceptMode acceptMode; @@ -434,23 +454,6 @@ inline QString QFileDialogPrivate::rootPath() const { inline QString QFileDialogPrivate::selectedNameFilter_sys() const { return QString(); } #endif -#ifndef QT_NO_COMPLETER -/*! - QCompleter that can deal with QFileSystemModel - */ -class QFSCompletor : public QCompleter { -public: - QFSCompletor(QAbstractItemModel *model, QObject *parent = 0) : QCompleter(model, parent) - { -#ifdef Q_OS_WIN - setCaseSensitivity(Qt::CaseInsensitive); -#endif - } - QString pathFromIndex(const QModelIndex &index) const; - QStringList splitPath(const QString& path) const; -}; -#endif // QT_NO_COMPLETER - QT_END_NAMESPACE #endif // QT_NO_FILEDIALOG diff --git a/src/gui/dialogs/qfileinfogatherer.cpp b/src/gui/dialogs/qfileinfogatherer.cpp index 3fe64ff..23a2cbc 100644 --- a/src/gui/dialogs/qfileinfogatherer.cpp +++ b/src/gui/dialogs/qfileinfogatherer.cpp @@ -168,6 +168,20 @@ void QFileInfoGatherer::clear() } /* + Remove a \a path from the watcher + + \sa listed() +*/ +void QFileInfoGatherer::removePath(const QString &path) +{ +#ifndef QT_NO_FILESYSTEMWATCHER + mutex.lock(); + watcher->removePath(path); + mutex.unlock(); +#endif +} + +/* List all files in \a directoryPath \sa listed() @@ -286,15 +300,9 @@ QString QFileInfoGatherer::translateDriveName(const QFileInfo &drive) const void QFileInfoGatherer::getFileInfos(const QString &path, const QStringList &files) { #ifndef QT_NO_FILESYSTEMWATCHER - //### We test here if the path still exist before adding it in the watcher - //### because sometime the file is deleted just before enter here so QStringList files is not up to date - //### It is not a proper fix, perhaps in 4.6 we should have a better way to avoid that - //### to ensure the gatherer have fresh information - QFileInfo info(path); if (files.isEmpty() && !watcher->directories().contains(path) && !path.isEmpty() - && info.exists() && !path.startsWith(QLatin1String("//")) /*don't watch UNC path*/) { watcher->addPath(path); } diff --git a/src/gui/dialogs/qfileinfogatherer_p.h b/src/gui/dialogs/qfileinfogatherer_p.h index eac0d46..60b9d5f 100644 --- a/src/gui/dialogs/qfileinfogatherer_p.h +++ b/src/gui/dialogs/qfileinfogatherer_p.h @@ -161,6 +161,7 @@ public: ~QFileInfoGatherer(); void clear(); + void removePath(const QString &path); QExtendedInformation getInfo(const QFileInfo &info) const; public Q_SLOTS: diff --git a/src/gui/dialogs/qfilesystemmodel.cpp b/src/gui/dialogs/qfilesystemmodel.cpp index 5f375b5..012d3a1 100644 --- a/src/gui/dialogs/qfilesystemmodel.cpp +++ b/src/gui/dialogs/qfilesystemmodel.cpp @@ -166,6 +166,8 @@ bool QFileSystemModel::remove(const QModelIndex &aindex) const { //### TODO optim QString path = filePath(aindex); + QFileSystemModelPrivate * d = const_cast<QFileSystemModelPrivate*>(d_func()); + d->fileInfoGatherer.removePath(path); QDirIterator it(path, QDir::AllDirs | QDir:: Files | QDir::NoDotAndDotDot, QDirIterator::Subdirectories); @@ -375,7 +377,7 @@ QFileSystemModelPrivate::QFileSystemNode *QFileSystemModelPrivate::node(const QS if (!info.exists()) return rootNode; QFileSystemModelPrivate *p = const_cast<QFileSystemModelPrivate*>(this); - p->addNode(rootNode, host); + p->addNode(rootNode, host,info); p->addVisibleFiles(rootNode, QStringList(host)); } r = rootNode->visibleLocation(host); @@ -395,6 +397,7 @@ QFileSystemModelPrivate::QFileSystemNode *QFileSystemModelPrivate::node(const QS #endif QFileSystemModelPrivate::QFileSystemNode *parent = node(index); + for (int i = 0; i < pathElements.count(); ++i) { QString element = pathElements.at(i); #ifdef Q_OS_WIN @@ -423,7 +426,7 @@ QFileSystemModelPrivate::QFileSystemNode *QFileSystemModelPrivate::node(const QS if (!info.exists()) return const_cast<QFileSystemModelPrivate::QFileSystemNode*>(&root); QFileSystemModelPrivate *p = const_cast<QFileSystemModelPrivate*>(this); - node = p->addNode(parent, element); + node = p->addNode(parent, element,info); #ifndef QT_NO_FILESYSTEMWATCHER node->populate(fileInfoGatherer.getInfo(info)); #endif @@ -843,7 +846,7 @@ bool QFileSystemModel::setData(const QModelIndex &idx, const QVariant &value, in QFileSystemModelPrivate::QFileSystemNode *parentNode = indexNode->parent; int visibleLocation = parentNode->visibleLocation(parentNode->children.value(indexNode->fileName)->fileName); - d->addNode(parentNode, newName); + d->addNode(parentNode, newName,indexNode->info->fileInfo()); parentNode->visibleChildren.removeAt(visibleLocation); QFileSystemModelPrivate::QFileSystemNode * oldValue = parentNode->children.value(oldName); parentNode->children[newName] = oldValue; @@ -1076,11 +1079,10 @@ private: /* \internal - Sort all of the children of parent (including their children) + Sort all of the children of parent */ -void QFileSystemModelPrivate::sortChildren(int column, Qt::SortOrder order, const QModelIndex &parent) +void QFileSystemModelPrivate::sortChildren(int column, const QModelIndex &parent) { - Q_Q(QFileSystemModel); QFileSystemModelPrivate::QFileSystemNode *indexNode = node(parent); if (indexNode->children.count() == 0) return; @@ -1104,9 +1106,6 @@ void QFileSystemModelPrivate::sortChildren(int column, Qt::SortOrder order, cons indexNode->visibleChildren.append(values.at(i).first->fileName); values.at(i).first->isVisible = true; } - - for (int i = 0; i < q->rowCount(parent); ++i) - sortChildren(column, order, q->index(i, 0, parent)); } /*! @@ -1128,7 +1127,7 @@ void QFileSystemModel::sort(int column, Qt::SortOrder order) if (!(d->sortColumn == column && d->sortOrder != order && !d->forceSort)) { //we sort only from where we are, don't need to sort all the model - d->sortChildren(column, order, index(rootPath())); + d->sortChildren(column, index(rootPath())); d->sortColumn = column; d->forceSort = false; } @@ -1286,7 +1285,7 @@ QModelIndex QFileSystemModel::mkdir(const QModelIndex &parent, const QString &na if (!dir.mkdir(name)) return QModelIndex(); QFileSystemModelPrivate::QFileSystemNode *parentNode = d->node(parent); - d->addNode(parentNode, name); + d->addNode(parentNode, name, QFileInfo()); Q_ASSERT(parentNode->children.contains(name)); QFileSystemModelPrivate::QFileSystemNode *node = parentNode->children[name]; node->populate(d->fileInfoGatherer.getInfo(QFileInfo(dir.absolutePath() + QDir::separator() + name))); @@ -1431,7 +1430,10 @@ void QFileSystemModel::setFilter(QDir::Filters filters) } /*! - Returns the filter specification for the directory model. + Returns the filter specified for the directory model. + + If a filter has not been set, the default filter is QDir::AllEntries | + QDir::NoDotAndDotDot | QDir::AllDirs. \sa QDir::Filters */ @@ -1605,10 +1607,13 @@ void QFileSystemModelPrivate::_q_directoryChanged(const QString &directory, cons *WARNING* this will change the count of children */ -QFileSystemModelPrivate::QFileSystemNode* QFileSystemModelPrivate::addNode(QFileSystemNode *parentNode, const QString &fileName) +QFileSystemModelPrivate::QFileSystemNode* QFileSystemModelPrivate::addNode(QFileSystemNode *parentNode, const QString &fileName, const QFileInfo& info) { // In the common case, itemLocation == count() so check there first QFileSystemModelPrivate::QFileSystemNode *node = new QFileSystemModelPrivate::QFileSystemNode(fileName, parentNode); +#ifndef QT_NO_FILESYSTEMWATCHER + node->populate(info); +#endif parentNode->children.insert(fileName, node); return node; } @@ -1726,7 +1731,7 @@ void QFileSystemModelPrivate::_q_fileSystemChanged(const QString &path, const QL QExtendedInformation info = fileInfoGatherer.getInfo(updates.at(i).second); bool previouslyHere = parentNode->children.contains(fileName); if (!previouslyHere) { - addNode(parentNode, fileName); + addNode(parentNode, fileName, info.fileInfo()); } QFileSystemModelPrivate::QFileSystemNode * node = parentNode->children.value(fileName); bool isCaseSensitive = parentNode->caseSensitive(); diff --git a/src/gui/dialogs/qfilesystemmodel.h b/src/gui/dialogs/qfilesystemmodel.h index 52ecaf9..995268b 100644 --- a/src/gui/dialogs/qfilesystemmodel.h +++ b/src/gui/dialogs/qfilesystemmodel.h @@ -158,6 +158,8 @@ private: Q_PRIVATE_SLOT(d_func(), void _q_performDelayedSort()) Q_PRIVATE_SLOT(d_func(), void _q_fileSystemChanged(const QString &path, const QList<QPair<QString, QFileInfo> > &)) Q_PRIVATE_SLOT(d_func(), void _q_resolvedName(const QString &fileName, const QString &resolvedName)) + + friend class QFileDialogPrivate; }; inline bool QFileSystemModel::rmdir(const QModelIndex &aindex) const diff --git a/src/gui/dialogs/qfilesystemmodel_p.h b/src/gui/dialogs/qfilesystemmodel_p.h index 95fbe20..0a1265a 100644 --- a/src/gui/dialogs/qfilesystemmodel_p.h +++ b/src/gui/dialogs/qfilesystemmodel_p.h @@ -163,7 +163,11 @@ public: info->icon = iconProvider->icon(QFileInfo(path)); QHash<QString, QFileSystemNode *>::const_iterator iterator; for(iterator = children.constBegin() ; iterator != children.constEnd() ; ++iterator) { - iterator.value()->updateIcon(iconProvider, path + QLatin1Char('/') + iterator.value()->fileName); + //On windows the root (My computer) has no path so we don't want to add a / for nothing (e.g. /C:/) + if (!path.isEmpty()) + iterator.value()->updateIcon(iconProvider, path + QLatin1Char('/') + iterator.value()->fileName); + else + iterator.value()->updateIcon(iconProvider, iterator.value()->fileName); } } @@ -172,7 +176,11 @@ public: info->displayType = iconProvider->type(QFileInfo(path)); QHash<QString, QFileSystemNode *>::const_iterator iterator; for(iterator = children.constBegin() ; iterator != children.constEnd() ; ++iterator) { - iterator.value()->retranslateStrings(iconProvider, path + QLatin1Char('/') + iterator.value()->fileName); + //On windows the root (My computer) has no path so we don't want to add a / for nothing (e.g. /C:/) + if (!path.isEmpty()) + iterator.value()->retranslateStrings(iconProvider, path + QLatin1Char('/') + iterator.value()->fileName); + else + iterator.value()->retranslateStrings(iconProvider, iterator.value()->fileName); } } @@ -182,7 +190,7 @@ public: QList<QString> visibleChildren; QFileSystemNode *parent; - private: + QExtendedInformation *info; }; @@ -216,10 +224,10 @@ public: bool filtersAcceptsNode(const QFileSystemNode *node) const; bool passNameFilters(const QFileSystemNode *node) const; void removeNode(QFileSystemNode *parentNode, const QString &name); - QFileSystemNode* addNode(QFileSystemNode *parentNode, const QString &fileName); + QFileSystemNode* addNode(QFileSystemNode *parentNode, const QString &fileName, const QFileInfo &info); void addVisibleFiles(QFileSystemNode *parentNode, const QStringList &newFiles); void removeVisibleFile(QFileSystemNode *parentNode, int visibleLocation); - void sortChildren(int column, Qt::SortOrder order, const QModelIndex &parent); + void sortChildren(int column, const QModelIndex &parent); inline int translateVisibleLocation(QFileSystemNode *parent, int row) const { return (sortOrder == Qt::AscendingOrder) ? row : parent->visibleChildren.count() - row - 1; diff --git a/src/gui/dialogs/qfontdialog_mac.mm b/src/gui/dialogs/qfontdialog_mac.mm index d6ddfa3..50917a1 100644 --- a/src/gui/dialogs/qfontdialog_mac.mm +++ b/src/gui/dialogs/qfontdialog_mac.mm @@ -87,7 +87,6 @@ const int StyleMask = NSTitledWindowMask | NSClosableWindowMask | NSResizableWin NSButton *mOkButton; NSButton *mCancelButton; QFontDialogPrivate *mPriv; - NSFont *mCocoaFont; QFont *mQtFont; BOOL mPanelHackedWithButtons; CGFloat mDialogExtraWidth; @@ -119,6 +118,29 @@ const int StyleMask = NSTitledWindowMask | NSClosableWindowMask | NSResizableWin - (void)cleanUpAfterMyself; @end +static QFont qfontForCocoaFont(NSFont *cocoaFont, const QFont &resolveFont) +{ + QFont newFont; + if (cocoaFont) { + int pSize = qRound([cocoaFont pointSize]); + QString family(QCFString::toQString(reinterpret_cast<CFStringRef>([cocoaFont familyName]))); + QString typeface(QCFString::toQString(reinterpret_cast<CFStringRef>([cocoaFont fontName]))); +// qDebug() << "original family" << family << "typeface" << typeface << "psize" << pSize; + int hyphenPos = typeface.indexOf(QLatin1Char('-')); + if (hyphenPos != -1) { + typeface.remove(0, hyphenPos + 1); + } else { + typeface = QLatin1String("Normal"); + } +// qDebug() << " massaged family" << family << "typeface" << typeface << "psize" << pSize; + newFont = QFontDatabase().font(family, typeface, pSize); + newFont.setUnderline(resolveFont.underline()); + newFont.setStrikeOut(resolveFont.strikeOut()); + + } + return newFont; +} + @implementation QCocoaFontPanelDelegate - (id)initWithFontPanel:(NSFontPanel *)panel stolenContentView:(NSView *)stolenContentView @@ -134,7 +156,6 @@ const int StyleMask = NSTitledWindowMask | NSClosableWindowMask | NSResizableWin mOkButton = okButton; mCancelButton = cancelButton; mPriv = priv; - mCocoaFont = 0; mPanelHackedWithButtons = (okButton != 0); mDialogExtraWidth = extraWidth; mDialogExtraHeight = extraHeight; @@ -155,42 +176,14 @@ const int StyleMask = NSTitledWindowMask | NSClosableWindowMask | NSResizableWin - (void)dealloc { - if (mCocoaFont) - [mCocoaFont release]; delete mQtFont; [super dealloc]; } - (void)changeFont:(id)sender { - Q_UNUSED(sender); - - QFont newFont; - - if (mCocoaFont) - [mCocoaFont autorelease]; NSFont *dummyFont = [NSFont userFontOfSize:12.0]; - mCocoaFont = [sender convertFont:dummyFont]; - if (mCocoaFont) { - [mCocoaFont retain]; - - int pSize = qRound([mCocoaFont pointSize]); - QString family(QCFString::toQString(reinterpret_cast<CFStringRef>([mCocoaFont familyName]))); - QString typeface(QCFString::toQString(reinterpret_cast<CFStringRef>([mCocoaFont fontName]))); -// qDebug() << "original family" << family << "typeface" << typeface << "psize" << pSize; - int hyphenPos = typeface.indexOf(QLatin1Char('-')); - if (hyphenPos != -1) { - typeface.remove(0, hyphenPos + 1); - } else { - typeface = QLatin1String("Normal"); - } -// qDebug() << " massaged family" << family << "typeface" << typeface << "psize" << pSize; - newFont = QFontDatabase().font(family, typeface, pSize); - newFont.setUnderline(mQtFont->underline()); - newFont.setStrikeOut(mQtFont->strikeOut()); - } - - [self setQtFont:newFont]; + [self setQtFont:qfontForCocoaFont([sender convertFont:dummyFont], *mQtFont)]; if (mPriv) mPriv->updateSampleFont(*mQtFont); } @@ -317,6 +310,9 @@ const int StyleMask = NSTitledWindowMask | NSClosableWindowMask | NSResizableWin - (void)onOkClicked { Q_ASSERT(mPanelHackedWithButtons); + NSFontManager *fontManager = [NSFontManager sharedFontManager]; + [self setQtFont:qfontForCocoaFont([fontManager convertFont:[fontManager selectedFont]], + *mQtFont)]; [[mStolenContentView window] close]; [self finishOffWithCode:NSOKButton]; } @@ -357,8 +353,8 @@ const int StyleMask = NSTitledWindowMask | NSClosableWindowMask | NSResizableWin - (void)setQtFont:(const QFont &)newFont { - delete mQtFont; - mQtFont = new QFont(newFont); + delete mQtFont; + mQtFont = new QFont(newFont); } - (QFont)qtFont @@ -374,16 +370,7 @@ const int StyleMask = NSTitledWindowMask | NSClosableWindowMask | NSResizableWin mModalSession = 0; } - // temporary hack to work around bug in deleteLater() in Qt/Mac Cocoa -#if 1 - bool deleteDialog = mPriv->fontDialog()->testAttribute(Qt::WA_DeleteOnClose); - mPriv->fontDialog()->setAttribute(Qt::WA_DeleteOnClose, false); -#endif mPriv->done((code == NSOKButton) ? QDialog::Accepted : QDialog::Rejected); -#if 1 - if (deleteDialog) - delete mPriv->fontDialog(); -#endif } else { [NSApp stopModalWithCode:code]; } @@ -404,6 +391,7 @@ const int StyleMask = NSTitledWindowMask | NSClosableWindowMask | NSResizableWin } [mFontPanel setDelegate:nil]; [[NSFontManager sharedFontManager] setDelegate:nil]; + [[NSFontManager sharedFontManager] setTarget:nil]; } @end @@ -527,6 +515,7 @@ void *QFontDialogPrivate::openCocoaFontPanel(const QFont &initial, extraHeight:dialogExtraHeight]; [ourPanel setDelegate:delegate]; [[NSFontManager sharedFontManager] setDelegate:delegate]; + [[NSFontManager sharedFontManager] setTarget:delegate]; setFont(delegate, initial); // hack to get correct initial layout diff --git a/src/gui/dialogs/qinputdialog.cpp b/src/gui/dialogs/qinputdialog.cpp index b63c8ee..78d99e3 100644 --- a/src/gui/dialogs/qinputdialog.cpp +++ b/src/gui/dialogs/qinputdialog.cpp @@ -424,26 +424,27 @@ void QInputDialogPrivate::_q_currentRowChanged(const QModelIndex &newIndex, /*! \class QInputDialog - \brief The QInputDialog class provides a simple convenience dialog to get a single value from the user. + \brief The QInputDialog class provides a simple convenience dialog to get a + single value from the user. \ingroup dialogs \mainclass - The input value can be a string, a number or an item from a list. A - label must be set to tell the user what they should enter. + The input value can be a string, a number or an item from a list. A label + must be set to tell the user what they should enter. - Four static convenience functions are provided: - getText(), getInt(), getDouble(), and getItem(). All the - functions can be used in a similar way, for example: + Four static convenience functions are provided: getText(), getInt(), + getDouble(), and getItem(). All the functions can be used in a similar way, + for example: \snippet examples/dialogs/standarddialogs/dialog.cpp 3 - The \c ok variable is set to true if the user clicks \gui OK; - otherwise it is set to false. + The \c ok variable is set to true if the user clicks \gui OK; otherwise it + is set to false. \img inputdialogs.png Input Dialogs - The \l{dialogs/standarddialogs}{Standard Dialogs} example shows - how to use QInputDialog as well as other built-in Qt dialogs. + The \l{dialogs/standarddialogs}{Standard Dialogs} example shows how to use + QInputDialog as well as other built-in Qt dialogs. \sa QMessageBox, {Standard Dialogs Example} */ @@ -452,11 +453,13 @@ void QInputDialogPrivate::_q_currentRowChanged(const QModelIndex &newIndex, \enum QInputDialog::InputMode \since 4.5 - This enum describes the different modes of input that can be selected for the dialog. + This enum describes the different modes of input that can be selected for + the dialog. \value TextInput Used to input text strings. \value IntInput Used to input integers. - \value DoubleInput Used to input floating point numbers with double precision accuracy. + \value DoubleInput Used to input floating point numbers with double + precision accuracy. \sa inputMode */ @@ -487,7 +490,8 @@ QInputDialog::~QInputDialog() \brief the mode used for input - This property help determines which widget is used for entering input into the dialog. + This property help determines which widget is used for entering input into + the dialog. */ void QInputDialog::setInputMode(InputMode mode) { @@ -1104,15 +1108,18 @@ void QInputDialog::done(int result) } /*! - Static convenience function to get a string from the user. \a - title is the text which is displayed in the title bar of the - dialog. \a label is the text which is shown to the user (it should - say what should be entered). \a text is the default text which is - placed in the line edit. The \a mode is the echo mode the line - edit will use. If \a ok is nonnull \e *\a ok will be set to true - if the user pressed \gui OK and to false if the user pressed - \gui Cancel. The dialog's parent is \a parent. The dialog will be - modal and uses the specified widget \a flags. + Static convenience function to get a string from the user. + + \a title is the text which is displayed in the title bar of the dialog. + \a label is the text which is shown to the user (it should say what should + be entered). + \a text is the default text which is placed in the line edit. + \a mode is the echo mode the line edit will use. + + If \a ok is nonnull \e *\a ok will be set to true if the user pressed + \gui OK and to false if the user pressed \gui Cancel. The dialog's parent + is \a parent. The dialog will be modal and uses the specified widget + \a flags. This function returns the text which has been entered in the line edit. It will not return an empty string. @@ -1121,11 +1128,11 @@ void QInputDialog::done(int result) \snippet examples/dialogs/standarddialogs/dialog.cpp 3 - \warning Do not delete \a parent during the execution of the dialog. - If you want to do this, you should create the dialog - yourself using one of the QInputDialog constructors. + \warning Do not delete \a parent during the execution of the dialog. If you + want to do this, you should create the dialog yourself using one of the + QInputDialog constructors. - \sa getInteger(), getDouble(), getItem() + \sa getInt(), getDouble(), getItem() */ QString QInputDialog::getText(QWidget *parent, const QString &title, const QString &label, @@ -1149,30 +1156,32 @@ QString QInputDialog::getText(QWidget *parent, const QString &title, const QStri } /*! - Static convenience function to get an integer input from the - user. \a title is the text which is displayed in the title bar - of the dialog. \a label is the text which is shown to the user - (it should say what should be entered). \a value is the default - integer which the spinbox will be set to. \a min and \a - max are the minimum and maximum values the user may choose, - and \a step is the amount by which the values change as the user - presses the arrow buttons to increment or decrement the value. - - If \a ok is nonnull *\a ok will be set to true if the user - pressed \gui OK and to false if the user pressed \gui Cancel. The - dialog's parent is \a parent. The dialog will be modal and uses - the widget \a flags. - - On success, this function returns the integer which has been - entered by the user; on failure, it returns the initial \a value. + \since 4.5 + + Static convenience function to get an integer input from the user. + + \a title is the text which is displayed in the title bar of the dialog. + \a label is the text which is shown to the user (it should say what should + be entered). + \a value is the default integer which the spinbox will be set to. + \a min and \a max are the minimum and maximum values the user may choose. + \a step is the amount by which the values change as the user presses the + arrow buttons to increment or decrement the value. + + If \a ok is nonnull *\a ok will be set to true if the user pressed \gui OK + and to false if the user pressed \gui Cancel. The dialog's parent is + \a parent. The dialog will be modal and uses the widget \a flags. + + On success, this function returns the integer which has been entered by the + user; on failure, it returns the initial \a value. Use this static function like this: \snippet examples/dialogs/standarddialogs/dialog.cpp 0 - \warning Do not delete \a parent during the execution of the dialog. - If you want to do this, you should create the dialog - yourself using one of the QInputDialog constructors. + \warning Do not delete \a parent during the execution of the dialog. If you + want to do this, you should create the dialog yourself using one of the + QInputDialog constructors. \sa getText(), getDouble(), getItem() */ @@ -1198,32 +1207,32 @@ int QInputDialog::getInt(QWidget *parent, const QString &title, const QString &l } /*! - Static convenience function to get a floating point number from - the user. \a title is the text which is displayed in the title - bar of the dialog. \a label is the text which is shown to the user - (it should say what should be entered). \a value is the default - floating point number that the line edit will be set to. \a - min and \a max are the minimum and maximum values the - user may choose, and \a decimals is the maximum number of decimal - places the number may have. - - If \a ok is nonnull, *\a ok will be set to true if the user - pressed \gui OK and to false if the user pressed \gui Cancel. The - dialog's parent is \a parent. The dialog will be modal and uses - the widget \a flags. - - This function returns the floating point number which has been - entered by the user. + Static convenience function to get a floating point number from the user. + + \a title is the text which is displayed in the title bar of the dialog. + \a label is the text which is shown to the user (it should say what should + be entered). + \a value is the default floating point number that the line edit will be + set to. + \a min and \a max are the minimum and maximum values the user may choose. + \a decimals is the maximum number of decimal places the number may have. + + If \a ok is nonnull, *\a ok will be set to true if the user pressed \gui OK + and to false if the user pressed \gui Cancel. The dialog's parent is + \a parent. The dialog will be modal and uses the widget \a flags. + + This function returns the floating point number which has been entered by + the user. Use this static function like this: \snippet examples/dialogs/standarddialogs/dialog.cpp 1 - \warning Do not delete \a parent during the execution of the dialog. - If you want to do this, you should create the dialog - yourself using one of the QInputDialog constructors. + \warning Do not delete \a parent during the execution of the dialog. If you + want to do this, you should create the dialog yourself using one of the + QInputDialog constructors. - \sa getText(), getInteger(), getItem() + \sa getText(), getInt(), getItem() */ double QInputDialog::getDouble(QWidget *parent, const QString &title, const QString &label, @@ -1248,32 +1257,34 @@ double QInputDialog::getDouble(QWidget *parent, const QString &title, const QStr } /*! - Static convenience function to let the user select an item from a - string list. \a title is the text which is displayed in the title - bar of the dialog. \a label is the text which is shown to the user (it - should say what should be entered). \a items is the - string list which is inserted into the combobox, and \a current is the number - of the item which should be the current item. If \a editable is true - the user can enter their own text; if \a editable is false the user - may only select one of the existing items. - - If \a ok is nonnull \e *\a ok will be set to true if the user - pressed \gui OK and to false if the user pressed \gui Cancel. The - dialog's parent is \a parent. The dialog will be modal and uses - the widget \a flags. - - This function returns the text of the current item, or if \a - editable is true, the current text of the combobox. + Static convenience function to let the user select an item from a string + list. + + \a title is the text which is displayed in the title bar of the dialog. + \a label is the text which is shown to the user (it should say what should + be entered). + \a items is the string list which is inserted into the combobox. + \a current is the number of the item which should be the current item. + + If \a editable is true the user can enter their own text; otherwise the + user may only select one of the existing items. + + If \a ok is nonnull \e *\a ok will be set to true if the user pressed + \gui OK and to false if the user pressed \gui Cancel. The dialog's parent + is \a parent. The dialog will be modal and uses the widget \a flags. + + This function returns the text of the current item, or if \a editable is + true, the current text of the combobox. Use this static function like this: \snippet examples/dialogs/standarddialogs/dialog.cpp 2 - \warning Do not delete \a parent during the execution of the dialog. - If you want to do this, you should create the dialog - yourself using one of the QInputDialog constructors. + \warning Do not delete \a parent during the execution of the dialog. If you + want to do this, you should create the dialog yourself using one of the + QInputDialog constructors. - \sa getText(), getInteger(), getDouble() + \sa getText(), getInt(), getDouble() */ QString QInputDialog::getItem(QWidget *parent, const QString &title, const QString &label, diff --git a/src/gui/dialogs/qmessagebox.cpp b/src/gui/dialogs/qmessagebox.cpp index f343405..5e59501 100644 --- a/src/gui/dialogs/qmessagebox.cpp +++ b/src/gui/dialogs/qmessagebox.cpp @@ -280,6 +280,9 @@ void QMessageBoxPrivate::updateSize() int hardLimit = screenSize.width() - (q->frameGeometry().width() - q->geometry().width()); #else int hardLimit = qMin(screenSize.width() - 480, 1000); // can never get bigger than this + // on small screens allows the messagebox be the same size as the screen + if (screenSize.width() <= 1024) + hardLimit = screenSize.width(); #endif #ifdef Q_WS_MAC int softLimit = qMin(screenSize.width()/2, 420); @@ -532,11 +535,11 @@ void QMessageBoxPrivate::_q_buttonClicked(QAbstractButton *button) \section2 Severity Levels and the Icon and Pixmap Properties - QMessageBox supports four predefined message severity levels, or - message types, which really only differ in the predefined icon - they each show. Specify one of the four predefined message types - by setting the \l{QMessageBox::icon} {icon} property to one of the - \l{QMessageBox::Icon} {predefined Icons}. The following rules are + QMessageBox supports four predefined message severity levels, or message + types, which really only differ in the predefined icon they each show. + Specify one of the four predefined message types by setting the + \l{QMessageBox::icon}{icon} property to one of the + \l{QMessageBox::Icon}{predefined icons}. The following rules are guidelines: \table @@ -558,17 +561,17 @@ void QMessageBoxPrivate::_q_buttonClicked(QAbstractButton *button) \o For reporting critical errors. \endtable - The default value is \l{QMessageBox::NoIcon} {No Icon}. The - message boxes are otherwise the same for all cases. When using a - standard icon, use the one recommended in the table, or use the - one recommended by the style guidelines for your platform. If none - of the standard icons is right for your message box, you can use a - custom icon by setting the \l{QMessageBox::iconPixmap} {icon - pixmap} property instead of setting the \l{QMessageBox::icon} - {icon} property. + \l{QMessageBox::Icon}{Predefined icons} are not defined by QMessageBox, but + provided by the style. The default value is \l{QMessageBox::NoIcon} + {No Icon}. The message boxes are otherwise the same for all cases. When + using a standard icon, use the one recommended in the table, or use the + one recommended by the style guidelines for your platform. If none of the + standard icons is right for your message box, you can use a custom icon by + setting the \l{QMessageBox::iconPixmap}{icon pixmap} property instead of + setting the \l{QMessageBox::icon}{icon} property. - In summary, to set an icon, use \e{either} setIcon() for one of - the standard icons, \e{or} setIconPixmap() for a custom icon. + In summary, to set an icon, use \e{either} setIcon() for one of the + standard icons, \e{or} setIconPixmap() for a custom icon. \section1 The Static Functions API @@ -1680,7 +1683,7 @@ void QMessageBox::aboutQt(QWidget *parent, const QString &title) { #ifdef Q_WS_MAC static QPointer<QMessageBox> oldMsgBox; - + if (oldMsgBox) { oldMsgBox->show(); oldMsgBox->raise(); @@ -1692,29 +1695,35 @@ void QMessageBox::aboutQt(QWidget *parent, const QString &title) QString translatedTextAboutQt; translatedTextAboutQt = QMessageBox::tr( "<h3>About Qt</h3>" - "%1<p>Qt is a C++ toolkit for cross-platform " - "application development.</p>" - "<p>Qt provides single-source " - "portability across MS Windows, Mac OS X, " - "Linux, and all major commercial Unix variants. Qt is also" - " available for embedded devices as Qt for Embedded Linux" - " and Qt for Windows CE.</p>" - "<p>Qt is a Nokia product. See " - "<a href=\"http://qtsoftware.com/qt/\">qtsoftware.com/qt/</a> for more information.</p>" - ) -#if QT_EDITION != QT_EDITION_OPENSOURCE - .arg(QMessageBox::tr("<p>This program uses Qt version %1.</p>")) -#else - .arg(QMessageBox::tr("<p>This program uses Qt Open Source Edition version %1.</p>" - "<p>Qt Open Source Edition is intended for the development " - "of Open Source applications. You need a commercial Qt " - "license for development of proprietary (closed source) " - "applications.</p>" - "<p>Please see <a href=\"http://qtsoftware.com/company/model/\">qtsoftware.com/company/model/</a> " - "for an overview of Qt licensing.</p>")) -#endif - - .arg(QLatin1String(QT_VERSION_STR)); + "<p>This program uses Qt version %1.</p>" + "<p>Qt is a C++ toolkit for cross-platform application " + "development.</p>" + "<p>Qt provides single-source portability across MS Windows, " + "Mac OS X, Linux, and all major commercial Unix variants. " + "Qt is also available for embedded devices as Qt for Embedded Linux " + "and Qt for Windows CE.</p>" + "<p>Qt is available under three different licensing options designed " + "to accommodate the needs of our various users.</p>" + "Qt licensed under our commercial license agreement is appropriate " + "for development of proprietary/commercial software where you do not " + "want to share any source code with third parties or otherwise cannot " + "comply with the terms of the GNU LGPL version 2.1 or GNU GPL version " + "3.0.</p>" + "<p>Qt licensed under the GNU LGPL version 2.1 is appropriate for the " + "development of Qt applications (proprietary or open source) provided " + "you can comply with the terms and conditions of the GNU LGPL version " + "2.1.</p>" + "<p>Qt licensed under the GNU General Public License version 3.0 is " + "appropriate for the development of Qt applications where you wish to " + "use such applications in combination with software subject to the " + "terms of the GNU GPL version 3.0 or where you are otherwise willing " + "to comply with the terms of the GNU GPL version 3.0.</p>" + "<p>Please see <a href=\"http://www.qtsoftware.com/products/licensing\">www.qtsoftware.com/products/licensing</a> " + "for an overview of Qt licensing.</p>" + "<p>Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).</p>" + "<p>Qt is a Nokia product. See <a href=\"http://www.qtsoftware.com/qt/\">www.qtsoftware.com/qt</a> " + "for more information.</p>" + ).arg(QLatin1String(QT_VERSION_STR)); QMessageBox *msgBox = new QMessageBox(parent); msgBox->setAttribute(Qt::WA_DeleteOnClose); diff --git a/src/gui/dialogs/qprintdialog_unix.cpp b/src/gui/dialogs/qprintdialog_unix.cpp index 76c22d0..87a4e65 100644 --- a/src/gui/dialogs/qprintdialog_unix.cpp +++ b/src/gui/dialogs/qprintdialog_unix.cpp @@ -727,7 +727,9 @@ void QUnixPrintWidgetPrivate::updateWidget() widget.printers->removeItem(widget.printers->count()-1); // remove separator filePrintersAdded = false; } - if (printer && filePrintersAdded && printer->printerName().isEmpty()) { + if (printer && filePrintersAdded && (printer->outputFormat() != QPrinter::NativeFormat + || printer->printerName().isEmpty())) + { if (printer->outputFormat() == QPrinter::PdfFormat) widget.printers->setCurrentIndex(widget.printers->count() - 2); else if (printer->outputFormat() == QPrinter::PostScriptFormat) diff --git a/src/gui/dialogs/qsidebar.cpp b/src/gui/dialogs/qsidebar.cpp index 1bd2b7d..26108d7 100644 --- a/src/gui/dialogs/qsidebar.cpp +++ b/src/gui/dialogs/qsidebar.cpp @@ -55,6 +55,18 @@ QT_BEGIN_NAMESPACE +void QSideBarDelegate::initStyleOption(QStyleOptionViewItem *option, + const QModelIndex &index) const +{ + QStyledItemDelegate::initStyleOption(option,index); + QVariant value = index.data(QUrlModel::EnabledRole); + if (value.isValid()) { + //If the bookmark/entry is not enabled then we paint it in gray + if (!qvariant_cast<bool>(value)) + option->state &= ~QStyle::State_Enabled; + } +} + /*! QUrlModel lets you have indexes from a QFileSystemModel to a list. When QFileSystemModel changes them QUrlModel will automatically update. @@ -88,9 +100,6 @@ Qt::ItemFlags QUrlModel::flags(const QModelIndex &index) const if (index.data(Qt::DecorationRole).isNull()) flags &= ~Qt::ItemIsEnabled; - if (invalidUrls.contains(index.data(UrlRole).toUrl())) - flags &= ~Qt::ItemIsEnabled; - return flags; } @@ -193,6 +202,11 @@ void QUrlModel::setUrl(const QModelIndex &index, const QUrl &url, const QModelIn newName = QFileInfo(url.toLocalFile()).fileName(); if (!invalidUrls.contains(url)) invalidUrls.append(url); + //The bookmark is invalid then we set to false the EnabledRole + setData(index, false, EnabledRole); + } else { + //The bookmark is valid then we set to true the EnabledRole + setData(index, true, EnabledRole); } // Make sure that we have at least 32x32 images @@ -234,7 +248,11 @@ void QUrlModel::addUrls(const QList<QUrl> &list, int row, bool move) if (!url.isValid() || url.scheme() != QLatin1String("file")) continue; for (int j = 0; move && j < rowCount(); ++j) { +#if defined(Q_OS_WIN) + if (index(j, 0).data(UrlRole).toUrl().toLocalFile().toLower() == url.toLocalFile().toLower()) { +#else if (index(j, 0).data(UrlRole) == url) { +#endif removeRow(j); if (j <= row) row--; @@ -356,6 +374,7 @@ void QSidebar::init(QFileSystemModel *model, const QList<QUrl> &newUrls) urlModel = new QUrlModel(this); urlModel->setFileSystemModel(model); setModel(urlModel); + setItemDelegate(new QSideBarDelegate(this)); connect(selectionModel(), SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)), this, SLOT(clicked(const QModelIndex &))); diff --git a/src/gui/dialogs/qsidebar_p.h b/src/gui/dialogs/qsidebar_p.h index ecbbb37..56fd6d4 100644 --- a/src/gui/dialogs/qsidebar_p.h +++ b/src/gui/dialogs/qsidebar_p.h @@ -55,6 +55,7 @@ #include <qlistwidget.h> #include <qstandarditemmodel.h> +#include <qstyleditemdelegate.h> #include <qurl.h> #ifndef QT_NO_FILEDIALOG @@ -62,13 +63,23 @@ QT_BEGIN_NAMESPACE class QFileSystemModel; + +class QSideBarDelegate : public QStyledItemDelegate +{ + public: + QSideBarDelegate(QWidget *parent = 0) : QStyledItemDelegate(parent) {} + void initStyleOption(QStyleOptionViewItem *option, + const QModelIndex &index) const; +}; + class Q_AUTOTEST_EXPORT QUrlModel : public QStandardItemModel { Q_OBJECT public: enum Roles { - UrlRole = Qt::UserRole + 1 + UrlRole = Qt::UserRole + 1, + EnabledRole = Qt::UserRole + 2 }; QUrlModel(QObject *parent = 0); diff --git a/src/gui/dialogs/qwizard.cpp b/src/gui/dialogs/qwizard.cpp index fcd8ccf..32395c4 100644 --- a/src/gui/dialogs/qwizard.cpp +++ b/src/gui/dialogs/qwizard.cpp @@ -516,6 +516,7 @@ public: , vistaInitPending(false) , vistaState(QVistaHelper::Dirty) , vistaStateChanged(false) + , inHandleAeroStyleChange(false) #endif , minimumWidth(0) , minimumHeight(0) @@ -617,6 +618,7 @@ public: bool vistaInitPending; QVistaHelper::VistaState vistaState; bool vistaStateChanged; + bool inHandleAeroStyleChange; #endif int minimumWidth; int minimumHeight; @@ -1459,6 +1461,10 @@ void QWizardPrivate::handleAeroStyleChange() { Q_Q(QWizard); + if (inHandleAeroStyleChange) + return; // prevent recursion + inHandleAeroStyleChange = true; + vistaHelper->backButton()->disconnect(); q->removeEventFilter(vistaHelper); @@ -1493,6 +1499,8 @@ void QWizardPrivate::handleAeroStyleChange() if (q->isVisible()) vistaHelper->setWindowPosHack(); + + inHandleAeroStyleChange = false; } #endif diff --git a/src/gui/embedded/qscreen_qws.cpp b/src/gui/embedded/qscreen_qws.cpp index 6f32879..6741f2c 100644 --- a/src/gui/embedded/qscreen_qws.cpp +++ b/src/gui/embedded/qscreen_qws.cpp @@ -2038,7 +2038,8 @@ QScreen::~QScreen() void QScreen::shutdownDevice() { #ifndef QT_NO_QWS_CURSOR - qt_screencursor->hide(); + if (qt_screencursor) + qt_screencursor->hide(); #endif } diff --git a/src/gui/embedded/qscreenlinuxfb_qws.cpp b/src/gui/embedded/qscreenlinuxfb_qws.cpp index fed7aad..48fe881 100644 --- a/src/gui/embedded/qscreenlinuxfb_qws.cpp +++ b/src/gui/embedded/qscreenlinuxfb_qws.cpp @@ -342,8 +342,18 @@ bool QLinuxFbScreen::connect(const QString &displaySpec) } dw=w; dh=h; - xoff += (vinfo.xres - w)/2; - yoff += (vinfo.yres - h)/2; + int xxoff, yyoff; + if (sscanf(qwssize, "%*dx%*d+%d+%d", &xxoff, &yyoff) == 2) { + if (xxoff < 0 || xxoff + w > vinfo.xres) + xxoff = vinfo.xres - w; + if (yyoff < 0 || yyoff + h > vinfo.yres) + yyoff = vinfo.yres - h; + xoff += xxoff; + yoff += yyoff; + } else { + xoff += (vinfo.xres - w)/2; + yoff += (vinfo.yres - h)/2; + } } else { dw=w=vinfo.xres; dh=h=vinfo.yres; diff --git a/src/gui/embedded/qscreentransformed_qws.cpp b/src/gui/embedded/qscreentransformed_qws.cpp index f988789..e22ea1f 100644 --- a/src/gui/embedded/qscreentransformed_qws.cpp +++ b/src/gui/embedded/qscreentransformed_qws.cpp @@ -400,7 +400,19 @@ void QTransformedScreen::blit(const QImage &image, const QPoint &topLeft, #endif #if defined(QT_QWS_DEPTH_16) || defined(QT_QWS_DEPTH_15) || defined(QT_QWS_DEPTH_12) case 16: +#if defined QT_QWS_ROTATE_BGR + if (pixelType() == BGRPixel && image.depth() == 16) { + SET_BLIT_FUNC(qbgr565, quint16, trans, func); + break; + } //fall-through here!!! +#endif case 15: +#if defined QT_QWS_ROTATE_BGR + if (pixelType() == BGRPixel && image.format() == QImage::Format_RGB555) { + SET_BLIT_FUNC(qbgr555, qrgb555, trans, func); + break; + } //fall-through here!!! +#endif case 12: if (image.depth() == 16) SET_BLIT_FUNC(quint16, quint16, trans, func); @@ -410,7 +422,9 @@ void QTransformedScreen::blit(const QImage &image, const QPoint &topLeft, #endif #ifdef QT_QWS_DEPTH_8 case 8: - if (image.depth() == 16) + if (image.format() == QImage::Format_RGB444) + SET_BLIT_FUNC(quint8, qrgb444, trans, func); + else if (image.depth() == 16) SET_BLIT_FUNC(quint8, quint16, trans, func); else SET_BLIT_FUNC(quint8, quint32, trans, func); diff --git a/src/gui/embedded/qscreenvfb_qws.cpp b/src/gui/embedded/qscreenvfb_qws.cpp index abbe73b..accfe1f 100644 --- a/src/gui/embedded/qscreenvfb_qws.cpp +++ b/src/gui/embedded/qscreenvfb_qws.cpp @@ -310,6 +310,9 @@ bool QVFbScreen::connect(const QString &displaySpec) connected = this; + if (qgetenv("QT_QVFB_BGR").toInt()) + pixeltype = BGRPixel; + return true; } diff --git a/src/gui/embedded/qwindowsystem_qws.cpp b/src/gui/embedded/qwindowsystem_qws.cpp index dffebf2..fdcd193 100644 --- a/src/gui/embedded/qwindowsystem_qws.cpp +++ b/src/gui/embedded/qwindowsystem_qws.cpp @@ -4044,7 +4044,7 @@ void QWSServer::setDesktopBackground(const QImage &img) */ void QWSServer::setDesktopBackground(const QColor &c) { - setDesktopBackground(QBrush(c)); + setBackground(QBrush(c)); } #endif //QT3_SUPPORT diff --git a/src/gui/graphicsview/qgraphicsitem.cpp b/src/gui/graphicsview/qgraphicsitem.cpp index d95b194..201dfb8 100644 --- a/src/gui/graphicsview/qgraphicsitem.cpp +++ b/src/gui/graphicsview/qgraphicsitem.cpp @@ -528,25 +528,22 @@ QT_BEGIN_NAMESPACE // QRectF::intersects() returns false always if either the source or target // rectangle's width or height are 0. This works around that problem. -static QRectF _q_adjustedRect(const QRectF &rect) -{ - static const qreal p = (qreal)0.00001; - QRectF r = rect; - if (!r.width()) - r.adjust(-p, 0, p, 0); - if (!r.height()) - r.adjust(0, -p, 0, p); - return r; +static inline void _q_adjustRect(QRectF *rect) +{ + Q_ASSERT(rect); + if (!rect->width()) + rect->adjust(-0.00001, 0, 0.00001, 0); + if (!rect->height()) + rect->adjust(0, -0.00001, 0, 0.00001); } -static QRect _q_adjustedRect(const QRect &rect) +static inline void _q_adjustRect(QRect *rect) { - QRect r = rect; - if (!r.width()) - r.adjust(0, 0, 1, 0); - if (!r.height()) - r.adjust(0, 0, 0, 1); - return r; + Q_ASSERT(rect); + if (!rect->width()) + rect->adjust(0, 0, 1, 0); + if (!rect->height()) + rect->adjust(0, 0, 0, 1); } /* @@ -631,6 +628,7 @@ void QGraphicsItemPrivate::updateAncestorFlag(QGraphicsItem::GraphicsItemFlag ch case QGraphicsItem::ItemClipsChildrenToShape: flag = AncestorClipsChildren; enabled = flags & QGraphicsItem::ItemClipsChildrenToShape; + invalidateCachedClipPathRecursively(/*childrenOnly=*/true); break; case QGraphicsItem::ItemIgnoresTransformations: flag = AncestorIgnoresTransformations; @@ -1028,9 +1026,8 @@ void QGraphicsItem::setParentItem(QGraphicsItem *parent) } if (parent == d_ptr->parent) return; - QVariant variant; - qVariantSetValue<QGraphicsItem *>(variant, parent); - parent = qVariantValue<QGraphicsItem *>(itemChange(ItemParentChange, variant)); + const QVariant newParentVariant(itemChange(ItemParentChange, qVariantFromValue<QGraphicsItem *>(parent))); + parent = qVariantValue<QGraphicsItem *>(newParentVariant); if (parent == d_ptr->parent) return; @@ -1045,11 +1042,11 @@ void QGraphicsItem::setParentItem(QGraphicsItem *parent) // We anticipate geometry changes prepareGeometryChange(); + const QVariant thisPointerVariant(qVariantFromValue<QGraphicsItem *>(this)); if (d_ptr->parent) { // Remove from current parent qt_graphicsitem_removeChild(this, &d_ptr->parent->d_func()->children); - qVariantSetValue<QGraphicsItem *>(variant, this); - d_ptr->parent->itemChange(ItemChildRemovedChange, variant); + d_ptr->parent->itemChange(ItemChildRemovedChange, thisPointerVariant); } if ((d_ptr->parent = parent)) { @@ -1064,10 +1061,9 @@ void QGraphicsItem::setParentItem(QGraphicsItem *parent) } d_ptr->parent->d_func()->children << this; - qVariantSetValue<QGraphicsItem *>(variant, this); - d_ptr->parent->itemChange(ItemChildAddedChange, variant); + d_ptr->parent->itemChange(ItemChildAddedChange, thisPointerVariant); if (!implicitUpdate) - d_ptr->updateHelper(); + d_ptr->updateHelper(QRectF(), false, true); // Inherit ancestor flags from the new parent. d_ptr->updateAncestorFlag(QGraphicsItem::GraphicsItemFlag(-1)); @@ -1096,7 +1092,7 @@ void QGraphicsItem::setParentItem(QGraphicsItem *parent) if (!d_ptr->enabled && !d_ptr->explicitlyDisabled) d_ptr->setEnabledHelper(true, /* explicit = */ false); - d_ptr->updateHelper(); + d_ptr->updateHelper(QRectF(), false, true); } if (d_ptr->scene) { @@ -1106,10 +1102,7 @@ void QGraphicsItem::setParentItem(QGraphicsItem *parent) } // Resolve opacity. - if (QGraphicsItem *p = d_ptr->parent) - d_ptr->resolveEffectiveOpacity(p->effectiveOpacity()); - else - d_ptr->resolveEffectiveOpacity(1.0); + d_ptr->updateEffectiveOpacity(); // Resolve depth. d_ptr->resolveDepth(parent ? parent->d_ptr->depth : -1); @@ -1118,7 +1111,7 @@ void QGraphicsItem::setParentItem(QGraphicsItem *parent) d_ptr->invalidateSceneTransformCache(); // Deliver post-change notification - itemChange(QGraphicsItem::ItemParentHasChanged, qVariantFromValue<QGraphicsItem *>(parent)); + itemChange(QGraphicsItem::ItemParentHasChanged, newParentVariant); } /*! @@ -1237,10 +1230,10 @@ void QGraphicsItem::setFlags(GraphicsItemFlags flags) return; // Flags that alter the geometry of the item (or its children). - int geomChangeFlagsMask = (ItemClipsChildrenToShape | ItemClipsToShape | ItemIgnoresTransformations); - bool fullUpdate = (flags & geomChangeFlagsMask) != (d_ptr->flags & geomChangeFlagsMask); + const quint32 geomChangeFlagsMask = (ItemClipsChildrenToShape | ItemClipsToShape | ItemIgnoresTransformations); + bool fullUpdate = (quint32(flags) & geomChangeFlagsMask) != (d_ptr->flags & geomChangeFlagsMask); if (fullUpdate) - d_ptr->fullUpdateHelper(); + d_ptr->fullUpdateHelper(false, true); // Keep the old flags to compare the diff. GraphicsItemFlags oldFlags = this->flags(); @@ -1250,12 +1243,8 @@ void QGraphicsItem::setFlags(GraphicsItemFlags flags) // Reresolve effective opacity if the opacity flags change. static const quint32 opacityFlagsMask = ItemIgnoresParentOpacity | ItemDoesntPropagateOpacityToChildren; - if ((flags & opacityFlagsMask) != (oldFlags & opacityFlagsMask)) { - if (QGraphicsItem *p = d_ptr->parent) - d_ptr->resolveEffectiveOpacity(p->effectiveOpacity()); - else - d_ptr->resolveEffectiveOpacity(1.0); - } + if ((flags & opacityFlagsMask) != (oldFlags & opacityFlagsMask)) + d_ptr->updateEffectiveOpacity(); if (!(d_ptr->flags & ItemIsFocusable) && hasFocus()) { // Clear focus on the item if it has focus when the focusable flag @@ -1275,6 +1264,9 @@ void QGraphicsItem::setFlags(GraphicsItemFlags flags) d_ptr->updateAncestorFlag(ItemClipsChildrenToShape); } + if ((flags & ItemClipsToShape) != (oldFlags & ItemClipsToShape)) + d_ptr->invalidateCachedClipPath(); + if ((flags & ItemIgnoresTransformations) != (oldFlags & ItemIgnoresTransformations)) { // Item children clipping changes. Propagate the ancestor flag to // all children. @@ -1282,7 +1274,7 @@ void QGraphicsItem::setFlags(GraphicsItemFlags flags) } // ### Why updateHelper? - d_ptr->updateHelper(); + d_ptr->updateHelper(QRectF(), false, true); // Notify change. itemChange(ItemFlagsHaveChanged, quint32(flags)); @@ -1380,9 +1372,9 @@ QString QGraphicsItem::toolTip() const */ void QGraphicsItem::setToolTip(const QString &toolTip) { - QString newCursor = itemChange(ItemToolTipChange, toolTip).toString(); - d_ptr->setExtra(QGraphicsItemPrivate::ExtraToolTip, toolTip); - itemChange(ItemToolTipHasChanged, toolTip); + const QVariant toolTipVariant(itemChange(ItemToolTipChange, toolTip)); + d_ptr->setExtra(QGraphicsItemPrivate::ExtraToolTip, toolTipVariant.toString()); + itemChange(ItemToolTipHasChanged, toolTipVariant); } #endif // QT_NO_TOOLTIP @@ -1424,9 +1416,8 @@ QCursor QGraphicsItem::cursor() const */ void QGraphicsItem::setCursor(const QCursor &cursor) { - QCursor newCursor = qVariantValue<QCursor>(itemChange(ItemCursorChange, - qVariantFromValue<QCursor>(cursor))); - d_ptr->setExtra(QGraphicsItemPrivate::ExtraCursor, newCursor); + const QVariant cursorVariant(itemChange(ItemCursorChange, qVariantFromValue<QCursor>(cursor))); + d_ptr->setExtra(QGraphicsItemPrivate::ExtraCursor, qVariantValue<QCursor>(cursorVariant)); d_ptr->hasCursor = 1; if (d_ptr->scene) { foreach (QGraphicsView *view, d_ptr->scene->views()) { @@ -1443,7 +1434,7 @@ void QGraphicsItem::setCursor(const QCursor &cursor) } } } - itemChange(ItemCursorHasChanged, qVariantFromValue<QCursor>(newCursor)); + itemChange(ItemCursorHasChanged, cursorVariant); } /*! @@ -1537,14 +1528,20 @@ void QGraphicsItemPrivate::setVisibleHelper(bool newVisible, bool explicitly, bo return; // Modify the property. - newVisible = q_ptr->itemChange(QGraphicsItem::ItemVisibleChange, quint32(newVisible)).toBool(); + const QVariant newVisibleVariant(q_ptr->itemChange(QGraphicsItem::ItemVisibleChange, + quint32(newVisible))); + newVisible = newVisibleVariant.toBool(); if (visible == quint32(newVisible)) return; visible = newVisible; // Schedule redrawing - if (update) + if (update) { + QGraphicsItemCache *c = (QGraphicsItemCache *)qVariantValue<void *>(extra(ExtraCacheData)); + if (c) + c->purge(); updateHelper(QRectF(), /* force = */ true); + } // Certain properties are dropped as an item becomes invisible. if (!newVisible) { @@ -1580,9 +1577,10 @@ void QGraphicsItemPrivate::setVisibleHelper(bool newVisible, bool explicitly, bo } // Update children with explicitly = false. + const bool updateChildren = update && !(flags & QGraphicsItem::ItemClipsChildrenToShape); foreach (QGraphicsItem *child, children) { if (!newVisible || !child->d_ptr->explicitlyHidden) - child->d_ptr->setVisibleHelper(newVisible, false); + child->d_ptr->setVisibleHelper(newVisible, false, updateChildren); } // Enable subfocus @@ -1594,7 +1592,7 @@ void QGraphicsItemPrivate::setVisibleHelper(bool newVisible, bool explicitly, bo } // Deliver post-change notification. - q_ptr->itemChange(QGraphicsItem::ItemVisibleHasChanged, quint32(visible)); + q_ptr->itemChange(QGraphicsItem::ItemVisibleHasChanged, newVisibleVariant); } /*! @@ -1700,7 +1698,9 @@ void QGraphicsItemPrivate::setEnabledHelper(bool newEnabled, bool explicitly, bo } // Modify the property. - enabled = q_ptr->itemChange(QGraphicsItem::ItemEnabledChange, quint32(newEnabled)).toBool(); + const QVariant newEnabledVariant(q_ptr->itemChange(QGraphicsItem::ItemEnabledChange, + quint32(newEnabled))); + enabled = newEnabledVariant.toBool(); // Schedule redraw. if (update) @@ -1712,7 +1712,7 @@ void QGraphicsItemPrivate::setEnabledHelper(bool newEnabled, bool explicitly, bo } // Deliver post-change notification. - q_ptr->itemChange(QGraphicsItem::ItemEnabledHasChanged, quint32(enabled)); + q_ptr->itemChange(QGraphicsItem::ItemEnabledHasChanged, newEnabledVariant); } /*! @@ -1799,7 +1799,8 @@ void QGraphicsItem::setSelected(bool selected) selected = false; if (d_ptr->selected == selected) return; - bool newSelected = itemChange(ItemSelectedChange, quint32(selected)).toBool(); + const QVariant newSelectedVariant(itemChange(ItemSelectedChange, quint32(selected))); + bool newSelected = newSelectedVariant.toBool(); if (d_ptr->selected == newSelected) return; d_ptr->selected = newSelected; @@ -1819,7 +1820,7 @@ void QGraphicsItem::setSelected(bool selected) } // Deliver post-change notification. - itemChange(QGraphicsItem::ItemSelectedHasChanged, quint32(d_ptr->selected)); + itemChange(QGraphicsItem::ItemSelectedHasChanged, newSelectedVariant); } /*! @@ -1863,6 +1864,9 @@ qreal QGraphicsItem::opacity() const */ qreal QGraphicsItem::effectiveOpacity() const { + if (!d_ptr->hasEffectiveOpacity) + return qreal(1.0); + QVariant effectiveOpacity = d_ptr->extra(QGraphicsItemPrivate::ExtraEffectiveOpacity); return effectiveOpacity.isNull() ? qreal(1.0) : qreal(effectiveOpacity.toDouble()); } @@ -1892,7 +1896,8 @@ qreal QGraphicsItem::effectiveOpacity() const void QGraphicsItem::setOpacity(qreal opacity) { // Notify change. - qreal newOpacity = itemChange(ItemOpacityChange, double(opacity)).toDouble(); + const QVariant newOpacityVariant(itemChange(ItemOpacityChange, double(opacity))); + qreal newOpacity = newOpacityVariant.toDouble(); // Normalize. newOpacity = qBound<qreal>(0.0, newOpacity, 1.0); @@ -1921,7 +1926,7 @@ void QGraphicsItem::setOpacity(qreal opacity) itemChange(ItemOpacityHasChanged, newOpacity); // Update. - d_ptr->fullUpdateHelper(); + d_ptr->fullUpdateHelper(/*childrenOnly=*/false, /*maybeDirtyClipPath=*/false, /*ignoreOpacity=*/true); } /*! @@ -2350,19 +2355,22 @@ QPointF QGraphicsItem::scenePos() const the item is also updated; otherwise it is not updated before and after the change. */ -void QGraphicsItemPrivate::setPosHelper(const QPointF &pos, bool update) +void QGraphicsItemPrivate::setPosHelper(const QPointF &pos) { Q_Q(QGraphicsItem); if (this->pos == pos) return; // Notify the item that the position is changing. - QPointF newPos = q->itemChange(QGraphicsItem::ItemPositionChange, pos).toPointF(); + const QVariant newPosVariant(q->itemChange(QGraphicsItem::ItemPositionChange, pos)); + QPointF newPos = newPosVariant.toPointF(); if (newPos == this->pos) return; // Update and repositition. - if (scene && update) { + inSetPosHelper = 1; + updateCachedClipPathFromSetPosHelper(newPos); + if (scene) { fullUpdateHelper(true); q->prepareGeometryChange(); } @@ -2370,7 +2378,8 @@ void QGraphicsItemPrivate::setPosHelper(const QPointF &pos, bool update) invalidateSceneTransformCache(); // Send post-notification. - q->itemChange(QGraphicsItem::ItemPositionHasChanged, newPos); + q->itemChange(QGraphicsItem::ItemPositionHasChanged, newPosVariant); + inSetPosHelper = 0; } /*! @@ -2385,7 +2394,7 @@ void QGraphicsItemPrivate::setPosHelper(const QPointF &pos, bool update) */ void QGraphicsItem::setPos(const QPointF &pos) { - d_ptr->setPosHelper(pos, /* update = */ true); + d_ptr->setPosHelper(pos); } /*! @@ -2529,10 +2538,10 @@ QTransform QGraphicsItem::sceneTransform() const QTransform m; if (d_ptr->hasTransform) { m = transform(); - m *= QTransform::fromTranslate(d_ptr->pos.x(), d_ptr->pos.y()); - } else { - // ### ? QTransform::fromTranslate(d_ptr->pos.x(), d_ptr->pos.y()) - m.translate(d_ptr->pos.x(), d_ptr->pos.y()); + if (!d_ptr->pos.isNull()) + m *= QTransform::fromTranslate(d_ptr->pos.x(), d_ptr->pos.y()); + } else if (!d_ptr->pos.isNull()) { + m = QTransform::fromTranslate(d_ptr->pos.x(), d_ptr->pos.y()); } // Combine with parent and add to cache. @@ -2657,6 +2666,8 @@ QTransform QGraphicsItem::itemTransform(const QGraphicsItem *other, bool *ok) co if (ok) *ok = true; const QPointF &itemPos = d_ptr->pos; + if (itemPos.isNull()) + return d_ptr->hasTransform ? transform() : QTransform(); if (d_ptr->hasTransform) return transform() * QTransform::fromTranslate(itemPos.x(), itemPos.y()); return QTransform::fromTranslate(itemPos.x(), itemPos.y()); @@ -2667,7 +2678,8 @@ QTransform QGraphicsItem::itemTransform(const QGraphicsItem *other, bool *ok) co const QPointF &otherPos = other->d_ptr->pos; if (other->d_ptr->hasTransform) { QTransform otherToParent = other->transform(); - otherToParent *= QTransform::fromTranslate(otherPos.x(), otherPos.y()); + if (!otherPos.isNull()) + otherToParent *= QTransform::fromTranslate(otherPos.x(), otherPos.y()); return otherToParent.inverted(ok); } else { if (ok) @@ -2692,11 +2704,11 @@ QTransform QGraphicsItem::itemTransform(const QGraphicsItem *other, bool *ok) co QTransform itemToParent = QTransform::fromTranslate(itemPos.x(), itemPos.y()); if (hasTr) - itemToParent = transform() * itemToParent; + itemToParent = itemPos.isNull() ? transform() : transform() * itemToParent; QTransform otherToParent = QTransform::fromTranslate(otherPos.x(), otherPos.y()); if (otherHasTr) - otherToParent = other->transform() * otherToParent; + otherToParent = otherPos.isNull() ? other->transform() : other->transform() * otherToParent; return itemToParent * otherToParent.inverted(ok); } @@ -2736,7 +2748,8 @@ QTransform QGraphicsItem::itemTransform(const QGraphicsItem *other, bool *ok) co const QGraphicsItemPrivate *pd = p->d_ptr; if (pd->hasTransform) x *= p->transform(); - x *= QTransform::fromTranslate(pd->pos.x(), pd->pos.y()); + if (!pd->pos.isNull()) + x *= QTransform::fromTranslate(pd->pos.x(), pd->pos.y()); } while ((p = p->d_ptr->parent) && p != root); if (parentOfOther) return x.inverted(ok); @@ -2777,16 +2790,15 @@ void QGraphicsItem::setMatrix(const QMatrix &matrix, bool combine) if (oldTransform == newTransform) return; - // Notify the item that the transformation matrix is changing. - QVariant variant; - qVariantSetValue<QMatrix>(variant, newTransform.toAffine()); - newTransform = QTransform(qVariantValue<QMatrix>(itemChange(ItemMatrixChange, variant))); - + // Notify the item that the matrix is changing. + QVariant newTransformVariant(itemChange(ItemMatrixChange, + qVariantFromValue<QMatrix>(newTransform.toAffine()))); + newTransform = QTransform(qVariantValue<QMatrix>(newTransformVariant)); if (oldTransform == newTransform) return; // Update and set the new transformation. - d_ptr->fullUpdateHelper(true); + d_ptr->fullUpdateHelper(true, true); prepareGeometryChange(); transformData->baseTransform = newTransform; transformData->dirty = true; @@ -2794,7 +2806,9 @@ void QGraphicsItem::setMatrix(const QMatrix &matrix, bool combine) d_ptr->invalidateSceneTransformCache(); // Send post-notification. - itemChange(ItemTransformHasChanged, newTransform); + // NB! We have to change the value from QMatrix to QTransform. + qVariantSetValue<QTransform>(newTransformVariant, newTransform); + itemChange(ItemTransformHasChanged, newTransformVariant); } /*! @@ -2836,14 +2850,14 @@ void QGraphicsItem::setTransform(const QTransform &matrix, bool combine) return; // Notify the item that the transformation matrix is changing. - QVariant variant; - qVariantSetValue<QTransform>(variant, newTransform); - newTransform = qVariantValue<QTransform>(itemChange(ItemTransformChange, variant)); + const QVariant newTransformVariant(itemChange(ItemTransformChange, + qVariantFromValue<QTransform>(newTransform))); + newTransform = qVariantValue<QTransform>(newTransformVariant); if (oldTransform == newTransform) return; // Update and set the new transformation. - d_ptr->fullUpdateHelper(true); + d_ptr->fullUpdateHelper(true, true); prepareGeometryChange(); transformData->baseTransform = newTransform; transformData->dirty = true; @@ -2852,7 +2866,7 @@ void QGraphicsItem::setTransform(const QTransform &matrix, bool combine) d_ptr->invalidateSceneTransformCache(); // Send post-notification. - itemChange(ItemTransformHasChanged, newTransform); + itemChange(ItemTransformHasChanged, newTransformVariant); } /*! @@ -3191,7 +3205,8 @@ qreal QGraphicsItem::zValue() const */ void QGraphicsItem::setZValue(qreal z) { - qreal newZ = qreal(itemChange(ItemZValueChange, double(z)).toDouble()); + const QVariant newZVariant(itemChange(ItemZValueChange, double(z))); + qreal newZ = qreal(newZVariant.toDouble()); if (newZ == d_ptr->z) return; d_ptr->z = z; @@ -3203,7 +3218,7 @@ void QGraphicsItem::setZValue(qreal z) d_ptr->scene->d_func()->invalidateSortCache(); } - itemChange(ItemZValueHasChanged, double(newZ)); + itemChange(ItemZValueHasChanged, newZVariant); } /*! @@ -3228,7 +3243,9 @@ QRectF QGraphicsItem::childrenBoundingRect() const QRectF childRect; foreach (QGraphicsItem *child, children()) { QPointF childPos = child->pos(); - QTransform matrix = child->transform() * QTransform::fromTranslate(childPos.x(), childPos.y()); + QTransform matrix = child->transform(); + if (!childPos.isNull()) + matrix *= QTransform::fromTranslate(childPos.x(), childPos.y()); childRect |= matrix.mapRect(child->boundingRect() | child->childrenBoundingRect()); } return childRect; @@ -3360,57 +3377,79 @@ bool QGraphicsItem::isClipped() const QPainterPath QGraphicsItem::clipPath() const { Q_D(const QGraphicsItem); - QPainterPath clip; - if (!isClipped()) - return clip; + if (!d->dirtyClipPath) + return d->emptyClipPath ? QPainterPath() : d->cachedClipPath; + + if (!isClipped()) { + d_ptr->setCachedClipPath(QPainterPath()); + return d->cachedClipPath; + } + + const QRectF thisBoundingRect(boundingRect()); + if (thisBoundingRect.isEmpty()) { + if (d_ptr->flags & ItemClipsChildrenToShape) + d_ptr->setEmptyCachedClipPathRecursively(); + else + d_ptr->setEmptyCachedClipPath(); + return QPainterPath(); + } + QPainterPath clip; // Start with the item's bounding rect. - clip.addRect(boundingRect()); + clip.addRect(thisBoundingRect); - bool clipAway = false; if (d->ancestorFlags & QGraphicsItemPrivate::AncestorClipsChildren) { - // Make list of parents up to the farthest ancestor that clips its - // children to its shape. - QVarLengthArray<const QGraphicsItem *, 32> clippingAncestors; - const QGraphicsItem *parent = parentItem(); - const QGraphicsItem *clipOwner = 0; - do { + const QGraphicsItem *parent = this; + const QGraphicsItem *lastParent = this; + + // Intersect any in-between clips starting at the top and moving downwards. + bool foundValidClipPath = false; + while ((parent = parent->d_ptr->parent)) { if (parent->d_ptr->flags & ItemClipsChildrenToShape) { - clippingAncestors.append(parent); - clipOwner = parent; - } - } while ((parent->d_ptr->ancestorFlags & QGraphicsItemPrivate::AncestorClipsChildren) && (parent = parent->parentItem())); + // Map clip to the current parent and intersect with its shape/clipPath + clip = lastParent->itemTransform(parent).map(clip); + if ((foundValidClipPath = !parent->d_ptr->dirtyClipPath && parent->isClipped())) { + if (parent->d_ptr->emptyClipPath) { + if (d_ptr->flags & ItemClipsChildrenToShape) + d_ptr->setEmptyCachedClipPathRecursively(); + else + d_ptr->setEmptyCachedClipPath(); + return QPainterPath(); + } + clip = clip.intersected(parent->d_ptr->cachedClipPath); + if (!(parent->d_ptr->flags & ItemClipsToShape)) + clip = clip.intersected(parent->shape()); + } else { + clip = clip.intersected(parent->shape()); + } - // Start with the topmost clip. - QPainterPath parentClip = clipOwner->shape(); + if (clip.isEmpty()) { + if (d_ptr->flags & ItemClipsChildrenToShape) + d_ptr->setEmptyCachedClipPathRecursively(); + else + d_ptr->setEmptyCachedClipPath(); + return clip; + } + lastParent = parent; + } - // Intersect any in-between clips starting at the bottom and moving - // upwards. - for (int i = clippingAncestors.size() - 2; i >= 0; --i) { - const QGraphicsItem *item = clippingAncestors[i]; - // ### what if itemtransform fails - if (clipOwner) - parentClip = clipOwner->itemTransform(item).map(parentClip); - parentClip = parentClip.intersected(item->shape()); - if (parentClip.isEmpty()) { - clip = parentClip; - clipAway = true; + if (!(parent->d_ptr->ancestorFlags & QGraphicsItemPrivate::AncestorClipsChildren) + || foundValidClipPath) { break; } - clipOwner = item; } - if (!clipAway) { + if (lastParent != this) { + // Map clip back to the item's transform. // ### what if itemtransform fails - clip = clip.intersected(clipOwner->itemTransform(this).map(parentClip)); - if (clip.isEmpty()) - clipAway = true; + clip = lastParent->itemTransform(this).map(clip); } } - if (!clipAway && d->flags & ItemClipsToShape) + if (d->flags & ItemClipsToShape) clip = clip.intersected(shape()); + d_ptr->setCachedClipPath(clip); return clip; } @@ -3432,10 +3471,16 @@ bool QGraphicsItem::contains(const QPointF &point) const } /*! - Returns true if this item collides with \a other; otherwise returns false. - The ways items collide is determined by \a mode. The default value for \a - mode is Qt::IntersectsItemShape; \a other collides with this item if it - either intersects, contains, or is contained by this item's shape. + + Returns true if this item collides with \a other; otherwise + returns false. + + The \a mode is applied to \a other, and the resulting shape or + bounding rectangle is then compared to this item's shape. The + default value for \a mode is Qt::IntersectsItemShape; \a other + collides with this item if it either intersects, contains, or is + contained by this item's shape (see Qt::ItemSelectionMode for + details). The default implementation is based on shape intersection, and it calls shape() on both items. Because the complexity of arbitrary shape-shape @@ -3490,6 +3535,11 @@ bool QGraphicsItem::collidesWithItem(const QGraphicsItem *other, Qt::ItemSelecti Qt::IntersectsItemShape; \a path collides with this item if it either intersects, contains, or is contained by this item's shape. + Note that this function checks whether the item's shape or + bounding rectangle (depending on \a mode) is contained within \a + path, and not whether \a path is contained within the items shape + or bounding rectangle. + \sa collidesWithItem(), contains(), shape() */ bool QGraphicsItem::collidesWithPath(const QPainterPath &path, Qt::ItemSelectionMode mode) const @@ -3499,8 +3549,10 @@ bool QGraphicsItem::collidesWithPath(const QPainterPath &path, Qt::ItemSelection return false; } - QRectF rectA = _q_adjustedRect(boundingRect()); - QRectF rectB = _q_adjustedRect(path.controlPointRect()); + QRectF rectA(boundingRect()); + _q_adjustRect(&rectA); + QRectF rectB(path.controlPointRect()); + _q_adjustRect(&rectB); if (!rectA.intersects(rectB)) { // This we can determine efficiently. If the two rects neither // intersect nor contain eachother, then the two items do not collide. @@ -3509,12 +3561,11 @@ bool QGraphicsItem::collidesWithPath(const QPainterPath &path, Qt::ItemSelection // For further testing, we need this item's shape or bounding rect. QPainterPath thisShape; - if (mode == Qt::IntersectsItemShape || mode == Qt::ContainsItemShape) { + if (mode == Qt::IntersectsItemShape || mode == Qt::ContainsItemShape) thisShape = (isClipped() && !d_ptr->localCollisionHack) ? clipPath() : shape(); - } else { - thisShape.addPolygon(_q_adjustedRect(boundingRect())); - thisShape.closeSubpath(); - } + else + thisShape.addRect(rectA); + if (thisShape == QPainterPath()) { // Empty shape? No collision. return false; @@ -3529,11 +3580,12 @@ bool QGraphicsItem::collidesWithPath(const QPainterPath &path, Qt::ItemSelection /*! Returns a list of all items that collide with this item. - The way collisions are detected is determined by \a mode. The default - value for \a mode is Qt::IntersectsItemShape; All items whose shape - intersects or is contained by this item's shape are returned. + The way collisions are detected is determined by applying \a mode + to items that are compared to this item, i.e., each item's shape + or bounding rectangle is checked against this item's shape. The + default value for \a mode is Qt::IntersectsItemShape. - \sa QGraphicsScene::collidingItems(), collidesWithItem() + \sa collidesWithItem() */ QList<QGraphicsItem *> QGraphicsItem::collidingItems(Qt::ItemSelectionMode mode) const { @@ -3684,7 +3736,8 @@ QRegion QGraphicsItem::boundingRegion(const QTransform &itemToDeviceTransform) c // into the bitmap, converts the result to a QRegion and scales the region // back to device space with inverse granularity. qreal granularity = boundingRegionGranularity(); - QRect deviceRect = _q_adjustedRect(itemToDeviceTransform.mapRect(boundingRect()).toRect()); + QRect deviceRect = itemToDeviceTransform.mapRect(boundingRect()).toRect(); + _q_adjustRect(&deviceRect); if (granularity == 0.0) return QRegion(deviceRect); @@ -3814,6 +3867,23 @@ void QGraphicsItem::setBoundingRegionGranularity(qreal granularity) /*! \internal + Returns true if we can discard an update request; otherwise false. +*/ +bool QGraphicsItemPrivate::discardUpdateRequest(bool ignoreClipping, bool ignoreVisibleBit, + bool ignoreDirtyBit, bool ignoreOpacity) const +{ + // No scene, or if the scene is updating everything, means we have nothing + // to do. The only exception is if the scene tracks the growing scene rect. + return (!visible && !ignoreVisibleBit) + || (dirty && !ignoreDirtyBit) + || !scene + || (scene->d_func()->updateAll && scene->d_func()->hasSceneRect) + || (!ignoreClipping && (childrenClippedToShape() && isClippedAway())) + || (!ignoreOpacity && childrenCombineOpacity() && isFullyTransparent()); +} + +/*! + \internal Asks the scene to mark this item's scene rect as dirty, requesting a redraw. This does not invalidate any cache. @@ -3822,19 +3892,16 @@ void QGraphicsItem::setBoundingRegionGranularity(qreal granularity) only case where the item's background should be marked as dirty even when the item isn't visible. */ -void QGraphicsItemPrivate::updateHelper(const QRectF &rect, bool force) +void QGraphicsItemPrivate::updateHelper(const QRectF &rect, bool force, bool maybeDirtyClipPath) { // No scene, or if the scene is updating everything, means we have nothing // to do. The only exception is if the scene tracks the growing scene rect. - if (dirty) + if (discardUpdateRequest(/*ignoreClipping=*/maybeDirtyClipPath, /*ignoreVisibleBit=*/force)) return; - if (!scene || (scene && scene->d_func()->updateAll && scene->d_func()->hasSceneRect)) - return; - if (scene && (visible || force)) { - if (rect.isNull()) - dirty = 1; - scene->itemUpdated(q_ptr, rect); - } + + if (rect.isNull()) + dirty = 1; + scene->itemUpdated(q_ptr, rect); } /*! @@ -3842,21 +3909,24 @@ void QGraphicsItemPrivate::updateHelper(const QRectF &rect, bool force) Propagates updates to \a item and all its children. */ -void QGraphicsItemPrivate::fullUpdateHelper(bool childrenOnly) +void QGraphicsItemPrivate::fullUpdateHelper(bool childrenOnly, bool maybeDirtyClipPath, bool ignoreOpacity) { - // No scene, or if the scene is updating everything, means we have nothing - // to do. The only exception is if the scene tracks the growing scene rect. - if (!scene || (scene && scene->d_func()->updateAll && scene->d_func()->hasSceneRect)) - return; - if (!childrenOnly && !dirty) - updateHelper(); - if (children.isEmpty() || dirtyChildren) + if (discardUpdateRequest(/*ignoreClipping=*/maybeDirtyClipPath, /*ignoreVisibleBit=*/false, + /*ignoreDirtyBit=*/true, ignoreOpacity)) { return; - if (flags & QGraphicsItem::ItemClipsChildrenToShape) { - // ### mark all children dirty? + } + + if (!childrenOnly && !dirty) { + // Effectively the same as updateHelper(QRectF(), false, maybeDirtyClipPath). + dirty = 1; + scene->itemUpdated(q_ptr, QRectF()); + } + + if (dirtyChildren || childrenClippedToShape()) { // Unnecessary to update children as well. return; } + if (ancestorFlags & AncestorClipsChildren) { Q_Q(QGraphicsItem); // Check if we can avoid updating all children. @@ -3879,10 +3949,36 @@ void QGraphicsItemPrivate::fullUpdateHelper(bool childrenOnly) } } foreach (QGraphicsItem *child, children) - child->d_ptr->fullUpdateHelper(); + child->d_ptr->fullUpdateHelper(false, maybeDirtyClipPath); dirtyChildren = 1; } +static inline bool qt_allChildrenCombineOpacity(QGraphicsItem *parent) +{ + Q_ASSERT(parent); + if (parent->flags() & QGraphicsItem::ItemDoesntPropagateOpacityToChildren) + return false; + + const QList<QGraphicsItem *> children(parent->childItems()); + for (int i = 0; i < children.size(); ++i) { + if (children.at(i)->flags() & QGraphicsItem::ItemIgnoresParentOpacity) + return false; + } + return true; +} + +void QGraphicsItemPrivate::updateEffectiveOpacity() +{ + Q_Q(QGraphicsItem); + if (parent) { + resolveEffectiveOpacity(parent->effectiveOpacity()); + parent->d_ptr->allChildrenCombineOpacity = qt_allChildrenCombineOpacity(parent); + } else { + resolveEffectiveOpacity(1.0); + } + allChildrenCombineOpacity = qt_allChildrenCombineOpacity(q); +} + /*! \internal @@ -3907,7 +4003,14 @@ void QGraphicsItemPrivate::resolveEffectiveOpacity(qreal parentEffectiveOpacity) } // Set this item's resolved opacity. - setExtra(ExtraEffectiveOpacity, myEffectiveOpacity); + if (qFuzzyCompare(myEffectiveOpacity, qreal(1.0))) { + // Opaque, unset effective opacity. + hasEffectiveOpacity = 0; + unsetExtra(ExtraEffectiveOpacity); + } else { + hasEffectiveOpacity = 1; + setExtra(ExtraEffectiveOpacity, myEffectiveOpacity); + } // Resolve children always. for (int i = 0; i < children.size(); ++i) @@ -3960,6 +4063,109 @@ void QGraphicsItemPrivate::removeExtraItemCache() unsetExtra(ExtraCacheData); } +void QGraphicsItemPrivate::setEmptyCachedClipPathRecursively(const QRectF &emptyIfOutsideThisRect) +{ + setEmptyCachedClipPath(); + + const bool checkRect = !emptyIfOutsideThisRect.isNull() + && !(flags & QGraphicsItem::ItemClipsChildrenToShape); + for (int i = 0; i < children.size(); ++i) { + if (!checkRect) { + children.at(i)->d_ptr->setEmptyCachedClipPathRecursively(); + continue; + } + + QGraphicsItem *child = children.at(i); + const QRectF rect = child->mapRectFromParent(emptyIfOutsideThisRect); + if (rect.intersects(child->boundingRect())) + child->d_ptr->invalidateCachedClipPathRecursively(false, rect); + else + child->d_ptr->setEmptyCachedClipPathRecursively(rect); + } +} + +void QGraphicsItemPrivate::invalidateCachedClipPathRecursively(bool childrenOnly, const QRectF &emptyIfOutsideThisRect) +{ + if (!childrenOnly) + invalidateCachedClipPath(); + + const bool checkRect = !emptyIfOutsideThisRect.isNull(); + for (int i = 0; i < children.size(); ++i) { + if (!checkRect) { + children.at(i)->d_ptr->invalidateCachedClipPathRecursively(false); + continue; + } + + QGraphicsItem *child = children.at(i); + const QRectF rect = child->mapRectFromParent(emptyIfOutsideThisRect); + if (rect.intersects(child->boundingRect())) + child->d_ptr->invalidateCachedClipPathRecursively(false, rect); + else + child->d_ptr->setEmptyCachedClipPathRecursively(rect); + } +} + +void QGraphicsItemPrivate::updateCachedClipPathFromSetPosHelper(const QPointF &newPos) +{ + Q_ASSERT(inSetPosHelper); + + if (!(ancestorFlags & QGraphicsItemPrivate::AncestorClipsChildren)) + return; // Not clipped by any ancestor. + + // Find closest clip ancestor and transform. + Q_Q(QGraphicsItem); + QTransform thisToParentTransform = hasTransform + ? q->transform() * QTransform::fromTranslate(newPos.x(), newPos.y()) + : QTransform::fromTranslate(newPos.x(), newPos.y()); + QGraphicsItem *clipParent = parent; + while (clipParent && !(clipParent->d_ptr->flags & QGraphicsItem::ItemClipsChildrenToShape)) { + if (clipParent->d_ptr->hasTransform) + thisToParentTransform *= clipParent->transform(); + if (!clipParent->d_ptr->pos.isNull()) { + thisToParentTransform *= QTransform::fromTranslate(clipParent->d_ptr->pos.x(), + clipParent->d_ptr->pos.y()); + } + clipParent = clipParent->d_ptr->parent; + } + + // thisToParentTransform is now the same as q->itemTransform(clipParent), except + // that the new position (which is not yet set on the item) is taken into account. + Q_ASSERT(clipParent); + Q_ASSERT(clipParent->d_ptr->flags & QGraphicsItem::ItemClipsChildrenToShape); + + // From here everything is calculated in clip parent's coordinates. + const QRectF parentBoundingRect(clipParent->boundingRect()); + const QRectF thisBoundingRect(thisToParentTransform.mapRect(q->boundingRect())); + + if (!parentBoundingRect.intersects(thisBoundingRect)) { + // Item is moved outside the clip parent's bounding rect, + // i.e. it is fully clipped and the clip path is empty. + if (flags & QGraphicsItem::ItemClipsChildrenToShape) + setEmptyCachedClipPathRecursively(); + else + setEmptyCachedClipPathRecursively(thisToParentTransform.inverted().mapRect(parentBoundingRect)); + return; + } + + const QPainterPath parentClip(clipParent->isClipped() ? clipParent->clipPath() : clipParent->shape()); + if (parentClip.contains(thisBoundingRect)) + return; // Item is inside the clip parent's shape. No update required. + + const QRectF parentClipRect(parentClip.controlPointRect()); + if (!parentClipRect.intersects(thisBoundingRect)) { + // Item is moved outside the clip parent's shape, + // i.e. it is fully clipped and the clip path is empty. + if (flags & QGraphicsItem::ItemClipsChildrenToShape) + setEmptyCachedClipPathRecursively(); + else + setEmptyCachedClipPathRecursively(thisToParentTransform.inverted().mapRect(parentClipRect)); + } else { + // Item is partially inside the clip parent's shape, + // i.e. the cached clip path must be invalidated. + invalidateCachedClipPathRecursively(false, thisToParentTransform.inverted().mapRect(parentClipRect)); + } +} + /*! \internal @@ -3990,20 +4196,35 @@ bool QGraphicsItemPrivate::isProxyWidget() const */ void QGraphicsItem::update(const QRectF &rect) { - if (d_ptr->dirty) + if (rect.isEmpty() && !rect.isNull()) return; - if (d_ptr->scene && isVisible()) { - if (CacheMode(d_ptr->cacheMode) != NoCache) { - QGraphicsItemCache *cache = d_ptr->extraItemCache(); - if (rect.isNull()) { - cache->allExposed = true; - cache->exposed.clear(); - } else { - cache->exposed.append(rect); - } + + if (CacheMode(d_ptr->cacheMode) != NoCache) { + QGraphicsItemCache *cache = d_ptr->extraItemCache(); + if (d_ptr->discardUpdateRequest(/* ignoreVisibleBit = */ false, + /* ignoreClipping = */ false, + /* ignoreDirtyBit = */ true)) { + return; } - d_ptr->updateHelper(rect); + + // Invalidate cache. + if (rect.isNull()) { + cache->allExposed = true; + cache->exposed.clear(); + } else { + cache->exposed.append(rect); + } + // Only invalidate cache; item is already dirty. + if (d_ptr->dirty) + return; + } else if (d_ptr->discardUpdateRequest()) { + return; } + + // Effectively the same as updateHelper(rect); + if (rect.isNull()) + d_ptr->dirty = 1; + d_ptr->scene->itemUpdated(this, rect); } @@ -4260,9 +4481,9 @@ QPolygonF QGraphicsItem::mapToItem(const QGraphicsItem *item, const QRectF &rect */ QPolygonF QGraphicsItem::mapToParent(const QRectF &rect) const { - if (!d_ptr->hasTransform) - return QPolygonF(rect.translated(d_ptr->pos)); - return transform().map(rect.translated(d_ptr->pos)); + QPolygonF p = !d_ptr->hasTransform ? rect : transform().map(rect); + p.translate(d_ptr->pos); + return p; } /*! @@ -4329,8 +4550,8 @@ QRectF QGraphicsItem::mapRectToItem(const QGraphicsItem *item, const QRectF &rec */ QRectF QGraphicsItem::mapRectToParent(const QRectF &rect) const { - QRectF r = rect.translated(d_ptr->pos.x(), d_ptr->pos.y()); - return !d_ptr->hasTransform ? r : transform().mapRect(r); + QRectF r = !d_ptr->hasTransform ? rect : transform().mapRect(rect); + return r.translated(d_ptr->pos); } /*! @@ -4461,9 +4682,9 @@ QPolygonF QGraphicsItem::mapToItem(const QGraphicsItem *item, const QPolygonF &p */ QPolygonF QGraphicsItem::mapToParent(const QPolygonF &polygon) const { - QPolygonF p = polygon; + QPolygonF p = !d_ptr->hasTransform ? polygon : transform().map(polygon); p.translate(d_ptr->pos); - return d_ptr->hasTransform ? transform().map(p) : p; + return p; } /*! @@ -4505,7 +4726,10 @@ QPainterPath QGraphicsItem::mapToItem(const QGraphicsItem *item, const QPainterP */ QPainterPath QGraphicsItem::mapToParent(const QPainterPath &path) const { - return d_ptr->parent ? itemTransform(d_ptr->parent).map(path) : mapToScene(path); + QTransform x = QTransform::fromTranslate(d_ptr->pos.x(), d_ptr->pos.y()); + if (d_ptr->hasTransform) + x = transform() * x; + return x.map(path); } /*! @@ -5735,11 +5959,18 @@ void QGraphicsItem::removeFromIndex() void QGraphicsItem::prepareGeometryChange() { if (d_ptr->scene) { - d_ptr->updateHelper(); - + d_ptr->updateHelper(QRectF(), false, /*maybeDirtyClipPath=*/!d_ptr->inSetPosHelper); QGraphicsScenePrivate *scenePrivate = d_ptr->scene->d_func(); scenePrivate->removeFromIndex(this); } + + if (d_ptr->inSetPosHelper) + return; + + if (d_ptr->flags & ItemClipsChildrenToShape) + d_ptr->invalidateCachedClipPathRecursively(); + else + d_ptr->invalidateCachedClipPath(); } /*! @@ -7253,6 +7484,7 @@ QVariant QGraphicsLineItem::extension(const QVariant &variant) const QPixmap::createHeuristicMask(). The performance and memory consumption is similar to MaskShape. */ +extern QPainterPath qt_regionToPath(const QRegion ®ion); class QGraphicsPixmapItemPrivate : public QGraphicsItemPrivate { @@ -7273,7 +7505,6 @@ public: void updateShape() { - extern QPainterPath qt_regionToPath(const QRegion ®ion); shape = QPainterPath(); switch (shapeMode) { case QGraphicsPixmapItem::MaskShape: { @@ -8323,6 +8554,8 @@ void QGraphicsTextItem::setTabChangesFocus(bool b) Returns true if the \gui Tab key will cause the widget to change focus; otherwise, false is returned. + By default, this behavior is disabled, and this function will return false. + \sa setTabChangesFocus() */ bool QGraphicsTextItem::tabChangesFocus() const @@ -8514,6 +8747,7 @@ void QGraphicsSimpleTextItem::setText(const QString &text) return; d->text = text; d->updateBoundingRect(); + update(); } /*! @@ -8775,13 +9009,17 @@ void QGraphicsItemGroup::addToGroup(QGraphicsItem *item) QTransform oldSceneMatrix = item->sceneTransform(); item->setPos(mapFromItem(item, 0, 0)); item->setParentItem(this); - item->setTransform(oldSceneMatrix - * sceneTransform().inverted() - * QTransform::fromTranslate(-item->x(), -item->y())); + QTransform newItemTransform(oldSceneMatrix); + newItemTransform *= sceneTransform().inverted(); + if (!item->pos().isNull()) + newItemTransform *= QTransform::fromTranslate(-item->x(), -item->y()); + item->setTransform(newItemTransform); item->d_func()->setIsMemberOfGroup(true); prepareGeometryChange(); - d->itemsBoundingRect |= (item->transform() * QTransform::fromTranslate(item->x(), item->y())) - .mapRect(item->boundingRect() | item->childrenBoundingRect()); + QTransform itemTransform(item->transform()); + if (!item->pos().isNull()) + itemTransform *= QTransform::fromTranslate(item->x(), item->y()); + d->itemsBoundingRect |= itemTransform.mapRect(item->boundingRect() | item->childrenBoundingRect()); update(); } diff --git a/src/gui/graphicsview/qgraphicsitem_p.h b/src/gui/graphicsview/qgraphicsitem_p.h index c14b978..e8ab63d 100644 --- a/src/gui/graphicsview/qgraphicsitem_p.h +++ b/src/gui/graphicsview/qgraphicsitem_p.h @@ -142,10 +142,15 @@ public: hasBoundingRegionGranularity(0), flags(0), hasOpacity(0), + hasEffectiveOpacity(0), isWidget(0), dirty(0), dirtyChildren(0), localCollisionHack(0), + dirtyClipPath(1), + emptyClipPath(0), + inSetPosHelper(0), + allChildrenCombineOpacity(1), globalStackingOrder(-1), sceneTransformIndex(-1), q_ptr(0) @@ -166,11 +171,14 @@ public: virtual QVariant inputMethodQueryHelper(Qt::InputMethodQuery query) const; static bool movableAncestorIsSelected(const QGraphicsItem *item); - void setPosHelper(const QPointF &pos, bool update); + void setPosHelper(const QPointF &pos); void setVisibleHelper(bool newVisible, bool explicitly, bool update = true); void setEnabledHelper(bool newEnabled, bool explicitly, bool update = true); - void updateHelper(const QRectF &rect = QRectF(), bool force = false); - void fullUpdateHelper(bool childrenOnly = false); + bool discardUpdateRequest(bool ignoreClipping = false, bool ignoreVisibleBit = false, + bool ignoreDirtyBit = false, bool ignoreOpacity = false) const; + void updateHelper(const QRectF &rect = QRectF(), bool force = false, bool maybeDirtyClipPath = false); + void fullUpdateHelper(bool childrenOnly = false, bool maybeDirtyClipPath = false, bool ignoreOpacity = false); + void updateEffectiveOpacity(); void resolveEffectiveOpacity(qreal effectiveParentOpacity); void resolveDepth(int parentDepth); void invalidateSceneTransformCache(); @@ -243,6 +251,47 @@ public: QGraphicsItemCache *extraItemCache() const; void removeExtraItemCache(); + inline void setCachedClipPath(const QPainterPath &path) + { + cachedClipPath = path; + dirtyClipPath = 0; + emptyClipPath = 0; + } + + inline void setEmptyCachedClipPath() + { + emptyClipPath = 1; + dirtyClipPath = 0; + } + + void setEmptyCachedClipPathRecursively(const QRectF &emptyIfOutsideThisRect = QRectF()); + + inline void invalidateCachedClipPath() + { /*static int count = 0 ;qWarning("%i", ++count);*/ dirtyClipPath = 1; emptyClipPath = 0; } + + void invalidateCachedClipPathRecursively(bool childrenOnly = false, const QRectF &emptyIfOutsideThisRect = QRectF()); + void updateCachedClipPathFromSetPosHelper(const QPointF &newPos); + + inline bool isFullyTransparent() const + { return hasEffectiveOpacity && qFuzzyCompare(q_func()->effectiveOpacity() + 1, qreal(1.0)); } + + inline bool childrenCombineOpacity() const + { return allChildrenCombineOpacity || children.isEmpty(); } + + inline bool isClippedAway() const + { return !dirtyClipPath && q_func()->isClipped() && (emptyClipPath || cachedClipPath.isEmpty()); } + + inline bool childrenClippedToShape() const + { return (flags & QGraphicsItem::ItemClipsChildrenToShape) || children.isEmpty(); } + + inline bool isInvisible() const + { + return !visible + || (childrenClippedToShape() && isClippedAway()) + || (childrenCombineOpacity() && isFullyTransparent()); + } + + QPainterPath cachedClipPath; QPointF pos; qreal z; QGraphicsScene *scene; @@ -272,10 +321,15 @@ public: // New 32 bytes quint32 hasOpacity : 1; + quint32 hasEffectiveOpacity : 1; quint32 isWidget : 1; quint32 dirty : 1; quint32 dirtyChildren : 1; quint32 localCollisionHack : 1; + quint32 dirtyClipPath : 1; + quint32 emptyClipPath : 1; + quint32 inSetPosHelper : 1; + quint32 allChildrenCombineOpacity : 1; // Optional stacking order int globalStackingOrder; diff --git a/src/gui/graphicsview/qgraphicslayoutitem.cpp b/src/gui/graphicsview/qgraphicslayoutitem.cpp index 0ea7692..eaa97ff 100644 --- a/src/gui/graphicsview/qgraphicslayoutitem.cpp +++ b/src/gui/graphicsview/qgraphicslayoutitem.cpp @@ -117,7 +117,7 @@ QGraphicsLayoutItemPrivate::QGraphicsLayoutItemPrivate(QGraphicsLayoutItem *par, */ void QGraphicsLayoutItemPrivate::init() { - sizeHintCacheDirty = true; + sizeHintCacheDirty = true; sizePolicy = QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); } @@ -175,12 +175,12 @@ QSizeF *QGraphicsLayoutItemPrivate::effectiveSizeHints(const QSizeF &constraint) Returns the parent item of this layout, or 0 if this layout is not installed on any widget. - + If this is the item that the layout is installed on, it will return "itself". If the layout is a sub-layout, this function returns the parent widget of the parent layout. - + Note that it will traverse up the layout item hierarchy instead of just calling QGraphicsItem::parentItem(). This is on purpose. @@ -233,7 +233,7 @@ QGraphicsItem *QGraphicsLayoutItemPrivate::parentItem() const position. Calling setGeometry() will always resize and reposition the item immediately. Normally, this function is called by QGraphicsLayout after the layout has been activated, but it can also be called by the item's user - at any time. + at any time. The sizeHint() function returns the item' minimum, preferred and maximum size hints. You can override these properties by calling setMinimumSize(), @@ -360,7 +360,7 @@ void QGraphicsLayoutItem::setSizePolicy(QSizePolicy::Policy hPolicy, } /*! - Returns the current size policy. + Returns the current size policy. \sa setSizePolicy(), QWidget::sizePolicy() */ @@ -626,14 +626,15 @@ void QGraphicsLayoutItem::setMaximumHeight(qreal height) */ /*! - \fn virtual void QGraphicsLayoutItem::setGeometry(const QRectF &rect) = 0 + \fn virtual void QGraphicsLayoutItem::setGeometry(const QRectF &rect) - This pure virtual function sets the geometry of the QGraphicsLayoutItem to + This virtual function sets the geometry of the QGraphicsLayoutItem to \a rect, which is in parent coordinates (e.g., the top-left corner of \a rect is equivalent to the item's position in parent coordinates). - Reimplement this function in a subclass of QGraphicsLayoutItem to enable - your item to receive geometry updates. + You must reimplement this function in a subclass of QGraphicsLayoutItem to + receive geometry updates. The layout will call this function when it does a + rearrangement. If \a rect is outside of the bounds of minimumSize and maximumSize, it will be adjusted to its closest size so that it is within the legal @@ -744,7 +745,7 @@ QSizeF QGraphicsLayoutItem::effectiveSizeHint(Qt::SizeHint which, const QSizeF & \sa effectiveSizeHint() */ void QGraphicsLayoutItem::updateGeometry() -{ +{ Q_D(QGraphicsLayoutItem); d->sizeHintCacheDirty = true; } @@ -768,7 +769,7 @@ QGraphicsLayoutItem *QGraphicsLayoutItem::parentLayoutItem() const \sa parentLayoutItem() */ void QGraphicsLayoutItem::setParentLayoutItem(QGraphicsLayoutItem *parent) -{ +{ d_func()->parent = parent; } @@ -789,12 +790,12 @@ bool QGraphicsLayoutItem::isLayout() const If its true, then the layout will delete it. If its false, then it is assumed that another object has the ownership of it, and the layout won't delete this item. - - If the item inherits both QGraphicsItem and QGraphicsLayoutItem (such - as QGraphicsWidget does) the item is really part of two ownership + + If the item inherits both QGraphicsItem and QGraphicsLayoutItem (such + as QGraphicsWidget does) the item is really part of two ownership hierarchies. This property informs what the layout should do with its child items when it is destructed. In the case of QGraphicsWidget, it - is preferred that when the layout is deleted it won't delete its children + is preferred that when the layout is deleted it won't delete its children (since they are also part of the graphics item hierarchy). By default this value is initialized to false in QGraphicsLayoutItem, @@ -822,9 +823,9 @@ void QGraphicsLayoutItem::setOwnedByLayout(bool ownership) /*! * Returns the QGraphicsItem that this layout item represents. - * For QGraphicsWidget it will return itself. For custom items it can return an - * aggregated value. - * + * For QGraphicsWidget it will return itself. For custom items it can return an + * aggregated value. + * * \sa setGraphicsItem() */ QGraphicsItem *QGraphicsLayoutItem::graphicsItem() const @@ -836,10 +837,10 @@ QGraphicsItem *QGraphicsLayoutItem::graphicsItem() const * If the QGraphicsLayoutItem represents a QGraphicsItem, and it wants to take * advantage of the automatic reparenting capabilities of QGraphicsLayout it * should set this value. - * Note that if you delete \a item and not delete the layout item, you are - * responsible of calling setGraphicsItem(0) in order to avoid having a + * Note that if you delete \a item and not delete the layout item, you are + * responsible of calling setGraphicsItem(0) in order to avoid having a * dangling pointer. - * + * * \sa graphicsItem() */ void QGraphicsLayoutItem::setGraphicsItem(QGraphicsItem *item) @@ -848,5 +849,5 @@ void QGraphicsLayoutItem::setGraphicsItem(QGraphicsItem *item) } QT_END_NAMESPACE - + #endif //QT_NO_GRAPHICSVIEW diff --git a/src/gui/graphicsview/qgraphicsproxywidget.cpp b/src/gui/graphicsview/qgraphicsproxywidget.cpp index 1bd2e21..973254f 100644 --- a/src/gui/graphicsview/qgraphicsproxywidget.cpp +++ b/src/gui/graphicsview/qgraphicsproxywidget.cpp @@ -177,6 +177,10 @@ QT_BEGIN_NAMESPACE while the widget is embedded. In this state, the widget may differ slightly in behavior from when it is not embedded. + \warning This class is provided for convenience when bridging + QWidgets and QGraphicsItems, it should not be used for + high-performance scenarios. + \sa QGraphicsScene::addWidget(), QGraphicsWidget */ @@ -1034,7 +1038,7 @@ void QGraphicsProxyWidget::dragMoveEvent(QGraphicsSceneDragDropEvent *event) if (receiver != d->dragDropWidget) { // Try to enter before we leave QDragEnterEvent dragEnter(receiverPos, event->possibleActions(), event->mimeData(), event->buttons(), event->modifiers()); - dragEnter.setDropAction(event->proposedAction()); + dragEnter.setDropAction(event->proposedAction()); QApplication::sendEvent(receiver, &dragEnter); event->setAccepted(dragEnter.isAccepted()); event->setDropAction(dragEnter.dropAction()); @@ -1433,7 +1437,7 @@ int QGraphicsProxyWidget::type() const Creates a proxy widget for the given \a child of the widget contained in this proxy. - + This function makes it possible to aquire proxies for non top-level widgets. For instance, you can embed a dialog, and then transform only one of its widgets. diff --git a/src/gui/graphicsview/qgraphicsscene.cpp b/src/gui/graphicsview/qgraphicsscene.cpp index 1f78a18..13f70e5 100644 --- a/src/gui/graphicsview/qgraphicsscene.cpp +++ b/src/gui/graphicsview/qgraphicsscene.cpp @@ -292,15 +292,21 @@ static inline bool QRectF_intersects(const QRectF &s, const QRectF &r) // QRectF::intersects() returns false always if either the source or target // rectangle's width or height are 0. This works around that problem. -static QRectF _q_adjustedRect(const QRectF &rect) +static inline void _q_adjustRect(QRectF *rect) { - static const qreal p = (qreal)0.00001; - QRectF r = rect; - if (!r.width()) - r.adjust(-p, 0, p, 0); - if (!r.height()) - r.adjust(0, -p, 0, p); - return r; + Q_ASSERT(rect); + if (!rect->width()) + rect->adjust(-0.00001, 0, 0.00001, 0); + if (!rect->height()) + rect->adjust(0, -0.00001, 0, 0.00001); +} + +static inline QRectF adjustedItemBoundingRect(const QGraphicsItem *item) +{ + Q_ASSERT(item); + QRectF boundingRect(item->boundingRect()); + _q_adjustRect(&boundingRect); + return boundingRect; } static void _q_hoverFromMouseEvent(QGraphicsSceneHoverEvent *hover, const QGraphicsSceneMouseEvent *mouseEvent) @@ -632,10 +638,11 @@ void QGraphicsScenePrivate::_q_updateLater() */ void QGraphicsScenePrivate::_q_polishItems() { + const QVariant booleanTrueVariant(true); foreach (QGraphicsItem *item, unpolishedItems) { if (!item->d_ptr->explicitlyHidden) { - item->itemChange(QGraphicsItem::ItemVisibleChange, true); - item->itemChange(QGraphicsItem::ItemVisibleHasChanged, true); + item->itemChange(QGraphicsItem::ItemVisibleChange, booleanTrueVariant); + item->itemChange(QGraphicsItem::ItemVisibleHasChanged, booleanTrueVariant); } if (item->isWidget()) { QEvent event(QEvent::Polish); @@ -690,13 +697,6 @@ void QGraphicsScenePrivate::_q_removeItemLater(QGraphicsItem *item) { Q_Q(QGraphicsScene); - if (QGraphicsItem *parent = item->d_func()->parent) { - QVariant variant; - qVariantSetValue<QGraphicsItem *>(variant, item); - parent->itemChange(QGraphicsItem::ItemChildRemovedChange, variant); - parent->d_func()->children.removeAll(item); - } - // Clear focus on the item to remove any reference in the focusWidget // chain. item->clearFocus(); @@ -740,6 +740,15 @@ void QGraphicsScenePrivate::_q_removeItemLater(QGraphicsItem *item) unpolishedItems.removeAll(item); dirtyItems.removeAll(item); + //We remove all references of item from the sceneEventFilter arrays + QMultiMap<QGraphicsItem*, QGraphicsItem*>::iterator iterator = sceneEventFilters.begin(); + while (iterator != sceneEventFilters.end()) { + if (iterator.value() == item || iterator.key() == item) + iterator = sceneEventFilters.erase(iterator); + else + ++iterator; + } + // Remove from scene transform cache int transformIndex = item->d_func()->sceneTransformIndex; if (transformIndex != -1) { @@ -1358,6 +1367,48 @@ QGraphicsWidget *QGraphicsScenePrivate::windowForItem(const QGraphicsItem *item) return 0; } + +QList<QGraphicsItem *> QGraphicsScenePrivate::items_helper(const QPointF &pos) const +{ + QList<QGraphicsItem *> items; + + // The index returns a rough estimate of what items are inside the rect. + // Refine it by iterating through all returned items. + QRectF adjustedRect = QRectF(pos, QSize(1,1)); + foreach (QGraphicsItem *item, estimateItemsInRect(adjustedRect)) { + // Find the item's scene transform in a clever way. + QTransform x = item->sceneTransform(); + bool keep = false; + + // ### _q_adjustedRect is only needed because QRectF::intersects, + // QRectF::contains and QTransform::map() and friends don't work with + // flat rectangles. + const QRectF br(adjustedItemBoundingRect(item)); + // Rect intersects/contains item's shape + if (QRectF_intersects(adjustedRect, x.mapRect(br))) { + bool ok; + QTransform xinv = x.inverted(&ok); + if (ok) { + if (item->contains(xinv.map(pos))) { + items << item; + keep = true; + } + } + } + + if (keep && (item->flags() & QGraphicsItem::ItemClipsChildrenToShape)) { + // Recurse into children that clip children. + bool ok; + QTransform xinv = x.inverted(&ok); + if (ok) + childItems_helper(&items, item, xinv.map(pos)); + } + } + + sortItems(&items, Qt::AscendingOrder, sortCacheEnabled); + return items; +} + QList<QGraphicsItem *> QGraphicsScenePrivate::items_helper(const QRectF &rect, Qt::ItemSelectionMode mode, Qt::SortOrder order) const @@ -1368,7 +1419,8 @@ QList<QGraphicsItem *> QGraphicsScenePrivate::items_helper(const QRectF &rect, // The index returns a rough estimate of what items are inside the rect. // Refine it by iterating through all returned items. - QRectF adjustedRect = _q_adjustedRect(rect); + QRectF adjustedRect(rect); + _q_adjustRect(&adjustedRect); foreach (QGraphicsItem *item, estimateItemsInRect(adjustedRect)) { // Find the item's scene transform in a clever way. QTransform x = item->sceneTransform(); @@ -1377,7 +1429,7 @@ QList<QGraphicsItem *> QGraphicsScenePrivate::items_helper(const QRectF &rect, // ### _q_adjustedRect is only needed because QRectF::intersects, // QRectF::contains and QTransform::map() and friends don't work with // flat rectangles. - QRectF br = _q_adjustedRect(item->boundingRect()); + const QRectF br(adjustedItemBoundingRect(item)); if (mode >= Qt::ContainsItemBoundingRect) { // Rect intersects/contains item's bounding rect QRectF mbr = x.mapRect(br); @@ -1392,7 +1444,7 @@ QList<QGraphicsItem *> QGraphicsScenePrivate::items_helper(const QRectF &rect, bool ok; QTransform xinv = x.inverted(&ok); if (ok) { - if (path == QPainterPath()) + if (path.isEmpty()) path.addRect(rect); if (itemCollidesWithPath(item, xinv.map(path), mode)) { items << item; @@ -1429,7 +1481,8 @@ QList<QGraphicsItem *> QGraphicsScenePrivate::items_helper(const QPolygonF &poly { QList<QGraphicsItem *> items; - QRectF polyRect = _q_adjustedRect(polygon.boundingRect()); + QRectF polyRect(polygon.boundingRect()); + _q_adjustRect(&polyRect); QPainterPath path; // The index returns a rough estimate of what items are inside the rect. @@ -1442,7 +1495,7 @@ QList<QGraphicsItem *> QGraphicsScenePrivate::items_helper(const QPolygonF &poly // ### _q_adjustedRect is only needed because QRectF::intersects, // QRectF::contains and QTransform::map() and friends don't work with // flat rectangles. - QRectF br = _q_adjustedRect(item->boundingRect()); + const QRectF br(adjustedItemBoundingRect(item)); if (mode >= Qt::ContainsItemBoundingRect) { // Polygon contains/intersects item's bounding rect if (path == QPainterPath()) @@ -1487,21 +1540,47 @@ QList<QGraphicsItem *> QGraphicsScenePrivate::items_helper(const QPainterPath &p Qt::SortOrder order) const { QList<QGraphicsItem *> items; + QRectF pathRect(path.controlPointRect()); + _q_adjustRect(&pathRect); + // The index returns a rough estimate of what items are inside the rect. // Refine it by iterating through all returned items. - foreach (QGraphicsItem *item, estimateItemsInRect(_q_adjustedRect(path.controlPointRect()))) { + foreach (QGraphicsItem *item, estimateItemsInRect(pathRect)) { // Find the item's scene transform in a clever way. QTransform x = item->sceneTransform(); - bool ok; - QTransform xinv = x.inverted(&ok); - if (ok) { - QPainterPath mappedPath = xinv.map(path); - if (itemCollidesWithPath(item, mappedPath, mode)) { + bool keep = false; + + // ### _q_adjustedRect is only needed because QRectF::intersects, + // QRectF::contains and QTransform::map() and friends don't work with + // flat rectangles. + const QRectF br(adjustedItemBoundingRect(item)); + if (mode >= Qt::ContainsItemBoundingRect) { + // Path contains/intersects item's bounding rect + if ((mode == Qt::IntersectsItemBoundingRect && path.intersects(x.mapRect(br))) + || (mode == Qt::ContainsItemBoundingRect && path.contains(x.mapRect(br)))) { items << item; - if (item->flags() & QGraphicsItem::ItemClipsChildrenToShape) - childItems_helper(&items, item, mappedPath, mode); + keep = true; + } + } else { + // Path contains/intersects item's shape + if (QRectF_intersects(pathRect, x.mapRect(br))) { + bool ok; + QTransform xinv = x.inverted(&ok); + if (ok) { + if (itemCollidesWithPath(item, xinv.map(path), mode)) { + items << item; + keep = true; + } + } } } + + if (keep && (item->flags() & QGraphicsItem::ItemClipsChildrenToShape)) { + bool ok; + QTransform xinv = x.inverted(&ok); + if (ok) + childItems_helper(&items, item, xinv.map(path), mode); + } } if (order != Qt::SortOrder(-1)) @@ -1511,13 +1590,13 @@ QList<QGraphicsItem *> QGraphicsScenePrivate::items_helper(const QPainterPath &p void QGraphicsScenePrivate::childItems_helper(QList<QGraphicsItem *> *items, const QGraphicsItem *parent, - const QRectF &rect, - Qt::ItemSelectionMode mode) const + const QPointF &pos) const { - QPainterPath path; bool parentClip = (parent->flags() & QGraphicsItem::ItemClipsChildrenToShape); - QRectF r = !parentClip ? _q_adjustedRect(rect) : _q_adjustedRect(rect).intersected(_q_adjustedRect(parent->boundingRect())); - if (r.isEmpty()) + if (parentClip && parent->d_ptr->isClippedAway()) + return; + // ### is this needed? + if (parentClip && !parent->boundingRect().contains(pos)) return; QList<QGraphicsItem *> &children = parent->d_ptr->children; @@ -1527,31 +1606,73 @@ void QGraphicsScenePrivate::childItems_helper(QList<QGraphicsItem *> *items, continue; // Skip invisible items and all their children. - if (!item->d_ptr->visible || qFuzzyCompare(item->effectiveOpacity(), qreal(0.0))) + if (item->d_ptr->isInvisible()) continue; - // ### _q_adjustedRect is only needed because QRectF::intersects, - // QRectF::contains and QTransform::map() and friends don't work with - // flat rectangles. - QRectF br = _q_adjustedRect(item->boundingRect()); - QRectF mbr = item->mapRectToParent(br); bool keep = false; - if (mode >= Qt::ContainsItemBoundingRect) { - // Rect intersects/contains item's bounding rect - if ((mode == Qt::IntersectsItemBoundingRect && QRectF_intersects(rect, mbr)) - || (mode == Qt::ContainsItemBoundingRect && rect != mbr && rect.contains(br))) { + if (!item->d_ptr->isClippedAway()) { + if (item->contains(item->mapFromParent(pos))) { items->append(item); keep = true; } - } else { - // Rect intersects/contains item's shape - if (QRectF_intersects(rect, mbr)) { - if (path == QPainterPath()) - path.addRect(rect); - if (itemCollidesWithPath(item, item->mapFromParent(path), mode)) { + } + + if ((keep || !(item->flags() & QGraphicsItem::ItemClipsChildrenToShape)) && !item->d_ptr->children.isEmpty()) + // Recurse into children. + childItems_helper(items, item, item->mapFromParent(pos)); + } +} + + +void QGraphicsScenePrivate::childItems_helper(QList<QGraphicsItem *> *items, + const QGraphicsItem *parent, + const QRectF &rect, + Qt::ItemSelectionMode mode) const +{ + bool parentClip = (parent->flags() & QGraphicsItem::ItemClipsChildrenToShape); + if (parentClip && parent->d_ptr->isClippedAway()) + return; + QRectF adjustedRect(rect); + _q_adjustRect(&adjustedRect); + QRectF r = !parentClip ? adjustedRect : adjustedRect.intersected(adjustedItemBoundingRect(parent)); + if (r.isEmpty()) + return; + + QPainterPath path; + QList<QGraphicsItem *> &children = parent->d_ptr->children; + for (int i = 0; i < children.size(); ++i) { + QGraphicsItem *item = children.at(i); + if (item->d_ptr->hasTransform && !item->transform().isInvertible()) + continue; + + // Skip invisible items and all their children. + if (item->d_ptr->isInvisible()) + continue; + + bool keep = false; + if (!item->d_ptr->isClippedAway()) { + // ### _q_adjustedRect is only needed because QRectF::intersects, + // QRectF::contains and QTransform::map() and friends don't work with + // flat rectangles. + const QRectF br(adjustedItemBoundingRect(item)); + QRectF mbr = item->mapRectToParent(br); + if (mode >= Qt::ContainsItemBoundingRect) { + // Rect intersects/contains item's bounding rect + if ((mode == Qt::IntersectsItemBoundingRect && QRectF_intersects(rect, mbr)) + || (mode == Qt::ContainsItemBoundingRect && rect != mbr && rect.contains(br))) { items->append(item); keep = true; } + } else { + // Rect intersects/contains item's shape + if (QRectF_intersects(rect, mbr)) { + if (path == QPainterPath()) + path.addRect(rect); + if (itemCollidesWithPath(item, item->mapFromParent(path), mode)) { + items->append(item); + keep = true; + } + } } } @@ -1568,18 +1689,22 @@ void QGraphicsScenePrivate::childItems_helper(QList<QGraphicsItem *> *items, } } + void QGraphicsScenePrivate::childItems_helper(QList<QGraphicsItem *> *items, const QGraphicsItem *parent, const QPolygonF &polygon, Qt::ItemSelectionMode mode) const { - QPainterPath path; bool parentClip = (parent->flags() & QGraphicsItem::ItemClipsChildrenToShape); - QRectF polyRect = _q_adjustedRect(polygon.boundingRect()); - QRectF r = !parentClip ? polyRect : polyRect.intersected(_q_adjustedRect(parent->boundingRect())); + if (parentClip && parent->d_ptr->isClippedAway()) + return; + QRectF polyRect(polygon.boundingRect()); + _q_adjustRect(&polyRect); + QRectF r = !parentClip ? polyRect : polyRect.intersected(adjustedItemBoundingRect(parent)); if (r.isEmpty()) return; + QPainterPath path; QList<QGraphicsItem *> &children = parent->d_ptr->children; for (int i = 0; i < children.size(); ++i) { QGraphicsItem *item = children.at(i); @@ -1587,32 +1712,34 @@ void QGraphicsScenePrivate::childItems_helper(QList<QGraphicsItem *> *items, continue; // Skip invisible items. - if (!item->d_ptr->visible || qFuzzyCompare(item->effectiveOpacity() + 1, qreal(1.0))) + if (item->d_ptr->isInvisible()) continue; - // ### _q_adjustedRect is only needed because QRectF::intersects, - // QRectF::contains and QTransform::map() and friends don't work with - // flat rectangles. - QRectF br = _q_adjustedRect(item->boundingRect()); bool keep = false; - if (mode >= Qt::ContainsItemBoundingRect) { - // Polygon contains/intersects item's bounding rect - if (path == QPainterPath()) - path.addPolygon(polygon); - if ((mode == Qt::IntersectsItemBoundingRect && path.intersects(item->mapRectToParent(br))) - || (mode == Qt::ContainsItemBoundingRect && path.contains(item->mapRectToParent(br)))) { - items->append(item); - keep = true; - } - } else { - // Polygon contains/intersects item's shape - if (QRectF_intersects(polyRect, item->mapRectToParent(br))) { + if (!item->d_ptr->isClippedAway()) { + // ### _q_adjustedRect is only needed because QRectF::intersects, + // QRectF::contains and QTransform::map() and friends don't work with + // flat rectangles. + const QRectF br(adjustedItemBoundingRect(item)); + if (mode >= Qt::ContainsItemBoundingRect) { + // Polygon contains/intersects item's bounding rect if (path == QPainterPath()) path.addPolygon(polygon); - if (itemCollidesWithPath(item, item->mapFromParent(path), mode)) { + if ((mode == Qt::IntersectsItemBoundingRect && path.intersects(item->mapRectToParent(br))) + || (mode == Qt::ContainsItemBoundingRect && path.contains(item->mapRectToParent(br)))) { items->append(item); keep = true; } + } else { + // Polygon contains/intersects item's shape + if (QRectF_intersects(polyRect, item->mapRectToParent(br))) { + if (path == QPainterPath()) + path.addPolygon(polygon); + if (itemCollidesWithPath(item, item->mapFromParent(path), mode)) { + items->append(item); + keep = true; + } + } } } @@ -1629,30 +1756,52 @@ void QGraphicsScenePrivate::childItems_helper(QList<QGraphicsItem *> *items, Qt::ItemSelectionMode mode) const { bool parentClip = (parent->flags() & QGraphicsItem::ItemClipsChildrenToShape); - QPainterPath intersectedPath = !parentClip ? path : path.intersected(parent->shape()); - if (intersectedPath.isEmpty()) + if (parentClip && parent->d_ptr->isClippedAway()) + return; + QRectF pathRect(path.boundingRect()); + _q_adjustRect(&pathRect); + QRectF r = !parentClip ? pathRect : pathRect.intersected(adjustedItemBoundingRect(parent)); + if (r.isEmpty()) return; QList<QGraphicsItem *> &children = parent->d_ptr->children; for (int i = 0; i < children.size(); ++i) { QGraphicsItem *item = children.at(i); + if (item->d_ptr->hasTransform && !item->transform().isInvertible()) + continue; // Skip invisible items. - if (!item->d_ptr->visible || qFuzzyCompare(item->effectiveOpacity(), qreal(0.0))) + if (item->d_ptr->isInvisible()) continue; - QTransform x = item->sceneTransform(); - - bool ok; - QTransform xinv = x.inverted(&ok); - if (ok) { - QPainterPath mappedPath = xinv.map(path); - if (itemCollidesWithPath(item, mappedPath, mode)) { - items->append(item); - if (!item->d_ptr->children.isEmpty()) - childItems_helper(items, item, mappedPath, mode); + bool keep = false; + if (!item->d_ptr->isClippedAway()) { + // ### _q_adjustedRect is only needed because QRectF::intersects, + // QRectF::contains and QTransform::map() and friends don't work with + // flat rectangles. + const QRectF br(adjustedItemBoundingRect(item)); + if (mode >= Qt::ContainsItemBoundingRect) { + // Polygon contains/intersects item's bounding rect + if ((mode == Qt::IntersectsItemBoundingRect && path.intersects(item->mapRectToParent(br))) + || (mode == Qt::ContainsItemBoundingRect && path.contains(item->mapRectToParent(br)))) { + items->append(item); + keep = true; + } + } else { + // Path contains/intersects item's shape + if (QRectF_intersects(pathRect, item->mapRectToParent(br))) { + if (itemCollidesWithPath(item, item->mapFromParent(path), mode)) { + items->append(item); + keep = true; + } + } } } + + if ((keep || !(item->flags() & QGraphicsItem::ItemClipsChildrenToShape)) && !item->d_ptr->children.isEmpty()) { + // Recurse into children that clip children. + childItems_helper(items, item, item->mapFromParent(path), mode); + } } } @@ -2326,17 +2475,8 @@ QList<QGraphicsItem *> QGraphicsScene::items() const */ QList<QGraphicsItem *> QGraphicsScene::items(const QPointF &pos) const { - QList<QGraphicsItem *> itemsAtPoint; - - // Find all items within a 1x1 rect area starting at pos. This can be - // inefficient for scenes that use small coordinates (like unity - // coordinates), or for detailed graphs. ### The index should support - // fetching items at a pos to avoid this limitation. - foreach (QGraphicsItem *item, items(QRectF(pos, QSizeF(1, 1)), Qt::IntersectsItemBoundingRect)) { - if (item->contains(item->mapFromScene(pos))) - itemsAtPoint << item; - } - return itemsAtPoint; + Q_D(const QGraphicsScene); + return d->items_helper(pos); } @@ -2723,8 +2863,9 @@ void QGraphicsScene::addItem(QGraphicsItem *item) // Notify the item that its scene is changing, and allow the item to // react. - QGraphicsScene *targetScene = qVariantValue<QGraphicsScene *>(item->itemChange(QGraphicsItem::ItemSceneChange, - qVariantFromValue<QGraphicsScene *>(this))); + const QVariant newSceneVariant(item->itemChange(QGraphicsItem::ItemSceneChange, + qVariantFromValue<QGraphicsScene *>(this))); + QGraphicsScene *targetScene = qVariantValue<QGraphicsScene *>(newSceneVariant); if (targetScene != this) { if (targetScene && item->scene() != targetScene) targetScene->addItem(item); @@ -2818,7 +2959,7 @@ void QGraphicsScene::addItem(QGraphicsItem *item) emit selectionChanged(); // Deliver post-change notification - item->itemChange(QGraphicsItem::ItemSceneHasChanged, qVariantFromValue<QGraphicsScene *>(this)); + item->itemChange(QGraphicsItem::ItemSceneHasChanged, newSceneVariant); } /*! @@ -3082,8 +3223,9 @@ void QGraphicsScene::removeItem(QGraphicsItem *item) // Notify the item that it's scene is changing to 0, allowing the item to // react. - QGraphicsScene *targetScene = qVariantValue<QGraphicsScene *>(item->itemChange(QGraphicsItem::ItemSceneChange, - qVariantFromValue<QGraphicsScene *>(0))); + const QVariant newSceneVariant(item->itemChange(QGraphicsItem::ItemSceneChange, + qVariantFromValue<QGraphicsScene *>(0))); + QGraphicsScene *targetScene = qVariantValue<QGraphicsScene *>(newSceneVariant); if (targetScene != 0 && targetScene != this) { targetScene->addItem(item); return; @@ -3154,6 +3296,16 @@ void QGraphicsScene::removeItem(QGraphicsItem *item) d->unpolishedItems.removeAll(item); d->dirtyItems.removeAll(item); + //We remove all references of item from the sceneEventFilter arrays + QMultiMap<QGraphicsItem*, QGraphicsItem*>::iterator iterator = d->sceneEventFilters.begin(); + while (iterator != d->sceneEventFilters.end()) { + if (iterator.value() == item || iterator.key() == item) + iterator = d->sceneEventFilters.erase(iterator); + else + ++iterator; + } + + //Ensure dirty flag have the correct default value so the next time it will be added it will receive updates item->d_func()->dirty = 0; item->d_func()->dirtyChildren = 0; @@ -3181,7 +3333,7 @@ void QGraphicsScene::removeItem(QGraphicsItem *item) emit selectionChanged(); // Deliver post-change notification - item->itemChange(QGraphicsItem::ItemSceneHasChanged, qVariantFromValue<QGraphicsScene *>(0)); + item->itemChange(QGraphicsItem::ItemSceneHasChanged, newSceneVariant); } /*! @@ -3455,7 +3607,7 @@ QVariant QGraphicsScene::inputMethodQuery(Qt::InputMethodQuery query) const void QGraphicsScene::update(const QRectF &rect) { Q_D(QGraphicsScene); - if (d->updateAll) + if (d->updateAll || (rect.isEmpty() && !rect.isNull())) return; // Check if anyone's connected; if not, we can send updates directly to @@ -4564,7 +4716,9 @@ void QGraphicsScenePrivate::drawItemHelper(QGraphicsItem *item, QPainter *painte // Item's (local) bounding rect QRectF brect = item->boundingRect(); - if (_q_adjustedRect(brect).isEmpty()) + QRectF adjustedBrect(brect); + _q_adjustRect(&adjustedBrect); + if (adjustedBrect.isEmpty()) return; // Fetch the off-screen transparent buffer and exposed area info. @@ -4595,16 +4749,17 @@ void QGraphicsScenePrivate::drawItemHelper(QGraphicsItem *item, QPainter *painte if (cacheMode == QGraphicsItem::ItemCoordinateCache) { QSize pixmapSize; bool fixedCacheSize = false; + QRectF brectAligned = brect.toAlignedRect(); if ((fixedCacheSize = itemCache->fixedSize.isValid())) { pixmapSize = itemCache->fixedSize; } else { - pixmapSize = brect.toAlignedRect().size(); + pixmapSize = brectAligned.size().toSize(); } // Create or recreate the pixmap. int adjust = itemCache->fixedSize.isValid() ? 0 : 2; QSize adjustSize(adjust*2, adjust*2); - QRectF br = brect.adjusted(-adjust, -adjust, adjust, adjust); + QRectF br = brectAligned.adjusted(-adjust, -adjust, adjust, adjust); if (pix.isNull() || (!fixedCacheSize && (pixmapSize + adjustSize) != pix.size())) { pix = QPixmap(pixmapSize + adjustSize); itemCache->exposed.clear(); @@ -4614,9 +4769,11 @@ void QGraphicsScenePrivate::drawItemHelper(QGraphicsItem *item, QPainter *painte // Redraw any newly exposed areas. if (itemCache->allExposed || !itemCache->exposed.isEmpty()) { // Fit the item's bounding rect into the pixmap's coordinates. - const QPointF scale(pixmapSize.width() / brect.width(), pixmapSize.height() / brect.height()); QTransform itemToPixmap; - itemToPixmap.scale(scale.x(), scale.y()); + if (fixedCacheSize) { + const QPointF scale(pixmapSize.width() / brect.width(), pixmapSize.height() / brect.height()); + itemToPixmap.scale(scale.x(), scale.y()); + } itemToPixmap.translate(-br.x(), -br.y()); // Generate the item's exposedRect and map its list of expose @@ -4769,8 +4926,9 @@ void QGraphicsScenePrivate::drawItemHelper(QGraphicsItem *item, QPainter *painte if (itemCache->allExposed || !itemCache->exposed.isEmpty() || !scrollExposure.isEmpty()) { // Construct an item-to-pixmap transform. QPointF p = deviceRect.topLeft(); - QTransform itemToPixmap = QTransform::fromTranslate(-p.x(), -p.y()); - itemToPixmap = painter->worldTransform() * itemToPixmap; + QTransform itemToPixmap = painter->worldTransform(); + if (!p.isNull()) + itemToPixmap *= QTransform::fromTranslate(-p.x(), -p.y()); // Map the item's logical expose to pixmap coordinates. QRegion pixmapExposed = scrollExposure; @@ -5104,9 +5262,12 @@ void QGraphicsScene::itemUpdated(QGraphicsItem *item, const QRectF &rect) update(item->sceneBoundingRect()); } else { // ### Remove _q_adjustedRects(). - QRectF boundingRect = _q_adjustedRect(item->boundingRect()); - if (!rect.isNull()) - boundingRect &= _q_adjustedRect(rect); + QRectF boundingRect(adjustedItemBoundingRect(item)); + if (!rect.isNull()) { + QRectF adjustedRect(rect); + _q_adjustRect(&adjustedRect); + boundingRect &= adjustedRect; + } // Update each view directly. for (int i = 0; i < d->views.size(); ++i) @@ -5118,6 +5279,9 @@ void QGraphicsScene::itemUpdated(QGraphicsItem *item, const QRectF &rect) d->resetDirtyItemsLater(); } + if (!item->isVisible()) + return; // Hiding an item won't effect the largestUntransformableItem/sceneRect. + // Update d->largestUntransformableItem by mapping this item's bounding // rect back to the topmost untransformable item's untransformed // coordinate system (which sort of equals the 1:1 coordinate system of an @@ -5133,7 +5297,9 @@ void QGraphicsScene::itemUpdated(QGraphicsItem *item, const QRectF &rect) // defined scene rect. if (!d->hasSceneRect) { QRectF oldGrowingItemsBoundingRect = d->growingItemsBoundingRect; - d->growingItemsBoundingRect |= _q_adjustedRect(item->sceneBoundingRect()); + QRectF adjustedItemSceneBoundingRect(item->sceneBoundingRect()); + _q_adjustRect(&adjustedItemSceneBoundingRect); + d->growingItemsBoundingRect |= adjustedItemSceneBoundingRect; if (d->growingItemsBoundingRect != oldGrowingItemsBoundingRect) emit sceneRectChanged(d->growingItemsBoundingRect); } diff --git a/src/gui/graphicsview/qgraphicsscene_p.h b/src/gui/graphicsview/qgraphicsscene_p.h index 9c165d1..befbbd8 100644 --- a/src/gui/graphicsview/qgraphicsscene_p.h +++ b/src/gui/graphicsview/qgraphicsscene_p.h @@ -197,6 +197,7 @@ public: void mousePressEventHandler(QGraphicsSceneMouseEvent *mouseEvent); QGraphicsWidget *windowForItem(const QGraphicsItem *item) const; + QList<QGraphicsItem *> items_helper(const QPointF &pos) const; QList<QGraphicsItem *> items_helper(const QRectF &rect, Qt::ItemSelectionMode mode, Qt::SortOrder order) const; @@ -208,6 +209,9 @@ public: Qt::SortOrder order) const; void childItems_helper(QList<QGraphicsItem *> *items, const QGraphicsItem *parent, + const QPointF &pos) const; + void childItems_helper(QList<QGraphicsItem *> *items, + const QGraphicsItem *parent, const QRectF &rect, Qt::ItemSelectionMode mode) const; void childItems_helper(QList<QGraphicsItem *> *items, diff --git a/src/gui/graphicsview/qgraphicssceneevent.cpp b/src/gui/graphicsview/qgraphicssceneevent.cpp index 57c79db..b819c2c 100644 --- a/src/gui/graphicsview/qgraphicssceneevent.cpp +++ b/src/gui/graphicsview/qgraphicssceneevent.cpp @@ -133,7 +133,7 @@ A QContextMenuEvent received by a QGraphicsView is translated into a QGraphicsSceneContextMenuEvent. The - QWheelEvent::globalPos() is translated into item, scene, and + QContextMenuEvent::globalPos() is translated into item, scene, and screen coordinates (pos(), scenePos(), and screenPos()). \sa QGraphicsSceneMouseEvent, QGraphicsSceneWheelEvent, diff --git a/src/gui/graphicsview/qgraphicsview.cpp b/src/gui/graphicsview/qgraphicsview.cpp index 15c0e25..05e4907 100644 --- a/src/gui/graphicsview/qgraphicsview.cpp +++ b/src/gui/graphicsview/qgraphicsview.cpp @@ -790,6 +790,19 @@ QRegion QGraphicsViewPrivate::mapToViewRegion(const QGraphicsItem *item, const Q return item->boundingRegion(itv) & itv.mapRect(rect).toAlignedRect(); } +// QRectF::intersects() returns false always if either the source or target +// rectangle's width or height are 0. This works around that problem. +static inline QRectF adjustedItemBoundingRect(const QGraphicsItem *item) +{ + Q_ASSERT(item); + QRectF boundingRect(item->boundingRect()); + if (!boundingRect.width()) + boundingRect.adjust(-0.00001, 0, 0.00001, 0); + if (!boundingRect.height()) + boundingRect.adjust(0, -0.00001, 0, 0.00001); + return boundingRect; +} + /*! \internal */ @@ -801,38 +814,37 @@ void QGraphicsViewPrivate::itemUpdated(QGraphicsItem *item, const QRectF &rect) updateLater(); QRectF updateRect = rect; - if (item->isClipped()) { + if ((item->d_ptr->flags & QGraphicsItem::ItemClipsChildrenToShape) || item->d_ptr->children.isEmpty()) { + updateRect &= adjustedItemBoundingRect(item); + if (updateRect.isEmpty()) + return; + } + + QGraphicsItem *clipItem = item; + if (item->d_ptr->ancestorFlags & QGraphicsItemPrivate::AncestorClipsChildren) { // Minimize unnecessary redraw. - QGraphicsItem *p = item; - while ((p = p->d_ptr->parent)) { - if (p->flags() & QGraphicsItem::ItemClipsChildrenToShape) { - updateRect &= p->itemTransform(item).mapRect(p->boundingRect()); - if (updateRect.isNull()) + QGraphicsItem *parent = item; + while ((parent = parent->d_ptr->parent)) { + if (parent->d_ptr->flags & QGraphicsItem::ItemClipsChildrenToShape) { + // Map update rect to the current parent and itersect with its bounding rect. + updateRect = clipItem->itemTransform(parent).mapRect(updateRect) + & adjustedItemBoundingRect(parent); + if (updateRect.isEmpty()) return; + clipItem = parent; } - if (!(p->d_ptr->ancestorFlags & QGraphicsItemPrivate::AncestorClipsChildren)) + if (!(parent->d_ptr->ancestorFlags & QGraphicsItemPrivate::AncestorClipsChildren)) break; } - - if (updateRect.isNull()) - return; } - // Map the rect to view coordinates. - QRect vr = viewport->rect(); - - if (!item->d_ptr->hasBoundingRegionGranularity) { - QRect r = mapToViewRect(item, updateRect) & vr; - if (r.isNull()) - return; - this->updateRect(r); - } else { - QRegion r = mapToViewRegion(item, updateRect) & vr; - if (r.isEmpty()) - return; - updateRegion(r); - } + // Map update rect from clipItem coordinates to view coordinates. + Q_ASSERT(clipItem); + if (!item->d_ptr->hasBoundingRegionGranularity) + this->updateRect(mapToViewRect(clipItem, updateRect) & viewport->rect()); + else + updateRegion(mapToViewRegion(clipItem, updateRect) & viewport->rect()); } void QGraphicsViewPrivate::updateLater() @@ -855,16 +867,19 @@ void QGraphicsViewPrivate::_q_updateLaterSlot() const QList<QGraphicsItem *> &dirtyItems = scene->d_func()->dirtyItems; for (int i = 0; i < dirtyItems.size(); ++i) { const QGraphicsItem *item = dirtyItems.at(i); + if (item->d_ptr->discardUpdateRequest(/*ignoreClipping=*/false, + /*ignoreVisibleBit=*/false, + /*ignoreDirtyBit=*/true)) { + continue; + } QTransform x = item->sceneTransform() * viewTransform; - QRect viewRect = x.mapRect(item->boundingRect()).toAlignedRect() & vr; - if (!viewRect.isNull()) - updateRect(viewRect); + updateRect(x.mapRect(item->boundingRect()).toAlignedRect() & vr); } dirtyRectCount += dirtyRects.size(); bool noUpdate = !fullUpdatePending && viewportUpdateMode == QGraphicsView::FullViewportUpdate; - if ((dirtyRectCount > 0 || !dirtyBoundingRect.isNull()) && !fullUpdatePending && !noUpdate) { + if ((dirtyRectCount > 0 || !dirtyBoundingRect.isEmpty()) && !fullUpdatePending && !noUpdate) { if (viewportUpdateMode == QGraphicsView::BoundingRectViewportUpdate || (viewportUpdateMode == QGraphicsView::SmartViewportUpdate && dirtyRectCount >= QGRAPHICSVIEW_REGION_RECT_THRESHOLD)) { @@ -921,6 +936,9 @@ void QGraphicsViewPrivate::updateAll() void QGraphicsViewPrivate::updateRegion(const QRegion &r) { + if (r.isEmpty()) + return; + Q_Q(QGraphicsView); // Rect intersects viewport - update everything? @@ -969,6 +987,9 @@ void QGraphicsViewPrivate::updateRegion(const QRegion &r) void QGraphicsViewPrivate::updateRect(const QRect &r) { + if (r.isEmpty()) + return; + Q_Q(QGraphicsView); // Rect intersects viewport - update everything? @@ -1023,105 +1044,77 @@ void QGraphicsViewPrivate::freeStyleOptionsArray(QStyleOptionGraphicsItem *array delete [] array; } +extern QPainterPath qt_regionToPath(const QRegion ®ion); -QList<QGraphicsItem *> QGraphicsViewPrivate::findItems(const QRegion &exposedRegion, - const QTransform &worldTransform, - bool *allItems) const +/*! + ### Adjustments in findItems: mapToScene(QRect) forces us to adjust the + input rectangle by (0, 0, 1, 1), because it uses QRect::bottomRight() + (etc) when mapping the rectangle to a polygon (which is _wrong_). In + addition, as QGraphicsItem::boundingRect() is defined in logical space, + but the default pen for QPainter is cosmetic with a width of 0, QPainter + is at risk of painting 1 pixel outside the bounding rect. Therefore we + must search for items with an adjustment of (-1, -1, 1, 1). +*/ +QList<QGraphicsItem *> QGraphicsViewPrivate::findItems(const QRegion &exposedRegion, bool *allItems) const { Q_Q(const QGraphicsView); - QList<QGraphicsItem *> itemList; - QSet<QGraphicsItem *> tmp; - bool simpleTransform = worldTransform.type() <= QTransform::TxScale; - - extern QPainterPath qt_regionToPath(const QRegion ®ion); - QPainterPath path = qt_regionToPath(exposedRegion); - *allItems = path.contains(q->mapFromScene(scene->d_func()->growingItemsBoundingRect).boundingRect()); - QList<QRectF> exposedRects; - QList<QPolygonF> exposedPolys; - - // Transform the exposed viewport rects to scene rects or polygons - foreach (const QRect &rect, exposedRegion.rects()) { - QPolygonF exposedPoly = q->mapToScene(rect.adjusted(-1, -1, 1, 1)); - QRectF exposedRect = exposedPoly.boundingRect(); - if (!simpleTransform) - exposedPolys << exposedPoly; - exposedRects << exposedRect; - } - - // Find which items need to be drawn. - if (*allItems) { + + // Step 1) If all items are contained within the expose region, then + // return a list of all visible items. + const QRectF exposedRegionSceneBounds = q->mapToScene(exposedRegion.boundingRect().adjusted(-1, -1, 2, 2)) + .boundingRect(); + if (exposedRegionSceneBounds.contains(scene->d_func()->growingItemsBoundingRect)) { + Q_ASSERT(allItems); + *allItems = true; + // All items are guaranteed within the exposed region, don't bother using the index. - foreach (QGraphicsItem *item, scene->items()) { + QList<QGraphicsItem *> itemList(scene->items()); + int i = 0; + while (i < itemList.size()) { + const QGraphicsItem *item = itemList.at(i); // But we only want to include items that are visible - if (item->isVisible()) - itemList << item; - } - } else if (simpleTransform) { - // Simple rect lookups will do. - if (exposedRects.size() > 1) { - foreach (const QRectF &rect, exposedRects) { - foreach (QGraphicsItem *item, scene->d_func()->items_helper(rect, Qt::IntersectsItemBoundingRect, Qt::SortOrder(-1) /* don't sort */)) { - if (!tmp.contains(item)) { - tmp << item; - itemList << item; - } - } - } - } else { - itemList += scene->d_func()->items_helper(exposedRects[0], Qt::IntersectsItemBoundingRect, Qt::SortOrder(-1) /* don't sort */); - } - } else { - // Polygon lookup is necessary. - if (exposedRects.size() > 1) { - foreach (const QPolygonF &poly, exposedPolys) { - foreach (QGraphicsItem *item, scene->d_func()->items_helper(poly, Qt::IntersectsItemBoundingRect, Qt::SortOrder(-1) /* don't sort */)) { - if (!tmp.contains(item)) { - tmp << item; - itemList << item; - } - } - } - } else { - itemList += scene->d_func()->items_helper(exposedPolys[0], Qt::IntersectsItemBoundingRect, Qt::SortOrder(-1) /* don't sort */); + // The following check is basically the same as item->d_ptr->isInvisible(), except + // that we don't check whether the item clips children to shape or propagates its + // opacity (we loop through all items, so those checks are wrong in this context). + if (!item->isVisible() || item->d_ptr->isClippedAway() || item->d_ptr->isFullyTransparent()) + itemList.removeAt(i); + else + ++i; } + + // Sort the items. + QGraphicsScenePrivate::sortItems(&itemList, Qt::DescendingOrder, scene->d_func()->sortCacheEnabled); + return itemList; } - // Check for items that ignore inherited transformations, and add them if - // necessary. - QRectF untr = scene->d_func()->largestUntransformableItem; - if (!*allItems && !untr.isNull()) { - // Map the largest untransformable item subtree boundingrect from view - // to scene coordinates, and use this to expand all exposed rects in - // search for untransformable items. - QRectF ltri = matrix.inverted().mapRect(untr); - ltri.adjust(-untr.width(), -untr.height(), untr.width(), untr.height()); - - foreach (const QRect &rect, exposedRegion.rects()) { - QRectF exposed = q->mapToScene(rect.adjusted(-1, -1, 1, 1)).boundingRect(); - exposed.adjust(-ltri.width(), -ltri.height(), ltri.width(), ltri.height()); - - foreach (QGraphicsItem *item, scene->d_func()->estimateItemsInRect(exposed)) { - if (item->d_ptr->itemIsUntransformable()) { - if (!tmp.contains(item)) { - QPainterPath rectPath; - rectPath.addRect(rect); - QPainterPath path = item->deviceTransform(q->viewportTransform()).inverted().map(rectPath); - if (item->collidesWithPath(path, Qt::IntersectsItemBoundingRect)) { - itemList << item; - tmp << item; - } - } - } - } - } + // Step 2) If the expose region is a simple rect and the view is only + // translated or scaled, search for items using + // QGraphicsScene::items(QRectF). + bool simpleRectLookup = (scene->d_func()->largestUntransformableItem.isNull() + && exposedRegion.numRects() == 1 && matrix.type() <= QTransform::TxScale); + if (simpleRectLookup) { + return scene->d_func()->items_helper(exposedRegionSceneBounds, + Qt::IntersectsItemBoundingRect, + Qt::DescendingOrder); } - tmp.clear(); - // Sort the items. - QGraphicsScenePrivate::sortItems(&itemList, Qt::DescendingOrder, - scene->d_func()->sortCacheEnabled); + // If the region is complex or the view has a complex transform, adjust + // the expose region, convert it to a path, and then search for items + // using QGraphicsScene::items(QPainterPath); + QRegion adjustedRegion; + foreach (const QRect &r, exposedRegion.rects()) + adjustedRegion += r.adjusted(-1, -1, 1, 1); + + const QPainterPath exposedPath(qt_regionToPath(adjustedRegion)); + if (scene->d_func()->largestUntransformableItem.isNull()) { + const QPainterPath exposedScenePath(q->mapToScene(exposedPath)); + return scene->d_func()->items_helper(exposedScenePath, + Qt::IntersectsItemBoundingRect, + Qt::DescendingOrder); + } - return itemList; + // NB! Path must be in viewport coordinates. + return itemsInArea(exposedPath, Qt::IntersectsItemBoundingRect, Qt::DescendingOrder); } void QGraphicsViewPrivate::generateStyleOptions(const QList<QGraphicsItem *> &itemList, @@ -2224,7 +2217,8 @@ QList<QGraphicsItem *> QGraphicsView::items() const certainly room for improvement. */ QList<QGraphicsItem *> QGraphicsViewPrivate::itemsInArea(const QPainterPath &path, - Qt::ItemSelectionMode mode) const + Qt::ItemSelectionMode mode, + Qt::SortOrder order) const { Q_Q(const QGraphicsView); @@ -2274,8 +2268,8 @@ QList<QGraphicsItem *> QGraphicsViewPrivate::itemsInArea(const QPainterPath &pat } // ### Insertion sort would be faster. - QGraphicsScenePrivate::sortItems(&result, Qt::AscendingOrder, - scene->d_func()->sortCacheEnabled); + if (order != Qt::SortOrder(-1)) + QGraphicsScenePrivate::sortItems(&result, order, scene->d_func()->sortCacheEnabled); return result; } @@ -3280,7 +3274,7 @@ void QGraphicsView::mouseMoveEvent(QMouseEvent *event) } // Update old rubberband - if (d->viewportUpdateMode != QGraphicsView::NoViewportUpdate && !d->rubberBandRect.isNull()) { + if (d->viewportUpdateMode != QGraphicsView::NoViewportUpdate && !d->rubberBandRect.isEmpty()) { if (d->viewportUpdateMode != FullViewportUpdate) viewport()->update(d->rubberBandRegion(viewport(), d->rubberBandRect)); else @@ -3462,7 +3456,7 @@ void QGraphicsView::paintEvent(QPaintEvent *event) QPainter painter(viewport()); QTransform original = painter.worldTransform(); #ifndef QT_NO_RUBBERBAND - if (d->rubberBanding && !d->rubberBandRect.isNull()) + if (d->rubberBanding && !d->rubberBandRect.isEmpty()) painter.save(); #endif // Set up render hints @@ -3481,7 +3475,7 @@ void QGraphicsView::paintEvent(QPaintEvent *event) // Find all exposed items bool allItems = false; - QList<QGraphicsItem *> itemList = d->findItems(exposedRegion, viewTransform, &allItems); + QList<QGraphicsItem *> itemList = d->findItems(exposedRegion, &allItems); #ifdef QGRAPHICSVIEW_DEBUG int exposedTime = stopWatch.elapsed(); @@ -3557,7 +3551,7 @@ void QGraphicsView::paintEvent(QPaintEvent *event) #ifndef QT_NO_RUBBERBAND // Rubberband - if (d->rubberBanding && !d->rubberBandRect.isNull()) { + if (d->rubberBanding && !d->rubberBandRect.isEmpty()) { painter.restore(); QStyleOptionRubberBand option; option.initFrom(viewport()); @@ -3631,30 +3625,30 @@ void QGraphicsView::scrollContentsBy(int dx, int dy) if (isRightToLeft()) dx = -dx; - if (d->viewportUpdateMode != QGraphicsView::NoViewportUpdate - && d->viewportUpdateMode != QGraphicsView::FullViewportUpdate) { - for (int i = 0; i < d->dirtyRects.size(); ++i) - d->dirtyRects[i].translate(dx, dy); - for (int i = 0; i < d->dirtyRegions.size(); ++i) - d->dirtyRegions[i].translate(dx, dy); - } - + if (d->viewportUpdateMode != QGraphicsView::NoViewportUpdate) { + if (d->viewportUpdateMode != QGraphicsView::FullViewportUpdate) { + for (int i = 0; i < d->dirtyRects.size(); ++i) + d->dirtyRects[i].translate(dx, dy); + for (int i = 0; i < d->dirtyRegions.size(); ++i) + d->dirtyRegions[i].translate(dx, dy); + if (d->accelerateScrolling) { #ifndef QT_NO_RUBBERBAND - // Update old rubberband - if (d->viewportUpdateMode != QGraphicsView::NoViewportUpdate && !d->rubberBandRect.isNull()) { - if (d->viewportUpdateMode != FullViewportUpdate) - viewport()->update(d->rubberBandRegion(viewport(), d->rubberBandRect)); - else - viewport()->update(); - } + // Update new and old rubberband regions + if (!d->rubberBandRect.isEmpty()) { + QRegion rubberBandRegion(d->rubberBandRegion(viewport(), d->rubberBandRect)); + rubberBandRegion += rubberBandRegion.translated(-dx, -dy); + viewport()->update(rubberBandRegion); + } #endif - - if (d->viewportUpdateMode != QGraphicsView::NoViewportUpdate){ - if (d->accelerateScrolling && d->viewportUpdateMode != FullViewportUpdate) - viewport()->scroll(dx, dy); - else + viewport()->scroll(dx, dy); + } else { + viewport()->update(); + } + } else { viewport()->update(); + } } + d->updateLastCenterPoint(); if ((d->cacheMode & CacheBackground) diff --git a/src/gui/graphicsview/qgraphicsview_p.h b/src/gui/graphicsview/qgraphicsview_p.h index 2109673..a76279e 100644 --- a/src/gui/graphicsview/qgraphicsview_p.h +++ b/src/gui/graphicsview/qgraphicsview_p.h @@ -85,7 +85,8 @@ public: qint64 verticalScroll() const; QList<QGraphicsItem *> itemsInArea(const QPainterPath &path, - Qt::ItemSelectionMode mode = Qt::IntersectsItemShape) const; + Qt::ItemSelectionMode mode = Qt::IntersectsItemShape, + Qt::SortOrder = Qt::AscendingOrder) const; QPointF mousePressItemPoint; QPointF mousePressScenePoint; @@ -172,9 +173,7 @@ public: void updateRegion(const QRegion ®ion); bool updateSceneSlotReimplementedChecked; - QList<QGraphicsItem *> findItems(const QRegion &exposedRegion, - const QTransform &worldTransform, - bool *allItems) const; + QList<QGraphicsItem *> findItems(const QRegion &exposedRegion, bool *allItems) const; void generateStyleOptions(const QList<QGraphicsItem *> &itemList, QGraphicsItem **itemArray, diff --git a/src/gui/graphicsview/qgraphicswidget.cpp b/src/gui/graphicsview/qgraphicswidget.cpp index 5cc18f9..7f02fb9 100644 --- a/src/gui/graphicsview/qgraphicswidget.cpp +++ b/src/gui/graphicsview/qgraphicswidget.cpp @@ -366,32 +366,33 @@ void QGraphicsWidget::resize(const QSizeF &size) void QGraphicsWidget::setGeometry(const QRectF &rect) { QGraphicsWidgetPrivate *wd = QGraphicsWidget::d_func(); - const QGraphicsLayoutItemPrivate *d = QGraphicsLayoutItem::d_ptr; - setAttribute(Qt::WA_Resized); - QRectF newGeom = rect; - newGeom.setSize(rect.size().expandedTo(effectiveSizeHint(Qt::MinimumSize)) - .boundedTo(effectiveSizeHint(Qt::MaximumSize))); - if (newGeom == d->geom) - return; - - // Update and prepare to change the geometry (remove from index). - if (wd->scene) { - if (rect.topLeft() != d->geom.topLeft()) - wd->fullUpdateHelper(true); - else - update(); - } - prepareGeometryChange(); - - // setPos triggers ItemPositionChange, which can adjust position + QGraphicsLayoutItemPrivate *d = QGraphicsLayoutItem::d_ptr; + QRectF newGeom; QPointF oldPos = d->geom.topLeft(); - wd->inSetGeometry = 1; - wd->setPosHelper(newGeom.topLeft(), /* update = */ false); - wd->inSetGeometry = 0; - newGeom.moveTopLeft(pos()); - - if (newGeom == d->geom) - return; + if (!wd->inSetPos) { + setAttribute(Qt::WA_Resized); + newGeom = rect; + newGeom.setSize(rect.size().expandedTo(effectiveSizeHint(Qt::MinimumSize)) + .boundedTo(effectiveSizeHint(Qt::MaximumSize))); + if (newGeom == d->geom) + return; + + // setPos triggers ItemPositionChange, which can adjust position + wd->inSetGeometry = 1; + wd->setPosHelper(newGeom.topLeft()); + wd->inSetGeometry = 0; + newGeom.moveTopLeft(pos()); + + if (newGeom == d->geom) + return; + + // Update and prepare to change the geometry (remove from index) if the size has changed. + if (wd->scene) { + if (rect.topLeft() == d->geom.topLeft()) { + prepareGeometryChange(); + } + } + } // Update the layout item geometry bool moved = oldPos != pos(); @@ -401,6 +402,11 @@ void QGraphicsWidget::setGeometry(const QRectF &rect) event.setOldPos(oldPos); event.setNewPos(pos()); QApplication::sendEvent(this, &event); + if (wd->inSetPos) { + //set the new pos + d->geom.moveTopLeft(pos()); + return; + } } QSizeF oldSize = size(); QGraphicsLayoutItem::setGeometry(newGeom); @@ -1016,9 +1022,11 @@ QVariant QGraphicsWidget::itemChange(GraphicsItemChange change, const QVariant & break; case ItemPositionHasChanged: if (!d->inSetGeometry) { + d->inSetPos = 1; // Ensure setGeometry is called (avoid recursion when setPos is // called from within setGeometry). setGeometry(QRectF(pos(), size())); + d->inSetPos = 0 ; } break; case ItemParentChange: { @@ -1269,6 +1277,8 @@ bool QGraphicsWidget::event(QEvent *event) break; case QEvent::Polish: polishEvent(); + d->polished = true; + d->updateFont(d->font); break; case QEvent::WindowActivate: case QEvent::WindowDeactivate: diff --git a/src/gui/graphicsview/qgraphicswidget_p.cpp b/src/gui/graphicsview/qgraphicswidget_p.cpp index 641409d..789f8da 100644 --- a/src/gui/graphicsview/qgraphicswidget_p.cpp +++ b/src/gui/graphicsview/qgraphicswidget_p.cpp @@ -274,6 +274,8 @@ void QGraphicsWidgetPrivate::updateFont(const QFont &font) } } + if (!polished) + return; // Notify change. QEvent event(QEvent::FontChange); QApplication::sendEvent(q, &event); diff --git a/src/gui/graphicsview/qgraphicswidget_p.h b/src/gui/graphicsview/qgraphicswidget_p.h index afa6812..53eaa31 100644 --- a/src/gui/graphicsview/qgraphicswidget_p.h +++ b/src/gui/graphicsview/qgraphicswidget_p.h @@ -85,6 +85,8 @@ public: inheritedPaletteResolveMask(0), inheritedFontResolveMask(0), inSetGeometry(0), + polished(0), + inSetPos(0), focusPolicy(Qt::NoFocus), focusNext(0), focusPrev(0), @@ -193,6 +195,8 @@ public: } quint32 attributes : 10; quint32 inSetGeometry : 1; + quint32 polished: 1; + quint32 inSetPos : 1; // Focus Qt::FocusPolicy focusPolicy; diff --git a/src/gui/image/qimage.cpp b/src/gui/image/qimage.cpp index 558d574..c7a20db 100644 --- a/src/gui/image/qimage.cpp +++ b/src/gui/image/qimage.cpp @@ -3607,6 +3607,9 @@ int QImage::pixelIndex(int x, int y) const If the \a position is not valid, the results are undefined. + \warning This function is expensive when used for massive pixel + manipulations. + \sa setPixel(), valid(), {QImage#Pixel Manipulation}{Pixel Manipulation} */ @@ -4937,10 +4940,12 @@ int QImage::dotsPerMeterY() const meter, to \a x. Together with dotsPerMeterY(), this number defines the intended - scale and aspect ratio of the image. + scale and aspect ratio of the image, and determines the scale + at which QPainter will draw graphics on the image. It does not + change the scale or aspect ratio of the image when it is rendered + on other paint devices. - \sa dotsPerMeterX(), {QImage#Image Information}{Image - Information} + \sa dotsPerMeterX(), {QImage#Image Information}{Image Information} */ void QImage::setDotsPerMeterX(int x) { @@ -4957,10 +4962,12 @@ void QImage::setDotsPerMeterX(int x) to \a y. Together with dotsPerMeterX(), this number defines the intended - scale and aspect ratio of the image. + scale and aspect ratio of the image, and determines the scale + at which QPainter will draw graphics on the image. It does not + change the scale or aspect ratio of the image when it is rendered + on other paint devices. - \sa dotsPerMeterY(), {QImage#Image Information}{Image - Information} + \sa dotsPerMeterY(), {QImage#Image Information}{Image Information} */ void QImage::setDotsPerMeterY(int y) { @@ -5577,6 +5584,8 @@ bool QImage::isDetached() const Use one of the composition mods in QPainter::CompositionMode instead. + \warning This function is expensive. + \sa alphaChannel(), {QImage#Image Transformations}{Image Transformations}, {QImage#Image Formats}{Image Formats} */ @@ -5659,6 +5668,11 @@ void QImage::setAlphaChannel(const QImage &alphaChannel) \l{QPixmap::}{alphaChannel()}, which works in the same way as this function on QPixmaps. + Most usecases for this function can be replaced with QPainter and + using composition modes. + + \warning This is an expensive function. + \sa setAlphaChannel(), hasAlphaChannel(), {QPixmap#Pixmap Information}{Pixmap}, {QImage#Image Transformations}{Image Transformations} diff --git a/src/gui/image/qimagereader.cpp b/src/gui/image/qimagereader.cpp index 5de39d9..7f36be9 100644 --- a/src/gui/image/qimagereader.cpp +++ b/src/gui/image/qimagereader.cpp @@ -1337,6 +1337,7 @@ QByteArray QImageReader::imageFormat(QIODevice *device) \row \o TIFF \o Tagged Image File Format \row \o XBM \o X11 Bitmap \row \o XPM \o X11 Pixmap + \row \o SVG \o Scalable Vector Graphics \endtable Reading and writing SVG files is supported through Qt's diff --git a/src/gui/image/qnativeimage.cpp b/src/gui/image/qnativeimage.cpp index 6b74323..33e565c 100644 --- a/src/gui/image/qnativeimage.cpp +++ b/src/gui/image/qnativeimage.cpp @@ -100,7 +100,9 @@ QNativeImage::QNativeImage(int width, int height, QImage::Format format, bool is bmi.blueMask = 0; } - hdc = CreateCompatibleDC(qt_win_display_dc()); + HDC display_dc = GetDC(0); + hdc = CreateCompatibleDC(display_dc); + ReleaseDC(0, display_dc); Q_ASSERT(hdc); uchar *bits = 0; diff --git a/src/gui/image/qpaintengine_pic.cpp b/src/gui/image/qpaintengine_pic.cpp index cba9827..a130a1a 100644 --- a/src/gui/image/qpaintengine_pic.cpp +++ b/src/gui/image/qpaintengine_pic.cpp @@ -346,7 +346,7 @@ void QPicturePaintEngine::writeCmdLength(int pos, const QRectF &r, bool corr) if (corr) { // widen bounding rect int w2 = painter()->pen().width() / 2; br.setCoords(br.left() - w2, br.top() - w2, - br.right() + w2, br.bottom() + w2); + br.right() + w2, br.bottom() + w2); } br = painter()->transform().mapRect(br); if (painter()->hasClipping()) { @@ -458,6 +458,25 @@ void QPicturePaintEngine::drawTiledPixmap(const QRectF &r, const QPixmap &pixmap writeCmdLength(pos, r, false); } +void QPicturePaintEngine::drawImage(const QRectF &r, const QImage &image, const QRectF &sr, + Qt::ImageConversionFlags flags) +{ + Q_D(QPicturePaintEngine); +#ifdef QT_PICTURE_DEBUG + qDebug() << " -> drawImage():" << r << sr; +#endif + int pos; + SERIALIZE_CMD(QPicturePrivate::PdcDrawImage); + if (d->pic_d->in_memory_only) { + int index = d->pic_d->image_list.size(); + d->pic_d->image_list.append(image); + d->s << r << index << sr << (quint32) flags; + } else { + d->s << r << image << sr << (quint32) flags; + } + writeCmdLength(pos, r, false); +} + extern int qt_defaultDpi(); void QPicturePaintEngine::drawTextItem(const QPointF &p , const QTextItem &ti) diff --git a/src/gui/image/qpaintengine_pic_p.h b/src/gui/image/qpaintengine_pic_p.h index 3ae0845..745d057 100644 --- a/src/gui/image/qpaintengine_pic_p.h +++ b/src/gui/image/qpaintengine_pic_p.h @@ -100,6 +100,8 @@ public: void drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr); void drawTiledPixmap(const QRectF &r, const QPixmap &pixmap, const QPointF &s); + void drawImage(const QRectF &r, const QImage &image, const QRectF &sr, + Qt::ImageConversionFlags flags = Qt::AutoColor); void drawTextItem(const QPointF &p, const QTextItem &ti); Type type() const { return Picture; } diff --git a/src/gui/image/qpicture.cpp b/src/gui/image/qpicture.cpp index d5d7cb0..92023e0 100644 --- a/src/gui/image/qpicture.cpp +++ b/src/gui/image/qpicture.cpp @@ -759,13 +759,21 @@ bool QPicture::exec(QPainter *painter, QDataStream &s, int nrecords) QImage image; if (d->formatMajor < 4) { s >> p >> image; - painter->drawPixmap(p, QPixmap::fromImage(image)); + painter->drawImage(p, image); } else if (d->formatMajor <= 5){ s >> ir >> image; - painter->drawPixmap(ir, QPixmap::fromImage(image), QRect(0, 0, ir.width(), ir.height())); + painter->drawImage(ir, image, QRect(0, 0, ir.width(), ir.height())); } else { - s >> r >> image; - painter->drawPixmap(r, QPixmap::fromImage(image), QRectF(0, 0, r.width(), r.height())); + QRectF sr; + if (d->in_memory_only) { + int index; + s >> r >> index >> sr >> ul; + Q_ASSERT(index < d->image_list.size()); + image = d->image_list.at(index); + } else { + s >> r >> image >> sr >> ul; + } + painter->drawImage(r, image, sr, Qt::ImageConversionFlags(ul)); } } break; diff --git a/src/gui/image/qpicture_p.h b/src/gui/image/qpicture_p.h index 1da7f07..a3fd34f 100644 --- a/src/gui/image/qpicture_p.h +++ b/src/gui/image/qpicture_p.h @@ -158,6 +158,7 @@ public: QRect override_rect; QPaintEngine *paintEngine; bool in_memory_only; + QList<QImage> image_list; QList<QPixmap> pixmap_list; QList<QBrush> brush_list; QList<QPen> pen_list; diff --git a/src/gui/image/qpixmap.cpp b/src/gui/image/qpixmap.cpp index 8684a1b..efb8260 100644 --- a/src/gui/image/qpixmap.cpp +++ b/src/gui/image/qpixmap.cpp @@ -674,7 +674,7 @@ void QPixmap::resize_helper(const QSize &s) pixels black. The effect of this function is undefined when the pixmap is being painted on. - This is potentially an expensive operation. + \warning This is potentially an expensive operation. \sa mask(), {QPixmap#Pixmap Transformations}{Pixmap Transformations}, QBitmap @@ -1380,6 +1380,12 @@ void QPixmap::deref() If the given \a size is empty, this function returns a null pixmap. + + In some cases it can be more beneficial to draw the pixmap to a + painter with a scale set rather than scaling the pixmap. This is + the case when the painter is for instance based on OpenGL or when + the scale factor changes rapidly. + \sa isNull(), {QPixmap#Pixmap Transformations}{Pixmap Transformations} @@ -1751,6 +1757,10 @@ int QPixmap::metric(PaintDeviceMetric metric) const The effect of this function is undefined when the pixmap is being painted on. + \warning This is potentially an expensive operation. Most usecases + for this function are covered by QPainter and compositionModes + which will normally execute faster. + \sa alphaChannel(), {QPixmap#Pixmap Transformations}{Pixmap Transformations} */ @@ -1793,6 +1803,9 @@ void QPixmap::setAlphaChannel(const QPixmap &alphaChannel) \image alphachannelimage.png The pixmap and channelImage QPixmaps + \warning This is an expensive operation. The alpha channel of the + pixmap is extracted dynamically from the pixeldata. + \sa setAlphaChannel(), {QPixmap#Pixmap Information}{Pixmap Information} */ @@ -1814,7 +1827,8 @@ QPaintEngine *QPixmap::paintEngine() const Extracts a bitmap mask from the pixmap's alphachannel. - This is potentially an expensive operation. + \warning This is potentially an expensive operation. The mask of + the pixmap is extracted dynamically from the pixeldata. \sa setMask(), {QPixmap#Pixmap Information}{Pixmap Information} */ diff --git a/src/gui/image/qpixmap_mac.cpp b/src/gui/image/qpixmap_mac.cpp index bfc605b..26d9618 100644 --- a/src/gui/image/qpixmap_mac.cpp +++ b/src/gui/image/qpixmap_mac.cpp @@ -303,7 +303,7 @@ void QMacPixmapData::fromImage(const QImage &img, else one_bit = one_bit >> (x % 8); if ((one_bit & 0x01)) - *(drow+x) = 0x00000000; + *(drow+x) = 0xFF000000; else *(drow+x) = 0xFFFFFFFF; } diff --git a/src/gui/image/qpixmap_x11.cpp b/src/gui/image/qpixmap_x11.cpp index d758221..38916c7 100644 --- a/src/gui/image/qpixmap_x11.cpp +++ b/src/gui/image/qpixmap_x11.cpp @@ -1288,6 +1288,12 @@ void QX11PixmapData::setMask(const QBitmap &newmask) 0, 0, 0, 0, 0, 0, w, h); release(); *this = newData; + // the new QX11PixmapData object isn't referenced yet, so + // ref it + ref.ref(); + + // the below is to make sure the QX11PixmapData destructor + // doesn't delete our newly created render picture newData.hd = 0; newData.x11_mask = 0; newData.picture = 0; @@ -1431,7 +1437,7 @@ QImage QX11PixmapData::toImage() const // we may have to swap the byte order if ((QSysInfo::ByteOrder == QSysInfo::LittleEndian && xi->byte_order == MSBFirst) - || (QSysInfo::ByteOrder == QSysInfo::BigEndian)) + || (QSysInfo::ByteOrder == QSysInfo::BigEndian && xi->byte_order == LSBFirst)) { for (int i=0; i < image.height(); i++) { uint *p = (uint*)image.scanLine(i); diff --git a/src/gui/image/qpixmapcache.cpp b/src/gui/image/qpixmapcache.cpp index 4253f8d..458d6b9 100644 --- a/src/gui/image/qpixmapcache.cpp +++ b/src/gui/image/qpixmapcache.cpp @@ -187,6 +187,11 @@ bool QPMCache::insert(const QString& key, const QPixmap &pixmap, int cost) cacheKeys.insert(key, cacheKey); return true; } + qint64 oldCacheKey = cacheKeys.value(key, -1); + //If for the same key we add already a pixmap we should delete it + if (oldCacheKey != -1) + QCache<qint64, QDetachedPixmap>::remove(oldCacheKey); + bool success = QCache<qint64, QDetachedPixmap>::insert(cacheKey, new QDetachedPixmap(pixmap), cost); if (success) { cacheKeys.insert(key, cacheKey); @@ -275,7 +280,8 @@ bool QPixmapCache::insert(const QString &key, const QPixmap &pm) /*! Returns the cache limit (in kilobytes). - The default cache limit is 2048 KB for Embedded, 10240 KB for Desktops. + The default cache limit is 2048 KB for Embedded, 10240 KB for + Desktops. \sa setCacheLimit() */ @@ -288,7 +294,8 @@ int QPixmapCache::cacheLimit() /*! Sets the cache limit to \a n kilobytes. - The default setting is 1024 kilobytes. + The default setting is 2048 KB for Embedded, 10240 KB for + Desktops. \sa cacheLimit() */ diff --git a/src/gui/image/qpixmapdata_p.h b/src/gui/image/qpixmapdata_p.h index 2e4da40..7296426 100644 --- a/src/gui/image/qpixmapdata_p.h +++ b/src/gui/image/qpixmapdata_p.h @@ -109,6 +109,7 @@ protected: private: friend class QPixmap; friend class QGLContextPrivate; + friend class QX11PixmapData; QAtomicInt ref; int detach_no; diff --git a/src/gui/inputmethod/qwininputcontext_win.cpp b/src/gui/inputmethod/qwininputcontext_win.cpp index 720f0b8..e3e8aa4 100644 --- a/src/gui/inputmethod/qwininputcontext_win.cpp +++ b/src/gui/inputmethod/qwininputcontext_win.cpp @@ -57,15 +57,17 @@ #ifdef Q_IME_DEBUG #include "qdebug.h" -#endif - -QT_BEGIN_NAMESPACE +#endif -extern bool qt_sendSpontaneousEvent(QObject*, QEvent*); #if defined(Q_OS_WINCE) extern void qt_wince_show_SIP(bool show); // defined in qguifunctions_wince.cpp #endif +QT_BEGIN_NAMESPACE + +extern bool qt_sendSpontaneousEvent(QObject*, QEvent*); + + DEFINE_GUID(IID_IActiveIMMApp, 0x08c0e040, 0x62d1, 0x11d1, 0x93, 0x26, 0x0, 0x60, 0xb0, 0x67, 0xb8, 0x6e); diff --git a/src/gui/inputmethod/qximinputcontext_p.h b/src/gui/inputmethod/qximinputcontext_p.h index ca2103b..3773122 100644 --- a/src/gui/inputmethod/qximinputcontext_p.h +++ b/src/gui/inputmethod/qximinputcontext_p.h @@ -98,6 +98,7 @@ public: QString text; QBitArray selectedChars; bool composing; + bool preeditEmpty; void clear(); }; diff --git a/src/gui/inputmethod/qximinputcontext_x11.cpp b/src/gui/inputmethod/qximinputcontext_x11.cpp index 2fbe86f..c320fb4 100644 --- a/src/gui/inputmethod/qximinputcontext_x11.cpp +++ b/src/gui/inputmethod/qximinputcontext_x11.cpp @@ -264,6 +264,7 @@ extern "C" { qic->standardFormat(QInputContext::PreeditFormat)); attrs << QInputMethodEvent::Attribute(QInputMethodEvent::Cursor, cursor, sellen ? 0 : 1, QVariant()); QInputMethodEvent e(data->text, attrs); + data->preeditEmpty = data->text.isEmpty(); qic->sendEvent(e); return 0; @@ -286,11 +287,14 @@ void QXIMInputContext::ICData::clear() text = QString(); selectedChars.clear(); composing = false; + preeditEmpty = true; } QXIMInputContext::ICData *QXIMInputContext::icData() const { - return ximData.value(focusWidget()->effectiveWinId()); + if (QWidget *w = focusWidget()) + return ximData.value(w->effectiveWinId()); + return 0; } /* The cache here is needed, as X11 leaks a few kb for every XFreeFontSet call, so we avoid creating and deletion of fontsets as @@ -433,7 +437,8 @@ void QXIMInputContext::create_xim() // reinitialize input context after the input method // server (like SCIM) has been launched without // requiring the user to manually switch focus. - if (focusWidget->testAttribute(Qt::WA_InputMethodEnabled)) + if (focusWidget->testAttribute(Qt::WA_InputMethodEnabled) + && focusWidget->testAttribute(Qt::WA_WState_Created)) setFocusWidget(focusWidget); } // following code fragment is not required for immodule @@ -531,12 +536,14 @@ void QXIMInputContext::reset() if (data->ic) { char *mb = XmbResetIC(data->ic); + QInputMethodEvent e; if (mb) { - QInputMethodEvent e; e.setCommitString(QString::fromLocal8Bit(mb)); - sendEvent(e); XFree(mb); - + data->preeditEmpty = false; // force sending an event + } + if (!data->preeditEmpty) { + sendEvent(e); update(); } } @@ -562,12 +569,14 @@ void QXIMInputContext::mouseHandler(int pos, QMouseEvent *e) return; XIM_DEBUG("QXIMInputContext::mouseHandler pos=%d", pos); - ICData *data = ximData.value(focusWidget()->effectiveWinId()); - if (!data) - return; - if (pos < 0 || pos > data->text.length()) - reset(); - // ##### handle mouse position + if (QWidget *w = focusWidget()) { + ICData *data = ximData.value(w->effectiveWinId()); + if (!data) + return; + if (pos < 0 || pos > data->text.length()) + reset(); + // ##### handle mouse position + } } bool QXIMInputContext::isComposing() const @@ -683,6 +692,7 @@ QXIMInputContext::ICData *QXIMInputContext::createICData(QWidget *w) { ICData *data = new ICData; data->widget = w; + data->preeditEmpty = true; XVaNestedList preedit_attr = 0; XIMCallback startcallback, drawcallback, donecallback; diff --git a/src/gui/itemviews/qabstractitemview.cpp b/src/gui/itemviews/qabstractitemview.cpp index c7ba95d..83e05b4 100644 --- a/src/gui/itemviews/qabstractitemview.cpp +++ b/src/gui/itemviews/qabstractitemview.cpp @@ -88,6 +88,7 @@ QAbstractItemViewPrivate::QAbstractItemViewPrivate() autoScroll(true), autoScrollMargin(16), autoScrollCount(0), + shouldScrollToCurrentOnShow(false), alternatingColors(false), textElideMode(Qt::ElideRight), verticalScrollMode(QAbstractItemView::ScrollPerItem), @@ -1374,9 +1375,15 @@ bool QAbstractItemView::event(QEvent *event) { Q_D(QAbstractItemView); switch (event->type()) { + case QEvent::Paint: + //we call this here because the scrollbars' visibility might be altered + //so this can't be done in the paintEvent method + d->executePostedLayout(); //make sure we set the layout properly + break; case QEvent::Show: - { - d->executePostedLayout(); //make sure we set the layout properly + d->executePostedLayout(); //make sure we set the layout properly + if (d->shouldScrollToCurrentOnShow) { + d->shouldScrollToCurrentOnShow = false; const QModelIndex current = currentIndex(); if (current.isValid() && (d->state == QAbstractItemView::EditingState || d->autoScroll)) scrollTo(current); @@ -1395,6 +1402,9 @@ bool QAbstractItemView::event(QEvent *event) case QEvent::FocusOut: d->checkPersistentEditorFocus(); break; + case QEvent::FontChange: + d->doDelayedItemsLayout(); // the size of the items will change + break; default: break; } @@ -1501,12 +1511,7 @@ void QAbstractItemView::mousePressEvent(QMouseEvent *event) // when the user is interacting with it (ie. clicking on it) bool autoScroll = d->autoScroll; d->autoScroll = false; - // setSelection will update the current item too - // and it seems that the two updates are not merged - bool updates = d->viewport->updatesEnabled(); - d->viewport->setUpdatesEnabled(command == QItemSelectionModel::NoUpdate); d->selectionModel->setCurrentIndex(index, QItemSelectionModel::NoUpdate); - d->viewport->setUpdatesEnabled(updates); d->autoScroll = autoScroll; QRect rect(d->pressedPosition - offset, pos); setSelection(rect, command); @@ -3160,14 +3165,18 @@ void QAbstractItemView::currentChanged(const QModelIndex ¤t, const QModelI d->updateDirtyRegion(); } } - if (isVisible() && current.isValid() && !d->autoScrollTimer.isActive()) { - if (d->autoScroll) - scrollTo(current); - d->setDirtyRegion(visualRect(current)); - d->updateDirtyRegion(); - edit(current, CurrentChanged, 0); - if (current.row() == (d->model->rowCount(d->root) - 1)) - d->_q_fetchMore(); + if (current.isValid() && !d->autoScrollTimer.isActive()) { + if (isVisible()) { + if (d->autoScroll) + scrollTo(current); + d->setDirtyRegion(visualRect(current)); + d->updateDirtyRegion(); + edit(current, CurrentChanged, 0); + if (current.row() == (d->model->rowCount(d->root) - 1)) + d->_q_fetchMore(); + } else { + d->shouldScrollToCurrentOnShow = d->autoScroll; + } } } diff --git a/src/gui/itemviews/qabstractitemview_p.h b/src/gui/itemviews/qabstractitemview_p.h index 37fe4a2..16bd1ab 100644 --- a/src/gui/itemviews/qabstractitemview_p.h +++ b/src/gui/itemviews/qabstractitemview_p.h @@ -359,6 +359,7 @@ public: QBasicTimer autoScrollTimer; int autoScrollMargin; int autoScrollCount; + bool shouldScrollToCurrentOnShow; //used to know if we should scroll to current on show event bool alternatingColors; diff --git a/src/gui/itemviews/qheaderview.cpp b/src/gui/itemviews/qheaderview.cpp index 5bd82d4..dc63b25 100644 --- a/src/gui/itemviews/qheaderview.cpp +++ b/src/gui/itemviews/qheaderview.cpp @@ -1388,8 +1388,7 @@ int QHeaderView::defaultSectionSize() const void QHeaderView::setDefaultSectionSize(int size) { Q_D(QHeaderView); - d->defaultSectionSize = size; - d->forceInitializing = true; + d->setDefaultSectionSize(size); } /*! @@ -1894,9 +1893,6 @@ void QHeaderView::initializeSections() //make sure we update the hidden sections if (newCount < oldCount) d->updateHiddenSections(0, newCount-1); - } else if (d->forceInitializing) { - initializeSections(0, newCount - 1); - d->forceInitializing = false; } } @@ -1952,7 +1948,7 @@ void QHeaderView::initializeSections(int start, int end) if (!d->sectionHidden.isEmpty()) d->sectionHidden.resize(d->sectionCount); - if (d->sectionCount > oldCount || d->forceInitializing) + if (d->sectionCount > oldCount) d->createSectionSpan(start, end, (end - start + 1) * d->defaultSectionSize, d->globalResizeMode); //Q_ASSERT(d->headerLength() == d->length); @@ -3364,6 +3360,29 @@ void QHeaderViewPrivate::cascadingResize(int visual, int newSize) viewport->update(); } +void QHeaderViewPrivate::setDefaultSectionSize(int size) +{ + Q_Q(QHeaderView); + defaultSectionSize = size; + int currentVisualIndex = 0; + for (int i = 0; i < sectionSpans.count(); ++i) { + QHeaderViewPrivate::SectionSpan &span = sectionSpans[i]; + if (span.size > 0) { + //we resize it if it is not hidden (ie size > 0) + const int newSize = span.count * size; + if (newSize != span.size) { + length += newSize - span.size; //the whole length is changed + const int oldSectionSize = span.sectionSize(); + span.size = span.count * size; + for (int i = currentVisualIndex; i < currentVisualIndex + span.count; ++i) { + emit q->sectionResized(logicalIndex(i), oldSectionSize, size); + } + } + } + currentVisualIndex += span.count; + } +} + void QHeaderViewPrivate::resizeSectionSpan(int visualIndex, int oldSize, int newSize) { Q_Q(QHeaderView); diff --git a/src/gui/itemviews/qheaderview_p.h b/src/gui/itemviews/qheaderview_p.h index fbba69a..2889f08 100644 --- a/src/gui/itemviews/qheaderview_p.h +++ b/src/gui/itemviews/qheaderview_p.h @@ -90,7 +90,6 @@ public: highlightSelected(false), stretchLastSection(false), cascadingResizing(false), - forceInitializing(false), stretchSections(0), contentsSections(0), minimumSectionSize(-1), @@ -275,7 +274,6 @@ public: bool highlightSelected; bool stretchLastSection; bool cascadingResizing; - bool forceInitializing; int stretchSections; int contentsSections; int defaultSectionSize; @@ -310,6 +308,7 @@ public: void createSectionSpan(int start, int end, int size, QHeaderView::ResizeMode mode); void removeSectionsFromSpans(int start, int end); void resizeSectionSpan(int visualIndex, int oldSize, int newSize); + void setDefaultSectionSize(int size); inline int headerSectionCount() const { // for debugging int count = 0; diff --git a/src/gui/itemviews/qitemdelegate.cpp b/src/gui/itemviews/qitemdelegate.cpp index 0aad6bb..bf9b5c5 100644 --- a/src/gui/itemviews/qitemdelegate.cpp +++ b/src/gui/itemviews/qitemdelegate.cpp @@ -291,6 +291,18 @@ QSizeF QItemDelegatePrivate::doTextLayout(int lineWidth) const setModelData(), and updateEditorGeometry(). This process is described in the \l{Spin Box Delegate Example}. + \section1 QStyledItemDelegate vs. QItemDelegate + + Since Qt 4.4, there are two delegate classes: QItemDelegate and + QStyledItemDelegate. However, the default delegate is QStyledItemDelegate. + These two classes are independent alternatives to painting and providing + editors for items in views. The difference between them is that + QStyledItemDelegate uses the current style to paint its items. We therefore + recommend using QStyledItemDelegate as the base class when implementing + custom delegates or when working with Qt style sheets. The code required + for either class should be equal unless the custom delegate needs to use + the style for drawing. + \sa {Delegate Classes}, QStyledItemDelegate, QAbstractItemDelegate, {Spin Box Delegate Example}, {Settings Editor Example}, {Icons Example} diff --git a/src/gui/itemviews/qitemselectionmodel.cpp b/src/gui/itemviews/qitemselectionmodel.cpp index 1a3ae2d..8baefdf 100644 --- a/src/gui/itemviews/qitemselectionmodel.cpp +++ b/src/gui/itemviews/qitemselectionmodel.cpp @@ -1313,11 +1313,11 @@ bool QItemSelectionModel::rowIntersectsSelection(int row, const QModelIndex &par int left = sel.at(i).left(); int right = sel.at(i).right(); if (top <= row && bottom >= row) { - Qt::ItemFlags leftFlags = d->model->index(row, left, parent).flags(); - Qt::ItemFlags rightFlags = d->model->index(row, right, parent).flags(); - if ((leftFlags & Qt::ItemIsSelectable) && (leftFlags & Qt::ItemIsEnabled) - && (rightFlags & Qt::ItemIsSelectable) && (rightFlags & Qt::ItemIsEnabled)) - return true; + for (int j = left; j <= right; j++) { + const Qt::ItemFlags flags = d->model->index(row, j, parent).flags(); + if ((flags & Qt::ItemIsSelectable) && (flags & Qt::ItemIsEnabled)) + return true; + } } } @@ -1342,11 +1342,11 @@ bool QItemSelectionModel::columnIntersectsSelection(int column, const QModelInde int top = sel.at(i).top(); int bottom = sel.at(i).bottom(); if (left <= column && right >= column) { - Qt::ItemFlags topFlags = d->model->index(top, column, parent).flags(); - Qt::ItemFlags bottomFlags = d->model->index(bottom, column, parent).flags(); - if ((topFlags & Qt::ItemIsSelectable) && (topFlags & Qt::ItemIsEnabled) - && (bottomFlags & Qt::ItemIsSelectable) && (bottomFlags & Qt::ItemIsEnabled)) - return true; + for (int j = top; j <= bottom; j++) { + const Qt::ItemFlags flags = d->model->index(j, column, parent).flags(); + if ((flags & Qt::ItemIsSelectable) && (flags & Qt::ItemIsEnabled)) + return true; + } } } diff --git a/src/gui/itemviews/qlistview.cpp b/src/gui/itemviews/qlistview.cpp index d2fec21..48f53a0 100644 --- a/src/gui/itemviews/qlistview.cpp +++ b/src/gui/itemviews/qlistview.cpp @@ -1997,14 +1997,15 @@ bool QListViewPrivate::doItemsLayout(int delta) int first = batchStartRow(); int last = qMin(first + delta - 1, max); - if (max < 0 || last < first) - return true; // nothing to do - if (first == 0) { layoutChildren(); // make sure the viewport has the right size prepareItemsLayout(); } + if (max < 0 || last < first) { + return true; // nothing to do + } + QListViewLayoutInfo info; info.bounds = layoutBounds; info.grid = gridSize(); @@ -2854,7 +2855,7 @@ void QDynamicListViewBase::addLeaf(QVector<int> &leaf, const QRect &area, continue; vi = &_this->dynamicListView->items[idx]; Q_ASSERT(vi); - if (vi->rect().intersects(area) && vi->visited != visited) { + if (vi->isValid() && vi->rect().intersects(area) && vi->visited != visited) { QModelIndex index = _this->listViewItemToIndex(*vi); Q_ASSERT(index.isValid()); _this->intersectVector.append(index); diff --git a/src/gui/itemviews/qsortfilterproxymodel.cpp b/src/gui/itemviews/qsortfilterproxymodel.cpp index b3993c7..43feda8 100644 --- a/src/gui/itemviews/qsortfilterproxymodel.cpp +++ b/src/gui/itemviews/qsortfilterproxymodel.cpp @@ -144,6 +144,7 @@ public: const QModelIndex &proxy_index) const { Q_ASSERT(proxy_index.isValid()); + Q_ASSERT(proxy_index.model() == q_func()); const void *p = proxy_index.internalPointer(); Q_ASSERT(p); QMap<QModelIndex, Mapping *>::const_iterator it = @@ -311,6 +312,10 @@ QModelIndex QSortFilterProxyModelPrivate::proxy_to_source(const QModelIndex &pro { if (!proxy_index.isValid()) return QModelIndex(); // for now; we may want to be able to set a root index later + if (proxy_index.model() != q_func()) { + qWarning() << "QSortFilterProxyModel: index from wrong model passed to mapToSource"; + return QModelIndex(); + } IndexMap::const_iterator it = index_to_iterator(proxy_index); Mapping *m = it.value(); if ((proxy_index.row() >= m->source_rows.size()) || (proxy_index.column() >= m->source_columns.size())) @@ -324,6 +329,10 @@ QModelIndex QSortFilterProxyModelPrivate::source_to_proxy(const QModelIndex &sou { if (!source_index.isValid()) return QModelIndex(); // for now; we may want to be able to set a root index later + if (source_index.model() != model) { + qWarning() << "QSortFilterProxyModel: index from wrong model passed to mapFromSource"; + return QModelIndex(); + } QModelIndex source_parent = source_index.parent(); IndexMap::const_iterator it = create_mapping(source_parent); Mapping *m = it.value(); @@ -1032,9 +1041,21 @@ void QSortFilterProxyModelPrivate::_q_sourceDataChanged(const QModelIndex &sourc } } - if (!source_rows_remove.isEmpty()) + if (!source_rows_remove.isEmpty()) { remove_source_items(m->proxy_rows, m->source_rows, source_rows_remove, source_parent, Qt::Vertical); + QSet<int> source_rows_remove_set = source_rows_remove.toList().toSet(); + QVector<QModelIndex>::iterator it = m->mapped_children.begin(); + while (it != m->mapped_children.end()) { + const QModelIndex source_child_index = *it; + if (source_rows_remove_set.contains(source_child_index.row())) { + it = m->mapped_children.erase(it); + remove_from_mapping(source_child_index); + } else { + ++it; + } + } + } if (!source_rows_resort.isEmpty()) { // Re-sort the rows @@ -1103,6 +1124,8 @@ void QSortFilterProxyModelPrivate::_q_sourceReset() // All internal structures are deleted in clear() q->reset(); update_source_sort_column(); + if (dynamic_sortfilter) + sort(); } void QSortFilterProxyModelPrivate::_q_sourceLayoutAboutToBeChanged() @@ -1495,6 +1518,7 @@ void QSortFilterProxyModel::setSourceModel(QAbstractItemModel *sourceModel) d->clear_mapping(); reset(); + d->update_source_sort_column(); } /*! @@ -1566,6 +1590,10 @@ bool QSortFilterProxyModel::hasChildren(const QModelIndex &parent) const return false; if (!d->model->hasChildren(source_parent)) return false; + + if (d->model->canFetchMore(source_parent)) + return true; //we assume we might have children that can be fetched + QSortFilterProxyModelPrivate::Mapping *m = d->create_mapping(source_parent).value(); return m->source_rows.count() != 0 && m->source_columns.count() != 0; } @@ -1893,7 +1921,7 @@ QSize QSortFilterProxyModel::span(const QModelIndex &index) const void QSortFilterProxyModel::sort(int column, Qt::SortOrder order) { Q_D(QSortFilterProxyModel); - if (d->proxy_sort_column == column && d->sort_order == order) + if (d->dynamic_sortfilter && d->proxy_sort_column == column && d->sort_order == order) return; d->sort_order = order; d->proxy_sort_column = column; @@ -2107,6 +2135,8 @@ void QSortFilterProxyModel::setDynamicSortFilter(bool enable) { Q_D(QSortFilterProxyModel); d->dynamic_sortfilter = enable; + if (enable) + d->sort(); } /*! diff --git a/src/gui/itemviews/qstyleditemdelegate.cpp b/src/gui/itemviews/qstyleditemdelegate.cpp index 271cc0d..be0971b 100644 --- a/src/gui/itemviews/qstyleditemdelegate.cpp +++ b/src/gui/itemviews/qstyleditemdelegate.cpp @@ -218,16 +218,17 @@ public: The \l{Star Delegate Example}{Star Delegate} example creates editors by reimplementing these methods. - \section1 QStyledItemDelegate and QItemDelegate - - QStyledItemDelegate has taken over the job as default delegate - - leaving QItemDelegate behind. They will now co-exist peacefully as - independent alternatives to painting and providing editors for - items in views. The difference between them is that the new - delegate uses the current style to paint its items. We therefore - recommend using QStyledItemDelegate as base when implementing - custom delegates. The code required should be equal unless the - custom delegate also wishes to use the style for drawing. + \section1 QStyledItemDelegate vs. QItemDelegate + + Since Qt 4.4, there are two delegate classes: QItemDelegate and + QStyledItemDelegate. However, the default delegate is QStyledItemDelegate. + These two classes are independent alternatives to painting and providing + editors for items in views. The difference between them is that + QStyledItemDelegate uses the current style to paint its items. We therefore + recommend using QStyledItemDelegate as the base class when implementing + custom delegates or when working with Qt style sheets. The code required + for either class should be equal unless the custom delegate needs to use + the style for drawing. If you wish to customize the painting of item views, you should implement a custom style. Please see the QStyle class diff --git a/src/gui/itemviews/qtableview.cpp b/src/gui/itemviews/qtableview.cpp index 34bb180..2902768 100644 --- a/src/gui/itemviews/qtableview.cpp +++ b/src/gui/itemviews/qtableview.cpp @@ -320,26 +320,12 @@ QRect QTableViewPrivate::visualSpanRect(const Span &span) const \a drawn is a QBitArray of visualRowCountxvisualCoulumnCount which say if particular cell has been drawn */ void QTableViewPrivate::drawAndClipSpans(const QRect &area, QPainter *painter, - const QStyleOptionViewItemV4 &option, - QBitArray *drawn) + const QStyleOptionViewItemV4 &option, QBitArray *drawn, + int firstVisualRow, int lastVisualRow, int firstVisualColumn, int lastVisualColumn) { bool alternateBase = false; QRegion region = viewport->rect(); - int firstVisualRow = qMax(verticalHeader->visualIndexAt(0),0); - int lastVisualRow = verticalHeader->visualIndexAt(viewport->height()); - if (lastVisualRow == -1) - lastVisualRow = model->rowCount(root) - 1; - - int firstVisualColumn = horizontalHeader->visualIndexAt(0); - int lastVisualColumn = horizontalHeader->visualIndexAt(viewport->width()); - if (q_func()->isRightToLeft()) - qSwap(firstVisualColumn, lastVisualColumn); - if (firstVisualColumn == -1) - firstVisualColumn = 0; - if (lastVisualColumn == -1) - lastVisualColumn = model->columnCount(root) - 1; - QList<Span>::const_iterator it; for (it = spans.constBegin(); it != spans.constEnd(); ++it) { Span span = *it; @@ -768,10 +754,13 @@ void QTableView::paintEvent(QPaintEvent *event) uint y = verticalHeader->length() - verticalHeader->offset() - 1; QVector<QRect> rects = event->region().rects(); + + //firstVisualRow is the visual index of the first visible row. lastVisualRow is the visual index of the last visible Row. + //same goes for ...VisualColumn int firstVisualRow = qMax(verticalHeader->visualIndexAt(0),0); int lastVisualRow = verticalHeader->visualIndexAt(verticalHeader->viewport()->height()); if (lastVisualRow == -1) - lastVisualRow = d->model->rowCount(d->root); + lastVisualRow = d->model->rowCount(d->root) - 1; int firstVisualColumn = horizontalHeader->visualIndexAt(0); int lastVisualColumn = horizontalHeader->visualIndexAt(horizontalHeader->viewport()->width()); @@ -795,7 +784,8 @@ void QTableView::paintEvent(QPaintEvent *event) } if (d->hasSpans()) - d->drawAndClipSpans(dirtyArea, &painter, option, &drawn); + d->drawAndClipSpans(dirtyArea, &painter, option, &drawn, + firstVisualRow, lastVisualRow, firstVisualColumn, lastVisualColumn); // get the horizontal start and end visual sections int left = horizontalHeader->visualIndexAt(dirtyArea.left()); diff --git a/src/gui/itemviews/qtableview_p.h b/src/gui/itemviews/qtableview_p.h index a1c1152..b08eabd 100644 --- a/src/gui/itemviews/qtableview_p.h +++ b/src/gui/itemviews/qtableview_p.h @@ -103,7 +103,8 @@ public: bool spansIntersectColumns(const QList<int> &columns) const; bool spansIntersectRows(const QList<int> &rows) const; void drawAndClipSpans(const QRect &area, QPainter *painter, - const QStyleOptionViewItemV4 &option, QBitArray *drawn); + const QStyleOptionViewItemV4 &option, QBitArray *drawn, + int firstVisualRow, int lastVisualRow, int firstVisualColumn, int lastVisualColumn); void drawCell(QPainter *painter, const QStyleOptionViewItemV4 &option, const QModelIndex &index); bool showGrid; diff --git a/src/gui/itemviews/qtreeview.cpp b/src/gui/itemviews/qtreeview.cpp index 943b194..62c1277 100644 --- a/src/gui/itemviews/qtreeview.cpp +++ b/src/gui/itemviews/qtreeview.cpp @@ -1239,16 +1239,23 @@ bool QTreeView::viewportEvent(QEvent *event) int oldBranch = d->hoverBranch; d->hoverBranch = d->itemDecorationAt(he->pos()); if (oldBranch != d->hoverBranch) { - QRect oldRect = visualRect(d->modelIndex(oldBranch)); - QRect newRect = visualRect(d->modelIndex(d->hoverBranch)); - viewport()->update(oldRect.left() - d->indent, oldRect.top(), d->indent, oldRect.height()); - viewport()->update(newRect.left() - d->indent, newRect.top(), d->indent, newRect.height()); + QModelIndex oldIndex = d->modelIndex(oldBranch), + newIndex = d->modelIndex(d->hoverBranch); + if (oldIndex != newIndex) { + QRect oldRect = visualRect(oldIndex); + QRect newRect = visualRect(newIndex); + viewport()->update(oldRect.left() - d->indent, oldRect.top(), d->indent, oldRect.height()); + viewport()->update(newRect.left() - d->indent, newRect.top(), d->indent, newRect.height()); + } } if (selectionBehavior() == QAbstractItemView::SelectRows) { - QRect oldHoverRect = visualRect(d->hover); - QRect newHoverRect = visualRect(indexAt(he->pos())); - viewport()->update(QRect(0, newHoverRect.y(), viewport()->width(), newHoverRect.height())); - viewport()->update(QRect(0, oldHoverRect.y(), viewport()->width(), oldHoverRect.height())); + QModelIndex newHoverIndex = indexAt(he->pos()); + if (d->hover != newHoverIndex) { + QRect oldHoverRect = visualRect(d->hover); + QRect newHoverRect = visualRect(newHoverIndex); + viewport()->update(QRect(0, newHoverRect.y(), viewport()->width(), newHoverRect.height())); + viewport()->update(QRect(0, oldHoverRect.y(), viewport()->width(), oldHoverRect.height())); + } } break; } default: @@ -1377,7 +1384,7 @@ void QTreeView::drawTree(QPainter *painter, const QRegion ®ion) const // start at the top of the viewport and iterate down to the update area for (; i < viewItems.count(); ++i) { const int itemHeight = d->itemHeight(i); - if (y + itemHeight >= area.top()) + if (y + itemHeight > area.top()) break; y += itemHeight; } @@ -2012,6 +2019,7 @@ int QTreeView::verticalOffset() const // If we are scrolling per item and have non-uniform row heights, // finding the vertical offset in pixels is going to be relatively slow. // ### find a faster way to do this + d->executePostedLayout(); int offset = 0; for (int i = 0; i < d->viewItems.count(); ++i) { if (i == verticalScrollBar()->value()) @@ -2307,11 +2315,12 @@ void QTreeView::scrollContentsBy(int dx, int dy) } } - if (d->viewItems.isEmpty() || d->defaultItemHeight == 0) + const int itemHeight = d->defaultItemHeight <= 0 ? sizeHintForRow(0) : d->defaultItemHeight; + if (d->viewItems.isEmpty() || itemHeight == 0) return; // guestimate the number of items in the viewport - int viewCount = d->viewport->height() / d->defaultItemHeight; + int viewCount = d->viewport->height() / itemHeight; int maxDeltaY = qMin(d->viewItems.count(), viewCount); // no need to do a lot of work if we are going to redraw the whole thing anyway if (qAbs(dy) > qAbs(maxDeltaY) && d->editors.isEmpty()) { @@ -2558,8 +2567,11 @@ void QTreeView::sortByColumn(int column, Qt::SortOrder order) { Q_D(QTreeView); - //will emit a signal connected to _q_sortIndicatorChanged, which then actually sorts + //If sorting is enabled will emit a signal connected to _q_sortIndicatorChanged, which then actually sorts d->header->setSortIndicator(column, order); + //If sorting is not enabled, force to sort now. + if (!d->sortingEnabled) + d->model->sort(column, order); } /*! @@ -3496,6 +3508,7 @@ void QTreeViewPrivate::updateScrollBars() int QTreeViewPrivate::itemDecorationAt(const QPoint &pos) const { + const_cast<QTreeView *>(q_func())->executeDelayedItemsLayout(); int x = pos.x(); int column = header->logicalIndexAt(x); if (column != 0) diff --git a/src/gui/itemviews/qtreewidget.cpp b/src/gui/itemviews/qtreewidget.cpp index 357153d..6103225 100644 --- a/src/gui/itemviews/qtreewidget.cpp +++ b/src/gui/itemviews/qtreewidget.cpp @@ -2951,18 +2951,21 @@ QWidget *QTreeWidget::itemWidget(QTreeWidgetItem *item, int column) const /*! \since 4.1 - Sets the given \a widget to be displayed in the cell specified by - the given \a item and \a column. - - Note that the given \a widget's \l {QWidget}{autoFillBackground} - property must be set to true, otherwise the widget's background will - be transparent, showing both the model data and the tree widget - item. - - This function should only be used to display static content in the - place of a tree widget item. If you want to display custom dynamic - content or implement a custom editor widget, use QTreeView and - subclass QItemDelegate instead. + Sets the given \a widget to be displayed in the cell specified by the given + \a item and \a column. + + The given \a widget's \l {QWidget::}{autoFillBackground} property must be + set to true, otherwise the widget's background will be transparent, showing + both the model data and the tree widget item. + + This function should only be used to display static content in the place of + a tree widget item. If you want to display custom dynamic content or + implement a custom editor widget, use QTreeView and subclass QItemDelegate + instead. + + This function cannot be called before the item hierarchy has been set up, + i.e., the QTreeWidgetItem that will hold \a widget must have been added to + the view before \a widget is set. \note The tree takes ownership of the widget. diff --git a/src/gui/kernel/qapplication.cpp b/src/gui/kernel/qapplication.cpp index 6971ed4..b04d5bf 100644 --- a/src/gui/kernel/qapplication.cpp +++ b/src/gui/kernel/qapplication.cpp @@ -169,189 +169,174 @@ QApplicationPrivate::~QApplicationPrivate() } /*! - \class QApplication - \brief The QApplication class manages the GUI application's control - flow and main settings. - - \ingroup application - \mainclass - - It contains the main event loop, where all events from the window - system and other sources are processed and dispatched. It also - handles the application's initialization and finalization, and - provides session management. It also handles most system-wide and - application-wide settings. - - For any GUI application that uses Qt, there is precisely one - QApplication object, no matter whether the application has 0, 1, 2 - or more windows at any time. For non-GUI Qt applications, use - QCoreApplication instead, which doesn't depend on the \l QtGui - library. - - The QApplication object is accessible through the instance() - function which return a pointer equivalent to the global qApp - pointer. - - QApplication's main areas of responsibility are: - \list - - \o It initializes the application with the user's desktop settings - such as palette(), font() and doubleClickInterval(). It keeps track - of these properties in case the user changes the desktop globally, for - example through some kind of control panel. - - \o It performs event handling, meaning that it receives events - from the underlying window system and dispatches them to the relevant - widgets. By using sendEvent() and postEvent() you can send your own - events to widgets. - - \o It parses common command line arguments and sets its internal - state accordingly. See the \link QApplication::QApplication() - constructor documentation\endlink below for more details about this. - - \o It defines the application's look and feel, which is - encapsulated in a QStyle object. This can be changed at runtime - with setStyle(). - - \o It specifies how the application is to allocate colors. - See setColorSpec() for details. - - \o It provides localization of strings that are visible to the user - via translate(). - - \o It provides some magical objects like the desktop() and the - clipboard(). - - \o It knows about the application's windows. You can ask which - widget is at a certain position using widgetAt(), get a list of - topLevelWidgets() and closeAllWindows(), etc. - - \o It manages the application's mouse cursor handling, - see setOverrideCursor() - - \o On the X window system, it provides functions to flush and sync - the communication stream, see flushX() and syncX(). - - \o It provides support for sophisticated \link - session.html session management \endlink. This makes it possible - for applications to terminate gracefully when the user logs out, to - cancel a shutdown process if termination isn't possible and even to - preserve the entire application's state for a future session. See - isSessionRestored(), sessionId() and commitData() and saveState() - for details. - - \endlist - - Since the QApplication object does so much initialization, it - \e{must} be created before any other objects related to the user - interface are created. - - Since it also deals with common command line arguments, it is - usually a good idea to create it \e before any interpretation or - modification of \c argv is done in the application itself. - - \table - \header \o{2,1} Groups of functions - \row - \o System settings - \o - desktopSettingsAware(), - setDesktopSettingsAware(), - cursorFlashTime(), - setCursorFlashTime(), - doubleClickInterval(), - setDoubleClickInterval(), - setKeyboardInputInterval(), - wheelScrollLines(), - setWheelScrollLines(), - palette(), - setPalette(), - font(), - setFont(), - fontMetrics(). - - \row - \o Event handling - \o - exec(), - processEvents(), - exit(), - quit(). - sendEvent(), - postEvent(), - sendPostedEvents(), - removePostedEvents(), - hasPendingEvents(), - notify(), - macEventFilter(), - qwsEventFilter(), - x11EventFilter(), - x11ProcessEvent(), - winEventFilter(). - - \row - \o GUI Styles - \o - style(), - setStyle(). - - \row - \o Color usage - \o - colorSpec(), - setColorSpec(), - qwsSetCustomColors(). - - \row - \o Text handling - \o - installTranslator(), - removeTranslator() - translate(). - - \row - \o Widgets - \o - allWidgets(), - topLevelWidgets(), - desktop(), - activePopupWidget(), - activeModalWidget(), - clipboard(), - focusWidget(), - winFocus(), - activeWindow(), - widgetAt(). - - \row - \o Advanced cursor handling - \o - overrideCursor(), - setOverrideCursor(), - restoreOverrideCursor(). - - \row - \o X Window System synchronization - \o - flushX(), - syncX(). - - \row - \o Session management - \o - isSessionRestored(), - sessionId(), - commitData(), - saveState(). - - \row - \o Miscellaneous - \o - closeAllWindows(), - startingUp(), - closingDown(), - type(). - \endtable + \class QApplication + \brief The QApplication class manages the GUI application's control + flow and main settings. + + \ingroup application + \mainclass + + QApplication contains the main event loop, where all events from the window + system and other sources are processed and dispatched. It also handles the + application's initialization and finalization, and provides session + management. In addition, it handles most system-wide and application-wide + settings. + + For any GUI application using Qt, there is precisely one QApplication + object, no matter whether the application has 0, 1, 2 or more windows at + any given time. For non-GUI Qt applications, use QCoreApplication instead, + as it does not depend on the \l QtGui library. + + The QApplication object is accessible through the instance() function that + returns a pointer equivalent to the global qApp pointer. + + QApplication's main areas of responsibility are: + \list + \o It initializes the application with the user's desktop settings + such as palette(), font() and doubleClickInterval(). It keeps + track of these properties in case the user changes the desktop + globally, for example through some kind of control panel. + + \o It performs event handling, meaning that it receives events + from the underlying window system and dispatches them to the + relevant widgets. By using sendEvent() and postEvent() you can + send your own events to widgets. + + \o It parses common command line arguments and sets its internal + state accordingly. See the \l{QApplication::QApplication()} + {constructor documentation} below for more details. + + \o It defines the application's look and feel, which is + encapsulated in a QStyle object. This can be changed at runtime + with setStyle(). + + \o It specifies how the application is to allocate colors. See + setColorSpec() for details. + + \o It provides localization of strings that are visible to the + user via translate(). + + \o It provides some magical objects like the desktop() and the + clipboard(). + + \o It knows about the application's windows. You can ask which + widget is at a certain position using widgetAt(), get a list of + topLevelWidgets() and closeAllWindows(), etc. + + \o It manages the application's mouse cursor handling, see + setOverrideCursor() + + \o On the X window system, it provides functions to flush and sync + the communication stream, see flushX() and syncX(). + + \o It provides support for sophisticated \l{Session Management} + {session management}. This makes it possible for applications + to terminate gracefully when the user logs out, to cancel a + shutdown process if termination isn't possible and even to + preserve the entire application's state for a future session. + See isSessionRestored(), sessionId() and commitData() and + saveState() for details. + \endlist + + The QApplication object does so much initialization. Hence, it \e{must} be + created before any other objects related to the user interface are created. + Since QApplication also deals with common command line arguments, it is + usually a good idea to create it \e before any interpretation or + modification of \c argv is done in the application itself. + + \table + \header + \o{2,1} Groups of functions + + \row + \o System settings + \o desktopSettingsAware(), + setDesktopSettingsAware(), + cursorFlashTime(), + setCursorFlashTime(), + doubleClickInterval(), + setDoubleClickInterval(), + setKeyboardInputInterval(), + wheelScrollLines(), + setWheelScrollLines(), + palette(), + setPalette(), + font(), + setFont(), + fontMetrics(). + + \row + \o Event handling + \o exec(), + processEvents(), + exit(), + quit(). + sendEvent(), + postEvent(), + sendPostedEvents(), + removePostedEvents(), + hasPendingEvents(), + notify(), + macEventFilter(), + qwsEventFilter(), + x11EventFilter(), + x11ProcessEvent(), + winEventFilter(). + + \row + \o GUI Styles + \o style(), + setStyle(). + + \row + \o Color usage + \o colorSpec(), + setColorSpec(), + qwsSetCustomColors(). + + \row + \o Text handling + \o installTranslator(), + removeTranslator() + translate(). + + \row + \o Widgets + \o allWidgets(), + topLevelWidgets(), + desktop(), + activePopupWidget(), + activeModalWidget(), + clipboard(), + focusWidget(), + activeWindow(), + widgetAt(). + + \row + \o Advanced cursor handling + \o overrideCursor(), + setOverrideCursor(), + restoreOverrideCursor(). + + \row + \o X Window System synchronization + \o flushX(), + syncX(). + + \row + \o Session management + \o isSessionRestored(), + sessionId(), + commitData(), + saveState(). + + \row + \o Miscellaneous + \o closeAllWindows(), + startingUp(), + closingDown(), + type(). + \endtable \sa QCoreApplication, QAbstractEventDispatcher, QEventLoop, QSettings */ @@ -382,6 +367,7 @@ QApplicationPrivate::~QApplicationPrivate() Returns the top-level widget at the given \a point; returns 0 if there is no such widget. */ + /*! \fn QWidget *QApplication::topLevelAt(int x, int y) @@ -393,8 +379,8 @@ QApplicationPrivate::~QApplicationPrivate() /* - The qt_init() and qt_cleanup() functions are implemented in the - qapplication_xyz.cpp file. + The qt_init() and qt_cleanup() functions are implemented in the + qapplication_xyz.cpp file. */ void qt_init(QApplicationPrivate *priv, int type @@ -580,99 +566,100 @@ void QApplicationPrivate::process_cmdline() } /*! - Initializes the window system and constructs an application object - with \a argc command line arguments in \a argv. - - \warning The data referred to by \a argc and \a argv must stay valid - for the entire lifetime of the QApplication object. In addition, - \a argc must be greater than zero and \a argv must contain at least - one valid character string. - - The global \c qApp pointer refers to this application object. Only - one application object should be created. - - This application object must be constructed before any \link - QPaintDevice paint devices\endlink (including widgets, pixmaps, bitmaps - etc.). - - Note that \a argc and \a argv might be changed. Qt removes command - line arguments that it recognizes. - - Qt debugging options (not available if Qt was compiled without the - QT_DEBUG flag defined): - \list - \o -nograb, tells Qt that it must never grab the mouse or the keyboard. - \o -dograb (only under X11), running under a debugger can cause - an implicit -nograb, use -dograb to override. - \o -sync (only under X11), switches to synchronous mode for - debugging. - \endlist - - See \link debug.html Debugging Techniques \endlink for a more - detailed explanation. - - All Qt programs automatically support the following command line options: - \list - \o -style= \e style, sets the application GUI style. Possible values - are \c motif, \c windows, and \c platinum. If you compiled Qt - with additional styles or have additional styles as plugins these - will be available to the \c -style command line option. - \o -style \e style, is the same as listed above. - \o -stylesheet= \e stylesheet, sets the application \l styleSheet. The value - must be a path to a file that contains the Style Sheet. Note that relative URLs - in the Style Sheet file are relative to the Style Sheet file's path. - \o -stylesheet \e stylesheet, is the same as listed above. - \o -session= \e session, restores the application from an earlier - \link session.html session \endlink. - \o -session \e session, is the same as listed above. - \o -widgetcount, prints debug message at the end about number of widgets left - undestroyed and maximum number of widgets existed at the same time - \o -reverse, sets the application's layout direction to Qt::RightToLeft - \o -graphicssystem, sets the backend to be used for on-screen - widgets and QPixmaps. Available options are \c{raster} and \c{opengl}. - - \endlist - - The Windows version of Qt also support one additional command line - option, if Direct3D support has been compiled into Qt: - \list - \o -direct3d will make the Direct3D paint engine the default widget - paint engine in Qt. \bold {This functionality is experimental.} - \endlist - - The X11 version of Qt also supports some traditional X11 - command line options: - \list - \o -display \e display, sets the X display (default is $DISPLAY). - \o -geometry \e geometry, sets the client geometry of the - first window that is shown. - \o -fn or \c -font \e font, defines the application font. The - font should be specified using an X logical font description. - \o -bg or \c -background \e color, sets the default background color - and an application palette (light and dark shades are calculated). - \o -fg or \c -foreground \e color, sets the default foreground color. - \o -btn or \c -button \e color, sets the default button color. - \o -name \e name, sets the application name. - \o -title \e title, sets the application title. - \o -visual \c TrueColor, forces the application to use a TrueColor visual - on an 8-bit display. - \o -ncols \e count, limits the number of colors allocated in the - color cube on an 8-bit display, if the application is using the - QApplication::ManyColor color specification. If \e count is - 216 then a 6x6x6 color cube is used (i.e. 6 levels of red, 6 of green, - and 6 of blue); for other values, a cube - approximately proportional to a 2x3x1 cube is used. - \o -cmap, causes the application to install a private color map - on an 8-bit display. - \o -im, sets the input method server (equivalent to setting the XMODIFIERS - environment variable) - \o -inputstyle, defines how the input is inserted into the given widget. E.g., - \c onTheSpot makes the input appear directly in the widget, while - \c overTheSpot makes the input appear in a box floating over the - widget and is not inserted until the editing is done. - \endlist - - \sa arguments() + Initializes the window system and constructs an application object with + \a argc command line arguments in \a argv. + + \warning The data referred to by \a argc and \a argv must stay valid for + the entire lifetime of the QApplication object. In addition, \a argc must + be greater than zero and \a argv must contain at least one valid character + string. + + The global \c qApp pointer refers to this application object. Only one + application object should be created. + + This application object must be constructed before any \l{QPaintDevice} + {paint devices} (including widgets, pixmaps, bitmaps etc.). + + \note \a argc and \a argv might be changed as Qt removes command line + arguments that it recognizes. + + Qt debugging options (not available if Qt was compiled without the QT_DEBUG + flag defined): + \list + \o -nograb, tells Qt that it must never grab the mouse or the + keyboard. + \o -dograb (only under X11), running under a debugger can cause an + implicit -nograb, use -dograb to override. + \o -sync (only under X11), switches to synchronous mode for + debugging. + \endlist + + See \l{Debugging Techniques} for a more detailed explanation. + + All Qt programs automatically support the following command line options: + \list + \o -style= \e style, sets the application GUI style. Possible values + are \c motif, \c windows, and \c platinum. If you compiled Qt with + additional styles or have additional styles as plugins these will + be available to the \c -style command line option. + \o -style \e style, is the same as listed above. + \o -stylesheet= \e stylesheet, sets the application \l styleSheet. The + value must be a path to a file that contains the Style Sheet. + \note Relative URLs in the Style Sheet file are relative to the + Style Sheet file's path. + \o -stylesheet \e stylesheet, is the same as listed above. + \o -session= \e session, restores the application from an earlier + \l{Session Management}{session}. + \o -session \e session, is the same as listed above. + \o -widgetcount, prints debug message at the end about number of + widgets left undestroyed and maximum number of widgets existed at + the same time + \o -reverse, sets the application's layout direction to + Qt::RightToLeft + \o -graphicssystem, sets the backend to be used for on-screen widgets + and QPixmaps. Available options are \c{raster} and \c{opengl}. + \endlist + + The Windows version of Qt supports an additional command line option, if + Direct3D support has been compiled into Qt: + \list + \o -direct3d will make the Direct3D paint engine the default widget + paint engine in Qt. \bold {This functionality is experimental.} + \endlist + + The X11 version of Qt supports some traditional X11 command line options: + \list + \o -display \e display, sets the X display (default is $DISPLAY). + \o -geometry \e geometry, sets the client geometry of the first window + that is shown. + \o -fn or \c -font \e font, defines the application font. The font + should be specified using an X logical font description. + \o -bg or \c -background \e color, sets the default background color + and an application palette (light and dark shades are calculated). + \o -fg or \c -foreground \e color, sets the default foreground color. + \o -btn or \c -button \e color, sets the default button color. + \o -name \e name, sets the application name. + \o -title \e title, sets the application title. + \o -visual \c TrueColor, forces the application to use a TrueColor + visual on an 8-bit display. + \o -ncols \e count, limits the number of colors allocated in the color + cube on an 8-bit display, if the application is using the + QApplication::ManyColor color specification. If \e count is 216 + then a 6x6x6 color cube is used (i.e. 6 levels of red, 6 of green, + and 6 of blue); for other values, a cube approximately proportional + to a 2x3x1 cube is used. + \o -cmap, causes the application to install a private color map on an + 8-bit display. + \o -im, sets the input method server (equivalent to setting the + XMODIFIERS environment variable) + \o -inputstyle, defines how the input is inserted into the given + widget, e.g., \c onTheSpot makes the input appear directly in the + widget, while \c overTheSpot makes the input appear in a box + floating over the widget and is not inserted until the editing is + done. + \endlist + + \sa arguments() */ QApplication::QApplication(int &argc, char **argv) @@ -685,26 +672,26 @@ QApplication::QApplication(int &argc, char **argv, int _internal) /*! - Constructs an application object with \a argc command line arguments - in \a argv. If \a GUIenabled is true, a GUI application is - constructed, otherwise a non-GUI (console) application is created. + Constructs an application object with \a argc command line arguments in + \a argv. If \a GUIenabled is true, a GUI application is constructed, + otherwise a non-GUI (console) application is created. - \warning The data referred to by \a argc and \a argv must stay valid - for the entire lifetime of the QApplication object. In addition, - \a argc must be greater than zero and \a argv must contain at least - one valid character string. + \warning The data referred to by \a argc and \a argv must stay valid for + the entire lifetime of the QApplication object. In addition, \a argc must + be greater than zero and \a argv must contain at least one valid character + string. - Set \a GUIenabled to false for programs without a graphical user - interface that should be able to run without a window system. + Set \a GUIenabled to false for programs without a graphical user interface + that should be able to run without a window system. - On X11, the window system is initialized if \a GUIenabled is true. - If \a GUIenabled is false, the application does not connect to the - X server. On Windows and Macintosh, currently the window system is - always initialized, regardless of the value of GUIenabled. This may - change in future versions of Qt. + On X11, the window system is initialized if \a GUIenabled is true. If + \a GUIenabled is false, the application does not connect to the X server. + On Windows and Macintosh, currently the window system is always + initialized, regardless of the value of GUIenabled. This may change in + future versions of Qt. - The following example shows how to create an application that - uses a graphical interface when available. + The following example shows how to create an application that uses a + graphical interface when available. \snippet doc/src/snippets/code/src_gui_kernel_qapplication.cpp 0 */ @@ -720,17 +707,17 @@ QApplication::QApplication(int &argc, char **argv, bool GUIenabled , int _intern /*! - Constructs an application object with \a argc command line arguments - in \a argv. + Constructs an application object with \a argc command line arguments in + \a argv. - \warning The data referred to by \a argc and \a argv must stay valid - for the entire lifetime of the QApplication object. In addition, - \a argc must be greater than zero and \a argv must contain at least - one valid character string. + \warning The data referred to by \a argc and \a argv must stay valid for + the entire lifetime of the QApplication object. In addition, \a argc must + be greater than zero and \a argv must contain at least one valid character + string. - With Qt for Embedded Linux, passing QApplication::GuiServer for \a type - makes this application the server (equivalent to running with the - \c -qws option). + With Qt for Embedded Linux, passing QApplication::GuiServer for \a type + makes this application the server (equivalent to running with the + \c -qws option). */ QApplication::QApplication(int &argc, char **argv, Type type) : QCoreApplication(*new QApplicationPrivate(argc, argv, type)) @@ -778,16 +765,16 @@ static int aargc = 1; static char *aargv[] = { (char*)"unknown", 0 }; /*! - \fn QApplication::QApplication(Display* display, Qt::HANDLE visual, Qt::HANDLE colormap) + \fn QApplication::QApplication(Display* display, Qt::HANDLE visual, Qt::HANDLE colormap) - Create an application, given an already open display \a display. If \a - visual and \a colormap are non-zero, the application will use those as - the default Visual and Colormap contexts. + Creates an application, given an already open display \a display. If + \a visual and \a colormap are non-zero, the application will use those + values as the default Visual and Colormap contexts. - \warning Qt only supports TrueColor visuals at depths higher than 8 - bits-per-pixel. + \warning Qt only supports TrueColor visuals at depths higher than 8 + bits-per-pixel. - This is available only on X11. + This function is only available on X11. */ QApplication::QApplication(Display* dpy, Qt::HANDLE visual, Qt::HANDLE colormap) : QCoreApplication(*new QApplicationPrivate(aargc, aargv, GuiClient)) @@ -809,19 +796,18 @@ QApplication::QApplication(Display* dpy, Qt::HANDLE visual, Qt::HANDLE colormap, } /*! - \fn QApplication::QApplication(Display *display, int &argc, char **argv, - Qt::HANDLE visual, Qt::HANDLE colormap) - - Create an application, given an already open \a display and using \a - argc command line arguments in \a argv. If \a visual and \a colormap - are non-zero, the application will use those as the default Visual - and Colormap contexts. + \fn QApplication::QApplication(Display *display, int &argc, char **argv, + Qt::HANDLE visual, Qt::HANDLE colormap) - \warning Qt only supports TrueColor visuals at depths higher than 8 - bits-per-pixel. + Creates an application, given an already open \a display and using \a argc + command line arguments in \a argv. If \a visual and \a colormap are + non-zero, the application will use those values as the default Visual + and Colormap contexts. - This is available only on X11. + \warning Qt only supports TrueColor visuals at depths higher than 8 + bits-per-pixel. + This function is only available on X11. */ QApplication::QApplication(Display *dpy, int &argc, char **argv, Qt::HANDLE visual, Qt::HANDLE colormap) @@ -846,11 +832,13 @@ QApplication::QApplication(Display *dpy, int &argc, char **argv, #endif // Q_WS_X11 +extern void qInitDrawhelperAsm(); /*! + \fn void QApplicationPrivate::initialize() + Initializes the QApplication object, called from the constructors. */ - void QApplicationPrivate::initialize() { QWidgetPrivate::mapper = new QWidgetMapper; @@ -893,7 +881,6 @@ void QApplicationPrivate::initialize() #endif //Q_OS_WINCE // Set up which span functions should be used in raster engine... - extern void qInitDrawhelperAsm(); qInitDrawhelperAsm(); #if !defined(Q_WS_X11) && !defined(Q_WS_QWS) @@ -926,19 +913,18 @@ QApplication::Type QApplication::type() *****************************************************************************/ /*! - Returns the active popup widget. + Returns the active popup widget. - A popup widget is a special top-level widget that sets the \c - Qt::WType_Popup widget flag, e.g. the QMenu widget. When the - application opens a popup widget, all events are sent to the popup. - Normal widgets and modal widgets cannot be accessed before the popup - widget is closed. + A popup widget is a special top-level widget that sets the \c + Qt::WType_Popup widget flag, e.g. the QMenu widget. When the application + opens a popup widget, all events are sent to the popup. Normal widgets and + modal widgets cannot be accessed before the popup widget is closed. - Only other popup widgets may be opened when a popup widget is shown. - The popup widgets are organized in a stack. This function returns - the active popup widget at the top of the stack. + Only other popup widgets may be opened when a popup widget is shown. The + popup widgets are organized in a stack. This function returns the active + popup widget at the top of the stack. - \sa activeModalWidget(), topLevelWidgets() + \sa activeModalWidget(), topLevelWidgets() */ QWidget *QApplication::activePopupWidget() @@ -949,17 +935,17 @@ QWidget *QApplication::activePopupWidget() /*! - Returns the active modal widget. + Returns the active modal widget. - A modal widget is a special top-level widget which is a subclass of - QDialog that specifies the modal parameter of the constructor as - true. A modal widget must be closed before the user can continue - with other parts of the program. + A modal widget is a special top-level widget which is a subclass of QDialog + that specifies the modal parameter of the constructor as true. A modal + widget must be closed before the user can continue with other parts of the + program. - Modal widgets are organized in a stack. This function returns - the active modal widget at the top of the stack. + Modal widgets are organized in a stack. This function returns the active + modal widget at the top of the stack. - \sa activePopupWidget(), topLevelWidgets() + \sa activePopupWidget(), topLevelWidgets() */ QWidget *QApplication::activeModalWidget() @@ -968,8 +954,8 @@ QWidget *QApplication::activeModalWidget() } /*! - Cleans up any window system resources that were allocated by this - application. Sets the global variable \c qApp to 0. + Cleans up any window system resources that were allocated by this + application. Sets the global variable \c qApp to 0. */ QApplication::~QApplication() @@ -1098,8 +1084,8 @@ QApplication::~QApplication() /*! \fn QWidget *QApplication::widgetAt(const QPoint &point) - Returns the widget at global screen position \a point, or 0 if there - is no Qt widget there. + Returns the widget at global screen position \a point, or 0 if there is no + Qt widget there. This function can be slow. @@ -1147,8 +1133,8 @@ QWidget *QApplication::widgetAt(const QPoint &p) \overload - Returns the widget at global screen position (\a x, \a y), or 0 - if there is no Qt widget there. + Returns the widget at global screen position (\a x, \a y), or 0 if there is + no Qt widget there. */ /*! @@ -1217,16 +1203,17 @@ bool QApplication::compressEvent(QEvent *event, QObject *receiver, QPostEventLis \since 4.4 \brief defines a threshold for auto maximizing widgets - The auto maximize threshold is only available - as part of Qt for Windows CE. + The auto maximize threshold is only available as part of Qt for Windows CE. This property defines a threshold for the size of a window as a percentage - of the screen size. If the minimum size hint of a window exceeds the threshold, - calling show() will then cause the window to be maximized automatically. + of the screen size. If the minimum size hint of a window exceeds the + threshold, calling show() will then cause the window to be maximized + automatically. - Setting the threshold to be 100 or greater means that it will cause it to always - be maximized. Setting it to be 50 means that the widget is maximized if the vertical - minimum size hint is at least 50% of the vertical screen size. + Setting the threshold to be 100 or greater means that it will cause it to + always be maximized. Setting it to be 50 means that the widget is maximized + if the vertical minimum size hint is at least 50% of the vertical screen + size. If -1 is specified then this will disable the feature. @@ -1239,12 +1226,11 @@ bool QApplication::compressEvent(QEvent *event, QObject *receiver, QPostEventLis \since 4.5 \brief toggles automatic SIP (software input panel) visibility - The auto SIP property is only available - as part of Qt for Windows CE. + The auto SIP property is only available as part of Qt for Windows CE. Set this property to true to automatically display the SIP when entering - widgets that accept keyboard input. This only affects widgets that have the - attribute WA_InputMethodEnabled set. + widgets that accept keyboard input. This property only affects widgets with + the WA_InputMethodEnabled attribute set. */ #ifdef Q_OS_WINCE @@ -1296,9 +1282,9 @@ void QApplication::setStyleSheet(const QString& styleSheet) #endif // QT_NO_STYLE_STYLESHEET /*! - Returns the application's style object. + Returns the application's style object. - \sa setStyle(), QStyle + \sa setStyle(), QStyle */ QStyle *QApplication::style() { @@ -1381,22 +1367,21 @@ QStyle *QApplication::style() } /*! - Sets the application's GUI style to \a style. Ownership of the style - object is transferred to QApplication, so QApplication will delete - the style object on application exit or when a new style is set and - the old style is still the parent of the application object. + Sets the application's GUI style to \a style. Ownership of the style object + is transferred to QApplication, so QApplication will delete the style + object on application exit or when a new style is set and the old style is + still the parent of the application object. Example usage: \snippet doc/src/snippets/code/src_gui_kernel_qapplication.cpp 1 - When switching application styles, the color palette is set back to - the initial colors or the system defaults. This is necessary since - certain styles have to adapt the color palette to be fully - style-guide compliant. + When switching application styles, the color palette is set back to the + initial colors or the system defaults. This is necessary since certain + styles have to adapt the color palette to be fully style-guide compliant. - Note that setting the style before a palette has been set - (i.e. before creating QApplication) will cause the application to - use QStyle::standardPalette() for the palette. + Setting the style before a palette has been se, i.e., before creating + QApplication, will cause the application to use QStyle::standardPalette() + for the palette. \warning Qt style sheets are currently not supported for custom QStyle subclasses. We plan to address this in some future release. @@ -1499,20 +1484,20 @@ void QApplication::setStyle(QStyle *style) } /*! - \overload + \overload - Requests a QStyle object for \a style from the QStyleFactory. + Requests a QStyle object for \a style from the QStyleFactory. - The string must be one of the QStyleFactory::keys(), typically one - of "windows", "motif", "cde", "plastique", "windowsxp", or - "macintosh". Style names are case insensitive. + The string must be one of the QStyleFactory::keys(), typically one of + "windows", "motif", "cde", "plastique", "windowsxp", or "macintosh". Style + names are case insensitive. - Returns 0 if an unknown \a style is passed, otherwise the QStyle object - returned is set as the application's GUI style. + Returns 0 if an unknown \a style is passed, otherwise the QStyle object + returned is set as the application's GUI style. - \warning To ensure that the application's style is set correctly, it is - best to call this function before the QApplication constructor, if - possible. + \warning To ensure that the application's style is set correctly, it is + best to call this function before the QApplication constructor, if + possible. */ QStyle* QApplication::setStyle(const QString& style) { @@ -1525,20 +1510,19 @@ QStyle* QApplication::setStyle(const QString& style) } /*! - \since 4.5 + \since 4.5 - Sets the default graphics backend to \a system, which will be used - for on-screen widgets and QPixmaps. The available systems are - \c{"native"}, \c{"raster"} and \c{"opengl"}. + Sets the default graphics backend to \a system, which will be used for + on-screen widgets and QPixmaps. The available systems are \c{"native"}, + \c{"raster"} and \c{"opengl"}. - Note that this function call overrides both the application - commandline \c{-graphicssystem} switch and the configure - \c{-graphicssystem} switch. + This function call overrides both the application commandline + \c{-graphicssystem} switch and the configure \c{-graphicssystem} switch. - \warning This function must be called before the QApplication - constructor is called. + \warning This function must be called before the QApplication constructor + is called. - The \c{"opengl"} option is currently considered experimental. + \note The \c{"opengl"} option is currently experimental. */ void QApplication::setGraphicsSystem(const QString &system) @@ -1547,9 +1531,10 @@ void QApplication::setGraphicsSystem(const QString &system) } /*! - Returns the color specification. - \sa QApplication::setColorSpec() - */ + Returns the color specification. + + \sa QApplication::setColorSpec() +*/ int QApplication::colorSpec() { @@ -1557,54 +1542,54 @@ int QApplication::colorSpec() } /*! - Sets the color specification for the application to \a spec. - - The color specification controls how the application allocates colors - when run on a display with a limited amount of colors, e.g. 8 bit / 256 - color displays. - - The color specification must be set before you create the QApplication - object. - - The options are: - \list - \o QApplication::NormalColor. - This is the default color allocation strategy. Use this option if - your application uses buttons, menus, texts and pixmaps with few - colors. With this option, the application uses system global - colors. This works fine for most applications under X11, but on - Windows machines it may cause dithering of non-standard colors. - \o QApplication::CustomColor. - Use this option if your application needs a small number of custom - colors. On X11, this option is the same as NormalColor. On Windows, Qt - creates a Windows palette, and allocates colors to it on demand. - \o QApplication::ManyColor. - Use this option if your application is very color hungry - (e.g. it requires thousands of colors). - Under X11 the effect is: + Sets the color specification for the application to \a spec. + + The color specification controls how the application allocates colors when + run on a display with a limited amount of colors, e.g. 8 bit / 256 color + displays. + + The color specification must be set before you create the QApplication + object. + + The options are: \list - \o For 256-color displays which have at best a 256 color true - color visual, the default visual is used, and colors are - allocated from a color cube. The color cube is the 6x6x6 (216 - color) "Web palette" (the red, green, and blue components - always have one of the following values: 0x00, 0x33, 0x66, - 0x99, 0xCC, or 0xFF), but the number of colors can be changed - by the \e -ncols option. The user can force the application to - use the true color visual with the \link - QApplication::QApplication() -visual \endlink option. - \o For 256-color displays which have a true color visual with more - than 256 colors, use that visual. Silicon Graphics X servers - have this feature, for example. They provide an 8 bit visual - by default but can deliver true color when asked. + \o QApplication::NormalColor. This is the default color allocation + strategy. Use this option if your application uses buttons, menus, + texts and pixmaps with few colors. With this option, the + application uses system global colors. This works fine for most + applications under X11, but on Windows machines it may cause + dithering of non-standard colors. + \o QApplication::CustomColor. Use this option if your application + needs a small number of custom colors. On X11, this option is the + same as NormalColor. On Windows, Qt creates a Windows palette, and + allocates colors to it on demand. + \o QApplication::ManyColor. Use this option if your application is + very color hungry, e.g., it requires thousands of colors. \br + Under X11 the effect is: + \list + \o For 256-color displays which have at best a 256 color true + color visual, the default visual is used, and colors are + allocated from a color cube. The color cube is the 6x6x6 + (216 color) "Web palette" (the red, green, and blue + components always have one of the following values: 0x00, + 0x33, 0x66, 0x99, 0xCC, or 0xFF), but the number of colors + can be changed by the \e -ncols option. The user can force + the application to use the true color visual with the + \l{QApplication::QApplication()}{-visual} option. + \o For 256-color displays which have a true color visual with + more than 256 colors, use that visual. Silicon Graphics X + servers this feature, for example. They provide an 8 bit + visual by default but can deliver true color when asked. + \endlist + On Windows, Qt creates a Windows palette, and fills it with a color + cube. \endlist - On Windows, Qt creates a Windows palette, and fills it with a color cube. - \endlist - Be aware that the CustomColor and ManyColor choices may lead to colormap - flashing: The foreground application gets (most) of the available - colors, while the background windows will look less attractive. + Be aware that the CustomColor and ManyColor choices may lead to colormap + flashing: The foreground application gets (most) of the available colors, + while the background windows will look less attractive. - Example: + Example: \snippet doc/src/snippets/code/src_gui_kernel_qapplication.cpp 2 @@ -1624,10 +1609,9 @@ void QApplication::setColorSpec(int spec) \brief the minimum size that any GUI element that the user can interact with should have - For example, no button should be resized to be smaller than the - global strut size. The strut size should be considered when - reimplementing GUI controls that may be used on touch-screens or - similar I/O devices. + For example, no button should be resized to be smaller than the global + strut size. The strut size should be considered when reimplementing GUI + controls that may be used on touch-screens or similar I/O devices. Example: @@ -1661,12 +1645,11 @@ QPalette QApplication::palette() \fn QPalette QApplication::palette(const QWidget* widget) \overload - If a \a widget is passed, the default palette for the - widget's class is returned. This may or may not be the application - palette. In most cases there isn't a special palette for certain - types of widgets, but one notable exception is the popup menu - under Windows, if the user has defined a special background color - for menus in the display settings. + If a \a widget is passed, the default palette for the widget's class is + returned. This may or may not be the application palette. In most cases + there is no special palette for certain types of widgets, but one notable + exception is the popup menu under Windows, if the user has defined a + special background color for menus in the display settings. \sa setPalette(), QWidget::palette() */ @@ -1760,26 +1743,26 @@ void QApplicationPrivate::setPalette_helper(const QPalette &palette, const char* } /*! - Changes the default application palette to \a palette. + Changes the default application palette to \a palette. - If \a className is passed, the change applies only to widgets that - inherit \a className (as reported by QObject::inherits()). If - \a className is left 0, the change affects all widgets, thus overriding - any previously set class specific palettes. + If \a className is passed, the change applies only to widgets that inherit + \a className (as reported by QObject::inherits()). If \a className is left + 0, the change affects all widgets, thus overriding any previously set class + specific palettes. - The palette may be changed according to the current GUI style in - QStyle::polish(). + The palette may be changed according to the current GUI style in + QStyle::polish(). - \warning Do not use this function in conjunction with \l{Qt Style Sheets}. - When using style sheets, the palette of a widget can be customized using the "color", - "background-color", "selection-color", "selection-background-color" and - "alternate-background-color". + \warning Do not use this function in conjunction with \l{Qt Style Sheets}. + When using style sheets, the palette of a widget can be customized using + the "color", "background-color", "selection-color", + "selection-background-color" and "alternate-background-color". - Note that some styles do not use the palette for all drawing, - for instance, if they make use of native theme engines. This is - the case for the Windows XP, Windows Vista, and Mac OS X styles. + \note Some styles do not use the palette for all drawing, for instance, if + they make use of native theme engines. This is the case for the Windows XP, + Windows Vista, and Mac OS X styles. - \sa QWidget::setPalette(), palette(), QStyle::polish() + \sa QWidget::setPalette(), palette(), QStyle::polish() */ void QApplication::setPalette(const QPalette &palette, const char* className) @@ -1884,15 +1867,15 @@ QFont QApplication::font(const char *className) /*! - Changes the default application font to \a font. If \a className - is passed, the change applies only to classes that inherit \a - className (as reported by QObject::inherits()). + Changes the default application font to \a font. If \a className is passed, + the change applies only to classes that inherit \a className (as reported + by QObject::inherits()). - On application start-up, the default font depends on the window - system. It can vary depending on both the window system version and - the locale. This function lets you override the default font; but - overriding may be a bad idea because, for example, some locales need - extra large fonts to support their special characters. + On application start-up, the default font depends on the window system. It + can vary depending on both the window system version and the locale. This + function lets you override the default font; but overriding may be a bad + idea because, for example, some locales need extra large fonts to support + their special characters. \warning Do not use this function in conjunction with \l{Qt Style Sheets}. The font of an application can be customized using the "font" style sheet @@ -1994,11 +1977,10 @@ void QApplication::setWindowIcon(const QIcon &icon) } /*! - Returns a list of the top-level widgets (windows) in the - application. + Returns a list of the top-level widgets (windows) in the application. - Note that some of the top-level widgets may be hidden, for - example a tooltip if no tooltip is currently shown. + \note Some of the top-level widgets may be hidden, for example a tooltip if + no tooltip is currently shown. Example: @@ -2024,7 +2006,7 @@ QWidgetList QApplication::topLevelWidgets() The list is empty (QList::isEmpty()) if there are no widgets. - Note that some of the widgets may be hidden. + \note Some of the widgets may be hidden. Example: \snippet doc/src/snippets/code/src_gui_kernel_qapplication.cpp 5 @@ -2043,10 +2025,10 @@ QWidgetList QApplication::allWidgets() } /*! - Returns the application widget that has the keyboard input focus, or - 0 if no widget in this application has the focus. + Returns the application widget that has the keyboard input focus, or 0 if + no widget in this application has the focus. - \sa QWidget::setFocus(), QWidget::hasFocus(), activeWindow(), focusChanged() + \sa QWidget::setFocus(), QWidget::hasFocus(), activeWindow(), focusChanged() */ QWidget *QApplication::focusWidget() @@ -2080,9 +2062,13 @@ void QApplicationPrivate::setFocusWidget(QWidget *focus, Qt::FocusReason reason) QWidget *prev = focus_widget; focus_widget = focus; - if (prev && reason != Qt::PopupFocusReason && reason != Qt::MenuBarFocusReason && - prev->testAttribute(Qt::WA_InputMethodEnabled)) { - QInputContext *qic = prev->inputContext(); + if (prev && ((reason != Qt::PopupFocusReason && reason != Qt::MenuBarFocusReason + && prev->testAttribute(Qt::WA_InputMethodEnabled)) + // Do reset the input context, in case the new focus widget won't accept keyboard input + // or it is not created fully yet. + || (focus_widget && (!focus_widget->testAttribute(Qt::WA_InputMethodEnabled) + || !focus_widget->testAttribute(Qt::WA_WState_Created))))) { + QInputContext *qic = prev->inputContext(); if(qic) { qic->reset(); qic->setFocusWidget(0); @@ -2120,19 +2106,19 @@ void QApplicationPrivate::setFocusWidget(QWidget *focus, Qt::FocusReason reason) if (that) QApplication::sendEvent(that->style(), &in); } + emit qApp->focusChanged(prev, focus_widget); } - emit qApp->focusChanged(prev, focus_widget); } } /*! - Returns the application top-level window that has the keyboard input - focus, or 0 if no application window has the focus. Note that - there might be an activeWindow() even if there is no focusWidget(), - for example if no widget in that window accepts key events. + Returns the application top-level window that has the keyboard input focus, + or 0 if no application window has the focus. There might be an + activeWindow() even if there is no focusWidget(), for example if no widget + in that window accepts key events. - \sa QWidget::setFocus(), QWidget::hasFocus(), focusWidget() + \sa QWidget::setFocus(), QWidget::hasFocus(), focusWidget() */ QWidget *QApplication::activeWindow() @@ -2141,9 +2127,9 @@ QWidget *QApplication::activeWindow() } /*! - Returns display (screen) font metrics for the application font. + Returns display (screen) font metrics for the application font. - \sa font(), setFont(), QWidget::fontMetrics(), QPainter::fontMetrics() + \sa font(), setFont(), QWidget::fontMetrics(), QPainter::fontMetrics() */ QFontMetrics QApplication::fontMetrics() @@ -2155,19 +2141,20 @@ QFontMetrics QApplication::fontMetrics() /*! Closes all top-level windows. - This function is particularly useful for applications with many - top-level windows. It could, for example, be connected to a - \gui{Exit} entry in the \gui{File} menu: + This function is particularly useful for applications with many top-level + windows. It could, for example, be connected to a \gui{Exit} entry in the + \gui{File} menu: \snippet examples/mainwindows/mdi/mainwindow.cpp 0 - The windows are closed in random order, until one window does not - accept the close event. The application quits when the last window - was successfully closed; this can be turned off by setting \l - quitOnLastWindowClosed to false. + The windows are closed in random order, until one window does not accept + the close event. The application quits when the last window was + successfully closed; this can be turned off by setting + \l quitOnLastWindowClosed to false. - \sa quitOnLastWindowClosed, lastWindowClosed() QWidget::close(), QWidget::closeEvent(), lastWindowClosed(), - quit(), topLevelWidgets(), QWidget::isWindow() + \sa quitOnLastWindowClosed, lastWindowClosed(), QWidget::close(), + QWidget::closeEvent(), lastWindowClosed(), quit(), topLevelWidgets(), + QWidget::isWindow() */ void QApplication::closeAllWindows() { @@ -2190,11 +2177,11 @@ void QApplication::closeAllWindows() } /*! - Displays a simple message box about Qt. The message includes the - version number of Qt being used by the application. + Displays a simple message box about Qt. The message includes the version + number of Qt being used by the application. - This is useful for inclusion in the \gui Help menu of an application, - as shown in the \l{mainwindows/menus}{Menus} example. + This is useful for inclusion in the \gui Help menu of an application, as + shown in the \l{mainwindows/menus}{Menus} example. This function is a convenience slot for QMessageBox::aboutQt(). */ @@ -2215,22 +2202,20 @@ void QApplication::aboutQt() /*! \fn void QApplication::lastWindowClosed() - This signal is emitted from QApplication::exec() when the last - visible primary window (i.e. window with no parent) with the - Qt::WA_QuitOnClose attribute set is closed. + This signal is emitted from QApplication::exec() when the last visible + primary window (i.e. window with no parent) with the Qt::WA_QuitOnClose + attribute set is closed. By default, \list + \o this attribute is set for all widgets except transient windows such + as splash screens, tool windows, and popup menus - \i this attribute is set for all widgets except transient windows - such as splash screens, tool windows, and popup menus - - \i QApplication implicitly quits when this signal is emitted. - + \o QApplication implicitly quits when this signal is emitted. \endlist - This feature be turned off by setting \l quitOnLastWindowClosed to + This feature can be turned off by setting \l quitOnLastWindowClosed to false. \sa QWidget::close() @@ -2240,15 +2225,15 @@ void QApplication::aboutQt() \since 4.1 \fn void QApplication::focusChanged(QWidget *old, QWidget *now) - This signal is emitted when the widget that has keyboard focus - changed from \a old to \a now, i.e. because the user pressed the - tab-key, clicked into a widget or changed the active window. Note - that both \a old and \a now can be the null-pointer. + This signal is emitted when the widget that has keyboard focus changed from + \a old to \a now, i.e., because the user pressed the tab-key, clicked into + a widget or changed the active window. Both \a old and \a now can be the + null-pointer. - The signal is emitted after both widget have been notified about - the change through QFocusEvent. + The signal is emitted after both widget have been notified about the change + through QFocusEvent. - \sa QWidget::setFocus() QWidget::clearFocus() Qt::FocusReason + \sa QWidget::setFocus(), QWidget::clearFocus(), Qt::FocusReason */ /*! @@ -2257,10 +2242,10 @@ void QApplication::aboutQt() This signal is emitted when application fonts are loaded or removed. - \sa QFontDatabase::addApplicationFont() - \sa QFontDatabase::addApplicationFontFromData() - \sa QFontDatabase::removeAllApplicationFonts() - \sa QFontDatabase::removeApplicationFont() + \sa QFontDatabase::addApplicationFont(), + QFontDatabase::addApplicationFontFromData(), + QFontDatabase::removeAllApplicationFonts(), + QFontDatabase::removeApplicationFont() */ #ifndef QT_NO_TRANSLATION @@ -2357,18 +2342,17 @@ void QApplication::syncX() {} // do nothing \fn void QApplication::setActiveWindow(QWidget* active) Sets the active window to the \a active widget in response to a system - event. The function is called from the platform specific event - handlers. + event. The function is called from the platform specific event handlers. - \warning This function does \e not set the keyboard focus to the - active widget. Call QWidget::activateWindow() instead. + \warning This function does \e not set the keyboard focus to the active + widget. Call QWidget::activateWindow() instead. - It sets the activeWindow() and focusWidget() attributes and sends - proper \l{QEvent::WindowActivate}{WindowActivate}/\l{QEvent::WindowDeactivate}{WindowDeactivate} - and \l{QEvent::FocusIn}{FocusIn}/\l{QEvent::FocusOut}{FocusOut} events - to all appropriate widgets. The window will then be painted in - active state (e.g. cursors in line edits will blink), and it will - have tool tips enabled. + It sets the activeWindow() and focusWidget() attributes and sends proper + \l{QEvent::WindowActivate}{WindowActivate}/\l{QEvent::WindowDeactivate} + {WindowDeactivate} and \l{QEvent::FocusIn}{FocusIn}/\l{QEvent::FocusOut} + {FocusOut} events to all appropriate widgets. The window will then be + painted in active state (e.g. cursors in line edits will blink), and it + will have tool tips enabled. \sa activeWindow(), QWidget::activateWindow() */ @@ -2467,7 +2451,9 @@ void QApplication::setActiveWindow(QWidget* act) } else { // If the focus widget is not in the activate_window, clear the focus w = QApplicationPrivate::focus_widget; - if (w && !QApplicationPrivate::active_window->isAncestorOf(w)) + if (!w && QApplicationPrivate::active_window->focusPolicy() != Qt::NoFocus) + QApplicationPrivate::setFocusWidget(QApplicationPrivate::active_window, Qt::ActiveWindowFocusReason); + else if (!QApplicationPrivate::active_window->isAncestorOf(w)) QApplicationPrivate::setFocusWidget(0, Qt::ActiveWindowFocusReason); } } @@ -2512,11 +2498,11 @@ QWidget *QApplicationPrivate::focusNextPrevChild_helper(QWidget *toplevel, bool } /*! - \fn void QApplicationPrivate::dispatchEnterLeave(QWidget* enter, QWidget* leave) - \internal + \fn void QApplicationPrivate::dispatchEnterLeave(QWidget* enter, QWidget* leave) + \internal - Creates the proper Enter/Leave event when widget \a enter is entered - and widget \a leave is left. + Creates the proper Enter/Leave event when widget \a enter is entered and + widget \a leave is left. */ #if defined(Q_WS_WIN) extern void qt_win_set_cursor(QWidget *, bool); @@ -3033,11 +3019,11 @@ void QApplicationPrivate::sendSyntheticEnterLeave(QWidget *widget) /*! Returns the desktop widget (also called the root window). - Note that the desktop may be composed of multiple screens, so it would be - incorrect, for example, to attempt to \e center some widget in the - desktop's geometry. QDesktopWidget has various functions for obtaining - useful geometries upon the desktop, such as QDesktopWidget::screenGeometry() - and QDesktopWidget::availableGeometry(). + The desktop may be composed of multiple screens, so it would be incorrect, + for example, to attempt to \e center some widget in the desktop's geometry. + QDesktopWidget has various functions for obtaining useful geometries upon + the desktop, such as QDesktopWidget::screenGeometry() and + QDesktopWidget::availableGeometry(). On X11, it is also possible to draw on the desktop. */ @@ -3052,10 +3038,10 @@ QDesktopWidget *QApplication::desktop() #ifndef QT_NO_CLIPBOARD /*! - Returns a pointer to the application global clipboard. + Returns a pointer to the application global clipboard. - \note The QApplication object should already be constructed before - accessing the clipboard. + \note The QApplication object should already be constructed before + accessing the clipboard. */ QClipboard *QApplication::clipboard() { @@ -3071,11 +3057,11 @@ QClipboard *QApplication::clipboard() #endif // QT_NO_CLIPBOARD /*! - Sets whether Qt should use the system's standard colors, fonts, - etc., to \a on. By default, this is true. + Sets whether Qt should use the system's standard colors, fonts, etc., to + \a on. By default, this is true. - This function must be called before creating the QApplication - object, like this: + This function must be called before creating the QApplication object, like + this: \snippet doc/src/snippets/code/src_gui_kernel_qapplication.cpp 6 @@ -3087,8 +3073,8 @@ void QApplication::setDesktopSettingsAware(bool on) } /*! - Returns true if Qt is set to use the system's standard colors, - fonts, etc.; otherwise returns false. The default is true. + Returns true if Qt is set to use the system's standard colors, fonts, etc.; + otherwise returns false. The default is true. \sa setDesktopSettingsAware() */ @@ -3098,17 +3084,17 @@ bool QApplication::desktopSettingsAware() } /*! - Returns the current state of the modifier keys on the keyboard. The - current state is updated sychronously as the event queue is emptied - of events that will spontaneously change the keyboard state - (QEvent::KeyPress and QEvent::KeyRelease events). + Returns the current state of the modifier keys on the keyboard. The current + state is updated sychronously as the event queue is emptied of events that + will spontaneously change the keyboard state (QEvent::KeyPress and + QEvent::KeyRelease events). - It should be noted this may not reflect the actual keys held on the - input device at the time of calling but rather the modifiers as - last reported in one of the above events. If no keys are being held - Qt::NoModifier is returned. + It should be noted this may not reflect the actual keys held on the input + device at the time of calling but rather the modifiers as last reported in + one of the above events. If no keys are being held Qt::NoModifier is + returned. - \sa mouseButtons() + \sa mouseButtons() */ Qt::KeyboardModifiers QApplication::keyboardModifiers() @@ -3117,17 +3103,17 @@ Qt::KeyboardModifiers QApplication::keyboardModifiers() } /*! - Returns the current state of the buttons on the mouse. The current - state is updated syncronously as the event queue is emptied of - events that will spontaneously change the mouse state - (QEvent::MousePress and QEvent::MouseRelease events). + Returns the current state of the buttons on the mouse. The current state is + updated syncronously as the event queue is emptied of events that will + spontaneously change the mouse state (QEvent::MouseButtonPress and + QEvent::MouseButtonRelease events). - It should be noted this may not reflect the actual buttons held on - theinput device at the time of calling but rather the mouse buttons - as last reported in one of the above events. If no mouse buttons are - being held Qt::NoButton is returned. + It should be noted this may not reflect the actual buttons held on the + input device at the time of calling but rather the mouse buttons as last + reported in one of the above events. If no mouse buttons are being held + Qt::NoButton is returned. - \sa keyboardModifiers() + \sa keyboardModifiers() */ Qt::MouseButtons QApplication::mouseButtons() @@ -3136,43 +3122,40 @@ Qt::MouseButtons QApplication::mouseButtons() } /*! - \fn bool QApplication::isSessionRestored() const + \fn bool QApplication::isSessionRestored() const - Returns true if the application has been restored from an earlier - \link session.html session\endlink; otherwise returns false. + Returns true if the application has been restored from an earlier + \l{Session Management}{session}; otherwise returns false. - \sa sessionId(), commitData(), saveState() + \sa sessionId(), commitData(), saveState() */ /*! - \fn QString QApplication::sessionId() const + \fn QString QApplication::sessionId() const - Returns the current \link session.html session's\endlink identifier. + Returns the current \l{Session Management}{session's} identifier. - If the application has been restored from an earlier session, this - identifier is the same as it was in that previous session. + If the application has been restored from an earlier session, this + identifier is the same as it was in that previous session. The session + identifier is guaranteed to be unique both for different applications + and for different instances of the same application. - The session identifier is guaranteed to be unique both for different - applications and for different instances of the same application. - - \sa isSessionRestored(), sessionKey(), commitData(), saveState() - */ + \sa isSessionRestored(), sessionKey(), commitData(), saveState() +*/ /*! - \fn QString QApplication::sessionKey() const + \fn QString QApplication::sessionKey() const - Returns the session key in the current \link session.html - session\endlink. + Returns the session key in the current \l{Session Management}{session}. - If the application has been restored from an earlier session, this - key is the same as it was when the previous session ended. + If the application has been restored from an earlier session, this key is + the same as it was when the previous session ended. - The session key changes with every call of commitData() or - saveState(). + The session key changes with every call of commitData() or saveState(). - \sa isSessionRestored(), sessionId(), commitData(), saveState() - */ + \sa isSessionRestored(), sessionId(), commitData(), saveState() +*/ #ifndef QT_NO_SESSIONMANAGER bool QApplication::isSessionRestored() const { @@ -3195,59 +3178,57 @@ QString QApplication::sessionKey() const - - /*! - \since 4.2 - \fn void QApplication::commitDataRequest(QSessionManager &manager) + \since 4.2 + \fn void QApplication::commitDataRequest(QSessionManager &manager) - This signal deals with \link session.html session - management\endlink. It is emitted when the QSessionManager wants the - application to commit all its data. + This signal deals with \l{Session Management}{session management}. It is + emitted when the QSessionManager wants the application to commit all its + data. - Usually this means saving all open files, after getting - permission from the user. Furthermore you may want to provide a means - by which the user can cancel the shutdown. + Usually this means saving all open files, after getting permission from + the user. Furthermore you may want to provide a means by which the user + can cancel the shutdown. - Note that you should not exit the application when called. - Instead, the session manager may or may not do this afterwards, - depending on the context. + You should not exit the application within this signal. Instead, + the session manager may or may not do this afterwards, depending on the + context. - \warning Within this signal, no user interaction is possible, \e - unless you ask the \a manager for explicit permission. See - QSessionManager::allowsInteraction() and - QSessionManager::allowsErrorInteraction() for details and example - usage. + \warning Within this signal, no user interaction is possible, \e + unless you ask the \a manager for explicit permission. See + QSessionManager::allowsInteraction() and + QSessionManager::allowsErrorInteraction() for details and example + usage. - Note: You should use Qt::DirectConnection when connecting to this signal. + \note You should use Qt::DirectConnection when connecting to this signal. - \sa isSessionRestored(), sessionId(), saveState(), {Session Management} + \sa isSessionRestored(), sessionId(), saveState(), {Session Management} */ /*! - This function deals with \link session.html session - management\endlink. It is invoked when the QSessionManager wants the - application to commit all its data. + This function deals with \l{Session Management}{session management}. It is + invoked when the QSessionManager wants the application to commit all its + data. - Usually this means saving all open files, after getting - permission from the user. Furthermore you may want to provide a means - by which the user can cancel the shutdown. + Usually this means saving all open files, after getting permission from the + user. Furthermore you may want to provide a means by which the user can + cancel the shutdown. - Note that you should not exit the application within this function. - Instead, the session manager may or may not do this afterwards, - depending on the context. + You should not exit the application within this function. Instead, the + session manager may or may not do this afterwards, depending on the + context. - \warning Within this function, no user interaction is possible, \e - unless you ask the \a manager for explicit permission. See - QSessionManager::allowsInteraction() and - QSessionManager::allowsErrorInteraction() for details and example - usage. + \warning Within this function, no user interaction is possible, \e + unless you ask the \a manager for explicit permission. See + QSessionManager::allowsInteraction() and + QSessionManager::allowsErrorInteraction() for details and example + usage. - The default implementation requests interaction and sends a close - event to all visible top-level widgets. If any event was - rejected, the shutdown is canceled. + The default implementation requests interaction and sends a close event to + all visible top-level widgets. If any event was rejected, the shutdown is + canceled. - \sa isSessionRestored(), sessionId(), saveState(), {Session Management} + \sa isSessionRestored(), sessionId(), saveState(), {Session Management} */ #ifndef QT_NO_SESSIONMANAGER void QApplication::commitData(QSessionManager& manager ) @@ -3273,58 +3254,54 @@ void QApplication::commitData(QSessionManager& manager ) } /*! - \since 4.2 - \fn void QApplication::saveStateRequest(QSessionManager &manager) + \since 4.2 + \fn void QApplication::saveStateRequest(QSessionManager &manager) - This signal deals with \link session.html session - management\endlink. It is invoked when the - \link QSessionManager session manager \endlink wants the application - to preserve its state for a future session. + This signal deals with \l{Session Management}{session management}. It is + invoked when the \l{QSessionManager}{session manager} wants the application + to preserve its state for a future session. - For example, a text editor would create a temporary file that - includes the current contents of its edit buffers, the location of - the cursor and other aspects of the current editing session. + For example, a text editor would create a temporary file that includes the + current contents of its edit buffers, the location of the cursor and other + aspects of the current editing session. - Note that you should never exit the application within this - signal. Instead, the session manager may or may not do this - afterwards, depending on the context. Futhermore, most session - managers will very likely request a saved state immediately after - the application has been started. This permits the session manager - to learn about the application's restart policy. + You should never exit the application within this signal. Instead, the + session manager may or may not do this afterwards, depending on the + context. Futhermore, most session managers will very likely request a saved + state immediately after the application has been started. This permits the + session manager to learn about the application's restart policy. - \warning Within this function, no user interaction is possible, \e - unless you ask the \a manager for explicit permission. See - QSessionManager::allowsInteraction() and - QSessionManager::allowsErrorInteraction() for details. + \warning Within this function, no user interaction is possible, \e + unless you ask the \a manager for explicit permission. See + QSessionManager::allowsInteraction() and + QSessionManager::allowsErrorInteraction() for details. - Note:: You should use Qt::DirectConnection when connecting to this signal. + \note You should use Qt::DirectConnection when connecting to this signal. - \sa isSessionRestored(), sessionId(), commitData(), {Session Management} + \sa isSessionRestored(), sessionId(), commitData(), {Session Management} */ /*! - This function deals with \link session.html session - management\endlink. It is invoked when the - \link QSessionManager session manager \endlink wants the application - to preserve its state for a future session. + This function deals with \l{Session Management}{session management}. It is + invoked when the \l{QSessionManager}{session manager} wants the application + to preserve its state for a future session. - For example, a text editor would create a temporary file that - includes the current contents of its edit buffers, the location of - the cursor and other aspects of the current editing session. + For example, a text editor would create a temporary file that includes the + current contents of its edit buffers, the location of the cursor and other + aspects of the current editing session. - Note that you should never exit the application within this - function. Instead, the session manager may or may not do this - afterwards, depending on the context. Futhermore, most session - managers will very likely request a saved state immediately after - the application has been started. This permits the session manager - to learn about the application's restart policy. + You should never exit the application within this function. Instead, the + session manager may or may not do this afterwards, depending on the + context. Futhermore, most session managers will very likely request a saved + state immediately after the application has been started. This permits the + session manager to learn about the application's restart policy. - \warning Within this function, no user interaction is possible, \e - unless you ask the \a manager for explicit permission. See - QSessionManager::allowsInteraction() and - QSessionManager::allowsErrorInteraction() for details. + \warning Within this function, no user interaction is possible, \e + unless you ask the \a manager for explicit permission. See + QSessionManager::allowsInteraction() and + QSessionManager::allowsErrorInteraction() for details. - \sa isSessionRestored(), sessionId(), commitData(), {Session Management} + \sa isSessionRestored(), sessionId(), commitData(), {Session Management} */ void QApplication::saveState(QSessionManager &manager) @@ -3348,13 +3325,12 @@ void QApplication::setStartDragTime(int ms) \brief the time in milliseconds that a mouse button must be held down before a drag and drop operation will begin - If you support drag and drop in your application, and want to start a - drag and drop operation after the user has held down a mouse button for - a certain amount of time, you should use this property's value as the - delay. + If you support drag and drop in your application, and want to start a drag + and drop operation after the user has held down a mouse button for a + certain amount of time, you should use this property's value as the delay. - Qt also uses this delay internally, e.g. in QTextEdit and QLineEdit, - for starting a drag. + Qt also uses this delay internally, e.g. in QTextEdit and QLineEdit, for + starting a drag. The default value is 500 ms. @@ -3367,9 +3343,9 @@ int QApplication::startDragTime() } /* - Sets the distance after which a drag should start to \a l pixels. + Sets the distance after which a drag should start to \a l pixels. - \sa startDragDistance() + \sa startDragDistance() */ void QApplication::setStartDragDistance(int l) @@ -3380,15 +3356,14 @@ void QApplication::setStartDragDistance(int l) /*! \property QApplication::startDragDistance - If you support drag and drop in your application, and want to start a - drag and drop operation after the user has moved the cursor a certain - distance with a button held down, you should use this property's value - as the minimum distance required. + If you support drag and drop in your application, and want to start a drag + and drop operation after the user has moved the cursor a certain distance + with a button held down, you should use this property's value as the + minimum distance required. - For example, if the mouse position of the click is stored in \c - startPos and the current position (e.g. in the mouse move event) is - \c currentPos, you can find out if a drag should be started with code - like this: + For example, if the mouse position of the click is stored in \c startPos + and the current position (e.g. in the mouse move event) is \c currentPos, + you can find out if a drag should be started with code like this: \snippet doc/src/snippets/code/src_gui_kernel_qapplication.cpp 7 @@ -3434,14 +3409,14 @@ int QApplication::startDragDistance() \sa layoutDirection(), isRightToLeft() */ -/*! \property QApplication::layoutDirection - - \brief the default layout direction for this application +/*! + \property QApplication::layoutDirection + \brief the default layout direction for this application - On system start-up, the default layout direction depends on the - application's language. + On system start-up, the default layout direction depends on the + application's language. - \sa QWidget::layoutDirection, isLeftToRight(), isRightToLeft() + \sa QWidget::layoutDirection, isLeftToRight(), isRightToLeft() */ void QApplication::setLayoutDirection(Qt::LayoutDirection direction) @@ -3465,11 +3440,12 @@ Qt::LayoutDirection QApplication::layoutDirection() } -/*! \obsolete +/*! + \obsolete - Strips out vertical alignment flags and transforms an - alignment \a align of Qt::AlignLeft into Qt::AlignLeft or - Qt::AlignRight according to the language used. + Strips out vertical alignment flags and transforms an alignment \a align + of Qt::AlignLeft into Qt::AlignLeft or Qt::AlignRight according to the + language used. */ #ifdef QT3_SUPPORT @@ -3485,8 +3461,8 @@ Qt::Alignment QApplication::horizontalAlignment(Qt::Alignment align) Returns the active application override cursor. - This function returns 0 if no application cursor has been defined - (i.e. the internal cursor stack is empty). + This function returns 0 if no application cursor has been defined (i.e. the + internal cursor stack is empty). \sa setOverrideCursor(), restoreOverrideCursor() */ @@ -3499,9 +3475,10 @@ QCursor *QApplication::overrideCursor() /*! Changes the currently active application override cursor to \a cursor. - This function has no effect if setOverrideCursor() wasn't called. + This function has no effect if setOverrideCursor() was not called. - \sa setOverrideCursor() overrideCursor() restoreOverrideCursor() QWidget::setCursor() + \sa setOverrideCursor(), overrideCursor(), restoreOverrideCursor(), + QWidget::setCursor() */ void QApplication::changeOverrideCursor(const QCursor &cursor) { @@ -3515,8 +3492,8 @@ void QApplication::changeOverrideCursor(const QCursor &cursor) /*! \fn void QApplication::setOverrideCursor(const QCursor &cursor, bool replace) - Use changeOverrideCursor(\a cursor) (if \a replace is true) - or setOverrideCursor(\a cursor) (if \a replace is false). + Use changeOverrideCursor(\a cursor) (if \a replace is true) or + setOverrideCursor(\a cursor) (if \a replace is false). */ /*! @@ -3524,29 +3501,26 @@ void QApplication::changeOverrideCursor(const QCursor &cursor) the value that was set to exit() (which is 0 if exit() is called via quit()). - It is necessary to call this function to start event handling. The - main event loop receives events from the window system and - dispatches these to the application widgets. + It is necessary to call this function to start event handling. The main + event loop receives events from the window system and dispatches these to + the application widgets. + + Generally, no user interaction can take place before calling exec(). As a + special case, modal widgets like QMessageBox can be used before calling + exec(), because modal widgets call exec() to start a local event loop. - Generally speaking, no user interaction can take place before - calling exec(). As a special case, modal widgets like QMessageBox - can be used before calling exec(), because modal widgets call - exec() to start a local event loop. - - To make your application perform idle processing, i.e. executing a - special function whenever there are no pending events, use a - QTimer with 0 timeout. More advanced idle processing schemes can - be achieved using processEvents(). + To make your application perform idle processing, i.e., executing a special + function whenever there are no pending events, use a QTimer with 0 timeout. + More advanced idle processing schemes can be achieved using processEvents(). We recommend that you connect clean-up code to the - \l{QCoreApplication::}{aboutToQuit()} signal, instead of putting it in - your application's \c{main()} function because on some platforms the - QApplication::exec() call may not return. For example, on Windows - when the user logs off, the system terminates the process after Qt - closes all top-level windows. Hence, there is no guarantee that the - application will have time to exit its event loop and execute code at - the end of the \c{main()} function after the QApplication::exec() - call. + \l{QCoreApplication::}{aboutToQuit()} signal, instead of putting it in your + application's \c{main()} function because on some platforms the + QApplication::exec() call may not return. For example, on Windows when the + user logs off, the system terminates the process after Qt closes all + top-level windows. Hence, there is no guarantee that the application will + have time to exit its event loop and execute code at the end of the + \c{main()} function after the QApplication::exec() call. \sa quitOnLastWindowClosed, quit(), exit(), processEvents(), QCoreApplication::exec() @@ -4094,101 +4068,98 @@ bool QApplicationPrivate::notify_helper(QObject *receiver, QEvent * e) /*! - \class QSessionManager - \brief The QSessionManager class provides access to the session manager. - - \ingroup application - \ingroup environment - - A session manager in a desktop environment (in which Qt GUI - applications live) keeps track of a session, which is a group of - running applications, each of which has a particular state. The - state of an application contains (most notably) the documents the - application has open and the position and size of its windows. - - The session manager is used to save the session, e.g. when the - machine is shut down, and to restore a session, e.g. when the - machine is started up. We recommend that you use QSettings to save - an individual application's settings, e.g. window positions, - recently used files, etc. When the application is restarted by the - session manager, you can restore the settings. - - QSessionManager provides an interface between the application - and the session manager so that the program can work well with the - session manager. In Qt, session management requests for action are - handled by the two virtual functions QApplication::commitData() - and QApplication::saveState(). Both provide a reference to a - session manager object as argument, to allow the application to - communicate with the session manager. The session manager can only - be accessed through these functions. - - No user interaction is possible \e unless the application gets - explicit permission from the session manager. You ask for permission - by calling allowsInteraction() or, if it's really urgent, - allowsErrorInteraction(). Qt does not enforce this, but the session - manager may. - - You can try to abort the shutdown process by calling cancel(). The - default commitData() function does this if some top-level window - rejected its closeEvent(). - - For sophisticated session managers provided on Unix/X11, QSessionManager - offers further possibilities to fine-tune an application's session - management behavior: setRestartCommand(), setDiscardCommand(), - setRestartHint(), setProperty(), requestPhase2(). See the respective - function descriptions for further details. - - \sa QApplication, {Session Management} + \class QSessionManager + \brief The QSessionManager class provides access to the session manager. + + \ingroup application + \ingroup environment + + A session manager in a desktop environment (in which Qt GUI applications + live) keeps track of a session, which is a group of running applications, + each of which has a particular state. The state of an application contains + (most notably) the documents the application has open and the position and + size of its windows. + + The session manager is used to save the session, e.g., when the machine is + shut down, and to restore a session, e.g., when the machine is started up. + We recommend that you use QSettings to save an application's settings, + for example, window positions, recently used files, etc. When the + application is restarted by the session manager, you can restore the + settings. + + QSessionManager provides an interface between the application and the + session manager so that the program can work well with the session manager. + In Qt, session management requests for action are handled by the two + virtual functions QApplication::commitData() and QApplication::saveState(). + Both provide a reference to a session manager object as argument, to allow + the application to communicate with the session manager. The session + manager can only be accessed through these functions. + + No user interaction is possible \e unless the application gets explicit + permission from the session manager. You ask for permission by calling + allowsInteraction() or, if it is really urgent, allowsErrorInteraction(). + Qt does not enforce this, but the session manager may. + + You can try to abort the shutdown process by calling cancel(). The default + commitData() function does this if some top-level window rejected its + closeEvent(). + + For sophisticated session managers provided on Unix/X11, QSessionManager + offers further possibilities to fine-tune an application's session + management behavior: setRestartCommand(), setDiscardCommand(), + setRestartHint(), setProperty(), requestPhase2(). See the respective + function descriptions for further details. + + \sa QApplication, {Session Management} */ /*! \enum QSessionManager::RestartHint - This enum type defines the circumstances under which this - application wants to be restarted by the session manager. The - current values are + This enum type defines the circumstances under which this application wants + to be restarted by the session manager. The current values are: - \value RestartIfRunning if the application is still running when - the session is shut down, it wants to be restarted at the start of - the next session. + \value RestartIfRunning If the application is still running when the + session is shut down, it wants to be restarted + at the start of the next session. - \value RestartAnyway the application wants to be started at the - start of the next session, no matter what. (This is useful for - utilities that run just after startup and then quit.) + \value RestartAnyway The application wants to be started at the + start of the next session, no matter what. + (This is useful for utilities that run just + after startup and then quit.) - \value RestartImmediately the application wants to be started - immediately whenever it is not running. + \value RestartImmediately The application wants to be started immediately + whenever it is not running. - \value RestartNever the application does not want to be restarted - automatically. + \value RestartNever The application does not want to be restarted + automatically. - The default hint is \c RestartIfRunning. + The default hint is \c RestartIfRunning. */ /*! - \fn QString QSessionManager::sessionId() const + \fn QString QSessionManager::sessionId() const - Returns the identifier of the current session. + Returns the identifier of the current session. - If the application has been restored from an earlier session, this - identifier is the same as it was in that earlier session. + If the application has been restored from an earlier session, this + identifier is the same as it was in the earlier session. - \sa sessionKey(), QApplication::sessionId() - */ + \sa sessionKey(), QApplication::sessionId() +*/ /*! - \fn QString QSessionManager::sessionKey() const + \fn QString QSessionManager::sessionKey() const - Returns the session key in the current session. + Returns the session key in the current session. - If the application has been restored from an earlier session, this - key is the same as it was when the previous session ended. + If the application has been restored from an earlier session, this key is + the same as it was when the previous session ended. - The session key changes with every call of commitData() or - saveState(). + The session key changes with every call of commitData() or saveState(). - \sa sessionId(), QApplication::sessionKey() - */ + \sa sessionId(), QApplication::sessionKey() +*/ /*! \fn void* QSessionManager::handle() const @@ -4197,120 +4168,116 @@ bool QApplicationPrivate::notify_helper(QObject *receiver, QEvent * e) */ /*! - \fn bool QSessionManager::allowsInteraction() + \fn bool QSessionManager::allowsInteraction() - Asks the session manager for permission to interact with the - user. Returns true if interaction is permitted; otherwise - returns false. + Asks the session manager for permission to interact with the user. Returns + true if interaction is permitted; otherwise returns false. - The rationale behind this mechanism is to make it possible to - synchronize user interaction during a shutdown. Advanced session - managers may ask all applications simultaneously to commit their - data, resulting in a much faster shutdown. + The rationale behind this mechanism is to make it possible to synchronize + user interaction during a shutdown. Advanced session managers may ask all + applications simultaneously to commit their data, resulting in a much + faster shutdown. - When the interaction is completed we strongly recommend releasing the - user interaction semaphore with a call to release(). This way, other - applications may get the chance to interact with the user while your - application is still busy saving data. (The semaphore is implicitly - released when the application exits.) + When the interaction is completed we strongly recommend releasing the user + interaction semaphore with a call to release(). This way, other + applications may get the chance to interact with the user while your + application is still busy saving data. (The semaphore is implicitly + released when the application exits.) - If the user decides to cancel the shutdown process during the - interaction phase, you must tell the session manager that this has - happened by calling cancel(). + If the user decides to cancel the shutdown process during the interaction + phase, you must tell the session manager that this has happened by calling + cancel(). - Here's an example of how an application's QApplication::commitData() - might be implemented: + Here's an example of how an application's QApplication::commitData() might + be implemented: - \snippet doc/src/snippets/code/src_gui_kernel_qapplication.cpp 8 + \snippet doc/src/snippets/code/src_gui_kernel_qapplication.cpp 8 - If an error occurred within the application while saving its data, - you may want to try allowsErrorInteraction() instead. + If an error occurred within the application while saving its data, you may + want to try allowsErrorInteraction() instead. - \sa QApplication::commitData(), release(), cancel() + \sa QApplication::commitData(), release(), cancel() */ /*! - \fn bool QSessionManager::allowsErrorInteraction() + \fn bool QSessionManager::allowsErrorInteraction() - Returns true if error interaction is permitted; otherwise returns false. + Returns true if error interaction is permitted; otherwise returns false. - This is similar to allowsInteraction(), but also enables the application - to tell the user about any errors that occur. Session managers - may give error interaction requests higher priority, which means that it - is more likely that an error interaction is permitted. However, you are - still not guaranteed that the session manager will allow interaction. + This is similar to allowsInteraction(), but also enables the application to + tell the user about any errors that occur. Session managers may give error + interaction requests higher priority, which means that it is more likely + that an error interaction is permitted. However, you are still not + guaranteed that the session manager will allow interaction. - \sa allowsInteraction(), release(), cancel() + \sa allowsInteraction(), release(), cancel() */ /*! - \fn void QSessionManager::release() + \fn void QSessionManager::release() - Releases the session manager's interaction semaphore after an - interaction phase. + Releases the session manager's interaction semaphore after an interaction + phase. - \sa allowsInteraction(), allowsErrorInteraction() + \sa allowsInteraction(), allowsErrorInteraction() */ /*! - \fn void QSessionManager::cancel() - - Tells the session manager to cancel the shutdown process. Applications - should not call this function without first asking the user. + \fn void QSessionManager::cancel() - \sa allowsInteraction(), allowsErrorInteraction() + Tells the session manager to cancel the shutdown process. Applications + should not call this function without asking the user first. + \sa allowsInteraction(), allowsErrorInteraction() */ /*! - \fn void QSessionManager::setRestartHint(RestartHint hint) + \fn void QSessionManager::setRestartHint(RestartHint hint) - Sets the application's restart hint to \a hint. On application - startup the hint is set to \c RestartIfRunning. + Sets the application's restart hint to \a hint. On application startup, the + hint is set to \c RestartIfRunning. - Note that these flags are only hints, a session manager may or may - not respect them. + \note These flags are only hints, a session manager may or may not respect + them. - We recommend setting the restart hint in QApplication::saveState() - because most session managers perform a checkpoint shortly after an - application's startup. + We recommend setting the restart hint in QApplication::saveState() because + most session managers perform a checkpoint shortly after an application's + startup. - \sa restartHint() + \sa restartHint() */ /*! - \fn QSessionManager::RestartHint QSessionManager::restartHint() const + \fn QSessionManager::RestartHint QSessionManager::restartHint() const - Returns the application's current restart hint. The default is - \c RestartIfRunning. + Returns the application's current restart hint. The default is + \c RestartIfRunning. - \sa setRestartHint() + \sa setRestartHint() */ /*! - \fn void QSessionManager::setRestartCommand(const QStringList& command) + \fn void QSessionManager::setRestartCommand(const QStringList& command) - If the session manager is capable of restoring sessions it will - execute \a command in order to restore the application. The command - defaults to + If the session manager is capable of restoring sessions it will execute + \a command in order to restore the application. The command defaults to \snippet doc/src/snippets/code/src_gui_kernel_qapplication.cpp 9 - The \c -session option is mandatory; otherwise QApplication cannot - tell whether it has been restored or what the current session - identifier is. See QApplication::isSessionRestored() and - QApplication::sessionId() for details. + The \c -session option is mandatory; otherwise QApplication cannot tell + whether it has been restored or what the current session identifier is. + See QApplication::isSessionRestored() and QApplication::sessionId() for + details. - If your application is very simple, it may be possible to store the - entire application state in additional command line options. This - is usually a very bad idea because command lines are often limited - to a few hundred bytes. Instead, use QSettings, or temporary files - or a database for this purpose. By marking the data with the unique - sessionId(), you will be able to restore the application in a future - session. + If your application is very simple, it may be possible to store the entire + application state in additional command line options. This is usually a + very bad idea because command lines are often limited to a few hundred + bytes. Instead, use QSettings, temporary files, or a database for this + purpose. By marking the data with the unique sessionId(), you will be able + to restore the application in a future session. - \sa restartCommand(), setDiscardCommand(), setRestartHint() + \sa restartCommand(), setDiscardCommand(), setRestartHint() */ /*! @@ -4318,8 +4285,7 @@ bool QApplicationPrivate::notify_helper(QObject *receiver, QEvent * e) Returns the currently set restart command. - To iterate over the list, you can use the \l foreach - pseudo-keyword: + To iterate over the list, you can use the \l foreach pseudo-keyword: \snippet doc/src/snippets/code/src_gui_kernel_qapplication.cpp 10 @@ -4327,11 +4293,11 @@ bool QApplicationPrivate::notify_helper(QObject *receiver, QEvent * e) */ /*! - \fn void QSessionManager::setDiscardCommand(const QStringList& list) + \fn void QSessionManager::setDiscardCommand(const QStringList& list) - Sets the discard command to the given \a list. + Sets the discard command to the given \a list. - \sa discardCommand(), setRestartCommand() + \sa discardCommand(), setRestartCommand() */ @@ -4340,8 +4306,7 @@ bool QApplicationPrivate::notify_helper(QObject *receiver, QEvent * e) Returns the currently set discard command. - To iterate over the list, you can use the \l foreach - pseudo-keyword: + To iterate over the list, you can use the \l foreach pseudo-keyword: \snippet doc/src/snippets/code/src_gui_kernel_qapplication.cpp 11 @@ -4349,53 +4314,51 @@ bool QApplicationPrivate::notify_helper(QObject *receiver, QEvent * e) */ /*! - \fn void QSessionManager::setManagerProperty(const QString &name, const QString &value) - \overload + \fn void QSessionManager::setManagerProperty(const QString &name, const QString &value) + \overload - Low-level write access to the application's identification and state - records are kept in the session manager. + Low-level write access to the application's identification and state + records are kept in the session manager. - The property called \a name has its value set to the string \a value. + The property called \a name has its value set to the string \a value. */ /*! - \fn void QSessionManager::setManagerProperty(const QString& name, - const QStringList& value) + \fn void QSessionManager::setManagerProperty(const QString& name, + const QStringList& value) - Low-level write access to the application's identification and state - record are kept in the session manager. + Low-level write access to the application's identification and state record + are kept in the session manager. - The property called \a name has its value set to the string list \a value. + The property called \a name has its value set to the string list \a value. */ /*! - \fn bool QSessionManager::isPhase2() const + \fn bool QSessionManager::isPhase2() const - Returns true if the session manager is currently performing a second - session management phase; otherwise returns false. + Returns true if the session manager is currently performing a second + session management phase; otherwise returns false. - \sa requestPhase2() + \sa requestPhase2() */ /*! - \fn void QSessionManager::requestPhase2() + \fn void QSessionManager::requestPhase2() - Requests a second session management phase for the application. The - application may then return immediately from the - QApplication::commitData() or QApplication::saveState() function, - and they will be called again once most or all other applications have - finished their session management. + Requests a second session management phase for the application. The + application may then return immediately from the QApplication::commitData() + or QApplication::saveState() function, and they will be called again once + most or all other applications have finished their session management. - The two phases are useful for applications such as the X11 window manager - that need to store information about another application's windows - and therefore have to wait until these applications have completed their - respective session management tasks. + The two phases are useful for applications such as the X11 window manager + that need to store information about another application's windows and + therefore have to wait until these applications have completed their + respective session management tasks. - Note that if another application has requested a second phase it - may get called before, simultaneously with, or after your - application's second phase. + \note If another application has requested a second phase it may get called + before, simultaneously with, or after your application's second phase. - \sa isPhase2() + \sa isPhase2() */ /***************************************************************************** @@ -4588,15 +4551,14 @@ void QSessionManager::requestPhase2() /*! \fn bool QApplication::hasGlobalMouseTracking() - This feature does not exist anymore. This function - always returns true in Qt 4. + This feature does not exist anymore. This function always returns true + in Qt 4. */ /*! \fn void QApplication::setGlobalMouseTracking(bool dummy) - This function does nothing in Qt 4. The \a dummy parameter - is ignored. + This function does nothing in Qt 4. The \a dummy parameter is ignored. */ /*! @@ -4634,15 +4596,14 @@ void QSessionManager::requestPhase2() /*! \fn const QColor &QApplication::winStyleHighlightColor() - Use qApp->palette().color(QPalette::Active, QPalette::Highlight) - instead. + Use qApp->palette().color(QPalette::Active, QPalette::Highlight) instead. */ /*! \fn QWidget *QApplication::widgetAt(int x, int y, bool child) - Use the two-argument widgetAt() overload to get the child widget. - To get the top-level widget do this: + Use the two-argument widgetAt() overload to get the child widget. To get + the top-level widget do this: \snippet doc/src/snippets/code/src_gui_kernel_qapplication.cpp 12 */ @@ -4650,8 +4611,8 @@ void QSessionManager::requestPhase2() /*! \fn QWidget *QApplication::widgetAt(const QPoint &point, bool child) - Use the single-argument widgetAt() overload to get the child widget. - To get the top-level widget do this: + Use the single-argument widgetAt() overload to get the child widget. To get + the top-level widget do this: \snippet doc/src/snippets/code/src_gui_kernel_qapplication.cpp 13 */ @@ -4723,10 +4684,9 @@ void QApplicationPrivate::emitLastWindowClosed() Sets whether Qt should use focus navigation suitable for use with a minimal keypad. - If \a enable is true, Qt::Key_Up and Qt::Key_Down are used to - change focus. + If \a enable is true, Qt::Key_Up and Qt::Key_Down are used to change focus. - This feature is only available in Qt for Embedded Linux. + This feature is available in Qt for Embedded Linux only. \sa keypadNavigationEnabled() */ @@ -4739,7 +4699,8 @@ void QApplication::setKeypadNavigationEnabled(bool enable) Returns true if Qt is set to use keypad navigation; otherwise returns false. The default is false. - This feature is only available in Qt for Embedded Linux. + This feature is available in Qt for Embedded Linux only. + \sa setKeypadNavigationEnabled() */ bool QApplication::keypadNavigationEnabled() @@ -4762,12 +4723,12 @@ bool QApplication::keypadNavigationEnabled() On Mac OS X, this works more at the application level and will cause the application icon to bounce in the dock. - On Windows this causes the window's taskbar entry to flash for a time. If \a - msec is zero, the flashing will stop and the taskbar entry will turn a + On Windows this causes the window's taskbar entry to flash for a time. If + \a msec is zero, the flashing will stop and the taskbar entry will turn a different color (currently orange). - On X11, this will cause the window to be marked as "demands attention", - the window must not be hidden (i.e. not have hide() called on it, but be + On X11, this will cause the window to be marked as "demands attention", the + window must not be hidden (i.e. not have hide() called on it, but be visible in some sort of way) in order for this to work. */ @@ -4775,18 +4736,16 @@ bool QApplication::keypadNavigationEnabled() \property QApplication::cursorFlashTime \brief the text cursor's flash (blink) time in milliseconds - The flash time is the time required to display, invert and - restore the caret display. Usually the text cursor is displayed - for half the cursor flash time, then hidden for the same amount - of time, but this may vary. + The flash time is the time required to display, invert and restore the + caret display. Usually the text cursor is displayed for half the cursor + flash time, then hidden for the same amount of time, but this may vary. - The default value on X11 is 1000 milliseconds. On Windows, the - control panel value is used. Widgets should not cache this value - since it may be changed at any time by the user changing the - global desktop settings. + The default value on X11 is 1000 milliseconds. On Windows, the control + panel value is used. Widgets should not cache this value since it may be + changed at any time by the user changing the global desktop settings. - Note that on Microsoft Windows, setting this property sets the - cursor flash time for all applications. + \note On Microsoft Windows, setting this property sets the cursor flash + time for all applications. */ /*! @@ -4794,11 +4753,11 @@ bool QApplication::keypadNavigationEnabled() \brief the time limit in milliseconds that distinguishes a double click from two consecutive mouse clicks - The default value on X11 is 400 milliseconds. On Windows and Mac - OS X, the operating system's value is used. + The default value on X11 is 400 milliseconds. On Windows and Mac OS X, the + operating system's value is used. - On Microsoft Windows, calling this function sets the - double click interval for all applications. + On Microsoft Windows, calling this function sets the double click interval + for all applications. */ /*! @@ -4816,15 +4775,13 @@ bool QApplication::keypadNavigationEnabled() \brief the number of lines to scroll a widget, when the mouse wheel is rotated. - If the value exceeds the widget's number of visible lines, the - widget should interpret the scroll operation as a single \e{page - up} or \e{page down}. If the widget is an \l{QAbstractItemView} - {item view class}, then the result of scrolling one \e line - depends on the setting of the widget's - \l{QAbstractItemView::verticalScrollMode()} {scroll mode}. Scroll - one \e line can mean \l{QAbstractItemView::ScrollPerItem} {scroll - one item} or \l{QAbstractItemView::ScrollPerPixel} {scroll one - pixel}. + If the value exceeds the widget's number of visible lines, the widget + should interpret the scroll operation as a single \e{page up} or + \e{page down}. If the widget is an \l{QAbstractItemView}{item view class}, + then the result of scrolling one \e line depends on the setting of the + widget's \l{QAbstractItemView::verticalScrollMode()}{scroll mode}. Scroll + one \e line can mean \l{QAbstractItemView::ScrollPerItem}{scroll one item} + or \l{QAbstractItemView::ScrollPerPixel}{scroll one pixel}. By default, this property has a value of 3. */ @@ -4832,11 +4789,11 @@ bool QApplication::keypadNavigationEnabled() /*! \fn void QApplication::setEffectEnabled(Qt::UIEffect effect, bool enable) - Enables the UI effect \a effect if \a enable is true, otherwise - the effect will not be used. + Enables the UI effect \a effect if \a enable is true, otherwise the effect + will not be used. - Note: All effects are disabled on screens running at less than - 16-bit color depth. + \note All effects are disabled on screens running at less than 16-bit color + depth. \sa isEffectEnabled(), Qt::UIEffect, setDesktopSettingsAware() */ @@ -4846,11 +4803,11 @@ bool QApplication::keypadNavigationEnabled() Returns true if \a effect is enabled; otherwise returns false. - By default, Qt will try to use the desktop settings. Call - setDesktopSettingsAware(false) to prevent this. + By default, Qt will try to use the desktop settings. To prevent this, call + setDesktopSettingsAware(false). - Note: All effects are disabled on screens running at less than - 16-bit color depth. + \note All effects are disabled on screens running at less than 16-bit color + depth. \sa setEffectEnabled(), Qt::UIEffect */ @@ -4858,8 +4815,7 @@ bool QApplication::keypadNavigationEnabled() /*! \fn QWidget *QApplication::mainWidget() - Returns the main application widget, or 0 if there is no main - widget. + Returns the main application widget, or 0 if there is no main widget. */ /*! @@ -4867,19 +4823,17 @@ bool QApplication::keypadNavigationEnabled() Sets the application's main widget to \a mainWidget. - In most respects the main widget is like any other widget, except - that if it is closed, the application exits. Note that - QApplication does \e not take ownership of the \a mainWidget, so - if you create your main widget on the heap you must delete it - yourself. + In most respects the main widget is like any other widget, except that if + it is closed, the application exits. QApplication does \e not take + ownership of the \a mainWidget, so if you create your main widget on the + heap you must delete it yourself. - You need not have a main widget; connecting lastWindowClosed() to - quit() is an alternative. + You need not have a main widget; connecting lastWindowClosed() to quit() + is an alternative. - For X11, this function also resizes and moves the main widget - according to the \e -geometry command-line option, so you should - set the default geometry (using \l QWidget::setGeometry()) before - calling setMainWidget(). + For X11, this function also resizes and moves the main widget according + to the \e -geometry command-line option, so you should set the default + geometry (using \l QWidget::setGeometry()) before calling setMainWidget(). \sa mainWidget(), exec(), quit() */ @@ -4887,8 +4841,8 @@ bool QApplication::keypadNavigationEnabled() /*! \fn void QApplication::beep() - Sounds the bell, using the default volume and sound. The function - is \e not available in Qt for Embedded Linux. + Sounds the bell, using the default volume and sound. The function is \e not + available in Qt for Embedded Linux. */ /*! @@ -4896,26 +4850,25 @@ bool QApplication::keypadNavigationEnabled() Sets the application override cursor to \a cursor. - Application override cursors are intended for showing the user - that the application is in a special state, for example during an - operation that might take some time. + Application override cursors are intended for showing the user that the + application is in a special state, for example during an operation that + might take some time. - This cursor will be displayed in all the application's widgets - until restoreOverrideCursor() or another setOverrideCursor() is - called. + This cursor will be displayed in all the application's widgets until + restoreOverrideCursor() or another setOverrideCursor() is called. - Application cursors are stored on an internal stack. - setOverrideCursor() pushes the cursor onto the stack, and - restoreOverrideCursor() pops the active cursor off the - stack. changeOverrideCursor() changes the curently active - application override cursor. Every setOverrideCursor() must + Application cursors are stored on an internal stack. setOverrideCursor() + pushes the cursor onto the stack, and restoreOverrideCursor() pops the + active cursor off the stack. changeOverrideCursor() changes the curently + active application override cursor. Every setOverrideCursor() must eventually be followed by a corresponding restoreOverrideCursor(), otherwise the stack will never be emptied. Example: \snippet doc/src/snippets/code/src_gui_kernel_qapplication_x11.cpp 0 - \sa overrideCursor() restoreOverrideCursor() changeOverrideCursor() QWidget::setCursor() + \sa overrideCursor(), restoreOverrideCursor(), changeOverrideCursor(), + QWidget::setCursor() */ /*! @@ -4924,9 +4877,8 @@ bool QApplication::keypadNavigationEnabled() Undoes the last setOverrideCursor(). If setOverrideCursor() has been called twice, calling - restoreOverrideCursor() will activate the first cursor set. - Calling this function a second time restores the original widgets' - cursors. + restoreOverrideCursor() will activate the first cursor set. Calling this + function a second time restores the original widgets' cursors. \sa setOverrideCursor(), overrideCursor() */ @@ -4936,9 +4888,9 @@ bool QApplication::keypadNavigationEnabled() \relates QApplication A global pointer referring to the unique application object. It is - equivalent to the pointer returned by the - QCoreApplication::instance() function except that, in GUI applications, - it is a pointer to a QApplication instance. + equivalent to the pointer returned by the QCoreApplication::instance() + function except that, in GUI applications, it is a pointer to a + QApplication instance. Only one application object can be created. @@ -4950,8 +4902,8 @@ bool QApplication::keypadNavigationEnabled() // ************************************************************************ /*! - This function replaces the QInputContext instance used by the - application with \a inputContext. + This function replaces the QInputContext instance used by the application + with \a inputContext. \sa inputContext() */ @@ -4982,7 +4934,11 @@ QInputContext *QApplication::inputContext() const return 0; if (!d->inputContext) { QApplication *that = const_cast<QApplication *>(this); - that->d_func()->inputContext = QInputContextFactory::create(X11->default_im, that); + QInputContext *qic = QInputContextFactory::create(X11->default_im, that); + // fallback to default X Input Method. + if (!qic) + qic = QInputContextFactory::create(QLatin1String("xim"), that); + that->d_func()->inputContext = qic; } #endif return d->inputContext; @@ -5048,6 +5004,137 @@ bool QApplicationPrivate::shouldSetFocus(QWidget *w, Qt::FocusPolicy policy) return true; } +/*! \fn QDecoration &QApplication::qwsDecoration() + Return the QWSDecoration used for decorating windows. + + \warning This method is non-portable. It is only available in + Qt for Embedded Linux. + + \sa QDecoration +*/ + +/*! + \fn void QApplication::qwsSetDecoration(QDecoration *decoration) + + Sets the QDecoration derived class to use for decorating the + windows used by Qt for Embedded Linux to the \a decoration + specified. + + This method is non-portable. It is only available in Qt for Embedded Linux. + + \sa QDecoration +*/ + +/*! \fn QDecoration* QApplication::qwsSetDecoration(const QString &decoration) + \overload + + Requests a QDecoration object for \a decoration from the QDecorationFactory. + + The string must be one of the QDecorationFactory::keys(). Keys are + case insensitive. + + A later call to the QApplication constructor will override the + requested style when a "-style" option is passed in as a commandline + parameter. + + Returns 0 if an unknown \a decoration is passed, otherwise the QStyle object + returned is set as the application's GUI style. +*/ + +/*! + \fn bool QApplication::qwsEventFilter(QWSEvent *event) + + This virtual function is only implemented under Qt for Embedded Linux. + + If you create an application that inherits QApplication and + reimplement this function, you get direct access to all QWS (Q + Window System) events that the are received from the QWS master + process. The events are passed in the \a event parameter. + + Return true if you want to stop the event from being processed. + Return false for normal event dispatching. The default + implementation returns false. +*/ + +/*! \fn void QApplication::qwsSetCustomColors(QRgb *colorTable, int start, int numColors) + Set Qt for Embedded Linux custom color table. + + Qt for Embedded Linux on 8-bpp displays allocates a standard 216 color cube. + The remaining 40 colors may be used by setting a custom color + table in the QWS master process before any clients connect. + + \a colorTable is an array of up to 40 custom colors. \a start is + the starting index (0-39) and \a numColors is the number of colors + to be set (1-40). + + This method is non-portable. It is available \e only in + Qt for Embedded Linux. + + \note The custom colors will not be used by the default screen + driver. To make use of the new colors, implement a custom screen + driver, or use QDirectPainter. +*/ + +/*! \fn int QApplication::qwsProcessEvent(QWSEvent* event) + \internal +*/ + +/*! \fn int QApplication::x11ClientMessage(QWidget* w, XEvent* event, bool passive_only) + \internal +*/ + +/*! \fn int QApplication::x11ProcessEvent(XEvent* event) + This function does the core processing of individual X + \a{event}s, normally by dispatching Qt events to the right + destination. + + It returns 1 if the event was consumed by special handling, 0 if + the \a event was consumed by normal handling, and -1 if the \a + event was for an unrecognized widget. + + \sa x11EventFilter() +*/ + +/*! + \fn bool QApplication::x11EventFilter(XEvent *event) + + \warning This virtual function is only implemented under X11. + + If you create an application that inherits QApplication and + reimplement this function, you get direct access to all X events + that the are received from the X server. The events are passed in + the \a event parameter. + + Return true if you want to stop the event from being processed. + Return false for normal event dispatching. The default + implementation returns false. + + It is only the directly addressed messages that are filtered. + You must install an event filter directly on the event + dispatcher, which is returned by + QAbstractEventDispatcher::instance(), to handle system wide + messages. + + \sa x11ProcessEvent() +*/ + +/*! \fn void QApplication::winFocus(QWidget *widget, bool gotFocus) + \internal + \since 4.1 + + If \a gotFocus is true, \a widget will become the active window. + Otherwise the active window is reset to 0. +*/ + +/*! \fn void QApplication::winMouseButtonUp() + \internal + */ + +/*! \fn void QApplication::syncX() + Synchronizes with the X server in the X11 implementation. + This normally takes some time. Does nothing on other platforms. +*/ + QT_END_NAMESPACE #include "moc_qapplication.cpp" diff --git a/src/gui/kernel/qapplication_mac.mm b/src/gui/kernel/qapplication_mac.mm index 5f8c572..69302ec 100644 --- a/src/gui/kernel/qapplication_mac.mm +++ b/src/gui/kernel/qapplication_mac.mm @@ -194,8 +194,8 @@ static bool appNoGrab = false; // mouse/keyboard grabbing #ifndef QT_MAC_USE_COCOA static EventHandlerRef app_proc_handler = 0; static EventHandlerUPP app_proc_handlerUPP = 0; -static AEEventHandlerUPP app_proc_ae_handlerUPP = NULL; #endif +static AEEventHandlerUPP app_proc_ae_handlerUPP = NULL; static EventHandlerRef tablet_proximity_handler = 0; static EventHandlerUPP tablet_proximity_UPP = 0; bool QApplicationPrivate::native_modal_dialog_active; @@ -951,7 +951,6 @@ void qt_mac_event_release(QWidget *w) } } -#ifndef QT_MAC_USE_COCOA struct QMacAppleEventTypeSpec { AEEventClass mac_class; AEEventID mac_id; @@ -959,6 +958,7 @@ struct QMacAppleEventTypeSpec { { kCoreEventClass, kAEQuitApplication }, { kCoreEventClass, kAEOpenDocuments } }; +#ifndef QT_MAC_USE_COCOA /* watched events */ static EventTypeSpec app_events[] = { { kEventClassQt, kEventQtRequestWindowChange }, @@ -1156,13 +1156,13 @@ void qt_init(QApplicationPrivate *priv, int) qt_init_app_proc_handler(); } +#endif if (!app_proc_ae_handlerUPP) { app_proc_ae_handlerUPP = AEEventHandlerUPP(QApplicationPrivate::globalAppleEventProcessor); for(uint i = 0; i < sizeof(app_apple_events) / sizeof(QMacAppleEventTypeSpec); ++i) AEInstallEventHandler(app_apple_events[i].mac_class, app_apple_events[i].mac_id, app_proc_ae_handlerUPP, SRefCon(qApp), true); } -#endif if (QApplicationPrivate::app_style) { QEvent ev(QEvent::Style); @@ -1210,6 +1210,17 @@ void qt_init(QApplicationPrivate *priv, int) } +void qt_release_apple_event_handler() +{ + if(app_proc_ae_handlerUPP) { + for(uint i = 0; i < sizeof(app_apple_events) / sizeof(QMacAppleEventTypeSpec); ++i) + AERemoveEventHandler(app_apple_events[i].mac_class, app_apple_events[i].mac_id, + app_proc_ae_handlerUPP, true); + DisposeAEEventHandlerUPP(app_proc_ae_handlerUPP); + app_proc_ae_handlerUPP = 0; + } +} + /***************************************************************************** qt_cleanup() - cleans up when the application is finished *****************************************************************************/ @@ -1223,15 +1234,8 @@ void qt_cleanup() DisposeEventHandlerUPP(app_proc_handlerUPP); app_proc_handlerUPP = 0; } - if(app_proc_ae_handlerUPP) { - for(uint i = 0; i < sizeof(app_apple_events) / sizeof(QMacAppleEventTypeSpec); ++i) - AERemoveEventHandler(app_apple_events[i].mac_class, app_apple_events[i].mac_id, - app_proc_ae_handlerUPP, true); - DisposeAEEventHandlerUPP(app_proc_ae_handlerUPP); - app_proc_ae_handlerUPP = NULL; - } #endif - + qt_release_apple_event_handler(); qt_release_tablet_proximity_handler(); if (tablet_proximity_UPP) DisposeEventHandlerUPP(tablet_proximity_UPP); @@ -2367,6 +2371,12 @@ QApplicationPrivate::globalEventProcessor(EventHandlerCallRef er, EventRef event #endif } +// In Carbon this is your one stop for apple events. +// In Cocoa, it ISN'T. This is the catch-all Apple Event handler that exists +// for the time between instantiating the NSApplication, but before the +// NSApplication has installed it's OWN Apple Event handler. When Cocoa has +// that set up, we remove this. So, if you are debugging problems, you likely +// want to check out QCocoaApplicationDelegate instead. OSStatus QApplicationPrivate::globalAppleEventProcessor(const AppleEvent *ae, AppleEvent *, long handlerRefcon) { QApplication *app = (QApplication *)handlerRefcon; diff --git a/src/gui/kernel/qapplication_qws.cpp b/src/gui/kernel/qapplication_qws.cpp index 2deda8e..018440f 100644 --- a/src/gui/kernel/qapplication_qws.cpp +++ b/src/gui/kernel/qapplication_qws.cpp @@ -2675,9 +2675,6 @@ void QApplication::alert(QWidget *, int) { } -/*! - \internal -*/ int QApplication::qwsProcessEvent(QWSEvent* event) { Q_D(QApplication); @@ -3056,43 +3053,11 @@ int QApplication::qwsProcessEvent(QWSEvent* event) return 0; } -/*! - \fn bool QApplication::qwsEventFilter(QWSEvent *event) - - This virtual function is only implemented under Qt for Embedded Linux. - - If you create an application that inherits QApplication and - reimplement this function, you get direct access to all QWS (Q - Window System) events that the are received from the QWS master - process. The events are passed in the \a event parameter. - - Return true if you want to stop the event from being processed. - Return false for normal event dispatching. The default - implementation returns false. -*/ bool QApplication::qwsEventFilter(QWSEvent *) { return false; } -/*! - Set Qt for Embedded Linux custom color table. - - Qt for Embedded Linux on 8-bpp displays allocates a standard 216 color cube. - The remaining 40 colors may be used by setting a custom color - table in the QWS master process before any clients connect. - - \a colorTable is an array of up to 40 custom colors. \a start is - the starting index (0-39) and \a numColors is the number of colors - to be set (1-40). - - This method is non-portable. It is available \e only in - Qt for Embedded Linux. - - \note The custom colors will not be used by the default screen - driver. To make use of the new colors, implement a custom screen - driver, or use QDirectPainter. -*/ void QApplication::qwsSetCustomColors(QRgb *colorTable, int start, int numColors) { if (start < 0 || start > 39) { @@ -3111,30 +3076,11 @@ void QApplication::qwsSetCustomColors(QRgb *colorTable, int start, int numColors } #ifndef QT_NO_QWS_MANAGER -/*! - Return the QWSDecoration used for decorating windows. - - \warning This method is non-portable. It is only available in - Qt for Embedded Linux. - - \sa QDecoration -*/ QDecoration &QApplication::qwsDecoration() { return *qws_decoration; } -/*! - \fn void QApplication::qwsSetDecoration(QDecoration *decoration) - - Sets the QDecoration derived class to use for decorating the - windows used by Qt for Embedded Linux to the \a decoration - specified. - - This method is non-portable. It is only available in Qt for Embedded Linux. - - \sa QDecoration -*/ void QApplication::qwsSetDecoration(QDecoration *dec) { if (dec) { @@ -3153,21 +3099,6 @@ void QApplication::qwsSetDecoration(QDecoration *dec) } } -/*! - \overload - - Requests a QDecoration object for \a decoration from the QDecorationFactory. - - The string must be one of the QDecorationFactory::keys(). Keys are - case insensitive. - - A later call to the QApplication constructor will override the - requested style when a "-style" option is passed in as a commandline - parameter. - - Returns 0 if an unknown \a decoration is passed, otherwise the QStyle object - returned is set as the application's GUI style. -*/ QDecoration* QApplication::qwsSetDecoration(const QString &decoration) { QDecoration *decore = QDecorationFactory::create(decoration); diff --git a/src/gui/kernel/qapplication_win.cpp b/src/gui/kernel/qapplication_win.cpp index fae0335..f14ad6f 100644 --- a/src/gui/kernel/qapplication_win.cpp +++ b/src/gui/kernel/qapplication_win.cpp @@ -1371,13 +1371,6 @@ QString QApplicationPrivate::appName() const extern uint qGlobalPostedEventsCount(); -/*! - \internal - \since 4.1 - - If \a gotFocus is true, \a widget will become the active window. - Otherwise the active window is reset to 0. -*/ void QApplication::winFocus(QWidget *widget, bool gotFocus) { if (d_func()->inPopupMode()) // some delayed focus event to ignore @@ -1732,6 +1725,21 @@ LRESULT CALLBACK QtWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam // fall-through intended case WM_KEYUP: case WM_SYSKEYUP: +#if Q_OS_WINCE_WM + case WM_HOTKEY: + if(HIWORD(msg.lParam) == VK_TBACK) { + const bool hotKeyDown = !(LOWORD(msg.lParam) & MOD_KEYUP); + msg.lParam = 0x69 << 16; + msg.wParam = VK_BACK; + if (hotKeyDown) { + msg.message = WM_KEYDOWN; + qt_keymapper_private()->updateKeyMap(msg); + } else { + msg.message = WM_KEYUP; + } + } + // fall-through intended +#endif case WM_IME_CHAR: case WM_IME_KEYDOWN: case WM_CHAR: { @@ -2432,10 +2440,12 @@ LRESULT CALLBACK QtWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam widget = (QETWidget*)qApp->focusWidget(); HWND focus = ::GetFocus(); //if there is a current widget and the new widget belongs to the same toplevel window + //or if the current widget was embedded into non-qt window (i.e. we won't get WM_ACTIVATEAPP) //then we clear the focus on the widget //in case the new widget belongs to a different widget hierarchy, clearing the focus //will be handled because the active window will change - if (widget && ::IsChild(widget->window()->internalWinId(), focus)) { + const bool embedded = widget && ((QETWidget*)widget->window())->topData()->embedded; + if (widget && (embedded || ::IsChild(widget->window()->internalWinId(), focus))) { widget->clearFocus(); result = true; } else { @@ -2919,7 +2929,6 @@ void qt_win_eatMouseMove() // In DnD, the mouse release event never appears, so the // mouse button state machine must be manually reset -/*! \internal */ void QApplication::winMouseButtonUp() { qt_button_down = 0; diff --git a/src/gui/kernel/qapplication_x11.cpp b/src/gui/kernel/qapplication_x11.cpp index 1df442f..a3c9406 100644 --- a/src/gui/kernel/qapplication_x11.cpp +++ b/src/gui/kernel/qapplication_x11.cpp @@ -398,7 +398,7 @@ extern bool qt_xdnd_dragging; // gui or non-gui from qapplication.cpp extern bool qt_is_gui_used; -/*! +/*! \internal Try to resolve a \a symbol from \a library with the version specified by \a vernum. @@ -829,11 +829,14 @@ bool QApplicationPrivate::x11_apply_settings() QColor(strlist[i])); } - if (groupCount == QPalette::NColorGroups) - QApplicationPrivate::setSystemPalette(pal); + // ### Fix properly for 4.6 + if (!(QApplicationPrivate::app_style && QApplicationPrivate::app_style->inherits("QGtkStyle"))) { + if (groupCount == QPalette::NColorGroups) + QApplicationPrivate::setSystemPalette(pal); + } int kdeSessionVersion = QString::fromLocal8Bit(qgetenv("KDE_SESSION_VERSION")).toInt(); - + if (!appFont) { QFont font(QApplication::font()); QString fontDescription; @@ -887,11 +890,15 @@ bool QApplicationPrivate::x11_apply_settings() } } + static QString currentStyleName = stylename; if (QCoreApplication::startingUp()) { if (!stylename.isEmpty() && !QApplicationPrivate::styleOverride) QApplicationPrivate::styleOverride = new QString(stylename); } else { - QApplication::setStyle(stylename); + if (currentStyleName != stylename) { + currentStyleName = stylename; + QApplication::setStyle(stylename); + } } int num = @@ -1355,8 +1362,10 @@ static void qt_set_x11_resources(const char* font = 0, const char* fg = 0, pal.setColor(QPalette::Disabled, QPalette::Highlight, Qt::darkBlue); } - QApplicationPrivate::setSystemPalette(pal); - + // QGtkStyle sets it's own system palette + if (!(QApplicationPrivate::app_style && QApplicationPrivate::app_style->inherits("QGtkStyle"))) { + QApplicationPrivate::setSystemPalette(pal); + } QColor::setAllowX11ColorNames(allowX11ColorNames); } @@ -1939,11 +1948,17 @@ void qt_init(QApplicationPrivate *priv, int, { QString displayName = QLatin1String(XDisplayName(NULL)); - // apparently MITSHM only works for local displays, so do a quick check here - // to determine whether the display is local or not (not 100 % accurate) + // MITSHM only works for local displays, so do a quick check here + // to determine whether the display is local or not (not 100 % accurate). + // BGR server layouts are not supported either, since it requires the raster + // engine to work on a QImage with BGR layout. bool local = displayName.isEmpty() || displayName.lastIndexOf(QLatin1Char(':')) == 0; - if (local && (qgetenv("QT_X11_NO_MITSHM").toInt() == 0)) - X11->use_mitshm = mitshm_pixmaps; + if (local && (qgetenv("QT_X11_NO_MITSHM").toInt() == 0)) { + Visual *defaultVisual = DefaultVisual(X11->display, DefaultScreen(X11->display)); + X11->use_mitshm = mitshm_pixmaps && (defaultVisual->red_mask == 0xff0000 + && defaultVisual->green_mask == 0xff00 + && defaultVisual->blue_mask == 0xff); + } } #endif // QT_NO_MITSHM @@ -2961,11 +2976,6 @@ QWidget *QApplication::topLevelAt(const QPoint &p) #endif } -/*! - Synchronizes with the X server in the X11 implementation. This - normally takes some time. Does nothing on other platforms. -*/ - void QApplication::syncX() { if (X11->display) @@ -3071,9 +3081,6 @@ static QETWidget *qPRFindWidget(Window oldwin) return wPRmapper ? (QETWidget*)wPRmapper->value((int)oldwin, 0) : 0; } -/*! - \internal -*/ int QApplication::x11ClientMessage(QWidget* w, XEvent* event, bool passive_only) { if (w && !w->internalWinId()) @@ -3136,17 +3143,6 @@ int QApplication::x11ClientMessage(QWidget* w, XEvent* event, bool passive_only) return 0; } -/*! - This function does the core processing of individual X - \a{event}s, normally by dispatching Qt events to the right - destination. - - It returns 1 if the event was consumed by special handling, 0 if - the \a event was consumed by normal handling, and -1 if the \a - event was for an unrecognized widget. - - \sa x11EventFilter() -*/ int QApplication::x11ProcessEvent(XEvent* event) { Q_D(QApplication); @@ -3154,43 +3150,48 @@ int QApplication::x11ProcessEvent(XEvent* event) #ifdef ALIEN_DEBUG //qDebug() << "QApplication::x11ProcessEvent:" << event->type; #endif + Time time = 0, userTime = 0; switch (event->type) { case ButtonPress: pressed_window = event->xbutton.window; - X11->userTime = event->xbutton.time; + userTime = event->xbutton.time; // fallthrough intended case ButtonRelease: - X11->time = event->xbutton.time; + time = event->xbutton.time; break; case MotionNotify: - X11->time = event->xmotion.time; + time = event->xmotion.time; break; case XKeyPress: - X11->userTime = event->xkey.time; + userTime = event->xkey.time; // fallthrough intended case XKeyRelease: - X11->time = event->xkey.time; + time = event->xkey.time; break; case PropertyNotify: - X11->time = event->xproperty.time; + time = event->xproperty.time; break; case EnterNotify: case LeaveNotify: - X11->time = event->xcrossing.time; + time = event->xcrossing.time; break; case SelectionClear: - X11->time = event->xselectionclear.time; + time = event->xselectionclear.time; break; default: - break; - } #ifndef QT_NO_XFIXES - if (X11->use_xfixes && event->type == (X11->xfixes_eventbase + XFixesSelectionNotify)) { - XFixesSelectionNotifyEvent *req = - reinterpret_cast<XFixesSelectionNotifyEvent *>(event); - X11->time = req->selection_timestamp; - } + if (X11->use_xfixes && event->type == (X11->xfixes_eventbase + XFixesSelectionNotify)) { + XFixesSelectionNotifyEvent *req = + reinterpret_cast<XFixesSelectionNotifyEvent *>(event); + time = req->selection_timestamp; + } #endif + break; + } + if (time > X11->time) + X11->time = time; + if (userTime > X11->userTime) + X11->userTime = userTime; QETWidget *widget = (QETWidget*)QWidget::find((WId)event->xany.window); @@ -3351,15 +3352,24 @@ int QApplication::x11ProcessEvent(XEvent* event) // update the size for desktop widget int scr = X11->ptrXRRRootToScreen(X11->display, event->xany.window); - QWidget *w = desktop()->screen(scr); + QDesktopWidget *desktop = QApplication::desktop(); + QWidget *w = desktop->screen(scr); QSize oldSize(w->size()); w->data->crect.setWidth(DisplayWidth(X11->display, scr)); w->data->crect.setHeight(DisplayHeight(X11->display, scr)); - if (w->size() != oldSize) { - QResizeEvent e(w->size(), oldSize); - QApplication::sendEvent(w, &e); - emit desktop()->resized(scr); - } + QVarLengthArray<QRect> oldSizes(desktop->numScreens()); + for (int i = 0; i < desktop->numScreens(); ++i) + oldSizes[i] = desktop->screenGeometry(i); + QResizeEvent e(w->size(), oldSize); + QApplication::sendEvent(w, &e); + for (int i = 0; i < qMin(oldSizes.count(), desktop->numScreens()); ++i) { + if (oldSizes[i] != desktop->screenGeometry(i)) + emit desktop->resized(i); + } + for (int i = oldSizes.count(); i < desktop->numScreens(); ++i) + emit desktop->resized(i); // added + for (int i = desktop->numScreens(); i < oldSizes.count(); ++i) + emit desktop->resized(i); // removed } #endif // QT_NO_XRANDR @@ -3814,29 +3824,6 @@ int QApplication::x11ProcessEvent(XEvent* event) return 0; } -/*! - \fn bool QApplication::x11EventFilter(XEvent *event) - - \warning This virtual function is only implemented under X11. - - If you create an application that inherits QApplication and - reimplement this function, you get direct access to all X events - that the are received from the X server. The events are passed in - the \a event parameter. - - Return true if you want to stop the event from being processed. - Return false for normal event dispatching. The default - implementation returns false. - - It is only the directly addressed messages that are filtered. - You must install an event filter directly on the event - dispatcher, which is returned by - QAbstractEventDispatcher::instance(), to handle system wide - messages. - - \sa x11ProcessEvent() -*/ - bool QApplication::x11EventFilter(XEvent *) { return false; diff --git a/src/gui/kernel/qcocoaapplication_mac.mm b/src/gui/kernel/qcocoaapplication_mac.mm index f95f004f..a3cc2c1 100644 --- a/src/gui/kernel/qcocoaapplication_mac.mm +++ b/src/gui/kernel/qcocoaapplication_mac.mm @@ -1,11 +1,11 @@ /**************************************************************************** - ** - ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). ** Contact: Qt Software Information (qt-info@nokia.com) - ** - ** This file is part of the QtGui module of the Qt Toolkit. - ** - ** $QT_BEGIN_LICENSE:LGPL$ +** +** 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 @@ -36,11 +36,11 @@ ** If you are unsure which license is appropriate for your use, please ** contact the sales department at qt-sales@nokia.com. ** $QT_END_LICENSE$ - ** - ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE - ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. - ** - ****************************************************************************/ +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +****************************************************************************/ /**************************************************************************** ** diff --git a/src/gui/kernel/qcocoaapplicationdelegate_mac.mm b/src/gui/kernel/qcocoaapplicationdelegate_mac.mm index 650ebbd..9a24645 100644 --- a/src/gui/kernel/qcocoaapplicationdelegate_mac.mm +++ b/src/gui/kernel/qcocoaapplicationdelegate_mac.mm @@ -1,11 +1,11 @@ /**************************************************************************** - ** - ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). ** Contact: Qt Software Information (qt-info@nokia.com) - ** - ** This file is part of the QtGui module of the Qt Toolkit. - ** - ** $QT_BEGIN_LICENSE:LGPL$ +** +** 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 @@ -36,11 +36,11 @@ ** If you are unsure which license is appropriate for your use, please ** contact the sales department at qt-sales@nokia.com. ** $QT_END_LICENSE$ - ** - ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE - ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. - ** - ****************************************************************************/ +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +****************************************************************************/ /**************************************************************************** ** @@ -107,6 +107,8 @@ static void cleanupCocoaApplicationDelegate() - (id)init { self = [super init]; + if (self) + inLaunch = true; return self; } @@ -181,29 +183,48 @@ static void cleanupCocoaApplicationDelegate() { Q_UNUSED(sender); // The reflection delegate gets precedence - NSApplicationTerminateReply reply = NSTerminateCancel; if (reflectionDelegate && [reflectionDelegate respondsToSelector:@selector(applicationShouldTerminate:)]) { return [reflectionDelegate applicationShouldTerminate:sender]; } if (qtPrivate->canQuit()) { - reply = NSTerminateNow; if (!startedQuit) { startedQuit = true; qAppInstance()->quit(); startedQuit = false; } } - return reply; + + // Prevent Cocoa from terminating the application, since this simply + // exits the program whithout allowing QApplication::exec() to return. + // The call to QApplication::quit() above will instead quit the + // application from the Qt side. + return NSTerminateCancel; +} + +- (void)applicationDidFinishLaunching:(NSNotification *)aNotification +{ + Q_UNUSED(aNotification); + inLaunch = false; + extern void qt_release_apple_event_handler(); //qapplication_mac.mm + qt_release_apple_event_handler(); } - (void)application:(NSApplication *)sender openFiles:(NSArray *)filenames { - unsigned int ix; - for( ix = 0; ix < [filenames count]; ix++) { - NSString *fileName = [filenames objectAtIndex:ix]; - qApp->postEvent(qApp, new QFileOpenEvent(QCFString::toQString((CFStringRef)fileName))); + for (NSString *fileName in filenames) { + QString qtFileName = qt_mac_NSStringToQString(fileName); + if (inLaunch) { + // We need to be careful because Cocoa will be nice enough to take + // command line arguments and send them to us as events. Given the history + // of Qt Applications, this will result in behavior people don't want, as + // they might be doing the opening themselves with the command line parsing. + if (qApp->arguments().contains(qtFileName)) + continue; + } + QFileOpenEvent foe(qtFileName); + qt_sendSpontaneousEvent(qAppInstance(), &foe); } if (reflectionDelegate && diff --git a/src/gui/kernel/qcocoaapplicationdelegate_mac_p.h b/src/gui/kernel/qcocoaapplicationdelegate_mac_p.h index c5336f1..fca2a15 100644 --- a/src/gui/kernel/qcocoaapplicationdelegate_mac_p.h +++ b/src/gui/kernel/qcocoaapplicationdelegate_mac_p.h @@ -107,6 +107,7 @@ QT_FORWARD_DECLARE_CLASS(QApplicationPrivate); NSMenu *dockMenu; QT_MANGLE_NAMESPACE(QCocoaMenuLoader) *qtMenuLoader; id <NSApplicationDelegate> reflectionDelegate; + bool inLaunch; } + (QT_MANGLE_NAMESPACE(QCocoaApplicationDelegate)*)sharedDelegate; - (void)setDockMenu:(NSMenu *)newMenu; diff --git a/src/gui/kernel/qcocoamenuloader_mac.mm b/src/gui/kernel/qcocoamenuloader_mac.mm index 7ecb765..e836286 100644 --- a/src/gui/kernel/qcocoamenuloader_mac.mm +++ b/src/gui/kernel/qcocoamenuloader_mac.mm @@ -1,11 +1,11 @@ /**************************************************************************** - ** - ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). ** Contact: Qt Software Information (qt-info@nokia.com) - ** - ** This file is part of the QtGui module of the Qt Toolkit. - ** - ** $QT_BEGIN_LICENSE:LGPL$ +** +** 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 @@ -36,11 +36,11 @@ ** If you are unsure which license is appropriate for your use, please ** contact the sales department at qt-sales@nokia.com. ** $QT_END_LICENSE$ - ** - ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE - ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. - ** - ****************************************************************************/ +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +****************************************************************************/ #include "qmacdefines_mac.h" #ifdef QT_MAC_USE_COCOA diff --git a/src/gui/kernel/qcocoapanel_mac.mm b/src/gui/kernel/qcocoapanel_mac.mm index 6aeee34..c69826f 100644 --- a/src/gui/kernel/qcocoapanel_mac.mm +++ b/src/gui/kernel/qcocoapanel_mac.mm @@ -43,10 +43,16 @@ #ifdef QT_MAC_USE_COCOA #import <private/qt_cocoa_helpers_mac_p.h> #import <private/qcocoawindow_mac_p.h> +#import <private/qcocoawindowdelegate_mac_p.h> +#import <private/qcocoaview_mac_p.h> #import <private/qcocoawindowcustomthemeframe_mac_p.h> #include <QtGui/QWidget> +QT_FORWARD_DECLARE_CLASS(QWidget); +QT_BEGIN_NAMESPACE +extern Qt::MouseButton cocoaButton2QtButton(NSInteger buttonNum); // qcocoaview.mm +QT_END_NAMESPACE QT_USE_NAMESPACE @implementation QT_MANGLE_NAMESPACE(QCocoaPanel) @@ -60,18 +66,115 @@ QT_USE_NAMESPACE return !(isPopup || isToolTip); } +/*********************************************************************** + BEGIN Copy and Paste between QCocoaWindow and QCocoaPanel + This is a bit unfortunate, but thanks to the dynamic dispatch we + have to duplicate this code or resort to really silly forwarding methods +**************************************************************************/ + +/* + The methods keyDown, keyUp, and flagsChanged... These really shouldn't ever + get hit. We automatically say we can be first responder if we are a window. + So, the handling should get handled by the view. This is here more as a + last resort (i.e., this is code that can potentially be removed). + */ + +- (void)keyDown:(NSEvent *)theEvent +{ + bool keyOK = qt_dispatchKeyEvent(theEvent, [self QT_MANGLE_NAMESPACE(qt_qwidget)]); + if (!keyOK) + [super keyDown:theEvent]; +} + +- (void)keyUp:(NSEvent *)theEvent +{ + bool keyOK = qt_dispatchKeyEvent(theEvent, [self QT_MANGLE_NAMESPACE(qt_qwidget)]); + if (!keyOK) + [super keyUp:theEvent]; +} + +- (void)flagsChanged:(NSEvent *)theEvent +{ + qt_dispatchModifiersChanged(theEvent, [self QT_MANGLE_NAMESPACE(qt_qwidget)]); + [super flagsChanged:theEvent]; +} + + +- (void)tabletProximity:(NSEvent *)tabletEvent +{ + qt_dispatchTabletProximityEvent(tabletEvent); +} + - (void)sendEvent:(NSEvent *)event { [self retain]; - [super sendEvent:event]; + + QWidget *widget = [[QT_MANGLE_NAMESPACE(QCocoaWindowDelegate) sharedDelegate] qt_qwidgetForWindow:self]; + QT_MANGLE_NAMESPACE(QCocoaView) *view = static_cast<QT_MANGLE_NAMESPACE(QCocoaView) *>(qt_mac_nativeview_for(widget)); + Qt::MouseButton mouseButton = cocoaButton2QtButton([event buttonNumber]); + + // sometimes need to redirect mouse events to the popup. + QWidget *popup = qAppInstance()->activePopupWidget(); + if (popup && popup != widget) { + switch([event type]) + { + case NSLeftMouseDown: + qt_mac_handleMouseEvent(view, event, QEvent::MouseButtonPress, mouseButton); + // Don't call super here. This prevents us from getting the mouseUp event, + // which we need to send even if the mouseDown event was not accepted. + // (this is standard Qt behavior.) + break; + case NSRightMouseDown: + case NSOtherMouseDown: + if (!qt_mac_handleMouseEvent(view, event, QEvent::MouseButtonPress, mouseButton)) + [super sendEvent:event]; + break; + case NSLeftMouseUp: + case NSRightMouseUp: + case NSOtherMouseUp: + if (!qt_mac_handleMouseEvent(view, event, QEvent::MouseButtonRelease, mouseButton)) + [super sendEvent:event]; + break; + case NSMouseMoved: + qt_mac_handleMouseEvent(view, event, QEvent::MouseMove, Qt::NoButton); + break; + case NSLeftMouseDragged: + case NSRightMouseDragged: + case NSOtherMouseDragged: + [QT_MANGLE_NAMESPACE(QCocoaView) currentMouseEvent]->view = view; + [QT_MANGLE_NAMESPACE(QCocoaView) currentMouseEvent]->theEvent = event; + if (!qt_mac_handleMouseEvent(view, event, QEvent::MouseMove, mouseButton)) + [super sendEvent:event]; + break; + default: + [super sendEvent:event]; + break; + } + } else { + [super sendEvent:event]; + } qt_mac_dispatchNCMouseMessage(self, event, [self QT_MANGLE_NAMESPACE(qt_qwidget)], leftButtonIsRightButton); + + [self release]; } +- (BOOL)makeFirstResponder:(NSResponder *)responder +{ + // For some reason Cocoa wants to flip the first responder + // when Qt doesn't want to, sorry, but "No" :-) + if (responder == nil && qApp->focusWidget()) + return NO; + return [super makeFirstResponder:responder]; +} + +/*********************************************************************** + END Copy and Paste between QCocoaWindow and QCocoaPanel +***********************************************************************/ + (Class)frameViewClassForStyleMask:(NSUInteger)styleMask { if (styleMask & QtMacCustomizeWindow) - return [QCocoaWindowCustomThemeFrame class]; + return [QT_MANGLE_NAMESPACE(QCocoaWindowCustomThemeFrame) class]; return [super frameViewClassForStyleMask:styleMask]; } diff --git a/src/gui/kernel/qcocoaview_mac.mm b/src/gui/kernel/qcocoaview_mac.mm index df42e79..4ceae3f 100644 --- a/src/gui/kernel/qcocoaview_mac.mm +++ b/src/gui/kernel/qcocoaview_mac.mm @@ -181,6 +181,7 @@ QT_FORWARD_DECLARE_CLASS(QAbstractScrollAreaPrivate) QT_FORWARD_DECLARE_CLASS(QPaintEvent) QT_FORWARD_DECLARE_CLASS(QPainter) QT_FORWARD_DECLARE_CLASS(QHoverEvent) +QT_FORWARD_DECLARE_CLASS(QCursor) QT_USE_NAMESPACE extern "C" { extern NSString *NSTextInputReplacementRangeAttributeName; @@ -197,6 +198,7 @@ extern "C" { } composing = false; sendKeyEvents = true; + currentCustomTypes = 0; [self setHidden:YES]; return self; } @@ -211,10 +213,16 @@ extern "C" { object:self]; } --(void)registerDragTypes:(bool)accept +-(void)registerDragTypes { QMacCocoaAutoReleasePool pool; - if (accept) { + // Calling registerForDraggedTypes is slow, so only do it once for each widget + // or when the custom types change. + const QStringList& customTypes = qEnabledDraggedTypes(); + if (currentCustomTypes == 0 || *currentCustomTypes != customTypes) { + if (currentCustomTypes == 0) + currentCustomTypes = new QStringList(); + *currentCustomTypes = customTypes; const NSString* mimeTypeGeneric = @"com.trolltech.qt.MimeTypeName"; NSMutableArray *supportedTypes = [NSMutableArray arrayWithObjects:NSColorPboardType, NSFilenamesPboardType, NSStringPboardType, @@ -226,13 +234,38 @@ extern "C" { NSFilesPromisePboardType, NSInkTextPboardType, NSMultipleTextSelectionPboardType, mimeTypeGeneric, nil]; // Add custom types supported by the application. - const QStringList& customTypes = qEnabledDraggedTypes(); for (int i = 0; i < customTypes.size(); i++) { [supportedTypes addObject:reinterpret_cast<const NSString *>(QCFString::toCFStringRef(customTypes[i]))]; } [self registerForDraggedTypes:supportedTypes]; + } +} + +- (void)resetCursorRects +{ + QWidget *cursorWidget = qwidget; + + if (cursorWidget->testAttribute(Qt::WA_TransparentForMouseEvents)) + cursorWidget = QApplication::widgetAt(qwidget->mapToGlobal(qwidget->rect().center())); + + if (cursorWidget == 0) + return; + + if (!cursorWidget->testAttribute(Qt::WA_SetCursor)) { + [super resetCursorRects]; + return; + } + + QRegion mask = qt_widget_private(cursorWidget)->extra->mask; + NSCursor *nscursor = static_cast<NSCursor *>(nsCursorForQCursor(cursorWidget->cursor())); + if (mask.isEmpty()) { + [self addCursorRect:[qt_mac_nativeview_for(cursorWidget) visibleRect] cursor:nscursor]; } else { - [self unregisterDraggedTypes]; + const QVector<QRect> &rects = mask.rects(); + for (int i = 0; i < rects.size(); ++i) { + const QRect &rect = rects.at(i); + [self addCursorRect:NSMakeRect(rect.x(), rect.y(), rect.width(), rect.height()) cursor:nscursor]; + } } } @@ -253,6 +286,8 @@ extern "C" { - (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender { + if (qwidget->testAttribute(Qt::WA_DropSiteRegistered) == false) + return NSDragOperationNone; [self addDropData:sender]; QMimeData *mimeData = dropData; if (QDragManager::self()->source()) @@ -263,9 +298,18 @@ extern "C" { QPoint posDrag(localPoint.x, localPoint.y); NSDragOperation nsActions = [sender draggingSourceOperationMask]; Qt::DropActions qtAllowed = qt_mac_mapNSDragOperations(nsActions); + QT_PREPEND_NAMESPACE(qt_mac_dnd_answer_rec.lastOperation) = nsActions; + Qt::KeyboardModifiers modifiers = Qt::NoModifier; + if ([sender draggingSource] != nil) { + // modifier flags might have changed, update it here since we don't send any input events. + QApplicationPrivate::modifier_buttons = qt_cocoaModifiers2QtModifiers([[NSApp currentEvent] modifierFlags]); + modifiers = QApplication::keyboardModifiers(); + } else { + // when the source is from another application the above technique will not work. + modifiers = qt_cocoaDragOperation2QtModifiers(nsActions); + } // send the drag enter event to the widget. - QDragEnterEvent qDEEvent(posDrag, qtAllowed, mimeData, - QApplication::mouseButtons(), QApplication::keyboardModifiers()); + QDragEnterEvent qDEEvent(posDrag, qtAllowed, mimeData, QApplication::mouseButtons(), modifiers); QApplication::sendEvent(qwidget, &qDEEvent); if (!qDEEvent.isAccepted()) { // widget is not interested in this drag, so ignore this drop data. @@ -273,24 +317,23 @@ extern "C" { return NSDragOperationNone; } else { // send a drag move event immediately after a drag enter event (as per documentation). - QDragMoveEvent qDMEvent(posDrag, qtAllowed, mimeData, - QApplication::mouseButtons(), QApplication::keyboardModifiers()); + QDragMoveEvent qDMEvent(posDrag, qtAllowed, mimeData, QApplication::mouseButtons(), modifiers); qDMEvent.setDropAction(qDEEvent.dropAction()); qDMEvent.accept(); // accept by default, since enter event was accepted. QApplication::sendEvent(qwidget, &qDMEvent); if (!qDMEvent.isAccepted() || qDMEvent.dropAction() == Qt::IgnoreAction) { // since we accepted the drag enter event, the widget expects // future drage move events. - // ### check if we need to treat this like the drag enter event. + // ### check if we need to treat this like the drag enter event. nsActions = QT_PREPEND_NAMESPACE(qt_mac_mapDropAction)(qDEEvent.dropAction()); } else { nsActions = QT_PREPEND_NAMESPACE(qt_mac_mapDropAction)(qDMEvent.dropAction()); - } + } QT_PREPEND_NAMESPACE(qt_mac_copy_answer_rect)(qDMEvent); - return nsActions; + return nsActions; } } - + - (NSDragOperation)draggingUpdated:(id < NSDraggingInfo >)sender { // drag enter event was rejected, so ignore the move event. @@ -300,17 +343,27 @@ extern "C" { NSPoint windowPoint = [sender draggingLocation]; NSPoint globalPoint = [[sender draggingDestinationWindow] convertBaseToScreen:windowPoint]; NSPoint localPoint = [self convertPoint:windowPoint fromView:nil]; + NSDragOperation nsActions = [sender draggingSourceOperationMask]; QPoint posDrag(localPoint.x, localPoint.y); - if (qt_mac_mouse_inside_answer_rect(posDrag)) + if (qt_mac_mouse_inside_answer_rect(posDrag) + && QT_PREPEND_NAMESPACE(qt_mac_dnd_answer_rec.lastOperation) == nsActions) return QT_PREPEND_NAMESPACE(qt_mac_mapDropActions)(QT_PREPEND_NAMESPACE(qt_mac_dnd_answer_rec.lastAction)); // send drag move event to the widget - NSDragOperation nsActions = [sender draggingSourceOperationMask]; + QT_PREPEND_NAMESPACE(qt_mac_dnd_answer_rec.lastOperation) = nsActions; Qt::DropActions qtAllowed = QT_PREPEND_NAMESPACE(qt_mac_mapNSDragOperations)(nsActions); + Qt::KeyboardModifiers modifiers = Qt::NoModifier; + if ([sender draggingSource] != nil) { + // modifier flags might have changed, update it here since we don't send any input events. + QApplicationPrivate::modifier_buttons = qt_cocoaModifiers2QtModifiers([[NSApp currentEvent] modifierFlags]); + modifiers = QApplication::keyboardModifiers(); + } else { + // when the source is from another application the above technique will not work. + modifiers = qt_cocoaDragOperation2QtModifiers(nsActions); + } QMimeData *mimeData = dropData; if (QDragManager::self()->source()) mimeData = QDragManager::self()->dragPrivate()->data; - QDragMoveEvent qDMEvent(posDrag, qtAllowed, mimeData, - QApplication::mouseButtons(), QApplication::keyboardModifiers()); + QDragMoveEvent qDMEvent(posDrag, qtAllowed, mimeData, QApplication::mouseButtons(), modifiers); qDMEvent.setDropAction(QT_PREPEND_NAMESPACE(qt_mac_dnd_answer_rec).lastAction); qDMEvent.accept(); QApplication::sendEvent(qwidget, &qDMEvent); @@ -339,12 +392,12 @@ extern "C" { - (BOOL)performDragOperation:(id <NSDraggingInfo>)sender { [self addDropData:sender]; - + NSPoint windowPoint = [sender draggingLocation]; NSPoint globalPoint = [[sender draggingDestinationWindow] convertBaseToScreen:windowPoint]; NSPoint localPoint = [self convertPoint:windowPoint fromView:nil]; QPoint posDrop(localPoint.x, localPoint.y); - + NSDragOperation nsActions = [sender draggingSourceOperationMask]; Qt::DropActions qtAllowed = qt_mac_mapNSDragOperations(nsActions); QMimeData *mimeData = dropData; @@ -356,6 +409,8 @@ extern "C" { if (QDragManager::self()->object) QDragManager::self()->dragPrivate()->target = qwidget; QApplication::sendEvent(qwidget, &de); + if (QDragManager::self()->object) + QDragManager::self()->dragPrivate()->executed_action = de.dropAction(); if (!de.isAccepted()) return NO; else @@ -365,6 +420,8 @@ extern "C" { - (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; + delete currentCustomTypes; + [self unregisterDraggedTypes]; [super dealloc]; } @@ -386,10 +443,9 @@ extern "C" { - (void) setFrameSize:(NSSize)newSize { [super setFrameSize:newSize]; - + // A change in size has required the view to be invalidated. - if ([self inLiveResize]) - { + if ([self inLiveResize]) { NSRect rects[4]; NSInteger count; [self getRectsExposedDuringLiveResize:rects count:&count]; @@ -397,9 +453,7 @@ extern "C" { { [self setNeedsDisplayInRect:rects[count]]; } - } - else - { + } else { [self setNeedsDisplay:YES]; } } @@ -534,7 +588,7 @@ extern "C" { if (!qAppInstance()->activeModalWidget() || QApplicationPrivate::tryModalHelper(qwidget, 0)) { QApplication::sendEvent(qwidget, &enterEvent); qt_mouseover = qwidget; - + // Update cursor and dispatch hover events. qt_mac_update_cursor_at_global_pos(flipPoint(globalPoint).toPoint()); if (qwidget->testAttribute(Qt::WA_Hover) && @@ -589,7 +643,7 @@ extern "C" { [viewsToLookAt addObject:qt_mac_nativeview_for(parentWidget)]; parentWidget = parentWidget->parentWidget(); } - + // Now walk through the subviews of each view and determine which subview should // get the event. We look through all the subviews at a given level with // the assumption that the last item to be found the candidate has a higher z-order. @@ -599,7 +653,7 @@ extern "C" { for (NSView *lookView in viewsToLookAt) { NSPoint tmpPoint = [lookView convertPoint:windowPoint fromView:nil]; for (NSView *view in [lookView subviews]) { - if (view == mouseView) + if (view == mouseView || [view isHidden]) continue; NSRect frameRect = [view frame]; if (NSMouseInRect(tmpPoint, [view frame], [view isFlipped])) @@ -618,7 +672,7 @@ extern "C" { NSPoint tmpPoint = [viewForDescent convertPoint:windowPoint fromView:nil]; // Apply same rule as above wrt z-order. for (NSView *view in [viewForDescent subviews]) { - if (NSMouseInRect(tmpPoint, [view frame], [view isFlipped])) + if (![view isHidden] && NSMouseInRect(tmpPoint, [view frame], [view isFlipped])) lowerView = view; } if (!lowerView) // Low as we can be at this point. @@ -725,7 +779,7 @@ extern "C" { if (currentIManager && [currentIManager wantsToHandleMouseEvents]) { [currentIManager handleMouseEvent:theEvent]; } - + NSPoint windowPoint = [theEvent locationInWindow]; NSPoint globalPoint = [[theEvent window] convertBaseToScreen:windowPoint]; NSPoint localPoint = [self convertPoint:windowPoint fromView:nil]; @@ -734,7 +788,7 @@ extern "C" { Qt::MouseButton buttons = cocoaButton2QtButton([theEvent buttonNumber]); bool wheelOK = false; Qt::KeyboardModifiers keyMods = qt_cocoaModifiers2QtModifiers([theEvent modifierFlags]); - + // Mouse wheel deltas seem to tick in at increments of 0.1. Qt widgets // expect the delta to be a multiple of 120. const int ScrollFactor = 10 * 120; @@ -756,20 +810,20 @@ extern "C" { wheelOK = qwe2.isAccepted(); } } - + if (deltaY) { QWheelEvent qwe(qlocal, qglobal, deltaY, buttons, keyMods, Qt::Vertical); qt_sendSpontaneousEvent(qwidget, &qwe); wheelOK = qwe.isAccepted(); - if (wheelOK && QApplicationPrivate::focus_widget + if (!wheelOK && QApplicationPrivate::focus_widget && QApplicationPrivate::focus_widget != qwidget) { QWheelEvent qwe2(QApplicationPrivate::focus_widget->mapFromGlobal(qglobal), qglobal, - deltaZ, buttons, keyMods, Qt::Vertical); + deltaY, buttons, keyMods, Qt::Vertical); qt_sendSpontaneousEvent(QApplicationPrivate::focus_widget, &qwe2); wheelOK = qwe2.isAccepted(); } } - + if (deltaZ) { // Qt doesn't explicitly support wheels with a Z component. In a misguided attempt to // try to be ahead of the pack, I'm adding this extra value. @@ -858,6 +912,11 @@ extern "C" { Q_UNUSED(anImage); Q_UNUSED(aPoint); qMacDnDParams()->performedAction = operation; + if (QDragManager::self()->object + && QDragManager::self()->dragPrivate()->executed_action != Qt::ActionMask) { + qMacDnDParams()->performedAction = + qt_mac_mapDropAction(QDragManager::self()->dragPrivate()->executed_action); + } } - (QWidget *)qt_qwidget @@ -887,15 +946,18 @@ extern "C" { QWidget *widgetToGetKey = qwidget; QWidget *popup = qAppInstance()->activePopupWidget(); - if (popup && popup != qwidget->window()) + bool sendToPopup = false; + if (popup && popup != qwidget->window()) { widgetToGetKey = popup->focusWidget() ? popup->focusWidget() : popup; + sendToPopup = true; + } if (widgetToGetKey->testAttribute(Qt::WA_InputMethodEnabled)) { [qt_mac_nativeview_for(widgetToGetKey) interpretKeyEvents:[NSArray arrayWithObject: theEvent]]; } if (sendKeyEvents && !composing) { bool keyOK = qt_dispatchKeyEvent(theEvent, widgetToGetKey); - if (!keyOK) + if (!keyOK && !sendToPopup) [super keyDown:theEvent]; } } @@ -910,6 +972,27 @@ extern "C" { } } +- (void)viewWillMoveToWindow:(NSWindow *)window +{ + if (qwidget->windowFlags() & Qt::MSWindowsOwnDC + && (window != [self window])) { // OpenGL Widget + // Create a stupid ClearDrawable Event + QEvent event(QEvent::MacGLClearDrawable); + qApp->sendEvent(qwidget, &event); + } +} + +- (void)viewDidMoveToWindow +{ + if (qwidget->windowFlags() & Qt::MSWindowsOwnDC && [self window]) { + // call update paint event + qwidgetprivate->needWindowChange = true; + QEvent event(QEvent::MacGLWindowChange); + qApp->sendEvent(qwidget, &event); + } +} + + // NSTextInput Protocol implementation - (void) insertText:(id)aString @@ -1147,13 +1230,13 @@ Qt::DropAction QDragManager::drag(QDrag *o) so we just bail early to prevent it */ if(!(GetCurrentEventButtonState() & kEventMouseButtonPrimary)) return Qt::IgnoreAction; - + if(object) { dragPrivate()->source->removeEventFilter(this); cancel(); beingCancelled = false; } - + object = o; dragPrivate()->target = 0; @@ -1165,7 +1248,7 @@ Qt::DropAction QDragManager::drag(QDrag *o) QMacPasteboard dragBoard((CFStringRef) NSDragPboard, QMacPasteboardMime::MIME_DND); dragPrivate()->data->setData(QLatin1String("application/x-qt-mime-type-name"), QByteArray()); dragBoard.setMimeData(dragPrivate()->data); - + // create the image QPoint hotspot; QPixmap pix = dragPrivate()->pixmap; @@ -1211,6 +1294,7 @@ Qt::DropAction QDragManager::drag(QDrag *o) NSSize mouseOffset = {0.0, 0.0}; NSPasteboard *pboard = [NSPasteboard pasteboardWithName:NSDragPboard]; NSPoint windowPoint = [dndParams->theEvent locationInWindow]; + dragPrivate()->executed_action = Qt::ActionMask; // do the drag [dndParams->view retain]; [dndParams->view dragImage:image @@ -1222,6 +1306,7 @@ Qt::DropAction QDragManager::drag(QDrag *o) slideBack:YES]; [dndParams->view release]; [image release]; + dragPrivate()->executed_action = Qt::IgnoreAction; object = 0; Qt::DropAction performedAction(qt_mac_mapNSDragOperation(dndParams->performedAction)); // do post drag processing, if required. diff --git a/src/gui/kernel/qcocoaview_mac_p.h b/src/gui/kernel/qcocoaview_mac_p.h index 9de94d5..983c762 100644 --- a/src/gui/kernel/qcocoaview_mac_p.h +++ b/src/gui/kernel/qcocoaview_mac_p.h @@ -83,6 +83,7 @@ Q_GUI_EXPORT bool composing; int composingLength; bool sendKeyEvents; + QStringList *currentCustomTypes; } - (id)initWithQWidget:(QWidget *)widget widgetPrivate:(QWidgetPrivate *)widgetprivate; - (void) finishInitWithQWidget:(QWidget *)widget widgetPrivate:(QWidgetPrivate *)widgetprivate; @@ -91,7 +92,7 @@ Q_GUI_EXPORT - (NSDragOperation)draggingUpdated:(id < NSDraggingInfo >)sender; - (void)draggingExited:(id < NSDraggingInfo >)sender; - (BOOL)performDragOperation:(id <NSDraggingInfo>)sender; -- (void)registerDragTypes:(bool)accept; +- (void)registerDragTypes; - (void)removeDropData; - (void)addDropData:(id <NSDraggingInfo>)sender; - (void)setSupportedActions:(NSDragOperation)actions; diff --git a/src/gui/kernel/qcocoawindow_mac.mm b/src/gui/kernel/qcocoawindow_mac.mm index 6b30444..89f481f 100644 --- a/src/gui/kernel/qcocoawindow_mac.mm +++ b/src/gui/kernel/qcocoawindow_mac.mm @@ -1,11 +1,11 @@ /**************************************************************************** - ** - ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). ** Contact: Qt Software Information (qt-info@nokia.com) - ** - ** This file is part of the QtGui module of the Qt Toolkit. - ** - ** $QT_BEGIN_LICENSE:LGPL$ +** +** 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 @@ -36,11 +36,11 @@ ** If you are unsure which license is appropriate for your use, please ** contact the sales department at qt-sales@nokia.com. ** $QT_END_LICENSE$ - ** - ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE - ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. - ** - ****************************************************************************/ +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +****************************************************************************/ #include "qmacdefines_mac.h" #ifdef QT_MAC_USE_COCOA @@ -53,9 +53,10 @@ #include <QtGui/QWidget> QT_FORWARD_DECLARE_CLASS(QWidget); -QT_USE_NAMESPACE - +QT_BEGIN_NAMESPACE extern Qt::MouseButton cocoaButton2QtButton(NSInteger buttonNum); // qcocoaview.mm +QT_END_NAMESPACE +QT_USE_NAMESPACE @implementation NSWindow (QT_MANGLE_NAMESPACE(QWidgetIntegration)) @@ -86,6 +87,12 @@ extern Qt::MouseButton cocoaButton2QtButton(NSInteger buttonNum); // qcocoaview. return YES; } +/*********************************************************************** + BEGIN Copy and Paste between QCocoaWindow and QCocoaPanel + This is a bit unfortunate, but thanks to the dynamic dispatch we + have to duplicate this code or resort to really silly forwarding methods +**************************************************************************/ + /* The methods keyDown, keyUp, and flagsChanged... These really shouldn't ever get hit. We automatically say we can be first responder if we are a window. @@ -124,7 +131,7 @@ extern Qt::MouseButton cocoaButton2QtButton(NSInteger buttonNum); // qcocoaview. [self retain]; QWidget *widget = [[QT_MANGLE_NAMESPACE(QCocoaWindowDelegate) sharedDelegate] qt_qwidgetForWindow:self]; - QCocoaView *view = static_cast<QCocoaView *>(qt_mac_nativeview_for(widget)); + QT_MANGLE_NAMESPACE(QCocoaView) *view = static_cast<QT_MANGLE_NAMESPACE(QCocoaView) *>(qt_mac_nativeview_for(widget)); Qt::MouseButton mouseButton = cocoaButton2QtButton([event buttonNumber]); // sometimes need to redirect mouse events to the popup. @@ -173,6 +180,20 @@ extern Qt::MouseButton cocoaButton2QtButton(NSInteger buttonNum); // qcocoaview. [self release]; } + +- (BOOL)makeFirstResponder:(NSResponder *)responder +{ + // For some reason Cocoa wants to flip the first responder + // when Qt doesn't want to, sorry, but "No" :-) + if (responder == nil && qApp->focusWidget()) + return NO; + return [super makeFirstResponder:responder]; +} + +/*********************************************************************** + END Copy and Paste between QCocoaWindow and QCocoaPanel +***********************************************************************/ + + (Class)frameViewClassForStyleMask:(NSUInteger)styleMask { if (styleMask & QtMacCustomizeWindow) diff --git a/src/gui/kernel/qcocoawindowdelegate_mac.mm b/src/gui/kernel/qcocoawindowdelegate_mac.mm index 8cd97b9..fa325f4 100644 --- a/src/gui/kernel/qcocoawindowdelegate_mac.mm +++ b/src/gui/kernel/qcocoawindowdelegate_mac.mm @@ -1,11 +1,11 @@ /**************************************************************************** - ** - ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). ** Contact: Qt Software Information (qt-info@nokia.com) - ** - ** This file is part of the QtGui module of the Qt Toolkit. - ** - ** $QT_BEGIN_LICENSE:LGPL$ +** +** 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 @@ -36,11 +36,11 @@ ** If you are unsure which license is appropriate for your use, please ** contact the sales department at qt-sales@nokia.com. ** $QT_END_LICENSE$ - ** - ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE - ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. - ** - ****************************************************************************/ +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +****************************************************************************/ #import "private/qcocoawindowdelegate_mac_p.h" #ifdef QT_MAC_USE_COCOA @@ -194,7 +194,6 @@ static void cleanupCocoaWindowDelegate() { NSWindow *window = [notification object]; QWidget *qwidget = m_windowHash->value(window); - // Just here to handle the is zoomed method. QWidgetData *widgetData = qt_qwidget_data(qwidget); if (!(qwidget->windowState() & (Qt::WindowMaximized | Qt::WindowFullScreen)) && [window isZoomed]) { widgetData->window_state = widgetData->window_state | Qt::WindowMaximized; @@ -202,7 +201,6 @@ static void cleanupCocoaWindowDelegate() & ~Qt::WindowMaximized)); qt_sendSpontaneousEvent(qwidget, &e); } - [self checkForMove:[window frame] forWidget:qwidget]; NSRect rect = [[window contentView] frame]; const QSize newSize(rect.size.width, rect.size.height); const QSize &oldSize = widgetData->crect.size(); @@ -212,12 +210,18 @@ static void cleanupCocoaWindowDelegate() } } -- (void)checkForMove:(const NSRect &)newRect forWidget:(QWidget *)qwidget +- (void)windowDidMove:(NSNotification *)notification { - // newRect's origin is bottom left. + // The code underneath needs to translate the window location + // from bottom left (which is the origin used by Cocoa) to + // upper left (which is the origin used by Qt): + NSWindow *window = [notification object]; + NSRect newRect = [window frame]; + QWidget *qwidget = m_windowHash->value(window); QPoint qtPoint = flipPoint(NSMakePoint(newRect.origin.x, newRect.origin.y + newRect.size.height)).toPoint(); const QRect &oldRect = qwidget->frameGeometry(); + if (qtPoint.x() != oldRect.x() || qtPoint.y() != oldRect.y()) { QWidgetData *widgetData = qt_qwidget_data(qwidget); QRect oldCRect = widgetData->crect; @@ -233,11 +237,6 @@ static void cleanupCocoaWindowDelegate() } } -- (void)windowDidMove:(NSNotification *)notification -{ - [self windowDidResize:notification]; -} - -(BOOL)windowShouldClose:(id)windowThatWantsToClose { QWidget *qwidget = m_windowHash->value(windowThatWantsToClose); @@ -266,18 +265,18 @@ static void cleanupCocoaWindowDelegate() -(void)windowDidBecomeMain:(NSNotification*)notification { - NSWindow *window = [notification object]; - if ([window isKeyWindow]) - return; // Should have already got an activate notification from "become key." - QWidget *qwidget = m_windowHash->value([notification object]); + Q_ASSERT(qwidget); + if (qwidget->isActiveWindow()) + return; // Widget is already active, no need to go through re-activation. + onApplicationWindowChangedActivation(qwidget, true); } -(void)windowDidResignMain:(NSNotification*)notification { QWidget *qwidget = m_windowHash->value([notification object]); - + Q_ASSERT(qwidget); onApplicationWindowChangedActivation(qwidget, false); } @@ -285,11 +284,11 @@ static void cleanupCocoaWindowDelegate() // tiny difference between main and key windows. -(void)windowDidBecomeKey:(NSNotification*)notification { - NSWindow *window = [notification object]; - if ([window isMainWindow]) - return; // Should have already got an activate notification from "become main." + QWidget *qwidget = m_windowHash->value([notification object]); + Q_ASSERT(qwidget); + if (qwidget->isActiveWindow()) + return; // Widget is already active, no need to go through re-activation - QWidget *qwidget = m_windowHash->value(window); onApplicationWindowChangedActivation(qwidget, true); } @@ -297,6 +296,7 @@ static void cleanupCocoaWindowDelegate() -(void)windowDidResignKey:(NSNotification*)notification { QWidget *qwidget = m_windowHash->value([notification object]); + Q_ASSERT(qwidget); onApplicationWindowChangedActivation(qwidget, false); } diff --git a/src/gui/kernel/qcursor.h b/src/gui/kernel/qcursor.h index 15b4597..ad1860d 100644 --- a/src/gui/kernel/qcursor.h +++ b/src/gui/kernel/qcursor.h @@ -77,6 +77,7 @@ class QBitmap; class QPixmap; #if defined(Q_WS_MAC) +void *nsCursorForQCursor(const QCursor &c); void qt_mac_set_cursor(const QCursor *c, const QPoint &p); #endif @@ -128,6 +129,7 @@ public: private: QCursorData *d; #if defined(Q_WS_MAC) + friend void *nsCursorForQCursor(const QCursor &c); friend void qt_mac_set_cursor(const QCursor *c, const QPoint &p); #endif }; diff --git a/src/gui/kernel/qcursor_mac.mm b/src/gui/kernel/qcursor_mac.mm index d632eb79..ae98f2e 100644 --- a/src/gui/kernel/qcursor_mac.mm +++ b/src/gui/kernel/qcursor_mac.mm @@ -95,9 +95,19 @@ protected: } }; +void *nsCursorForQCursor(const QCursor &c) +{ + c.d->update(); + return [[static_cast<NSCursor *>(c.d->curs.cp.nscursor) retain] autorelease]; +} + static QCursorData *currentCursor = 0; //current cursor void qt_mac_set_cursor(const QCursor *c, const QPoint &) { +#ifdef QT_MAC_USE_COCOA + Q_UNUSED(c); + return; +#else if (!c) { currentCursor = 0; return; @@ -128,10 +138,15 @@ void qt_mac_set_cursor(const QCursor *c, const QPoint &) } } currentCursor = c->d; +#endif } void qt_mac_update_cursor_at_global_pos(const QPoint &globalPos) { +#ifdef QT_MAC_USE_COCOA + Q_UNUSED(globalPos); + return; +#else QCursor cursor(Qt::ArrowCursor); if (QApplication::overrideCursor()) { cursor = *QApplication::overrideCursor(); @@ -144,6 +159,7 @@ void qt_mac_update_cursor_at_global_pos(const QPoint &globalPos) } } qt_mac_set_cursor(&cursor, globalPos); +#endif } void qt_mac_update_cursor() diff --git a/src/gui/kernel/qevent.cpp b/src/gui/kernel/qevent.cpp index 3f1df5e..2aed287 100644 --- a/src/gui/kernel/qevent.cpp +++ b/src/gui/kernel/qevent.cpp @@ -675,12 +675,13 @@ QWheelEvent::QWheelEvent(const QPoint &pos, const QPoint& globalPos, int delta, The \a type parameter must be QEvent::KeyPress, QEvent::KeyRelease, or QEvent::ShortcutOverride. - If \a key is 0, the event is not a result of - a known key; for example, it may be the result of a compose - sequence or keyboard macro. The \a modifiers holds the keyboard - modifiers, and the given \a text is the Unicode text that the - key generated. If \a autorep is true, isAutoRepeat() will be - true. \a count is the number of keys involved in the event. + Int \a key is the code for the Qt::Key that the event loop should listen + for. If \a key is 0, the event is not a result of a known key; for + example, it may be the result of a compose sequence or keyboard macro. + The \a modifiers holds the keyboard modifiers, and the given \a text + is the Unicode text that the key generated. If \a autorep is true, + isAutoRepeat() will be true. \a count is the number of keys involved + in the event. */ QKeyEvent::QKeyEvent(Type type, int key, Qt::KeyboardModifiers modifiers, const QString& text, bool autorep, ushort count) @@ -1656,7 +1657,7 @@ Qt::ButtonState QContextMenuEvent::state() const The variant contains a QLocale object specifying the language of a certain part of the preedit string. There should be at most one language set for every part of the preedit string. If several are - specified for any character in the string the behaviour is undefined. + specified for any character in the string the behavior is undefined. \value Ruby The ruby text for a part of the preedit string. There should be at diff --git a/src/gui/kernel/qlayout.cpp b/src/gui/kernel/qlayout.cpp index aa46249..4463aab 100644 --- a/src/gui/kernel/qlayout.cpp +++ b/src/gui/kernel/qlayout.cpp @@ -1028,8 +1028,13 @@ void QLayout::freeze(int w, int h) void QLayout::setMenuBar(QWidget *widget) { Q_D(QLayout); - if (widget) - addChildWidget(widget); + +#ifdef Q_OS_WINCE_WM + if (widget && widget->size().height() > 0) +#else + if (widget) +#endif + addChildWidget(widget); d->menubar = widget; } @@ -1239,7 +1244,7 @@ bool QLayout::activate() Must be implemented in subclasses to remove the layout item at \a index from the layout, and return the item. If there is no such item, the function must do nothing and return 0. Items are numbered - consecutively from 0. If an item is deleted, other items will be + consecutively from 0. If an item is removed, other items will be renumbered. The following code fragment shows a safe way to remove all items diff --git a/src/gui/kernel/qmacdefines_mac.h b/src/gui/kernel/qmacdefines_mac.h index 97ec544..035b8c5 100644 --- a/src/gui/kernel/qmacdefines_mac.h +++ b/src/gui/kernel/qmacdefines_mac.h @@ -105,7 +105,7 @@ Yes, it is an informative comment ;-) # undef qDebug #endif -#if __LP64__ +#ifdef __LP64__ typedef signed int OSStatus; #else typedef signed long OSStatus; diff --git a/src/gui/kernel/qshortcutmap.cpp b/src/gui/kernel/qshortcutmap.cpp index ed9654b..86894b4 100644 --- a/src/gui/kernel/qshortcutmap.cpp +++ b/src/gui/kernel/qshortcutmap.cpp @@ -753,6 +753,7 @@ bool QShortcutMap::correctGraphicsWidgetContext(Qt::ShortcutContext context, QGr tw = tw->parentWidget(); return tw == w; } + return false; } // Below is Qt::WindowShortcut context diff --git a/src/gui/kernel/qt_cocoa_helpers_mac.mm b/src/gui/kernel/qt_cocoa_helpers_mac.mm index 9c381b4..9165836 100644 --- a/src/gui/kernel/qt_cocoa_helpers_mac.mm +++ b/src/gui/kernel/qt_cocoa_helpers_mac.mm @@ -515,6 +515,18 @@ Qt::KeyboardModifiers qt_cocoaModifiers2QtModifiers(ulong modifierFlags) return qtMods; } +Qt::KeyboardModifiers qt_cocoaDragOperation2QtModifiers(uint dragOperations) +{ + Qt::KeyboardModifiers qtMods =Qt::NoModifier; + if (dragOperations & NSDragOperationLink) + qtMods |= Qt::MetaModifier; + if (dragOperations & NSDragOperationGeneric) + qtMods |= Qt::ControlModifier; + if (dragOperations & NSDragOperationCopy) + qtMods |= Qt::AltModifier; + return qtMods; +} + static inline QEvent::Type cocoaEvent2QtEvent(NSUInteger eventType) { // Handle the trivial cases that can be determined from the type. @@ -555,12 +567,15 @@ bool qt_dispatchKeyEventWithCocoa(void * /*NSEvent * */ keyEvent, QWidget *widge int keyLength = [keyChars length]; if (keyLength == 0) return false; // Dead Key, nothing to do! + bool ignoreText = false; Qt::Key qtKey = Qt::Key_unknown; if (keyLength == 1) { QChar ch([keyChars characterAtIndex:0]); if (ch.isLower()) ch = ch.toUpper(); qtKey = cocoaKey2QtKey(ch); + // Do not set the text for Function-Key Unicodes characters (0xF700–0xF8FF). + ignoreText = (ch.unicode() >= 0xF700 && ch.unicode() <= 0xF8FF); } Qt::KeyboardModifiers keyMods = qt_cocoaModifiers2QtModifiers([event modifierFlags]); QString text; @@ -568,7 +583,7 @@ bool qt_dispatchKeyEventWithCocoa(void * /*NSEvent * */ keyEvent, QWidget *widge // To quote from the Carbon port: This is actually wrong--but it is the best that // can be done for now because of the Control/Meta mapping issues // (we always get text on the Mac) - if (!(keyMods & (Qt::ControlModifier | Qt::MetaModifier))) + if (!ignoreText && !(keyMods & (Qt::ControlModifier | Qt::MetaModifier))) text = QCFString::toQString(reinterpret_cast<CFStringRef>(keyChars)); UInt32 macScanCode = 1; @@ -811,13 +826,28 @@ bool qt_mac_handleMouseEvent(void * /* NSView * */view, void * /* NSEvent * */ev QWidget *qwidget = [theView qt_qwidget]; QWidget *widgetToGetMouse = qwidget; QWidget *popup = qAppInstance()->activePopupWidget(); - if (popup && popup != qwidget->window()) - widgetToGetMouse = popup; NSView *tmpView = theView; - if (widgetToGetMouse != qwidget) { - tmpView = qt_mac_nativeview_for(widgetToGetMouse); + + if (popup && popup != qwidget->window()) { + widgetToGetMouse = popup; + tmpView = qt_mac_nativeview_for(popup); windowPoint = [[tmpView window] convertScreenToBase:globalPoint]; + + QPoint qWindowPoint(windowPoint.x, windowPoint.y); + if (widgetToGetMouse->rect().contains(qWindowPoint)) { + // Keeping the mouse pressed on a combobox button will make + // the popup pop in front of the mouse. But all mouse events + // will be sendt to the button. Since we want mouse events + // to be sendt to widgets inside the popup, we search for the + // widget in front of the mouse: + tmpView = [tmpView hitTest:windowPoint]; + if (!tmpView) + return false; + widgetToGetMouse = + [static_cast<QT_MANGLE_NAMESPACE(QCocoaView) *>(tmpView) qt_qwidget]; + } } + NSPoint localPoint = [tmpView convertPoint:windowPoint fromView:nil]; QPoint qlocalPoint(localPoint.x, localPoint.y); diff --git a/src/gui/kernel/qt_cocoa_helpers_mac_p.h b/src/gui/kernel/qt_cocoa_helpers_mac_p.h index ef55aa4..63a301c 100644 --- a/src/gui/kernel/qt_cocoa_helpers_mac_p.h +++ b/src/gui/kernel/qt_cocoa_helpers_mac_p.h @@ -141,6 +141,7 @@ inline QApplication *qAppInstance() { return static_cast<QApplication *>(QCoreAp struct ::TabletProximityRec; void qt_dispatchTabletProximityEvent(const ::TabletProximityRec &proxRec); Qt::KeyboardModifiers qt_cocoaModifiers2QtModifiers(ulong modifierFlags); +Qt::KeyboardModifiers qt_cocoaDragOperation2QtModifiers(uint dragOperations); inline int flipYCoordinate(int y) { return QApplication::desktop()->screenGeometry(0).height() - y; diff --git a/src/gui/kernel/qt_mac.cpp b/src/gui/kernel/qt_mac.cpp index b462b13..44e10a8 100644 --- a/src/gui/kernel/qt_mac.cpp +++ b/src/gui/kernel/qt_mac.cpp @@ -93,6 +93,8 @@ static QColor qcolorFromCGColor(CGColorRef cgcolor) pc.setRgbF(components[0], components[1], components[2], components[3]); } else if (model == kCGColorSpaceModelCMYK) { pc.setCmykF(components[0], components[1], components[2], components[3]); + } else if (model == kCGColorSpaceModelMonochrome) { + pc.setRgbF(components[0], components[0], components[0], components[1]); } else { // Colorspace we can't deal with. qWarning("Qt: qcolorFromCGColor: cannot convert from colorspace model: %d", model); @@ -129,16 +131,47 @@ QColor qcolorForTheme(ThemeBrush brush) QColor qcolorForThemeTextColor(ThemeTextColor themeColor) { -#ifndef QT_MAC_USE_COCOA +#ifdef Q_OS_MAC32 RGBColor c; GetThemeTextColor(themeColor, 32, true, &c); - return QColor(c.red / 265, c.green / 256, c.blue / 256); + QColor color = QColor(c.red / 265, c.green / 256, c.blue / 256); + return color; #else - QNativeImage nativeImage(16,16, QNativeImage::systemFormat()); - CGRect cgrect = CGRectMake(0, 0, 16, 16); - HIThemeSetTextFill(themeColor, 0, nativeImage.cg, kHIThemeOrientationNormal); - CGContextFillRect(nativeImage.cg, cgrect); - return QColor(nativeImage.image.pixel(0 , 0)); + // There is no equivalent to GetThemeTextColor in 64-bit and it was rather bad that + // I didn't file a request to implement this for Snow Leopard. So, in the meantime + // I've encoded the values from the GetThemeTextColor. This is not exactly ideal + // as if someone really wants to mess with themeing, these colors will be wrong. + // It also means that we need to make sure the values for differences between + // OS releases (and it will be likely that we are a step behind.) + switch (themeColor) { + case kThemeTextColorAlertActive: + case kThemeTextColorTabFrontActive: + case kThemeTextColorBevelButtonActive: + case kThemeTextColorListView: + case kThemeTextColorPlacardActive: + case kThemeTextColorPopupButtonActive: + case kThemeTextColorPopupLabelActive: + case kThemeTextColorPushButtonActive: + return Qt::black; + case kThemeTextColorAlertInactive: + case kThemeTextColorDialogInactive: + case kThemeTextColorPlacardInactive: + return QColor(67, 69, 69, 255); + case kThemeTextColorPopupButtonInactive: + case kThemeTextColorPopupLabelInactive: + case kThemeTextColorPushButtonInactive: + case kThemeTextColorTabFrontInactive: + case kThemeTextColorBevelButtonInactive: + return QColor(123, 127, 127, 255); + default: { + QNativeImage nativeImage(16,16, QNativeImage::systemFormat()); + CGRect cgrect = CGRectMake(0, 0, 16, 16); + HIThemeSetTextFill(themeColor, 0, nativeImage.cg, kHIThemeOrientationNormal); + CGContextFillRect(nativeImage.cg, cgrect); + QColor color = nativeImage.image.pixel(0,0); + return QColor(nativeImage.image.pixel(0 , 0)); + } + } #endif } QT_END_NAMESPACE diff --git a/src/gui/kernel/qt_mac_p.h b/src/gui/kernel/qt_mac_p.h index 3aec23f..ca995dc 100644 --- a/src/gui/kernel/qt_mac_p.h +++ b/src/gui/kernel/qt_mac_p.h @@ -233,6 +233,7 @@ extern QPaintDevice *qt_mac_safe_pdev; //qapplication_mac.cpp extern OSWindowRef qt_mac_window_for(const QWidget*); //qwidget_mac.mm extern OSViewRef qt_mac_nativeview_for(const QWidget *); //qwidget_mac.mm +extern QPoint qt_mac_nativeMapFromParent(const QWidget *child, const QPoint &pt); //qwidget_mac.mm #ifdef check # undef check @@ -249,11 +250,13 @@ struct QMacDndAnswerRecord { Qt::KeyboardModifiers modifiers; Qt::MouseButtons buttons; Qt::DropAction lastAction; + unsigned int lastOperation; void clear() { rect = QRect(); modifiers = Qt::NoModifier; buttons = Qt::NoButton; lastAction = Qt::IgnoreAction; + lastOperation = 0; } }; extern QMacDndAnswerRecord qt_mac_dnd_answer_rec; diff --git a/src/gui/kernel/qwidget.cpp b/src/gui/kernel/qwidget.cpp index 63d31b5..d911b48 100644 --- a/src/gui/kernel/qwidget.cpp +++ b/src/gui/kernel/qwidget.cpp @@ -66,6 +66,7 @@ #ifdef Q_WS_MAC # include "qt_mac_p.h" # include "qt_cocoa_helpers_mac_p.h" +# include "qmainwindow.h" #endif #if defined(Q_WS_QWS) # include "qwsdisplay_qws.h" @@ -164,6 +165,7 @@ static inline bool bypassGraphicsProxyWidget(QWidget *p) #endif extern bool qt_sendSpontaneousEvent(QObject*, QEvent*); // qapplication.cpp +extern QDesktopWidget *qt_desktopWidget; // qapplication.cpp QWidgetPrivate::QWidgetPrivate(int version) : QObjectPrivate(version), extra(0), focus_child(0) @@ -181,6 +183,7 @@ QWidgetPrivate::QWidgetPrivate(int version) : ,inDirtyList(0) ,isScrolled(0) ,isMoved(0) + ,usesDoubleBufferedGLContext(0) #ifdef Q_WS_WIN ,noPaintOnScreen(0) #endif @@ -234,28 +237,6 @@ QWindowSurface *QWidgetPrivate::createDefaultWindowSurface() /*! \internal - This is an internal function, you should never call this. - - This function is called to focus associated input context. The - code intends to eliminate duplicate focus for the context even if - the context is shared between widgets - - \sa QInputContext::setFocus() - */ -void QWidgetPrivate::focusInputContext() -{ -#ifndef QT_NO_IM - Q_Q(QWidget); - QInputContext *qic = q->inputContext(); - if (qic) { - if(qic->focusWidget() != q) - qic->setFocusWidget(q); - } -#endif // QT_NO_IM -} - -/*! - \internal */ void QWidgetPrivate::scrollChildren(int dx, int dy) { @@ -329,20 +310,24 @@ void QWidget::setInputContext(QInputContext *context) /*! + \obsolete + This function can be called on the widget that currently has focus to reset the input method operating on it. - \sa QInputContext, QInputContext::reset() + This function is providing for convenience, instead you should use + \l{QInputContext::}{reset()} on the input context that was + returned by inputContext(). + + \sa QInputContext, inputContext(), QInputContext::reset() */ void QWidget::resetInputContext() { if (!hasFocus()) return; #ifndef QT_NO_IM - if (!d_func()->ic) - return; QInputContext *qic = this->inputContext(); - if( qic ) + if(qic) qic->reset(); #endif // QT_NO_IM } @@ -1400,7 +1385,13 @@ int QWidgetPrivate::maxInstances = 0; // Maximum number of widget instances void QWidgetPrivate::setWinId(WId id) // set widget identifier { Q_Q(QWidget); - if (mapper && data.winid) { + // the user might create a widget with Qt::Desktop window + // attribute (or create another QDesktopWidget instance), which + // will have the same windowid (the root window id) as the + // qt_desktopWidget. We should not add the second desktop widget + // to the mapper. + bool userDesktopWidget = qt_desktopWidget != 0 && qt_desktopWidget != q && q->windowType() == Qt::Desktop; + if (mapper && data.winid && !userDesktopWidget) { mapper->remove(data.winid); uncreatedWidgets->insert(q); } @@ -1409,7 +1400,7 @@ void QWidgetPrivate::setWinId(WId id) // set widget identifier #if defined(Q_WS_X11) hd = id; // X11: hd == ident #endif - if (mapper && id) { + if (mapper && id && !userDesktopWidget) { mapper->insert(data.winid, q); uncreatedWidgets->remove(q); } @@ -2142,6 +2133,10 @@ QWidget *QWidget::find(WId id) If a widget is non-native (alien) and winId() is invoked on it, that widget will be provided a native handle. + On Mac OS X, the type returned depends on which framework Qt was linked + against. If Qt is using Carbon, the {WId} is actually an HIViewRef. If Qt + is using Cocoa, {WId} is a pointer to an NSView. + \note We recommend that you do not store this value as it is likely to change at run-time. @@ -2244,9 +2239,10 @@ WId QWidget::effectiveWinId() const The style sheet contains a textual description of customizations to the widget's style, as described in the \l{Qt Style Sheets} document. - \note Qt style sheets are currently not supported for QMacStyle - (the default style on Mac OS X). We plan to address this in some future - release. + Since Qt 4.5, Qt style sheets fully supports Mac OS X. + + \warning Qt style sheets are currently not supported for custom QStyle + subclasses. We plan to address this in some future release. \sa setStyle(), QApplication::styleSheet, {Qt Style Sheets} */ @@ -4653,6 +4649,8 @@ void QWidget::unsetCursor() */ /*! + \since 4.3 + Renders the \a sourceRegion of this widget into the \a target using \a renderFlags to determine how to render. Rendering starts at \a targetOffset in the \a target. For example: @@ -4662,12 +4660,13 @@ void QWidget::unsetCursor() If \a sourceRegion is a null region, this function will use QWidget::rect() as the region, i.e. the entire widget. - \bold{Note:} Make sure to call QPainter::end() for the given \a target's + Ensure that you call QPainter::end() for the \a target device's active painter (if any) before rendering. For example: \snippet doc/src/snippets/code/src_gui_kernel_qwidget.cpp 8 - \since 4.3 + \note To obtain the contents of an OpenGL widget, use QGLWidget::grabFrameBuffer() + or QGLWidget::renderPixmap() instead. */ void QWidget::render(QPaintDevice *target, const QPoint &targetOffset, const QRegion &sourceRegion, RenderFlags renderFlags) @@ -4715,10 +4714,13 @@ void QWidget::render(QPaintDevice *target, const QPoint &targetOffset, if (redirected) { target = redirected; offset -= redirectionOffset; - if (!inRenderWithPainter) { // Clip handled by shared painter (in qpainter.cpp). - const QRegion redirectedSystemClip = redirected->paintEngine()->systemClip(); - if (!redirectedSystemClip.isEmpty()) - paintRegion &= redirectedSystemClip.translated(-offset); + } + + if (!inRenderWithPainter) { // Clip handled by shared painter (in qpainter.cpp). + if (QPaintEngine *targetEngine = target->paintEngine()) { + const QRegion targetSystemClip = targetEngine->systemClip(); + if (!targetSystemClip.isEmpty()) + paintRegion &= targetSystemClip.translated(-offset); } } @@ -4803,7 +4805,7 @@ void QWidget::render(QPainter *painter, const QPoint &targetOffset, Q_ASSERT(engine); QPaintEnginePrivate *enginePriv = engine->d_func(); Q_ASSERT(enginePriv); - QPaintDevice *target = painter->worldMatrixEnabled() ? engine->paintDevice() : painter->device(); + QPaintDevice *target = engine->paintDevice(); Q_ASSERT(target); // Render via a pixmap when dealing with non-opaque painters or printers. @@ -4822,8 +4824,13 @@ void QWidget::render(QPainter *painter, const QPoint &targetOffset, const QRegion oldSystemClip = enginePriv->systemClip; const QRegion oldSystemViewport = enginePriv->systemViewport; - // This ensures that transformed system clips are inside the current system clip. - enginePriv->setSystemViewport(oldSystemClip); + // This ensures that all painting triggered by render() is clipped to the current engine clip. + if (painter->hasClipping()) { + const QRegion painterClip = painter->deviceTransform().map(painter->clipRegion()); + enginePriv->setSystemViewport(oldSystemClip.isEmpty() ? painterClip : oldSystemClip & painterClip); + } else { + enginePriv->setSystemViewport(oldSystemClip); + } render(target, targetOffset, toBePainted, renderFlags); @@ -5928,12 +5935,12 @@ bool QWidget::isActiveWindow() const return true; #endif if(style()->styleHint(QStyle::SH_Widget_ShareActivation, 0, this)) { - if(((tlw->windowType() == Qt::Dialog) || (tlw->windowType() == Qt::Tool)) && + if(tlw->windowType() == Qt::Tool && !tlw->isModal() && (!tlw->parentWidget() || tlw->parentWidget()->isActiveWindow())) return true; QWidget *w = qApp->activeWindow(); - while(w && ((tlw->windowType() == Qt::Dialog) || (tlw->windowType() == Qt::Tool)) && + while(w && tlw->windowType() == Qt::Tool && !w->isModal() && w->parentWidget()) { w = w->parentWidget()->window(); if(w == tlw) @@ -8974,17 +8981,36 @@ QWidget *QWidget::childAt(const QPoint &p) const QWidget *QWidgetPrivate::childAt_helper(const QPoint &p, bool ignoreChildrenInDestructor) const { Q_Q(const QWidget); - if (!q->rect().contains(p)) +#ifdef Q_WS_MAC + bool includeFrame = q->isWindow() && qobject_cast<const QMainWindow *>(q) + && static_cast<const QMainWindow *>(q)->unifiedTitleAndToolBarOnMac(); +#endif + + if ( +#ifdef Q_WS_MAC + !includeFrame && +#endif + !q->rect().contains(p)) return 0; + for (int i = children.size(); i > 0 ;) { --i; QWidget *w = qobject_cast<QWidget *>(children.at(i)); - if (w && !w->isWindow() && !w->isHidden() && w->geometry().contains(p)) { + if (w && !w->isWindow() && !w->isHidden() + && (w->geometry().contains(p) +#ifdef Q_WS_MAC + || (includeFrame && w->geometry().contains(qt_mac_nativeMapFromParent(w, p))) +#endif + )) { if (ignoreChildrenInDestructor && w->data->in_destructor) continue; if (w->testAttribute(Qt::WA_TransparentForMouseEvents)) continue; QPoint childPoint = w->mapFromParent(p); +#ifdef Q_WS_MAC + if (includeFrame && !w->geometry().contains(p)) + childPoint = qt_mac_nativeMapFromParent(w, p); +#endif if (QWidget *t = w->d_func()->childAt_helper(childPoint, ignoreChildrenInDestructor)) return t; // if WMouseNoMask is set the widget mask is ignored, if @@ -9425,11 +9451,13 @@ void QWidget::repaint(const QRect &rect) if (!isVisible() || !updatesEnabled() || rect.isEmpty()) return; - QTLWExtra *tlwExtra = !d->paintOnScreen() ? window()->d_func()->maybeTopData() : 0; - if (tlwExtra && !tlwExtra->inTopLevelResize && tlwExtra->backingStore) { - tlwExtra->inRepaint = true; - tlwExtra->backingStore->markDirty(rect, this, true); - tlwExtra->inRepaint = false; + if (hasBackingStoreSupport()) { + QTLWExtra *tlwExtra = window()->d_func()->maybeTopData(); + if (tlwExtra && !tlwExtra->inTopLevelResize && tlwExtra->backingStore) { + tlwExtra->inRepaint = true; + tlwExtra->backingStore->markDirty(rect, this, true); + tlwExtra->inRepaint = false; + } } else { d->repaint_sys(rect); } @@ -9452,11 +9480,13 @@ void QWidget::repaint(const QRegion &rgn) if (!isVisible() || !updatesEnabled() || rgn.isEmpty()) return; - QTLWExtra *tlwExtra = !d->paintOnScreen() ? window()->d_func()->maybeTopData() : 0; - if (tlwExtra && !tlwExtra->inTopLevelResize && tlwExtra->backingStore) { - tlwExtra->inRepaint = true; - tlwExtra->backingStore->markDirty(rgn, this, true); - tlwExtra->inRepaint = false; + if (hasBackingStoreSupport()) { + QTLWExtra *tlwExtra = window()->d_func()->maybeTopData(); + if (tlwExtra && !tlwExtra->inTopLevelResize && tlwExtra->backingStore) { + tlwExtra->inRepaint = true; + tlwExtra->backingStore->markDirty(rgn, this, true); + tlwExtra->inRepaint = false; + } } else { d->repaint_sys(rgn); } @@ -9638,7 +9668,7 @@ void QWidget::setAttribute(Qt::WidgetAttribute attribute, bool on) "QWidgetPrivate::high_attributes[] too small to contain all attributes in WidgetAttribute"); #ifdef Q_WS_WIN - if (attribute == Qt::WA_PaintOnScreen) { + if (attribute == Qt::WA_PaintOnScreen && on) { // see qwidget_win.cpp, ::paintEngine for details paintEngine(); if (d->noPaintOnScreen) @@ -9783,12 +9813,21 @@ void QWidget::setAttribute(Qt::WidgetAttribute attribute, bool on) } break; #endif - case Qt::WA_NativeWindow: + case Qt::WA_NativeWindow: { + QInputContext *ic = 0; + if (on && !internalWinId() && testAttribute(Qt::WA_InputMethodEnabled) && hasFocus()) { + ic = d->inputContext(); + ic->reset(); + ic->setFocusWidget(0); + } if (!qApp->testAttribute(Qt::AA_DontCreateNativeWidgetSiblings) && parentWidget()) parentWidget()->d_func()->enforceNativeChildren(); if (on && !internalWinId() && testAttribute(Qt::WA_WState_Created)) d->createWinId(); + if (ic) + ic->setFocusWidget(this); break; + } case Qt::WA_PaintOnScreen: d->updateIsOpaque(); #if defined(Q_WS_WIN) || defined(Q_WS_X11) @@ -11268,7 +11307,7 @@ QT_END_NAMESPACE currently the active one then it will not make it the active window. It will change the color of the taskbar entry to indicate that the window has changed in some way. This is because Microsoft - do not allow an application to interrupt what the user is currently + does not allow an application to interrupt what the user is currently doing in another application. \sa isActiveWindow(), window(), show() @@ -11393,3 +11432,17 @@ void QWidget::clearMask() setMask(QRegion()); } +/*! \fn const QX11Info &QWidget::x11Info() const + Returns information about the configuration of the X display used to display + the widget. + + \warning This function is only available on X11. +*/ + +/*! \fn Qt::HANDLE QWidget::x11PictureHandle() const + Returns the X11 Picture handle of the widget for XRender + support. Use of this function is not portable. This function will + return 0 if XRender support is not compiled into Qt, if the + XRender extension is not supported on the X11 display, or if the + handle could not be created. +*/ diff --git a/src/gui/kernel/qwidget_mac.mm b/src/gui/kernel/qwidget_mac.mm index 7cceb4f..b315eaf 100644 --- a/src/gui/kernel/qwidget_mac.mm +++ b/src/gui/kernel/qwidget_mac.mm @@ -295,9 +295,7 @@ bool qt_mac_is_macsheet(const QWidget *w) Qt::WindowModality modality = w->windowModality(); if (modality == Qt::ApplicationModal) return false; - if (modality == Qt::WindowModal || w->windowType() == Qt::Sheet) - return true; - return false; + return w->parentWidget() && (modality == Qt::WindowModal || w->windowType() == Qt::Sheet); } bool qt_mac_is_macdrawer(const QWidget *w) @@ -467,7 +465,18 @@ Q_GUI_EXPORT OSWindowRef qt_mac_window_for(const QWidget *w) if (hiview){ OSWindowRef window = qt_mac_window_for(hiview); if (!window && qt_isGenuineQWidget(hiview)) { - w->window()->d_func()->createWindow_sys(); + QWidget *myWindow = w->window(); + // This is a workaround for NSToolbar. When a widget is hidden + // by clicking the toolbar button, Cocoa reparents the widgets + // to another window (but Qt doesn't know about it). + // When we start showing them, it reparents back, + // but at this point it's window is nil, but the window it's being brought + // into (the Qt one) is for sure created. + // This stops the hierarchy moving under our feet. + if (myWindow != w && qt_mac_window_for(qt_mac_nativeview_for(myWindow))) + return qt_mac_window_for(qt_mac_nativeview_for(myWindow)); + + myWindow->d_func()->createWindow_sys(); // Reget the hiview since the "create window could potentially move the view (I guess). hiview = qt_mac_nativeview_for(w); window = qt_mac_window_for(hiview); @@ -2153,6 +2162,7 @@ void QWidgetPrivate::finishCreateWindow_sys_Carbon(OSWindowRef windowRef) setWindowModified_sys(q->isWindowModified()); updateFrameStrut(); qt_mac_update_sizer(q); + applyMaxAndMinSizeOnWindow(); } #else // QT_MAC_USE_COCOA void QWidgetPrivate::finishCreateWindow_sys_Cocoa(void * /*NSWindow * */ voidWindowRef) @@ -2174,11 +2184,13 @@ void QWidgetPrivate::finishCreateWindow_sys_Cocoa(void * /*NSWindow * */ voidWin if ((popup || type == Qt::Tool || type == Qt::ToolTip) && !q->isModal()) { [windowRef setHidesOnDeactivate:YES]; [windowRef setHasShadow:YES]; + } else { + [windowRef setHidesOnDeactivate:NO]; } + Q_UNUSED(parentWidget); Q_UNUSED(dialog); - // May need to do something the equivalent to ReshapeCustomWindow from Carbon here stuff, currently seems OK. data.fstrut_dirty = true; // when we create a toplevel widget, the frame strut should be dirty OSViewRef nsview = (OSViewRef)data.winid; OSViewRef window_contentview = qt_mac_get_contentview_for(windowRef); @@ -2236,6 +2248,7 @@ void QWidgetPrivate::finishCreateWindow_sys_Cocoa(void * /*NSWindow * */ voidWin syncCocoaMask(); macUpdateIsOpaque(); qt_mac_update_sizer(q); + applyMaxAndMinSizeOnWindow(); } #endif // QT_MAC_USE_COCOA @@ -2515,6 +2528,8 @@ void QWidgetPrivate::create_sys(WId window, bool initializeWindow, bool destroyO } updateIsOpaque(); + if (q->hasFocus()) + setFocus_sys(); if (!topLevel && initializeWindow) setWSGeometry(); @@ -2845,12 +2860,26 @@ void QWidgetPrivate::updateSystemBackground() void QWidgetPrivate::setCursor_sys(const QCursor &) { +#ifndef QT_MAC_USE_COCOA qt_mac_update_cursor(); +#else + Q_Q(QWidget); + if (q->testAttribute(Qt::WA_WState_Created)) { + [qt_mac_window_for(q) invalidateCursorRectsForView:qt_mac_nativeview_for(q)]; + } +#endif } void QWidgetPrivate::unsetCursor_sys() { +#ifndef QT_MAC_USE_COCOA qt_mac_update_cursor(); +#else + Q_Q(QWidget); + if (q->testAttribute(Qt::WA_WState_Created)) { + [qt_mac_window_for(q) invalidateCursorRectsForView:qt_mac_nativeview_for(q)]; + } +#endif } void QWidgetPrivate::setWindowTitle_sys(const QString &caption) @@ -3275,6 +3304,20 @@ void QWidgetPrivate::show_sys() qt_event_request_window_change(q); } + +QPoint qt_mac_nativeMapFromParent(const QWidget *child, const QPoint &pt) +{ +#ifndef QT_MAC_USE_COCOA + CGPoint nativePoint = CGPointMake(pt.x(), pt.y()); + HIViewConvertPoint(&nativePoint, qt_mac_nativeview_for(child->parentWidget()), + qt_mac_nativeview_for(child)); +#else + NSPoint nativePoint = [qt_mac_nativeview_for(child) convertPoint:NSMakePoint(pt.x(), pt.y()) fromView:qt_mac_nativeview_for(child->parentWidget())]; +#endif + return QPoint(nativePoint.x, nativePoint.y); +} + + void QWidgetPrivate::hide_sys() { Q_Q(QWidget); @@ -3556,7 +3599,10 @@ void QWidgetPrivate::raise_sys() #if QT_MAC_USE_COCOA QMacCocoaAutoReleasePool pool; if (isRealWindow()) { - [qt_mac_window_for(q) orderFront:qt_mac_window_for(q)]; + // Calling orderFront shows the window on Cocoa too. + if (!q->testAttribute(Qt::WA_DontShowOnScreen)) { + [qt_mac_window_for(q) orderFront:qt_mac_window_for(q)]; + } if (qt_mac_raise_process) { //we get to be the active process now ProcessSerialNumber psn; GetCurrentProcess(&psn); @@ -3957,6 +4003,53 @@ void QWidgetPrivate::setWSGeometry(bool dontShow, const QRect &oldRect) } } +void QWidgetPrivate::adjustWithinMaxAndMinSize(int &w, int &h) +{ + if (QWExtra *extra = extraData()) { + w = qMin(w, extra->maxw); + h = qMin(h, extra->maxh); + w = qMax(w, extra->minw); + h = qMax(h, extra->minh); + + // Deal with size increment + if (QTLWExtra *top = topData()) { + if(top->incw) { + w = w/top->incw; + w *= top->incw; + } + if(top->inch) { + h = h/top->inch; + h *= top->inch; + } + } + } + + if (isRealWindow()) { + w = qMax(0, w); + h = qMax(0, h); + } +} + +void QWidgetPrivate::applyMaxAndMinSizeOnWindow() +{ + Q_Q(QWidget); + const float max_f(20000); +#ifndef QT_MAC_USE_COCOA +#define SF(x) ((x > max_f) ? max_f : x) + HISize max = CGSizeMake(SF(extra->maxw), SF(extra->maxh)); + HISize min = CGSizeMake(SF(extra->minw), SF(extra->minh)); +#undef SF + SetWindowResizeLimits(qt_mac_window_for(q), &min, &max); +#else +#define SF(x) ((x > max_f) ? max_f : x) + NSSize max = NSMakeSize(SF(extra->maxw), SF(extra->maxh)); + NSSize min = NSMakeSize(SF(extra->minw), SF(extra->minh)); +#undef SF + [qt_mac_window_for(q) setMinSize:min]; + [qt_mac_window_for(q) setMaxSize:max]; +#endif +} + void QWidgetPrivate::setGeometry_sys(int x, int y, int w, int h, bool isMove) { Q_Q(QWidget); @@ -3967,12 +4060,19 @@ void QWidgetPrivate::setGeometry_sys(int x, int y, int w, int h, bool isMove) QMacCocoaAutoReleasePool pool; bool realWindow = isRealWindow(); - if (realWindow && !(w == 0 && h == 0) && !q->testAttribute(Qt::WA_DontShowOnScreen)) { - topData()->isSetGeometry = 1; - topData()->isMove = isMove; + + if (realWindow && !q->testAttribute(Qt::WA_DontShowOnScreen)){ + adjustWithinMaxAndMinSize(w, h); #ifndef QT_MAC_USE_COCOA - Rect r; SetRect(&r, x, y, x + w, y + h); - SetWindowBounds(qt_mac_window_for(q), kWindowContentRgn, &r); + if (w != 0 && h != 0) { + topData()->isSetGeometry = 1; + topData()->isMove = isMove; + Rect r; SetRect(&r, x, y, x + w, y + h); + SetWindowBounds(qt_mac_window_for(q), kWindowContentRgn, &r); + topData()->isSetGeometry = 0; + } else { + setGeometry_sys_helper(x, y, w, h, isMove); + } #else NSWindow *window = qt_mac_window_for(q); const QRect &fStrut = frameStrut(); @@ -3981,9 +4081,25 @@ void QWidgetPrivate::setGeometry_sys(int x, int y, int w, int h, bool isMove) fStrut.top() + fStrut.bottom() + h)); NSRect cocoaFrameRect = NSMakeRect(frameRect.x(), flipYCoordinate(frameRect.bottom() + 1), frameRect.width(), frameRect.height()); - [window setFrame:cocoaFrameRect display:NO]; + + QPoint currTopLeft = data.crect.topLeft(); + if (currTopLeft.x() == x && currTopLeft.y() == y + && cocoaFrameRect.size.width != 0 + && cocoaFrameRect.size.height != 0) { + [window setFrame:cocoaFrameRect display:NO]; + } else { + // The window is moved and resized (or resized to zero). + // Since Cocoa usually only sends us a resize callback after + // setting a window frame, we issue an explicit move as + // well. To stop Cocoa from optimize away the move (since the move + // would have the same origin as the setFrame call) we shift the + // window back and forth inbetween. + cocoaFrameRect.origin.y += 1; + [window setFrame:cocoaFrameRect display:NO]; + cocoaFrameRect.origin.y -= 1; + [window setFrameOrigin:cocoaFrameRect.origin]; + } #endif - topData()->isSetGeometry = 0; } else { setGeometry_sys_helper(x, y, w, h, isMove); } @@ -3993,74 +4109,34 @@ void QWidgetPrivate::setGeometry_sys_helper(int x, int y, int w, int h, bool isM { Q_Q(QWidget); bool realWindow = isRealWindow(); - if(QWExtra *extra = extraData()) { // any size restrictions? - if(realWindow) { - qt_mac_update_sizer(q); - if(q->windowFlags() & Qt::WindowMaximizeButtonHint) { -#ifndef QT_MAC_USE_COCOA - OSWindowRef window = qt_mac_window_for(q); - if(extra->maxw && extra->maxh && extra->maxw == extra->minw - && extra->maxh == extra->minh) { - ChangeWindowAttributes(window, kWindowNoAttributes, kWindowFullZoomAttribute); - } else { - ChangeWindowAttributes(window, kWindowFullZoomAttribute, kWindowNoAttributes); - } -#endif - } - } - - w = qMin(w,extra->maxw); - h = qMin(h,extra->maxh); - w = qMax(w,extra->minw); - h = qMax(h,extra->minh); - - // Deal with size increment - if(QTLWExtra *top = topData()) { - if(top->incw) { - w = w/top->incw; - w *= top->incw; - } - if(top->inch) { - h = h/top->inch; - h *= top->inch; - } - } - } - - if (realWindow) { - w = qMax(0, w); - h = qMax(0, h); - } QPoint oldp = q->pos(); QSize olds = q->size(); const bool isResize = (olds != QSize(w, h)); - if(!realWindow && !isResize && QPoint(x, y) == oldp) + + if (!realWindow && !isResize && QPoint(x, y) == oldp) return; - if(isResize && q->isMaximized()) + + if (isResize) data.window_state = data.window_state & ~Qt::WindowMaximized; + const bool visible = q->isVisible(); data.crect = QRect(x, y, w, h); - if(realWindow) { - if(QWExtra *extra = extraData()) { //set constraints - const float max_f(20000); + if (realWindow) { + adjustWithinMaxAndMinSize(w, h); + qt_mac_update_sizer(q); + #ifndef QT_MAC_USE_COCOA -#define SF(x) ((x > max_f) ? max_f : x) - HISize max = CGSizeMake(SF(extra->maxw), SF(extra->maxh)); - HISize min = CGSizeMake(SF(extra->minw), SF(extra->minh)); -#undef SF - SetWindowResizeLimits(qt_mac_window_for(q), &min, &max); -#else -#define SF(x) ((x > max_f) ? max_f : x) - NSSize max = NSMakeSize(SF(extra->maxw), SF(extra->maxh)); - NSSize min = NSMakeSize(SF(extra->minw), SF(extra->minh)); -#undef SF - [qt_mac_window_for(q) setMinSize:min]; - [qt_mac_window_for(q) setMaxSize:max]; -#endif + if (q->windowFlags() & Qt::WindowMaximizeButtonHint) { + OSWindowRef window = qt_mac_window_for(q); + if (extra->maxw && extra->maxh && extra->maxw == extra->minw + && extra->maxh == extra->minh) { + ChangeWindowAttributes(window, kWindowNoAttributes, kWindowFullZoomAttribute); + } else { + ChangeWindowAttributes(window, kWindowFullZoomAttribute, kWindowNoAttributes); + } } -#ifndef QT_MAC_USE_COCOA HIRect bounds = CGRectMake(0, 0, w, h); HIViewSetFrame(qt_mac_nativeview_for(q), &bounds); #else @@ -4106,6 +4182,7 @@ void QWidgetPrivate::setGeometry_sys_helper(int x, int y, int w, int h, bool isM void QWidgetPrivate::setConstraints_sys() { updateMaximizeButton_sys(); + applyMaxAndMinSizeOnWindow(); } void QWidgetPrivate::updateMaximizeButton_sys() @@ -4420,8 +4497,8 @@ void QWidgetPrivate::registerDropSite(bool on) SetControlDragTrackingEnabled(qt_mac_nativeview_for(q), on); #else NSView *view = qt_mac_nativeview_for(q); - if ([view isKindOfClass:[QT_MANGLE_NAMESPACE(QCocoaView) class]]) { - [static_cast<QT_MANGLE_NAMESPACE(QCocoaView) *>(view) registerDragTypes:on]; + if (on && [view isKindOfClass:[QT_MANGLE_NAMESPACE(QCocoaView) class]]) { + [static_cast<QT_MANGLE_NAMESPACE(QCocoaView) *>(view) registerDragTypes]; } #endif } @@ -4579,12 +4656,15 @@ void QWidgetPrivate::setModal_sys() OSWindowRef windowRef = qt_mac_window_for(q); #ifdef QT_MAC_USE_COCOA - bool windowIsSheet = [windowRef styleMask] & NSDocModalWindowMask; + bool alreadySheet = [windowRef styleMask] & NSDocModalWindowMask; - if (q->windowModality() == Qt::WindowModal){ + if (windowParent && q->windowModality() == Qt::WindowModal){ // Window should be window-modal, which implies a sheet. - if (!windowIsSheet) + if (!alreadySheet) { + // NB: the following call will call setModal_sys recursivly: recreateMacWindow(); + windowRef = qt_mac_window_for(q); + } if ([windowRef isKindOfClass:[NSPanel class]]){ // If the primary window of the sheet parent is a child of a modal dialog, // the sheet parent should not be modally shaddowed. @@ -4597,7 +4677,7 @@ void QWidgetPrivate::setModal_sys() } } else { // Window shold not be window-modal, and as such, not a sheet. - if (windowIsSheet){ + if (alreadySheet){ // NB: the following call will call setModal_sys recursivly: recreateMacWindow(); windowRef = qt_mac_window_for(q); @@ -4612,6 +4692,7 @@ void QWidgetPrivate::setModal_sys() if ([windowRef isKindOfClass:[NSPanel class]]) [static_cast<NSPanel *>(windowRef) setWorksWhenModal:YES]; } else { + // INVARIANT: q should not be modal. NSInteger winLevel = -1; if (q->windowType() == Qt::Popup) { winLevel = NSPopUpMenuWindowLevel; @@ -4622,9 +4703,10 @@ void QWidgetPrivate::setModal_sys() } } else if (q->windowType() == Qt::Tool) { winLevel = NSFloatingWindowLevel; + } else if (q->windowType() == Qt::Dialog) { + winLevel = NSModalPanelWindowLevel; } - // StayOnTop window should appear above Tool windows. if (data.window_flags & Qt::WindowStaysOnTopHint) winLevel = NSPopUpMenuWindowLevel; diff --git a/src/gui/kernel/qwidget_p.h b/src/gui/kernel/qwidget_p.h index f254c4a..2461820 100644 --- a/src/gui/kernel/qwidget_p.h +++ b/src/gui/kernel/qwidget_p.h @@ -257,6 +257,8 @@ public: void macUpdateIsOpaque(); void setEnabled_helper_sys(bool enable); bool isRealWindow() const; + void adjustWithinMaxAndMinSize(int &w, int &h); + void applyMaxAndMinSizeOnWindow(); #endif void raise_sys(); @@ -354,8 +356,6 @@ public: void setWindowIcon_sys(bool forceReset = false); void setWindowOpacity_sys(qreal opacity); - void focusInputContext(); - void adjustQuitOnCloseAttribute(); #if defined(Q_WS_X11) @@ -537,6 +537,7 @@ public: uint inDirtyList : 1; uint isScrolled : 1; uint isMoved : 1; + uint usesDoubleBufferedGLContext : 1; #ifdef Q_WS_WIN uint noPaintOnScreen : 1; // see qwidget_win.cpp ::paintEngine() diff --git a/src/gui/kernel/qwidget_win.cpp b/src/gui/kernel/qwidget_win.cpp index 228ef7c..ffbb341 100644 --- a/src/gui/kernel/qwidget_win.cpp +++ b/src/gui/kernel/qwidget_win.cpp @@ -1037,6 +1037,8 @@ void QWidget::setWindowState(Qt::WindowStates newstate) #else UINT style = WS_POPUP; #endif + if (d->topData()->savedFlags & WS_SYSMENU) + style |= WS_SYSMENU; if (isVisible()) style |= WS_VISIBLE; SetWindowLongA(internalWinId(), GWL_STYLE, style); diff --git a/src/gui/kernel/qwidget_x11.cpp b/src/gui/kernel/qwidget_x11.cpp index a12b50c..6202b35 100644 --- a/src/gui/kernel/qwidget_x11.cpp +++ b/src/gui/kernel/qwidget_x11.cpp @@ -898,7 +898,7 @@ void QWidgetPrivate::x11UpdateIsOpaque() bool visible = q->isVisible(); if (visible) q->hide(); - q->setParent(q->parentWidget(), q->windowFlags() & ~Qt::WindowType_Mask); + q->setParent(q->parentWidget(), q->windowFlags()); q->move(pos); if (visible) q->show(); @@ -1516,7 +1516,6 @@ void QWidget::activateWindow() X11->userTime = X11->time; qt_net_update_user_time(tlw, X11->userTime); XSetInputFocus(X11->display, tlw->internalWinId(), XRevertToParent, X11->time); - d->focusInputContext(); } } @@ -1751,8 +1750,8 @@ void QWidgetPrivate::show_sys() mwmhints.functions &= ~MWM_FUNC_RESIZE; } - mwmhints.flags |= MWM_HINTS_DECORATIONS; if (mwmhints.decorations == MWM_DECOR_ALL) { + mwmhints.flags |= MWM_HINTS_DECORATIONS; mwmhints.decorations = (MWM_DECOR_BORDER | MWM_DECOR_TITLE | MWM_DECOR_MENU); @@ -1761,10 +1760,12 @@ void QWidgetPrivate::show_sys() } if (q->windowFlags() & Qt::WindowMinimizeButtonHint) { + mwmhints.flags |= MWM_HINTS_DECORATIONS; mwmhints.decorations |= MWM_DECOR_MINIMIZE; mwmhints.functions |= MWM_FUNC_MINIMIZE; } if (q->windowFlags() & Qt::WindowMaximizeButtonHint) { + mwmhints.flags |= MWM_HINTS_DECORATIONS; mwmhints.decorations |= MWM_DECOR_MAXIMIZE; mwmhints.functions |= MWM_FUNC_MAXIMIZE; } @@ -2746,12 +2747,6 @@ void QWidgetPrivate::setWindowOpacity_sys(qreal opacity) 32, PropModeReplace, (uchar*)&value, 1); } -/*! - Returns information about the configuration of the X display used to display - the widget. - - \warning This function is only available on X11. -*/ const QX11Info &QWidget::x11Info() const { Q_D(const QWidget); @@ -2788,13 +2783,6 @@ QWindowSurface *QWidgetPrivate::createDefaultWindowSurface_sys() return new QX11WindowSurface(q_func()); } -/*! - Returns the X11 Picture handle of the widget for XRender - support. Use of this function is not portable. This function will - return 0 if XRender support is not compiled into Qt, if the - XRender extension is not supported on the X11 display, or if the - handle could not be created. -*/ Qt::HANDLE QWidget::x11PictureHandle() const { #ifndef QT_NO_XRENDER diff --git a/src/gui/kernel/qx11embed_x11.cpp b/src/gui/kernel/qx11embed_x11.cpp index e49c4d6..6329135 100644 --- a/src/gui/kernel/qx11embed_x11.cpp +++ b/src/gui/kernel/qx11embed_x11.cpp @@ -481,7 +481,7 @@ QX11EmbedWidget::QX11EmbedWidget(QWidget *parent) | ExposureMask | StructureNotifyMask | SubstructureNotifyMask | PropertyChangeMask); - unsigned int data[] = {XEMBED_VERSION, XEMBED_MAPPED}; + long data[] = {XEMBED_VERSION, XEMBED_MAPPED}; XChangeProperty(x11Info().display(), internalWinId(), ATOM(_XEMBED_INFO), ATOM(_XEMBED_INFO), 32, PropModeReplace, (unsigned char*) data, 2); @@ -1571,7 +1571,7 @@ void QX11EmbedContainer::showEvent(QShowEvent *) { Q_D(QX11EmbedContainer); if (d->client) { - unsigned int data[] = {XEMBED_VERSION, XEMBED_MAPPED}; + long data[] = {XEMBED_VERSION, XEMBED_MAPPED}; XChangeProperty(x11Info().display(), d->client, ATOM(_XEMBED_INFO), ATOM(_XEMBED_INFO), 32, PropModeReplace, (unsigned char *) data, 2); } @@ -1587,8 +1587,7 @@ void QX11EmbedContainer::hideEvent(QHideEvent *) { Q_D(QX11EmbedContainer); if (d->client) { - unsigned int data[] = {XEMBED_VERSION, XEMBED_MAPPED}; - + long data[] = {XEMBED_VERSION, XEMBED_MAPPED}; XChangeProperty(x11Info().display(), d->client, ATOM(_XEMBED_INFO), ATOM(_XEMBED_INFO), 32, PropModeReplace, (unsigned char *) data, 2); } diff --git a/src/gui/painting/qbackingstore.cpp b/src/gui/painting/qbackingstore.cpp index fbac811a..0a3a8dd 100644 --- a/src/gui/painting/qbackingstore.cpp +++ b/src/gui/painting/qbackingstore.cpp @@ -492,7 +492,8 @@ static inline void sendUpdateRequest(QWidget *widget, bool updateImmediately) return; #if defined(Q_WS_WIN) && !defined(Q_OS_WINCE) - if (QApplicationPrivate::inSizeMove && widget->internalWinId() && !updateImmediately) { + if (QApplicationPrivate::inSizeMove && widget->internalWinId() && !updateImmediately + && !widget->testAttribute(Qt::WA_DontShowOnScreen)) { // Tell Windows to send us a paint event if we're in WM_SIZE/WM_MOVE; posted events // are blocked until the mouse button is released. See task 146849. const QRegion rgn(qt_dirtyRegion(widget)); @@ -1510,6 +1511,9 @@ void QWidgetPrivate::invalidateBuffer(const QRect &rect) void QWidgetPrivate::repaint_sys(const QRegion &rgn) { + if (data.in_destructor) + return; + Q_Q(QWidget); if (q->testAttribute(Qt::WA_StaticContents)) { if (!extra) @@ -1517,13 +1521,20 @@ void QWidgetPrivate::repaint_sys(const QRegion &rgn) extra->staticContentsSize = data.crect.size(); } + QPaintEngine *engine = q->paintEngine(); + // QGLWidget does not support partial updates if: + // 1) The context is double buffered + // 2) The context is single buffered and auto-fill background is enabled. + const bool noPartialUpdateSupport = (engine && engine->type() == QPaintEngine::OpenGL) + && (usesDoubleBufferedGLContext || q->autoFillBackground()); + QRegion toBePainted(noPartialUpdateSupport ? q->rect() : rgn); + #ifdef Q_WS_MAC // No difference between update() and repaint() on the Mac. - update_sys(rgn); + update_sys(toBePainted); return; #endif - QRegion toBePainted(rgn); toBePainted &= clipRect(); clipToEffectiveMask(toBePainted); if (toBePainted.isEmpty()) diff --git a/src/gui/painting/qblendfunctions.cpp b/src/gui/painting/qblendfunctions.cpp index cf73eb7..93f11e1 100644 --- a/src/gui/painting/qblendfunctions.cpp +++ b/src/gui/painting/qblendfunctions.cpp @@ -44,21 +44,6 @@ QT_BEGIN_NAMESPACE - -// This ifdef is made with the best of intention. GCC fails to -// optimzie the code properly so the bytemul approach is the fastest -// it gets. Both on ARM and on MSVC the code is optimized to be better -// than the bytemul approach... On the other hand... This code is -// almost never run on i386 so it may be downright silly to have this -// piece of code here... -#if defined (Q_CC_GNU) && (defined (QT_ARCH_I386) || defined (QT_ARCH_X86_64)) -# define QT_BLEND_USE_BYTEMUL -#endif - -// #define QT_DEBUG_DRAW - -static const qreal aliasedCoordinateDelta = 0.5 - 0.015625; - struct SourceOnlyAlpha { inline uchar alpha(uchar src) const { return src; } @@ -158,8 +143,6 @@ void qt_scale_image_16bit(uchar *destPixels, int dbpl, const QRect &clip, T blender) { - - qreal sx = targetRect.width() / (qreal) srcRect.width(); qreal sy = targetRect.height() / (qreal) srcRect.height(); @@ -177,10 +160,10 @@ void qt_scale_image_16bit(uchar *destPixels, int dbpl, int cy1 = clip.top(); int cy2 = clip.y() + clip.height(); - int tx1 = qFloor(targetRect.left() + aliasedCoordinateDelta); - int tx2 = qFloor(targetRect.right() + aliasedCoordinateDelta); - int ty1 = qFloor(targetRect.top() + aliasedCoordinateDelta); - int ty2 = qFloor(targetRect.bottom() + aliasedCoordinateDelta); + int tx1 = qRound(targetRect.left()); + int tx2 = qRound(targetRect.right()); + int ty1 = qRound(targetRect.top()); + int ty2 = qRound(targetRect.bottom()); if (tx2 < tx1) qSwap(tx2, tx1); @@ -285,7 +268,7 @@ static void qt_blend_rgb16_on_rgb16(uchar *dst, int dbpl, int const_alpha) { #ifdef QT_DEBUG_DRAW - printf("qt_blend_argb16_on_rgb16: dst=(%p, %d), src=(%p, %d), dim=(%d, %d) alpha=%d\n", + printf("qt_blend_rgb16_on_rgb16: dst=(%p, %d), src=(%p, %d), dim=(%d, %d) alpha=%d\n", dst, dbpl, src, sbpl, w, h, const_alpha); #endif @@ -346,11 +329,6 @@ template <typename T> void qt_blend_argb24_on_rgb16(uchar *destPixels, int dbpl, if (alpha == 255) { *dst = spix; } else if (alpha != 0) { -#ifdef QT_BLEND_USE_BYTEMUL - // truncate green channel to avoid overflow - *dst = (alphaFunc.bytemul(spix) & 0xffdf) - + (quint16) qrgb565(*dst).byte_mul(qrgb565::ialpha(alpha)); -#else quint16 dpix = *dst; quint32 sia = 255 - alpha; @@ -362,12 +340,11 @@ template <typename T> void qt_blend_argb24_on_rgb16(uchar *destPixels, int dbpl, quint32 siag = dg * sia; quint32 siab = db * sia; - quint32 rr = ((siar + (siar>>8) + (0x80 << 11)) >> 8) & 0xf800; - quint32 rg = ((siag + (siag>>8) + (0x80 << 5)) >> 8) & 0x07e0; - quint32 rb = ((siab + (siab>>8) + (0x80 >> 3)) >> 8); + quint32 rr = ((siar + (siar>>8) + (0x80 << 8)) >> 8) & 0xf800; + quint32 rg = ((siag + (siag>>8) + (0x80 << 3)) >> 8) & 0x07e0; + quint32 rb = ((siab + (siab>>8) + (0x80 >> 3)) >> 8) & 0x001f; *dst = alphaFunc.bytemul(spix) + rr + rg + rb; -#endif } ++dst; @@ -434,111 +411,45 @@ static void qt_blend_argb32_on_rgb16(uchar *destPixels, int dbpl, } quint16 *dst = (quint16 *) destPixels; - int dstExtraStride = dbpl / 2 - w; - - const quint32 *src = (const quint32 *) srcPixels; - int srcExtraStride = sbpl / 4 - w; + quint32 *src = (quint32 *) srcPixels; for (int y=0; y<h; ++y) { - int length = w; - const int dstAlign = ((quintptr)dst) & 0x3; - if (dstAlign) { - const quint8 alpha = qAlpha(*src); - if (alpha) { - quint16 s = convert_argb32_to_rgb16(*src); - if (alpha < 255) - s += BYTE_MUL_RGB16(*dst, 255 - alpha); - *dst = s; - } - ++dst; - ++src; - --length; - } + for (int x=0; x<w; ++x) { - const int length32 = length >> 1; - const int srcAlign = ((quintptr)src) & 0x3; - if (length32) { - if (srcAlign) { - for (int i = 0; i < length32; ++i) { - quint32 *dest32 = reinterpret_cast<quint32*>(dst); - const quint8 a1 = qAlpha(src[0]); - const quint8 a2 = qAlpha(src[1]); - quint32 s; - - if (!a1 && !a2) { - src += 2; - dst +=2; - continue; - } - - s = convert_argb32_to_rgb16(src[0]) - | (convert_argb32_to_rgb16(src[1]) << 16); - - if (a1 == a2) { - if (a1 < 255) { - const quint8 sa = ((255 - a1)+1) >> 3; - s += BYTE_MUL_RGB16_32(*dest32, sa); - } - } else { - if (a1 < 255) - s += BYTE_MUL_RGB16(dst[0], 255 - a1); - if (a2 < 255) - s += BYTE_MUL_RGB16(dst[1], 255 - a2) << 16; - } - - *dest32 = s; - src += 2; - dst += 2; - } - } else { - for (int i = 0; i < length32; ++i) { - quint32 *dest32 = reinterpret_cast<quint32*>(dst); - const quint8 a1 = qAlpha(src[0]); - const quint8 a2 = qAlpha(src[1]); - quint32 s; - - if (!a1 && !a2) { - src += 2; - dst +=2; - continue; - } - - const quint64 *src64 = - reinterpret_cast<const quint64*>(src); - s = qConvertRgb32To16x2(*src64); - - if (a1 == a2) { - if (a1 < 255) { - const quint8 sa = ((255 - a1)+1) >> 3; - s += BYTE_MUL_RGB16_32(*dest32, sa); - } - } else { - if (a1 < 255) - s += BYTE_MUL_RGB16(dst[0], 255 - a1); - if (a2 < 255) - s += BYTE_MUL_RGB16(dst[1], 255 - a2) << 16; - } - - *dest32 = s; - src += 2; - dst += 2; - } - } - } - const int tail = length & 0x1; - if (tail) { - const quint8 alpha = qAlpha(*src); - if (alpha) { - quint16 s = convert_argb32_to_rgb16(*src); - if (alpha < 255) - s += BYTE_MUL_RGB16(*dst, 255 - alpha); - *dst = s; + quint32 spix = src[x]; + quint32 alpha = spix >> 24; + + if (alpha == 255) { + dst[x] = convert_argb32_to_rgb16(spix); + } else if (alpha != 0) { + quint32 dpix = dst[x]; + + quint32 sia = 255 - alpha; + + quint32 sr = (spix >> 8) & 0xf800; + quint32 sg = (spix >> 5) & 0x07e0; + quint32 sb = (spix >> 3) & 0x001f; + + quint32 dr = (dpix & 0x0000f800); + quint32 dg = (dpix & 0x000007e0); + quint32 db = (dpix & 0x0000001f); + + quint32 siar = dr * sia; + quint32 siag = dg * sia; + quint32 siab = db * sia; + + quint32 rr = sr + ((siar + (siar>>8) + (0x80 << 8)) >> 8); + quint32 rg = sg + ((siag + (siag>>8) + (0x80 << 3)) >> 8); + quint32 rb = sb + ((siab + (siab>>8) + (0x80 >> 3)) >> 8); + + dst[x] = (rr & 0xf800) + | (rg & 0x07e0) + | (rb); } } - dst += dstExtraStride; - src += srcExtraStride; + dst = (quint16 *) (((uchar *) dst) + dbpl); + src = (quint32 *) (((uchar *) src) + sbpl); } - } @@ -724,10 +635,10 @@ template <typename T> void qt_scale_image_32bit(uchar *destPixels, int dbpl, int cy1 = clip.top(); int cy2 = clip.y() + clip.height(); - int tx1 = qFloor(targetRect.left() + aliasedCoordinateDelta); - int tx2 = qFloor(targetRect.right() + aliasedCoordinateDelta); - int ty1 = qFloor(targetRect.top() + aliasedCoordinateDelta); - int ty2 = qFloor(targetRect.bottom() + aliasedCoordinateDelta); + int tx1 = qRound(targetRect.left()); + int tx2 = qRound(targetRect.right()); + int ty1 = qRound(targetRect.top()); + int ty2 = qRound(targetRect.bottom()); if (tx2 < tx1) qSwap(tx2, tx1); diff --git a/src/gui/painting/qcolor.cpp b/src/gui/painting/qcolor.cpp index d44e2a6..5d7d4ab 100644 --- a/src/gui/painting/qcolor.cpp +++ b/src/gui/painting/qcolor.cpp @@ -526,7 +526,6 @@ void QColor::setNamedColor(const QString &name) if (qt_get_hex_rgb(name.constData(), name.length(), &rgb)) { setRgb(rgb); } else { - qWarning("QColor::setNamedColor: Could not parse color '%s'", name.toLatin1().constData()); invalidate(); } return; diff --git a/src/gui/painting/qcolormap_win.cpp b/src/gui/painting/qcolormap_win.cpp index d61b933..7d36582 100644 --- a/src/gui/painting/qcolormap_win.cpp +++ b/src/gui/painting/qcolormap_win.cpp @@ -138,7 +138,11 @@ void QColormap::cleanup() } QColormap QColormap::instance(int) -{ return QColormap(); } +{ + Q_ASSERT_X(screenMap, "QColormap", + "A QApplication object needs to be constructed before QColormap is used."); + return QColormap(); +} QColormap::QColormap() : d(screenMap) diff --git a/src/gui/painting/qdrawhelper.cpp b/src/gui/painting/qdrawhelper.cpp index 018aff5..35d0b52 100644 --- a/src/gui/painting/qdrawhelper.cpp +++ b/src/gui/painting/qdrawhelper.cpp @@ -370,7 +370,7 @@ Q_STATIC_TEMPLATE_FUNCTION void QT_FASTCALL destStore(QRasterBuffer *rasterBuffe Q_TEMPLATE_FIX(DST)) { DST *dest = reinterpret_cast<DST*>(rasterBuffer->scanLine(y)) + x; - const quint32 *src = reinterpret_cast<const quint32*>(buffer); + const quint32p *src = reinterpret_cast<const quint32p*>(buffer); while (length--) *dest++ = DST(*src++); } @@ -2400,8 +2400,7 @@ static inline int color_burn_op(int dst, int src, int da, int sa) if (src == 0 || src_da + dst_sa <= sa_da) return qt_div_255(temp); - else - return qt_div_255(sa * (src_da + dst_sa - sa_da) / src + temp); + return qt_div_255(sa * (src_da + dst_sa - sa_da) / src + temp); } template <typename T> @@ -4763,7 +4762,7 @@ void QT_FASTCALL blendUntransformed(int count, const QSpan *spans, void *userDat static void blend_untransformed_rgb888(int count, const QSpan *spans, void *userData) { -#if !defined(Q_WS_QWS) || defined(QT_QWS_DEPTH_24) +#if defined(QT_QWS_DEPTH_24) QSpanData *data = reinterpret_cast<QSpanData *>(userData); if (data->texture.format == QImage::Format_RGB888) @@ -4777,7 +4776,7 @@ static void blend_untransformed_rgb888(int count, const QSpan *spans, static void blend_untransformed_argb6666(int count, const QSpan *spans, void *userData) { -#if !defined(Q_WS_QWS) || defined(QT_QWS_DEPTH_18) +#if defined(QT_QWS_DEPTH_18) QSpanData *data = reinterpret_cast<QSpanData *>(userData); if (data->texture.format == QImage::Format_ARGB6666_Premultiplied) @@ -4793,7 +4792,7 @@ static void blend_untransformed_argb6666(int count, const QSpan *spans, static void blend_untransformed_rgb666(int count, const QSpan *spans, void *userData) { -#if !defined(Q_WS_QWS) || defined(QT_QWS_DEPTH_18) +#if defined(QT_QWS_DEPTH_18) QSpanData *data = reinterpret_cast<QSpanData *>(userData); if (data->texture.format == QImage::Format_ARGB6666_Premultiplied) @@ -4809,7 +4808,7 @@ static void blend_untransformed_rgb666(int count, const QSpan *spans, static void blend_untransformed_argb8565(int count, const QSpan *spans, void *userData) { -#if !defined(Q_WS_QWS) || defined(QT_QWS_DEPTH_16) +#if defined(QT_QWS_DEPTH_16) QSpanData *data = reinterpret_cast<QSpanData *>(userData); if (data->texture.format == QImage::Format_ARGB8565_Premultiplied) @@ -4825,7 +4824,7 @@ static void blend_untransformed_argb8565(int count, const QSpan *spans, static void blend_untransformed_rgb565(int count, const QSpan *spans, void *userData) { -#if !defined(Q_WS_QWS) || defined(QT_QWS_DEPTH_16) +#if defined(QT_QWS_DEPTH_16) QSpanData *data = reinterpret_cast<QSpanData *>(userData); if (data->texture.format == QImage::Format_ARGB8565_Premultiplied) @@ -4841,7 +4840,7 @@ static void blend_untransformed_rgb565(int count, const QSpan *spans, static void blend_untransformed_argb8555(int count, const QSpan *spans, void *userData) { -#if !defined(Q_WS_QWS) || defined(QT_QWS_DEPTH_15) +#if defined(QT_QWS_DEPTH_15) QSpanData *data = reinterpret_cast<QSpanData *>(userData); if (data->texture.format == QImage::Format_ARGB8555_Premultiplied) @@ -4857,7 +4856,7 @@ static void blend_untransformed_argb8555(int count, const QSpan *spans, static void blend_untransformed_rgb555(int count, const QSpan *spans, void *userData) { -#if !defined(Q_WS_QWS) || defined(QT_QWS_DEPTH_15) +#if defined(QT_QWS_DEPTH_15) QSpanData *data = reinterpret_cast<QSpanData *>(userData); if (data->texture.format == QImage::Format_ARGB8555_Premultiplied) @@ -4873,7 +4872,7 @@ static void blend_untransformed_rgb555(int count, const QSpan *spans, static void blend_untransformed_argb4444(int count, const QSpan *spans, void *userData) { -#if !defined(Q_WS_QWS) || defined(QT_QWS_DEPTH_12) +#if defined(QT_QWS_DEPTH_12) QSpanData *data = reinterpret_cast<QSpanData *>(userData); if (data->texture.format == QImage::Format_ARGB4444_Premultiplied) @@ -4889,7 +4888,7 @@ static void blend_untransformed_argb4444(int count, const QSpan *spans, static void blend_untransformed_rgb444(int count, const QSpan *spans, void *userData) { -#if !defined(Q_WS_QWS) || defined(QT_QWS_DEPTH_12) +#if defined(QT_QWS_DEPTH_12) QSpanData *data = reinterpret_cast<QSpanData *>(userData); if (data->texture.format == QImage::Format_ARGB4444_Premultiplied) @@ -5084,7 +5083,7 @@ Q_STATIC_TEMPLATE_FUNCTION void blendTiled(int count, const QSpan *spans, void * static void blend_tiled_rgb888(int count, const QSpan *spans, void *userData) { -#if !defined(Q_WS_QWS) || defined(QT_QWS_DEPTH_24) +#if defined(QT_QWS_DEPTH_24) QSpanData *data = reinterpret_cast<QSpanData *>(userData); if (data->texture.format == QImage::Format_RGB888) @@ -5097,7 +5096,7 @@ static void blend_tiled_rgb888(int count, const QSpan *spans, void *userData) static void blend_tiled_argb6666(int count, const QSpan *spans, void *userData) { -#if !defined(Q_WS_QWS) || defined(QT_QWS_DEPTH_18) +#if defined(QT_QWS_DEPTH_18) QSpanData *data = reinterpret_cast<QSpanData *>(userData); if (data->texture.format == QImage::Format_ARGB6666_Premultiplied) @@ -5112,7 +5111,7 @@ static void blend_tiled_argb6666(int count, const QSpan *spans, void *userData) static void blend_tiled_rgb666(int count, const QSpan *spans, void *userData) { -#if !defined(Q_WS_QWS) || defined(QT_QWS_DEPTH_18) +#if defined(QT_QWS_DEPTH_18) QSpanData *data = reinterpret_cast<QSpanData *>(userData); if (data->texture.format == QImage::Format_ARGB6666_Premultiplied) @@ -5127,7 +5126,7 @@ static void blend_tiled_rgb666(int count, const QSpan *spans, void *userData) static void blend_tiled_argb8565(int count, const QSpan *spans, void *userData) { -#if !defined(Q_WS_QWS) || defined(QT_QWS_DEPTH_16) +#if defined(QT_QWS_DEPTH_16) QSpanData *data = reinterpret_cast<QSpanData *>(userData); if (data->texture.format == QImage::Format_ARGB8565_Premultiplied) @@ -5142,7 +5141,7 @@ static void blend_tiled_argb8565(int count, const QSpan *spans, void *userData) static void blend_tiled_rgb565(int count, const QSpan *spans, void *userData) { -#if !defined(Q_WS_QWS) || defined(QT_QWS_DEPTH_16) +#if defined(QT_QWS_DEPTH_16) QSpanData *data = reinterpret_cast<QSpanData *>(userData); if (data->texture.format == QImage::Format_ARGB8565_Premultiplied) @@ -5157,7 +5156,7 @@ static void blend_tiled_rgb565(int count, const QSpan *spans, void *userData) static void blend_tiled_argb8555(int count, const QSpan *spans, void *userData) { -#if !defined(Q_WS_QWS) || defined(QT_QWS_DEPTH_15) +#if defined(QT_QWS_DEPTH_15) QSpanData *data = reinterpret_cast<QSpanData *>(userData); if (data->texture.format == QImage::Format_ARGB8555_Premultiplied) @@ -5172,7 +5171,7 @@ static void blend_tiled_argb8555(int count, const QSpan *spans, void *userData) static void blend_tiled_rgb555(int count, const QSpan *spans, void *userData) { -#if !defined(Q_WS_QWS) || defined(QT_QWS_DEPTH_15) +#if defined(QT_QWS_DEPTH_15) QSpanData *data = reinterpret_cast<QSpanData *>(userData); if (data->texture.format == QImage::Format_ARGB8555_Premultiplied) @@ -5187,7 +5186,7 @@ static void blend_tiled_rgb555(int count, const QSpan *spans, void *userData) static void blend_tiled_argb4444(int count, const QSpan *spans, void *userData) { -#if !defined(Q_WS_QWS) || defined(QT_QWS_DEPTH_12) +#if defined(QT_QWS_DEPTH_12) QSpanData *data = reinterpret_cast<QSpanData *>(userData); if (data->texture.format == QImage::Format_ARGB4444_Premultiplied) @@ -5202,7 +5201,7 @@ static void blend_tiled_argb4444(int count, const QSpan *spans, void *userData) static void blend_tiled_rgb444(int count, const QSpan *spans, void *userData) { -#if !defined(Q_WS_QWS) || defined(QT_QWS_DEPTH_12) +#if defined(QT_QWS_DEPTH_12) QSpanData *data = reinterpret_cast<QSpanData *>(userData); if (data->texture.format == QImage::Format_ARGB4444_Premultiplied) @@ -5599,7 +5598,7 @@ Q_STATIC_TEMPLATE_FUNCTION void blendTransformedBilinear(int count, const QSpan static void blend_transformed_bilinear_rgb888(int count, const QSpan *spans, void *userData) { -#if !defined(Q_WS_QWS) || defined(QT_QWS_DEPTH_24) +#if defined(QT_QWS_DEPTH_24) QSpanData *data = reinterpret_cast<QSpanData *>(userData); if (data->texture.format == QImage::Format_RGB888) @@ -5612,7 +5611,7 @@ static void blend_transformed_bilinear_rgb888(int count, const QSpan *spans, voi static void blend_transformed_bilinear_argb6666(int count, const QSpan *spans, void *userData) { -#if !defined(Q_WS_QWS) || defined(QT_QWS_DEPTH_18) +#if defined(QT_QWS_DEPTH_18) QSpanData *data = reinterpret_cast<QSpanData *>(userData); if (data->texture.format == QImage::Format_ARGB6666_Premultiplied) @@ -5627,7 +5626,7 @@ static void blend_transformed_bilinear_argb6666(int count, const QSpan *spans, v static void blend_transformed_bilinear_rgb666(int count, const QSpan *spans, void *userData) { -#if !defined(Q_WS_QWS) || defined(QT_QWS_DEPTH_18) +#if defined(QT_QWS_DEPTH_18) QSpanData *data = reinterpret_cast<QSpanData *>(userData); if (data->texture.format == QImage::Format_ARGB6666_Premultiplied) @@ -5642,7 +5641,7 @@ static void blend_transformed_bilinear_rgb666(int count, const QSpan *spans, voi static void blend_transformed_bilinear_argb8565(int count, const QSpan *spans, void *userData) { -#if !defined(Q_WS_QWS) || defined(QT_QWS_DEPTH_16) +#if defined(QT_QWS_DEPTH_16) QSpanData *data = reinterpret_cast<QSpanData *>(userData); if (data->texture.format == QImage::Format_ARGB8565_Premultiplied) @@ -5658,7 +5657,7 @@ static void blend_transformed_bilinear_argb8565(int count, const QSpan *spans, v static void blend_transformed_bilinear_rgb565(int count, const QSpan *spans, void *userData) { -#if !defined(Q_WS_QWS) || defined(QT_QWS_DEPTH_16) +#if defined(QT_QWS_DEPTH_16) QSpanData *data = reinterpret_cast<QSpanData *>(userData); if (data->texture.format == QImage::Format_RGB16) @@ -5673,7 +5672,7 @@ static void blend_transformed_bilinear_rgb565(int count, const QSpan *spans, static void blend_transformed_bilinear_argb8555(int count, const QSpan *spans, void *userData) { -#if !defined(Q_WS_QWS) || defined(QT_QWS_DEPTH_15) +#if defined(QT_QWS_DEPTH_15) QSpanData *data = reinterpret_cast<QSpanData *>(userData); if (data->texture.format == QImage::Format_ARGB8555_Premultiplied) @@ -5688,7 +5687,7 @@ static void blend_transformed_bilinear_argb8555(int count, const QSpan *spans, v static void blend_transformed_bilinear_rgb555(int count, const QSpan *spans, void *userData) { -#if !defined(Q_WS_QWS) || defined(QT_QWS_DEPTH_15) +#if defined(QT_QWS_DEPTH_15) QSpanData *data = reinterpret_cast<QSpanData *>(userData); if (data->texture.format == QImage::Format_ARGB8555_Premultiplied) @@ -5703,7 +5702,7 @@ static void blend_transformed_bilinear_rgb555(int count, const QSpan *spans, voi static void blend_transformed_bilinear_argb4444(int count, const QSpan *spans, void *userData) { -#if !defined(Q_WS_QWS) || defined(QT_QWS_DEPTH_12) +#if defined(QT_QWS_DEPTH_12) QSpanData *data = reinterpret_cast<QSpanData *>(userData); if (data->texture.format == QImage::Format_ARGB4444_Premultiplied) @@ -5718,7 +5717,7 @@ static void blend_transformed_bilinear_argb4444(int count, const QSpan *spans, v static void blend_transformed_bilinear_rgb444(int count, const QSpan *spans, void *userData) { -#if !defined(Q_WS_QWS) || defined(QT_QWS_DEPTH_12) +#if defined(QT_QWS_DEPTH_12) QSpanData *data = reinterpret_cast<QSpanData *>(userData); if (data->texture.format == QImage::Format_ARGB4444_Premultiplied) @@ -6195,7 +6194,7 @@ Q_STATIC_TEMPLATE_FUNCTION void blendTransformed(int count, const QSpan *spans, static void blend_transformed_rgb888(int count, const QSpan *spans, void *userData) { -#if !defined(Q_WS_QWS) || defined(QT_QWS_DEPTH_24) +#if defined(QT_QWS_DEPTH_24) QSpanData *data = reinterpret_cast<QSpanData *>(userData); if (data->texture.format == QImage::Format_RGB888) @@ -6209,7 +6208,7 @@ static void blend_transformed_rgb888(int count, const QSpan *spans, static void blend_transformed_argb6666(int count, const QSpan *spans, void *userData) { -#if !defined(Q_WS_QWS) || defined(QT_QWS_DEPTH_18) +#if defined(QT_QWS_DEPTH_18) QSpanData *data = reinterpret_cast<QSpanData *>(userData); if (data->texture.format == QImage::Format_ARGB6666_Premultiplied) @@ -6225,7 +6224,7 @@ static void blend_transformed_argb6666(int count, const QSpan *spans, static void blend_transformed_rgb666(int count, const QSpan *spans, void *userData) { -#if !defined(Q_WS_QWS) || defined(QT_QWS_DEPTH_18) +#if defined(QT_QWS_DEPTH_18) QSpanData *data = reinterpret_cast<QSpanData *>(userData); if (data->texture.format == QImage::Format_ARGB6666_Premultiplied) @@ -6241,7 +6240,7 @@ static void blend_transformed_rgb666(int count, const QSpan *spans, static void blend_transformed_argb8565(int count, const QSpan *spans, void *userData) { -#if !defined(Q_WS_QWS) || defined(QT_QWS_DEPTH_16) +#if defined(QT_QWS_DEPTH_16) QSpanData *data = reinterpret_cast<QSpanData *>(userData); if (data->texture.format == QImage::Format_ARGB8565_Premultiplied) @@ -6257,7 +6256,7 @@ static void blend_transformed_argb8565(int count, const QSpan *spans, static void blend_transformed_rgb565(int count, const QSpan *spans, void *userData) { -#if !defined(Q_WS_QWS) || defined(QT_QWS_DEPTH_16) +#if defined(QT_QWS_DEPTH_16) QSpanData *data = reinterpret_cast<QSpanData *>(userData); if (data->texture.format == QImage::Format_ARGB8565_Premultiplied) @@ -6273,7 +6272,7 @@ static void blend_transformed_rgb565(int count, const QSpan *spans, static void blend_transformed_argb8555(int count, const QSpan *spans, void *userData) { -#if !defined(Q_WS_QWS) || defined(QT_QWS_DEPTH_15) +#if defined(QT_QWS_DEPTH_15) QSpanData *data = reinterpret_cast<QSpanData *>(userData); if (data->texture.format == QImage::Format_ARGB8555_Premultiplied) @@ -6289,7 +6288,7 @@ static void blend_transformed_argb8555(int count, const QSpan *spans, static void blend_transformed_rgb555(int count, const QSpan *spans, void *userData) { -#if !defined(Q_WS_QWS) || defined(QT_QWS_DEPTH_15) +#if defined(QT_QWS_DEPTH_15) QSpanData *data = reinterpret_cast<QSpanData *>(userData); if (data->texture.format == QImage::Format_ARGB8555_Premultiplied) @@ -6305,7 +6304,7 @@ static void blend_transformed_rgb555(int count, const QSpan *spans, static void blend_transformed_argb4444(int count, const QSpan *spans, void *userData) { -#if !defined(Q_WS_QWS) || defined(QT_QWS_DEPTH_12) +#if defined(QT_QWS_DEPTH_12) QSpanData *data = reinterpret_cast<QSpanData *>(userData); if (data->texture.format == QImage::Format_ARGB4444_Premultiplied) @@ -6321,7 +6320,7 @@ static void blend_transformed_argb4444(int count, const QSpan *spans, static void blend_transformed_rgb444(int count, const QSpan *spans, void *userData) { -#if !defined(Q_WS_QWS) || defined(QT_QWS_DEPTH_12) +#if defined(QT_QWS_DEPTH_12) QSpanData *data = reinterpret_cast<QSpanData *>(userData); if (data->texture.format == QImage::Format_ARGB4444_Premultiplied) @@ -6619,7 +6618,7 @@ Q_STATIC_TEMPLATE_FUNCTION void blendTransformedTiled(int count, const QSpan *sp static void blend_transformed_tiled_rgb888(int count, const QSpan *spans, void *userData) { -#if !defined(Q_WS_QWS) || defined(QT_QWS_DEPTH_24) +#if defined(QT_QWS_DEPTH_24) QSpanData *data = reinterpret_cast<QSpanData *>(userData); if (data->texture.format == QImage::Format_RGB888) @@ -6633,7 +6632,7 @@ static void blend_transformed_tiled_rgb888(int count, const QSpan *spans, static void blend_transformed_tiled_argb6666(int count, const QSpan *spans, void *userData) { -#if !defined(Q_WS_QWS) || defined(QT_QWS_DEPTH_18) +#if defined(QT_QWS_DEPTH_18) QSpanData *data = reinterpret_cast<QSpanData *>(userData); if (data->texture.format == QImage::Format_ARGB6666_Premultiplied) @@ -6649,7 +6648,7 @@ static void blend_transformed_tiled_argb6666(int count, const QSpan *spans, static void blend_transformed_tiled_rgb666(int count, const QSpan *spans, void *userData) { -#if !defined(Q_WS_QWS) || defined(QT_QWS_DEPTH_18) +#if defined(QT_QWS_DEPTH_18) QSpanData *data = reinterpret_cast<QSpanData *>(userData); if (data->texture.format == QImage::Format_ARGB6666_Premultiplied) @@ -6665,7 +6664,7 @@ static void blend_transformed_tiled_rgb666(int count, const QSpan *spans, static void blend_transformed_tiled_argb8565(int count, const QSpan *spans, void *userData) { -#if !defined(Q_WS_QWS) || defined(QT_QWS_DEPTH_16) +#if defined(QT_QWS_DEPTH_16) QSpanData *data = reinterpret_cast<QSpanData *>(userData); if (data->texture.format == QImage::Format_ARGB8565_Premultiplied) @@ -6681,7 +6680,7 @@ static void blend_transformed_tiled_argb8565(int count, const QSpan *spans, static void blend_transformed_tiled_rgb565(int count, const QSpan *spans, void *userData) { -#if !defined(Q_WS_QWS) || defined(QT_QWS_DEPTH_16) +#if defined(QT_QWS_DEPTH_16) QSpanData *data = reinterpret_cast<QSpanData *>(userData); if (data->texture.format == QImage::Format_ARGB8565_Premultiplied) @@ -6697,7 +6696,7 @@ static void blend_transformed_tiled_rgb565(int count, const QSpan *spans, static void blend_transformed_tiled_argb8555(int count, const QSpan *spans, void *userData) { -#if !defined(Q_WS_QWS) || defined(QT_QWS_DEPTH_15) +#if defined(QT_QWS_DEPTH_15) QSpanData *data = reinterpret_cast<QSpanData *>(userData); if (data->texture.format == QImage::Format_ARGB8555_Premultiplied) @@ -6713,7 +6712,7 @@ static void blend_transformed_tiled_argb8555(int count, const QSpan *spans, static void blend_transformed_tiled_rgb555(int count, const QSpan *spans, void *userData) { -#if !defined(Q_WS_QWS) || defined(QT_QWS_DEPTH_15) +#if defined(QT_QWS_DEPTH_15) QSpanData *data = reinterpret_cast<QSpanData *>(userData); if (data->texture.format == QImage::Format_ARGB8555_Premultiplied) @@ -6729,7 +6728,7 @@ static void blend_transformed_tiled_rgb555(int count, const QSpan *spans, static void blend_transformed_tiled_argb4444(int count, const QSpan *spans, void *userData) { -#if !defined(Q_WS_QWS) || defined(QT_QWS_DEPTH_12) +#if defined(QT_QWS_DEPTH_12) QSpanData *data = reinterpret_cast<QSpanData *>(userData); if (data->texture.format == QImage::Format_ARGB4444_Premultiplied) @@ -6745,7 +6744,7 @@ static void blend_transformed_tiled_argb4444(int count, const QSpan *spans, static void blend_transformed_tiled_rgb444(int count, const QSpan *spans, void *userData) { -#if !defined(Q_WS_QWS) || defined(QT_QWS_DEPTH_12) +#if defined(QT_QWS_DEPTH_12) QSpanData *data = reinterpret_cast<QSpanData *>(userData); if (data->texture.format == QImage::Format_ARGB4444_Premultiplied) diff --git a/src/gui/painting/qemulationpaintengine.cpp b/src/gui/painting/qemulationpaintengine.cpp index 3397c45..175f1ab 100644 --- a/src/gui/painting/qemulationpaintengine.cpp +++ b/src/gui/painting/qemulationpaintengine.cpp @@ -123,14 +123,30 @@ void QEmulationPaintEngine::stroke(const QVectorPath &path, const QPen &pen) real_engine->stroke(path, bgPen); } - QBrush brush = pen.brush(); + QPen copy = pen; Qt::BrushStyle style = qbrush_style(brush); if (style >= Qt::LinearGradientPattern && style <= Qt::ConicalGradientPattern) { const QGradient *g = brush.gradient(); + if (g->coordinateMode() > QGradient::LogicalMode) { - QPaintEngineEx::stroke(path, pen); - return; + if (g->coordinateMode() == QGradient::StretchToDeviceMode) { + QTransform mat = brush.transform(); + mat.scale(real_engine->painter()->device()->width(), real_engine->painter()->device()->height()); + brush.setTransform(mat); + copy.setBrush(brush); + real_engine->stroke(path, copy); + return; + } else if (g->coordinateMode() == QGradient::ObjectBoundingMode) { + QTransform mat = brush.transform(); + QRealRect r = path.controlPointRect(); + mat.translate(r.x1, r.y1); + mat.scale(r.x2 - r.x1, r.y2 - r.y1); + brush.setTransform(mat); + copy.setBrush(brush); + real_engine->stroke(path, copy); + return; + } } } diff --git a/src/gui/painting/qmatrix.cpp b/src/gui/painting/qmatrix.cpp index 40ff379..4439d52 100644 --- a/src/gui/painting/qmatrix.cpp +++ b/src/gui/painting/qmatrix.cpp @@ -633,6 +633,8 @@ QPolygonF QMatrix::map(const QPolygonF &a) const \sa QMatrix::map() */ +extern QPainterPath qt_regionToPath(const QRegion ®ion); + /*! \fn QRegion QMatrix::map(const QRegion ®ion) const \overload @@ -653,7 +655,6 @@ QRegion QMatrix::map(const QRegion &r) const return copy; } - extern QPainterPath qt_regionToPath(const QRegion ®ion); QPainterPath p = map(qt_regionToPath(r)); return p.toFillPolygon().toPolygon(); } diff --git a/src/gui/painting/qmemrotate.cpp b/src/gui/painting/qmemrotate.cpp index 7ad0e42..471f544 100644 --- a/src/gui/painting/qmemrotate.cpp +++ b/src/gui/painting/qmemrotate.cpp @@ -528,6 +528,26 @@ void qt_memrotate270(const srctype *src, int w, int h, int sstride, \ qt_memrotate270_template(src, w, h, sstride, dest, dstride); \ } +#define QT_IMPL_SIMPLE_MEMROTATE(srctype, desttype) \ +void qt_memrotate90(const srctype *src, int w, int h, int sstride, \ + desttype *dest, int dstride) \ +{ \ + qt_memrotate90_tiled_unpacked<desttype,srctype>(src, w, h, sstride, dest, dstride); \ +} \ +void qt_memrotate180(const srctype *src, int w, int h, int sstride, \ + desttype *dest, int dstride) \ +{ \ + qt_memrotate180_template(src, w, h, sstride, dest, dstride); \ +} \ +void qt_memrotate270(const srctype *src, int w, int h, int sstride, \ + desttype *dest, int dstride) \ +{ \ + qt_memrotate270_tiled_unpacked<desttype,srctype>(src, w, h, sstride, dest, dstride); \ +} + + + + QT_IMPL_MEMROTATE(quint32, quint32) QT_IMPL_MEMROTATE(quint32, quint16) QT_IMPL_MEMROTATE(quint16, quint32) @@ -537,7 +557,16 @@ QT_IMPL_MEMROTATE(quint32, quint24) QT_IMPL_MEMROTATE(quint32, quint18) QT_IMPL_MEMROTATE(quint32, quint8) QT_IMPL_MEMROTATE(quint16, quint8) +QT_IMPL_MEMROTATE(qrgb444, quint8) QT_IMPL_MEMROTATE(quint8, quint8) + +#if defined(QT_QWS_ROTATE_BGR) +QT_IMPL_SIMPLE_MEMROTATE(quint16, qbgr565) +QT_IMPL_SIMPLE_MEMROTATE(quint32, qbgr565) +QT_IMPL_SIMPLE_MEMROTATE(qrgb555, qbgr555) +QT_IMPL_SIMPLE_MEMROTATE(quint32, qbgr555) +#endif + #ifdef QT_QWS_DEPTH_GENERIC QT_IMPL_MEMROTATE(quint32, qrgb_generic16) QT_IMPL_MEMROTATE(quint16, qrgb_generic16) diff --git a/src/gui/painting/qmemrotate_p.h b/src/gui/painting/qmemrotate_p.h index bd6006b..87cfb1a 100644 --- a/src/gui/painting/qmemrotate_p.h +++ b/src/gui/painting/qmemrotate_p.h @@ -90,7 +90,16 @@ QT_DECL_MEMROTATE(quint32, quint24); QT_DECL_MEMROTATE(quint32, quint18); QT_DECL_MEMROTATE(quint32, quint8); QT_DECL_MEMROTATE(quint16, quint8); +QT_DECL_MEMROTATE(qrgb444, quint8); QT_DECL_MEMROTATE(quint8, quint8); + +#ifdef QT_QWS_ROTATE_BGR +QT_DECL_MEMROTATE(quint16, qbgr565); +QT_DECL_MEMROTATE(quint32, qbgr565); +QT_DECL_MEMROTATE(qrgb555, qbgr555); +QT_DECL_MEMROTATE(quint32, qbgr555); +#endif + #ifdef QT_QWS_DEPTH_GENERIC QT_DECL_MEMROTATE(quint32, qrgb_generic16); QT_DECL_MEMROTATE(quint16, qrgb_generic16); diff --git a/src/gui/painting/qpaintdevice_qws.cpp b/src/gui/painting/qpaintdevice_qws.cpp index 6a68d28..c67be86 100644 --- a/src/gui/painting/qpaintdevice_qws.cpp +++ b/src/gui/painting/qpaintdevice_qws.cpp @@ -81,9 +81,6 @@ int QPaintDevice::metric(PaintDeviceMetric m) const } } -/*! - \internal -*/ QWSDisplay *QPaintDevice::qwsDisplay() { return qt_fbdpy; diff --git a/src/gui/painting/qpaintdevice_win.cpp b/src/gui/painting/qpaintdevice_win.cpp index 6cae744..7cd3392 100644 --- a/src/gui/painting/qpaintdevice_win.cpp +++ b/src/gui/painting/qpaintdevice_win.cpp @@ -71,16 +71,11 @@ int QPaintDevice::metric(PaintDeviceMetric) const return 0; } - -/*! \internal -*/ HDC QPaintDevice::getDC() const { return 0; } -/*! \internal -*/ void QPaintDevice::releaseDC(HDC) const { } diff --git a/src/gui/painting/qpaintdevice_x11.cpp b/src/gui/painting/qpaintdevice_x11.cpp index 4ea9f57..95cb115 100644 --- a/src/gui/painting/qpaintdevice_x11.cpp +++ b/src/gui/painting/qpaintdevice_x11.cpp @@ -106,33 +106,11 @@ int QPaintDevice::metric(PaintDeviceMetric) const #ifdef QT3_SUPPORT -/*! - Use QX11Info::display() instead. - - \oldcode - Display *display = widget->x11Display(); - \newcode - Display *display = QX11Info::display(); - \endcode - - \sa QWidget::x11Info(), QX11Info::display() -*/ Display *QPaintDevice::x11Display() const { return X11->display; } -/*! - Use QX11Info::screen() instead. - - \oldcode - int screen = widget->x11Screen(); - \newcode - int screen = widget->x11Info().screen(); - \endcode - - \sa QWidget::x11Info(), QPixmap::x11Info() -*/ int QPaintDevice::x11Screen() const { const QX11Info *info = qt_x11Info(this); @@ -141,17 +119,6 @@ int QPaintDevice::x11Screen() const return QX11Info::appScreen(); } -/*! - Use QX11Info::visual() instead. - - \oldcode - void *visual = widget->x11Visual(); - \newcode - void *visual = widget->x11Info().visual(); - \endcode - - \sa QWidget::x11Info(), QPixmap::x11Info() -*/ void *QPaintDevice::x11Visual() const { const QX11Info *info = qt_x11Info(this); @@ -160,17 +127,6 @@ void *QPaintDevice::x11Visual() const return QX11Info::appVisual(); } -/*! - Use QX11Info::depth() instead. - - \oldcode - int depth = widget->x11Depth(); - \newcode - int depth = widget->x11Info().depth(); - \endcode - - \sa QWidget::x11Info(), QPixmap::x11Info() -*/ int QPaintDevice::x11Depth() const { const QX11Info *info = qt_x11Info(this); @@ -179,17 +135,6 @@ int QPaintDevice::x11Depth() const return QX11Info::appDepth(); } -/*! - Use QX11Info::cells() instead. - - \oldcode - int cells = widget->x11Cells(); - \newcode - int cells = widget->x11Info().cells(); - \endcode - - \sa QWidget::x11Info(), QPixmap::x11Info() -*/ int QPaintDevice::x11Cells() const { const QX11Info *info = qt_x11Info(this); @@ -198,17 +143,6 @@ int QPaintDevice::x11Cells() const return QX11Info::appCells(); } -/*! - Use QX11Info::colormap() instead. - - \oldcode - unsigned long screen = widget->x11Colormap(); - \newcode - unsigned long screen = widget->x11Info().colormap(); - \endcode - - \sa QWidget::x11Info(), QPixmap::x11Info() -*/ Qt::HANDLE QPaintDevice::x11Colormap() const { const QX11Info *info = qt_x11Info(this); @@ -217,17 +151,6 @@ Qt::HANDLE QPaintDevice::x11Colormap() const return QX11Info::appColormap(); } -/*! - Use QX11Info::defaultColormap() instead. - - \oldcode - bool isDefault = widget->x11DefaultColormap(); - \newcode - bool isDefault = widget->x11Info().defaultColormap(); - \endcode - - \sa QWidget::x11Info(), QPixmap::x11Info() -*/ bool QPaintDevice::x11DefaultColormap() const { const QX11Info *info = qt_x11Info(this); @@ -236,17 +159,6 @@ bool QPaintDevice::x11DefaultColormap() const return QX11Info::appDefaultColormap(); } -/*! - Use QX11Info::defaultVisual() instead. - - \oldcode - bool isDefault = widget->x11DefaultVisual(); - \newcode - bool isDefault = widget->x11Info().defaultVisual(); - \endcode - - \sa QWidget::x11Info(), QPixmap::x11Info() -*/ bool QPaintDevice::x11DefaultVisual() const { const QX11Info *info = qt_x11Info(this); @@ -255,176 +167,48 @@ bool QPaintDevice::x11DefaultVisual() const return QX11Info::appDefaultVisual(); } -/*! - Use QX11Info::visual() instead. - - \oldcode - void *visual = QPaintDevice::x11AppVisual(screen); - \newcode - void *visual = qApp->x11Info(screen).visual(); - \endcode - - \sa QWidget::x11Info(), QPixmap::x11Info() -*/ void *QPaintDevice::x11AppVisual(int screen) { return QX11Info::appVisual(screen); } -/*! - Use QX11Info::colormap() instead. - - \oldcode - unsigned long colormap = QPaintDevice::x11AppColormap(screen); - \newcode - unsigned long colormap = qApp->x11Info(screen).colormap(); - \endcode - - \sa QWidget::x11Info(), QPixmap::x11Info() -*/ Qt::HANDLE QPaintDevice::x11AppColormap(int screen) { return QX11Info::appColormap(screen); } -/*! - Use QX11Info::display() instead. - - \oldcode - Display *display = QPaintDevice::x11AppDisplay(); - \newcode - Display *display = qApp->x11Info().display(); - \endcode - - \sa QWidget::x11Info(), QPixmap::x11Info() -*/ Display *QPaintDevice::x11AppDisplay() { return QX11Info::display(); } -/*! - Use QX11Info::screen() instead. - - \oldcode - int screen = QPaintDevice::x11AppScreen(); - \newcode - int screen = qApp->x11Info().screen(); - \endcode - - \sa QWidget::x11Info(), QPixmap::x11Info() -*/ int QPaintDevice::x11AppScreen() { return QX11Info::appScreen(); } -/*! - Use QX11Info::depth() instead. - - \oldcode - int depth = QPaintDevice::x11AppDepth(screen); - \newcode - int depth = qApp->x11Info(screen).depth(); - \endcode - - \sa QWidget::x11Info(), QPixmap::x11Info() -*/ int QPaintDevice::x11AppDepth(int screen) { return QX11Info::appDepth(screen); } -/*! - Use QX11Info::cells() instead. - - \oldcode - int cells = QPaintDevice::x11AppCells(screen); - \newcode - int cells = qApp->x11Info(screen).cells(); - \endcode - - \sa QWidget::x11Info(), QPixmap::x11Info() -*/ int QPaintDevice::x11AppCells(int screen) { return QX11Info::appCells(screen); } -/*! - Use QX11Info::appRootWindow() instead. - - \oldcode - unsigned long window = QPaintDevice::x11AppRootWindow(screen); - \newcode - unsigned long window = qApp->x11Info(screen).appRootWindow(); - \endcode - - \sa QWidget::x11Info(), QPixmap::x11Info() -*/ Qt::HANDLE QPaintDevice::x11AppRootWindow(int screen) { return QX11Info::appRootWindow(screen); } -/*! - Use QX11Info::defaultColormap() instead. - - \oldcode - bool isDefault = QPaintDevice::x11AppDefaultColormap(screen); - \newcode - bool isDefault = qApp->x11Info(screen).defaultColormap(); - \endcode - - \sa QWidget::x11Info(), QPixmap::x11Info() -*/ bool QPaintDevice::x11AppDefaultColormap(int screen) { return QX11Info::appDefaultColormap(screen); } -/*! - Use QX11Info::defaultVisual() instead. - - \oldcode - bool isDefault = QPaintDevice::x11AppDefaultVisual(screen); - \newcode - bool isDefault = qApp->x11Info(screen).defaultVisual(); - \endcode - - \sa QWidget::x11Info(), QPixmap::x11Info() -*/ bool QPaintDevice::x11AppDefaultVisual(int screen) { return QX11Info::appDefaultVisual(screen); } -/*! - Use QX11Info::setAppDpiX() instead. -*/ void QPaintDevice::x11SetAppDpiX(int dpi, int screen) { QX11Info::setAppDpiX(dpi, screen); } -/*! - Use QX11Info::setAppDpiY() instead. -*/ void QPaintDevice::x11SetAppDpiY(int dpi, int screen) { QX11Info::setAppDpiY(dpi, screen); } - -/*! - Use QX11Info::appDpiX() instead. - - \oldcode - bool isDefault = QPaintDevice::x11AppDpiX(screen); - \newcode - bool isDefault = qApp->x11Info(screen).appDpiX(); - \endcode - - \sa QWidget::x11Info(), QPixmap::x11Info() -*/ int QPaintDevice::x11AppDpiX(int screen) { return QX11Info::appDpiX(screen); } -/*! - Use QX11Info::appDpiY() instead. - - \oldcode - bool isDefault = QPaintDevice::x11AppDpiY(screen); - \newcode - bool isDefault = qApp->x11Info(screen).appDpiY(); - \endcode - - \sa QWidget::x11Info(), QPixmap::x11Info() -*/ int QPaintDevice::x11AppDpiY(int screen) { return QX11Info::appDpiY(screen); diff --git a/src/gui/painting/qpaintengine.cpp b/src/gui/painting/qpaintengine.cpp index ad09060..7de1ec4 100644 --- a/src/gui/painting/qpaintengine.cpp +++ b/src/gui/painting/qpaintengine.cpp @@ -949,8 +949,8 @@ void QPaintEngine::setSystemClip(const QRegion ®ion) Q_D(QPaintEngine); d->systemClip = region; // Be backward compatible and only call d->systemStateChanged() - // if we currently have a system transform set. - if (d->hasSystemTransform) { + // if we currently have a system transform/viewport set. + if (d->hasSystemTransform || d->hasSystemViewport) { d->transformSystemClip(); d->systemStateChanged(); } diff --git a/src/gui/painting/qpaintengine_alpha.cpp b/src/gui/painting/qpaintengine_alpha.cpp index e38f6a4..74cbebe 100644 --- a/src/gui/painting/qpaintengine_alpha.cpp +++ b/src/gui/painting/qpaintengine_alpha.cpp @@ -80,6 +80,7 @@ bool QAlphaPaintEngine::begin(QPaintDevice *pdev) d->m_advancedPen = false; d->m_advancedBrush = false; d->m_complexTransform = false; + d->m_emulateProjectiveTransforms = false; // clear alpha region d->m_alphargn = QRegion(); @@ -116,6 +117,9 @@ void QAlphaPaintEngine::updateState(const QPaintEngineState &state) if (flags & QPaintEngine::DirtyTransform) { d->m_transform = state.transform(); d->m_complexTransform = (d->m_transform.type() > QTransform::TxScale); + d->m_emulateProjectiveTransforms = !(d->m_savedcaps & QPaintEngine::PerspectiveTransform) + && !(d->m_savedcaps & QPaintEngine::AlphaBlend) + && (d->m_transform.type() >= QTransform::TxProject); } if (flags & QPaintEngine::DirtyPen) { d->m_pen = state.pen(); @@ -163,7 +167,9 @@ void QAlphaPaintEngine::drawPath(const QPainterPath &path) if (d->m_pass == 0) { d->m_continueCall = false; - if (d->m_hasalpha || d->m_advancedPen || d->m_advancedBrush) { + if (d->m_hasalpha || d->m_advancedPen || d->m_advancedBrush + || d->m_emulateProjectiveTransforms) + { d->addAlphaRect(tr); } if (d->m_picengine) @@ -187,7 +193,9 @@ void QAlphaPaintEngine::drawPolygon(const QPointF *points, int pointCount, Polyg if (d->m_pass == 0) { d->m_continueCall = false; - if (d->m_hasalpha || d->m_advancedPen || d->m_advancedBrush) { + if (d->m_hasalpha || d->m_advancedPen || d->m_advancedBrush + || d->m_emulateProjectiveTransforms) + { d->addAlphaRect(tr); } diff --git a/src/gui/painting/qpaintengine_alpha_p.h b/src/gui/painting/qpaintengine_alpha_p.h index f510c73..f7d7a34 100644 --- a/src/gui/painting/qpaintengine_alpha_p.h +++ b/src/gui/painting/qpaintengine_alpha_p.h @@ -113,6 +113,7 @@ public: bool m_advancedPen; bool m_advancedBrush; bool m_complexTransform; + bool m_emulateProjectiveTransforms; bool m_continueCall; QTransform m_transform; diff --git a/src/gui/painting/qpaintengine_d3d.cpp b/src/gui/painting/qpaintengine_d3d.cpp index 26708b0..bb81623 100644 --- a/src/gui/painting/qpaintengine_d3d.cpp +++ b/src/gui/painting/qpaintengine_d3d.cpp @@ -2866,9 +2866,10 @@ void QDirect3DPaintEnginePrivate::updateClipPath(const QPainterPath &path, Qt::C m_draw_helper->setClipPath(m_clip_path, aaitem); */ } +extern QPainterPath qt_regionToPath(const QRegion ®ion); + void QDirect3DPaintEnginePrivate::updateClipRegion(const QRegion &clipregion, Qt::ClipOperation op) { - extern QPainterPath qt_regionToPath(const QRegion ®ion); if (m_draw_helper->needsFlushing()) flushBatch(); if (m_has_complex_clipping) { diff --git a/src/gui/painting/qpaintengine_mac.cpp b/src/gui/painting/qpaintengine_mac.cpp index 0644a02..5889388 100644 --- a/src/gui/painting/qpaintengine_mac.cpp +++ b/src/gui/painting/qpaintengine_mac.cpp @@ -996,15 +996,14 @@ void QCoreGraphicsPaintEngine::drawPixmap(const QRectF &r, const QPixmap &pm, co } else if (differentSize) { #if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4) if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_4) { - CGImageRef img = (CGImageRef)pm.macCGHandle(); + QCFType<CGImageRef> img = pm.toMacCGImageRef(); image = CGImageCreateWithImageInRect(img, CGRectMake(qRound(sr.x()), qRound(sr.y()), qRound(sr.width()), qRound(sr.height()))); - CGImageRelease(img); } else #endif { const int sx = qRound(sr.x()), sy = qRound(sr.y()), sw = qRound(sr.width()), sh = qRound(sr.height()); const QMacPixmapData *pmData = static_cast<const QMacPixmapData*>(pm.data); - quint32 *pantherData = pmData->pixels + (sy * pm.width() + sx); + quint32 *pantherData = pmData->pixels + sy * (pmData->bytesPerRow / 4) + sx; QCFType<CGDataProviderRef> provider = CGDataProviderCreateWithData(0, pantherData, sw*sh*pmData->bytesPerRow, 0); image = CGImageCreate(sw, sh, 8, 32, pmData->bytesPerRow, macGenericColorSpace(), diff --git a/src/gui/painting/qpaintengine_p.h b/src/gui/painting/qpaintengine_p.h index eeba7ec..0b5e175 100644 --- a/src/gui/painting/qpaintengine_p.h +++ b/src/gui/painting/qpaintengine_p.h @@ -83,10 +83,12 @@ public: if (systemClip.isEmpty()) return; - if (systemTransform.type() <= QTransform::TxTranslate) - systemClip.translate(qRound(systemTransform.dx()), qRound(systemTransform.dy())); - else - systemClip = systemTransform.map(systemClip); + if (hasSystemTransform) { + if (systemTransform.type() <= QTransform::TxTranslate) + systemClip.translate(qRound(systemTransform.dx()), qRound(systemTransform.dy())); + else + systemClip = systemTransform.map(systemClip); + } // Make sure we're inside the viewport. if (hasSystemViewport) { @@ -101,7 +103,7 @@ public: inline void setSystemTransform(const QTransform &xform) { systemTransform = xform; - if ((hasSystemTransform = !xform.isIdentity())) + if ((hasSystemTransform = !xform.isIdentity()) || hasSystemViewport) transformSystemClip(); systemStateChanged(); } diff --git a/src/gui/painting/qpaintengine_raster.cpp b/src/gui/painting/qpaintengine_raster.cpp index 495e6c4..847904b 100644 --- a/src/gui/painting/qpaintengine_raster.cpp +++ b/src/gui/painting/qpaintengine_raster.cpp @@ -104,6 +104,8 @@ QT_BEGIN_NAMESPACE +extern bool qt_scaleForTransform(const QTransform &transform, qreal *scale); // qtransform.cpp + #define qreal_to_fixed_26_6(f) (int(f * 64)) #define qt_swap_int(x, y) { int tmp = (x); (x) = (y); (y) = tmp; } #define qt_swap_qreal(x, y) { qreal tmp = (x); (x) = (y); (y) = tmp; } @@ -607,7 +609,6 @@ void QRasterPaintEngine::updateMatrix(const QTransform &matrix) break; } - extern bool qt_scaleForTransform(const QTransform &transform, qreal *scale); // qtransform.cpp s->flags.tx_noshear = qt_scaleForTransform(s->matrix, &s->txscale); ensureOutlineMapper(); @@ -1021,7 +1022,7 @@ void QRasterPaintEnginePrivate::drawImage(const QPointF &pt, int alpha, const QRect &sr) { - if (!clip.isValid()) + if (alpha == 0 || !clip.isValid()) return; Q_ASSERT(img.depth() >= 8); @@ -1139,6 +1140,33 @@ void QRasterPaintEnginePrivate::updateMatrixData(QSpanData *spanData, const QBru } } +// #define QT_CLIPPING_RATIOS + +#ifdef QT_CLIPPING_RATIOS +int rectClips; +int regionClips; +int totalClips; + +static void checkClipRatios(QRasterPaintEnginePrivate *d) +{ + if (d->clip()->hasRectClip) + rectClips++; + if (d->clip()->hasRegionClip) + regionClips++; + totalClips++; + + if ((totalClips % 5000) == 0) { + printf("Clipping ratio: rectangular=%f%%, region=%f%%, complex=%f%%\n", + rectClips * 100.0 / (qreal) totalClips, + regionClips * 100.0 / (qreal) totalClips, + (totalClips - rectClips - regionClips) * 100.0 / (qreal) totalClips); + totalClips = 0; + rectClips = 0; + regionClips = 0; + } + +} +#endif /*! \internal @@ -1240,6 +1268,10 @@ void QRasterPaintEngine::clip(const QVectorPath &path, Qt::ClipOperation op) d->solid_color_filler.clip = d->clip(); d->solid_color_filler.adjustSpanMethods(); + +#ifdef QT_CLIPPING_RATIOS + checkClipRatios(d); +#endif } @@ -1314,6 +1346,11 @@ void QRasterPaintEngine::clip(const QRect &rect, Qt::ClipOperation op) d->solid_color_filler.clip = d->clip(); d->solid_color_filler.adjustSpanMethods(); + + +#ifdef QT_CLIPPING_RATIOS + checkClipRatios(d); +#endif } /*! @@ -1528,7 +1565,7 @@ void QRasterPaintEngine::drawRects(const QRectF *rects, int rectCount) d->initializeRasterizer(&s->brushData); for (int i = 0; i < rectCount; ++i) { const QRectF &rect = rects[i].normalized(); - if (rects[i].isEmpty()) + if (rect.isEmpty()) continue; const QPointF a = s->matrix.map((rect.topLeft() + rect.bottomLeft()) * 0.5f); const QPointF b = s->matrix.map((rect.topRight() + rect.bottomRight()) * 0.5f); @@ -1701,10 +1738,10 @@ void QRasterPaintEngine::stroke(const QVectorPath &path, const QPen &pen) static inline QRect toNormalizedFillRect(const QRectF &rect) { - const int x1 = qFloor(rect.x() + aliasedCoordinateDelta); - const int y1 = qFloor(rect.y() + aliasedCoordinateDelta); - const int x2 = qFloor(rect.right() + aliasedCoordinateDelta); - const int y2 = qFloor(rect.bottom() + aliasedCoordinateDelta); + const int x1 = qRound(rect.x() + aliasedCoordinateDelta); + const int y1 = qRound(rect.y() + aliasedCoordinateDelta); + const int x2 = qRound(rect.right() + aliasedCoordinateDelta); + const int y2 = qRound(rect.bottom() + aliasedCoordinateDelta); return QRect(x1, y1, x2 - x1, y2 - y1).normalized(); } @@ -1906,7 +1943,6 @@ void QRasterPaintEngine::drawPath(const QPainterPath &path) } else { Q_ASSERT(s->stroker); d->outlineMapper->beginOutline(Qt::WindingFill); - extern bool qt_scaleForTransform(const QTransform &transform, qreal *scale); // qtransform.cpp qreal txscale = 1; if (s->pen.isCosmetic() || (qt_scaleForTransform(s->matrix, &txscale) && txscale != 1)) { const qreal strokeWidth = d->basicStroker.strokeWidth(); @@ -2355,11 +2391,6 @@ void QRasterPaintEngine::strokePolygonCosmetic(const QPoint *points, int pointCo } } -#define IMAGE_FROM_PIXMAP(pixmap) \ - pixmap.data->classId() == QPixmapData::RasterClass \ - ? ((QRasterPixmapData *) pixmap.data)->image \ - : pixmap.toImage() - /*! \internal */ @@ -2368,16 +2399,33 @@ void QRasterPaintEngine::drawPixmap(const QPointF &pos, const QPixmap &pixmap) #ifdef QT_DEBUG_DRAW qDebug() << " - QRasterPaintEngine::drawPixmap(), pos=" << pos << " pixmap=" << pixmap.size() << "depth=" << pixmap.depth(); #endif - if (pixmap.depth() == 1) { - Q_D(QRasterPaintEngine); - QRasterPaintEngineState *s = state(); - if (s->matrix.type() <= QTransform::TxTranslate) { - drawBitmap(pos + QPointF(s->matrix.dx(), s->matrix.dy()), pixmap, &s->penData); + + if (pixmap.data->classId() == QPixmapData::RasterClass) { + const QImage &image = ((QRasterPixmapData *) pixmap.data)->image; + if (image.depth() == 1) { + Q_D(QRasterPaintEngine); + QRasterPaintEngineState *s = state(); + if (s->matrix.type() <= QTransform::TxTranslate) { + drawBitmap(pos + QPointF(s->matrix.dx(), s->matrix.dy()), image, &s->penData); + } else { + drawImage(pos, d->rasterBuffer->colorizeBitmap(image, s->pen.color())); + } } else { - drawImage(pos, d->rasterBuffer->colorizeBitmap(IMAGE_FROM_PIXMAP(pixmap), s->pen.color())); + QRasterPaintEngine::drawImage(pos, image); } } else { - QRasterPaintEngine::drawImage(pos, IMAGE_FROM_PIXMAP(pixmap)); + const QImage image = pixmap.toImage(); + if (pixmap.depth() == 1) { + Q_D(QRasterPaintEngine); + QRasterPaintEngineState *s = state(); + if (s->matrix.type() <= QTransform::TxTranslate) { + drawBitmap(pos + QPointF(s->matrix.dx(), s->matrix.dy()), image, &s->penData); + } else { + drawImage(pos, d->rasterBuffer->colorizeBitmap(image, s->pen.color())); + } + } else { + QRasterPaintEngine::drawImage(pos, image); + } } } @@ -2390,22 +2438,40 @@ void QRasterPaintEngine::drawPixmap(const QRectF &r, const QPixmap &pixmap, cons qDebug() << " - QRasterPaintEngine::drawPixmap(), r=" << r << " sr=" << sr << " pixmap=" << pixmap.size() << "depth=" << pixmap.depth(); #endif - Q_D(QRasterPaintEngine); - QRasterPaintEngineState *s = state(); - - if (pixmap.depth() == 1) { - if (s->matrix.type() <= QTransform::TxTranslate - && r.size() == sr.size() - && r.size() == pixmap.size()) { - ensurePen(); - drawBitmap(r.topLeft() + QPointF(s->matrix.dx(), s->matrix.dy()), pixmap, &s->penData); - return; + if (pixmap.data->classId() == QPixmapData::RasterClass) { + const QImage &image = ((QRasterPixmapData *) pixmap.data)->image; + if (image.depth() == 1) { + Q_D(QRasterPaintEngine); + QRasterPaintEngineState *s = state(); + if (s->matrix.type() <= QTransform::TxTranslate + && r.size() == sr.size() + && r.size() == pixmap.size()) { + ensurePen(); + drawBitmap(r.topLeft() + QPointF(s->matrix.dx(), s->matrix.dy()), image, &s->penData); + return; + } else { + drawImage(r, d->rasterBuffer->colorizeBitmap(image, s->pen.color()), sr); + } } else { - drawImage(r, d->rasterBuffer->colorizeBitmap(IMAGE_FROM_PIXMAP(pixmap), - s->pen.color()), sr); + drawImage(r, image, sr); } } else { - drawImage(r, IMAGE_FROM_PIXMAP(pixmap), sr); + const QImage image = pixmap.toImage(); + if (image.depth() == 1) { + Q_D(QRasterPaintEngine); + QRasterPaintEngineState *s = state(); + if (s->matrix.type() <= QTransform::TxTranslate + && r.size() == sr.size() + && r.size() == pixmap.size()) { + ensurePen(); + drawBitmap(r.topLeft() + QPointF(s->matrix.dx(), s->matrix.dy()), image, &s->penData); + return; + } else { + drawImage(r, d->rasterBuffer->colorizeBitmap(image, s->pen.color()), sr); + } + } else { + drawImage(r, image, sr); + } } } @@ -2507,7 +2573,12 @@ void QRasterPaintEngine::drawImage(const QRectF &r, const QImage &img, const QRe QRasterPaintEngineState *s = state(); const bool aa = s->flags.antialiased || s->flags.bilinear; if (!aa && sr.size() == QSize(1, 1)) { + // as fillRect will apply the aliased coordinate delta we need to + // subtract it here as we don't use it for image drawing + QTransform old = s->matrix; + s->matrix = s->matrix * QTransform::fromTranslate(-aliasedCoordinateDelta, -aliasedCoordinateDelta); fillRect(r, QColor::fromRgba(img.pixel(sr.x(), sr.y()))); + s->matrix = old; return; } @@ -2541,6 +2612,18 @@ void QRasterPaintEngine::drawImage(const QRectF &r, const QImage &img, const QRe return; d->image_filler_xform.setupMatrix(copy, s->flags.bilinear); + if (!aa && s->matrix.type() == QTransform::TxScale) { + QRectF rr = s->matrix.mapRect(r); + + const int x1 = qRound(rr.x()); + const int y1 = qRound(rr.y()); + const int x2 = qRound(rr.right()); + const int y2 = qRound(rr.bottom()); + + fillRect_normalized(QRect(x1, y1, x2-x1, y2-y1), &d->image_filler_xform, d); + return; + } + #ifdef QT_FAST_SPANS ensureState(); if (s->flags.tx_noshear || s->matrix.type() == QTransform::TxScale) { @@ -2598,7 +2681,13 @@ void QRasterPaintEngine::drawImage(const QRectF &r, const QImage &img, const QRe QRectF rr = r; rr.translate(s->matrix.dx(), s->matrix.dy()); - fillRect_normalized(toRect_normalized(rr), &d->image_filler, d); + + const int x1 = qRound(rr.x()); + const int y1 = qRound(rr.y()); + const int x2 = qRound(rr.right()); + const int y2 = qRound(rr.bottom()); + + fillRect_normalized(QRect(x1, y1, x2-x1, y2-y1), &d->image_filler, d); } } @@ -2614,10 +2703,15 @@ void QRasterPaintEngine::drawTiledPixmap(const QRectF &r, const QPixmap &pixmap, QRasterPaintEngineState *s = state(); QImage image; - if (pixmap.depth() == 1) - image = d->rasterBuffer->colorizeBitmap(IMAGE_FROM_PIXMAP(pixmap), s->pen.color()); - else - image = IMAGE_FROM_PIXMAP(pixmap); + + if (pixmap.data->classId() == QPixmapData::RasterClass) { + image = ((QRasterPixmapData *) pixmap.data)->image; + } else { + image = pixmap.toImage(); + } + + if (image.depth() == 1) + image = d->rasterBuffer->colorizeBitmap(image, s->pen.color()); if (s->matrix.type() > QTransform::TxTranslate) { QTransform copy = s->matrix; @@ -3650,14 +3744,13 @@ void QRasterPaintEngine::drawBufferSpan(const uint *buffer, int bufsize, } #endif // Q_WS_QWS -void QRasterPaintEngine::drawBitmap(const QPointF &pos, const QPixmap &pm, QSpanData *fg) +void QRasterPaintEngine::drawBitmap(const QPointF &pos, const QImage &image, QSpanData *fg) { Q_ASSERT(fg); if (!fg->blend) return; Q_D(QRasterPaintEngine); - const QImage image = IMAGE_FROM_PIXMAP(pm); Q_ASSERT(image.depth() == 1); const int spanCount = 256; @@ -3665,8 +3758,8 @@ void QRasterPaintEngine::drawBitmap(const QPointF &pos, const QPixmap &pm, QSpan int n = 0; // Boundaries - int w = pm.width(); - int h = pm.height(); + int w = image.width(); + int h = image.height(); int ymax = qMin(qRound(pos.y() + h), d->rasterBuffer->height()); int ymin = qMax(qRound(pos.y()), 0); int xmax = qMin(qRound(pos.x() + w), d->rasterBuffer->width()); @@ -4335,6 +4428,9 @@ void QClipData::fixup() */ void QClipData::setClipRect(const QRect &rect) { + if (rect == clipRect) + return; + // qDebug() << "setClipRect" << clipSpanHeight << count << allocated << rect; hasRectClip = true; clipRect = rect; @@ -4344,6 +4440,11 @@ void QClipData::setClipRect(const QRect &rect) ymin = qMin(rect.y(), clipSpanHeight); ymax = qMin(rect.y() + rect.height(), clipSpanHeight); + if (m_spans) { + delete m_spans; + m_spans = 0; + } + // qDebug() << xmin << xmax << ymin << ymax; } @@ -4367,6 +4468,12 @@ void QClipData::setClipRegion(const QRegion ®ion) ymin = rect.y(); ymax = rect.y() + rect.height(); } + + if (m_spans) { + delete m_spans; + m_spans = 0; + } + } /*! @@ -5063,7 +5170,11 @@ void QSpanData::adjustSpanMethods() void QSpanData::setupMatrix(const QTransform &matrix, int bilin) { - QTransform inv = matrix.inverted(); + QTransform delta; + // make sure we round off correctly in qdrawhelper.cpp + delta.translate(1.0 / 65536, 1.0 / 65536); + + QTransform inv = (delta * matrix).inverted(); m11 = inv.m11(); m12 = inv.m12(); m13 = inv.m13(); diff --git a/src/gui/painting/qpaintengine_raster_p.h b/src/gui/painting/qpaintengine_raster_p.h index 0f8060a..26a2b3f 100644 --- a/src/gui/painting/qpaintengine_raster_p.h +++ b/src/gui/painting/qpaintengine_raster_p.h @@ -256,7 +256,7 @@ private: void init(); void fillRect(const QRectF &rect, QSpanData *data); - void drawBitmap(const QPointF &pos, const QPixmap &image, QSpanData *fill); + void drawBitmap(const QPointF &pos, const QImage &image, QSpanData *fill); void drawCachedGlyphs(const QPointF &p, const QTextItemInt &ti); diff --git a/src/gui/painting/qpaintengine_x11.cpp b/src/gui/painting/qpaintengine_x11.cpp index e9f1bb3..9cc9683 100644 --- a/src/gui/painting/qpaintengine_x11.cpp +++ b/src/gui/painting/qpaintengine_x11.cpp @@ -62,6 +62,7 @@ #include <private/qpaintengine_x11_p.h> #include <private/qfontengine_x11_p.h> #include <private/qwidget_p.h> +#include <private/qpainterpath_p.h> #include "qpen.h" #include "qcolor.h" @@ -1479,14 +1480,10 @@ void QX11PaintEngine::drawEllipse(const QRect &rect) return; } d->setupAdaptedOrigin(rect.topLeft()); - if (d->has_brush) { // draw filled ellipse - if (!d->has_pen) { - XFillArc(d->dpy, d->hd, d->gc_brush, x, y, w-1, h-1, 0, 360*64); + if (d->has_brush) { // draw filled ellipse + XFillArc(d->dpy, d->hd, d->gc_brush, x, y, w, h, 0, 360*64); + if (!d->has_pen) // make smoother outline XDrawArc(d->dpy, d->hd, d->gc_brush, x, y, w-1, h-1, 0, 360*64); - return; - } else{ - XFillArc(d->dpy, d->hd, d->gc_brush, x, y, w, h, 0, 360*64); - } } if (d->has_pen) // draw outline XDrawArc(d->dpy, d->hd, d->gc, x, y, w, h, 0, 360*64); @@ -1546,6 +1543,8 @@ void QX11PaintEnginePrivate::fillPolygon_dev(const QPointF *polygonPoints, int p QX11PaintEnginePrivate::GCMode gcMode, QPaintEngine::PolygonDrawMode mode) { + Q_Q(QX11PaintEngine); + int clippedCount = 0; qt_float_point *clippedPoints = 0; @@ -1620,7 +1619,29 @@ void QX11PaintEnginePrivate::fillPolygon_dev(const QPointF *polygonPoints, int p } else #endif if (fill.style() != Qt::NoBrush) { - if (clippedCount > 0) { + if (clippedCount > 200000) { + QPolygon poly; + for (int i = 0; i < clippedCount; ++i) + poly << QPoint(qFloor(clippedPoints[i].x), qFloor(clippedPoints[i].y)); + + const QRect bounds = poly.boundingRect(); + const QRect aligned = bounds + & QRect(QPoint(), QSize(pdev->width(), pdev->height())); + + QImage img(aligned.size(), QImage::Format_ARGB32_Premultiplied); + img.fill(0); + + QPainter painter(&img); + painter.translate(-aligned.x(), -aligned.y()); + painter.setPen(Qt::NoPen); + painter.setBrush(fill); + if (gcMode == BrushGC) + painter.setBrushOrigin(q->painter()->brushOrigin()); + painter.drawPolygon(poly); + painter.end(); + + q->drawImage(aligned, img, img.rect(), Qt::AutoColor); + } else if (clippedCount > 0) { QVarLengthArray<XPoint> xpoints(clippedCount); for (int i = 0; i < clippedCount; ++i) { xpoints[i].x = qFloor(clippedPoints[i].x); @@ -1760,9 +1781,14 @@ void QX11PaintEngine::drawPath(const QPainterPath &path) QPainterPath stroke; qreal width = d->cpen.widthF(); QPolygonF poly; + QRectF deviceRect(0, 0, d->pdev->width(), d->pdev->height()); // necessary to get aliased alphablended primitives to be drawn correctly if (d->cpen.isCosmetic() || d->has_scaling_xform) { - stroker.setWidth(width == 0 ? 1 : width * d->xform_scale); + if (d->cpen.isCosmetic()) + stroker.setWidth(width == 0 ? 1 : width); + else + stroker.setWidth(width * d->xform_scale); + stroker.d_ptr->stroker.setClipRect(deviceRect); stroke = stroker.createStroke(path * d->matrix); if (stroke.isEmpty()) return; @@ -1770,6 +1796,7 @@ void QX11PaintEngine::drawPath(const QPainterPath &path) d->fillPath(stroke, QX11PaintEnginePrivate::PenGC, false); } else { stroker.setWidth(width); + stroker.d_ptr->stroker.setClipRect(d->matrix.inverted().mapRect(deviceRect)); stroke = stroker.createStroke(path); if (stroke.isEmpty()) return; @@ -2349,7 +2376,9 @@ void QX11PaintEngine::drawFreetype(const QPointF &p, const QTextItemInt &ti) GlyphSet glyphSet = set->id; const QColor &pen = d->cpen.color(); ::Picture src = X11->getSolidFill(d->scrn, pen); - XRenderPictFormat *maskFormat = XRenderFindStandardFormat(X11->display, ft->xglyph_format); + XRenderPictFormat *maskFormat = 0; + if (ft->xglyph_format != PictStandardA1) + maskFormat = XRenderFindStandardFormat(X11->display, ft->xglyph_format); enum { t_min = SHRT_MIN, t_max = SHRT_MAX }; diff --git a/src/gui/painting/qpaintengineex.cpp b/src/gui/painting/qpaintengineex.cpp index 72dd189..8eaad60 100644 --- a/src/gui/painting/qpaintengineex.cpp +++ b/src/gui/painting/qpaintengineex.cpp @@ -258,6 +258,8 @@ QPainterState *QPaintEngineEx::createState(QPainterState *orig) const return new QPainterState(orig); } +extern bool qt_scaleForTransform(const QTransform &transform, qreal *scale); // qtransform.cpp + void QPaintEngineEx::stroke(const QVectorPath &path, const QPen &pen) { #ifdef QT_DEBUG_DRAW @@ -326,7 +328,6 @@ void QPaintEngineEx::stroke(const QVectorPath &path, const QPen &pen) flags |= QVectorPath::CurvedShapeHint; // ### Perspective Xforms are currently not supported... - extern bool qt_scaleForTransform(const QTransform &transform, qreal *scale); // qtransform.cpp qreal txscale = 1; if (!(pen.isCosmetic() || (qt_scaleForTransform(state()->matrix, &txscale) && txscale != 1))) { // We include cosmetic pens in this case to avoid having to diff --git a/src/gui/painting/qpainter.cpp b/src/gui/painting/qpainter.cpp index 1f61e2f..cc48d24 100644 --- a/src/gui/painting/qpainter.cpp +++ b/src/gui/painting/qpainter.cpp @@ -1293,7 +1293,7 @@ void QPainterPrivate::updateState(QPainterState *newState) destination. Note that composition transformation operates pixelwise. For that - reason, there is a difference between using the grahic primitive + reason, there is a difference between using the graphic primitive itself and its bounding rectangle: The bounding rect contains pixels with alpha == 0 (i.e the pixels surrounding the primitive). These pixels will overwrite the other image's pixels, @@ -1465,8 +1465,8 @@ bool QPainter::isActive() const /*! Initializes the painters pen, background and font to the same as - the given \a widget. Call this function after begin() while the - painter is active. + the given \a widget. This function is called automatically when the + painter is opened on a QWidget. \sa begin(), {QPainter#Settings}{Settings} */ @@ -1484,7 +1484,9 @@ void QPainter::initFrom(const QWidget *widget) d->state->bgBrush = pal.brush(widget->backgroundRole()); d->state->deviceFont = QFont(widget->font(), const_cast<QWidget*> (widget)); d->state->font = d->state->deviceFont; - if (d->engine) { + if (d->extended) { + d->extended->penChanged(); + } else if (d->engine) { d->engine->setDirty(QPaintEngine::DirtyPen); d->engine->setDirty(QPaintEngine::DirtyBrush); d->engine->setDirty(QPaintEngine::DirtyFont); @@ -2371,6 +2373,11 @@ void QPainter::setClipping(bool enable) Returns the currently set clip region. Note that the clip region is given in logical coordinates. + \warning QPainter does not store the combined clip explicitly as + this is handled by the underlying QPaintEngine, so the path is + recreated on demand and transformed to the current logical + coordinate system. This is potentially an expensive operation. + \sa setClipRegion(), clipPath(), setClipping() */ @@ -2391,7 +2398,6 @@ QRegion QPainter::clipRegion() const // ### Falcon: Use QPainterPath for (int i=0; i<d->state->clipInfo.size(); ++i) { const QPainterClipInfo &info = d->state->clipInfo.at(i); - QRegion other; switch (info.clipType) { case QPainterClipInfo::RegionClip: { @@ -2444,15 +2450,20 @@ QRegion QPainter::clipRegion() const lastWasNothing = false; continue; } - if (info.operation == Qt::IntersectClip) - region &= QRegion(info.rect) * matrix; - else if (info.operation == Qt::UniteClip) + if (info.operation == Qt::IntersectClip) { + // Use rect intersection if possible. + if (matrix.type() <= QTransform::TxScale) + region &= matrix.mapRect(info.rect); + else + region &= matrix.map(QRegion(info.rect)); + } else if (info.operation == Qt::UniteClip) { region |= QRegion(info.rect) * matrix; - else if (info.operation == Qt::NoClip) { + } else if (info.operation == Qt::NoClip) { lastWasNothing = true; region = QRegion(); - } else + } else { region = QRegion(info.rect) * matrix; + } break; } @@ -2463,15 +2474,20 @@ QRegion QPainter::clipRegion() const lastWasNothing = false; continue; } - if (info.operation == Qt::IntersectClip) - region &= QRegion(info.rectf.toRect()) * matrix; - else if (info.operation == Qt::UniteClip) + if (info.operation == Qt::IntersectClip) { + // Use rect intersection if possible. + if (matrix.type() <= QTransform::TxScale) + region &= matrix.mapRect(info.rectf.toRect()); + else + region &= matrix.map(QRegion(info.rectf.toRect())); + } else if (info.operation == Qt::UniteClip) { region |= QRegion(info.rectf.toRect()) * matrix; - else if (info.operation == Qt::NoClip) { + } else if (info.operation == Qt::NoClip) { lastWasNothing = true; region = QRegion(); - } else + } else { region = QRegion(info.rectf.toRect()) * matrix; + } break; } } @@ -2480,10 +2496,17 @@ QRegion QPainter::clipRegion() const return region; } +extern QPainterPath qt_regionToPath(const QRegion ®ion); + /*! Returns the currently clip as a path. Note that the clip path is given in logical coordinates. + \warning QPainter does not store the combined clip explicitly as + this is handled by the underlying QPaintEngine, so the path is + recreated on demand and transformed to the current logical + coordinate system. This is potentially an expensive operation. + \sa setClipPath(), clipRegion(), setClipping() */ QPainterPath QPainter::clipPath() const @@ -2520,7 +2543,6 @@ QPainterPath QPainter::clipPath() const return path * matrix; } else { // Fallback to clipRegion() for now, since we don't have isect/unite for paths - extern QPainterPath qt_regionToPath(const QRegion ®ion); return qt_regionToPath(clipRegion()); } } @@ -3084,6 +3106,9 @@ void QPainter::strokePath(const QPainterPath &path, const QPen &pen) return; } + if (path.isEmpty()) + return; + if (d->extended) { const QGradient *g = qpen_brush(pen).gradient(); if (!g || g->coordinateMode() == QGradient::LogicalMode) { @@ -3124,6 +3149,9 @@ void QPainter::fillPath(const QPainterPath &path, const QBrush &brush) return; } + if (path.isEmpty()) + return; + if (d->extended) { const QGradient *g = brush.gradient(); if (!g || g->coordinateMode() == QGradient::LogicalMode) { @@ -5114,6 +5142,11 @@ void QPainter::drawConvexPolygon(const QPointF *points, int pointCount) d->engine->drawPolygon(points, pointCount, QPaintEngine::ConvexMode); } +static inline QPointF roundInDeviceCoordinates(const QPointF &p, const QTransform &m) +{ + return m.inverted().map(QPointF(m.map(p).toPoint())); +} + /*! \fn void QPainter::drawPixmap(const QRectF &target, const QPixmap &pixmap, const QRectF &source) @@ -5148,7 +5181,7 @@ void QPainter::drawPixmap(const QPointF &p, const QPixmap &pm) Q_D(QPainter); - if (!d->engine || pm.isNull()) + if (!d->engine) return; #ifndef QT_NO_DEBUG @@ -5166,6 +5199,9 @@ void QPainter::drawPixmap(const QPointF &p, const QPixmap &pm) int w = pm.width(); int h = pm.height(); + if (w <= 0) + return; + // Emulate opaque background for bitmaps if (d->state->bgMode == Qt::OpaqueMode && pm.isQBitmap()) { fillRect(QRectF(x, y, w, h), d->state->bgBrush.color()); @@ -5179,11 +5215,12 @@ void QPainter::drawPixmap(const QPointF &p, const QPixmap &pm) || (d->state->opacity != 1.0 && !d->engine->hasFeature(QPaintEngine::ConstantOpacity))) { save(); - // If there is no scaling or transformation involved we have to make sure we use the + // If there is no rotation involved we have to make sure we use the // antialiased and not the aliased coordinate system by rounding the coordinates. - if (d->state->matrix.type() <= QTransform::TxTranslate) { - x = qRound(x + d->state->matrix.dx()) - d->state->matrix.dx(); - y = qRound(y + d->state->matrix.dy()) - d->state->matrix.dy(); + if (d->state->matrix.type() <= QTransform::TxScale) { + const QPointF p = roundInDeviceCoordinates(QPointF(x, y), d->state->matrix); + x = p.x(); + y = p.y(); } translate(x, y); setBackgroundMode(Qt::TransparentMode); @@ -5293,16 +5330,21 @@ void QPainter::drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr) || ((sw != w || sh != h) && !d->engine->hasFeature(QPaintEngine::PixmapTransform))) { save(); - // If there is no scaling or transformation involved we have to make sure we use the + // If there is no rotation involved we have to make sure we use the // antialiased and not the aliased coordinate system by rounding the coordinates. + if (d->state->matrix.type() <= QTransform::TxScale) { + const QPointF p = roundInDeviceCoordinates(QPointF(x, y), d->state->matrix); + x = p.x(); + y = p.y(); + } + if (d->state->matrix.type() <= QTransform::TxTranslate && sw == w && sh == h) { - x = qRound(x + d->state->matrix.dx()) - d->state->matrix.dx(); - y = qRound(y + d->state->matrix.dy()) - d->state->matrix.dy(); sx = qRound(sx); sy = qRound(sy); sw = qRound(sw); sh = qRound(sh); } + translate(x, y); scale(w / sw, h / sh); setBackgroundMode(Qt::TransparentMode); @@ -5452,11 +5494,12 @@ void QPainter::drawImage(const QPointF &p, const QImage &image) || (d->state->opacity != 1.0 && !d->engine->hasFeature(QPaintEngine::ConstantOpacity))) { save(); - // If there is no scaling or transformation involved we have to make sure we use the + // If there is no rotation involved we have to make sure we use the // antialiased and not the aliased coordinate system by rounding the coordinates. - if (d->state->matrix.type() <= QTransform::TxTranslate) { - x = qRound(x + d->state->matrix.dx()) - d->state->matrix.dx(); - y = qRound(y + d->state->matrix.dy()) - d->state->matrix.dy(); + if (d->state->matrix.type() <= QTransform::TxScale) { + const QPointF p = roundInDeviceCoordinates(QPointF(x, y), d->state->matrix); + x = p.x(); + y = p.y(); } translate(x, y); setBackgroundMode(Qt::TransparentMode); @@ -5555,11 +5598,15 @@ void QPainter::drawImage(const QRectF &targetRect, const QImage &image, const QR || (d->state->opacity != 1.0 && !d->engine->hasFeature(QPaintEngine::ConstantOpacity))) { save(); - // If there is no scaling or transformation involved we have to make sure we use the + // If there is no rotation involved we have to make sure we use the // antialiased and not the aliased coordinate system by rounding the coordinates. + if (d->state->matrix.type() <= QTransform::TxScale) { + const QPointF p = roundInDeviceCoordinates(QPointF(x, y), d->state->matrix); + x = p.x(); + y = p.y(); + } + if (d->state->matrix.type() <= QTransform::TxTranslate && sw == w && sh == h) { - x = qRound(x + d->state->matrix.dx()) - d->state->matrix.dx(); - y = qRound(y + d->state->matrix.dy()) - d->state->matrix.dy(); sx = qRound(sx); sy = qRound(sy); sw = qRound(sw); @@ -6302,17 +6349,18 @@ void QPainter::drawTiledPixmap(const QRectF &r, const QPixmap &pixmap, const QPo setBrush(QBrush(d->state->pen.color(), pixmap)); setPen(Qt::NoPen); - // If there is no scaling or transformation involved we have to make sure we use the + // If there is no rotation involved we have to make sure we use the // antialiased and not the aliased coordinate system by rounding the coordinates. - if (d->state->matrix.type() <= QTransform::TxTranslate) { - qreal x = qRound(r.x() + d->state->matrix.dx()) - d->state->matrix.dx(); - qreal y = qRound(r.y() + d->state->matrix.dy()) - d->state->matrix.dy(); - qreal w = qRound(r.width()); - qreal h = qRound(r.height()); - sx = qRound(sx); - sy = qRound(sy); + if (d->state->matrix.type() <= QTransform::TxScale) { + const QPointF p = roundInDeviceCoordinates(r.topLeft(), d->state->matrix); + + if (d->state->matrix.type() <= QTransform::TxTranslate) { + sx = qRound(sx); + sy = qRound(sy); + } + setBrushOrigin(QPointF(r.x()-sx, r.y()-sy)); - drawRect(QRectF(x, y, w, h)); + drawRect(QRectF(p, r.size())); } else { setBrushOrigin(QPointF(r.x()-sx, r.y()-sy)); drawRect(r); @@ -7111,14 +7159,14 @@ QPoint QPainter::xFormDev(const QPoint &p) const \fn QRect QPainter::xFormDev(const QRect &rectangle) const \overload - Use combineMatrix() combined with QMatrix::inverted() instead. + Use mapRect() combined with QMatrix::inverted() instead. \oldcode QPainter painter(this); QRect transformed = painter.xFormDev(rectangle); \newcode QPainter painter(this); - QRect transformed = rectangle * painter.combinedMatrix().inverted(); + QRect transformed = painter.combinedMatrix().inverted(rectangle); \endcode */ @@ -8523,4 +8571,252 @@ void qt_draw_helper(QPainterPrivate *p, const QPainterPath &path, QPainterPrivat p->draw_helper(path, operation); } +/*! \fn Display *QPaintDevice::x11Display() const + Use QX11Info::display() instead. + + \oldcode + Display *display = widget->x11Display(); + \newcode + Display *display = QX11Info::display(); + \endcode + + \sa QWidget::x11Info(), QX11Info::display() +*/ + +/*! \fn int QPaintDevice::x11Screen() const + Use QX11Info::screen() instead. + + \oldcode + int screen = widget->x11Screen(); + \newcode + int screen = widget->x11Info().screen(); + \endcode + + \sa QWidget::x11Info(), QPixmap::x11Info() +*/ + +/*! \fn void *QPaintDevice::x11Visual() const + Use QX11Info::visual() instead. + + \oldcode + void *visual = widget->x11Visual(); + \newcode + void *visual = widget->x11Info().visual(); + \endcode + + \sa QWidget::x11Info(), QPixmap::x11Info() +*/ + +/*! \fn int QPaintDevice::x11Depth() const + Use QX11Info::depth() instead. + + \oldcode + int depth = widget->x11Depth(); + \newcode + int depth = widget->x11Info().depth(); + \endcode + + \sa QWidget::x11Info(), QPixmap::x11Info() +*/ + +/*! \fn int QPaintDevice::x11Cells() const + Use QX11Info::cells() instead. + + \oldcode + int cells = widget->x11Cells(); + \newcode + int cells = widget->x11Info().cells(); + \endcode + + \sa QWidget::x11Info(), QPixmap::x11Info() +*/ + +/*! \fn Qt::HANDLE QPaintDevice::x11Colormap() const + Use QX11Info::colormap() instead. + + \oldcode + unsigned long screen = widget->x11Colormap(); + \newcode + unsigned long screen = widget->x11Info().colormap(); + \endcode + + \sa QWidget::x11Info(), QPixmap::x11Info() +*/ + +/*! \fn bool QPaintDevice::x11DefaultColormap() const + Use QX11Info::defaultColormap() instead. + + \oldcode + bool isDefault = widget->x11DefaultColormap(); + \newcode + bool isDefault = widget->x11Info().defaultColormap(); + \endcode + + \sa QWidget::x11Info(), QPixmap::x11Info() +*/ + +/*! \fn bool QPaintDevice::x11DefaultVisual() const + Use QX11Info::defaultVisual() instead. + + \oldcode + bool isDefault = widget->x11DefaultVisual(); + \newcode + bool isDefault = widget->x11Info().defaultVisual(); + \endcode + + \sa QWidget::x11Info(), QPixmap::x11Info() +*/ + +/*! \fn void *QPaintDevice::x11AppVisual(int screen) + Use QX11Info::visual() instead. + + \oldcode + void *visual = QPaintDevice::x11AppVisual(screen); + \newcode + void *visual = qApp->x11Info(screen).visual(); + \endcode + + \sa QWidget::x11Info(), QPixmap::x11Info() +*/ + +/*! \fn Qt::HANDLE QPaintDevice::x11AppColormap(int screen) + Use QX11Info::colormap() instead. + + \oldcode + unsigned long colormap = QPaintDevice::x11AppColormap(screen); + \newcode + unsigned long colormap = qApp->x11Info(screen).colormap(); + \endcode + + \sa QWidget::x11Info(), QPixmap::x11Info() +*/ + +/*! \fn Display *QPaintDevice::x11AppDisplay() + Use QX11Info::display() instead. + + \oldcode + Display *display = QPaintDevice::x11AppDisplay(); + \newcode + Display *display = qApp->x11Info().display(); + \endcode + + \sa QWidget::x11Info(), QPixmap::x11Info() +*/ + +/*! \fn int QPaintDevice::x11AppScreen() + Use QX11Info::screen() instead. + + \oldcode + int screen = QPaintDevice::x11AppScreen(); + \newcode + int screen = qApp->x11Info().screen(); + \endcode + + \sa QWidget::x11Info(), QPixmap::x11Info() +*/ + +/*! \fn int QPaintDevice::x11AppDepth(int screen) + Use QX11Info::depth() instead. + + \oldcode + int depth = QPaintDevice::x11AppDepth(screen); + \newcode + int depth = qApp->x11Info(screen).depth(); + \endcode + + \sa QWidget::x11Info(), QPixmap::x11Info() +*/ + +/*! \fn int QPaintDevice::x11AppCells(int screen) + Use QX11Info::cells() instead. + + \oldcode + int cells = QPaintDevice::x11AppCells(screen); + \newcode + int cells = qApp->x11Info(screen).cells(); + \endcode + + \sa QWidget::x11Info(), QPixmap::x11Info() +*/ + +/*! \fn Qt::HANDLE QPaintDevice::x11AppRootWindow(int screen) + Use QX11Info::appRootWindow() instead. + + \oldcode + unsigned long window = QPaintDevice::x11AppRootWindow(screen); + \newcode + unsigned long window = qApp->x11Info(screen).appRootWindow(); + \endcode + + \sa QWidget::x11Info(), QPixmap::x11Info() +*/ + +/*! \fn bool QPaintDevice::x11AppDefaultColormap(int screen) + Use QX11Info::defaultColormap() instead. + + \oldcode + bool isDefault = QPaintDevice::x11AppDefaultColormap(screen); + \newcode + bool isDefault = qApp->x11Info(screen).defaultColormap(); + \endcode + + \sa QWidget::x11Info(), QPixmap::x11Info() +*/ + +/*! \fn bool QPaintDevice::x11AppDefaultVisual(int screen) + Use QX11Info::defaultVisual() instead. + + \oldcode + bool isDefault = QPaintDevice::x11AppDefaultVisual(screen); + \newcode + bool isDefault = qApp->x11Info(screen).defaultVisual(); + \endcode + + \sa QWidget::x11Info(), QPixmap::x11Info() +*/ + +/*! \fn void QPaintDevice::x11SetAppDpiX(int dpi, int screen) + Use QX11Info::setAppDpiX() instead. +*/ + +/*! \fn void QPaintDevice::x11SetAppDpiY(int dpi, int screen) + Use QX11Info::setAppDpiY() instead. +*/ + +/*! \fn int QPaintDevice::x11AppDpiX(int screen) + Use QX11Info::appDpiX() instead. + + \oldcode + bool isDefault = QPaintDevice::x11AppDpiX(screen); + \newcode + bool isDefault = qApp->x11Info(screen).appDpiX(); + \endcode + + \sa QWidget::x11Info(), QPixmap::x11Info() +*/ + +/*! \fn int QPaintDevice::x11AppDpiY(int screen) + Use QX11Info::appDpiY() instead. + + \oldcode + bool isDefault = QPaintDevice::x11AppDpiY(screen); + \newcode + bool isDefault = qApp->x11Info(screen).appDpiY(); + \endcode + + \sa QWidget::x11Info(), QPixmap::x11Info() +*/ + +/*! \fn HDC QPaintDevice::getDC() const + \internal +*/ + +/*! \fn void QPaintDevice::releaseDC(HDC) const + \internal +*/ + +/*! \fn QWSDisplay *QPaintDevice::qwsDisplay() + \internal +*/ + QT_END_NAMESPACE diff --git a/src/gui/painting/qpainterpath.cpp b/src/gui/painting/qpainterpath.cpp index bb07f81..e1f5eea 100644 --- a/src/gui/painting/qpainterpath.cpp +++ b/src/gui/painting/qpainterpath.cpp @@ -1725,7 +1725,7 @@ static void qt_painterpath_isect_curve(const QBezier &bezier, const QPointF &pt, */ bool QPainterPath::contains(const QPointF &pt) const { - if (isEmpty()) + if (isEmpty() || !controlPointRect().contains(pt)) return false; QPainterPathData *d = d_func(); @@ -2387,21 +2387,13 @@ void qt_path_stroke_cubic_to(qfixed c1x, qfixed c1y, \sa QPen, QBrush */ -class QPainterPathStrokerPrivate +QPainterPathStrokerPrivate::QPainterPathStrokerPrivate() + : dashOffset(0) { -public: - QPainterPathStrokerPrivate() - : dashOffset(0) - { - stroker.setMoveToHook(qt_path_stroke_move_to); - stroker.setLineToHook(qt_path_stroke_line_to); - stroker.setCubicToHook(qt_path_stroke_cubic_to); - } - - QStroker stroker; - QVector<qfixed> dashPattern; - qreal dashOffset; -}; + stroker.setMoveToHook(qt_path_stroke_move_to); + stroker.setLineToHook(qt_path_stroke_line_to); + stroker.setCubicToHook(qt_path_stroke_cubic_to); +} /*! Creates a new stroker. @@ -2445,6 +2437,7 @@ QPainterPath QPainterPathStroker::createStroke(const QPainterPath &path) const QDashStroker dashStroker(&d->stroker); dashStroker.setDashPattern(d->dashPattern); dashStroker.setDashOffset(d->dashOffset); + dashStroker.setClipRect(d->stroker.clipRect()); dashStroker.strokePath(path, &stroke, QTransform()); } stroke.setFillRule(Qt::WindingFill); diff --git a/src/gui/painting/qpainterpath.h b/src/gui/painting/qpainterpath.h index 88fb19d..6cd2af8 100644 --- a/src/gui/painting/qpainterpath.h +++ b/src/gui/painting/qpainterpath.h @@ -277,6 +277,8 @@ public: QPainterPath createStroke(const QPainterPath &path) const; private: + friend class QX11PaintEngine; + QPainterPathStrokerPrivate *d_ptr; }; diff --git a/src/gui/painting/qpainterpath_p.h b/src/gui/painting/qpainterpath_p.h index 93f9704..29c48df 100644 --- a/src/gui/painting/qpainterpath_p.h +++ b/src/gui/painting/qpainterpath_p.h @@ -61,9 +61,20 @@ #include <qdebug.h> #include <private/qvectorpath_p.h> +#include <private/qstroker_p.h> QT_BEGIN_NAMESPACE +class QPainterPathStrokerPrivate +{ +public: + QPainterPathStrokerPrivate(); + + QStroker stroker; + QVector<qfixed> dashPattern; + qreal dashOffset; +}; + class QPolygonF; class QVectorPathConverter; diff --git a/src/gui/painting/qpdf.cpp b/src/gui/painting/qpdf.cpp index 4a87f6a..55006f6 100644 --- a/src/gui/painting/qpdf.cpp +++ b/src/gui/painting/qpdf.cpp @@ -1106,6 +1106,11 @@ void QPdfBaseEngine::drawTextItem(const QPointF &p, const QTextItem &textItem) if (!d->hasPen || (d->clipEnabled && d->allClipped)) return; + if (d->stroker.matrix.type() >= QTransform::TxProject) { + QPaintEngine::drawTextItem(p, textItem); + return; + } + *d->currentPage << "q\n"; if(!d->simplePen) *d->currentPage << QPdf::generateMatrix(d->stroker.matrix); @@ -1226,6 +1231,8 @@ void QPdfBaseEngine::setupGraphicsState(QPaintEngine::DirtyFlags flags) setPen(); } +extern QPainterPath qt_regionToPath(const QRegion ®ion); + void QPdfBaseEngine::updateClipPath(const QPainterPath &p, Qt::ClipOperation op) { Q_D(QPdfBaseEngine); @@ -1252,7 +1259,6 @@ void QPdfBaseEngine::updateClipPath(const QPainterPath &p, Qt::ClipOperation op) // if we have an alpha region, we have to subtract that from the // any existing clip region since that region will be filled in // later with images - extern QPainterPath qt_regionToPath(const QRegion ®ion); QPainterPath alphaClip = qt_regionToPath(alphaClipping()); if (!alphaClip.isEmpty()) { if (!d->clipEnabled) { diff --git a/src/gui/painting/qprintengine_mac.mm b/src/gui/painting/qprintengine_mac.mm index 7a77e47..b1216b7 100644 --- a/src/gui/painting/qprintengine_mac.mm +++ b/src/gui/painting/qprintengine_mac.mm @@ -62,6 +62,10 @@ bool QMacPrintEngine::begin(QPaintDevice *dev) { Q_D(QMacPrintEngine); + Q_ASSERT(dev && dev->devType() == QInternal::Printer); + if (!static_cast<QPrinter *>(dev)->isValid()) + return false; + if (d->state == QPrinter::Idle && !d->isPrintSessionInitialized()) // Need to reinitialize d->initialize(); @@ -121,24 +125,8 @@ bool QMacPrintEngine::end() if(d->paintEngine->type() == QPaintEngine::CoreGraphics) static_cast<QCoreGraphicsPaintEngine*>(d->paintEngine)->d_func()->hd = 0; d->paintEngine->end(); - if (d->state != QPrinter::Idle) { -#ifndef QT_MAC_USE_COCOA - if (d->shouldSuppressStatus()) { - PMSessionEndPageNoDialog(d->session); - PMSessionEndDocumentNoDialog(d->session); - } else { - PMSessionEndPage(d->session); - PMSessionEndDocument(d->session); - } - PMRelease(d->session); -#else - PMSessionEndPageNoDialog(d->session); - PMSessionEndDocumentNoDialog(d->session); - [d->printInfo release]; -#endif - d->printInfo = 0; - d->session = 0; - } + if (d->state != QPrinter::Idle) + d->releaseSession(); d->state = QPrinter::Idle; return true; } @@ -509,6 +497,26 @@ void QMacPrintEnginePrivate::initialize() } } +void QMacPrintEnginePrivate::releaseSession() +{ +#ifndef QT_MAC_USE_COCOA + if (shouldSuppressStatus()) { + PMSessionEndPageNoDialog(session); + PMSessionEndDocumentNoDialog(session); + } else { + PMSessionEndPage(session); + PMSessionEndDocument(session); + } + PMRelease(session); +#else + PMSessionEndPageNoDialog(session); + PMSessionEndDocumentNoDialog(session); + [printInfo release]; +#endif + printInfo = 0; + session = 0; +} + bool QMacPrintEnginePrivate::newPage_helper() { Q_Q(QMacPrintEngine); @@ -737,6 +745,7 @@ void QMacPrintEngine::setProperty(PrintEnginePropertyKey key, const QVariant &va d->setPaperSize(QPrinter::PaperSize(value.toInt())); break; case PPK_PrinterName: { + bool printerNameSet = false; OSStatus status = noErr; QCFType<CFArrayRef> printerList; status = PMServerCreatePrinterList(kPMServerLocal, &printerList); @@ -747,12 +756,18 @@ void QMacPrintEngine::setProperty(PrintEnginePropertyKey key, const QVariant &va QString name = QCFString::toQString(PMPrinterGetName(printer)); if (name == value.toString()) { status = PMSessionSetCurrentPMPrinter(d->session, printer); + printerNameSet = true; break; } } } if (status != noErr) qWarning("QMacPrintEngine::setPrinterName: Error setting printer: %ld", long(status)); + if (!printerNameSet) { + qWarning("QMacPrintEngine::setPrinterName: Failed to set printer named '%s'.", qPrintable(value.toString())); + d->releaseSession(); + d->state = QPrinter::Idle; + } break; } case PPK_SuppressSystemPrintStatus: d->suppressStatus = value.toBool(); @@ -876,17 +891,12 @@ QVariant QMacPrintEngine::property(PrintEnginePropertyKey key) const ret = r; break; } case PPK_PrinterName: { - CFIndex currIndex; - PMPrinter unused; - QCFType<CFArrayRef> printerList; - OSStatus status = PMSessionCreatePrinterList(d->session, &printerList, &currIndex, &unused); + PMPrinter printer; + OSStatus status = PMSessionGetCurrentPrinter(d->session, &printer); if (status != noErr) - qWarning("QMacPrintEngine::printerName: Problem getting list of printers: %ld", long(status)); - if (currIndex != -1 && printerList && currIndex < CFArrayGetCount(printerList)) { - const CFStringRef name = static_cast<CFStringRef>(CFArrayGetValueAtIndex(printerList, currIndex)); - if (name) - ret = QCFString::toQString(name); - } + qWarning("QMacPrintEngine::printerName: Failed getting current PMPrinter: %ld", long(status)); + if (printer) + ret = QCFString::toQString(PMPrinterGetName(printer)); break; } case PPK_Resolution: { ret = d->resolution.hRes; diff --git a/src/gui/painting/qprintengine_mac_p.h b/src/gui/painting/qprintengine_mac_p.h index 5e18845..bc917e7 100644 --- a/src/gui/painting/qprintengine_mac_p.h +++ b/src/gui/painting/qprintengine_mac_p.h @@ -143,6 +143,7 @@ public: hasCustomPaperSize(false), hasCustomPageMargins(false) {} ~QMacPrintEnginePrivate(); void initialize(); + void releaseSession(); bool newPage_helper(); void setPaperSize(QPrinter::PaperSize ps); QPrinter::PaperSize paperSize() const; diff --git a/src/gui/painting/qprintengine_win.cpp b/src/gui/painting/qprintengine_win.cpp index fdd44ba..7601beb 100644 --- a/src/gui/painting/qprintengine_win.cpp +++ b/src/gui/painting/qprintengine_win.cpp @@ -58,12 +58,13 @@ QT_BEGIN_NAMESPACE +extern QPainterPath qt_regionToPath(const QRegion ®ion); + // #define QT_DEBUG_DRAW static void draw_text_item_win(const QPointF &_pos, const QTextItemInt &ti, HDC hdc, bool convertToText, const QTransform &xform, const QPointF &topLeft); - static const struct { int winSizeName; QPrinter::PaperSize qtSizeName; @@ -368,7 +369,7 @@ void QWin32PrintEngine::drawTextItem(const QPointF &p, const QTextItem &textItem QRgb brushColor = state->pen().brush().color().rgb(); bool fallBack = state->pen().brush().style() != Qt::SolidPattern || qAlpha(brushColor) != 0xff - || QT_WA_INLINE(false, d->txop >= QTransform::TxScale) + || QT_WA_INLINE(d->txop >= QTransform::TxProject, d->txop >= QTransform::TxScale) || ti.fontEngine->type() != QFontEngine::Win; @@ -586,7 +587,6 @@ void QWin32PrintEngine::updateState(const QPaintEngineState &state) if (state.state() & DirtyClipRegion) { QRegion clipRegion = state.clipRegion(); - extern QPainterPath qt_regionToPath(const QRegion ®ion); QPainterPath clipPath = qt_regionToPath(clipRegion); updateClipPath(clipPath, state.clipOperation()); } @@ -621,7 +621,6 @@ void QWin32PrintEngine::updateClipPath(const QPainterPath &clipPath, Qt::ClipOpe } } - extern QPainterPath qt_regionToPath(const QRegion ®ion); QPainterPath aclip = qt_regionToPath(alphaClipping()); if (!aclip.isEmpty()) { QTransform tx(d->stretch_x, 0, 0, d->stretch_y, d->origin_x, d->origin_y); @@ -1533,7 +1532,7 @@ QVariant QWin32PrintEngine::property(PrintEnginePropertyKey key) const value = rect; } else { value = QTransform(1/d->stretch_x, 0, 0, 1/d->stretch_y, 0, 0) - .mapRect(d->fullPage ? d->devPaperRect : d->devPageRect); + .mapRect(d->fullPage ? d->devPhysicalPageRect : d->devPageRect); } break; diff --git a/src/gui/painting/qprinter.cpp b/src/gui/painting/qprinter.cpp index 413f4a1..5090b3a 100644 --- a/src/gui/painting/qprinter.cpp +++ b/src/gui/painting/qprinter.cpp @@ -285,6 +285,10 @@ void QPrinterPrivate::addToManualSetList(QPrintEngine::PrintEnginePropertyKey ke the printProgram() function can be used to specify the command or utility to use instead of the system default. + Note that setting parameters like paper size and resolution on an + invalid printer is undefined. You can use QPrinter::isValid() to + verify this before changing any parameters. + QPrinter supports a number of parameters, most of which can be changed by the end user through a \l{QPrintDialog}{print dialog}. In general, QPrinter passes these functions onto the underlying QPrintEngine. @@ -740,7 +744,7 @@ void QPrinter::setOutputFormat(OutputFormat format) #ifndef QT_NO_PDF Q_D(QPrinter); - if (d->outputFormat == format) + if (d->validPrinter && d->outputFormat == format) return; d->outputFormat = format; @@ -769,8 +773,8 @@ void QPrinter::setOutputFormat(OutputFormat format) if (def_engine) delete oldPrintEngine; - d->validPrinter = d->outputFormat == QPrinter::PdfFormat || d->outputFormat == QPrinter::PostScriptFormat; - + if (d->outputFormat == QPrinter::PdfFormat || d->outputFormat == QPrinter::PostScriptFormat) + d->validPrinter = true; #else Q_UNUSED(format); #endif @@ -849,7 +853,7 @@ void QPrinter::setPrinterName(const QString &name) Returns true if the printer currently selected is a valid printer in the system, or a pure PDF/PostScript printer; otherwise returns false. - To detect other failures check the output of QPainter::begin() or QPainter::nextPage(). + To detect other failures check the output of QPainter::begin() or QPrinter::newPage(). \snippet doc/src/snippets/printing-qprinter/errors.cpp 0 diff --git a/src/gui/painting/qregion.cpp b/src/gui/painting/qregion.cpp index f728f9d..c88af7c 100644 --- a/src/gui/painting/qregion.cpp +++ b/src/gui/painting/qregion.cpp @@ -40,6 +40,7 @@ ****************************************************************************/ #include "qregion.h" +#include "qpainterpath.h" #include "qpolygon.h" #include "qbuffer.h" #include "qdatastream.h" @@ -49,7 +50,6 @@ #include <qdebug.h> #if defined(Q_OS_UNIX) || defined(Q_OS_WINCE) -#include "qpainterpath.h" #include "qimage.h" #include "qbitmap.h" #include <stdlib.h> @@ -65,9 +65,17 @@ QT_BEGIN_NAMESPACE \ingroup shared QRegion is used with QPainter::setClipRegion() to limit the paint - area to what needs to be painted. There is also a - QWidget::repaint() function that takes a QRegion parameter. - QRegion is the best tool for reducing flicker. + area to what needs to be painted. There is also a QWidget::repaint() + function that takes a QRegion parameter. QRegion is the best tool for + minimizing the amount of screen area to be updated by a repaint. + + This class is not suitable for constructing shapes for rendering, especially + as outlines. Use QPainterPath to create paths and shapes for use with + QPainter. + + QRegion is an \l{implicitly shared} class. + + \section1 Creating and Using Regions A region can be created from a rectangle, an ellipse, a polygon or a bitmap. Complex regions may be created by combining simple @@ -84,8 +92,6 @@ QT_BEGIN_NAMESPACE Example of using complex regions: \snippet doc/src/snippets/code/src_gui_painting_qregion.cpp 0 - QRegion is an \l{implicitly shared} class. - \warning Due to window system limitations, the whole coordinate space for a region is limited to the points between -32767 and 32767 on Windows 95/98/ME. You can circumvent this limitation by using a QPainterPath. @@ -93,7 +99,7 @@ QT_BEGIN_NAMESPACE \section1 Additional License Information On Embedded Linux, Windows CE and X11 platforms, parts of this class rely on - code obtained under the following license: + code obtained under the following licenses: \legalese Copyright (c) 1987 X Consortium @@ -120,9 +126,7 @@ QT_BEGIN_NAMESPACE in this Software without prior written authorization from the X Consortium. \endlegalese - \raw HTML - <hr /> - \endraw + \br \legalese Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts. diff --git a/src/gui/painting/qtransform.cpp b/src/gui/painting/qtransform.cpp index c2e2a80..2383272 100644 --- a/src/gui/painting/qtransform.cpp +++ b/src/gui/painting/qtransform.cpp @@ -168,10 +168,10 @@ QT_BEGIN_NAMESPACE \image qtransform-representation.png - A QTransform object contains a 3 x 3 matrix. The \c dx and \c dy - elements specify horizontal and vertical translation. The \c m11 - and \c m22 elements specify horizontal and vertical scaling. The - \c m21 and \c m12 elements specify horizontal and vertical \e shearing. + A QTransform object contains a 3 x 3 matrix. The \c m31 (\c dx) and + \c m32 (\c dy) elements specify horizontal and vertical translation. + The \c m11 and \c m22 elements specify horizontal and vertical scaling. + The \c m21 and \c m12 elements specify horizontal and vertical \e shearing. And finally, the \c m13 and \c m23 elements specify horizontal and vertical projection, with \c m33 as an additional projection factor. @@ -246,8 +246,10 @@ QTransform::QTransform() } /*! - Constructs a matrix with the elements, \a h11, \a h12, \a h13, - \a h21, \a h22, \a h23, \a h31, \a h32, \a h33. + \fn QTransform::QTransform(qreal m11, qreal m12, qreal m13, qreal m21, qreal m22, qreal m23, qreal m31, qreal m32, qreal m33) + + Constructs a matrix with the elements, \a m11, \a m12, \a m13, + \a m21, \a m22, \a m23, \a m31, \a m32, \a m33. \sa setMatrix() */ @@ -263,8 +265,9 @@ QTransform::QTransform(qreal h11, qreal h12, qreal h13, } /*! - Constructs a matrix with the elements, \a h11, \a h12, \a h21, \a - h22, \a dx and \a dy. + \fn QTransform::QTransform(qreal m11, qreal m12, qreal m21, qreal m22, qreal dx, qreal dy) + + Constructs a matrix with the elements, \a m11, \a m12, \a m21, \a m22, \a dx and \a dy. \sa setMatrix() */ @@ -396,6 +399,9 @@ QTransform QTransform::inverted(bool *invertible) const */ QTransform & QTransform::translate(qreal dx, qreal dy) { + if (dx == 0 && dy == 0) + return *this; + switch(type()) { case TxNone: affine._dx = dx; @@ -432,7 +438,10 @@ QTransform & QTransform::translate(qreal dx, qreal dy) QTransform QTransform::fromTranslate(qreal dx, qreal dy) { QTransform transform(1, 0, 0, 1, dx, dy); - transform.m_dirty = TxTranslate; + if (dx == 0 && dy == 0) + transform.m_dirty = TxNone; + else + transform.m_dirty = TxTranslate; return transform; } @@ -444,6 +453,9 @@ QTransform QTransform::fromTranslate(qreal dx, qreal dy) */ QTransform & QTransform::scale(qreal sx, qreal sy) { + if (sx == 1 && sy == 1) + return *this; + switch(type()) { case TxNone: case TxTranslate: @@ -478,7 +490,10 @@ QTransform & QTransform::scale(qreal sx, qreal sy) QTransform QTransform::fromScale(qreal sx, qreal sy) { QTransform transform(sx, 0, 0, sy, 0, 0); - transform.m_dirty = TxScale; + if (sx == 1 && sy == 1) + transform.m_dirty = TxNone; + else + transform.m_dirty = TxScale; return transform; } @@ -541,6 +556,9 @@ const qreal inv_dist_to_plane = 1. / 1024.; */ QTransform & QTransform::rotate(qreal a, Qt::Axis axis) { + if (a == 0) + return *this; + qreal sina = 0; qreal cosa = 0; if (a == 90. || a == -270.) @@ -712,7 +730,15 @@ bool QTransform::operator!=(const QTransform &o) const */ QTransform & QTransform::operator*=(const QTransform &o) { - TransformationType t = qMax(type(), o.type()); + const TransformationType otherType = o.type(); + if (otherType == TxNone) + return *this; + + const TransformationType thisType = type(); + if (thisType == TxNone) + return operator=(o); + + TransformationType t = qMax(thisType, otherType); switch(t) { case TxNone: break; @@ -1219,7 +1245,8 @@ static QPolygonF mapProjective(const QTransform &transform, const QPolygonF &pol */ QPolygonF QTransform::map(const QPolygonF &a) const { - if (type() >= QTransform::TxProject) + TransformationType t = type(); + if (t >= QTransform::TxProject) return mapProjective(*this, a); int size = a.size(); @@ -1228,7 +1255,6 @@ QPolygonF QTransform::map(const QPolygonF &a) const const QPointF *da = a.constData(); QPointF *dp = p.data(); - TransformationType t = type(); for(i = 0; i < size; ++i) { MAP(da[i].xp, da[i].yp, dp[i].xp, dp[i].yp); } @@ -1246,7 +1272,8 @@ QPolygonF QTransform::map(const QPolygonF &a) const */ QPolygon QTransform::map(const QPolygon &a) const { - if (type() >= QTransform::TxProject) + TransformationType t = type(); + if (t >= QTransform::TxProject) return mapProjective(*this, QPolygonF(a)).toPolygon(); int size = a.size(); @@ -1255,7 +1282,6 @@ QPolygon QTransform::map(const QPolygon &a) const const QPoint *da = a.constData(); QPoint *dp = p.data(); - TransformationType t = type(); for(i = 0; i < size; ++i) { qreal nx = 0, ny = 0; MAP(da[i].xp, da[i].yp, nx, ny); @@ -1274,6 +1300,8 @@ QPolygon QTransform::map(const QPolygon &a) const \sa QTransform::map() */ +extern QPainterPath qt_regionToPath(const QRegion ®ion); + /*! \fn QRegion QTransform::map(const QRegion ®ion) const \overload @@ -1289,13 +1317,16 @@ QRegion QTransform::map(const QRegion &r) const TransformationType t = type(); if (t == TxNone) return r; + if (t == TxTranslate) { QRegion copy(r); copy.translate(qRound(affine._dx), qRound(affine._dy)); return copy; } - extern QPainterPath qt_regionToPath(const QRegion ®ion); + if (t == TxScale && r.numRects() == 1) + return QRegion(mapRect(r.boundingRect())); + QPainterPath p = map(qt_regionToPath(r)); return p.toFillPolygon(QTransform()).toPolygon(); } @@ -1688,13 +1719,12 @@ QRect QTransform::mapRect(const QRect &rect) const return QRect(x, y, w, h); } else if (t < TxProject) { // see mapToPolygon for explanations of the algorithm. - qreal x0 = 0, y0 = 0; - qreal x, y; - MAP(rect.left(), rect.top(), x0, y0); - qreal xmin = x0; - qreal ymin = y0; - qreal xmax = x0; - qreal ymax = y0; + qreal x = 0, y = 0; + MAP(rect.left(), rect.top(), x, y); + qreal xmin = x; + qreal ymin = y; + qreal xmax = x; + qreal ymax = y; MAP(rect.right() + 1, rect.top(), x, y); xmin = qMin(xmin, x); ymin = qMin(ymin, y); @@ -1755,13 +1785,12 @@ QRectF QTransform::mapRect(const QRectF &rect) const } return QRectF(x, y, w, h); } else if (t < TxProject) { - qreal x0 = 0, y0 = 0; - qreal x, y; - MAP(rect.x(), rect.y(), x0, y0); - qreal xmin = x0; - qreal ymin = y0; - qreal xmax = x0; - qreal ymax = y0; + qreal x = 0, y = 0; + MAP(rect.x(), rect.y(), x, y); + qreal xmin = x; + qreal ymin = y; + qreal xmax = x; + qreal ymax = y; MAP(rect.x() + rect.width(), rect.y(), x, y); xmin = qMin(xmin, x); ymin = qMin(ymin, y); @@ -1855,7 +1884,7 @@ const QMatrix &QTransform::toAffine() const QTransform::TransformationType QTransform::type() const { if (m_dirty >= m_type) { - if (m_dirty > TxShear && (!qFuzzyCompare(m_13 + 1, 1) || !qFuzzyCompare(m_23 + 1, 1))) + if (m_dirty > TxShear && (!qFuzzyCompare(m_13 + 1, 1) || !qFuzzyCompare(m_23 + 1, 1) || !qFuzzyCompare(m_33, 1))) m_type = TxProject; else if (m_dirty > TxScale && (!qFuzzyCompare(affine._m12 + 1, 1) || !qFuzzyCompare(affine._m21 + 1, 1))) { const qreal dot = affine._m11 * affine._m12 + affine._m21 * affine._m22; @@ -1863,7 +1892,7 @@ QTransform::TransformationType QTransform::type() const m_type = TxRotate; else m_type = TxShear; - } else if (m_dirty > TxTranslate && (!qFuzzyCompare(affine._m11, 1) || !qFuzzyCompare(affine._m22, 1) || !qFuzzyCompare(m_33, 1))) + } else if (m_dirty > TxTranslate && (!qFuzzyCompare(affine._m11, 1) || !qFuzzyCompare(affine._m22, 1))) m_type = TxScale; else if (m_dirty > TxNone && (!qFuzzyCompare(affine._dx + 1, 1) || !qFuzzyCompare(affine._dy + 1, 1))) m_type = TxTranslate; @@ -2057,10 +2086,11 @@ QTransform::operator QVariant() const Q_GUI_EXPORT bool qt_scaleForTransform(const QTransform &transform, qreal *scale) { - if (transform.type() <= QTransform::TxTranslate) { + const QTransform::TransformationType type = transform.type(); + if (type <= QTransform::TxTranslate) { *scale = 1; return true; - } else if (transform.type() == QTransform::TxScale) { + } else if (type == QTransform::TxScale) { const qreal xScale = qAbs(transform.m11()); const qreal yScale = qAbs(transform.m22()); *scale = qMax(xScale, yScale); @@ -2072,7 +2102,7 @@ bool qt_scaleForTransform(const QTransform &transform, qreal *scale) const qreal yScale = transform.m12() * transform.m12() + transform.m22() * transform.m22(); *scale = qSqrt(qMax(xScale, yScale)); - return transform.type() == QTransform::TxRotate && qFuzzyCompare(xScale, yScale); + return type == QTransform::TxRotate && qFuzzyCompare(xScale, yScale); } QT_END_NAMESPACE diff --git a/src/gui/painting/qtransform.h b/src/gui/painting/qtransform.h index de7ebcd..c76409b 100644 --- a/src/gui/painting/qtransform.h +++ b/src/gui/painting/qtransform.h @@ -257,6 +257,8 @@ inline qreal QTransform::dy() const inline QTransform &QTransform::operator*=(qreal num) { + if (num == 1.) + return *this; affine._m11 *= num; affine._m12 *= num; m_13 *= num; @@ -271,11 +273,15 @@ inline QTransform &QTransform::operator*=(qreal num) } inline QTransform &QTransform::operator/=(qreal div) { + if (div == 0) + return *this; div = 1/div; return operator*=(div); } inline QTransform &QTransform::operator+=(qreal num) { + if (num == 0) + return *this; affine._m11 += num; affine._m12 += num; m_13 += num; @@ -290,6 +296,8 @@ inline QTransform &QTransform::operator+=(qreal num) } inline QTransform &QTransform::operator-=(qreal num) { + if (num == 0) + return *this; affine._m11 -= num; affine._m12 -= num; m_13 -= num; diff --git a/src/gui/painting/qwindowsurface.cpp b/src/gui/painting/qwindowsurface.cpp index bcb0380..d941a24 100644 --- a/src/gui/painting/qwindowsurface.cpp +++ b/src/gui/painting/qwindowsurface.cpp @@ -310,10 +310,13 @@ void qt_scrollRectInImage(QImage &img, const QRect &rect, const QPoint &offset) int lineskip = img.bytesPerLine(); int depth = img.depth() >> 3; - - const QRect r = rect & QRect(0, 0, img.width(), img.height()); + const QRect imageRect(0, 0, img.width(), img.height()); + const QRect r = rect & imageRect & imageRect.translated(-offset); const QPoint p = rect.topLeft() + offset; + if (r.isEmpty()) + return; + const uchar *src; uchar *dest; diff --git a/src/gui/painting/qwindowsurface_raster.cpp b/src/gui/painting/qwindowsurface_raster.cpp index 7a74fe0..110ba2f 100644 --- a/src/gui/painting/qwindowsurface_raster.cpp +++ b/src/gui/painting/qwindowsurface_raster.cpp @@ -142,8 +142,7 @@ void QRasterWindowSurface::beginPaint(const QRegion &rgn) p.fillRect(*it, blank); } } -#endif -#if defined(Q_OS_WINCE) +#else Q_UNUSED(rgn); #endif } @@ -250,6 +249,7 @@ void QRasterWindowSurface::flush(QWidget *widget, const QRegion &rgn, const QPoi // d->image->image.save("flush.png"); + Q_UNUSED(offset); // Get a context for the widget. #ifndef QT_MAC_USE_COCOA CGContextRef context; diff --git a/src/gui/styles/gtksymbols.cpp b/src/gui/styles/gtksymbols.cpp index 947f9a2..0842ec7 100644 --- a/src/gui/styles/gtksymbols.cpp +++ b/src/gui/styles/gtksymbols.cpp @@ -75,6 +75,7 @@ QT_BEGIN_NAMESPACE static bool displayDepth = -1; +Q_GLOBAL_STATIC(QGtkStyleUpdateScheduler, styleScheduler) typedef QHash<QString, GtkWidget*> WidgetMap; Q_GLOBAL_STATIC(WidgetMap, gtkWidgetMap) @@ -486,11 +487,11 @@ static void init_gtk_menu() } // Updates window/windowtext palette based on the indicated gtk widget -static void ensureWidgetPalette(QWidget* widget, const QString >kWidgetName) +static QPalette gtkWidgetPalette(const QString >kWidgetName) { GtkWidget *gtkWidget = QGtk::gtkWidget(gtkWidgetName); Q_ASSERT(gtkWidget); - QPalette pal = widget->palette(); + QPalette pal = QApplication::palette(); GdkColor gdkBg = gtkWidget->style->bg[GTK_STATE_NORMAL]; GdkColor gdkText = gtkWidget->style->fg[GTK_STATE_NORMAL]; GdkColor gdkDisabledText = gtkWidget->style->fg[GTK_STATE_INSENSITIVE]; @@ -503,8 +504,7 @@ static void ensureWidgetPalette(QWidget* widget, const QString >kWidgetName) pal.setBrush(QPalette::Disabled, QPalette::WindowText, disabledTextColor); pal.setBrush(QPalette::All, QPalette::ButtonText, textColor); pal.setBrush(QPalette::Disabled, QPalette::ButtonText, disabledTextColor); - widget->setPalette(pal); - widget->setAttribute(Qt::WA_SetPalette, false); + return pal; } bool QGtk::isKDE4Session() @@ -515,44 +515,47 @@ bool QGtk::isKDE4Session() return (version == 4); } -// Maps a Gtk widget palettes to a Qt widget -void QGtk::applyGtkSystemPalette(QWidget *widget) +void QGtk::applyCustomPaletteHash() { - // Do not apply if the widget has a custom palette; - if (widget->testAttribute(Qt::WA_SetPalette)) - return; + QPalette menuPal = gtkWidgetPalette(QLS("GtkMenu")); + GdkColor gdkBg = QGtk::gtkWidget(QLS("GtkMenu"))->style->bg[GTK_STATE_NORMAL]; + QColor bgColor(gdkBg.red>>8, gdkBg.green>>8, gdkBg.blue>>8); + menuPal.setBrush(QPalette::Base, bgColor); + menuPal.setBrush(QPalette::Window, bgColor); + qApp->setPalette(menuPal, "QMenu"); - QPalette pal; - if (QStatusBar *statusbar = qobject_cast<QStatusBar*> (widget)) - ensureWidgetPalette(statusbar, QLS("GtkStatusbar")); - else if (QMenuBar *menubar = qobject_cast<QMenuBar*> (widget)) - ensureWidgetPalette(menubar, QLS("GtkMenuBar")); - else if (QToolBar *toolbar = qobject_cast<QToolBar*> (widget)) - ensureWidgetPalette(toolbar, QLS("GtkToolbar")); - else if (QMenu *menubar = qobject_cast<QMenu*> (widget)) { - // This really applies to the combo box rendering since - // QComboBox copies the palette from a QMenu - QPalette pal = widget->palette(); - GdkColor gdkBg = QGtk::gtkWidget(QLS("GtkMenu"))->style->bg[GTK_STATE_NORMAL]; - QColor bgColor(gdkBg.red>>8, gdkBg.green>>8, gdkBg.blue>>8); - pal.setBrush(QPalette::Base, bgColor); - menubar->setPalette(pal); - } - widget->setAttribute(Qt::WA_SetPalette, false); + QPalette toolbarPal = gtkWidgetPalette(QLS("GtkToolbar")); + qApp->setPalette(toolbarPal, "QToolBar"); + + QPalette menuBarPal = gtkWidgetPalette(QLS("GtkMenuBar")); + qApp->setPalette(menuBarPal, "QMenuBar"); } static void gtkStyleSetCallback(GtkWidget*, GtkStyle*, void*) { + // We have to let this function return and complete the event + // loop to ensure that all gtk widgets have been styled before + // updating + QMetaObject::invokeMethod(styleScheduler(), "updateTheme", Qt::QueuedConnection); +} + +void QGtkStyleUpdateScheduler::updateTheme() +{ static QString oldTheme(QLS("qt_not_set")); QPixmapCache::clear(); - qApp->setFont(QGtk::getThemeFont()); - QGtk::initGtkWidgets(); if (oldTheme != getThemeName()) { oldTheme = getThemeName(); - QApplicationPrivate::setSystemPalette(qApp->style()->standardPalette()); + qApp->setFont(QGtk::getThemeFont()); + QPalette newPalette = qApp->style()->standardPalette(); + QApplicationPrivate::setSystemPalette(newPalette); + QApplication::setPalette(newPalette); + QGtk::initGtkWidgets(); + QGtk::applyCustomPaletteHash(); QList<QWidget*> widgets = QApplication::allWidgets(); + // Notify all widgets that size metrics might have changed foreach (QWidget *widget, widgets) { - QGtk::applyGtkSystemPalette(widget); + QEvent e(QEvent::StyleChange); + QApplication::sendEvent(widget, &e); } } } @@ -629,17 +632,26 @@ GtkStyle* QGtk::gtkStyle(const QString &path) return gtkWidgetMap()->value(path)->style; return 0; } + +#ifdef Q_OS_LINUX QT_END_NAMESPACE int getresuid(uid_t *ruid, uid_t *euid, uid_t *suid); int getresgid(gid_t *rgid, gid_t *egid, gid_t *sgid); QT_BEGIN_NAMESPACE +#endif + void QGtk::initGtkWidgets() { // From gtkmain.c + uid_t ruid, rgid, euid, egid, suid, sgid; - if (getresuid (&ruid, &euid, &suid) != 0 || getresgid (&rgid, &egid, &sgid) != 0) { + +#ifdef Q_OS_LINUX + if (getresuid (&ruid, &euid, &suid) != 0 || getresgid (&rgid, &egid, &sgid) != 0) +#endif + { suid = ruid = getuid (); sgid = rgid = getgid (); euid = geteuid (); @@ -652,7 +664,7 @@ void QGtk::initGtkWidgets() "See http://www.gtk.org/setuid.html for more information.\n"); return; } - + init_gtk_window(); if (QGtk::gtk_init) { @@ -734,9 +746,9 @@ static void setupGtkFileChooser(GtkWidget* gtkFileChooser, QWidget *parent, foreach (const QString &rawfilter, filters) { GtkFileFilter *gtkFilter = QGtk::gtk_file_filter_new (); QString name = rawfilter.left(rawfilter.indexOf(QLatin1Char('('))); - QGtk::gtk_file_filter_set_name(gtkFilter, qPrintable(name)); - QStringList extensions = extract_filter(rawfilter); + QGtk::gtk_file_filter_set_name(gtkFilter, qPrintable(name.isEmpty() ? extensions.join(QLS(", ")) : name)); + foreach (const QString &fileExtension, extensions) { QGtk::gtk_file_filter_add_pattern (gtkFilter, qPrintable(fileExtension)); } diff --git a/src/gui/styles/gtksymbols_p.h b/src/gui/styles/gtksymbols_p.h index 0cea542..74c5dc3 100644 --- a/src/gui/styles/gtksymbols_p.h +++ b/src/gui/styles/gtksymbols_p.h @@ -204,7 +204,7 @@ public: static void cleanup_gtk_widgets(); static void initGtkWidgets(); static bool isKDE4Session(); - static void applyGtkSystemPalette(QWidget* widget); + static void applyCustomPaletteHash(); static QFont getThemeFont(); static bool isThemeAvailable() { return gtkStyle() != 0; } @@ -329,6 +329,15 @@ public: static Ptr_gconf_client_get_string gconf_client_get_string; }; +// Helper to ensure that we have polished all our gtk widgets +// before updating our own palettes +class QGtkStyleUpdateScheduler : public QObject +{ + Q_OBJECT +public slots: + void updateTheme(); +}; + QT_END_NAMESPACE #endif // !QT_NO_STYLE_GTK diff --git a/src/gui/styles/qgtkstyle.cpp b/src/gui/styles/qgtkstyle.cpp index 103e97f..ca71da2 100644 --- a/src/gui/styles/qgtkstyle.cpp +++ b/src/gui/styles/qgtkstyle.cpp @@ -38,7 +38,6 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ - #include "qgtkstyle.h" #if !defined(QT_NO_STYLE_GTK) @@ -138,6 +137,30 @@ static const char * const dock_widget_restore_xpm[] = }; +class QGtkStyleFilter : public QObject +{ +public: + QGtkStyleFilter() { + qApp->installEventFilter(this); + } + +private: + bool eventFilter(QObject *obj, QEvent *e); +}; + +bool QGtkStyleFilter::eventFilter(QObject *obj, QEvent *e) +{ + if (e->type() == QEvent::ApplicationPaletteChange) { + // Only do this the first time since this will also + // generate applicationPaletteChange events + extern QHash<QByteArray, QPalette> *qt_app_palettes_hash(); //qapplication.cpp + if (!qt_app_palettes_hash() || qt_app_palettes_hash()->isEmpty()) { + QGtk::applyCustomPaletteHash(); + } + } + return QObject::eventFilter(obj, e); +} + class QGtkStylePrivate : public QCleanlooksStylePrivate { Q_DECLARE_PUBLIC(QGtkStyle) @@ -145,6 +168,7 @@ public: QGtkStylePrivate() : QCleanlooksStylePrivate() {} + QGtkStyleFilter filter; }; static const int groupBoxBottomMargin = 2; // space below the groupbox @@ -217,6 +241,7 @@ static QString uniqueName(const QString &key, const QStyleOption *option, const Constructs a QGtkStyle object. */ QGtkStyle::QGtkStyle() + : QCleanlooksStyle(*new QGtkStylePrivate) { QGtk::initGtkWidgets(); } @@ -313,7 +338,7 @@ void QGtkStyle::polish(QPalette &palette) if (!QGtk::isThemeAvailable()) QCleanlooksStyle::polish(palette); else - palette = standardPalette(); + palette = palette.resolve(standardPalette()); } /*! @@ -328,6 +353,7 @@ void QGtkStyle::polish(QApplication *app) if (app->desktopSettingsAware() && QGtk::isThemeAvailable()) { QApplicationPrivate::setSystemPalette(standardPalette()); QApplicationPrivate::setSystemFont(QGtk::getThemeFont()); + QGtk::applyCustomPaletteHash(); if (!QGtk::isKDE4Session()) { qt_filedialog_open_filename_hook = &QGtk::openFilename; qt_filedialog_save_filename_hook = &QGtk::saveFilename; @@ -357,12 +383,12 @@ void QGtkStyle::unpolish(QApplication *app) /*! \reimp */ + void QGtkStyle::polish(QWidget *widget) { QCleanlooksStyle::polish(widget); if (!QGtk::isThemeAvailable()) return; - if (qobject_cast<QAbstractButton*>(widget) || qobject_cast<QToolButton*>(widget) || qobject_cast<QComboBox*>(widget) @@ -375,8 +401,6 @@ void QGtkStyle::polish(QWidget *widget) widget->setAttribute(Qt::WA_Hover); else if (QTreeView *tree = qobject_cast<QTreeView *> (widget)) tree->viewport()->setAttribute(Qt::WA_Hover); - - QGtk::applyGtkSystemPalette(widget); } /*! @@ -399,6 +423,17 @@ int QGtkStyle::pixelMetric(PixelMetric metric, return QCleanlooksStyle::pixelMetric(metric, option, widget); switch (metric) { + case PM_DefaultFrameWidth: + if (qobject_cast<const QFrame*>(widget)) { + if (GtkStyle *style = + QGtk::gtk_rc_get_style_by_paths(QGtk::gtk_settings_get_default(), + "*.GtkScrolledWindow", + "*.GtkScrolledWindow", + Q_GTK_TYPE_WINDOW)) + return qMax(style->xthickness, style->ythickness); + } + return 2; + case PM_MenuButtonIndicator: return 20; @@ -635,6 +670,66 @@ void QGtkStyle::drawPrimitive(PrimitiveElement element, QGtkPainter gtkPainter(painter); switch (element) { + case PE_Frame: { + if (widget && widget->inherits("QComboBoxPrivateContainer")){ + QStyleOption copy = *option; + copy.state |= State_Raised; + drawPrimitive(PE_PanelMenu, ©, painter, widget); + break; + } + // Drawing the entire itemview frame is very expensive, especially on the native X11 engine + // Instead we cheat a bit and draw a border image without the center part, hence only scaling + // thin rectangular images + const int pmSize = 64; + const int border = pixelMetric(PM_DefaultFrameWidth, option, widget); + const QString pmKey = QString(QLS("windowframe %0")).arg(option->state); + + QPixmap pixmap; + QPixmapCache::find(pmKey, pixmap); + QRect pmRect(QPoint(0,0), QSize(pmSize, pmSize)); + + // Only draw through style once + if (pixmap.isNull()) { + pixmap = QPixmap(pmSize, pmSize); + pixmap.fill(Qt::transparent); + QPainter pmPainter(&pixmap); + QGtkPainter gtkFramePainter(&pmPainter); + gtkFramePainter.setUsePixmapCache(false); // Don't cache twice + + GtkShadowType shadow_type = GTK_SHADOW_NONE; + if (option->state & State_Sunken) + shadow_type = GTK_SHADOW_IN; + else if (option->state & State_Raised) + shadow_type = GTK_SHADOW_OUT; + + GtkStyle *style = QGtk::gtk_rc_get_style_by_paths(QGtk::gtk_settings_get_default(), + "*.GtkScrolledWindow", "*.GtkScrolledWindow", Q_GTK_TYPE_WINDOW); + if (style) + gtkFramePainter.paintShadow(QGtk::gtkWidget(QLS("GtkFrame")), "viewport", pmRect, + option->state & State_Enabled ? GTK_STATE_NORMAL : GTK_STATE_INSENSITIVE, + shadow_type, style); + QPixmapCache::insert(pmKey, pixmap); + } + + QRect rect = option->rect; + const int rw = rect.width() - border; + const int rh = rect.height() - border; + const int pw = pmRect.width() - border; + const int ph = pmRect.height() - border; + + // Sidelines + painter->drawPixmap(rect.adjusted(border, 0, -border, -rh), pixmap, pmRect.adjusted(border, 0, -border,-ph)); + painter->drawPixmap(rect.adjusted(border, rh, -border, 0), pixmap, pmRect.adjusted(border, ph,-border,0)); + painter->drawPixmap(rect.adjusted(0, border, -rw, -border), pixmap, pmRect.adjusted(0, border, -pw, -border)); + painter->drawPixmap(rect.adjusted(rw, border, 0, -border), pixmap, pmRect.adjusted(pw, border, 0, -border)); + + // Corners + painter->drawPixmap(rect.adjusted(0, 0, -rw, -rh), pixmap, pmRect.adjusted(0, 0, -pw,-ph)); + painter->drawPixmap(rect.adjusted(rw, 0, 0, -rh), pixmap, pmRect.adjusted(pw, 0, 0,-ph)); + painter->drawPixmap(rect.adjusted(0, rh, -rw, 0), pixmap, pmRect.adjusted(0, ph, -pw,0)); + painter->drawPixmap(rect.adjusted(rw, rh, 0, 0), pixmap, pmRect.adjusted(pw, ph, 0,0)); + } + break; case PE_PanelTipLabel: { GtkWidget *gtkWindow = QGtk::gtkWidget(QLS("GtkWindow")); // The Murrine Engine currently assumes a widget is passed @@ -856,14 +951,15 @@ void QGtkStyle::drawPrimitive(PrimitiveElement element, "interior-focus", &interior_focus, "focus-line-width", &focus_line_width, NULL); + // See https://bugzilla.mozilla.org/show_bug.cgi?id=405421 for info about this hack + g_object_set_data(G_OBJECT(gtkEntry), "transparent-bg-hint", GINT_TO_POINTER(TRUE)); + if (!interior_focus && option->state & State_HasFocus) rect.adjust(focus_line_width, focus_line_width, -focus_line_width, -focus_line_width); - gtkPainter.paintShadow(gtkEntry, "entry", rect, option->state & State_Enabled ? GTK_STATE_NORMAL : GTK_STATE_INSENSITIVE, GTK_SHADOW_IN, gtkEntry->style, option->state & State_HasFocus ? QLS("focus") : QString()); - if (!interior_focus && option->state & State_HasFocus) gtkPainter.paintShadow(gtkEntry, "entry", option->rect, option->state & State_Enabled ? GTK_STATE_ACTIVE : GTK_STATE_INSENSITIVE, @@ -882,7 +978,7 @@ void QGtkStyle::drawPrimitive(PrimitiveElement element, if (widget && widget->testAttribute(Qt::WA_SetPalette) && resolve_mask & (1 << QPalette::Base)) // Palette overridden by user - painter->fillRect(textRect, option->palette.base().color()); + painter->fillRect(textRect, option->palette.base()); else gtkPainter.paintFlatBox( gtkEntry, "entry_bg", textRect, option->state & State_Enabled ? GTK_STATE_NORMAL : GTK_STATE_INSENSITIVE, GTK_SHADOW_NONE, gtkEntry->style); @@ -2412,6 +2508,10 @@ void QGtkStyle::drawControl(ControlElement element, if (selected) { QRect rect = option->rect.adjusted(0, 0, -1, -1); +#ifndef QT_NO_COMBOBOX + if (qobject_cast<const QComboBox*>(widget)) + rect = option->rect; +#endif gtkPainter.paintBox( gtkMenuItem, "menuitem", rect, GTK_STATE_PRELIGHT, GTK_SHADOW_OUT, style); } @@ -2528,16 +2628,24 @@ void QGtkStyle::drawControl(ControlElement element, opt.rect = vCheckRect; drawPrimitive(PE_PanelButtonCommand, &opt, painter, widget); } - painter->drawPixmap(pmr.topLeft(), pixmap); } GdkColor gdkText = gtkMenuItem->style->fg[GTK_STATE_NORMAL]; GdkColor gdkDText = gtkMenuItem->style->fg[GTK_STATE_INSENSITIVE]; GdkColor gdkHText = gtkMenuItem->style->fg[GTK_STATE_PRELIGHT]; + uint resolve_mask = option->palette.resolve(); QColor textColor = QColor(gdkText.red>>8, gdkText.green>>8, gdkText.blue>>8); QColor disabledTextColor = QColor(gdkDText.red>>8, gdkDText.green>>8, gdkDText.blue>>8); + if (resolve_mask & (1 << QPalette::ButtonText)) { + textColor = option->palette.buttonText().color(); + disabledTextColor = option->palette.brush(QPalette::Disabled, QPalette::ButtonText).color(); + } + QColor highlightedTextColor = QColor(gdkHText.red>>8, gdkHText.green>>8, gdkHText.blue>>8); + if (resolve_mask & (1 << QPalette::HighlightedText)) { + highlightedTextColor = option->palette.highlightedText().color(); + } if (selected) painter->setPen(highlightedTextColor); @@ -2653,10 +2761,13 @@ void QGtkStyle::drawControl(ControlElement element, if (tab->state & State_Selected) state = GTK_STATE_NORMAL; - bool first = tab->position == QStyleOptionTab::Beginning || tab->position == QStyleOptionTab::OnlyOneTab; - bool last = tab->position == QStyleOptionTab::End || tab->position == QStyleOptionTab::OnlyOneTab; bool selected = (tab->state & State_Selected); - if (option->direction == Qt::RightToLeft) { + bool first = false, last = false; + if (widget) { + // This is most accurate and avoids resizing tabs while moving + first = tab->rect.left() == widget->rect().left(); + last = tab->rect.right() == widget->rect().right(); + } else if (option->direction == Qt::RightToLeft) { bool tmp = first; first = last; last = tmp; diff --git a/src/gui/styles/qmacstyle_mac.mm b/src/gui/styles/qmacstyle_mac.mm index 2634d44..7a870fe 100644 --- a/src/gui/styles/qmacstyle_mac.mm +++ b/src/gui/styles/qmacstyle_mac.mm @@ -529,6 +529,7 @@ public: QPointer<QFocusFrame> focusWidget; CFAbsoluteTime defaultButtonStart; QMacStyle *q; + bool mouseDown; }; QT_BEGIN_INCLUDE_NAMESPACE @@ -548,7 +549,6 @@ extern QPaintDevice *qt_mac_safe_pdev; //qapplication_mac.cpp QMacCGStyle globals *****************************************************************************/ const int qt_mac_hitheme_version = 0; //the HITheme version we speak -const int macSpinBoxSep = 5; // distance between spinwidget and the lineedit const int macItemFrame = 2; // menu item frame width const int macItemHMargin = 3; // menu item hor text margin const int macItemVMargin = 2; // menu item ver text margin @@ -1477,7 +1477,7 @@ void QMacStylePrivate::getSliderInfo(QStyle::ComplexControl cc, const QStyleOpti #endif QMacStylePrivate::QMacStylePrivate(QMacStyle *style) - : timerID(-1), progressFrame(0), q(style) + : timerID(-1), progressFrame(0), q(style), mouseDown(false) { defaultButtonStart = CFAbsoluteTimeGetCurrent(); memset(&buttonState, 0, sizeof(ButtonState)); @@ -1494,7 +1494,7 @@ bool QMacStylePrivate::animatable(QMacStylePrivate::Animates as, const QWidget * { if (as == AquaPushButton) { QPushButton *pb = const_cast<QPushButton *>(static_cast<const QPushButton *>(w)); - if (w->window()->isActiveWindow() && pb) { + if (w->window()->isActiveWindow() && pb && !mouseDown) { if (static_cast<const QPushButton *>(w) != defaultButton) { // Changed on its own, update the value. const_cast<QMacStylePrivate *>(this)->stopAnimate(as, defaultButton); @@ -1514,8 +1514,7 @@ void QMacStylePrivate::stopAnimate(QMacStylePrivate::Animates as, QWidget *w) if (as == AquaPushButton && defaultButton) { QPushButton *tmp = defaultButton; defaultButton = 0; - if (tmp->isVisible()) - tmp->update(); + tmp->update(); } else if (as == AquaProgressBar) { progressBars.removeAll(w); } @@ -1841,10 +1840,15 @@ bool QMacStylePrivate::eventFilter(QObject *o, QEvent *e) break; case QEvent::MouseButtonPress: // It is very confusing to keep the button pulsing, so just stop the animation. + if (static_cast<QMouseEvent *>(e)->button() == Qt::LeftButton) + mouseDown = true; stopAnimate(AquaPushButton, btn); break; - case QEvent::FocusOut: case QEvent::MouseButtonRelease: + if (static_cast<QMouseEvent *>(e)->button() == Qt::LeftButton) + mouseDown = false; + // fall through + case QEvent::FocusOut: case QEvent::Show: case QEvent::WindowActivate: { QList<QPushButton *> list = qFindChildren<QPushButton *>(btn->window()); @@ -2141,8 +2145,11 @@ void qt_mac_fill_background(QPainter *painter, const QRegion &rgn, const QPoint /*! \reimp */ void QMacStyle::polish(QPalette &pal) { - if (qt_mac_backgroundPattern == 0) + if (!qt_mac_backgroundPattern) { + if (!qApp) + return; qt_mac_backgroundPattern = new QPixmap(d->generateBackgroundPattern()); + } QColor pc(Qt::black); pc = qcolorForTheme(kThemeBrushDialogBackgroundActive); @@ -2184,7 +2191,7 @@ void QMacStyle::polish(QWidget* w) } if (qobject_cast<QMenu*>(w) || qobject_cast<QComboBoxPrivateContainer *>(w)) { - w->setWindowOpacity(0.94); + w->setWindowOpacity(QSysInfo::MacintoshVersion >= QSysInfo::MV_10_5 ? 0.985 : 0.94); if (!w->testAttribute(Qt::WA_SetPalette)) { QPixmap px(64, 64); HIThemeMenuDrawInfo mtinfo; @@ -2368,7 +2375,14 @@ int QMacStyle::pixelMetric(PixelMetric metric, const QStyleOption *opt, const QW break; case PM_SpinBoxFrameWidth: GetThemeMetric(kThemeMetricEditTextFrameOutset, &ret); - ret += 2; + switch (d->aquaSizeConstrain(opt, widget)) { + default: + ret += 2; + break; + case QAquaSizeMini: + ret += 1; + break; + } break; case PM_ButtonShiftHorizontal: case PM_ButtonShiftVertical: @@ -3849,13 +3863,16 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter } break; case CE_TabBarTabShape: - if (const QStyleOptionTabV3 *tabOpt = qstyleoption_cast<const QStyleOptionTabV3 *>(opt)) { - if (tabOpt->documentMode) { - p->save(); - QRect tabRect = tabOpt->rect; - drawTabShape(p, tabOpt); - p->restore(); - return; + if (const QStyleOptionTab *tabOpt = qstyleoption_cast<const QStyleOptionTab *>(opt)) { + + if (const QStyleOptionTabV3 *tabOptV3 = qstyleoption_cast<const QStyleOptionTabV3 *>(opt)) { + if (tabOptV3->documentMode) { + p->save(); + QRect tabRect = tabOptV3->rect; + drawTabShape(p, tabOptV3); + p->restore(); + return; + } } #if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4) @@ -5006,11 +5023,10 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex bdi.kind = kThemeIncDecButton; break; case QAquaSizeMini: + bdi.kind = kThemeIncDecButtonMini; + break; case QAquaSizeSmall: - if (aquaSize == QAquaSizeMini) - bdi.kind = kThemeIncDecButtonMini; - else - bdi.kind = kThemeIncDecButtonSmall; + bdi.kind = kThemeIncDecButtonSmall; break; } if (!(sb->stepEnabled & (QAbstractSpinBox::StepUpEnabled @@ -5030,8 +5046,8 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex bdi.value = kThemeButtonOff; bdi.adornment = kThemeAdornmentNone; - QRect updown = subControlRect(CC_SpinBox, sb, SC_SpinBoxUp, - widget); + QRect updown = subControlRect(CC_SpinBox, sb, SC_SpinBoxUp, widget); + updown |= subControlRect(CC_SpinBox, sb, SC_SpinBoxDown, widget); HIRect newRect = qt_hirectForQRect(updown); QRect off_rct; @@ -5042,15 +5058,6 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex int(outRect.size.width - newRect.size.width), int(outRect.size.height - newRect.size.height)); - // HIThemeGetButtonBackgroundBounds offsets non-focused normal sized - // buttons by one in de y direction, account for that here. - if (bdi.adornment == kThemeAdornmentNone && bdi.kind == kThemeIncDecButton) - off_rct.adjust(0, 1, 0, 0); - - // Adjust the rect for small buttos also. - if (bdi.adornment == kThemeAdornmentFocus && bdi.kind == kThemeIncDecButtonSmall) - off_rct.adjust(0, 0, 0, -1); - newRect = qt_hirectForQRect(updown, off_rct); HIThemeDrawButton(&newRect, &bdi, cg, kHIThemeOrientationNormal, 0); } @@ -5715,39 +5722,61 @@ QRect QMacStyle::subControlRect(ComplexControl cc, const QStyleOptionComplex *op break; case CC_SpinBox: if (const QStyleOptionSpinBox *spin = qstyleoption_cast<const QStyleOptionSpinBox *>(opt)) { - const int spinner_w = 14, - fw = pixelMetric(PM_SpinBoxFrameWidth, spin, widget); + QAquaWidgetSize aquaSize = d->aquaSizeConstrain(spin, widget); + int spinner_w; + int spinBoxSep; + int fw = pixelMetric(PM_SpinBoxFrameWidth, spin, widget); + switch (aquaSize) { + default: + case QAquaSizeUnknown: + case QAquaSizeLarge: + spinner_w = 14; + spinBoxSep = 2; + break; + case QAquaSizeSmall: + spinner_w = 12; + spinBoxSep = 2; + break; + case QAquaSizeMini: + spinner_w = 10; + spinBoxSep = 1; + break; + } + switch (sc) { case SC_SpinBoxUp: case SC_SpinBoxDown: { if (spin->buttonSymbols == QAbstractSpinBox::NoButtons) break; - const int frameWidth = pixelMetric(PM_SpinBoxFrameWidth, spin, widget); - const int spinner_w = 18; - const int y = frameWidth; - const int x = spin->rect.width() - spinner_w + frameWidth; + + const int y = fw; + const int x = spin->rect.width() - spinner_w; ret.setRect(x + spin->rect.x(), y + spin->rect.y(), spinner_w, spin->rect.height() - y * 2); HIThemeButtonDrawInfo bdi; bdi.version = qt_mac_hitheme_version; bdi.kind = kThemeIncDecButton; - QAquaWidgetSize aquaSize = d->aquaSizeConstrain(opt, widget); + int hackTranslateX; switch (aquaSize) { - case QAquaSizeUnknown: - case QAquaSizeLarge: - bdi.kind = kThemeIncDecButton; - break; - case QAquaSizeMini: - case QAquaSizeSmall: - if (aquaSize == QAquaSizeMini) - bdi.kind = kThemeIncDecButtonMini; - else - bdi.kind = kThemeIncDecButtonSmall; - break; + default: + case QAquaSizeUnknown: + case QAquaSizeLarge: + bdi.kind = kThemeIncDecButton; + hackTranslateX = 0; + break; + case QAquaSizeSmall: + bdi.kind = kThemeIncDecButtonSmall; + hackTranslateX = -2; + break; + case QAquaSizeMini: + bdi.kind = kThemeIncDecButtonMini; + hackTranslateX = -1; + break; } bdi.state = kThemeStateActive; bdi.value = kThemeButtonOff; bdi.adornment = kThemeAdornmentNone; HIRect hirect = qt_hirectForQRect(ret); + HIRect outRect; HIThemeGetButtonBackgroundBounds(&hirect, &bdi, &outRect); ret = qt_qrectForHIRect(outRect); @@ -5762,13 +5791,13 @@ QRect QMacStyle::subControlRect(ComplexControl cc, const QStyleOptionComplex *op Q_ASSERT(0); break; } - ret.translate(-1, -2); // hack: position the buttons correctly (weird that we need this) + ret.translate(hackTranslateX, 0); // hack: position the buttons correctly (weird that we need this) ret = visualRect(spin->direction, spin->rect, ret); break; } case SC_SpinBoxEditField: ret.setRect(fw, fw, - spin->rect.width() - spinner_w - fw * 2 - macSpinBoxSep + 1, + spin->rect.width() - spinner_w - fw * 2 - spinBoxSep, spin->rect.height() - fw * 2); ret = visualRect(spin->direction, spin->rect, ret); break; @@ -5800,8 +5829,8 @@ QSize QMacStyle::sizeFromContents(ContentsType ct, const QStyleOption *opt, switch (ct) { case QStyle::CT_SpinBox: - sz.setWidth(sz.width() + macSpinBoxSep); - sz.setHeight(sz.height() - 3); // hack to work around horrible sizeHint() code in QAbstractSpinBox + // hack to work around horrible sizeHint() code in QAbstractSpinBox + sz.setHeight(sz.height() - 3); break; case QStyle::CT_TabBarTab: if (const QStyleOptionTabV3 *tab = qstyleoption_cast<const QStyleOptionTabV3 *>(opt)) { diff --git a/src/gui/styles/qstylesheetstyle.cpp b/src/gui/styles/qstylesheetstyle.cpp index f42792d..714b8c5 100644 --- a/src/gui/styles/qstylesheetstyle.cpp +++ b/src/gui/styles/qstylesheetstyle.cpp @@ -1514,20 +1514,11 @@ void QRenderRule::configurePalette(QPalette *p, QPalette::ColorRole fr, QPalette void QRenderRule::configurePalette(QPalette *p, QPalette::ColorGroup cg, const QWidget *w, bool embedded) { -#ifdef QT_NO_COMBOBOX - const bool isReadOnlyCombo = false; -#else - const bool isReadOnlyCombo = qobject_cast<const QComboBox *>(w) != 0; -#endif - if (bg && bg->brush.style() != Qt::NoBrush) { - if (isReadOnlyCombo) { - p->setBrush(cg, QPalette::Base, bg->brush); // for windows, windowxp - p->setBrush(cg, QPalette::Button, bg->brush); // for plastique - } else { - p->setBrush(cg, w->backgroundRole(), bg->brush); - //p->setBrush(cg, QPalette::Window, bg->brush); - } + p->setBrush(cg, QPalette::Base, bg->brush); // for windows, windowxp + p->setBrush(cg, QPalette::Button, bg->brush); // for plastique + p->setBrush(cg, w->backgroundRole(), bg->brush); + p->setBrush(cg, QPalette::Window, bg->brush); } if (embedded) { @@ -1542,12 +1533,9 @@ void QRenderRule::configurePalette(QPalette *p, QPalette::ColorGroup cg, const Q return; if (pal->foreground.style() != Qt::NoBrush) { - if (isReadOnlyCombo) { - p->setBrush(cg, QPalette::ButtonText, pal->foreground); - } else { - p->setBrush(cg, w->foregroundRole(), pal->foreground); - p->setBrush(cg, QPalette::WindowText, pal->foreground); - } + p->setBrush(cg, QPalette::ButtonText, pal->foreground); + p->setBrush(cg, w->foregroundRole(), pal->foreground); + p->setBrush(cg, QPalette::WindowText, pal->foreground); p->setBrush(cg, QPalette::Text, pal->foreground); } if (pal->selectionBackground.style() != Qt::NoBrush) @@ -2916,6 +2904,10 @@ void QStyleSheetStyle::polish(QWidget *w) if (ew->autoFillBackground()) { ew->setAutoFillBackground(false); autoFillDisabledWidgets->insert(w); + if (ew != w) { //eg. viewport of a scrollarea + //(in order to draw the background anyway in case we don't.) + ew->setAttribute(Qt::WA_StyledBackground, true); + } } if (!rule.hasBackground() || rule.background()->isTransparent() || rule.hasBox() || (!rule.hasNativeBorder() && !rule.border()->isOpaque())) @@ -4345,8 +4337,16 @@ void QStyleSheetStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *op return; case PE_Widget: - if (!rule.hasBackground()) + if (!rule.hasBackground()) { + QWidget *container = containerWidget(w); + if (autoFillDisabledWidgets->contains(container) + && (container == w || !renderRule(container, opt).hasBackground())) { + //we do not have a background, but we disabled the autofillbackground anyway. so fill the background now. + // (this may happen if we have rules like :focus) + p->fillRect(opt->rect, opt->palette.brush(w->backgroundRole())); + } break; + } #ifndef QT_NO_SCROLLAREA if (const QAbstractScrollArea *sa = qobject_cast<const QAbstractScrollArea *>(w)) { @@ -4623,15 +4623,6 @@ int QStyleSheetStyle::pixelMetric(PixelMetric m, const QStyleOption *opt, const break; case PM_DefaultFrameWidth: -#ifndef QT_NO_COMBOBOX - // QComboBox uses this for resizing its popup - if (qobject_cast<const QComboBox *>(w)) { - QAbstractItemView *view = qFindChild<QAbstractItemView *>(w); - QRenderRule subRule = renderRule(view, PseudoElement_None); - if (!subRule.hasNativeBorder()) - return subRule.border()->borders[TopEdge] + (subRule.hasBox() ? subRule.box()->paddings[TopEdge] : 0); - } else -#endif if (!rule.hasNativeBorder()) return rule.border()->borders[LeftEdge]; break; @@ -4849,7 +4840,8 @@ int QStyleSheetStyle::pixelMetric(PixelMetric m, const QStyleOption *opt, const if (subRule.hasContentsSize()) return subRule.size().height(); else if (subRule.hasBox() || subRule.hasBorder()) { - return subRule.size(QSize(0, opt->fontMetrics.lineSpacing())).height(); + QFontMetrics fm = opt ? opt->fontMetrics : w->fontMetrics(); + return subRule.size(QSize(0, fm.lineSpacing())).height(); } break; } @@ -4934,7 +4926,7 @@ QSize QStyleSheetStyle::sizeFromContents(ContentsType ct, const QStyleOption *op case CT_LineEdit: #ifndef QT_NO_SPINBOX // ### hopelessly broken QAbstractSpinBox (part 2) - if (QAbstractSpinBox *spinBox = qobject_cast<QAbstractSpinBox *>(w->parentWidget())) { + if (QAbstractSpinBox *spinBox = qobject_cast<QAbstractSpinBox *>(w ? w->parentWidget() : 0)) { QRenderRule rule = renderRule(spinBox, opt); if (rule.hasBox() || !rule.hasNativeBorder()) return csz; @@ -5850,7 +5842,7 @@ QRect QStyleSheetStyle::subElementRect(SubElement se, const QStyleOption *opt, c bool QStyleSheetStyle::event(QEvent *e) { - return baseStyle()->event(e) || ParentStyle::event(e); + return (baseStyle()->event(e) && e->isAccepted()) || ParentStyle::event(e); } void QStyleSheetStyle::updateStyleSheetFont(QWidget* w) const diff --git a/src/gui/styles/qwindowsmobilestyle.cpp b/src/gui/styles/qwindowsmobilestyle.cpp index c52c700..1c03b9e 100644 --- a/src/gui/styles/qwindowsmobilestyle.cpp +++ b/src/gui/styles/qwindowsmobilestyle.cpp @@ -3401,6 +3401,9 @@ int QWindowsMobileStyle::styleHint(StyleHint hint, const QStyleOption *opt, cons case SH_ScrollBar_ContextMenu: ret = false; break; + case SH_MenuBar_AltKeyNavigation: + ret = false; + break; default: ret = QWindowsStyle::styleHint(hint, opt, widget, returnData); break; diff --git a/src/gui/styles/qwindowsvistastyle.cpp b/src/gui/styles/qwindowsvistastyle.cpp index 4c3060d..013ca1e 100644 --- a/src/gui/styles/qwindowsvistastyle.cpp +++ b/src/gui/styles/qwindowsvistastyle.cpp @@ -801,12 +801,20 @@ void QWindowsVistaStyle::drawPrimitive(PrimitiveElement element, const QStyleOpt if (vopt->viewItemPosition == QStyleOptionViewItemV4::OnlyOne || vopt->viewItemPosition == QStyleOptionViewItemV4::Invalid) painter->drawPixmap(pixmapRect.topLeft(), pixmap); - else if (reverse ? rightSection : leftSection) - painter->drawPixmap(pixmapRect, pixmap, srcRect.adjusted(0, 0, -frame, 0)); - else if (reverse ? leftSection : rightSection) - painter->drawPixmap(pixmapRect, pixmap, - srcRect.adjusted(frame, 0, 0, 0)); - else if (vopt->viewItemPosition == QStyleOptionViewItemV4::Middle) + else if (reverse ? rightSection : leftSection){ + painter->drawPixmap(QRect(pixmapRect.topLeft(), + QSize(frame, pixmapRect.height())), pixmap, + QRect(QPoint(0, 0), QSize(frame, pixmapRect.height()))); + painter->drawPixmap(pixmapRect.adjusted(frame, 0, 0, 0), + pixmap, srcRect.adjusted(frame, 0, -frame, 0)); + } else if (reverse ? leftSection : rightSection) { + painter->drawPixmap(QRect(pixmapRect.topRight() - QPoint(frame - 1, 0), + QSize(frame, pixmapRect.height())), pixmap, + QRect(QPoint(pixmapRect.width() - frame, 0), + QSize(frame, pixmapRect.height()))); + painter->drawPixmap(pixmapRect.adjusted(0, 0, -frame, 0), + pixmap, srcRect.adjusted(frame, 0, -frame, 0)); + } else if (vopt->viewItemPosition == QStyleOptionViewItemV4::Middle) painter->drawPixmap(pixmapRect, pixmap, srcRect.adjusted(frame, 0, -frame, 0)); } else { @@ -2388,6 +2396,9 @@ void QWindowsVistaStyle::polish(QWidget *widget) else if (QTreeView *tree = qobject_cast<QTreeView *> (widget)) { tree->viewport()->setAttribute(Qt::WA_Hover); } + else if (QListView *list = qobject_cast<QListView *> (widget)) { + list->viewport()->setAttribute(Qt::WA_Hover); + } } /*! diff --git a/src/gui/styles/qwindowsvistastyle_p.h b/src/gui/styles/qwindowsvistastyle_p.h index 877bc50..cef2b71 100644 --- a/src/gui/styles/qwindowsvistastyle_p.h +++ b/src/gui/styles/qwindowsvistastyle_p.h @@ -76,6 +76,7 @@ #include <qscrollbar.h> #include <qprogressbar.h> #include <qdockwidget.h> +#include <qlistview.h> #include <qtreeview.h> #include <qtextedit.h> #include <qmessagebox.h> diff --git a/src/gui/styles/qwindowsxpstyle.cpp b/src/gui/styles/qwindowsxpstyle.cpp index 9d735a7..2f4254e 100644 --- a/src/gui/styles/qwindowsxpstyle.cpp +++ b/src/gui/styles/qwindowsxpstyle.cpp @@ -607,7 +607,7 @@ void QWindowsXPStylePrivate::drawBackground(XPThemeData &themeData) QPainter *painter = themeData.painter; Q_ASSERT_X(painter != 0, "QWindowsXPStylePrivate::drawBackground()", "Trying to draw a theme part without a painter"); - if (!painter) + if (!painter || !painter->isActive()) return; painter->save(); @@ -2834,7 +2834,7 @@ void QWindowsXPStyle::drawComplexControl(ComplexControl cc, const QStyleOptionCo bflags |= State_MouseOver; } } - + QStyleOption tool(0); tool.palette = toolbutton->palette; if (toolbutton->subControls & SC_ToolButton) { diff --git a/src/gui/text/qcssparser.cpp b/src/gui/text/qcssparser.cpp index 02fe2b2..8214e54 100644 --- a/src/gui/text/qcssparser.cpp +++ b/src/gui/text/qcssparser.cpp @@ -278,19 +278,15 @@ static const QCssKnownValue values[NumKnownValues - 1] = { { "xx-large", Value_XXLarge } }; +//Map id to strings as they appears in the 'values' array above +static const int indexOfId[NumKnownValues] = { 0, 40, 47, 41, 48, 53, 34, 26, 68, 69, 25, 42, 5, 62, 46, + 29, 57, 58, 27, 50, 60, 6, 10, 38, 55, 19, 13, 17, 18, 20, 21, 49, 24, 45, 65, 36, 3, 2, 39, 61, 16, + 11, 56, 14, 32, 63, 54, 64, 33, 67, 8, 28, 37, 12, 35, 59, 7, 9, 4, 66, 52, 22, 23, 30, 31, 1, 15, 0, + 51, 44, 43 }; + QString Value::toString() const { - static int indexOfId[NumKnownValues - 1]; - static bool hasCachedIndexes = false; - if (type == KnownIdentifier) { - if (!hasCachedIndexes) { - for (int i = 0; i < NumKnownValues - 1; ++i) - indexOfId[values[i].id] = i; - - hasCachedIndexes = true; - } - return QLatin1String(values[indexOfId[variant.toInt()]].name); } else { return variant.toString(); @@ -2682,7 +2678,10 @@ bool Parser::parseFunction(QString *name, QString *args) bool Parser::parseHexColor(QColor *col) { col->setNamedColor(lexem()); - if (!col->isValid()) return false; + if (!col->isValid()) { + qWarning("QCssParser::parseHexColor: Unknown color name '%s'",lexem().toLatin1().constData()); + return false; + } skipSpace(); return true; } diff --git a/src/gui/text/qfont.cpp b/src/gui/text/qfont.cpp index 8538040..f73ffb5 100644 --- a/src/gui/text/qfont.cpp +++ b/src/gui/text/qfont.cpp @@ -249,9 +249,10 @@ QFontPrivate::~QFontPrivate() } #if !defined(Q_WS_MAC) +extern QMutex *qt_fontdatabase_mutex(); + QFontEngine *QFontPrivate::engineForScript(int script) const { - extern QMutex *qt_fontdatabase_mutex(); QMutexLocker locker(qt_fontdatabase_mutex()); if (script >= QUnicodeTables::Inherited) script = QUnicodeTables::Common; @@ -889,7 +890,10 @@ int QFont::pointSize() const */ void QFont::setPointSize(int pointSize) { - Q_ASSERT_X (pointSize > 0, "QFont::setPointSize", "point size must be greater than 0"); + if (pointSize <= 0) { + qWarning("QFont::setPointSize: Point size <= 0 (%d), must be greater than 0", pointSize); + return; + } detach(); @@ -908,7 +912,10 @@ void QFont::setPointSize(int pointSize) */ void QFont::setPointSizeF(qreal pointSize) { - Q_ASSERT_X(pointSize > 0.0, "QFont::setPointSizeF", "point size must be greater than 0"); + if (pointSize <= 0) { + qWarning("QFont::setPointSizeF: Point size <= 0 (%f), must be greater than 0", pointSize); + return; + } detach(); diff --git a/src/gui/text/qfontdatabase_win.cpp b/src/gui/text/qfontdatabase_win.cpp index c9f5586..780ae28 100644 --- a/src/gui/text/qfontdatabase_win.cpp +++ b/src/gui/text/qfontdatabase_win.cpp @@ -699,6 +699,7 @@ QFontEngine *loadEngine(int script, const QFontPrivate *fp, const QFontDef &requ } bool stockFont = false; + bool preferClearTypeAA = false; HFONT hfont = 0; @@ -799,10 +800,12 @@ QFontEngine *loadEngine(int script, const QFontPrivate *fp, const QFontDef &requ #endif if (request.styleStrategy & QFont::PreferAntialias) { - if (QSysInfo::WindowsVersion >= QSysInfo::WV_XP) + if (QSysInfo::WindowsVersion >= QSysInfo::WV_XP) { qual = 5; // == CLEARTYPE_QUALITY; - else + preferClearTypeAA = true; + } else { qual = ANTIALIASED_QUALITY; + } } else if (request.styleStrategy & QFont::NoAntialias) { qual = NONANTIALIASED_QUALITY; } @@ -884,6 +887,9 @@ QFontEngine *loadEngine(int script, const QFontPrivate *fp, const QFontDef &requ } QFontEngineWin *few = new QFontEngineWin(font_name, hfont, stockFont, lf); + if (preferClearTypeAA) + few->glyphFormat = QFontEngineGlyphCache::Raster_RGBMask; + // Also check for OpenType tables when using complex scripts // ### TODO: This only works for scripts that require OpenType. More generally // for scripts that do not require OpenType we should just look at the list of @@ -1134,7 +1140,7 @@ static void getFamiliesAndSignatures(const QByteArray &fontData, QFontDatabasePr signature.fsUsb[1] = qFromBigEndian<quint32>(table + 46); signature.fsUsb[2] = qFromBigEndian<quint32>(table + 50); signature.fsUsb[3] = qFromBigEndian<quint32>(table + 54); - + signature.fsCsb[0] = qFromBigEndian<quint32>(table + 78); signature.fsCsb[1] = qFromBigEndian<quint32>(table + 82); } diff --git a/src/gui/text/qfontengine.cpp b/src/gui/text/qfontengine.cpp index c4dffdf..d7a9c23 100644 --- a/src/gui/text/qfontengine.cpp +++ b/src/gui/text/qfontengine.cpp @@ -542,7 +542,7 @@ void QFontEngine::addBitmapFontToPath(qreal x, qreal y, const QGlyphLayout &glyp advanceY += glyphs.advances_y[i]; continue; } - QImage alphaMask = alphaMapForGlyph(glyphs.glyphs[i]); + const QImage alphaMask = alphaMapForGlyph(glyphs.glyphs[i]); const int w = alphaMask.width(); const int h = alphaMask.height(); @@ -624,6 +624,45 @@ QImage QFontEngine::alphaRGBMapForGlyph(glyph_t glyph, int /* margin */, const Q return rgbMask; } +QImage QFontEngine::alphaMapForGlyph(glyph_t glyph) +{ + glyph_metrics_t gm = boundingBox(glyph); + int glyph_x = qFloor(gm.x.toReal()); + int glyph_y = qFloor(gm.y.toReal()); + int glyph_width = qCeil((gm.x + gm.width).toReal()) - glyph_x; + int glyph_height = qCeil((gm.y + gm.height).toReal()) - glyph_y; + + if (glyph_width <= 0 || glyph_height <= 0) + return QImage(); + QFixedPoint pt; + pt.x = 0; + pt.y = -glyph_y; // the baseline + QPainterPath path; + QImage im(glyph_width + qAbs(glyph_x) + 4, glyph_height, QImage::Format_ARGB32_Premultiplied); + im.fill(Qt::transparent); + QPainter p(&im); + p.setRenderHint(QPainter::Antialiasing); + addGlyphsToPath(&glyph, &pt, 1, &path, 0); + p.setPen(Qt::NoPen); + p.setBrush(Qt::black); + p.drawPath(path); + p.end(); + + QImage indexed(im.width(), im.height(), QImage::Format_Indexed8); + QVector<QRgb> colors(256); + for (int i=0; i<256; ++i) + colors[i] = qRgba(0, 0, 0, i); + indexed.setColorTable(colors); + + for (int y=0; y<im.height(); ++y) { + uchar *dst = (uchar *) indexed.scanLine(y); + uint *src = (uint *) im.scanLine(y); + for (int x=0; x<im.width(); ++x) + dst[x] = qAlpha(src[x]); + } + + return indexed; +} void QFontEngine::removeGlyphFromCache(glyph_t) { diff --git a/src/gui/text/qfontengine_ft.cpp b/src/gui/text/qfontengine_ft.cpp index 264d8de..6f5ee1f 100644 --- a/src/gui/text/qfontengine_ft.cpp +++ b/src/gui/text/qfontengine_ft.cpp @@ -521,15 +521,28 @@ QFontEngineFT::Glyph::~Glyph() delete [] data; } -#if !defined(QT_USE_FREETYPE_LCDFILTER) static const uint subpixel_filter[3][3] = { { 180, 60, 16 }, { 38, 180, 38 }, { 16, 60, 180 } }; -#endif -static void convertRGBToARGB(const uchar *src, uint *dst, int width, int height, int src_pitch, bool bgr) +static inline uint filterPixel(uint red, uint green, uint blue, bool legacyFilter) +{ + uint res; + if (legacyFilter) { + uint high = (red*subpixel_filter[0][0] + green*subpixel_filter[0][1] + blue*subpixel_filter[0][2]) >> 8; + uint mid = (red*subpixel_filter[1][0] + green*subpixel_filter[1][1] + blue*subpixel_filter[1][2]) >> 8; + uint low = (red*subpixel_filter[2][0] + green*subpixel_filter[2][1] + blue*subpixel_filter[2][2]) >> 8; + res = (mid << 24) + (high << 16) + (mid << 8) + low; + } else { + uint alpha = green; + res = (alpha << 24) + (red << 16) + (green << 8) + blue; + } + return res; +} + +static void convertRGBToARGB(const uchar *src, uint *dst, int width, int height, int src_pitch, bool bgr, bool legacyFilter) { int h = height; const int offs = bgr ? -1 : 1; @@ -540,9 +553,7 @@ static void convertRGBToARGB(const uchar *src, uint *dst, int width, int height, uint red = src[x+1-offs]; uint green = src[x+1]; uint blue = src[x+1+offs]; - uint alpha = green; - uint res = (alpha << 24) + (red << 16) + (green << 8) + blue; - *dd = res; + *dd = filterPixel(red, green, blue, legacyFilter); ++dd; } dst += width; @@ -550,7 +561,7 @@ static void convertRGBToARGB(const uchar *src, uint *dst, int width, int height, } } -static void convertRGBToARGB_V(const uchar *src, uint *dst, int width, int height, int src_pitch, bool bgr) +static void convertRGBToARGB_V(const uchar *src, uint *dst, int width, int height, int src_pitch, bool bgr, bool legacyFilter) { int h = height; const int offs = bgr ? -src_pitch : src_pitch; @@ -559,16 +570,7 @@ static void convertRGBToARGB_V(const uchar *src, uint *dst, int width, int heigh uint red = src[x+src_pitch-offs]; uint green = src[x+src_pitch]; uint blue = src[x+src_pitch+offs]; -#if defined(QT_USE_FREETYPE_LCDFILTER) - uint alpha = green; - uint res = (alpha << 24) + (red << 16) + (green << 8) + blue; -#else - uint high = (red*subpixel_filter[0][0] + green*subpixel_filter[0][1] + blue*subpixel_filter[0][2]) >> 8; - uint mid = (red*subpixel_filter[1][0] + green*subpixel_filter[1][1] + blue*subpixel_filter[1][2]) >> 8; - uint low = (red*subpixel_filter[2][0] + green*subpixel_filter[2][1] + blue*subpixel_filter[2][2]) >> 8; - uint res = (mid << 24) + (high << 16) + (mid << 8) + low; -#endif - dst[x] = res; + dst[x] = filterPixel(red, green, blue, legacyFilter); } dst += width; src += 3*src_pitch; @@ -611,7 +613,7 @@ QFontEngineFT::QFontEngineFT(const QFontDef &fd) subpixelType = Subpixel_None; lcdFilterType = 0; #if defined(FT_LCD_FILTER_H) - lcdFilterType = (int) FT_LCD_FILTER_DEFAULT; + lcdFilterType = (int)((quintptr) FT_LCD_FILTER_DEFAULT); #endif defaultFormat = Format_None; canUploadGlyphsToServer = false; @@ -923,8 +925,14 @@ QFontEngineFT::Glyph *QFontEngineFT::loadGlyph(QGlyphSet *set, uint glyph, Glyph uchar *glyph_buffer = 0; int glyph_buffer_size = 0; #if defined(QT_USE_FREETYPE_LCDFILTER) + bool useFreetypeRenderGlyph = false; if (slot->format == FT_GLYPH_FORMAT_OUTLINE && (hsubpixel || vfactor != 1)) { - FT_Library_SetLcdFilter(library, (FT_LcdFilter)lcdFilterType); + err = FT_Library_SetLcdFilter(library, (FT_LcdFilter)lcdFilterType); + if (err == FT_Err_Ok) + useFreetypeRenderGlyph = true; + } + + if (useFreetypeRenderGlyph) { err = FT_Render_Glyph(slot, hsubpixel ? FT_RENDER_MODE_LCD : FT_RENDER_MODE_LCD_V); if (err != FT_Err_Ok) @@ -932,8 +940,8 @@ QFontEngineFT::Glyph *QFontEngineFT::loadGlyph(QGlyphSet *set, uint glyph, Glyph FT_Library_SetLcdFilter(library, FT_LCD_FILTER_NONE); - info.height = slot->bitmap.rows; - info.width = slot->bitmap.width / 3; + info.height = slot->bitmap.rows / vfactor; + info.width = hsubpixel ? slot->bitmap.width / 3 : slot->bitmap.width; info.x = -slot->bitmap_left; info.y = slot->bitmap_top; @@ -941,9 +949,9 @@ QFontEngineFT::Glyph *QFontEngineFT::loadGlyph(QGlyphSet *set, uint glyph, Glyph glyph_buffer = new uchar[glyph_buffer_size]; if (hsubpixel) - convertRGBToARGB(slot->bitmap.buffer, (uint *)glyph_buffer, info.width, info.height, slot->bitmap.pitch, subpixelType != QFontEngineFT::Subpixel_RGB); + convertRGBToARGB(slot->bitmap.buffer, (uint *)glyph_buffer, info.width, info.height, slot->bitmap.pitch, subpixelType != QFontEngineFT::Subpixel_RGB, false); else if (vfactor != 1) - convertRGBToARGB_V(slot->bitmap.buffer, (uint *)glyph_buffer, info.width, info.height, slot->bitmap.pitch, subpixelType != QFontEngineFT::Subpixel_VRGB); + convertRGBToARGB_V(slot->bitmap.buffer, (uint *)glyph_buffer, info.width, info.height, slot->bitmap.pitch, subpixelType != QFontEngineFT::Subpixel_VRGB, false); } else #endif { @@ -1042,11 +1050,19 @@ QFontEngineFT::Glyph *QFontEngineFT::loadGlyph(QGlyphSet *set, uint glyph, Glyph Q_ASSERT (bitmap.pixel_mode == FT_PIXEL_MODE_GRAY); Q_ASSERT(antialias); uchar *convoluted = new uchar[bitmap.rows*bitmap.pitch]; - convoluteBitmap(bitmap.buffer, convoluted, bitmap.width, info.height, bitmap.pitch); - convertRGBToARGB(convoluted + 1, (uint *)glyph_buffer, info.width, info.height, bitmap.pitch, subpixelType != QFontEngineFT::Subpixel_RGB); + bool useLegacyLcdFilter = false; +#if defined(FC_LCD_FILTER) && defined(FT_LCD_FILTER_H) + useLegacyLcdFilter = (lcdFilterType == FT_LCD_FILTER_LEGACY); +#endif + uchar *buffer = bitmap.buffer; + if (!useLegacyLcdFilter) { + convoluteBitmap(bitmap.buffer, convoluted, bitmap.width, info.height, bitmap.pitch); + buffer = convoluted; + } + convertRGBToARGB(buffer + 1, (uint *)glyph_buffer, info.width, info.height, bitmap.pitch, subpixelType != QFontEngineFT::Subpixel_RGB, useLegacyLcdFilter); delete [] convoluted; } else if (vfactor != 1) { - convertRGBToARGB_V(bitmap.buffer, (uint *)glyph_buffer, info.width, info.height, bitmap.pitch, subpixelType != QFontEngineFT::Subpixel_VRGB); + convertRGBToARGB_V(bitmap.buffer, (uint *)glyph_buffer, info.width, info.height, bitmap.pitch, subpixelType != QFontEngineFT::Subpixel_VRGB, true); } if (bitmap.buffer != glyph_buffer) @@ -1505,6 +1521,11 @@ bool QFontEngineFT::stringToCMap(const QChar *str, int len, QGlyphLayout *glyphs return false; } +#if !defined(QT_NO_FONTCONFIG) + extern QMutex *qt_fontdatabase_mutex(); + QMutex *mtx = 0; +#endif + bool mirrored = flags & QTextEngine::RightToLeft; int glyph_pos = 0; if (freetype->symbol_map) { @@ -1517,6 +1538,11 @@ bool QFontEngineFT::stringToCMap(const QChar *str, int len, QGlyphLayout *glyphs if ( !glyphs->glyphs[glyph_pos] ) { glyph_t glyph; #if !defined(QT_NO_FONTCONFIG) + if (!mtx) { + mtx = qt_fontdatabase_mutex(); + mtx->lock(); + } + if (FcCharSetHasChar(freetype->charset, uc)) { #else if (false) { @@ -1545,20 +1571,26 @@ bool QFontEngineFT::stringToCMap(const QChar *str, int len, QGlyphLayout *glyphs if (mirrored) uc = QChar::mirroredChar(uc); glyphs->glyphs[glyph_pos] = uc < QFreetypeFace::cmapCacheSize ? freetype->cmapCache[uc] : 0; - if (!glyphs->glyphs[glyph_pos] + if (!glyphs->glyphs[glyph_pos]) { #if !defined(QT_NO_FONTCONFIG) - && FcCharSetHasChar(freetype->charset, uc) + if (!mtx) { + mtx = qt_fontdatabase_mutex(); + mtx->lock(); + } + + if (FcCharSetHasChar(freetype->charset, uc)) #endif - ) { - redo: - glyph_t glyph = FT_Get_Char_Index(face, uc); - if (!glyph && (uc == 0xa0 || uc == 0x9)) { - uc = 0x20; - goto redo; + { + redo: + glyph_t glyph = FT_Get_Char_Index(face, uc); + if (!glyph && (uc == 0xa0 || uc == 0x9)) { + uc = 0x20; + goto redo; + } + glyphs->glyphs[glyph_pos] = glyph; + if (uc < QFreetypeFace::cmapCacheSize) + freetype->cmapCache[uc] = glyph; } - glyphs->glyphs[glyph_pos] = glyph; - if (uc < QFreetypeFace::cmapCacheSize) - freetype->cmapCache[uc] = glyph; } ++glyph_pos; } @@ -1567,6 +1599,11 @@ bool QFontEngineFT::stringToCMap(const QChar *str, int len, QGlyphLayout *glyphs *nglyphs = glyph_pos; glyphs->numGlyphs = glyph_pos; +#if !defined(QT_NO_FONTCONFIG) + if (mtx) + mtx->unlock(); +#endif + if (flags & QTextEngine::GlyphIndicesOnly) return true; @@ -1772,9 +1809,11 @@ QImage QFontEngineFT::alphaMapForGlyph(glyph_t g) GlyphFormat glyph_format = antialias ? Format_A8 : Format_Mono; - Glyph *glyph = loadGlyph(g, glyph_format); - if (!glyph) - return QImage(); + Glyph *glyph = defaultGlyphSet.outline_drawing ? 0 : loadGlyph(g, glyph_format); + if (!glyph) { + unlockFace(); + return QFontEngine::alphaMapForGlyph(g); + } const int pitch = antialias ? (glyph->width + 3) & ~3 : ((glyph->width + 31)/32) * 4; diff --git a/src/gui/text/qfontengine_mac.mm b/src/gui/text/qfontengine_mac.mm index 40d145a..425cab2 100644 --- a/src/gui/text/qfontengine_mac.mm +++ b/src/gui/text/qfontengine_mac.mm @@ -120,7 +120,7 @@ OSStatus QMacFontPath::closePath(void *data) #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5 -QCoreTextFontEngineMulti::QCoreTextFontEngineMulti(const ATSFontFamilyRef &, const ATSFontRef &atsFontRef, const QFontDef &fontDef, bool) +QCoreTextFontEngineMulti::QCoreTextFontEngineMulti(const ATSFontFamilyRef &, const ATSFontRef &atsFontRef, const QFontDef &fontDef, bool kerning) : QFontEngineMulti(0) { this->fontDef = fontDef; @@ -149,11 +149,15 @@ QCoreTextFontEngineMulti::QCoreTextFontEngineMulti(const ATSFontFamilyRef &, con CFRetain(ctfont); } - const void *keys[] = { NSFontAttributeName }; - const void *values[] = { ctfont }; - attributeDict = CFDictionaryCreate(0, keys, values, 1, + attributeDict = CFDictionaryCreateMutable(0, 2, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); + CFDictionaryAddValue(attributeDict, NSFontAttributeName, ctfont); + if (!kerning) { + float zero = 0.0; + QCFType<CFNumberRef> noKern = CFNumberCreate(kCFAllocatorDefault, kCFNumberFloatType, &zero); + CFDictionaryAddValue(attributeDict, kCTKernAttributeName, &noKern); + } QCoreTextFontEngine *fe = new QCoreTextFontEngine(ctfont, fontDef, this); fe->ref.ref(); @@ -277,10 +281,11 @@ bool QCoreTextFontEngineMulti::stringToCMap(const QChar *str, int len, QGlyphLay outAdvances_x[idx] = QFixed::fromReal(tmpPoints[i + 1].x - tmpPoints[i].x); outAdvances_y[idx] = QFixed::fromReal(tmpPoints[i + 1].y - tmpPoints[i].y); } - double runWidth = ceil(CTRunGetTypographicBounds(run, range, 0, 0, 0)); - runWidth += tmpPoints[0].x; + CGSize lastGlyphAdvance; + CTFontGetAdvancesForGlyphs(runFont, kCTFontHorizontalOrientation, tmpGlyphs + glyphCount - 1, &lastGlyphAdvance, 1); + outGlyphs[rtl ? 0 : (glyphCount - 1)] = tmpGlyphs[glyphCount - 1] | fontIndex; - outAdvances_x[rtl ? 0 : (glyphCount - 1)] = QFixed::fromReal(runWidth - tmpPoints[glyphCount - 1].x); + outAdvances_x[rtl ? 0 : (glyphCount - 1)] = QFixed::fromReal(lastGlyphAdvance.width).ceil(); } outGlyphs += glyphCount; outAttributes += glyphCount; @@ -365,26 +370,26 @@ glyph_metrics_t QCoreTextFontEngine::boundingBox(glyph_t glyph) ret.y = -QFixed::fromReal(rect.origin.y) - ret.height; CGSize advances[1]; CTFontGetAdvancesForGlyphs(ctfont, kCTFontHorizontalOrientation, &g, advances, 1); - ret.xoff = QFixed::fromReal(advances[0].width); - ret.yoff = QFixed::fromReal(advances[0].height); + ret.xoff = QFixed::fromReal(advances[0].width).ceil(); + ret.yoff = QFixed::fromReal(advances[0].height).ceil(); return ret; } QFixed QCoreTextFontEngine::ascent() const { - return QFixed::fromReal(CTFontGetAscent(ctfont)); + return QFixed::fromReal(CTFontGetAscent(ctfont)).ceil(); } QFixed QCoreTextFontEngine::descent() const { - return QFixed::fromReal(CTFontGetDescent(ctfont)); + return QFixed::fromReal(CTFontGetDescent(ctfont)).ceil(); } QFixed QCoreTextFontEngine::leading() const { - return QFixed::fromReal(CTFontGetLeading(ctfont)); + return QFixed::fromReal(CTFontGetLeading(ctfont)).ceil(); } QFixed QCoreTextFontEngine::xHeight() const { - return QFixed::fromReal(CTFontGetXHeight(ctfont)); + return QFixed::fromReal(CTFontGetXHeight(ctfont)).ceil(); } QFixed QCoreTextFontEngine::averageCharWidth() const { diff --git a/src/gui/text/qfontengine_p.h b/src/gui/text/qfontengine_p.h index e289aa9..dc18991 100644 --- a/src/gui/text/qfontengine_p.h +++ b/src/gui/text/qfontengine_p.h @@ -178,7 +178,7 @@ public: * Create a qimage with the alpha values for the glyph. * Returns an image indexed_8 with index values ranging from 0=fully transparant to 255=opaque */ - virtual QImage alphaMapForGlyph(glyph_t) = 0; + virtual QImage alphaMapForGlyph(glyph_t); virtual QImage alphaMapForGlyph(glyph_t, const QTransform &t); virtual QImage alphaRGBMapForGlyph(glyph_t, int margin, const QTransform &t); @@ -480,7 +480,7 @@ private: uint fontIndexForFont(CTFontRef id) const; CTFontRef ctfont; - mutable QCFType<CFDictionaryRef> attributeDict; + mutable QCFType<CFMutableDictionaryRef> attributeDict; friend class QFontDialogPrivate; }; diff --git a/src/gui/text/qfontengine_win.cpp b/src/gui/text/qfontengine_win.cpp index e9f1c99..1996d44 100644 --- a/src/gui/text/qfontengine_win.cpp +++ b/src/gui/text/qfontengine_win.cpp @@ -1438,6 +1438,7 @@ QNativeImage *QFontEngineWin::drawGDIGlyph(HFONT font, glyph_t glyph, int margin extern bool qt_cleartype_enabled; +extern uint qt_pow_gamma[256]; QImage QFontEngineWin::alphaMapForGlyph(glyph_t glyph, const QTransform &xform) { @@ -1461,8 +1462,6 @@ QImage QFontEngineWin::alphaMapForGlyph(glyph_t glyph, const QTransform &xform) colors[i] = qRgba(0, 0, 0, i); indexed.setColorTable(colors); - extern uint qt_pow_gamma[256]; - // Copy data... Cannot use QPainter here as GDI has messed up the // Alpha channel of the ni.image pixels... for (int y=0; y<mask->height(); ++y) { diff --git a/src/gui/text/qtextcursor.cpp b/src/gui/text/qtextcursor.cpp index c327b9f..48963bb 100644 --- a/src/gui/text/qtextcursor.cpp +++ b/src/gui/text/qtextcursor.cpp @@ -1074,7 +1074,10 @@ QTextCursor::QTextCursor(const QTextCursor &cursor) } /*! - Makes a copy of \a cursor and assigns it to this QTextCursor. + Makes a copy of \a cursor and assigns it to this QTextCursor. Note + that QTextCursor is an \l{Implicitly Shared Classes}{implicitly + shared} class. + */ QTextCursor &QTextCursor::operator=(const QTextCursor &cursor) { diff --git a/src/gui/text/qtextdocument.cpp b/src/gui/text/qtextdocument.cpp index e84b324..873f846 100644 --- a/src/gui/text/qtextdocument.cpp +++ b/src/gui/text/qtextdocument.cpp @@ -287,7 +287,7 @@ QTextCodec *Qt::codecForHtml(const QByteArray &ba) that inform connected editor widgets about the state of the undo/redo system. - \sa QTextCursor QTextEdit \link richtext.html Rich Text Processing\endlink + \sa QTextCursor, QTextEdit, \link richtext.html Rich Text Processing\endlink , {Text Object Example} */ /*! diff --git a/src/gui/text/qtextdocument.h b/src/gui/text/qtextdocument.h index c337783..9c3d6c2 100644 --- a/src/gui/text/qtextdocument.h +++ b/src/gui/text/qtextdocument.h @@ -287,6 +287,7 @@ public: private: Q_DISABLE_COPY(QTextDocument) Q_DECLARE_PRIVATE(QTextDocument) + friend class QTextObjectPrivate; }; Q_DECLARE_OPERATORS_FOR_FLAGS(QTextDocument::FindFlags) diff --git a/src/gui/text/qtextdocument_p.cpp b/src/gui/text/qtextdocument_p.cpp index 320ecbf..05ddf47 100644 --- a/src/gui/text/qtextdocument_p.cpp +++ b/src/gui/text/qtextdocument_p.cpp @@ -1484,7 +1484,6 @@ QTextObject *QTextDocumentPrivate::createObject(const QTextFormat &f, int object QTextObject *obj = document()->createObject(f); if (obj) { - obj->d_func()->pieceTable = this; obj->d_func()->objectIndex = objectIndex == -1 ? formats.createObjectIndex(f) : objectIndex; objects[obj->d_func()->objectIndex] = obj; } diff --git a/src/gui/text/qtextformat.h b/src/gui/text/qtextformat.h index 0571d75..8eaeeb1 100644 --- a/src/gui/text/qtextformat.h +++ b/src/gui/text/qtextformat.h @@ -232,6 +232,12 @@ public: ImageWidth = 0x5010, ImageHeight = 0x5011, + // internal + /* + SuppressText = 0x5012, + SuppressBackground = 0x513 + */ + // selection properties FullWidthSelection = 0x06000, diff --git a/src/gui/text/qtexthtmlparser.cpp b/src/gui/text/qtexthtmlparser.cpp index 86a1f68..b1f1b75 100644 --- a/src/gui/text/qtexthtmlparser.cpp +++ b/src/gui/text/qtexthtmlparser.cpp @@ -1525,6 +1525,8 @@ void QTextHtmlParser::applyAttributes(const QStringList &attributes) node->charFormat.setFontFamily(value); } else if (key == QLatin1String("color")) { QColor c; c.setNamedColor(value); + if (!c.isValid()) + qWarning("QTextHtmlParser::applyAttributes: Unknown color name '%s'",value.toLatin1().constData()); node->charFormat.setForeground(c); } break; @@ -1570,6 +1572,8 @@ void QTextHtmlParser::applyAttributes(const QStringList &attributes) case Html_body: if (key == QLatin1String("bgcolor")) { QColor c; c.setNamedColor(value); + if (!c.isValid()) + qWarning("QTextHtmlParser::applyAttributes: Unknown color name '%s'",value.toLatin1().constData()); node->charFormat.setBackground(c); } else if (key == QLatin1String("background")) { node->applyBackgroundImage(value, resourceProvider); @@ -1581,6 +1585,8 @@ void QTextHtmlParser::applyAttributes(const QStringList &attributes) setWidthAttribute(&node->width, value); } else if (key == QLatin1String("bgcolor")) { QColor c; c.setNamedColor(value); + if (!c.isValid()) + qWarning("QTextHtmlParser::applyAttributes: Unknown color name '%s'",value.toLatin1().constData()); node->charFormat.setBackground(c); } else if (key == QLatin1String("background")) { node->applyBackgroundImage(value, resourceProvider); @@ -1597,6 +1603,8 @@ void QTextHtmlParser::applyAttributes(const QStringList &attributes) setFloatAttribute(&node->tableBorder, value); } else if (key == QLatin1String("bgcolor")) { QColor c; c.setNamedColor(value); + if (!c.isValid()) + qWarning("QTextHtmlParser::applyAttributes: Unknown color name '%s'",value.toLatin1().constData()); node->charFormat.setBackground(c); } else if (key == QLatin1String("background")) { node->applyBackgroundImage(value, resourceProvider); diff --git a/src/gui/text/qtextlayout.cpp b/src/gui/text/qtextlayout.cpp index 434d1ca..fa624ef 100644 --- a/src/gui/text/qtextlayout.cpp +++ b/src/gui/text/qtextlayout.cpp @@ -61,6 +61,8 @@ QT_BEGIN_NAMESPACE #define ObjectSelectionBrush (QTextFormat::ForegroundBrush + 1) +#define SuppressText 0x5012 +#define SuppressBackground 0x513 static inline QFixed leadingSpaceWidth(QTextEngine *eng, const QScriptLine &line) { @@ -1143,6 +1145,7 @@ void QTextLayout::draw(QPainter *p, const QPointF &pos, const QVector<FormatRang } QPainterPath excludedRegion; + QPainterPath textDoneRegion; for (int i = 0; i < selections.size(); ++i) { FormatRange selection = selections.at(i); const QBrush bg = selection.format.background(); @@ -1202,23 +1205,55 @@ void QTextLayout::draw(QPainter *p, const QPointF &pos, const QVector<FormatRang } + + bool hasText = (selection.format.foreground().style() != Qt::NoBrush); + bool hasBackground= (selection.format.background().style() != Qt::NoBrush); + + if (hasBackground) { + selection.format.setProperty(ObjectSelectionBrush, selection.format.property(QTextFormat::BackgroundBrush)); + // don't just clear the property, set an empty brush that overrides a potential + // background brush specified in the text + selection.format.setProperty(QTextFormat::BackgroundBrush, QBrush()); + selection.format.clearProperty(QTextFormat::OutlinePen); + } + + selection.format.setProperty(SuppressText, !hasText); + + if (hasText && !hasBackground && !(textDoneRegion & region).isEmpty()) + continue; + p->save(); p->setClipPath(region, Qt::IntersectClip); - selection.format.setProperty(ObjectSelectionBrush, selection.format.property(QTextFormat::BackgroundBrush)); - // don't just clear the property, set an empty brush that overrides a potential - // background brush specified in the text - selection.format.setProperty(QTextFormat::BackgroundBrush, QBrush()); - selection.format.clearProperty(QTextFormat::OutlinePen); - for (int line = firstLine; line < lastLine; ++line) { QTextLine l(line, d); l.draw(p, position, &selection); } p->restore(); - if (selection.format.foreground().style() != Qt::NoBrush) // i.e. we have drawn text - excludedRegion += region; + if (hasText) { + textDoneRegion += region; + } else { + if (hasBackground) + textDoneRegion -= region; + } + + excludedRegion += region; + } + + QPainterPath needsTextButNoBackground = excludedRegion - textDoneRegion; + if (!needsTextButNoBackground.isEmpty()){ + p->save(); + p->setClipPath(needsTextButNoBackground, Qt::IntersectClip); + FormatRange selection; + selection.start = 0; + selection.length = INT_MAX; + selection.format.setProperty(SuppressBackground, true); + for (int line = firstLine; line < lastLine; ++line) { + QTextLine l(line, d); + l.draw(p, position, &selection); + } + p->restore(); } if (!excludedRegion.isEmpty()) { @@ -1912,14 +1947,17 @@ static void drawMenuText(QPainter *p, QFixed x, QFixed y, const QScriptItem &si, static void setPenAndDrawBackground(QPainter *p, const QPen &defaultPen, const QTextCharFormat &chf, const QRectF &r) { QBrush c = chf.foreground(); - if (c.style() == Qt::NoBrush) + if (c.style() == Qt::NoBrush) { p->setPen(defaultPen); + } QBrush bg = chf.background(); - if (bg.style() != Qt::NoBrush) + if (bg.style() != Qt::NoBrush && !chf.property(SuppressBackground).toBool()) p->fillRect(r, bg); - if (c.style() != Qt::NoBrush) + if (c.style() != Qt::NoBrush) { p->setPen(QPen(c, 0)); + } + } /*! @@ -1933,7 +1971,7 @@ void QTextLine::draw(QPainter *p, const QPointF &pos, const QTextLayout::FormatR const QScriptLine &line = eng->lines[i]; QPen pen = p->pen(); - bool noText = (selection && selection->format.foreground().style() == Qt::NoBrush); + bool noText = (selection && selection->format.property(SuppressText).toBool()); if (!line.length) { if (selection diff --git a/src/gui/text/qtextlist.cpp b/src/gui/text/qtextlist.cpp index e305027..d1a3361 100644 --- a/src/gui/text/qtextlist.cpp +++ b/src/gui/text/qtextlist.cpp @@ -50,6 +50,11 @@ QT_BEGIN_NAMESPACE class QTextListPrivate : public QTextBlockGroupPrivate { +public: + QTextListPrivate(QTextDocument *doc) + : QTextBlockGroupPrivate(doc) + { + } }; /*! @@ -111,7 +116,7 @@ class QTextListPrivate : public QTextBlockGroupPrivate /*! \internal */ QTextList::QTextList(QTextDocument *doc) - : QTextBlockGroup(*new QTextListPrivate, doc) + : QTextBlockGroup(*new QTextListPrivate(doc), doc) { } diff --git a/src/gui/text/qtextobject.cpp b/src/gui/text/qtextobject.cpp index 1645a21..71b68e0 100644 --- a/src/gui/text/qtextobject.cpp +++ b/src/gui/text/qtextobject.cpp @@ -76,7 +76,7 @@ QT_BEGIN_NAMESPACE objects, you will also need to reimplement QTextDocument::createObject() which acts as a factory method for creating text objects. - \sa QTextDocument + \sa QTextDocument, {Text Object Example} */ /*! @@ -88,7 +88,7 @@ QT_BEGIN_NAMESPACE from QTextDocument::createObject(). */ QTextObject::QTextObject(QTextDocument *doc) - : QObject(*new QTextObjectPrivate, doc) + : QObject(*new QTextObjectPrivate(doc), doc) { } @@ -98,7 +98,7 @@ QTextObject::QTextObject(QTextDocument *doc) \internal */ QTextObject::QTextObject(QTextObjectPrivate &p, QTextDocument *doc) - :QObject(p, doc) + : QObject(p, doc) { } @@ -221,7 +221,7 @@ void QTextBlockGroupPrivate::markBlocksDirty() QTextDocument::createObject(). */ QTextBlockGroup::QTextBlockGroup(QTextDocument *doc) - : QTextObject(*new QTextBlockGroupPrivate, doc) + : QTextObject(*new QTextBlockGroupPrivate(doc), doc) { } @@ -410,7 +410,7 @@ QTextFrameLayoutData::~QTextFrameLayoutData() Creates a new empty frame for the text \a document. */ QTextFrame::QTextFrame(QTextDocument *doc) - : QTextObject(*new QTextFramePrivate, doc) + : QTextObject(*new QTextFramePrivate(doc), doc) { Q_D(QTextFrame); d->fragment_start = 0; diff --git a/src/gui/text/qtextobject_p.h b/src/gui/text/qtextobject_p.h index b00a16a..dd05eb4 100644 --- a/src/gui/text/qtextobject_p.h +++ b/src/gui/text/qtextobject_p.h @@ -55,6 +55,7 @@ #include "QtGui/qtextobject.h" #include "private/qobject_p.h" +#include "QtGui/qtextdocument.h" QT_BEGIN_NAMESPACE @@ -64,6 +65,10 @@ class QTextObjectPrivate : public QObjectPrivate { Q_DECLARE_PUBLIC(QTextObject) public: + QTextObjectPrivate(QTextDocument *doc) + : pieceTable(doc->d_func()), objectIndex(-1) + { + } QTextDocumentPrivate *pieceTable; int objectIndex; }; @@ -72,7 +77,10 @@ class QTextBlockGroupPrivate : public QTextObjectPrivate { Q_DECLARE_PUBLIC(QTextBlockGroup) public: - + QTextBlockGroupPrivate(QTextDocument *doc) + : QTextObjectPrivate(doc) + { + } typedef QList<QTextBlock> BlockList; BlockList blocks; void markBlocksDirty(); @@ -85,7 +93,10 @@ class QTextFramePrivate : public QTextObjectPrivate friend class QTextDocumentPrivate; Q_DECLARE_PUBLIC(QTextFrame) public: - + QTextFramePrivate(QTextDocument *doc) + : QTextObjectPrivate(doc) + { + } virtual void fragmentAdded(const QChar &type, uint fragment); virtual void fragmentRemoved(const QChar &type, uint fragment); void remove_me(); diff --git a/src/gui/text/qtexttable.cpp b/src/gui/text/qtexttable.cpp index 375bb09..48708c9 100644 --- a/src/gui/text/qtexttable.cpp +++ b/src/gui/text/qtexttable.cpp @@ -525,7 +525,12 @@ void QTextTablePrivate::update() const Rows and columns within a QTextTable can be merged and split using the mergeCells() and splitCell() functions. However, only cells that span multiple rows or columns can be split. (Merging or splitting does not increase or decrease - the number of rows and columns.) + the number of rows and columns.) + + Note that if you have merged multiple columns and rows into one cell, you will not + be able to split the merged cell into new cells spanning over more than one row + or column. To be able to split cells spanning over several rows and columns you + need to do this over several iterations. \table 80% \row @@ -553,7 +558,7 @@ void QTextTablePrivate::update() const /*! \internal */ QTextTable::QTextTable(QTextDocument *doc) - : QTextFrame(*new QTextTablePrivate, doc) + : QTextFrame(*new QTextTablePrivate(doc), doc) { } diff --git a/src/gui/text/qtexttable_p.h b/src/gui/text/qtexttable_p.h index 1ba3a3f..f2b45b6 100644 --- a/src/gui/text/qtexttable_p.h +++ b/src/gui/text/qtexttable_p.h @@ -62,7 +62,7 @@ class QTextTablePrivate : public QTextFramePrivate { Q_DECLARE_PUBLIC(QTextTable) public: - QTextTablePrivate() : grid(0), nRows(0), dirty(true), blockFragmentUpdates(false) {} + QTextTablePrivate(QTextDocument *document) : QTextFramePrivate(document), grid(0), nRows(0), dirty(true), blockFragmentUpdates(false) {} ~QTextTablePrivate(); static QTextTable *createTable(QTextDocumentPrivate *, int pos, int rows, int cols, const QTextTableFormat &tableFormat); diff --git a/src/gui/util/qcompleter.cpp b/src/gui/util/qcompleter.cpp index 8b07163..faa4e7b 100644 --- a/src/gui/util/qcompleter.cpp +++ b/src/gui/util/qcompleter.cpp @@ -824,9 +824,9 @@ void QCompleterPrivate::_q_complete(QModelIndex index, bool highlighted) Q_Q(QCompleter); QString completion; - if (!index.isValid()) + if (!index.isValid() || (!proxy->showAll && (index.row() >= proxy->engine->matchCount()))) { completion = prefix; - else { + } else { QModelIndex si = proxy->mapToSource(index); si = si.sibling(si.row(), column); // for clicked() completion = q->pathFromIndex(si); @@ -1079,7 +1079,14 @@ void QCompleter::setPopup(QAbstractItemView *popup) popup->setModel(d->proxy); popup->hide(); popup->setParent(0, Qt::Popup); + + Qt::FocusPolicy origPolicy = Qt::NoFocus; + if (d->widget) + origPolicy = d->widget->focusPolicy(); popup->setFocusPolicy(Qt::NoFocus); + if (d->widget) + d->widget->setFocusPolicy(origPolicy); + popup->setFocusProxy(d->widget); popup->installEventFilter(this); popup->setItemDelegate(new QCompleterItemDelegate(popup)); diff --git a/src/gui/util/qdesktopservices.cpp b/src/gui/util/qdesktopservices.cpp index 1056fa0..84aa16e 100644 --- a/src/gui/util/qdesktopservices.cpp +++ b/src/gui/util/qdesktopservices.cpp @@ -157,6 +157,11 @@ void QOpenUrlHandlerRegistry::handlerDestroyed(QObject *handler) If the URL is a reference to a local file (i.e., the URL scheme is "file") then it will be opened with a suitable application instead of a Web browser. + The following example opens a file on the Windows file system residing on a path + that contains spaces: + + \snippet doc/src/snippets/code/src_gui_util_qdesktopservices.cpp 2 + If a \c mailto URL is specified, the user's e-mail client will be used to open a composer window containing the options specified in the URL, similar to the way \c mailto links are handled by a Web browser. @@ -280,6 +285,17 @@ void QDesktopServices::unsetUrlHandler(const QString &scheme) \note The storage location returned can be a directory that does not exist; i.e., it may need to be created by the system or the user. + + \note On Mac OS X, DataLocation does not include QCoreApplication::organizationName. + Use code like this to add it: + + \code + QString location = QDesktopServices::storageLocation(QDesktopServices::DataLocation); + #ifdef Q_WS_MAC + location.insert(location.count() - QCoreApplication::applicationName().count(), + QCoreApplication::organizationName() + "/"); + #endif + \endcode */ /*! diff --git a/src/gui/widgets/qabstractbutton.cpp b/src/gui/widgets/qabstractbutton.cpp index 330a7f8..61ed0ea 100644 --- a/src/gui/widgets/qabstractbutton.cpp +++ b/src/gui/widgets/qabstractbutton.cpp @@ -1248,15 +1248,6 @@ void QAbstractButton::timerEvent(QTimerEvent *e) } } -#if defined(Q_OS_WINCE) && !defined(QT_NO_CONTEXTMENU) -/*! \reimp */ -void QAbstractButton::contextMenuEvent(QContextMenuEvent *e) -{ - e->ignore(); - setDown(false); -} -#endif - /*! \reimp */ void QAbstractButton::focusInEvent(QFocusEvent *e) { diff --git a/src/gui/widgets/qabstractbutton.h b/src/gui/widgets/qabstractbutton.h index 6503a56..f0cbb05 100644 --- a/src/gui/widgets/qabstractbutton.h +++ b/src/gui/widgets/qabstractbutton.h @@ -143,9 +143,6 @@ protected: void focusOutEvent(QFocusEvent *e); void changeEvent(QEvent *e); void timerEvent(QTimerEvent *e); -#ifdef Q_OS_WINCE - void contextMenuEvent(QContextMenuEvent *e); -#endif #ifdef QT3_SUPPORT public: diff --git a/src/gui/widgets/qcocoamenu_mac.mm b/src/gui/widgets/qcocoamenu_mac.mm index c5977e4..6434289 100644 --- a/src/gui/widgets/qcocoamenu_mac.mm +++ b/src/gui/widgets/qcocoamenu_mac.mm @@ -1,11 +1,11 @@ /**************************************************************************** - ** - ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). ** Contact: Qt Software Information (qt-info@nokia.com) - ** - ** This file is part of the QtGui module of the Qt Toolkit. - ** - ** $QT_BEGIN_LICENSE:LGPL$ +** +** 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 @@ -36,11 +36,11 @@ ** If you are unsure which license is appropriate for your use, please ** contact the sales department at qt-sales@nokia.com. ** $QT_END_LICENSE$ - ** - ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE - ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. - ** - ****************************************************************************/ +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +****************************************************************************/ #include "qmacdefines_mac.h" #include "qapplication.h" @@ -55,6 +55,16 @@ QT_FORWARD_DECLARE_CLASS(QAction) QT_FORWARD_DECLARE_CLASS(QWidget) QT_FORWARD_DECLARE_CLASS(QApplication) +QT_FORWARD_DECLARE_CLASS(QCoreApplication) +QT_FORWARD_DECLARE_CLASS(QApplicationPrivate) +QT_FORWARD_DECLARE_CLASS(QKeyEvent) +QT_FORWARD_DECLARE_CLASS(QEvent) + +QT_BEGIN_NAMESPACE +extern bool qt_sendSpontaneousEvent(QObject*, QEvent*); //qapplication.cpp +QT_END_NAMESPACE + +QT_USE_NAMESPACE @implementation QT_MANGLE_NAMESPACE(QCocoaMenu) @@ -130,8 +140,9 @@ QT_FORWARD_DECLARE_CLASS(QApplication) // If it does, then we will first send the key sequence to the QWidget that has focus // since (in Qt's eyes) it needs to a chance at the key event first. If the widget // accepts the key event, we then return YES, but set the target and action to be nil, - // which means that the action should not be triggered. In every other case we return - // NO, which means that Cocoa can do as it pleases (i.e., fire the menu action). + // which means that the action should not be triggered, and instead dispatch the event ourselves. + // In every other case we return NO, which means that Cocoa can do as it pleases + // (i.e., fire the menu action). NSMenuItem *whichItem; if ([self hasShortcut:menu forKey:[event characters] @@ -154,9 +165,11 @@ QT_FORWARD_DECLARE_CLASS(QApplication) accel_ev.ignore(); qt_sendSpontaneousEvent(widget, &accel_ev); if (accel_ev.isAccepted()) { - *target = nil; - *action = nil; - return YES; + if (qt_dispatchKeyEvent(event, widget)) { + *target = nil; + *action = nil; + return YES; + } } } } diff --git a/src/gui/widgets/qcombobox.cpp b/src/gui/widgets/qcombobox.cpp index 75b8b59..09a51fe 100644 --- a/src/gui/widgets/qcombobox.cpp +++ b/src/gui/widgets/qcombobox.cpp @@ -61,6 +61,7 @@ #endif #include <private/qcombobox_p.h> #include <private/qabstractitemmodel_p.h> +#include <private/qabstractscrollarea_p.h> #include <qdebug.h> #ifdef Q_WS_X11 @@ -108,7 +109,7 @@ QStyleOptionMenuItem QComboMenuDelegate::getStyleOption(const QStyleOptionViewIt const QModelIndex &index) const { QStyleOptionMenuItem menuOption; - menuOption.palette = QComboBoxPrivate::viewContainerPalette(mCombo).resolve(QApplication::palette("QMenu")); + menuOption.palette = option.palette.resolve(QApplication::palette("QMenu")); menuOption.state = QStyle::State_None; if (mCombo->window()->isActiveWindow()) menuOption.state = QStyle::State_Active; @@ -619,7 +620,6 @@ void QComboBoxPrivateContainer::changeEvent(QEvent *e) bool QComboBoxPrivateContainer::eventFilter(QObject *o, QEvent *e) { switch (e->type()) { - case QEvent::KeyPress: case QEvent::ShortcutOverride: switch (static_cast<QKeyEvent*>(e)->key()) { case Qt::Key_Enter: @@ -2274,7 +2274,6 @@ void QComboBox::showPopup() bool boundToScreen = !window()->testAttribute(Qt::WA_DontShowOnScreen); const bool usePopup = style->styleHint(QStyle::SH_ComboBox_Popup, &opt, this); - { int listHeight = 0; int count = 0; @@ -2306,10 +2305,23 @@ void QComboBox::showPopup() listRect.setHeight(listHeight); } - // ### Adjusting by PM_DefaultFrameWidth is not enough. Since QFrame supports - // SE_FrameContents, QFrame needs API to return the frameWidths - listRect.setHeight(listRect.height() + 2*container->spacing() - + style->pixelMetric(QStyle::PM_DefaultFrameWidth, &opt, this) * 2); + { + // add the spacing for the grid on the top and the bottom; + int heightMargin = 2*container->spacing(); + + // add the frame of the container + int marginTop, marginBottom; + container->getContentsMargins(0, &marginTop, 0, &marginBottom); + heightMargin += marginTop + marginBottom; + + //add the frame of the view + view()->getContentsMargins(0, &marginTop, 0, &marginBottom); + marginTop += static_cast<QAbstractScrollAreaPrivate *>(QObjectPrivate::get(view()))->top; + marginBottom += static_cast<QAbstractScrollAreaPrivate *>(QObjectPrivate::get(view()))->bottom; + heightMargin += marginTop + marginBottom; + + listRect.setHeight(listRect.height() + heightMargin); + } // Add space for margin at top and bottom if the style wants it. if (usePopup) @@ -2322,6 +2334,8 @@ void QComboBox::showPopup() listRect.setWidth(listRect.width() + diff); } + //we need to activate the layout to make sure the min/maximum size are set when the widget was not yet show + container->layout()->activate(); //takes account of the minimum/maximum size of the container listRect.setSize( listRect.size().expandedTo(container->minimumSize()) .boundedTo(container->maximumSize())); diff --git a/src/gui/widgets/qcombobox_p.h b/src/gui/widgets/qcombobox_p.h index f1203dc..c39a231 100644 --- a/src/gui/widgets/qcombobox_p.h +++ b/src/gui/widgets/qcombobox_p.h @@ -265,7 +265,7 @@ protected: const QStyleOptionViewItem &option, const QModelIndex &index) const { QStyleOptionMenuItem opt = getStyleOption(option, index); - painter->eraseRect(option.rect); + painter->fillRect(option.rect, opt.palette.background()); mCombo->style()->drawControl(QStyle::CE_MenuItem, &opt, painter, mCombo); } QSize sizeHint(const QStyleOptionViewItem &option, diff --git a/src/gui/widgets/qdialogbuttonbox.cpp b/src/gui/widgets/qdialogbuttonbox.cpp index 246da95..4a95292 100644 --- a/src/gui/widgets/qdialogbuttonbox.cpp +++ b/src/gui/widgets/qdialogbuttonbox.cpp @@ -752,7 +752,8 @@ QDialogButtonBox::~QDialogButtonBox() \value KdeLayout Use a policy appropriate for applications on KDE. \value GnomeLayout Use a policy appropriate for applications on GNOME. - The button layout is specified by the \l{style()}{current style}. + The button layout is specified by the \l{style()}{current style}. However, + on the X11 platform, it may be influenced by the desktop environment. */ /*! diff --git a/src/gui/widgets/qdockarealayout.cpp b/src/gui/widgets/qdockarealayout.cpp index 9261c63..4f0ec1e 100644 --- a/src/gui/widgets/qdockarealayout.cpp +++ b/src/gui/widgets/qdockarealayout.cpp @@ -579,7 +579,7 @@ void QDockAreaLayoutInfo::fitItems() QLayoutStruct &ls = layout_struct_list[j++]; ls.init(); ls.empty = false; - if (gap || (item.flags & QDockAreaLayoutItem::KeepSize)) { + if (item.flags & QDockAreaLayoutItem::KeepSize) { ls.minimumSize = ls.maximumSize = ls.sizeHint = item.size; ls.expansive = false; ls.stretch = 0; diff --git a/src/gui/widgets/qdockwidget.cpp b/src/gui/widgets/qdockwidget.cpp index 5ff7bf5..a5be5f8 100644 --- a/src/gui/widgets/qdockwidget.cpp +++ b/src/gui/widgets/qdockwidget.cpp @@ -292,8 +292,11 @@ QSize QDockWidgetLayout::sizeFromContent(const QSize &content, bool floating) co if (content.height() < 0) result.setHeight(-1); - QSize min = w->minimumSize(); - QSize max = w->maximumSize(); + int left, top, right, bottom; + w->getContentsMargins(&left, &top, &right, &bottom); + //we need to substract the contents margin (it will be added by the caller) + QSize min = w->minimumSize() - QSize(left + right, top + bottom); + QSize max = w->maximumSize() - QSize(left + right, top + bottom); /* A floating dockwidget will automatically get its minimumSize set to the layout's minimum size + deco. We're *not* interested in this, we only take minimumSize() @@ -403,10 +406,14 @@ int QDockWidgetLayout::minimumTitleWidth() const QSize closeSize(0, 0); QSize floatSize(0, 0); - if (QLayoutItem *item = item_list[CloseButton]) - closeSize = item->sizeHint(); - if (QLayoutItem *item = item_list[FloatButton]) - floatSize = item->sizeHint(); + if (hasFeature(q, QDockWidget::DockWidgetClosable)) { + if (QLayoutItem *item = item_list[CloseButton]) + closeSize = item->widget()->sizeHint(); + } + if (hasFeature(q, QDockWidget::DockWidgetFloatable)) { + if (QLayoutItem *item = item_list[FloatButton]) + floatSize = item->widget()->sizeHint(); + } int titleHeight = this->titleHeight(); diff --git a/src/gui/widgets/qmaccocoaviewcontainer_mac.mm b/src/gui/widgets/qmaccocoaviewcontainer_mac.mm index 710af6a..380e983 100644 --- a/src/gui/widgets/qmaccocoaviewcontainer_mac.mm +++ b/src/gui/widgets/qmaccocoaviewcontainer_mac.mm @@ -1,11 +1,11 @@ /**************************************************************************** - ** - ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). ** Contact: Qt Software Information (qt-info@nokia.com) - ** - ** This file is part of the QtGui module of the Qt Toolkit. - ** - ** $QT_BEGIN_LICENSE:LGPL$ +** +** 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 @@ -36,11 +36,11 @@ ** If you are unsure which license is appropriate for your use, please ** contact the sales department at qt-sales@nokia.com. ** $QT_END_LICENSE$ - ** - ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE - ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. - ** - ****************************************************************************/ +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +****************************************************************************/ #import <Cocoa/Cocoa.h> #include <private/qwidget_p.h> diff --git a/src/gui/widgets/qmacnativewidget_mac.mm b/src/gui/widgets/qmacnativewidget_mac.mm index 1bc0430..0f4edf9 100644 --- a/src/gui/widgets/qmacnativewidget_mac.mm +++ b/src/gui/widgets/qmacnativewidget_mac.mm @@ -1,11 +1,11 @@ /**************************************************************************** - ** - ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). ** Contact: Qt Software Information (qt-info@nokia.com) - ** - ** This file is part of the QtGui module of the Qt Toolkit. - ** - ** $QT_BEGIN_LICENSE:LGPL$ +** +** 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 @@ -36,11 +36,11 @@ ** If you are unsure which license is appropriate for your use, please ** contact the sales department at qt-sales@nokia.com. ** $QT_END_LICENSE$ - ** - ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE - ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. - ** - ****************************************************************************/ +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +****************************************************************************/ #import <Cocoa/Cocoa.h> #import <private/qcocoaview_mac_p.h> diff --git a/src/gui/widgets/qmainwindow.cpp b/src/gui/widgets/qmainwindow.cpp index 46d6471..502c1e9 100644 --- a/src/gui/widgets/qmainwindow.cpp +++ b/src/gui/widgets/qmainwindow.cpp @@ -480,9 +480,6 @@ void QMainWindow::setMenuBar(QMenuBar *menuBar) oldMenuBar->hide(); oldMenuBar->deleteLater(); } -#ifdef Q_OS_WINCE - if (menuBar->size().height() > 0) -#endif d->layout->setMenuBar(menuBar); } diff --git a/src/gui/widgets/qmainwindowlayout.cpp b/src/gui/widgets/qmainwindowlayout.cpp index 768446e..eade633 100644 --- a/src/gui/widgets/qmainwindowlayout.cpp +++ b/src/gui/widgets/qmainwindowlayout.cpp @@ -1542,8 +1542,8 @@ bool QMainWindowLayout::plug(QLayoutItem *widgetItem) if (!previousPath.isEmpty()) layoutState.remove(previousPath); + pluggingWidget = widget; if (dockOptions & QMainWindow::AnimatedDocks) { - pluggingWidget = widget; QRect globalRect = currentGapRect; globalRect.moveTopLeft(parentWidget()->mapToGlobal(globalRect.topLeft())); #ifndef QT_NO_DOCKWIDGET @@ -1575,6 +1575,7 @@ bool QMainWindowLayout::plug(QLayoutItem *widgetItem) #endif currentGapPos.clear(); updateGapIndicator(); + pluggingWidget = 0; } return true; diff --git a/src/gui/widgets/qmainwindowlayout_mac.mm b/src/gui/widgets/qmainwindowlayout_mac.mm index 950f758..c807afb 100644 --- a/src/gui/widgets/qmainwindowlayout_mac.mm +++ b/src/gui/widgets/qmainwindowlayout_mac.mm @@ -1,3 +1,47 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +****************************************************************************/ + #include <private/qmainwindowlayout_p.h> #include <qtoolbar.h> #include <private/qtoolbarlayout_p.h> diff --git a/src/gui/widgets/qmenu.cpp b/src/gui/widgets/qmenu.cpp index e96856a..7396a9d 100644 --- a/src/gui/widgets/qmenu.cpp +++ b/src/gui/widgets/qmenu.cpp @@ -578,7 +578,8 @@ void QMenuPrivate::setCurrentAction(QAction *action, int popup, SelectionReason //when the action has no QWidget, the QMenu itself should // get the focus // Since the menu is a pop-up, it uses the popup reason. - q->setFocus(Qt::PopupFocusReason); + if (!q->hasFocus()) + q->setFocus(Qt::PopupFocusReason); } } } else { //action is a separator @@ -2888,8 +2889,8 @@ void QMenu::internalDelayedPopup() int subMenuOffset = style()->pixelMetric(QStyle::PM_SubMenuOverlap, 0, this); const QRect actionRect(d->actionRect(d->currentAction)); const QSize menuSize(d->activeMenu->sizeHint()); - const QPoint rightPos(mapToGlobal(QPoint(rect().right() + subMenuOffset + 1, actionRect.top()))); - const QPoint leftPos(mapToGlobal(QPoint(rect().left() - subMenuOffset - menuSize.width(), actionRect.top()))); + const QPoint rightPos(mapToGlobal(QPoint(actionRect.right() + subMenuOffset + 1, actionRect.top()))); + const QPoint leftPos(mapToGlobal(QPoint(actionRect.left() - subMenuOffset - menuSize.width(), actionRect.top()))); QPoint pos(rightPos); QMenu *caused = qobject_cast<QMenu*>(d->activeMenu->d_func()->causedPopup.widget); diff --git a/src/gui/widgets/qmenu_wince.cpp b/src/gui/widgets/qmenu_wince.cpp index ea58d46..847a623 100644 --- a/src/gui/widgets/qmenu_wince.cpp +++ b/src/gui/widgets/qmenu_wince.cpp @@ -58,6 +58,9 @@ #include <QtCore/qlibrary.h> #include <commctrl.h> +#if Q_OS_WINCE_WM +# include <windowsm.h> +#endif #include "qguifunctions_wince.h" @@ -71,6 +74,12 @@ #define SHCMBM_GETSUBMENU (WM_USER + 401) #endif +#ifdef Q_OS_WINCE_WM +# define SHMBOF_NODEFAULT 0x00000001 +# define SHMBOF_NOTIFY 0x00000002 +# define SHCMBM_OVERRIDEKEY (WM_USER + 0x193) +#endif + extern bool qt_wince_is_smartphone();//defined in qguifunctions_wce.cpp extern bool qt_wince_is_pocket_pc(); //defined in qguifunctions_wce.cpp @@ -204,8 +213,13 @@ static HWND qt_wce_create_menubar(HWND parentHandle, HINSTANCE resourceHandle, i mbi.dwFlags = flags; mbi.nToolBarId = toolbarID; - if (ptrCreateMenuBar(&mbi)) + if (ptrCreateMenuBar(&mbi)) { + // Tell the menu bar that we want to override hot key behaviour. + LPARAM lparam = MAKELPARAM(SHMBOF_NODEFAULT | SHMBOF_NOTIFY, + SHMBOF_NODEFAULT | SHMBOF_NOTIFY); + SendMessage(mbi.hwndMB, SHCMBM_OVERRIDEKEY, VK_TBACK, lparam); return mbi.hwndMB; + } } return 0; } diff --git a/src/gui/widgets/qplaintextedit.cpp b/src/gui/widgets/qplaintextedit.cpp index 2e9201d..e563fa1 100644 --- a/src/gui/widgets/qplaintextedit.cpp +++ b/src/gui/widgets/qplaintextedit.cpp @@ -624,7 +624,7 @@ void QPlainTextEditPrivate::setTopBlock(int blockNumber, int lineNumber, int dx) if (viewport->updatesEnabled() && viewport->isVisible()) { int dy = 0; - if (doc->findBlockByLineNumber(control->topBlock).isValid()) { + if (doc->findBlockByNumber(control->topBlock).isValid()) { dy = (int)(-q->blockBoundingGeometry(block).y()) + verticalOffset() - verticalOffset(blockNumber, lineNumber); } diff --git a/src/gui/widgets/qscrollbar.cpp b/src/gui/widgets/qscrollbar.cpp index fc9e1a3..9bfe7a5 100644 --- a/src/gui/widgets/qscrollbar.cpp +++ b/src/gui/widgets/qscrollbar.cpp @@ -444,26 +444,19 @@ void QScrollBar::contextMenuEvent(QContextMenuEvent *event) #ifndef QT_NO_MENU bool horiz = HORIZONTAL; - QMenu menu; - QAction *actScrollHere = - menu.addAction(tr("Scroll here")); - menu.addSeparator(); - QAction *actScrollTop = - menu.addAction(horiz ? tr("Left edge") : tr("Top")); - QAction *actScrollBottom = - menu.addAction(horiz ? tr("Right edge") : tr("Bottom")); - menu.addSeparator(); - QAction *actPageUp = - menu.addAction(horiz ? tr("Page left") : tr("Page up")); - QAction *actPageDn = - menu.addAction(horiz ? tr("Page right") : tr("Page down")); - menu.addSeparator(); - QAction *actScrollUp = - menu.addAction(horiz ? tr("Scroll left") : tr("Scroll up")); - QAction *actScrollDn = - menu.addAction(horiz ? tr("Scroll right") : tr("Scroll down")); - - QAction *actionSelected = menu.exec(event->globalPos()); + QPointer<QMenu> menu = new QMenu(this); + QAction *actScrollHere = menu->addAction(tr("Scroll here")); + menu->addSeparator(); + QAction *actScrollTop = menu->addAction(horiz ? tr("Left edge") : tr("Top")); + QAction *actScrollBottom = menu->addAction(horiz ? tr("Right edge") : tr("Bottom")); + menu->addSeparator(); + QAction *actPageUp = menu->addAction(horiz ? tr("Page left") : tr("Page up")); + QAction *actPageDn = menu->addAction(horiz ? tr("Page right") : tr("Page down")); + menu->addSeparator(); + QAction *actScrollUp = menu->addAction(horiz ? tr("Scroll left") : tr("Scroll up")); + QAction *actScrollDn = menu->addAction(horiz ? tr("Scroll right") : tr("Scroll down")); + QAction *actionSelected = menu->exec(event->globalPos()); + delete menu; if (actionSelected == 0) /* do nothing */ ; else if (actionSelected == actScrollHere) diff --git a/src/gui/widgets/qtabbar.cpp b/src/gui/widgets/qtabbar.cpp index 7d970ad..69221ba 100644 --- a/src/gui/widgets/qtabbar.cpp +++ b/src/gui/widgets/qtabbar.cpp @@ -131,7 +131,7 @@ void QTabBar::initStyleOption(QStyleOptionTab *option, int tabIndex) const option->state &= ~QStyle::State_Enabled; if (isActiveWindow()) option->state |= QStyle::State_Active; - if (option->rect == d->hoverRect) + if (!d->dragInProgress && option->rect == d->hoverRect) option->state |= QStyle::State_MouseOver; option->shape = d->shape; option->text = tab.text; @@ -454,9 +454,6 @@ void QTabBarPrivate::layoutTabs() maxExtent = maxWidth; } - if (pressedIndex != -1 && movable) - grabCache(0, tabList.count(), true); - Q_ASSERT(tabChainIndex == tabChain.count() - 1); // add an assert just to make sure. // Mirror our front item. tabChain[tabChainIndex].init(); @@ -1088,7 +1085,7 @@ void QTabBar::setTabData(int index, const QVariant & data) } /*! - Returns the datad of the tab at position \a index, or a null + Returns the data of the tab at position \a index, or a null variant if \a index is out of range. */ QVariant QTabBar::tabData(int index) const @@ -1170,13 +1167,13 @@ void QTabBar::setCurrentIndex(int index) d->currentIndex = index; update(); d->makeVisible(index); + d->tabList[index].lastTab = oldIndex; + d->layoutWidgets(oldIndex); + d->layoutWidgets(index); #ifdef QT3_SUPPORT emit selected(index); #endif emit currentChanged(index); - d->tabList[index].lastTab = oldIndex; - d->layoutWidgets(oldIndex); - d->layoutWidgets(index); } } @@ -1484,6 +1481,8 @@ void QTabBar::paintEvent(QPaintEvent *) bool vertical = verticalTabs(d->shape); QStyleOptionTab cutTab; selected = d->currentIndex; + if (d->dragInProgress) + selected = d->pressedIndex; for (int i = 0; i < d->tabList.count(); ++i) optTabBase.tabBarRect |= tabRect(i); @@ -1522,11 +1521,7 @@ void QTabBar::paintEvent(QPaintEvent *) if (i == selected) continue; - if (!d->tabList[i].animatingCache.isNull() && d->paintWithOffsets) { - p.drawPixmap(tab.rect, d->tabList[i].animatingCache); - } else { - p.drawControl(QStyle::CE_TabBarTab, tab); - } + p.drawControl(QStyle::CE_TabBarTab, tab); } // Draw the selected tab last to get it "on top" @@ -1539,7 +1534,11 @@ void QTabBar::paintEvent(QPaintEvent *) else tab.rect.moveLeft(tab.rect.x() + d->tabList[selected].dragOffset); } - p.drawControl(QStyle::CE_TabBarTab, tab); + if (!d->dragInProgress) + p.drawControl(QStyle::CE_TabBarTab, tab); + else + d->movingTab->setGeometry(tab.rect); + } // Only draw the tear indicator if necessary. Most of the time we don't need too. @@ -1680,6 +1679,7 @@ void QTabBarPrivate::_q_moveTab(int offset) if (!validIndex(index)) return; tabList[index].dragOffset = offset; + layoutTab(index); // Make buttons follow tab q->update(); } } @@ -1727,8 +1727,7 @@ void QTabBar::mouseMoveEvent(QMouseEvent *event) if (!d->dragInProgress && d->pressedIndex != -1) { if ((event->pos() - d->dragStartPosition).manhattanLength() > QApplication::startDragDistance()) { d->dragInProgress = true; - if (d->animations.isEmpty()) - d->grabCache(0, d->tabList.count(), false); + d->setupMovableTab(); } } @@ -1773,7 +1772,6 @@ void QTabBar::mouseMoveEvent(QMouseEvent *event) if (dragDistance > needsToBeOver) d->slide(i + offset, d->pressedIndex); } - } // Buttons needs to follow the dragged tab d->layoutTab(d->pressedIndex); @@ -1801,32 +1799,41 @@ void QTabBarPrivate::_q_moveTabFinished() } } -void QTabBarPrivate::grabCache(int start, int end, bool unhide) +void QTabBarPrivate::setupMovableTab() { Q_Q(QTabBar); - paintWithOffsets = false; - bool showButtonsAgain = rightB->isVisible(); - rightB->hide(); - leftB->hide(); - - QWidget *topLevel = q->window(); - QPoint topLevelOffset(q->mapTo(topLevel, QPoint())); - for (int i = start; i < end; ++i) { - QRect tabRect = q->tabRect(i); - tabRect.translate(topLevelOffset); - if (unhide) { - tabList[i].unHideWidgets(); - layoutWidgets(i); - } - tabList[i].animatingCache = QPixmap::grabWidget(topLevel, tabRect); - if (i != pressedIndex) - tabList[i].hideWidgets(); - } - if (showButtonsAgain) { - rightB->show(); - leftB->show(); - } - paintWithOffsets = true; + if (!movingTab) + movingTab = new QWidget(q); + + QRect grabRect = q->tabRect(pressedIndex); + + QPixmap grabImage(grabRect.size()); + grabImage.fill(Qt::transparent); + QStylePainter p(&grabImage, q); + + QStyleOptionTabV3 tab; + q->initStyleOption(&tab, pressedIndex); + tab.rect.moveTopLeft(QPoint(0, 0)); + p.drawControl(QStyle::CE_TabBarTab, tab); + p.end(); + + QPalette pal; + pal.setBrush(QPalette::All, QPalette::Window, grabImage); + movingTab->setPalette(pal); + movingTab->setGeometry(grabRect); + movingTab->setAutoFillBackground(true); + movingTab->raise(); + + // Re-arrange widget order to avoid overlaps + if (tabList[pressedIndex].leftWidget) + tabList[pressedIndex].leftWidget->raise(); + if (tabList[pressedIndex].rightWidget) + tabList[pressedIndex].rightWidget->raise(); + if (leftB) + leftB->raise(); + if (rightB) + rightB->raise(); + movingTab->setVisible(true); } void QTabBarPrivate::_q_moveTabFinished(int index) @@ -1834,10 +1841,9 @@ void QTabBarPrivate::_q_moveTabFinished(int index) Q_Q(QTabBar); bool cleanup = (pressedIndex == index) || (pressedIndex == -1) || !validIndex(index); if (animations.isEmpty() && cleanup) { + movingTab->setVisible(false); // We might not get a mouse release for (int i = 0; i < tabList.count(); ++i) { tabList[i].dragOffset = 0; - tabList[i].unHideWidgets(); - tabList[i].animatingCache = QPixmap(); } if (pressedIndex != -1 && movable) { pressedIndex = -1; @@ -1881,6 +1887,7 @@ void QTabBar::mouseReleaseEvent(QMouseEvent *event) d->_q_moveTabFinished(d->pressedIndex); } d->dragInProgress = false; + d->movingTab->setVisible(false); d->dragStartPosition = QPoint(); } @@ -2203,21 +2210,19 @@ void QTabBar::setTabButton(int index, ButtonPosition position, QWidget *widget) widget->setParent(this); // make sure our left and right widgets stay on top widget->lower(); + widget->show(); } if (position == LeftSide) { if (d->tabList[index].leftWidget) d->tabList[index].leftWidget->hide(); d->tabList[index].leftWidget = widget; - if(!d->tabList[index].hidLeft && widget) - widget->show(); } else { if (d->tabList[index].rightWidget) d->tabList[index].rightWidget->hide(); d->tabList[index].rightWidget = widget; - if(!d->tabList[index].hidRight && widget) - widget->show(); } d->layoutTabs(); + d->refresh(); update(); } diff --git a/src/gui/widgets/qtabbar_p.h b/src/gui/widgets/qtabbar_p.h index a117aa3..cb1a15b 100644 --- a/src/gui/widgets/qtabbar_p.h +++ b/src/gui/widgets/qtabbar_p.h @@ -70,7 +70,6 @@ QT_BEGIN_NAMESPACE - class QTabBarPrivate : public QWidgetPrivate { Q_DECLARE_PUBLIC(QTabBar) @@ -78,7 +77,7 @@ public: QTabBarPrivate() :currentIndex(-1), pressedIndex(-1), shape(QTabBar::RoundedNorth), - layoutDirty(false), drawBase(true), scrollOffset(0), expanding(true), closeButtonOnTabs(false), selectionBehaviorOnRemove(QTabBar::SelectRightTab), paintWithOffsets(true), movable(false), dragInProgress(false), documentMode(false) {} + layoutDirty(false), drawBase(true), scrollOffset(0), expanding(true), closeButtonOnTabs(false), selectionBehaviorOnRemove(QTabBar::SelectRightTab), paintWithOffsets(true), movable(false), dragInProgress(false), documentMode(false), movingTab(0) {} int currentIndex; int pressedIndex; @@ -98,8 +97,6 @@ public: , lastTab(-1) , timeLine(0) , dragOffset(0) - , hidLeft(false) - , hidRight(false) {} bool enabled; int shortcutId; @@ -123,9 +120,6 @@ public: QTimeLine *timeLine; int dragOffset; - QPixmap animatingCache; - bool hidLeft; - bool hidRight; void makeTimeLine(QWidget *q) { if (timeLine) @@ -135,27 +129,6 @@ public: q->connect(timeLine, SIGNAL(finished()), q, SLOT(_q_moveTabFinished())); } - void hideWidgets() { - if (!hidRight && rightWidget) { - hidRight = rightWidget->isVisible(); - rightWidget->hide(); - } - - if (!hidLeft && leftWidget) { - hidLeft = leftWidget->isVisible(); - leftWidget->hide(); - } - } - - void unHideWidgets() { - if (leftWidget && hidLeft) - leftWidget->show(); - hidLeft = false; - if (rightWidget && hidRight) - rightWidget->show(); - hidRight = false; - } - }; QList<Tab> tabList; QHash<QTimeLine*, int> animations; @@ -184,12 +157,12 @@ public: void _q_moveTabFinished(int offset); QRect hoverRect; - void grabCache(int start, int end, bool unhide); void refresh(); void layoutTabs(); void layoutWidgets(int index = -1); void layoutTab(int index); void updateMacBorderMetrics(); + void setupMovableTab(); void makeVisible(int index); QSize iconSize; @@ -206,6 +179,8 @@ public: bool dragInProgress; bool documentMode; + QWidget *movingTab; + // shared by tabwidget and qtabbar static void initStyleBaseOption(QStyleOptionTabBarBaseV2 *optTabBase, QTabBar *tabbar, QSize size) { diff --git a/src/gui/widgets/qtextedit.cpp b/src/gui/widgets/qtextedit.cpp index b239e32..1c4df93 100644 --- a/src/gui/widgets/qtextedit.cpp +++ b/src/gui/widgets/qtextedit.cpp @@ -1478,7 +1478,13 @@ void QTextEditPrivate::paint(QPainter *p, QPaintEvent *e) layout->setViewport(QRect()); } -/*! \reimp +/*! \fn void QTextEdit::paintEvent(QPaintEvent *event) + +This event handler can be reimplemented in a subclass to receive paint events passed in \a event. +It is usually unnecessary to reimplement this function in a subclass of QTextEdit. + +\warning The underlying text document must not be modified from within a reimplementation +of this function. */ void QTextEdit::paintEvent(QPaintEvent *e) { diff --git a/src/gui/widgets/qtoolbar.cpp b/src/gui/widgets/qtoolbar.cpp index 85d6ea2..1babb6d 100644 --- a/src/gui/widgets/qtoolbar.cpp +++ b/src/gui/widgets/qtoolbar.cpp @@ -1153,6 +1153,17 @@ bool QToolBar::event(QEvent *event) if (d->mouseMoveEvent(static_cast<QMouseEvent*>(event))) return true; break; +#ifdef Q_OS_WINCE + case QEvent::ContextMenu: + { + QContextMenuEvent* contextMenuEvent = static_cast<QContextMenuEvent*>(event); + QWidget* child = childAt(contextMenuEvent->pos()); + QAbstractButton* button = qobject_cast<QAbstractButton*>(child); + if (button) + button->setDown(false); + } + break; +#endif case QEvent::Leave: if (d->state != 0 && d->state->dragging) { #ifdef Q_OS_WIN |