diff options
Diffstat (limited to 'src/widgets')
32 files changed, 238 insertions, 120 deletions
diff --git a/src/widgets/accessible/qaccessiblemenu.cpp b/src/widgets/accessible/qaccessiblemenu.cpp index 2a8b364b1c..e5e784d483 100644 --- a/src/widgets/accessible/qaccessiblemenu.cpp +++ b/src/widgets/accessible/qaccessiblemenu.cpp @@ -198,7 +198,7 @@ int QAccessibleMenuItem::indexOfChild(const QAccessibleInterface * child) const bool QAccessibleMenuItem::isValid() const { - return m_action && m_owner ? true : false; + return m_action && m_owner; } QAccessibleInterface *QAccessibleMenuItem::parent() const diff --git a/src/widgets/dialogs/qmessagebox.cpp b/src/widgets/dialogs/qmessagebox.cpp index fccddaccf5..effcef2bc9 100644 --- a/src/widgets/dialogs/qmessagebox.cpp +++ b/src/widgets/dialogs/qmessagebox.cpp @@ -1892,26 +1892,23 @@ void QMessageBox::aboutQt(QWidget *parent, const QString &title) "<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>" + "comply with the terms of the GNU LGPL version 3 or GNU LGPL version 2.1.</p>" + "<p>Qt licensed under the GNU LGPL version 3 is appropriate for the " + "development of Qt applications provided you can comply with the terms " + "and conditions of the GNU LGPL version 3.</p>" "<p>Qt licensed under the GNU LGPL version 2.1 is appropriate for the " "development of Qt applications 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://qt.digia.com/Product/Licensing/\">qt.digia.com/Product/Licensing</a> " + "<p>Please see <a href=\"http://%2/\">%2</a> " "for an overview of Qt licensing.</p>" - "<p>Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies) and other " + "<p>Copyright (C) %1 Digia Plc and/or its subsidiary(-ies) and other " "contributors.</p>" "<p>Qt and the Qt logo are trademarks of Digia Plc and/or its subsidiary(-ies).</p>" - "<p>Qt is developed as an open source project on " - "<a href=\"http://qt-project.org/\">qt-project.org</a>.</p>" - "<p>Qt is a Digia product. See <a href=\"http://qt.digia.com/\">qt.digia.com</a> " + "<p>Qt is a Digia product developed as an open source project. See <a href=\"http://%3/\">%3</a> " "for more information.</p>" - ); + ).arg(QStringLiteral("2014"), + QStringLiteral("qt.io/licensing"), + QStringLiteral("qt.io")); QMessageBox *msgBox = new QMessageBox(parent); msgBox->setAttribute(Qt::WA_DeleteOnClose); msgBox->setWindowTitle(title.isEmpty() ? tr("About Qt") : title); diff --git a/src/widgets/dialogs/qwizard.cpp b/src/widgets/dialogs/qwizard.cpp index 1a12b334e6..1f7b18e824 100644 --- a/src/widgets/dialogs/qwizard.cpp +++ b/src/widgets/dialogs/qwizard.cpp @@ -3254,7 +3254,7 @@ bool QWizard::nativeEvent(const QByteArray &eventType, void *message, long *resu { #if !defined(QT_NO_STYLE_WINDOWSVISTA) Q_D(QWizard); - if (d->isVistaThemeEnabled() && eventType == QByteArrayLiteral("windows_generic_MSG")) { + if (d->isVistaThemeEnabled() && eventType == "windows_generic_MSG") { MSG *windowsMessage = static_cast<MSG *>(message); const bool winEventResult = d->vistaHelper->handleWinEvent(windowsMessage, result); if (QVistaHelper::vistaState() != d->vistaState) { diff --git a/src/widgets/doc/qtwidgets.qdocconf b/src/widgets/doc/qtwidgets.qdocconf index 4b19702208..1f79d144bf 100644 --- a/src/widgets/doc/qtwidgets.qdocconf +++ b/src/widgets/doc/qtwidgets.qdocconf @@ -33,15 +33,6 @@ headerdirs += .. sourcedirs += .. \ ../../../examples/widgets/doc/src -excludefiles += ../widgets/qmacnativewidget_mac.h \ - ../widgets/qmaccocoaviewcontainer_mac.h \ - ../widgets/qcocoatoolbardelegate_mac_p.h \ - ../widgets/qcocoamenu_mac_p.h \ - ../widgets/qmaccocoaviewcontainer_mac.mm \ - ../widgets/qcocoatoolbardelegate_mac.mm \ - ../widgets/qmainwindowlayout_mac.mm \ - ../widgets/qmacnativewidget_mac.mm - exampledirs += ../../../examples/widgets \ ../../../doc/src/snippets \ ../ \ diff --git a/src/widgets/doc/src/model-view-programming.qdoc b/src/widgets/doc/src/model-view-programming.qdoc index 3a8fd54bcf..8978efa1e3 100644 --- a/src/widgets/doc/src/model-view-programming.qdoc +++ b/src/widgets/doc/src/model-view-programming.qdoc @@ -214,7 +214,7 @@ classes, such as QListView, QTableView, and QTreeView with QStandardItemModel. - \section1 Using models and views + \section1 Using Models and Views The following sections explain how to use the model/view pattern in Qt. Each section includes an example and is followed by a @@ -282,7 +282,7 @@ of items. This subject is covered in more detail in the section about \l{Handling Selections in Item Views}. - \section1 Model classes + \section1 Model Classes Before examining how selections are handled, you may find it useful to examine the concepts used in the model/view framework. @@ -518,7 +518,7 @@ section, we demonstrate this by creating a convenient ready-to-use model for holding lists of strings. - \section1 View classes + \section1 View Classes \section2 Concepts @@ -678,7 +678,7 @@ each view; for example, a contiguous selection in a table view can be represented as a fragmented set of highlighted items in a tree view. - \section1 Delegate classes + \section1 Delegate Classes \section2 Concepts @@ -863,7 +863,7 @@ be less integrated into applications, and will be less usable than those that emit hints to support common editing actions. - \section1 Handling selections in item views + \section1 Handling Selections in Item Views \section2 Concepts @@ -1139,7 +1139,7 @@ determine whether any given item is the parent of another level of items. - \section1 Creating new models + \section1 Creating New Models The separation of functionality between the model/view components allows models to be created that can take advantage of existing views. This @@ -1405,7 +1405,7 @@ virtual functions that must be implemented to enable various features in different types of models. - \section1 Item view convenience classes + \section1 Item View Convenience Classes The item-based widgets have names which reflect their uses: \c QListWidget provides a list of items, \c QTreeWidget displays a @@ -1832,7 +1832,7 @@ \sa {itemviews/puzzle}{Item Views Puzzle Example} - \section1 Proxy models + \section1 Proxy Models In the model/view framework, items of data supplied by a single model can be shared by any number of views, and each of these can possibly represent the same information @@ -1917,7 +1917,7 @@ \l{QSortFilterProxyModel::lessThan()}{lessThan()} function to perform custom comparisons. - \section1 Model subclassing reference + \section1 Model Subclassing Reference Model subclasses need to provide implementations of many of the virtual functions defined in the QAbstractItemModel base class. The number of these functions that need @@ -2299,7 +2299,7 @@ false and does nothing. \keyword Model/View Classes - \section1 The model/view classes + \section1 The Model/View Classes These classes use the model/view design pattern in which the underlying data (in the model) is kept separate from the way the @@ -2307,7 +2307,7 @@ \annotatedlist model-view - \section1 Related examples + \section1 Related Examples \list \li \l{itemviews/dirview}{Dir View} diff --git a/src/widgets/doc/src/widgets-and-layouts/styles.qdoc b/src/widgets/doc/src/widgets-and-layouts/styles.qdoc index f8b3d80b67..042a0c9f14 100644 --- a/src/widgets/doc/src/widgets-and-layouts/styles.qdoc +++ b/src/widgets/doc/src/widgets-and-layouts/styles.qdoc @@ -84,7 +84,7 @@ \annotatedlist appearance - \section1 The QStyle implementation + \section1 The QStyle Implementation The API of QStyle contains functions that draw the widgets, static helper functions to do common and difficult tasks (e.g., diff --git a/src/widgets/doc/src/widgets-and-layouts/stylesheet.qdoc b/src/widgets/doc/src/widgets-and-layouts/stylesheet.qdoc index 48e3478130..9f22ee1540 100644 --- a/src/widgets/doc/src/widgets-and-layouts/stylesheet.qdoc +++ b/src/widgets/doc/src/widgets-and-layouts/stylesheet.qdoc @@ -512,7 +512,7 @@ In contrast, setting a font and propagate using QWidget::setFont() and QWidget::setPalette() propagates to child widgets. - \section1 Widgets inside C++ namespaces + \section1 Widgets Inside C++ Namespaces The Type Selector can be used to style widgets of a particular type. For example, @@ -528,7 +528,7 @@ \snippet code/doc_src_stylesheet.cpp 27 - \section1 Setting QObject properties + \section1 Setting QObject Properties From 4.3 and above, any designable Q_PROPERTY can be set using the qproperty-<property name> syntax. @@ -3549,7 +3549,7 @@ [Hint: The \l{The Style Sheet Syntax#Conflict Resolution}{Conflict Resolution} section above explains what happens in cases like this.] - \section1 Customizing specific widgets + \section1 Customizing Specific Widgets This section provides examples to customize specific widgets using Style Sheets. @@ -3930,7 +3930,7 @@ \sa {Style Sheet Example}, {Supported HTML Subset}, QStyle - \section1 Common mistakes + \section1 Common Mistakes This section lists some common mistakes when using stylesheets. diff --git a/src/widgets/doc/src/widgets-tutorial.qdoc b/src/widgets/doc/src/widgets-tutorial.qdoc index 0a80a976b9..3e65d3e22d 100644 --- a/src/widgets/doc/src/widgets-tutorial.qdoc +++ b/src/widgets/doc/src/widgets-tutorial.qdoc @@ -54,7 +54,7 @@ This means that when you delete a window widget, all the child widgets it contains are also deleted. - \section1 Writing a main Function + \section1 Writing a Main Function Many of the GUI examples provided with Qt follow the pattern of having a \c{main.cpp} file, which contains the standard code to @@ -72,7 +72,7 @@ function returns. Finally, \c{main()} returns the value returned by QApplication::exec(). - \section1 Simple widget examples + \section1 Simple Widget Examples Each of theses simple widget examples is written entirely within the \c main() function. @@ -87,7 +87,7 @@ \li \l {tutorials/widgets/nestedlayouts} {Nested layouts} \endlist - \section1 Real world widget examples + \section1 Real World Widget Examples In these \l{Qt Widgets Examples} {more advanced examples}, the code that creates the widgets and layouts is stored in other files. For diff --git a/src/widgets/graphicsview/qgraphicsanchorlayout.cpp b/src/widgets/graphicsview/qgraphicsanchorlayout.cpp index 99d20c2aad..a7e0e71f15 100644 --- a/src/widgets/graphicsview/qgraphicsanchorlayout.cpp +++ b/src/widgets/graphicsview/qgraphicsanchorlayout.cpp @@ -92,7 +92,7 @@ If the spacing is negative, the items will overlap to some extent. - \section1 Known issues + \section1 Known Issues There are some features that QGraphicsAnchorLayout currently does not support. This might change in the future, so avoid using these features if you want to avoid any future regressions in behaviour: diff --git a/src/widgets/itemviews/qtreewidget.cpp b/src/widgets/itemviews/qtreewidget.cpp index 9dba8ef894..0a4e57812a 100644 --- a/src/widgets/itemviews/qtreewidget.cpp +++ b/src/widgets/itemviews/qtreewidget.cpp @@ -1002,6 +1002,9 @@ void QTreeModel::timerEvent(QTimerEvent *ev) \since 4.2 Hides the item if \a hide is true, otherwise shows the item. + \note A call to this function has no effect if the item is not currently in a view. In particular, + calling \c setHidden(true) on an item and only then adding it to a view will result in + a visible item. \sa isHidden() */ diff --git a/src/widgets/kernel/qopenglwidget.cpp b/src/widgets/kernel/qopenglwidget.cpp index de402cdb7d..543f59d7d1 100644 --- a/src/widgets/kernel/qopenglwidget.cpp +++ b/src/widgets/kernel/qopenglwidget.cpp @@ -149,7 +149,7 @@ QT_BEGIN_NAMESPACE \endlist - \section1 OpenGL function calls, headers and QOpenGLFunctions + \section1 OpenGL Function Calls, Headers and QOpenGLFunctions When making OpenGL function calls, it is strongly recommended to avoid calling the functions directly. Instead, prefer using QOpenGLFunctions (when making @@ -177,7 +177,7 @@ QT_BEGIN_NAMESPACE feasible. This means that constants and function pointer typedefs from ARB, EXT, OES extensions are automatically available. - \section1 Code examples + \section1 Code Examples To get started, the simplest QOpenGLWidget subclass could like like the following: @@ -282,7 +282,7 @@ QT_BEGIN_NAMESPACE fully controlled by the thread, e.g. an additional framebuffer object, and blitting to the QOpenGLWidget's framebuffer at a suitable time. - \section1 Context sharing + \section1 Context Sharing When multiple QOpenGLWidgets are added as children to the same top-level widget, their contexts will share with each other. This does not apply for @@ -311,7 +311,7 @@ QT_BEGIN_NAMESPACE created later. Some other drivers may behave in unexpected ways when trying to utilize shared resources between different threads. - \section1 Resource initialization and cleanup + \section1 Resource Initialization and Cleanup The QOpenGLWidget's associated OpenGL context is guaranteed to be current whenever initializeGL() and paintGL() are invoked. Do not attempt to create diff --git a/src/widgets/kernel/qshortcut.cpp b/src/widgets/kernel/qshortcut.cpp index a98b2db0fc..3349b45467 100644 --- a/src/widgets/kernel/qshortcut.cpp +++ b/src/widgets/kernel/qshortcut.cpp @@ -271,7 +271,7 @@ static bool correctActionContext(Qt::ShortcutContext context, QAction *a, QWidge // (and reaches this point), then the menu item itself has been disabled. // This occurs at the QPA level on Mac, were we disable all the Cocoa menus // when showing a modal window. - if (a->shortcut().count() <= 1) + if (a->shortcut().count() < 1 || (a->shortcut().count() == 1 && (a->shortcut()[0] & Qt::MODIFIER_MASK) != 0)) continue; #endif QAction *a = menu->menuAction(); diff --git a/src/widgets/kernel/qsizepolicy.h b/src/widgets/kernel/qsizepolicy.h index 276679a017..9730ec1206 100644 --- a/src/widgets/kernel/qsizepolicy.h +++ b/src/widgets/kernel/qsizepolicy.h @@ -85,7 +85,6 @@ public: QSizePolicy() : data(0) { } - // ### Qt 5: merge these two constructors (with type == DefaultType) QSizePolicy(Policy horizontal, Policy vertical, ControlType type = DefaultType) : data(0) { bits.horPolicy = horizontal; diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index 190fd3a134..00cf39bdbf 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -10526,6 +10526,22 @@ void QWidgetPrivate::setParent_sys(QWidget *newparent, Qt::WindowFlags f) if (wasCreated && !(f & Qt::Window) && (oldFlags & Qt::Window) && !q->testAttribute(Qt::WA_NativeWindow)) { if (extra && extra->hasWindowContainer) QWindowContainer::toplevelAboutToBeDestroyed(q); + + QWindow *newParentWindow = newparent->windowHandle(); + if (!newParentWindow) + if (QWidget *npw = newparent->nativeParentWidget()) + newParentWindow = npw->windowHandle(); + + Q_FOREACH (QObject *child, q->windowHandle()->children()) { + QWindow *childWindow = qobject_cast<QWindow *>(child); + if (!childWindow) + continue; + + QWidgetWindow *childWW = qobject_cast<QWidgetWindow *>(childWindow); + QWidget *childWidget = childWW ? childWW->widget() : 0; + if (!childWW || (childWidget && childWidget->testAttribute(Qt::WA_NativeWindow))) + childWindow->setParent(newParentWindow); + } q->destroy(); } diff --git a/src/widgets/kernel/qwidgetbackingstore.cpp b/src/widgets/kernel/qwidgetbackingstore.cpp index d3bc6f52e5..2f2db32852 100644 --- a/src/widgets/kernel/qwidgetbackingstore.cpp +++ b/src/widgets/kernel/qwidgetbackingstore.cpp @@ -1129,12 +1129,17 @@ void QWidgetBackingStore::doSync() // prevent triggering unnecessary backingstore painting when only the // OpenGL content changes. Check if we have such widgets in the special // dirty list. + QVarLengthArray<QWidget *, 16> paintPending; for (int i = 0; i < dirtyRenderToTextureWidgets.count(); ++i) { QWidget *w = dirtyRenderToTextureWidgets.at(i); - w->d_func()->sendPaintEvent(w->rect()); + paintPending << w; resetWidget(w); } dirtyRenderToTextureWidgets.clear(); + for (int i = 0; i < paintPending.count(); ++i) { + QWidget *w = paintPending[i]; + w->d_func()->sendPaintEvent(w->rect()); + } // We might have newly exposed areas on the screen if this function was // called from sync(QWidget *, QRegion)), so we have to make sure those diff --git a/src/widgets/styles/qandroidstyle.cpp b/src/widgets/styles/qandroidstyle.cpp index eb688e3c46..38c7497ffa 100644 --- a/src/widgets/styles/qandroidstyle.cpp +++ b/src/widgets/styles/qandroidstyle.cpp @@ -624,8 +624,6 @@ QRect QAndroidStyle::subElementRect(SubElement subElement, const QStyleOption *option, const QWidget *widget) const { - if (subElement == SE_LineEditContents) // fix spinbox display problem - return QFusionStyle::subElementRect(subElement, option, widget); const ItemType itemType = qtControl(subElement); AndroidControlsHash::const_iterator it = itemType != QC_UnknownType ? m_androidControlsHash.find(itemType) diff --git a/src/widgets/styles/qfusionstyle.cpp b/src/widgets/styles/qfusionstyle.cpp index 7814f80001..142bd5882e 100644 --- a/src/widgets/styles/qfusionstyle.cpp +++ b/src/widgets/styles/qfusionstyle.cpp @@ -3084,8 +3084,7 @@ int QFusionStyle::pixelMetric(PixelMetric metric, const QStyleOption *option, co val = 2; break; case PM_MaximumDragDistance: - val = -1; - break; + return -1; // Do not dpi-scale because the value is magic case PM_TabCloseIndicatorWidth: case PM_TabCloseIndicatorHeight: val = 20; @@ -3100,8 +3099,7 @@ int QFusionStyle::pixelMetric(PixelMetric metric, const QStyleOption *option, co val = 2; break; case PM_SubMenuOverlap: - val = -1; - break; + return -1; // Do not dpi-scale because the value is magic case PM_DockWidgetHandleExtent: case PM_SplitterWidth: val = 4; @@ -3122,7 +3120,6 @@ int QFusionStyle::pixelMetric(PixelMetric metric, const QStyleOption *option, co break; case PM_DefaultFrameWidth: return 1; // Do not dpi-scale because the drawn frame is always exactly 1 pixel thick - break; default: return QCommonStyle::pixelMetric(metric, option, widget); } diff --git a/src/widgets/styles/qgtkstyle.cpp b/src/widgets/styles/qgtkstyle.cpp index fe35c7c695..6f2a2046b7 100644 --- a/src/widgets/styles/qgtkstyle.cpp +++ b/src/widgets/styles/qgtkstyle.cpp @@ -289,6 +289,7 @@ static QColor mergedColors(const QColor &colorA, const QColor &colorB, int facto static GdkColor fromQColor(const QColor &color) { GdkColor retval; + retval.pixel = 0; retval.red = color.red() * 255; retval.green = color.green() * 255; retval.blue = color.blue() * 255; @@ -3235,8 +3236,8 @@ void QGtkStyle::drawControl(ControlElement element, else pixmap = menuItem->icon.pixmap(iconSize, mode); - int pixw = pixmap.width(); - int pixh = pixmap.height(); + const int pixw = pixmap.width() / pixmap.devicePixelRatio(); + const int pixh = pixmap.height() / pixmap.devicePixelRatio(); QRect pmr(0, 0, pixw, pixh); pmr.moveCenter(vCheckRect.center() - QPoint(0, 1)); painter->setPen(menuItem->palette.text().color()); diff --git a/src/widgets/styles/qmacstyle_mac.mm b/src/widgets/styles/qmacstyle_mac.mm index 7f6495e29d..a4838d5777 100644 --- a/src/widgets/styles/qmacstyle_mac.mm +++ b/src/widgets/styles/qmacstyle_mac.mm @@ -93,6 +93,7 @@ #include <qmath.h> #include <QtWidgets/qgraphicsproxywidget.h> #include <QtWidgets/qgraphicsview.h> +#include <QtCore/qvariant.h> #include <private/qstylehelper_p.h> #include <private/qstyleanimation_p.h> #include <qpa/qplatformfontdatabase.h> @@ -1728,7 +1729,7 @@ QMacStylePrivate::QMacStylePrivate() QMacStylePrivate::~QMacStylePrivate() { - Q_FOREACH (NSView *b, buttons) + Q_FOREACH (NSView *b, cocoaControls) [b release]; } @@ -1749,41 +1750,92 @@ ThemeDrawState QMacStylePrivate::getDrawState(QStyle::State flags) return tds; } -NSView *QMacStylePrivate::buttonOfKind(ThemeButtonKind kind) const +static QCocoaWidget cocoaWidgetFromHIThemeButtonKind(ThemeButtonKind kind) { - NSView *bv = buttons[kind]; + QCocoaWidget w; + + switch (kind) { + case kThemePopupButton: + case kThemePopupButtonSmall: + case kThemePopupButtonMini: + w.first = QCocoaPopupButton; + break; + case kThemeComboBox: + w.first = QCocoaComboBox; + break; + case kThemeArrowButton: + w.first = QCocoaArrowButton; + break; + case kThemeCheckBox: + case kThemeCheckBoxSmall: + case kThemeCheckBoxMini: + w.first = QCocoaCheckBox; + break; + case kThemeRadioButton: + case kThemeRadioButtonSmall: + case kThemeRadioButtonMini: + w.first = QCocoaRadioButton; + break; + case kThemePushButton: + case kThemePushButtonSmall: + case kThemePushButtonMini: + w.first = QCocoaPushButton; + break; + default: + break; + } + + switch (kind) { + case kThemePushButtonSmall: + case kThemePopupButtonSmall: + case kThemeCheckBoxSmall: + case kThemeRadioButtonSmall: + w.second = QAquaSizeSmall; + break; + case kThemePushButtonMini: + case kThemePopupButtonMini: + case kThemeCheckBoxMini: + case kThemeRadioButtonMini: + w.second = QAquaSizeMini; + break; + default: + w.second = QAquaSizeLarge; + break; + } + + return w; +} + +NSView *QMacStylePrivate::cocoaControl(QCocoaWidget widget, QPoint *offset) const +{ + NSView *bv = cocoaControls[widget]; if (!bv) { - if (kind == kThemePopupButton) + + if (widget.first == QCocoaPopupButton) bv = [[NSPopUpButton alloc] init]; - else if (kind == kThemeComboBox) + else if (widget.first == QCocoaComboBox) bv = [[NSComboBox alloc] init]; else bv = [[NSButton alloc] init]; - switch (kind) { - case kThemeArrowButton: { + switch (widget.first) { + case QCocoaArrowButton: { NSButton *bc = (NSButton *)bv; bc.buttonType = NSOnOffButton; bc.bezelStyle = NSDisclosureBezelStyle; break; } - case kThemeCheckBox: - case kThemeCheckBoxSmall: - case kThemeCheckBoxMini: { + case QCocoaCheckBox: { NSButton *bc = (NSButton *)bv; bc.buttonType = NSSwitchButton; break; } - case kThemeRadioButton: - case kThemeRadioButtonSmall: - case kThemeRadioButtonMini: { + case QCocoaRadioButton: { NSButton *bc = (NSButton *)bv; bc.buttonType = NSRadioButton; break; } - case kThemePushButton: - case kThemePushButtonSmall: - case kThemePushButtonMini: { + case QCocoaPushButton: { NSButton *bc = (NSButton *)bv; bc.buttonType = NSMomentaryPushButton; bc.bezelStyle = NSRoundedBezelStyle; @@ -1793,23 +1845,44 @@ NSView *QMacStylePrivate::buttonOfKind(ThemeButtonKind kind) const break; } -// if (kind == kThemePushButtonSmall -// || kind == kThemePopupButtonSmall -// || kind == kThemeCheckBoxSmall -// || kind == kThemeRadioButtonSmall) -// bc.controlSize = NSSmallControlSize; -// else if (kind == kThemePushButtonMini -// || kind == kThemePopupButtonMini -// || kind == kThemeCheckBoxMini -// || kind == kThemeRadioButtonMini) -// bc.controlSize = NSMiniControlSize; - if ([bv isKindOfClass:[NSButton class]]) { NSButton *bc = (NSButton *)bv; bc.title = nil; } - const_cast<QMacStylePrivate *>(this)->buttons.insert(kind, bv); + if ([bv isKindOfClass:[NSControl class]]) { + NSCell *bcell = [(NSControl *)bv cell]; + switch (widget.second) { + case QAquaSizeSmall: + bcell.controlSize = NSSmallControlSize; + break; + case QAquaSizeMini: + bcell.controlSize = NSMiniControlSize; + break; + default: + break; + } + } + + const_cast<QMacStylePrivate *>(this)->cocoaControls.insert(widget, bv); + } + + if (offset) { + if (widget == QCocoaWidget(QCocoaRadioButton, QAquaSizeLarge)) + offset->setY(2); + else if (widget == QCocoaWidget(QCocoaRadioButton, QAquaSizeSmall)) + *offset = QPoint(-1, 2); + else if (widget == QCocoaWidget(QCocoaRadioButton, QAquaSizeMini)) + offset->setY(2); + else if (widget == QCocoaWidget(QCocoaPopupButton, QAquaSizeSmall) + || widget == QCocoaWidget(QCocoaCheckBox, QAquaSizeLarge)) + offset->setY(1); + else if (widget == QCocoaWidget(QCocoaCheckBox, QAquaSizeSmall)) + offset->setX(-1); + else if (widget == QCocoaWidget(QCocoaCheckBox, QAquaSizeMini)) + *offset = QPoint(7, 5); + else if (widget == QCocoaWidget(QCocoaPopupButton, QAquaSizeMini)) + *offset = QPoint(2, -1); } return bv; @@ -1827,8 +1900,8 @@ void QMacStylePrivate::drawNSViewInRect(NSView *view, const QRect &qtRect, QPain CGRect rect = CGRectMake(qtRect.x() + 1, qtRect.y(), qtRect.width(), qtRect.height()); [backingStoreNSView addSubview:view]; - view.frame = rect; - [view drawRect:rect]; + view.frame = NSRectFromCGRect(rect); + [view drawRect:NSRectFromCGRect(rect)]; [view removeFromSuperviewWithoutNeedingDisplay]; [NSGraphicsContext restoreGraphicsState]; @@ -1928,14 +2001,20 @@ void QMacStylePrivate::drawColorlessButton(const HIRect &macRect, HIThemeButtonD } pm = QPixmap::fromImage(image); } else if ((usingYosemiteOrLater && combo && !editableCombo) || button) { - NSButton *bc = (NSButton *)buttonOfKind(bdi->kind); + QPoint offset; + NSButton *bc = (NSButton *)cocoaControl(cocoaWidgetFromHIThemeButtonKind(bdi->kind), &offset); [bc highlight:pressed]; bc.enabled = bdi->state != kThemeStateUnavailable && bdi->state != kThemeStateUnavailableInactive; + bc.allowsMixedState = YES; bc.state = bdi->value == kThemeButtonOn ? NSOnState : bdi->value == kThemeButtonMixed ? NSMixedState : NSOffState; - p->translate(0, 1); - drawNSViewInRect(bc, opt->rect, p); - p->translate(0, -1); + // The view frame may differ from what we pass to HITheme + QRect rect = opt->rect; + if (bdi->kind == kThemePopupButtonMini) + rect.adjust(0, 0, -5, 0); + p->translate(offset); + drawNSViewInRect(bc, rect, p); + p->translate(-offset); return; } else if (usingYosemiteOrLater && editableCombo) { QImage image = activePixmap.toImage(); @@ -3834,9 +3913,9 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter NSBezierPath *pushButtonFocusRingPath; if (bdi.kind == kThemeBevelButton) - pushButtonFocusRingPath = [NSBezierPath bezierPathWithRect:focusRect]; + pushButtonFocusRingPath = [NSBezierPath bezierPathWithRect:NSRectFromCGRect(focusRect)]; else - pushButtonFocusRingPath = [NSBezierPath bezierPathWithRoundedRect:focusRect xRadius:4 yRadius:4]; + pushButtonFocusRingPath = [NSBezierPath bezierPathWithRoundedRect:NSRectFromCGRect(focusRect) xRadius:4 yRadius:4]; qt_drawFocusRingOnPath(cg, pushButtonFocusRingPath); } @@ -5761,7 +5840,25 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex drawToolbarButtonArrow(tb->rect, tds, cg); } if (tb->state & State_On) { - if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_5) { + if (QSysInfo::MacintoshVersion > QSysInfo::MV_MAVERICKS) { + QWindow *window = 0; + if (widget && widget->window()) + window = widget->window()->windowHandle(); + else if (opt->styleObject) + window = opt->styleObject->property("_q_styleObjectWindow").value<QWindow *>(); + + NSView *view = window ? (NSView *)window->winId() : nil; + bool isKey = false; + if (view) + isKey = [view.window isKeyWindow]; + + QBrush brush(isKey ? QColor(0, 0, 0, 28) + : QColor(0, 0, 0, 21)); + QPainterPath path; + path.addRoundedRect(QRectF(tb->rect.x(), tb->rect.y(), tb->rect.width(), tb->rect.height() + 4), 4, 4); + p->setRenderHint(QPainter::Antialiasing); + p->fillPath(path, brush); + } else if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_5) { static QPixmap pm(QLatin1String(":/qt-project.org/mac/style/images/leopard-unified-toolbar-on.png")); p->setRenderHint(QPainter::SmoothPixmapTransform); QStyleHelper::drawBorderPixmap(pm, p, tb->rect, 2, 2, 2, 2); diff --git a/src/widgets/styles/qmacstyle_mac_p_p.h b/src/widgets/styles/qmacstyle_mac_p_p.h index f5b67cd549..b6267c43e6 100644 --- a/src/widgets/styles/qmacstyle_mac_p_p.h +++ b/src/widgets/styles/qmacstyle_mac_p_p.h @@ -85,6 +85,7 @@ #include <qlibrary.h> #include <qdatetimeedit.h> #include <qmath.h> +#include <qpair.h> #include <qset.h> #include <QtWidgets/qgraphicsproxywidget.h> #include <QtWidgets/qgraphicsview.h> @@ -120,6 +121,17 @@ QT_BEGIN_NAMESPACE enum QAquaWidgetSize { QAquaSizeLarge = 0, QAquaSizeSmall = 1, QAquaSizeMini = 2, QAquaSizeUnknown = -1 }; +enum QCocoaWidgetKind { + QCocoaArrowButton, // Disclosure triangle, like in QTreeView + QCocoaCheckBox, + QCocoaComboBox, // Editable QComboBox + QCocoaPopupButton, // Non-editable QComboBox + QCocoaPushButton, + QCocoaRadioButton +}; + +typedef QPair<QCocoaWidgetKind, QAquaWidgetSize> QCocoaWidget; + #define SIZE(large, small, mini) \ (controlSize == QAquaSizeLarge ? (large) : controlSize == QAquaSizeSmall ? (small) : (mini)) @@ -187,7 +199,7 @@ public: void setAutoDefaultButton(QObject *button) const; - NSView *buttonOfKind(ThemeButtonKind kind) const; + NSView *cocoaControl(QCocoaWidget widget, QPoint *offset) const; void drawNSViewInRect(NSView *view, const QRect &rect, QPainter *p) const; void resolveCurrentNSView(QWindow *window); @@ -211,7 +223,7 @@ public: #endif void *indicatorBranchButtonCell; NSView *backingStoreNSView; - QHash<ThemeButtonKind , NSView *> buttons; + QHash<QCocoaWidget, NSView *> cocoaControls; }; QT_END_NAMESPACE diff --git a/src/widgets/styles/qstyle.cpp b/src/widgets/styles/qstyle.cpp index 09cb6fd06b..3affd84124 100644 --- a/src/widgets/styles/qstyle.cpp +++ b/src/widgets/styles/qstyle.cpp @@ -302,8 +302,9 @@ static int unpackControlTypes(QSizePolicy::ControlTypes controls, QSizePolicy::C applications, which may not be yours and hence not available for you to recompile. The Qt Plugin system makes it possible to create styles as plugins. Styles created as plugins are loaded as shared - objects at runtime by Qt itself. Please refer to the \l{plugins-howto.html}{Qt Plugin} documentation for more - information on how to go about creating a style plugin. + objects at runtime by Qt itself. Please refer to the \l{How to Create Qt Plugins}{Qt Plugin} + documentation for more information on how to go about creating a style + plugin. Compile your plugin and put it into Qt's \c plugins/styles directory. We now have a pluggable style that Qt can load diff --git a/src/widgets/styles/qstylesheetstyle.cpp b/src/widgets/styles/qstylesheetstyle.cpp index 18cd793051..a6c7f5dde2 100644 --- a/src/widgets/styles/qstylesheetstyle.cpp +++ b/src/widgets/styles/qstylesheetstyle.cpp @@ -2485,7 +2485,7 @@ void QStyleSheetStyle::setProperties(QWidget *w) QSet<const QString> propertySet; for (int i = decls.count() - 1; i >= 0; --i) { const QString property = decls.at(i).d->property; - if (!property.startsWith(QStringLiteral("qproperty-"), Qt::CaseInsensitive)) + if (!property.startsWith(QLatin1String("qproperty-"), Qt::CaseInsensitive)) continue; if (!propertySet.contains(property)) { propertySet.insert(property); @@ -3573,8 +3573,8 @@ void QStyleSheetStyle::drawControl(ControlElement ce, const QStyleOption *opt, Q pixmap = mi.icon.pixmap(pixelMetric(PM_SmallIconSize), mode, QIcon::On); else pixmap = mi.icon.pixmap(pixelMetric(PM_SmallIconSize), mode); - int pixw = pixmap.width(); - int pixh = pixmap.height(); + const int pixw = pixmap.width() / pixmap.devicePixelRatio(); + const int pixh = pixmap.height() / pixmap.devicePixelRatio(); QRenderRule iconRule = renderRule(w, opt, PseudoElement_MenuIcon); if (!iconRule.hasGeometry()) { iconRule.geo = new QStyleSheetGeometryData(pixw, pixh, pixw, pixh, -1, -1); diff --git a/src/widgets/styles/qwindowscestyle.cpp b/src/widgets/styles/qwindowscestyle.cpp index ea5c0435d8..d3a8877d00 100644 --- a/src/widgets/styles/qwindowscestyle.cpp +++ b/src/widgets/styles/qwindowscestyle.cpp @@ -671,8 +671,8 @@ void QWindowsCEStyle::drawControl(ControlElement element, const QStyleOption *op pixmap = menuitem->icon.pixmap(pixelMetric(PM_SmallIconSize), mode, QIcon::On); else pixmap = menuitem->icon.pixmap(pixelMetric(PM_SmallIconSize), mode); - int pixw = pixmap.width(); - int pixh = pixmap.height(); + const int pixw = pixmap.width() / pixmap.devicePixelRatio(); + const int pixh = pixmap.height() / pixmap.devicePixelRatio(); if (act && !dis && !checked) qDrawPlainRect(painter, vCheckRect, menuitem->palette.button().color(), 1, &menuitem->palette.brush(QPalette::Button)); diff --git a/src/widgets/styles/qwindowsstyle.cpp b/src/widgets/styles/qwindowsstyle.cpp index f4306e7bd3..3619c3ff29 100644 --- a/src/widgets/styles/qwindowsstyle.cpp +++ b/src/widgets/styles/qwindowsstyle.cpp @@ -1156,8 +1156,8 @@ void QWindowsStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPai pixmap = menuitem->icon.pixmap(proxy()->pixelMetric(PM_SmallIconSize, opt, widget), mode, QIcon::On); else pixmap = menuitem->icon.pixmap(proxy()->pixelMetric(PM_SmallIconSize, opt, widget), mode); - int pixw = pixmap.width(); - int pixh = pixmap.height(); + const int pixw = pixmap.width() / pixmap.devicePixelRatio(); + const int pixh = pixmap.height() / pixmap.devicePixelRatio(); if (act && !dis && !checked) qDrawShadePanel(p, vCheckRect, menuitem->palette, false, 1, &menuitem->palette.brush(QPalette::Button)); diff --git a/src/widgets/styles/qwindowsvistastyle.cpp b/src/widgets/styles/qwindowsvistastyle.cpp index 35a5a08a2c..a6eb2c0bc6 100644 --- a/src/widgets/styles/qwindowsvistastyle.cpp +++ b/src/widgets/styles/qwindowsvistastyle.cpp @@ -1275,8 +1275,8 @@ void QWindowsVistaStyle::drawControl(ControlElement element, const QStyleOption pixmap = menuitem->icon.pixmap(proxy()->pixelMetric(PM_SmallIconSize, option, widget), mode, QIcon::On); else pixmap = menuitem->icon.pixmap(proxy()->pixelMetric(PM_SmallIconSize, option, widget), mode); - int pixw = pixmap.width(); - int pixh = pixmap.height(); + const int pixw = pixmap.width() / pixmap.devicePixelRatio(); + const int pixh = pixmap.height() / pixmap.devicePixelRatio(); QRect pmr(0, 0, pixw, pixh); pmr.moveCenter(vCheckRect.center()); painter->setPen(menuitem->palette.text().color()); diff --git a/src/widgets/styles/qwindowsxpstyle.cpp b/src/widgets/styles/qwindowsxpstyle.cpp index 5cd378acba..624023f627 100644 --- a/src/widgets/styles/qwindowsxpstyle.cpp +++ b/src/widgets/styles/qwindowsxpstyle.cpp @@ -2246,8 +2246,8 @@ void QWindowsXPStyle::drawControl(ControlElement element, const QStyleOption *op QPixmap pixmap = checked ? menuitem->icon.pixmap(proxy()->pixelMetric(PM_SmallIconSize, option, widget), mode, QIcon::On) : menuitem->icon.pixmap(proxy()->pixelMetric(PM_SmallIconSize, option, widget), mode); - int pixw = pixmap.width(); - int pixh = pixmap.height(); + const int pixw = pixmap.width() / pixmap.devicePixelRatio(); + const int pixh = pixmap.height() / pixmap.devicePixelRatio(); QRect iconRect(0, 0, pixw, pixh); iconRect.moveCenter(QRect(xpos, y, checkcol, h).center()); QRect vIconRect = visualRect(option->direction, option->rect, iconRect); diff --git a/src/widgets/util/qsystemtrayicon_x11.cpp b/src/widgets/util/qsystemtrayicon_x11.cpp index cda557b6b0..09f2d6266c 100644 --- a/src/widgets/util/qsystemtrayicon_x11.cpp +++ b/src/widgets/util/qsystemtrayicon_x11.cpp @@ -326,7 +326,7 @@ bool QSystemTrayIconPrivate::isSystemTrayAvailable_sys() // no QPlatformSystemTrayIcon so fall back to default xcb platform behavior const QString platform = QGuiApplication::platformName(); - if (platform.compare(QStringLiteral("xcb"), Qt::CaseInsensitive) == 0) + if (platform.compare(QLatin1String("xcb"), Qt::CaseInsensitive) == 0) return locateSystemTray(); return false; } diff --git a/src/widgets/widgets/qcombobox.cpp b/src/widgets/widgets/qcombobox.cpp index 4db3ab38a6..2fa197b2c8 100644 --- a/src/widgets/widgets/qcombobox.cpp +++ b/src/widgets/widgets/qcombobox.cpp @@ -295,7 +295,7 @@ QSize QComboBoxPrivate::recomputeSizeHint(QSize &sh) const { Q_Q(const QComboBox); if (!sh.isValid()) { - bool hasIcon = sizeAdjustPolicy == QComboBox::AdjustToMinimumContentsLengthWithIcon ? true : false; + bool hasIcon = sizeAdjustPolicy == QComboBox::AdjustToMinimumContentsLengthWithIcon; int count = q->count(); QSize iconSize = q->iconSize(); const QFontMetrics &fm = q->fontMetrics(); diff --git a/src/widgets/widgets/qmdiarea.cpp b/src/widgets/widgets/qmdiarea.cpp index dd33a2c6d6..1e291f469e 100644 --- a/src/widgets/widgets/qmdiarea.cpp +++ b/src/widgets/widgets/qmdiarea.cpp @@ -347,7 +347,8 @@ void SimpleCascader::rearrange(QList<QWidget *> &widgets, const QRect &domain) c options.initFrom(widgets.at(0)); int titleBarHeight = widgets.at(0)->style()->pixelMetric(QStyle::PM_TitleBarHeight, &options, widgets.at(0)); const QFontMetrics fontMetrics = QFontMetrics(QApplication::font("QMdiSubWindowTitleBar")); - const int dy = qMax(titleBarHeight - (titleBarHeight - fontMetrics.height()) / 2, 1); + const int dy = qMax(titleBarHeight - (titleBarHeight - fontMetrics.height()) / 2, 1) + + widgets.at(0)->style()->pixelMetric(QStyle::PM_FocusFrameVMargin, 0, widgets.at(0)); const int n = widgets.size(); const int nrows = qMax((domain.height() - (topOffset + bottomOffset)) / dy, 1); @@ -1465,7 +1466,7 @@ QMdiSubWindow *QMdiAreaPrivate::nextVisibleSubWindow(int increaseFactor, QMdiAre // Find the index for the current sub-window in the given activation order const int indexToCurrent = subWindows.indexOf(current); - const bool increasing = increaseFactor > 0 ? true : false; + const bool increasing = increaseFactor > 0; // and use that index + increseFactor as a candidate. int index = -1; @@ -2552,7 +2553,7 @@ bool QMdiArea::eventFilter(QObject *object, QEvent *event) if (!area) return QAbstractScrollArea::eventFilter(object, event); - const bool keyPress = (event->type() == QEvent::KeyPress) ? true : false; + const bool keyPress = (event->type() == QEvent::KeyPress); // 1) Ctrl-Tab once -> activate the previously active window. // 2) Ctrl-Tab (Tab, Tab, ...) -> iterate through all windows (activateNextSubWindow()). diff --git a/src/widgets/widgets/qmenu.cpp b/src/widgets/widgets/qmenu.cpp index f3461d26c2..affea4f9a3 100644 --- a/src/widgets/widgets/qmenu.cpp +++ b/src/widgets/widgets/qmenu.cpp @@ -1431,7 +1431,7 @@ void QMenu::initStyleOption(QStyleOptionMenuItem *option, const QAction *action) do not support the signals: aboutToHide (), aboutToShow () and hovered (). It is not possible to display an icon in a native menu on Windows Mobile. - \section1 QMenu on Mac OS X with Qt build against Cocoa + \section1 QMenu on Mac OS X with Qt Build Against Cocoa QMenu can be inserted only once in a menu/menubar. Subsequent insertions will have no effect or will result in a disabled menu item. diff --git a/src/widgets/widgets/qplaintextedit.cpp b/src/widgets/widgets/qplaintextedit.cpp index d33ac5fd7b..b6a21f183a 100644 --- a/src/widgets/widgets/qplaintextedit.cpp +++ b/src/widgets/widgets/qplaintextedit.cpp @@ -281,7 +281,7 @@ void QPlainTextDocumentLayout::documentChanged(int from, int charsRemoved, int c Q_D(QPlainTextDocumentLayout); QTextDocument *doc = document(); int newBlockCount = doc->blockCount(); - int charsChanged = qMax(charsRemoved, charsAdded); + int charsChanged = charsRemoved + charsAdded; QTextBlock changeStartBlock = doc->findBlock(from); QTextBlock changeEndBlock = doc->findBlock(qMax(0, from + charsChanged - 1)); diff --git a/src/widgets/widgets/qwidgettextcontrol.cpp b/src/widgets/widgets/qwidgettextcontrol.cpp index 4c11434fe9..dfec6a14d4 100644 --- a/src/widgets/widgets/qwidgettextcontrol.cpp +++ b/src/widgets/widgets/qwidgettextcontrol.cpp @@ -2188,7 +2188,7 @@ void QWidgetTextControlPrivate::editFocusEvent(QEvent *e) setBlinkingCursorEnabled(false); } - hasEditFocus = e->type() == QEvent::EnterEditFocus ? true : false; + hasEditFocus = e->type() == QEvent::EnterEditFocus; } #endif |