From a4f9cf23444dd76a11d4eb67c4ea65d5c3948894 Mon Sep 17 00:00:00 2001 From: Elvis Angelaccio Date: Sat, 29 Jul 2017 11:28:13 +0200 Subject: Disable window shortcuts if there is a window modal dialog If a window is blocked by a WindowModal dialog, it should not be possible to trigger window shortcuts on that window if it receives a WindowActivate event. This currently happens if the blocked window gets clicked, because the window becomes the active_window and then QApplication sends it a WindowActivate event (this doesn't happen with application modal dialogs). The correctWidgetContext() function calls QApplicationPrivate::tryModalHelper() only if the shortcut context is ApplicationShortcut. This patch makes it call even if the shortcut context is WindowShortcut. Change-Id: Iff87d85bcae603a6a24128e0cedfa9d33b6485fd Reviewed-by: Richard Moe Gustavsen --- src/widgets/kernel/qshortcut.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/widgets') diff --git a/src/widgets/kernel/qshortcut.cpp b/src/widgets/kernel/qshortcut.cpp index f944a7097b..32600d4152 100644 --- a/src/widgets/kernel/qshortcut.cpp +++ b/src/widgets/kernel/qshortcut.cpp @@ -205,7 +205,7 @@ static bool correctWidgetContext(Qt::ShortcutContext context, QWidget *w, QWidge #if defined(DEBUG_QSHORTCUTMAP) qDebug().nospace() << "..true [Pass-through]"; #endif - return true; + return QApplicationPrivate::tryModalHelper(w, nullptr); } #if QT_CONFIG(graphicsview) -- cgit v1.2.3 From 937ded010b09250c6ab9a57917f2e430fb5875f5 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Sat, 28 Oct 2017 19:13:58 +0200 Subject: QListView: make sure to respect grid size during dataChanged() handling When the dataChanged() signal is handled by QIconModeViewBase, the size of the items are recalculated. During this operation the optional grid size is not taken into account which leads to a screwed up layout. This patch adds the missing check similar it is done in doStaticLayout()/doDynamicLayout(). Task-number: QTBUG-45427 Change-Id: Iba7adb44b1510c511a69c289ccb4f168992a6871 Reviewed-by: Richard Moe Gustavsen --- src/widgets/itemviews/qlistview.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'src/widgets') diff --git a/src/widgets/itemviews/qlistview.cpp b/src/widgets/itemviews/qlistview.cpp index 9e959c8e1e..9217fec10e 100644 --- a/src/widgets/itemviews/qlistview.cpp +++ b/src/widgets/itemviews/qlistview.cpp @@ -2874,10 +2874,19 @@ void QIconModeViewBase::scrollContentsBy(int dx, int dy, bool scrollElasticBand) void QIconModeViewBase::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight) { if (column() >= topLeft.column() && column() <= bottomRight.column()) { - QStyleOptionViewItem option = viewOptions(); - int bottom = qMin(items.count(), bottomRight.row() + 1); + const QStyleOptionViewItem option = viewOptions(); + const int bottom = qMin(items.count(), bottomRight.row() + 1); + const bool useItemSize = !dd->grid.isValid(); for (int row = topLeft.row(); row < bottom; ++row) - items[row].resize(itemSize(option, modelIndex(row))); + { + QSize s = itemSize(option, modelIndex(row)); + if (!useItemSize) + { + s.setWidth(qMin(dd->grid.width(), s.width())); + s.setHeight(qMin(dd->grid.height(), s.height())); + } + items[row].resize(s); + } } } -- cgit v1.2.3 From 92c61b11c1704450adfa3a8ac839478c0f3dd19d Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Fri, 27 Oct 2017 15:23:39 +0200 Subject: Windows: Use SM_CXSMICON instead of SM_CXICON for the tray icon size Partially reverts b465fe759695bb7e1de693c3d4d20acfd2c49779. Task-number: QTBUG-63447 Change-Id: Iaf8a54b59a054e33811f65f64322af3aa746885e Reviewed-by: Oliver Wolff --- src/widgets/util/qsystemtrayicon_win.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'src/widgets') diff --git a/src/widgets/util/qsystemtrayicon_win.cpp b/src/widgets/util/qsystemtrayicon_win.cpp index 3f007f24c1..57d46912e0 100644 --- a/src/widgets/util/qsystemtrayicon_win.cpp +++ b/src/widgets/util/qsystemtrayicon_win.cpp @@ -313,9 +313,8 @@ HICON QSystemTrayIconSys::createIcon() const QIcon icon = q->icon(); if (icon.isNull()) return oldIcon; - const QSize requestedSize = QSysInfo::windowsVersion() >= QSysInfo::WV_VISTA - ? QSize(GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON)) - : QSize(GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON)); + // When merging this to 5.10, change at src/plugins/platforms/windows/qwindowssystemtrayicon.cpp:351. + const QSize requestedSize = QSize(GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON)); const QSize size = icon.actualSize(requestedSize); const QPixmap pm = icon.pixmap(size); if (pm.isNull()) -- cgit v1.2.3 From b4f4c384d9ee7cf93cc3db289a7d4275ac10a618 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Sat, 28 Oct 2017 13:20:53 +0200 Subject: QHeaderView: Honor maximumSectionSize property during resizeSections() Resizing a QTreeeView section with double click or resizeColumnToContents() does not respect the maximumSectionSize when the resize mode is Interactive or Fixed. Since the documentation of maximumSectionSize states that it should honor this property for those cases either the documentation or implementation is incorrect. This patch fixes the latter. Task-number: QTBUG-64036 Change-Id: Ic14c8e444d50b9c50a117efed19d0bca7ec1cf82 Reviewed-by: Richard Moe Gustavsen --- src/widgets/itemviews/qheaderview.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/widgets') diff --git a/src/widgets/itemviews/qheaderview.cpp b/src/widgets/itemviews/qheaderview.cpp index 213cc96b03..3af191b06c 100644 --- a/src/widgets/itemviews/qheaderview.cpp +++ b/src/widgets/itemviews/qheaderview.cpp @@ -3364,7 +3364,7 @@ void QHeaderViewPrivate::resizeSections(QHeaderView::ResizeMode globalMode, bool // because it isn't stretch, determine its width and remove that from lengthToStretch int sectionSize = 0; if (resizeMode == QHeaderView::Interactive || resizeMode == QHeaderView::Fixed) { - sectionSize = headerSectionSize(i); + sectionSize = qBound(q->minimumSectionSize(), headerSectionSize(i), q->maximumSectionSize()); } else { // resizeMode == QHeaderView::ResizeToContents int logicalIndex = q->logicalIndex(i); sectionSize = qMax(viewSectionSizeHint(logicalIndex), -- cgit v1.2.3 From 2937ab9e320ea04fdfda8e3a252559d4762e811e Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Tue, 31 Oct 2017 19:47:12 +0100 Subject: QHeaderView: Skip hidden sections on cascading resize When a section is hidden, QHeaderViewPrivate::cascadingResize() does resize a section even it is hidden. This leads to space between the neighbor sections and also some unneeded calculations. Task-number: QTBUG-54601 Change-Id: Ie139417ae2c77ef25e66cf628bfe400185f88ee8 Reviewed-by: Richard Moe Gustavsen --- src/widgets/itemviews/qheaderview.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/widgets') diff --git a/src/widgets/itemviews/qheaderview.cpp b/src/widgets/itemviews/qheaderview.cpp index 3af191b06c..298270a785 100644 --- a/src/widgets/itemviews/qheaderview.cpp +++ b/src/widgets/itemviews/qheaderview.cpp @@ -3539,6 +3539,8 @@ void QHeaderViewPrivate::cascadingResize(int visual, int newSize) // cascade the section size change for (int i = visual + 1; i < sectionCount(); ++i) { + if (isVisualIndexHidden(i)) + continue; if (!sectionIsCascadable(i)) continue; int currentSectionSize = headerSectionSize(i); @@ -3581,6 +3583,8 @@ void QHeaderViewPrivate::cascadingResize(int visual, int newSize) // cascade the section size change if (delta < 0 && newSize < minimumSize) { for (int i = visual - 1; i >= 0; --i) { + if (isVisualIndexHidden(i)) + continue; if (!sectionIsCascadable(i)) continue; int sectionSize = headerSectionSize(i); @@ -3595,6 +3599,8 @@ void QHeaderViewPrivate::cascadingResize(int visual, int newSize) // let the next section get the space from the resized section if (!sectionResized) { for (int i = visual + 1; i < sectionCount(); ++i) { + if (isVisualIndexHidden(i)) + continue; if (!sectionIsCascadable(i)) continue; int currentSectionSize = headerSectionSize(i); -- cgit v1.2.3 From c3aa422df6e3eb4af7bd75c7255586e9e5f79197 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Mon, 6 Nov 2017 15:18:14 +0100 Subject: QWidget: Propagate window file path after create MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Task-number: QTBUG-63340 Change-Id: Ic21964a33ee2910200627fe8a8c8ec2454e2e20c Reviewed-by: Morten Johan Sørvig --- src/widgets/kernel/qwidget.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/widgets') diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index 9b6c3df828..de734b6f51 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -1372,6 +1372,8 @@ void QWidget::create(WId window, bool initializeWindow, bool destroyOldWindow) d->setWindowIconText_helper(d->topData()->iconText); if (isWindow() && !d->topData()->caption.isEmpty()) d->setWindowTitle_helper(d->topData()->caption); + if (isWindow() && !d->topData()->filePath.isEmpty()) + d->setWindowFilePath_helper(d->topData()->filePath); if (windowType() != Qt::Desktop) { d->updateSystemBackground(); -- cgit v1.2.3 From b02bd4bbad9f80154307d06ad95a6f96c30858f0 Mon Sep 17 00:00:00 2001 From: Gabriel de Dietrich Date: Tue, 15 Aug 2017 11:19:32 +0700 Subject: QMenuPrivate: Rearrange member variables This saves 32 bytes per instance on 64-bit macOS, from 888 down to 856 bytes. Change-Id: I2592631aa3566d2eab72bad338aacfe76bee8ef3 Reviewed-by: Thiago Macieira Reviewed-by: Olivier Goffart (Woboq GmbH) --- src/widgets/widgets/qmenu_p.h | 129 +++++++++++++++++++++++++----------------- 1 file changed, 76 insertions(+), 53 deletions(-) (limited to 'src/widgets') diff --git a/src/widgets/widgets/qmenu_p.h b/src/widgets/widgets/qmenu_p.h index 4b7ce05169..8adfc82ef5 100644 --- a/src/widgets/widgets/qmenu_p.h +++ b/src/widgets/widgets/qmenu_p.h @@ -92,18 +92,18 @@ class QMenuSloppyState public: QMenuSloppyState() : m_menu(Q_NULLPTR) + , m_reset_action(Q_NULLPTR) + , m_origin_action(Q_NULLPTR) + , m_parent(Q_NULLPTR) + , m_uni_dir_discarded_count(0) + , m_uni_dir_fail_at_count(0) + , m_timeout(0) + , m_init_guard(false) + , m_first_mouse(true) , m_enabled(false) , m_uni_directional(false) , m_select_other_actions(false) - , m_first_mouse(true) - , m_init_guard(false) , m_use_reset_action(true) - , m_uni_dir_discarded_count(0) - , m_uni_dir_fail_at_count(0) - , m_timeout(0) - , m_reset_action(Q_NULLPTR) - , m_origin_action(Q_NULLPTR) - , m_parent(Q_NULLPTR) { } ~QMenuSloppyState() { reset(); } @@ -253,43 +253,59 @@ public: private: QMenu *m_menu; - bool m_enabled; - bool m_uni_directional; - bool m_select_other_actions; - bool m_first_mouse; - bool m_init_guard; - bool m_discard_state_when_entering_parent; - bool m_dont_start_time_on_leave; - bool m_use_reset_action; - short m_uni_dir_discarded_count; - short m_uni_dir_fail_at_count; - short m_timeout; - QBasicTimer m_time; QAction *m_reset_action; QAction *m_origin_action; QRectF m_action_rect; QPointF m_previous_point; QPointer m_sub_menu; QMenuSloppyState *m_parent; + QBasicTimer m_time; + short m_uni_dir_discarded_count; + short m_uni_dir_fail_at_count; + short m_timeout; + bool m_init_guard; + bool m_first_mouse; + + bool m_enabled : 1; + bool m_uni_directional : 1; + bool m_select_other_actions : 1; + bool m_discard_state_when_entering_parent : 1; + bool m_dont_start_time_on_leave : 1; + bool m_use_reset_action : 1; }; class QMenuPrivate : public QWidgetPrivate { Q_DECLARE_PUBLIC(QMenu) public: - QMenuPrivate() : itemsDirty(0), maxIconWidth(0), tabWidth(0), ncols(0), - collapsibleSeparators(true), toolTipsVisible(false), - activationRecursionGuard(false), delayedPopupGuard(false), - hasReceievedEnter(false), - hasHadMouse(0), aboutToHide(0), motions(0), - currentAction(0), + QMenuPrivate() : + currentAction(nullptr), #ifdef QT_KEYPAD_NAVIGATION - selectAction(0), - cancelAction(0), + selectAction(nullptr), + cancelAction(nullptr), #endif - scroll(0), eventLoop(0), tearoff(0), tornoff(0), tearoffHighlighted(0), - hasCheckableItems(0), doChildEffects(false), platformMenu(0), - scrollUpTearOffItem(nullptr), scrollDownItem(nullptr) + scroll(nullptr), + eventLoop(nullptr), + platformMenu(nullptr), + scrollUpTearOffItem(nullptr), + scrollDownItem(nullptr), + maxIconWidth(0), + tabWidth(0), + motions(0), + activationRecursionGuard(false), + ncols(0), + itemsDirty(false), + hasCheckableItems(false), + collapsibleSeparators(true), + toolTipsVisible(false), + delayedPopupGuard(false), + hasReceievedEnter(false), + hasHadMouse(false), + aboutToHide(false), + tearoff(false), + tornoff(false), + tearoffHighlighted(false), + doChildEffects(false) { } ~QMenuPrivate() @@ -310,8 +326,6 @@ public: int scrollerHeight() const; //item calculations - mutable uint itemsDirty : 1; - mutable uint maxIconWidth, tabWidth; QRect actionRect(QAction *) const; mutable QVector actionRects; @@ -320,22 +334,12 @@ public: void updateActionRects(const QRect &screen) const; QRect popupGeometry() const; QRect popupGeometry(int screen) const; - mutable uint ncols : 4; //4 bits is probably plenty - uint collapsibleSeparators : 1; - uint toolTipsVisible : 1; int getLastVisibleAction() const; - bool activationRecursionGuard; - bool delayedPopupGuard; - bool hasReceievedEnter; - //selection static QMenu *mouseDown; QPoint mousePopupPos; - uint hasHadMouse : 1; - uint aboutToHide : 1; - int motions; - int mousePopupDelay; + QAction *currentAction; #ifdef QT_KEYPAD_NAVIGATION QAction *selectAction; @@ -365,8 +369,8 @@ public: } QMenu *parent; - QBasicTimer timer; QAction *action; + QBasicTimer timer; } delayState; enum SelectionReason { SelectedFromKeyboard, @@ -383,11 +387,12 @@ public: struct QMenuScroller { enum ScrollLocation { ScrollStay, ScrollBottom, ScrollTop, ScrollCenter }; enum ScrollDirection { ScrollNone=0, ScrollUp=0x01, ScrollDown=0x02 }; - uint scrollFlags : 2, scrollDirection : 2; int scrollOffset; QBasicTimer scrollTimer; + quint8 scrollFlags; + quint8 scrollDirection; - QMenuScroller() : scrollFlags(ScrollNone), scrollDirection(ScrollNone), scrollOffset(0) { } + QMenuScroller() : scrollOffset(0), scrollFlags(ScrollNone), scrollDirection(ScrollNone) { } ~QMenuScroller() { } } *scroll; void scrollMenu(QMenuScroller::ScrollLocation location, bool active=false); @@ -421,11 +426,8 @@ public: inline int indexOf(QAction *act) const { return q_func()->actions().indexOf(act); } //tear off support - uint tearoff : 1, tornoff : 1, tearoffHighlighted : 1; QPointer tornPopup; - mutable bool hasCheckableItems; - QMenuSloppyState sloppyState; //default action @@ -450,9 +452,6 @@ public: void adjustMenuScreen(const QPoint &p); void updateLayoutDirection(); - //menu fading/scrolling effects - bool doChildEffects; - QPointer platformMenu; QPointer actionAboutToTrigger; @@ -477,6 +476,30 @@ public: void drawScroller(QPainter *painter, ScrollerTearOffItem::Type type, const QRect &rect); void drawTearOff(QPainter *painter, const QRect &rect); QRect rect() const; + + mutable uint maxIconWidth, tabWidth; + int motions; + int mousePopupDelay; + + bool activationRecursionGuard; + + mutable quint8 ncols; // "255cols ought to be enough for anybody." + + mutable bool itemsDirty : 1; + mutable bool hasCheckableItems : 1; + bool collapsibleSeparators : 1; + bool toolTipsVisible : 1; + bool delayedPopupGuard : 1; + bool hasReceievedEnter : 1; + // Selection + bool hasHadMouse : 1; + bool aboutToHide : 1; + // Tear-off menus + bool tearoff : 1; + bool tornoff : 1; + bool tearoffHighlighted : 1; + //menu fading/scrolling effects + bool doChildEffects : 1; }; QT_END_NAMESPACE -- cgit v1.2.3 From 237b1c1d689fabf1680a8cf3d9226da5f712302d Mon Sep 17 00:00:00 2001 From: Gabriel de Dietrich Date: Sat, 26 Aug 2017 11:26:45 +0700 Subject: QMenuPrivate: Use in-class initializers where possible Change-Id: I5347cb41443baf96e28bd399c84983a801b10fcd Reviewed-by: Thiago Macieira Reviewed-by: Olivier Goffart (Woboq GmbH) --- src/widgets/widgets/qmenu_p.h | 87 +++++++++++++++---------------------------- 1 file changed, 31 insertions(+), 56 deletions(-) (limited to 'src/widgets') diff --git a/src/widgets/widgets/qmenu_p.h b/src/widgets/widgets/qmenu_p.h index 8adfc82ef5..64d22087e3 100644 --- a/src/widgets/widgets/qmenu_p.h +++ b/src/widgets/widgets/qmenu_p.h @@ -91,16 +91,7 @@ class QMenuSloppyState Q_DISABLE_COPY(QMenuSloppyState) public: QMenuSloppyState() - : m_menu(Q_NULLPTR) - , m_reset_action(Q_NULLPTR) - , m_origin_action(Q_NULLPTR) - , m_parent(Q_NULLPTR) - , m_uni_dir_discarded_count(0) - , m_uni_dir_fail_at_count(0) - , m_timeout(0) - , m_init_guard(false) - , m_first_mouse(true) - , m_enabled(false) + : m_enabled(false) , m_uni_directional(false) , m_select_other_actions(false) , m_use_reset_action(true) @@ -252,19 +243,19 @@ public: QMenu *subMenu() const { return m_sub_menu; } private: - QMenu *m_menu; - QAction *m_reset_action; - QAction *m_origin_action; + QMenu *m_menu = nullptr; + QAction *m_reset_action = nullptr; + QAction *m_origin_action = nullptr; QRectF m_action_rect; QPointF m_previous_point; QPointer m_sub_menu; - QMenuSloppyState *m_parent; + QMenuSloppyState *m_parent = nullptr; QBasicTimer m_time; - short m_uni_dir_discarded_count; - short m_uni_dir_fail_at_count; - short m_timeout; - bool m_init_guard; - bool m_first_mouse; + short m_uni_dir_discarded_count = 0; + short m_uni_dir_fail_at_count = 0; + short m_timeout = 0; + bool m_init_guard = false; + bool m_first_mouse = true; bool m_enabled : 1; bool m_uni_directional : 1; @@ -279,21 +270,6 @@ class QMenuPrivate : public QWidgetPrivate Q_DECLARE_PUBLIC(QMenu) public: QMenuPrivate() : - currentAction(nullptr), -#ifdef QT_KEYPAD_NAVIGATION - selectAction(nullptr), - cancelAction(nullptr), -#endif - scroll(nullptr), - eventLoop(nullptr), - platformMenu(nullptr), - scrollUpTearOffItem(nullptr), - scrollDownItem(nullptr), - maxIconWidth(0), - tabWidth(0), - motions(0), - activationRecursionGuard(false), - ncols(0), itemsDirty(false), hasCheckableItems(false), collapsibleSeparators(true), @@ -340,15 +316,13 @@ public: static QMenu *mouseDown; QPoint mousePopupPos; - QAction *currentAction; + QAction *currentAction = nullptr; #ifdef QT_KEYPAD_NAVIGATION - QAction *selectAction; - QAction *cancelAction; + QAction *selectAction = nullptr; + QAction *cancelAction = nullptr; #endif struct DelayState { DelayState() - : parent(0) - , action(0) { } void initialize(QMenu *parent) { @@ -368,8 +342,8 @@ public: timer.stop(); } - QMenu *parent; - QAction *action; + QMenu *parent = nullptr; + QAction *action = nullptr; QBasicTimer timer; } delayState; enum SelectionReason { @@ -387,20 +361,20 @@ public: struct QMenuScroller { enum ScrollLocation { ScrollStay, ScrollBottom, ScrollTop, ScrollCenter }; enum ScrollDirection { ScrollNone=0, ScrollUp=0x01, ScrollDown=0x02 }; - int scrollOffset; + int scrollOffset = 0; QBasicTimer scrollTimer; - quint8 scrollFlags; - quint8 scrollDirection; + quint8 scrollFlags = ScrollNone; + quint8 scrollDirection = ScrollNone; - QMenuScroller() : scrollOffset(0), scrollFlags(ScrollNone), scrollDirection(ScrollNone) { } + QMenuScroller() { } ~QMenuScroller() { } - } *scroll; + } *scroll = nullptr; void scrollMenu(QMenuScroller::ScrollLocation location, bool active=false); void scrollMenu(QMenuScroller::ScrollDirection direction, bool page=false, bool active=false); void scrollMenu(QAction *action, QMenuScroller::ScrollLocation location, bool active=false); //synchronous operation (ie exec()) - QEventLoop *eventLoop; + QEventLoop *eventLoop = nullptr; QPointer syncAction; //search buffer @@ -433,8 +407,8 @@ public: //default action QPointer defaultAction; - QAction *menuAction; - QAction *defaultMenuAction; + QAction *menuAction = nullptr; + QAction *defaultMenuAction = nullptr; void setOverrideMenuAction(QAction *); void _q_overrideMenuActionDestroyed(); @@ -470,20 +444,21 @@ public: QMenuPrivate *menuPrivate; Type scrollType; }; - ScrollerTearOffItem *scrollUpTearOffItem; - ScrollerTearOffItem *scrollDownItem; + ScrollerTearOffItem *scrollUpTearOffItem = nullptr; + ScrollerTearOffItem *scrollDownItem = nullptr; void drawScroller(QPainter *painter, ScrollerTearOffItem::Type type, const QRect &rect); void drawTearOff(QPainter *painter, const QRect &rect); QRect rect() const; - mutable uint maxIconWidth, tabWidth; - int motions; - int mousePopupDelay; + mutable uint maxIconWidth = 0; + mutable uint tabWidth = 0; + int motions = 0; + int mousePopupDelay = 0; - bool activationRecursionGuard; + bool activationRecursionGuard = false; - mutable quint8 ncols; // "255cols ought to be enough for anybody." + mutable quint8 ncols = 0; // "255cols ought to be enough for anybody." mutable bool itemsDirty : 1; mutable bool hasCheckableItems : 1; -- cgit v1.2.3 From 7986e1e2f0c88ea305dd8a842884908ed4724fd7 Mon Sep 17 00:00:00 2001 From: Gabriel de Dietrich Date: Fri, 20 Oct 2017 18:12:17 +0700 Subject: QMenuBar: Update title on change MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When one of the menubar actions changed, we would omit to update several properties on the platform menu, most notably its title. Manual tested with BigMenuCreator, where the sequence menu->addAction(action); // A-operation action->setMenu(submenu); // S-operation would result in an "Untitled" menubar item on macOS, and this regardless of when the submenu is populated. Change-Id: I43989f36f6bf3f0b7056310ac986c06f8e02f128 Reviewed-by: Dmitry Shachnev Reviewed-by: Erik Verbruggen Reviewed-by: Morten Johan Sørvig --- src/widgets/widgets/qmenubar.cpp | 54 +++++++++++++++++++++++----------------- src/widgets/widgets/qmenubar_p.h | 4 ++- 2 files changed, 34 insertions(+), 24 deletions(-) (limited to 'src/widgets') diff --git a/src/widgets/widgets/qmenubar.cpp b/src/widgets/widgets/qmenubar.cpp index 41b6bf49f8..6dfbb7c8a1 100644 --- a/src/widgets/widgets/qmenubar.cpp +++ b/src/widgets/widgets/qmenubar.cpp @@ -1187,7 +1187,7 @@ void QMenuBar::leaveEvent(QEvent *) d->setCurrentAction(0); } -QPlatformMenu *QMenuBarPrivate::getPlatformMenu(QAction *action) +QPlatformMenu *QMenuBarPrivate::getPlatformMenu(const QAction *action) { if (!action || !action->menu()) return 0; @@ -1202,6 +1202,29 @@ QPlatformMenu *QMenuBarPrivate::getPlatformMenu(QAction *action) return platformMenu; } +QPlatformMenu *QMenuBarPrivate::findInsertionPlatformMenu(const QAction *action) +{ + Q_Q(QMenuBar); + QPlatformMenu *beforeMenu = nullptr; + for (int beforeIndex = indexOf(const_cast(action)) + 1; + !beforeMenu && (beforeIndex < q->actions().size()); + ++beforeIndex) { + beforeMenu = getPlatformMenu(q->actions().at(beforeIndex)); + } + + return beforeMenu; +} + +void QMenuBarPrivate::copyActionToPlatformMenu(const QAction *action, QPlatformMenu *menu) +{ + const auto tag = reinterpret_cast(action); + if (menu->tag() != tag) + menu->setTag(tag); + menu->setText(action->text()); + menu->setVisible(action->isVisible()); + menu->setEnabled(action->isEnabled()); +} + /*! \reimp */ @@ -1218,16 +1241,9 @@ void QMenuBar::actionEvent(QActionEvent *e) if (e->type() == QEvent::ActionAdded) { QPlatformMenu *menu = d->getPlatformMenu(e->action()); if (menu) { - QPlatformMenu* beforeMenu = NULL; - for (int beforeIndex = d->indexOf(e->action()) + 1; - !beforeMenu && (beforeIndex < actions().size()); - ++beforeIndex) - { - beforeMenu = d->getPlatformMenu(actions().at(beforeIndex)); - } + d->copyActionToPlatformMenu(e->action(), menu); - menu->setTag(reinterpret_cast(e->action())); - menu->setText(e->action()->text()); + QPlatformMenu *beforeMenu = d->findInsertionPlatformMenu(e->action()); d->platformMenuBar->insertMenu(menu, beforeMenu); } } else if (e->type() == QEvent::ActionRemoved) { @@ -1235,7 +1251,7 @@ void QMenuBar::actionEvent(QActionEvent *e) if (menu) d->platformMenuBar->removeMenu(menu); } else if (e->type() == QEvent::ActionChanged) { - QPlatformMenu* cur = d->platformMenuBar->menuForTag(reinterpret_cast(e->action())); + QPlatformMenu *cur = d->platformMenuBar->menuForTag(reinterpret_cast(e->action())); QPlatformMenu *menu = d->getPlatformMenu(e->action()); // the menu associated with the action can change, need to @@ -1244,21 +1260,13 @@ void QMenuBar::actionEvent(QActionEvent *e) if (cur) d->platformMenuBar->removeMenu(cur); if (menu) { - menu->setTag(reinterpret_cast(e->action())); - - QPlatformMenu* beforeMenu = NULL; - for (int beforeIndex = d->indexOf(e->action()) + 1; - !beforeMenu && (beforeIndex < actions().size()); - ++beforeIndex) - { - beforeMenu = d->getPlatformMenu(actions().at(beforeIndex)); - } + d->copyActionToPlatformMenu(e->action(), menu); + + QPlatformMenu *beforeMenu = d->findInsertionPlatformMenu(e->action()); d->platformMenuBar->insertMenu(menu, beforeMenu); } } else if (menu) { - menu->setText(e->action()->text()); - menu->setVisible(e->action()->isVisible()); - menu->setEnabled(e->action()->isEnabled()); + d->copyActionToPlatformMenu(e->action(), menu); d->platformMenuBar->syncMenu(menu); } } diff --git a/src/widgets/widgets/qmenubar_p.h b/src/widgets/widgets/qmenubar_p.h index 01d8793a3a..c276a4512d 100644 --- a/src/widgets/widgets/qmenubar_p.h +++ b/src/widgets/widgets/qmenubar_p.h @@ -132,7 +132,9 @@ public: QBasicTimer autoReleaseTimer; QPlatformMenuBar *platformMenuBar; - QPlatformMenu *getPlatformMenu(QAction *action); + QPlatformMenu *getPlatformMenu(const QAction *action); + QPlatformMenu *findInsertionPlatformMenu(const QAction *action); + void copyActionToPlatformMenu(const QAction *e, QPlatformMenu *menu); inline int indexOf(QAction *act) const { return q_func()->actions().indexOf(act); } }; -- cgit v1.2.3 From 5d6878f234d1d8697bba43cb5140094dee722a86 Mon Sep 17 00:00:00 2001 From: Gabriel de Dietrich Date: Tue, 24 Oct 2017 14:53:31 +0700 Subject: QMainWindow: Clear menubar parent when new one is set In QMainWindow::setMenuBar(), we hide and schedule the current menubar, if any, to be deleted later. However, it remains installed as its whole ancestry's event filter, which could conflict with the newly assigned menubar until the old menubar is destroyed. In our case, we have noticed issues with the Cocoa QPA plugin. We force uninstalling the old menubar as event filter by setting its parent to null, pending its deletion shortly after. This fixes BigMenuCreator's empty menubar when calling it with only the "--new-menubar" option. It also fixes QTBUG-34160 example which was not behaving as well as it should. Task-number: QTBUG-34160 Change-Id: Ifefb72affad01e7b7371005442074afd6a39a5b8 Reviewed-by: Dmitry Shachnev Reviewed-by: Shawn Rutledge --- src/widgets/widgets/qmainwindow.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/widgets') diff --git a/src/widgets/widgets/qmainwindow.cpp b/src/widgets/widgets/qmainwindow.cpp index 5c6f983149..ced7ec38ea 100644 --- a/src/widgets/widgets/qmainwindow.cpp +++ b/src/widgets/widgets/qmainwindow.cpp @@ -574,6 +574,7 @@ void QMainWindow::setMenuBar(QMenuBar *menuBar) menuBar->setCornerWidget(cornerWidget, Qt::TopRightCorner); } oldMenuBar->hide(); + oldMenuBar->setParent(nullptr); oldMenuBar->deleteLater(); } topLayout->setMenuBar(menuBar); -- cgit v1.2.3