diff options
Diffstat (limited to 'src/widgets/widgets')
-rw-r--r-- | src/widgets/widgets/qcombobox.cpp | 5 | ||||
-rw-r--r-- | src/widgets/widgets/qcombobox_p.h | 2 | ||||
-rw-r--r-- | src/widgets/widgets/qdialogbuttonbox.cpp | 2 | ||||
-rw-r--r-- | src/widgets/widgets/qdialogbuttonbox.h | 6 | ||||
-rw-r--r-- | src/widgets/widgets/qdockarealayout.cpp | 129 | ||||
-rw-r--r-- | src/widgets/widgets/qdockarealayout_p.h | 5 | ||||
-rw-r--r-- | src/widgets/widgets/qdockwidget.cpp | 14 | ||||
-rw-r--r-- | src/widgets/widgets/qlineedit.cpp | 21 | ||||
-rw-r--r-- | src/widgets/widgets/qmainwindow.cpp | 257 | ||||
-rw-r--r-- | src/widgets/widgets/qmainwindowlayout.cpp | 701 | ||||
-rw-r--r-- | src/widgets/widgets/qmainwindowlayout_p.h | 313 | ||||
-rw-r--r-- | src/widgets/widgets/qmdiarea.cpp | 3 | ||||
-rw-r--r-- | src/widgets/widgets/qmdisubwindow.cpp | 58 | ||||
-rw-r--r-- | src/widgets/widgets/qmenu.cpp | 12 | ||||
-rw-r--r-- | src/widgets/widgets/qmenu.h | 8 | ||||
-rw-r--r-- | src/widgets/widgets/qprogressbar.cpp | 2 | ||||
-rw-r--r-- | src/widgets/widgets/qpushbutton.cpp | 4 | ||||
-rw-r--r-- | src/widgets/widgets/qtabbar_p.h | 2 | ||||
-rw-r--r-- | src/widgets/widgets/qtoolbar.h | 4 | ||||
-rw-r--r-- | src/widgets/widgets/qwidgettextcontrol.cpp | 5 |
20 files changed, 719 insertions, 834 deletions
diff --git a/src/widgets/widgets/qcombobox.cpp b/src/widgets/widgets/qcombobox.cpp index 2376a18e43..0dde839629 100644 --- a/src/widgets/widgets/qcombobox.cpp +++ b/src/widgets/widgets/qcombobox.cpp @@ -67,11 +67,6 @@ #include <private/qabstractscrollarea_p.h> #include <private/qlineedit_p.h> #include <qdebug.h> -#if 0 /* Used to be included in Qt4 for Q_WS_MAC */ && !defined(QT_NO_EFFECTS) && QT_CONFIG(style_mac) -#include <private/qcore_mac_p.h> -#include <private/qmacstyle_mac_p.h> -#include <private/qt_cocoa_helpers_mac_p.h> -#endif #ifndef QT_NO_EFFECTS # include <private/qeffects_p.h> #endif diff --git a/src/widgets/widgets/qcombobox_p.h b/src/widgets/widgets/qcombobox_p.h index 6c36359f81..2340f06954 100644 --- a/src/widgets/widgets/qcombobox_p.h +++ b/src/widgets/widgets/qcombobox_p.h @@ -212,7 +212,7 @@ private: bool fast; }; -class Q_AUTOTEST_EXPORT QComboBoxPrivateContainer : public QFrame +class Q_WIDGETS_EXPORT QComboBoxPrivateContainer : public QFrame { Q_OBJECT diff --git a/src/widgets/widgets/qdialogbuttonbox.cpp b/src/widgets/widgets/qdialogbuttonbox.cpp index a3e55114bb..ad16acb96c 100644 --- a/src/widgets/widgets/qdialogbuttonbox.cpp +++ b/src/widgets/widgets/qdialogbuttonbox.cpp @@ -577,6 +577,8 @@ QDialogButtonBox::~QDialogButtonBox() \value MacLayout Use a policy appropriate for applications on \macos. \value KdeLayout Use a policy appropriate for applications on KDE. \value GnomeLayout Use a policy appropriate for applications on GNOME. + \value AndroidLayout Use a policy appropriate for applications on Android. + This enum value was added in Qt 5.10. 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/widgets/widgets/qdialogbuttonbox.h b/src/widgets/widgets/qdialogbuttonbox.h index af9e705234..02d14dee7c 100644 --- a/src/widgets/widgets/qdialogbuttonbox.h +++ b/src/widgets/widgets/qdialogbuttonbox.h @@ -108,11 +108,13 @@ public: Q_FLAG(StandardButtons) enum ButtonLayout { - // keep this in sync with QMessageBox::ButtonLayout and QPlatformDialogHelper::ButtonLayout + // keep this in sync with QPlatformDialogHelper::ButtonLayout WinLayout, MacLayout, KdeLayout, - GnomeLayout + GnomeLayout, + // MacModelessLayout, + AndroidLayout = GnomeLayout + 2 // ### Qt 6: reorder }; QDialogButtonBox(QWidget *parent = Q_NULLPTR); diff --git a/src/widgets/widgets/qdockarealayout.cpp b/src/widgets/widgets/qdockarealayout.cpp index 8140fa6def..60f6f6d26d 100644 --- a/src/widgets/widgets/qdockarealayout.cpp +++ b/src/widgets/widgets/qdockarealayout.cpp @@ -1044,33 +1044,6 @@ QLayoutItem *QDockAreaLayoutInfo::plug(const QList<int> &path) Q_ASSERT(item.widgetItem != 0); Q_ASSERT(item.flags & QDockAreaLayoutItem::GapItem); item.flags &= ~QDockAreaLayoutItem::GapItem; - - QRect result; - -#ifndef QT_NO_TABBAR - if (tabbed) { - } else -#endif - { - int prev = this->prev(index); - int next = this->next(index); - - if (prev != -1 && !(item_list.at(prev).flags & QDockAreaLayoutItem::GapItem)) { - item.pos += *sep; - item.size -= *sep; - } - if (next != -1 && !(item_list.at(next).flags & QDockAreaLayoutItem::GapItem)) - item.size -= *sep; - - QPoint pos; - rpick(o, pos) = item.pos; - rperp(o, pos) = perp(o, rect.topLeft()); - QSize s; - rpick(o, s) = item.size; - rperp(o, s) = perp(o, rect.size()); - result = QRect(pos, s); - } - return item.widgetItem; } @@ -1323,29 +1296,46 @@ QDockAreaLayoutInfo *QDockAreaLayoutInfo::info(const QList<int> &path) return item_list[index].subinfo->info(path.mid(1)); } -QRect QDockAreaLayoutInfo::itemRect(int index) const +QRect QDockAreaLayoutInfo::itemRect(int index, bool isGap) const { const QDockAreaLayoutItem &item = item_list.at(index); if (item.skip()) return QRect(); + if (isGap && !(item.flags & QDockAreaLayoutItem::GapItem)) + return QRect(); + QRect result; #ifndef QT_NO_TABBAR if (tabbed) { - if (tabId(item) == currentTabId()) + if (isGap || tabId(item) == currentTabId()) result = tabContentRect(); } else #endif { - QPoint pos; - rpick(o, pos) = item.pos; - rperp(o, pos) = perp(o, rect.topLeft()); + int pos = item.pos; + int size = item.size; + + if (isGap) { + int prev = this->prev(index); + int next = this->next(index); + if (prev != -1 && !(item_list.at(prev).flags & QDockAreaLayoutItem::GapItem)) { + pos += *sep; + size -= *sep; + } + if (next != -1 && !(item_list.at(next).flags & QDockAreaLayoutItem::GapItem)) + size -= *sep; + } + + QPoint p; + rpick(o, p) = pos; + rperp(o, p) = perp(o, rect.topLeft()); QSize s; - rpick(o, s) = item.size; + rpick(o, s) = size; rperp(o, s) = perp(o, rect.size()); - result = QRect(pos, s); + result = QRect(p, s); } return result; @@ -2428,20 +2418,21 @@ QList<int> QDockAreaLayout::indexOf(QWidget *dockWidget) const return QList<int>(); } -QList<int> QDockAreaLayout::gapIndex(const QPoint &pos) const +QList<int> QDockAreaLayout::gapIndex(const QPoint &pos, bool disallowTabs) const { QMainWindow::DockOptions opts = mainWindow->dockOptions(); bool nestingEnabled = opts & QMainWindow::AllowNestedDocks; QDockAreaLayoutInfo::TabMode tabMode = QDockAreaLayoutInfo::NoTabs; #ifndef QT_NO_TABBAR - if (opts & QMainWindow::AllowTabbedDocks - || opts & QMainWindow::VerticalTabs) - tabMode = QDockAreaLayoutInfo::AllowTabs; - if (opts & QMainWindow::ForceTabbedDocks) - tabMode = QDockAreaLayoutInfo::ForceTabs; + if (!disallowTabs) { + if (opts & QMainWindow::AllowTabbedDocks || opts & QMainWindow::VerticalTabs) + tabMode = QDockAreaLayoutInfo::AllowTabs; + if (opts & QMainWindow::ForceTabbedDocks) + tabMode = QDockAreaLayoutInfo::ForceTabs; - if (tabMode == QDockAreaLayoutInfo::ForceTabs) - nestingEnabled = false; + if (tabMode == QDockAreaLayoutInfo::ForceTabs) + nestingEnabled = false; + } #endif @@ -3313,6 +3304,19 @@ int QDockAreaLayout::separatorMove(const QList<int> &separator, const QPoint &or return delta; } +int QDockAreaLayoutInfo::separatorMove(const QList<int> &separator, const QPoint &origin, + const QPoint &dest) +{ + int delta = 0; + int index = separator.last(); + QDockAreaLayoutInfo *info = this->info(separator); + delta = pick(info->o, dest - origin); + if (delta != 0) + delta = info->separatorMove(index, delta); + info->apply(false); + return delta; +} + #ifndef QT_NO_TABBAR // Sets the correct positions for the separator widgets // Allocates new sepearator widgets with getSeparatorWidget @@ -3422,47 +3426,10 @@ QRect QDockAreaLayout::gapRect(const QList<int> &path) const const QDockAreaLayoutInfo *info = this->info(path); if (info == 0) return QRect(); - const QList<QDockAreaLayoutItem> &item_list = info->item_list; - Qt::Orientation o = info->o; int index = path.last(); - if (index < 0 || index >= item_list.count()) - return QRect(); - const QDockAreaLayoutItem &item = item_list.at(index); - if (!(item.flags & QDockAreaLayoutItem::GapItem)) + if (index < 0 || index >= info->item_list.count()) return QRect(); - - QRect result; - -#ifndef QT_NO_TABBAR - if (info->tabbed) { - result = info->tabContentRect(); - } else -#endif - { - int pos = item.pos; - int size = item.size; - - int prev = info->prev(index); - int next = info->next(index); - - if (prev != -1 && !(item_list.at(prev).flags & QDockAreaLayoutItem::GapItem)) { - pos += sep; - size -= sep; - } - if (next != -1 && !(item_list.at(next).flags & QDockAreaLayoutItem::GapItem)) - size -= sep; - - QPoint p; - rpick(o, p) = pos; - rperp(o, p) = perp(o, info->rect.topLeft()); - QSize s; - rpick(o, s) = size; - rperp(o, s) = perp(o, info->rect.size()); - - result = QRect(p, s); - } - - return result; + return info->itemRect(index, true); } void QDockAreaLayout::keepSize(QDockWidget *w) diff --git a/src/widgets/widgets/qdockarealayout_p.h b/src/widgets/widgets/qdockarealayout_p.h index 21787283f4..e4cdc9f296 100644 --- a/src/widgets/widgets/qdockarealayout_p.h +++ b/src/widgets/widgets/qdockarealayout_p.h @@ -160,7 +160,7 @@ public: void fitItems(); bool expansive(Qt::Orientation o) const; int changeSize(int index, int size, bool below); - QRect itemRect(int index) const; + QRect itemRect(int index, bool isGap = false) const; QRect itemRect(const QList<int> &path) const; QRect separatorRect(int index) const; QRect separatorRect(const QList<int> &path) const; @@ -182,6 +182,7 @@ public: const QPoint &mouse) const; QRegion separatorRegion() const; int separatorMove(int index, int delta); + int separatorMove(const QList<int> &separator, const QPoint &origin, const QPoint &dest); QLayoutItem *itemAt(int *x, int index) const; QLayoutItem *takeAt(int *x, int index); @@ -248,7 +249,7 @@ public: QList<int> indexOfPlaceHolder(const QString &objectName) const; QList<int> indexOf(QWidget *dockWidget) const; - QList<int> gapIndex(const QPoint &pos) const; + QList<int> gapIndex(const QPoint &pos, bool disallowTabs) const; QList<int> findSeparator(const QPoint &pos) const; QDockAreaLayoutItem &item(const QList<int> &path); diff --git a/src/widgets/widgets/qdockwidget.cpp b/src/widgets/widgets/qdockwidget.cpp index 6d9731e962..15f79638c8 100644 --- a/src/widgets/widgets/qdockwidget.cpp +++ b/src/widgets/widgets/qdockwidget.cpp @@ -57,11 +57,6 @@ #include "qdockwidget_p.h" #include "qmainwindowlayout_p.h" -#if 0 // Used to be included in Qt4 for Q_WS_MAC -#include <private/qapplication_p.h> -#include <private/qt_mac_p.h> -#include <private/qmacstyle_mac_p.h> -#endif QT_BEGIN_NAMESPACE @@ -218,10 +213,9 @@ QDockWidgetLayout::~QDockWidgetLayout() bool QDockWidgetLayout::nativeWindowDeco() const { bool floating = parentWidget()->isWindow(); - if (!floating) { - if (auto groupWindow = qobject_cast<const QDockWidgetGroupWindow*>(parentWidget()->parentWidget())) - return groupWindow->hasNativeDecos(); - } + if (auto groupWindow = + qobject_cast<const QDockWidgetGroupWindow *>(parentWidget()->parentWidget())) + floating = floating || groupWindow->tabLayoutInfo(); return nativeWindowDeco(floating); } @@ -1443,7 +1437,7 @@ void QDockWidget::paintEvent(QPaintEvent *event) } // Title must be painted after the frame, since the areas overlap, and - // the title may wish to extend out to all sides (eg. XP style) + // the title may wish to extend out to all sides (eg. Vista style) QStyleOptionDockWidget titleOpt; initStyleOption(&titleOpt); p.drawControl(QStyle::CE_DockWidgetTitle, titleOpt); diff --git a/src/widgets/widgets/qlineedit.cpp b/src/widgets/widgets/qlineedit.cpp index 27dd186f04..b7f19a3bcf 100644 --- a/src/widgets/widgets/qlineedit.cpp +++ b/src/widgets/widgets/qlineedit.cpp @@ -76,7 +76,10 @@ #include "private/qapplication_p.h" #include "private/qshortcutmap_p.h" #include "qkeysequence.h" -#define ACCEL_KEY(k) (!qApp->d_func()->shortcutMap.hasShortcutForKeySequence(k) ? \ +#define ACCEL_KEY(k) ((qApp->testAttribute(Qt::AA_DontShowIconsInMenus) \ + ? false \ + : qApp->styleHints()->showShortcutsInContextMenus()) \ + && !qApp->d_func()->shortcutMap.hasShortcutForKeySequence(k) ? \ QLatin1Char('\t') + QKeySequence(k).toString(QKeySequence::NativeText) : QString()) #else #define ACCEL_KEY(k) QString() @@ -89,10 +92,6 @@ QT_BEGIN_NAMESPACE -#if 0 // Used to be included in Qt4 for Q_WS_MAC -extern void qt_mac_secure_keyboard(bool); //qapplication_mac.cpp -#endif - /*! Initialize \a option with the values from this QLineEdit. This method is useful for subclasses when they need a QStyleOptionFrame, but don't want @@ -582,10 +581,6 @@ void QLineEdit::setEchoMode(EchoMode mode) setInputMethodHints(imHints); d->control->setEchoMode(mode); update(); -#if 0 // Used to be included in Qt4 for Q_WS_MAC - if (hasFocus()) - qt_mac_secure_keyboard(mode == Password || mode == NoEcho); -#endif } @@ -1821,10 +1816,6 @@ void QLineEdit::focusInEvent(QFocusEvent *e) if((!hasSelectedText() && d->control->preeditAreaText().isEmpty()) || style()->styleHint(QStyle::SH_BlinkCursorWhenTextSelected, &opt, this)) d->setCursorVisible(true); -#if 0 // Used to be included in Qt4 for Q_WS_MAC - if (d->control->echoMode() == Password || d->control->echoMode() == NoEcho) - qt_mac_secure_keyboard(true); -#endif #ifdef QT_KEYPAD_NAVIGATION d->control->setCancelText(d->control->text()); } @@ -1869,10 +1860,6 @@ void QLineEdit::focusOutEvent(QFocusEvent *e) if (hasAcceptableInput() || d->control->fixup()) emit editingFinished(); } -#if 0 // Used to be included in Qt4 for Q_WS_MAC - if (d->control->echoMode() == Password || d->control->echoMode() == NoEcho) - qt_mac_secure_keyboard(false); -#endif #ifdef QT_KEYPAD_NAVIGATION d->control->setCancelText(QString()); #endif diff --git a/src/widgets/widgets/qmainwindow.cpp b/src/widgets/widgets/qmainwindow.cpp index c9349ac72d..e47efb50b3 100644 --- a/src/widgets/widgets/qmainwindow.cpp +++ b/src/widgets/widgets/qmainwindow.cpp @@ -61,13 +61,6 @@ #ifdef Q_OS_OSX #include <qpa/qplatformnativeinterface.h> #endif -#if 0 // Used to be included in Qt4 for Q_WS_MAC -#include <private/qt_mac_p.h> -#include <private/qt_cocoa_helpers_mac_p.h> -QT_BEGIN_NAMESPACE -extern OSWindowRef qt_mac_window_for(const QWidget *); // qwidget_mac.cpp -QT_END_NAMESPACE -#endif QT_BEGIN_NAMESPACE @@ -80,13 +73,6 @@ public: #ifdef Q_OS_OSX , useUnifiedToolBar(false) #endif -#if 0 // Used to be included in Qt4 for Q_WS_MAC - , useHIToolBar(false) - , activateUnifiedToolbarAfterFullScreen(false) -#endif -#if !defined(QT_NO_DOCKWIDGET) && !defined(QT_NO_CURSOR) - , hasOldCursor(false) , cursorAdjusted(false) -#endif { } QMainWindowLayout *layout; QSize iconSize; @@ -95,22 +81,7 @@ public: #ifdef Q_OS_OSX bool useUnifiedToolBar; #endif -#if 0 // Used to be included in Qt4 for Q_WS_MAC - bool useHIToolBar; - bool activateUnifiedToolbarAfterFullScreen; -#endif void init(); - QList<int> hoverSeparator; - QPoint hoverPos; - -#if !defined(QT_NO_DOCKWIDGET) && !defined(QT_NO_CURSOR) - QCursor separatorCursor(const QList<int> &path) const; - void adjustCursor(const QPoint &pos); - QCursor oldCursor; - QCursor adjustedCursor; - uint hasOldCursor : 1; - uint cursorAdjusted : 1; -#endif static inline QMainWindowLayout *mainWindowLayout(const QMainWindow *mainWindow) { @@ -805,11 +776,7 @@ void QMainWindow::addToolBar(Qt::ToolBarArea area, QToolBar *toolbar) #endif } - if (!d->layout->usesHIToolBar(toolbar)) { - d->layout->removeWidget(toolbar); - } else { - d->layout->removeToolBar(toolbar); - } + d->layout->removeToolBar(toolbar); toolbar->d_func()->_q_updateIconSize(d->iconSize); toolbar->d_func()->_q_updateToolButtonStyle(d->toolButtonStyle); @@ -1111,21 +1078,6 @@ void QMainWindow::addDockWidget(Qt::DockWidgetArea area, QDockWidget *dockwidget } d_func()->layout->removeWidget(dockwidget); // in case it was already in here addDockWidget(area, dockwidget, orientation); - -#if 0 // Used to be included in Qt4 for Q_WS_MAC //drawer support - QMacAutoReleasePool pool; - extern bool qt_mac_is_macdrawer(const QWidget *); //qwidget_mac.cpp - if (qt_mac_is_macdrawer(dockwidget)) { - extern bool qt_mac_set_drawer_preferred_edge(QWidget *, Qt::DockWidgetArea); //qwidget_mac.cpp - window()->createWinId(); - dockwidget->window()->createWinId(); - qt_mac_set_drawer_preferred_edge(dockwidget, area); - if (dockwidget->isVisible()) { - dockwidget->hide(); - dockwidget->show(); - } - } -#endif } /*! @@ -1344,153 +1296,14 @@ bool QMainWindow::restoreState(const QByteArray &state, int version) return restored; } -#if !defined(QT_NO_DOCKWIDGET) && !defined(QT_NO_CURSOR) -QCursor QMainWindowPrivate::separatorCursor(const QList<int> &path) const -{ - QDockAreaLayoutInfo *info = layout->layoutState.dockAreaLayout.info(path); - Q_ASSERT(info != 0); - if (path.size() == 1) { // is this the "top-level" separator which separates a dock area - // from the central widget? - switch (path.first()) { - case QInternal::LeftDock: - case QInternal::RightDock: - return Qt::SplitHCursor; - case QInternal::TopDock: - case QInternal::BottomDock: - return Qt::SplitVCursor; - default: - break; - } - } - - // no, it's a splitter inside a dock area, separating two dock widgets - - return info->o == Qt::Horizontal - ? Qt::SplitHCursor : Qt::SplitVCursor; -} - -void QMainWindowPrivate::adjustCursor(const QPoint &pos) -{ - Q_Q(QMainWindow); - - hoverPos = pos; - - if (pos == QPoint(0, 0)) { - if (!hoverSeparator.isEmpty()) - q->update(layout->layoutState.dockAreaLayout.separatorRect(hoverSeparator)); - hoverSeparator.clear(); - - if (cursorAdjusted) { - cursorAdjusted = false; - if (hasOldCursor) - q->setCursor(oldCursor); - else - q->unsetCursor(); - } - } else if (layout->movingSeparator.isEmpty()) { // Don't change cursor when moving separator - QList<int> pathToSeparator - = layout->layoutState.dockAreaLayout.findSeparator(pos); - - if (pathToSeparator != hoverSeparator) { - if (!hoverSeparator.isEmpty()) - q->update(layout->layoutState.dockAreaLayout.separatorRect(hoverSeparator)); - - hoverSeparator = pathToSeparator; - - if (hoverSeparator.isEmpty()) { - if (cursorAdjusted) { - cursorAdjusted = false; - if (hasOldCursor) - q->setCursor(oldCursor); - else - q->unsetCursor(); - } - } else { - q->update(layout->layoutState.dockAreaLayout.separatorRect(hoverSeparator)); - if (!cursorAdjusted) { - oldCursor = q->cursor(); - hasOldCursor = q->testAttribute(Qt::WA_SetCursor); - } - adjustedCursor = separatorCursor(hoverSeparator); - q->setCursor(adjustedCursor); - cursorAdjusted = true; - } - } - } -} -#endif - /*! \reimp */ bool QMainWindow::event(QEvent *event) { Q_D(QMainWindow); + if (d->layout && d->layout->windowEvent(event)) + return true; switch (event->type()) { -#ifndef QT_NO_DOCKWIDGET - case QEvent::Paint: { - QPainter p(this); - QRegion r = static_cast<QPaintEvent*>(event)->region(); - d->layout->layoutState.dockAreaLayout.paintSeparators(&p, this, r, d->hoverPos); - break; - } - -#ifndef QT_NO_CURSOR - case QEvent::HoverMove: { - d->adjustCursor(static_cast<QHoverEvent*>(event)->pos()); - break; - } - - // We don't want QWidget to call update() on the entire QMainWindow - // on HoverEnter and HoverLeave, hence accept the event (return true). - case QEvent::HoverEnter: - return true; - case QEvent::HoverLeave: - d->adjustCursor(QPoint(0, 0)); - return true; - case QEvent::ShortcutOverride: // when a menu pops up - d->adjustCursor(QPoint(0, 0)); - break; -#endif // QT_NO_CURSOR - - case QEvent::MouseButtonPress: { - QMouseEvent *e = static_cast<QMouseEvent*>(event); - if (e->button() == Qt::LeftButton && d->layout->startSeparatorMove(e->pos())) { - // The click was on a separator, eat this event - e->accept(); - return true; - } - break; - } - - case QEvent::MouseMove: { - QMouseEvent *e = static_cast<QMouseEvent*>(event); - -#ifndef QT_NO_CURSOR - d->adjustCursor(e->pos()); -#endif - if (e->buttons() & Qt::LeftButton) { - if (d->layout->separatorMove(e->pos())) { - // We're moving a separator, eat this event - e->accept(); - return true; - } - } - - break; - } - - case QEvent::MouseButtonRelease: { - QMouseEvent *e = static_cast<QMouseEvent*>(event); - if (d->layout->endSeparatorMove(e->pos())) { - // We've released a separator, eat this event - e->accept(); - return true; - } - break; - } - -#endif - #ifndef QT_NO_TOOLBAR case QEvent::ToolBarChange: { d->layout->toggleToolBarsVisible(); @@ -1516,40 +1329,6 @@ bool QMainWindow::event(QEvent *event) if (!d->explicitIconSize) setIconSize(QSize()); break; -#if 0 // Used to be included in Qt4 for Q_WS_MAC - case QEvent::Show: - if (unifiedTitleAndToolBarOnMac()) - d->layout->syncUnifiedToolbarVisibility(); - d->layout->blockVisiblityCheck = false; - break; - case QEvent::WindowStateChange: - { - if (isHidden()) { - // We are coming out of a minimize, leave things as is. - d->layout->blockVisiblityCheck = true; - } - // We need to update the HIToolbar status when we go out of or into fullscreen. - QWindowStateChangeEvent *wce = static_cast<QWindowStateChangeEvent *>(event); - if ((windowState() & Qt::WindowFullScreen) || (wce->oldState() & Qt::WindowFullScreen)) { - d->layout->updateHIToolBarStatus(); - } - } - break; -#endif -#if !defined(QT_NO_DOCKWIDGET) && !defined(QT_NO_CURSOR) - case QEvent::CursorChange: - // CursorChange events are triggered as mouse moves to new widgets even - // if the cursor doesn't actually change, so do not change oldCursor if - // the "changed" cursor has same shape as adjusted cursor. - if (d->cursorAdjusted && d->adjustedCursor.shape() != cursor().shape()) { - d->oldCursor = cursor(); - d->hasOldCursor = testAttribute(Qt::WA_SetCursor); - - // Ensure our adjusted cursor stays visible - setCursor(d->adjustedCursor); - } - break; -#endif default: break; } @@ -1589,33 +1368,6 @@ void QMainWindow::setUnifiedTitleAndToolBarOnMac(bool set) (reinterpret_cast<SetContentBorderEnabledFunction>(function))(window()->windowHandle(), set); update(); } -#endif - -#if 0 // Used to be included in Qt4 for Q_WS_MAC - Q_D(QMainWindow); - if (!isWindow() || d->useHIToolBar == set || QSysInfo::MacintoshVersion < QSysInfo::MV_10_3) - return; - - d->useHIToolBar = set; - createWinId(); // We need the hiview for down below. - - // Activate the unified toolbar with the raster engine. - if (windowSurface() && set) { - d->layout->unifiedSurface = new QUnifiedToolbarSurface(this); - } - - d->layout->updateHIToolBarStatus(); - - // Deactivate the unified toolbar with the raster engine. - if (windowSurface() && !set) { - if (d->layout->unifiedSurface) { - delete d->layout->unifiedSurface; - d->layout->unifiedSurface = 0; - } - } - - // Enabling the unified toolbar clears the opaque size grip setting, update it. - d->macUpdateOpaqueSizeGrip(); #else Q_UNUSED(set) #endif @@ -1626,9 +1378,6 @@ bool QMainWindow::unifiedTitleAndToolBarOnMac() const #ifdef Q_OS_OSX return d_func()->useUnifiedToolBar; #endif -#if 0 // Used to be included in Qt4 for Q_WS_MAC - return d_func()->useHIToolBar && !testAttribute(Qt::WA_MacBrushedMetal) && !(windowFlags() & Qt::FramelessWindowHint); -#endif return false; } diff --git a/src/widgets/widgets/qmainwindowlayout.cpp b/src/widgets/widgets/qmainwindowlayout.cpp index d31fa3ddfa..e0269a3f02 100644 --- a/src/widgets/widgets/qmainwindowlayout.cpp +++ b/src/widgets/widgets/qmainwindowlayout.cpp @@ -70,10 +70,6 @@ #include <private/qapplication_p.h> #include <private/qlayoutengine_p.h> #include <private/qwidgetresizehandler_p.h> -#if 0 // Used to be included in Qt4 for Q_WS_MAC -# include <private/qcore_mac_p.h> -# include <private/qt_cocoa_helpers_mac_p.h> -#endif QT_BEGIN_NAMESPACE @@ -177,13 +173,17 @@ QDebug operator<<(QDebug debug, const QMainWindowLayout *layout) /****************************************************************************** ** QDockWidgetGroupWindow */ -// QDockWidgetGroupWindow is the floating window containing the tabbed dockwidgets in case several -// dockwidgets are dragged together (QMainWindow::GroupedDragging feature). +// QDockWidgetGroupWindow is the floating window containing several QDockWidgets floating together. +// (QMainWindow::GroupedDragging feature) // QDockWidgetGroupLayout is the layout of that window and use a QDockAreaLayoutInfo to layout -// the tabs inside it. +// the QDockWidgets inside it. +// If there is only one QDockWidgets, or all QDockWidgets are tabbed together, it is equivalent +// of a floating QDockWidget (the title of the QDockWidget is the title of the window). But if there +// are nested QDockWidget, an additional title bar is there. #ifndef QT_NO_DOCKWIDGET -class QDockWidgetGroupLayout : public QLayout { - QDockAreaLayoutInfo info; +class QDockWidgetGroupLayout : public QLayout, + public QMainWindowLayoutSeparatorHelper<QDockWidgetGroupLayout> +{ QWidgetResizeHandler *resizer; public: QDockWidgetGroupLayout(QDockWidgetGroupWindow* parent) : QLayout(parent) { @@ -192,7 +192,7 @@ public: resizer->setMovingEnabled(false); } ~QDockWidgetGroupLayout() { - info.deleteAllLayoutItems(); + layoutState.deleteAllLayoutItems(); } void addItem(QLayoutItem*) Q_DECL_OVERRIDE { Q_UNREACHABLE(); } @@ -200,32 +200,43 @@ public: QLayoutItem* itemAt(int index) const Q_DECL_OVERRIDE { int x = 0; - return info.itemAt(&x, index); + return layoutState.itemAt(&x, index); } QLayoutItem* takeAt(int index) Q_DECL_OVERRIDE { int x = 0; - return info.takeAt(&x, index); + QLayoutItem *ret = layoutState.takeAt(&x, index); + if (savedState.rect.isValid() && ret->widget()) { + // we need to remove the item also from the saved state to prevent crash + QList<int> path = savedState.indexOf(ret->widget()); + if (!path.isEmpty()) + savedState.remove(path); + // Also, the item may be contained several times as a gap item. + path = layoutState.indexOf(ret->widget()); + if (!path.isEmpty()) + layoutState.remove(path); + } + return ret; } QSize sizeHint() const Q_DECL_OVERRIDE { int fw = frameWidth(); - return info.sizeHint() + QSize(fw, fw); + return layoutState.sizeHint() + QSize(fw, fw); } QSize minimumSize() const Q_DECL_OVERRIDE { int fw = frameWidth(); - return info.minimumSize() + QSize(fw, fw); + return layoutState.minimumSize() + QSize(fw, fw); } QSize maximumSize() const Q_DECL_OVERRIDE { int fw = frameWidth(); - return info.maximumSize() + QSize(fw, fw); + return layoutState.maximumSize() + QSize(fw, fw); } void setGeometry(const QRect&r) Q_DECL_OVERRIDE { groupWindow()->destroyOrHideIfEmpty(); - QDockAreaLayoutInfo *li = layoutInfo(); + QDockAreaLayoutInfo *li = dockAreaLayoutInfo(); if (li->isEmpty()) return; int fw = frameWidth(); @@ -235,12 +246,12 @@ public: li->rect = r.adjusted(fw, fw, -fw, -fw); li->fitItems(); li->apply(false); + if (savedState.rect.isValid()) + savedState.rect = li->rect; resizer->setActive(QWidgetResizeHandler::Resize, !nativeWindowDeco()); } - QDockAreaLayoutInfo *layoutInfo() { - return &info; - } + QDockAreaLayoutInfo *dockAreaLayoutInfo() { return &layoutState; } bool nativeWindowDeco() const { @@ -257,14 +268,21 @@ public: { return static_cast<QDockWidgetGroupWindow *>(parent()); } + + QDockAreaLayoutInfo layoutState; + QDockAreaLayoutInfo savedState; }; bool QDockWidgetGroupWindow::event(QEvent *e) { + auto lay = static_cast<QDockWidgetGroupLayout *>(layout()); + if (lay && lay->windowEvent(e)) + return true; + switch (e->type()) { case QEvent::Close: // Forward the close to the QDockWidget just as if its close button was pressed - if (QDockWidget *dw = topDockWidget()) { + if (QDockWidget *dw = activeTabbedDockWidget()) { e->ignore(); dw->close(); adjustFlags(); @@ -272,7 +290,7 @@ bool QDockWidgetGroupWindow::event(QEvent *e) return true; case QEvent::Move: // Let QDockWidgetPrivate::moseEvent handle the dragging - if (QDockWidget *dw = topDockWidget()) + if (QDockWidget *dw = activeTabbedDockWidget()) static_cast<QDockWidgetPrivate *>(QObjectPrivate::get(dw))->moveEvent(static_cast<QMoveEvent*>(e)); return true; case QEvent::NonClientAreaMouseMove: @@ -280,7 +298,7 @@ bool QDockWidgetGroupWindow::event(QEvent *e) case QEvent::NonClientAreaMouseButtonRelease: case QEvent::NonClientAreaMouseButtonDblClick: // Let the QDockWidgetPrivate of the currently visible dock widget handle the drag and drop - if (QDockWidget *dw = topDockWidget()) + if (QDockWidget *dw = activeTabbedDockWidget()) static_cast<QDockWidgetPrivate *>(QObjectPrivate::get(dw))->nonClientAreaMouseEvent(static_cast<QMouseEvent*>(e)); return true; case QEvent::ChildAdded: @@ -312,17 +330,49 @@ void QDockWidgetGroupWindow::paintEvent(QPaintEvent *) QDockAreaLayoutInfo *QDockWidgetGroupWindow::layoutInfo() const { - return static_cast<QDockWidgetGroupLayout*>(layout())->layoutInfo(); + return static_cast<QDockWidgetGroupLayout *>(layout())->dockAreaLayoutInfo(); +} + +/*! \internal + If this is a floating tab bar returns the currently the QDockWidgetGroupWindow that contains + tab, otherwise, return nullptr; + \note: if there is only one QDockWidget, it's still considered as a floating tab + */ +const QDockAreaLayoutInfo *QDockWidgetGroupWindow::tabLayoutInfo() const +{ + const QDockAreaLayoutInfo *info = layoutInfo(); + while (info && !info->tabbed) { + // There should be only one tabbed subinfo otherwise we are not a floating tab but a real + // window + const QDockAreaLayoutInfo *next = nullptr; + bool isSingle = false; + for (const auto &item : info->item_list) { + if (item.skip() || (item.flags & QDockAreaLayoutItem::GapItem)) + continue; + if (next || isSingle) // Two visible things + return nullptr; + if (item.subinfo) + next = item.subinfo; + else if (item.widgetItem) + isSingle = true; + } + if (isSingle) + return info; + info = next; + } + return info; } /*! \internal - Returns the currently active QDockWidget. + If this is a floating tab bar returns the currently active QDockWidget, otherwise nullptr */ -QDockWidget *QDockWidgetGroupWindow::topDockWidget() const +QDockWidget *QDockWidgetGroupWindow::activeTabbedDockWidget() const { - QDockAreaLayoutInfo *info = layoutInfo(); - QDockWidget *dw = 0; + QDockWidget *dw = nullptr; #if QT_CONFIG(tabbar) + const QDockAreaLayoutInfo *info = tabLayoutInfo(); + if (!info) + return nullptr; if (info->tabBar && info->tabBar->currentIndex() >= 0) { int i = info->tabIndexToListIndex(info->tabBar->currentIndex()); if (i >= 0) { @@ -331,7 +381,6 @@ QDockWidget *QDockWidgetGroupWindow::topDockWidget() const dw = qobject_cast<QDockWidget *>(item.widgetItem->widget()); } } -#endif if (!dw) { for (int i = 0; !dw && i < info->item_list.count(); ++i) { const QDockAreaLayoutItem &item = info->item_list.at(i); @@ -342,6 +391,7 @@ QDockWidget *QDockWidgetGroupWindow::topDockWidget() const dw = qobject_cast<QDockWidget *>(item.widgetItem->widget()); } } +#endif return dw; } @@ -388,18 +438,18 @@ void QDockWidgetGroupWindow::destroyOrHideIfEmpty() } /*! \internal - Sets the flags of this window in accordence to the capabilities of the dock widgets + Sets the flags of this window in accordance to the capabilities of the dock widgets */ void QDockWidgetGroupWindow::adjustFlags() { - QDockWidget *top = topDockWidget(); - if (!top) - return; - const bool nativeDeco = static_cast<QDockWidgetGroupLayout *>(layout())->nativeWindowDeco(); - Qt::WindowFlags oldFlags = windowFlags(); Qt::WindowFlags flags = oldFlags; - if (nativeDeco) { + + QDockWidget *top = activeTabbedDockWidget(); + if (!top) { // nested tabs, show window decoration + flags = + ((oldFlags & ~Qt::FramelessWindowHint) | Qt::CustomizeWindowHint | Qt::WindowTitleHint); + } else if (static_cast<QDockWidgetGroupLayout *>(layout())->nativeWindowDeco()) { flags |= Qt::CustomizeWindowHint | Qt::WindowTitleHint; flags.setFlag(Qt::WindowCloseButtonHint, top->features() & QDockWidget::DockWidgetClosable); flags &= ~Qt::FramelessWindowHint; @@ -432,21 +482,99 @@ void QDockWidgetGroupWindow::adjustFlags() show(); // setWindowFlags hides the window } - setWindowTitle(top->windowTitle()); - setWindowIcon(top->windowIcon()); + QWidget *titleBarOf = top ? top : parentWidget(); + setWindowTitle(titleBarOf->windowTitle()); + setWindowIcon(titleBarOf->windowIcon()); } bool QDockWidgetGroupWindow::hasNativeDecos() const { + QDockWidget *dw = activeTabbedDockWidget(); + if (!dw) // We have a group of nested QDockWidgets (not just floating tabs) + return true; + if (!QDockWidgetLayout::wmSupportsNativeWindowDeco()) return false; - if (QDockWidget *dw = topDockWidget()) - return dw->titleBarWidget() == nullptr; + return dw->titleBarWidget() == nullptr; +} +/* + The given widget is hovered over this floating group. + This function will save the state and create a gap in the actual state. + currentGapRect and currentGapPos will be set. + One must call restore() or apply() after this function. + Returns true if there was any change in the currentGapPos + */ +bool QDockWidgetGroupWindow::hover(QLayoutItem *widgetItem, const QPoint &mousePos) +{ + QDockAreaLayoutInfo &savedState = static_cast<QDockWidgetGroupLayout *>(layout())->savedState; + if (savedState.isEmpty()) + savedState = *layoutInfo(); + + QMainWindow::DockOptions opts = static_cast<QMainWindow *>(parentWidget())->dockOptions(); + bool nestingEnabled = + (opts & QMainWindow::AllowNestedDocks) && !(opts & QMainWindow::ForceTabbedDocks); + QDockAreaLayoutInfo::TabMode tabMode = + nestingEnabled ? QDockAreaLayoutInfo::AllowTabs : QDockAreaLayoutInfo::ForceTabs; + if (auto group = qobject_cast<QDockWidgetGroupWindow *>(widgetItem->widget())) { + if (!group->tabLayoutInfo()) + tabMode = QDockAreaLayoutInfo::NoTabs; + } + + QDockAreaLayoutInfo newState = savedState; + if (newState.tabbed) { + // insertion into a top-level tab + newState.item_list = { QDockAreaLayoutItem(new QDockAreaLayoutInfo(newState)) }; + newState.item_list.first().size = pick(savedState.o, savedState.rect.size()); + newState.tabbed = false; + newState.tabBar = nullptr; + } + + auto newGapPos = newState.gapIndex(mousePos, nestingEnabled, tabMode); + Q_ASSERT(!newGapPos.isEmpty()); + if (newGapPos == currentGapPos) + return false; // gap is already there + currentGapPos = newGapPos; + newState.insertGap(currentGapPos, widgetItem); + newState.fitItems(); + currentGapRect = newState.info(currentGapPos)->itemRect(currentGapPos.last(), true); + *layoutInfo() = std::move(newState); + layoutInfo()->apply(opts & QMainWindow::AnimatedDocks); return true; } +/* + Remove the gap that was created by hover() + */ +void QDockWidgetGroupWindow::restore() +{ + QDockAreaLayoutInfo &savedState = static_cast<QDockWidgetGroupLayout *>(layout())->savedState; + if (!savedState.isEmpty()) { + *layoutInfo() = savedState; + savedState = QDockAreaLayoutInfo(); + } + currentGapRect = QRect(); + currentGapPos.clear(); + adjustFlags(); + layoutInfo()->fitItems(); + layoutInfo()->apply(static_cast<QMainWindow *>(parentWidget())->dockOptions() + & QMainWindow::AnimatedDocks); +} + +/* + Apply the state that was created by hover + */ +void QDockWidgetGroupWindow::apply() +{ + static_cast<QDockWidgetGroupLayout *>(layout())->savedState.clear(); + currentGapRect = QRect(); + layoutInfo()->plug(currentGapPos); + currentGapPos.clear(); + adjustFlags(); + layoutInfo()->apply(false); +} + #endif /****************************************************************************** @@ -700,7 +828,14 @@ QList<int> QMainWindowLayoutState::gapIndex(QWidget *widget, // is it a dock widget? if (qobject_cast<QDockWidget *>(widget) != 0 || qobject_cast<QDockWidgetGroupWindow *>(widget)) { - result = dockAreaLayout.gapIndex(pos); + bool disallowTabs = false; +#if QT_CONFIG(tabbar) + if (auto *group = qobject_cast<QDockWidgetGroupWindow *>(widget)) { + if (!group->tabLayoutInfo()) // Disallow to drop nested docks as a tab + disallowTabs = true; + } +#endif + result = dockAreaLayout.gapIndex(pos, disallowTabs); if (!result.isEmpty()) result.prepend(1); return result; @@ -1183,14 +1318,7 @@ void QMainWindowLayout::removeToolBar(QToolBar *toolbar) QObject::disconnect(parentWidget(), SIGNAL(toolButtonStyleChanged(Qt::ToolButtonStyle)), toolbar, SLOT(_q_updateToolButtonStyle(Qt::ToolButtonStyle))); -#if 0 // Used to be included in Qt4 for Q_WS_MAC - if (usesHIToolBar(toolbar)) { - removeFromMacToolbar(toolbar); - } else -#endif - { - removeWidget(toolbar); - } + removeWidget(toolbar); } } @@ -1202,25 +1330,17 @@ void QMainWindowLayout::addToolBar(Qt::ToolBarArea area, bool) { validateToolBarArea(area); -#if 0 // Used to be included in Qt4 for Q_WS_MAC - if ((area == Qt::TopToolBarArea) - && layoutState.mainWindow->unifiedTitleAndToolBarOnMac()) { - insertIntoMacToolbar(0, toolbar); - } else -#endif - { - //let's add the toolbar to the layout - addChildWidget(toolbar); - QLayoutItem * item = layoutState.toolBarAreaLayout.addToolBar(toDockPos(area), toolbar); - if (savedState.isValid() && item) { - // copy the toolbar also in the saved state - savedState.toolBarAreaLayout.insertItem(toDockPos(area), item); - } - invalidate(); - - //this ensures that the toolbar has the right window flags (not floating any more) - toolbar->d_func()->updateWindowFlags(false /*floating*/); + // let's add the toolbar to the layout + addChildWidget(toolbar); + QLayoutItem *item = layoutState.toolBarAreaLayout.addToolBar(toDockPos(area), toolbar); + if (savedState.isValid() && item) { + // copy the toolbar also in the saved state + savedState.toolBarAreaLayout.insertItem(toDockPos(area), item); } + invalidate(); + + // this ensures that the toolbar has the right window flags (not floating any more) + toolbar->d_func()->updateWindowFlags(false /*floating*/); } /*! @@ -1228,27 +1348,20 @@ void QMainWindowLayout::addToolBar(Qt::ToolBarArea area, */ void QMainWindowLayout::insertToolBar(QToolBar *before, QToolBar *toolbar) { -#if 0 // Used to be included in Qt4 for Q_WS_MAC - if (usesHIToolBar(before)) { - insertIntoMacToolbar(before, toolbar); - } else -#endif - { - addChildWidget(toolbar); - QLayoutItem * item = layoutState.toolBarAreaLayout.insertToolBar(before, toolbar); - if (savedState.isValid() && item) { - // copy the toolbar also in the saved state - savedState.toolBarAreaLayout.insertItem(before, item); + addChildWidget(toolbar); + QLayoutItem *item = layoutState.toolBarAreaLayout.insertToolBar(before, toolbar); + if (savedState.isValid() && item) { + // copy the toolbar also in the saved state + savedState.toolBarAreaLayout.insertItem(before, item); + } + if (!currentGapPos.isEmpty() && currentGapPos.constFirst() == 0) { + currentGapPos = layoutState.toolBarAreaLayout.currentGapIndex(); + if (!currentGapPos.isEmpty()) { + currentGapPos.prepend(0); + currentGapRect = layoutState.itemRect(currentGapPos); } - if (!currentGapPos.isEmpty() && currentGapPos.constFirst() == 0) { - currentGapPos = layoutState.toolBarAreaLayout.currentGapIndex(); - if (!currentGapPos.isEmpty()) { - currentGapPos.prepend(0); - currentGapRect = layoutState.itemRect(currentGapPos); - } - } - invalidate(); } + invalidate(); } Qt::ToolBarArea QMainWindowLayout::toolBarArea(QToolBar *toolbar) const @@ -1261,12 +1374,6 @@ Qt::ToolBarArea QMainWindowLayout::toolBarArea(QToolBar *toolbar) const case QInternal::BottomDock: return Qt::BottomToolBarArea; default: break; } -#if 0 // Used to be included in Qt4 for Q_WS_MAC - if (pos == QInternal::DockCount) { - if (qtoolbarsInUnifiedToolbarList.contains(toolbar)) - return Qt::TopToolBarArea; - } -#endif return Qt::NoToolBarArea; } @@ -1283,70 +1390,15 @@ void QMainWindowLayout::getStyleOptionInfo(QStyleOptionToolBar *option, QToolBar void QMainWindowLayout::toggleToolBarsVisible() { - bool updateNonUnifiedParts = true; -#if 0 // Used to be included in Qt4 for Q_WS_MAC - if (layoutState.mainWindow->unifiedTitleAndToolBarOnMac()) { - // If we hit this case, someone has pressed the "toolbar button" which will - // toggle the unified toolbar visibility, because that's what the user wants. - // We might be in a situation where someone has hidden all the toolbars - // beforehand (maybe in construction), but now they've hit this button and - // and are expecting the items to show. What do we do? - // 1) Check the visibility of all the toolbars, if one is visible, do nothing, this - // preserves what people would expect (these toolbars were visible when I clicked last time). - // 2) If NONE are visible, then show them all. Again, this preserves the user expectation - // of, "I want to see the toolbars." The user may get more toolbars than expected, but this - // is better seeing nothing. - // Don't worry about any of this if we are going invisible. This does mean we may get - // into issues when switching into and out of fullscreen mode, but this is probably minor. - // If we ever need to do hiding, that would have to be taken care of after the unified toolbar - // has finished hiding. - // People can of course handle the QEvent::ToolBarChange event themselves and do - // WHATEVER they want if they don't like what we are doing (though the unified toolbar - // will fire regardless). - - // Check if we REALLY need to update the geometry below. If we only have items in the - // unified toolbar, all the docks will be empty, so there's very little point - // in doing the geometry as Apple will do it (we also avoid flicker in Cocoa as well). - // FWIW, layoutState.toolBarAreaLayout.visible and the state of the unified toolbar - // visibility can get out of sync. I really don't think it's a big issue. It is kept - // to a minimum because we only change the visibility if we absolutely must. - // update the "non unified parts." - updateNonUnifiedParts = !layoutState.toolBarAreaLayout.isEmpty(); - - // We get this function before the unified toolbar does its thing. - // So, the value will be opposite of what we expect. - bool goingVisible = !macWindowToolbarIsVisible(qt_mac_window_for(layoutState.mainWindow)); - if (goingVisible) { - const int ToolBarCount = qtoolbarsInUnifiedToolbarList.size(); - bool needAllVisible = true; - for (int i = 0; i < ToolBarCount; ++i) { - if (!qtoolbarsInUnifiedToolbarList.at(i)->isHidden()) { - needAllVisible = false; - break; - } - } - if (needAllVisible) { - QBoolBlocker blocker(blockVisiblityCheck); // Disable the visibilty check because - // the toggle has already happened. - for (int i = 0; i < ToolBarCount; ++i) - qtoolbarsInUnifiedToolbarList.at(i)->setVisible(true); - } - } - if (!updateNonUnifiedParts) - layoutState.toolBarAreaLayout.visible = goingVisible; - } -#endif - if (updateNonUnifiedParts) { - layoutState.toolBarAreaLayout.visible = !layoutState.toolBarAreaLayout.visible; - if (!layoutState.mainWindow->isMaximized()) { - QPoint topLeft = parentWidget()->geometry().topLeft(); - QRect r = parentWidget()->geometry(); - r = layoutState.toolBarAreaLayout.rectHint(r); - r.moveTo(topLeft); - parentWidget()->setGeometry(r); - } else { - update(); - } + layoutState.toolBarAreaLayout.visible = !layoutState.toolBarAreaLayout.visible; + if (!layoutState.mainWindow->isMaximized()) { + QPoint topLeft = parentWidget()->geometry().topLeft(); + QRect r = parentWidget()->geometry(); + r = layoutState.toolBarAreaLayout.rectHint(r); + r.moveTo(topLeft); + parentWidget()->setGeometry(r); + } else { + update(); } } @@ -1776,39 +1828,6 @@ void QMainWindowLayout::tabMoved(int from, int to) } #endif // QT_NO_TABBAR -bool QMainWindowLayout::startSeparatorMove(const QPoint &pos) -{ - movingSeparator = layoutState.dockAreaLayout.findSeparator(pos); - - if (movingSeparator.isEmpty()) - return false; - - layoutState.dockAreaLayout.fallbackToSizeHints = false; - - savedState = layoutState; - movingSeparatorPos = movingSeparatorOrigin = pos; - - return true; -} - -bool QMainWindowLayout::separatorMove(const QPoint &pos) -{ - if (movingSeparator.isEmpty()) - return false; - movingSeparatorPos = pos; - separatorMoveTimer.start(0, this); - return true; -} - -bool QMainWindowLayout::endSeparatorMove(const QPoint&) -{ - if (movingSeparator.isEmpty()) - return false; - movingSeparator.clear(); - savedState.clear(); - return true; -} - void QMainWindowLayout::raise(QDockWidget *widget) { #ifndef QT_NO_TABBAR @@ -1933,14 +1952,6 @@ QSize QMainWindowLayout::minimumSize() const const QSize sbMin = statusbar ? statusbar->minimumSize() : QSize(0, 0); minSize = QSize(qMax(sbMin.width(), minSize.width()), sbMin.height() + minSize.height()); -#if 0 // Used to be included in Qt4 for Q_WS_MAC - const QSize storedSize = minSize; - int minWidth = 0; - foreach (QToolBar *toolbar, qtoolbarsInUnifiedToolbarList) { - minWidth += toolbar->sizeHint().width() + 20; - } - minSize = QSize(qMax(minWidth, storedSize.width()), storedSize.height()); -#endif } return minSize; } @@ -1952,12 +1963,16 @@ void QMainWindowLayout::invalidate() } #ifndef QT_NO_DOCKWIDGET -void QMainWindowLayout::setCurrentHoveredFloat(QWidget *w) +void QMainWindowLayout::setCurrentHoveredFloat(QDockWidgetGroupWindow *w) { if (currentHoveredFloat != w) { if (currentHoveredFloat) { disconnect(currentHoveredFloat.data(), &QObject::destroyed, this, &QMainWindowLayout::updateGapIndicator); + if (currentHoveredFloat) + currentHoveredFloat->restore(); + } else if (w) { + restore(true); } currentHoveredFloat = w; @@ -2028,52 +2043,30 @@ void QMainWindowLayout::revert(QLayoutItem *widgetItem) bool QMainWindowLayout::plug(QLayoutItem *widgetItem) { -#ifndef QT_NO_DOCKWIDGET +#if QT_CONFIG(dockwidget) && QT_CONFIG(tabwidget) && QT_CONFIG(tabbar) if (currentHoveredFloat) { QWidget *widget = widgetItem->widget(); QList<int> previousPath = layoutState.indexOf(widget); if (!previousPath.isEmpty()) layoutState.remove(previousPath); + previousPath = currentHoveredFloat->layoutInfo()->indexOf(widget); // Let's remove the widget from any possible group window foreach (QDockWidgetGroupWindow *dwgw, parent()->findChildren<QDockWidgetGroupWindow*>(QString(), Qt::FindDirectChildrenOnly)) { + if (dwgw == currentHoveredFloat) + continue; QList<int> path = dwgw->layoutInfo()->indexOf(widget); if (!path.isEmpty()) dwgw->layoutInfo()->remove(path); } currentGapRect = QRect(); -#if QT_CONFIG(tabwidget) - if (QDockWidget *dropTo = qobject_cast<QDockWidget*>(currentHoveredFloat)) { - //dropping to a normal widget, we mutate it in a QDockWidgetGroupWindow with two tabs - QDockWidgetGroupWindow *floatingTabs = createTabbedDockWindow(); - floatingTabs->setGeometry(dropTo->geometry()); - QDockAreaLayoutInfo *info = floatingTabs->layoutInfo(); - *info = QDockAreaLayoutInfo(&layoutState.dockAreaLayout.sep, QInternal::LeftDock, - Qt::Horizontal, QTabBar::RoundedSouth, - static_cast<QMainWindow*>(parentWidget())); - info->tabbed = true; - QLayout *parentLayout = currentHoveredFloat->parentWidget()->layout(); - info->item_list.append(QDockAreaLayoutItem(parentLayout->takeAt(parentLayout->indexOf(currentHoveredFloat)))); - - dropTo->setParent(floatingTabs); - dropTo->show(); - dropTo->d_func()->plug(QRect()); - setCurrentHoveredFloat(floatingTabs); - } -#endif // QT_CONFIG(tabwidget) -#if QT_CONFIG(tabbar) - QDockWidgetGroupWindow *dwgw = qobject_cast<QDockWidgetGroupWindow *>(currentHoveredFloat); - Q_ASSERT(dwgw); - Q_ASSERT(dwgw->layoutInfo()->tabbed); // because floating group should always be tabbed - previousPath = dwgw->layoutInfo()->indexOf(widget); + currentHoveredFloat->apply(); if (!previousPath.isEmpty()) - dwgw->layoutInfo()->remove(previousPath); - dwgw->layoutInfo()->tab(0, widgetItem); - QRect globalRect = dwgw->layoutInfo()->tabContentRect(); - globalRect.moveTopLeft(dwgw->mapToGlobal(globalRect.topLeft())); + currentHoveredFloat->layoutInfo()->remove(previousPath); + QRect globalRect = currentHoveredFloat->currentGapRect; + globalRect.moveTopLeft(currentHoveredFloat->mapToGlobal(globalRect.topLeft())); pluggingWidget = widget; widgetAnimator.animate(widget, globalRect, dockOptions & QMainWindow::AnimatedDocks); -#endif // QT_CONFIG(tabbar) return true; } #endif @@ -2142,57 +2135,55 @@ void QMainWindowLayout::animationFinished(QWidget *widget) if (widget == pluggingWidget) { #ifndef QT_NO_DOCKWIDGET +#if QT_CONFIG(tabbar) if (QDockWidgetGroupWindow *dwgw = qobject_cast<QDockWidgetGroupWindow *>(widget)) { // When the animated widget was a QDockWidgetGroupWindow, it means each of the // embedded QDockWidget needs to be plugged back into the QMainWindow layout. savedState.clear(); - QDockAreaLayoutInfo* info = dwgw->layoutInfo(); - QDockAreaLayoutInfo* parentInfo; - QList<int> path; - - if (QDockWidgetGroupWindow *dropTo = qobject_cast<QDockWidgetGroupWindow *>(currentHoveredFloat)) { - parentInfo = dropTo->layoutInfo(); -#if QT_CONFIG(tabbar) - Q_ASSERT(parentInfo->tabbed); -#endif - path = parentInfo->indexOf(widget); - Q_ASSERT(path.size() == 1); + QDockAreaLayoutInfo *srcInfo = dwgw->layoutInfo(); + const QDockAreaLayoutInfo *srcTabInfo = dwgw->tabLayoutInfo(); + QDockAreaLayoutInfo *dstParentInfo; + QList<int> dstPath; + + if (currentHoveredFloat) { + dstPath = currentHoveredFloat->layoutInfo()->indexOf(widget); + Q_ASSERT(dstPath.size() >= 1); + dstParentInfo = currentHoveredFloat->layoutInfo()->info(dstPath); } else { - path = layoutState.dockAreaLayout.indexOf(widget); - Q_ASSERT(path.size() >= 2); - parentInfo = layoutState.dockAreaLayout.info(path); - Q_ASSERT(parentInfo); + dstPath = layoutState.dockAreaLayout.indexOf(widget); + Q_ASSERT(dstPath.size() >= 2); + dstParentInfo = layoutState.dockAreaLayout.info(dstPath); } -#if QT_CONFIG(tabbar) - if (parentInfo->tabbed) { + Q_ASSERT(dstParentInfo); + int idx = dstPath.constLast(); + Q_ASSERT(dstParentInfo->item_list[idx].widgetItem->widget() == dwgw); + if (dstParentInfo->tabbed && srcTabInfo) { // merge the two tab widgets - int idx = path.constLast(); - Q_ASSERT(parentInfo->item_list[idx].widgetItem->widget() == dwgw); - delete parentInfo->item_list[idx].widgetItem; - parentInfo->item_list.removeAt(idx); - std::copy(info->item_list.cbegin(), info->item_list.cend(), - std::inserter(parentInfo->item_list, parentInfo->item_list.begin() + idx)); - quintptr currentId = info->currentTabId(); - *info = QDockAreaLayoutInfo(); - parentInfo->reparentWidgets(currentHoveredFloat ? currentHoveredFloat.data() : parentWidget()); - parentInfo->updateTabBar(); - parentInfo->setCurrentTabId(currentId); - } else -#endif // QT_CONFIG(tabbar) - { - QDockAreaLayoutItem &item = layoutState.dockAreaLayout.item(path); + delete dstParentInfo->item_list[idx].widgetItem; + dstParentInfo->item_list.removeAt(idx); + std::copy(srcTabInfo->item_list.cbegin(), srcTabInfo->item_list.cend(), + std::inserter(dstParentInfo->item_list, + dstParentInfo->item_list.begin() + idx)); + quintptr currentId = srcTabInfo->currentTabId(); + *srcInfo = QDockAreaLayoutInfo(); + dstParentInfo->reparentWidgets(currentHoveredFloat ? currentHoveredFloat.data() + : parentWidget()); + dstParentInfo->updateTabBar(); + dstParentInfo->setCurrentTabId(currentId); + } else { + QDockAreaLayoutItem &item = dstParentInfo->item_list[idx]; Q_ASSERT(item.widgetItem->widget() == dwgw); delete item.widgetItem; item.widgetItem = 0; - item.subinfo = new QDockAreaLayoutInfo(qMove(*info)); - *info = QDockAreaLayoutInfo(); -#if QT_CONFIG(tabbar) - item.subinfo->reparentWidgets(parentWidget()); - item.subinfo->setTabBarShape(parentInfo->tabBarShape); -#endif + item.subinfo = new QDockAreaLayoutInfo(std::move(*srcInfo)); + *srcInfo = QDockAreaLayoutInfo(); + item.subinfo->reparentWidgets(currentHoveredFloat ? currentHoveredFloat.data() + : parentWidget()); + item.subinfo->setTabBarShape(dstParentInfo->tabBarShape); } dwgw->destroyOrHideIfEmpty(); } +#endif if (QDockWidget *dw = qobject_cast<QDockWidget*>(widget)) { dw->setParent(currentHoveredFloat ? currentHoveredFloat.data() : parentWidget()); @@ -2272,9 +2263,6 @@ QMainWindowLayout::QMainWindowLayout(QMainWindow *mainwindow, QLayout *parentLay #endif // QT_NO_DOCKWIDGET , widgetAnimator(this) , pluggingWidget(0) -#if 0 // Used to be included in Qt4 for Q_WS_MAC - , blockVisiblityCheck(false) -#endif { if (parentLayout) setParent(parentLayout); @@ -2299,10 +2287,6 @@ QMainWindowLayout::~QMainWindowLayout() layoutState.deleteAllLayoutItems(); layoutState.deleteCentralWidgetItem(); -#if 0 // Used to be included in Qt4 for Q_WS_MAC - cleanUpMacToolbarItems(); -#endif - delete statusbar; } @@ -2355,6 +2339,36 @@ void QMainWindowLayout::setCentralWidget(QWidget *widget) invalidate(); } +#if QT_CONFIG(dockwidget) && QT_CONFIG(tabwidget) +/*! \internal + This helper function is called by QMainWindowLayout::unplug if QMainWindow::GroupedDragging is + set and we are dragging the title bar of a non-floating QDockWidget. + If one should unplug the whole group, do so and return true, otherwise return false. + \a item is pointing to the QLayoutItem that holds the QDockWidget, but will be updated to the + QLayoutItem that holds the new QDockWidgetGroupWindow if the group is unplugged. +*/ +static bool unplugGroup(QMainWindowLayout *layout, QLayoutItem **item, + QDockAreaLayoutItem &parentItem) +{ + if (!parentItem.subinfo || !parentItem.subinfo->tabbed) + return false; + + // The QDockWidget is part of a group of tab and we need to unplug them all. + + QDockWidgetGroupWindow *floatingTabs = layout->createTabbedDockWindow(); + QDockAreaLayoutInfo *info = floatingTabs->layoutInfo(); + *info = std::move(*parentItem.subinfo); + delete parentItem.subinfo; + parentItem.subinfo = nullptr; + floatingTabs->setGeometry(info->rect.translated(layout->parentWidget()->pos())); + floatingTabs->show(); + floatingTabs->raise(); + *item = new QDockWidgetGroupWindowItem(floatingTabs); + parentItem.widgetItem = *item; + return true; +} +#endif + /*! \internal Unplug \a widget (QDockWidget or QToolBar) from it's parent container. @@ -2368,19 +2382,31 @@ void QMainWindowLayout::setCentralWidget(QWidget *widget) QLayoutItem *QMainWindowLayout::unplug(QWidget *widget, bool group) { #if !defined(QT_NO_DOCKWIDGET) && !defined(QT_NO_TABBAR) - if (!widget->isWindow() && qobject_cast<const QDockWidgetGroupWindow *>(widget->parentWidget())) { - if (group) { + auto *groupWindow = qobject_cast<const QDockWidgetGroupWindow *>(widget->parentWidget()); + if (!widget->isWindow() && groupWindow) { + if (group && groupWindow->tabLayoutInfo()) { // We are just dragging a floating window as it, not need to do anything, we just have to // look up the corresponding QWidgetItem* if it exists - QList<int> tabbedWindowPath = layoutState.indexOf(widget->parentWidget()); - return tabbedWindowPath.isEmpty() ? 0 : layoutState.item(tabbedWindowPath); + if (QDockAreaLayoutInfo *info = dockInfo(widget->parentWidget())) { + QList<int> groupWindowPath = info->indexOf(widget->parentWidget()); + return groupWindowPath.isEmpty() ? nullptr : info->item(groupWindowPath).widgetItem; + } + return nullptr; + } + QList<int> path = groupWindow->layoutInfo()->indexOf(widget); + QLayoutItem *item = groupWindow->layoutInfo()->item(path).widgetItem; + if (group && path.size() > 1 + && unplugGroup(this, &item, + groupWindow->layoutInfo()->item(path.mid(0, path.size() - 1)))) { + return item; } else { // We are unplugging a dock widget from a floating window. - if (QDockWidget *dw = qobject_cast<QDockWidget*>(widget)) { - dw->d_func()->unplug(widget->geometry()); - int index = widget->parentWidget()->layout()->indexOf(widget); - return widget->parentWidget()->layout()->itemAt(index); - } + QDockWidget *dw = qobject_cast<QDockWidget *>(widget); + Q_ASSERT(dw); // cannot be a QDockWidgetGroupWindow because it's not floating. + dw->d_func()->unplug(widget->geometry()); + groupWindow->layoutInfo()->fitItems(); + groupWindow->layoutInfo()->apply(dockOptions & QMainWindow::AnimatedDocks); + return item; } } #endif @@ -2398,30 +2424,15 @@ QLayoutItem *QMainWindowLayout::unplug(QWidget *widget, bool group) #ifndef QT_NO_DOCKWIDGET if (QDockWidget *dw = qobject_cast<QDockWidget*>(widget)) { Q_ASSERT(path.constFirst() == 1); - bool actualGroup = false; #if QT_CONFIG(tabwidget) - if (group && (dockOptions & QMainWindow::GroupedDragging) && path.size() > 3) { - QDockAreaLayoutItem &parentItem = layoutState.dockAreaLayout.item(path.mid(1, path.size() - 2)); - if (parentItem.subinfo && parentItem.subinfo->tabbed) { - // The QDockWidget is part of a group of tab and we need to unplug them all. - actualGroup = true; - path.removeLast(); - - QDockWidgetGroupWindow* floatingTabs = createTabbedDockWindow(); - QDockAreaLayoutInfo* info = floatingTabs->layoutInfo(); - *info = qMove(*parentItem.subinfo); - delete parentItem.subinfo; - parentItem.subinfo = 0; - floatingTabs->setGeometry(info->rect.translated(parentWidget()->pos())); - floatingTabs->show(); - floatingTabs->raise(); - item = new QDockWidgetGroupWindowItem(floatingTabs); - parentItem.widgetItem = item; - savedState = layoutState; - } - } + if (group && (dockOptions & QMainWindow::GroupedDragging) && path.size() > 3 + && unplugGroup(this, &item, + layoutState.dockAreaLayout.item(path.mid(1, path.size() - 2)))) { + path.removeLast(); + savedState = layoutState; + } else #endif // QT_CONFIG(tabwidget) - if (!actualGroup) { + { dw->d_func()->unplug(r); } } @@ -2450,11 +2461,11 @@ QLayoutItem *QMainWindowLayout::unplug(QWidget *widget, bool group) void QMainWindowLayout::updateGapIndicator() { #ifndef QT_NO_RUBBERBAND - if ((!widgetAnimator.animating() && !currentGapPos.isEmpty()) + if (!widgetAnimator.animating() && (!currentGapPos.isEmpty() #if QT_CONFIG(dockwidget) - || currentHoveredFloat + || currentHoveredFloat #endif - ) { + )) { QWidget *expectedParent = #if QT_CONFIG(dockwidget) currentHoveredFloat ? currentHoveredFloat.data() : @@ -2467,11 +2478,13 @@ void QMainWindowLayout::updateGapIndicator() } else if (gapIndicator->parent() != expectedParent) { gapIndicator->setParent(expectedParent); } - gapIndicator->setGeometry( + #if QT_CONFIG(dockwidget) - currentHoveredFloat ? currentHoveredFloat->rect() : + if (currentHoveredFloat) + gapIndicator->setGeometry(currentHoveredFloat->currentGapRect); + else #endif - currentGapRect); + gapIndicator->setGeometry(currentGapRect); gapIndicator->show(); gapIndicator->raise(); } else if (gapIndicator) { @@ -2520,12 +2533,36 @@ void QMainWindowLayout::hover(QLayoutItem *widgetItem, const QPoint &mousePos) if (!w->geometry().contains(mousePos)) continue; - setCurrentHoveredFloat(w); - restore(true); + if (auto dropTo = qobject_cast<QDockWidget *>(w)) { + // dropping to a normal widget, we mutate it in a QDockWidgetGroupWindow with two + // tabs + QDockWidgetGroupWindow *floatingTabs = createTabbedDockWindow(); // FIXME + floatingTabs->setGeometry(dropTo->geometry()); + QDockAreaLayoutInfo *info = floatingTabs->layoutInfo(); + *info = QDockAreaLayoutInfo(&layoutState.dockAreaLayout.sep, QInternal::LeftDock, + Qt::Horizontal, QTabBar::RoundedSouth, + static_cast<QMainWindow *>(parentWidget())); + info->tabbed = true; + QLayout *parentLayout = dropTo->parentWidget()->layout(); + info->item_list.append( + QDockAreaLayoutItem(parentLayout->takeAt(parentLayout->indexOf(dropTo)))); + + dropTo->setParent(floatingTabs); + dropTo->show(); + dropTo->d_func()->plug(QRect()); + w = floatingTabs; + } + Q_ASSERT(qobject_cast<QDockWidgetGroupWindow *>(w)); + auto group = static_cast<QDockWidgetGroupWindow *>(w); + if (group->hover(widgetItem, group->mapFromGlobal(mousePos))) { + setCurrentHoveredFloat(group); + applyState(layoutState); // update the tabbars + } return; } } setCurrentHoveredFloat(nullptr); + layoutState.dockAreaLayout.fallbackToSizeHints = false; #endif //QT_NO_DOCKWIDGET QPoint pos = parentWidget()->mapFromGlobal(mousePos); @@ -2588,7 +2625,7 @@ void QMainWindowLayout::hover(QLayoutItem *widgetItem, const QPoint &mousePos) #ifndef QT_NO_DOCKWIDGET parentWidget()->update(layoutState.dockAreaLayout.separatorRegion()); #endif - layoutState = newState; + layoutState = std::move(newState); applyState(layoutState); updateGapIndicator(); @@ -2677,46 +2714,6 @@ bool QMainWindowLayout::restoreState(QDataStream &stream) return true; } - -// Returns if this toolbar *should* be using HIToolbar. Won't work for all in between cases -// for example, you have a toolbar in the top area and then you suddenly turn on -// HIToolbar. -bool QMainWindowLayout::usesHIToolBar(QToolBar *toolbar) const -{ -#if 1 // Used to be excluded in Qt4 for Q_WS_MAC - Q_UNUSED(toolbar); - return false; -#else - return qtoolbarsInUnifiedToolbarList.contains(toolbar) - || ((toolBarArea(toolbar) == Qt::TopToolBarArea) - && layoutState.mainWindow->unifiedTitleAndToolBarOnMac()); -#endif -} - -void QMainWindowLayout::timerEvent(QTimerEvent *e) -{ -#ifndef QT_NO_DOCKWIDGET - if (e->timerId() == separatorMoveTimer.timerId()) { - //let's move the separators - separatorMoveTimer.stop(); - if (movingSeparator.isEmpty()) - return; - if (movingSeparatorOrigin == movingSeparatorPos) - return; - - //when moving the separator, we need to update the previous position - parentWidget()->update(layoutState.dockAreaLayout.separatorRegion()); - - layoutState = savedState; - layoutState.dockAreaLayout.separatorMove(movingSeparator, movingSeparatorOrigin, - movingSeparatorPos); - movingSeparatorPos = movingSeparatorOrigin; - } -#endif - QLayout::timerEvent(e); -} - - QT_END_NAMESPACE #include "moc_qmainwindowlayout_p.cpp" diff --git a/src/widgets/widgets/qmainwindowlayout_p.h b/src/widgets/widgets/qmainwindowlayout_p.h index ed8da61bc3..cc3b4e9261 100644 --- a/src/widgets/widgets/qmainwindowlayout_p.h +++ b/src/widgets/widgets/qmainwindowlayout_p.h @@ -58,6 +58,8 @@ #include "QtWidgets/qlayout.h" #include "QtWidgets/qtabbar.h" +#include "QtGui/qpainter.h" +#include "QtGui/qevent.h" #include "QtCore/qvector.h" #include "QtCore/qset.h" #include "QtCore/qbasictimer.h" @@ -72,6 +74,251 @@ QT_BEGIN_NAMESPACE class QToolBar; class QRubberBand; +template <typename Layout> // Make use of the "Curiously recurring template pattern" +class QMainWindowLayoutSeparatorHelper +{ + Layout *layout() { return static_cast<Layout *>(this); } + const Layout *layout() const { return static_cast<const Layout *>(this); } + QWidget *window() { return layout()->parentWidget(); } + +public: + QList<int> hoverSeparator; + QPoint hoverPos; + +#if !defined(QT_NO_DOCKWIDGET) && !defined(QT_NO_CURSOR) + QCursor separatorCursor(const QList<int> &path); + void adjustCursor(const QPoint &pos); + QCursor oldCursor; + QCursor adjustedCursor; + bool hasOldCursor = false; + bool cursorAdjusted = false; + + QList<int> movingSeparator; + QPoint movingSeparatorOrigin, movingSeparatorPos; + QBasicTimer separatorMoveTimer; + + bool startSeparatorMove(const QPoint &pos); + bool separatorMove(const QPoint &pos); + bool endSeparatorMove(const QPoint &pos); + +#endif + + bool windowEvent(QEvent *e); +}; + +#if !defined(QT_NO_DOCKWIDGET) && !defined(QT_NO_CURSOR) +template <typename Layout> +QCursor QMainWindowLayoutSeparatorHelper<Layout>::separatorCursor(const QList<int> &path) +{ + const QDockAreaLayoutInfo *info = layout()->dockAreaLayoutInfo()->info(path); + Q_ASSERT(info != 0); + if (path.size() == 1) { // is this the "top-level" separator which separates a dock area + // from the central widget? + switch (path.first()) { + case QInternal::LeftDock: + case QInternal::RightDock: + return Qt::SplitHCursor; + case QInternal::TopDock: + case QInternal::BottomDock: + return Qt::SplitVCursor; + default: + break; + } + } + + // no, it's a splitter inside a dock area, separating two dock widgets + + return info->o == Qt::Horizontal ? Qt::SplitHCursor : Qt::SplitVCursor; +} + +template <typename Layout> +void QMainWindowLayoutSeparatorHelper<Layout>::adjustCursor(const QPoint &pos) +{ + QWidget *w = layout()->window(); + hoverPos = pos; + + if (pos == QPoint(0, 0)) { + if (!hoverSeparator.isEmpty()) + w->update(layout()->dockAreaLayoutInfo()->separatorRect(hoverSeparator)); + hoverSeparator.clear(); + + if (cursorAdjusted) { + cursorAdjusted = false; + if (hasOldCursor) + w->setCursor(oldCursor); + else + w->unsetCursor(); + } + } else if (movingSeparator.isEmpty()) { // Don't change cursor when moving separator + QList<int> pathToSeparator = layout()->dockAreaLayoutInfo()->findSeparator(pos); + + if (pathToSeparator != hoverSeparator) { + if (!hoverSeparator.isEmpty()) + w->update(layout()->dockAreaLayoutInfo()->separatorRect(hoverSeparator)); + + hoverSeparator = pathToSeparator; + + if (hoverSeparator.isEmpty()) { + if (cursorAdjusted) { + cursorAdjusted = false; + if (hasOldCursor) + w->setCursor(oldCursor); + else + w->unsetCursor(); + } + } else { + w->update(layout()->dockAreaLayoutInfo()->separatorRect(hoverSeparator)); + if (!cursorAdjusted) { + oldCursor = w->cursor(); + hasOldCursor = w->testAttribute(Qt::WA_SetCursor); + } + adjustedCursor = separatorCursor(hoverSeparator); + w->setCursor(adjustedCursor); + cursorAdjusted = true; + } + } + } +} + +template <typename Layout> +bool QMainWindowLayoutSeparatorHelper<Layout>::windowEvent(QEvent *event) +{ + QWidget *w = window(); + switch (event->type()) { + case QEvent::Paint: { + QPainter p(w); + QRegion r = static_cast<QPaintEvent *>(event)->region(); + layout()->dockAreaLayoutInfo()->paintSeparators(&p, w, r, hoverPos); + break; + } + +#ifndef QT_NO_CURSOR + case QEvent::HoverMove: { + adjustCursor(static_cast<QHoverEvent *>(event)->pos()); + break; + } + + // We don't want QWidget to call update() on the entire QMainWindow + // on HoverEnter and HoverLeave, hence accept the event (return true). + case QEvent::HoverEnter: + return true; + case QEvent::HoverLeave: + adjustCursor(QPoint(0, 0)); + return true; + case QEvent::ShortcutOverride: // when a menu pops up + adjustCursor(QPoint(0, 0)); + break; +#endif // QT_NO_CURSOR + + case QEvent::MouseButtonPress: { + QMouseEvent *e = static_cast<QMouseEvent *>(event); + if (e->button() == Qt::LeftButton && startSeparatorMove(e->pos())) { + // The click was on a separator, eat this event + e->accept(); + return true; + } + break; + } + + case QEvent::MouseMove: { + QMouseEvent *e = static_cast<QMouseEvent *>(event); + +#ifndef QT_NO_CURSOR + adjustCursor(e->pos()); +#endif + if (e->buttons() & Qt::LeftButton) { + if (separatorMove(e->pos())) { + // We're moving a separator, eat this event + e->accept(); + return true; + } + } + + break; + } + + case QEvent::MouseButtonRelease: { + QMouseEvent *e = static_cast<QMouseEvent *>(event); + if (endSeparatorMove(e->pos())) { + // We've released a separator, eat this event + e->accept(); + return true; + } + break; + } + +#if !defined(QT_NO_CURSOR) + case QEvent::CursorChange: + // CursorChange events are triggered as mouse moves to new widgets even + // if the cursor doesn't actually change, so do not change oldCursor if + // the "changed" cursor has same shape as adjusted cursor. + if (cursorAdjusted && adjustedCursor.shape() != w->cursor().shape()) { + oldCursor = w->cursor(); + hasOldCursor = w->testAttribute(Qt::WA_SetCursor); + + // Ensure our adjusted cursor stays visible + w->setCursor(adjustedCursor); + } + break; +#endif + case QEvent::Timer: + if (static_cast<QTimerEvent *>(event)->timerId() == separatorMoveTimer.timerId()) { + // let's move the separators + separatorMoveTimer.stop(); + if (movingSeparator.isEmpty()) + return true; + if (movingSeparatorOrigin == movingSeparatorPos) + return true; + + // when moving the separator, we need to update the previous position + window()->update(layout()->dockAreaLayoutInfo()->separatorRegion()); + + layout()->layoutState = layout()->savedState; + layout()->dockAreaLayoutInfo()->separatorMove(movingSeparator, movingSeparatorOrigin, + movingSeparatorPos); + movingSeparatorPos = movingSeparatorOrigin; + return true; + } + break; + default: + break; + } + return false; +} + +template <typename Layout> +bool QMainWindowLayoutSeparatorHelper<Layout>::startSeparatorMove(const QPoint &pos) +{ + movingSeparator = layout()->dockAreaLayoutInfo()->findSeparator(pos); + + if (movingSeparator.isEmpty()) + return false; + + layout()->savedState = layout()->layoutState; + movingSeparatorPos = movingSeparatorOrigin = pos; + + return true; +} +template <typename Layout> +bool QMainWindowLayoutSeparatorHelper<Layout>::separatorMove(const QPoint &pos) +{ + if (movingSeparator.isEmpty()) + return false; + movingSeparatorPos = pos; + separatorMoveTimer.start(0, window()); + return true; +} +template <typename Layout> +bool QMainWindowLayoutSeparatorHelper<Layout>::endSeparatorMove(const QPoint &) +{ + if (movingSeparator.isEmpty()) + return false; + movingSeparator.clear(); + layout()->savedState.clear(); + return true; +} +#endif + #ifndef QT_NO_DOCKWIDGET class QDockWidgetGroupWindow : public QWidget { @@ -80,11 +327,19 @@ public: explicit QDockWidgetGroupWindow(QWidget* parent = 0, Qt::WindowFlags f = 0) : QWidget(parent, f) {} QDockAreaLayoutInfo *layoutInfo() const; - QDockWidget *topDockWidget() const; + const QDockAreaLayoutInfo *tabLayoutInfo() const; + QDockWidget *activeTabbedDockWidget() const; void destroyOrHideIfEmpty(); void adjustFlags(); bool hasNativeDecos() const; + bool hover(QLayoutItem *widgetItem, const QPoint &mousePos); + void restore(); + void apply(); + + QRect currentGapRect; + QList<int> currentGapPos; + protected: bool event(QEvent *) Q_DECL_OVERRIDE; void paintEvent(QPaintEvent*) Q_DECL_OVERRIDE; @@ -168,7 +423,9 @@ public: bool restoreState(QDataStream &stream, const QMainWindowLayoutState &oldState); }; -class Q_AUTOTEST_EXPORT QMainWindowLayout : public QLayout +class Q_AUTOTEST_EXPORT QMainWindowLayout + : public QLayout, + public QMainWindowLayoutSeparatorHelper<QMainWindowLayout> { Q_OBJECT @@ -180,9 +437,6 @@ public: QMainWindow::DockOptions dockOptions; void setDockOptions(QMainWindow::DockOptions opts); - bool usesHIToolBar(QToolBar *toolbar) const; - - void timerEvent(QTimerEvent *e) Q_DECL_OVERRIDE; // status bar @@ -261,15 +515,7 @@ public: #endif // QT_NO_TABWIDGET #endif // QT_NO_TABBAR - // separators - - QList<int> movingSeparator; - QPoint movingSeparatorOrigin, movingSeparatorPos; - QBasicTimer separatorMoveTimer; - - bool startSeparatorMove(const QPoint &pos); - bool separatorMove(const QPoint &pos); - bool endSeparatorMove(const QPoint &pos); + QDockAreaLayout *dockAreaLayoutInfo() { return &layoutState.dockAreaLayout; } void keepSize(QDockWidget *w); #endif // QT_NO_DOCKWIDGET @@ -305,8 +551,8 @@ public: QPointer<QRubberBand> gapIndicator; #endif #ifndef QT_NO_DOCKWIDGET - QPointer<QWidget> currentHoveredFloat; // set when dragging over a floating dock widget - void setCurrentHoveredFloat(QWidget *w); + QPointer<QDockWidgetGroupWindow> currentHoveredFloat; // set when dragging over a floating dock widget + void setCurrentHoveredFloat(QDockWidgetGroupWindow *w); #endif void hover(QLayoutItem *widgetItem, const QPoint &mousePos); @@ -316,7 +562,6 @@ public: void paintDropIndicator(QPainter *p, QWidget *widget, const QRegion &clip); void applyState(QMainWindowLayoutState &newState, bool animate = true); void restore(bool keepSavedState = false); - void updateHIToolBarStatus(); void animationFinished(QWidget *widget); private Q_SLOTS: @@ -331,40 +576,6 @@ private: #ifndef QT_NO_TABBAR void updateTabBarShapes(); #endif -#if 0 // Used to be included in Qt4 for Q_WS_MAC - static OSStatus qtmacToolbarDelegate(EventHandlerCallRef, EventRef , void *); - static OSStatus qtoolbarInHIToolbarHandler(EventHandlerCallRef inCallRef, EventRef event, - void *data); - static void qtMacHIToolbarRegisterQToolBarInHIToolborItemClass(); - static HIToolbarItemRef CreateToolbarItemForIdentifier(CFStringRef identifier, CFTypeRef data); - static HIToolbarItemRef createQToolBarInHIToolbarItem(QToolBar *toolbar, - QMainWindowLayout *layout); -public: - struct ToolBarSaveState { - ToolBarSaveState() : movable(false) { } - ToolBarSaveState(bool newMovable, const QSize &newMax) - : movable(newMovable), maximumSize(newMax) { } - bool movable; - QSize maximumSize; - }; - QList<QToolBar *> qtoolbarsInUnifiedToolbarList; - QList<void *> toolbarItemsCopy; - QHash<void *, QToolBar *> unifiedToolbarHash; - QHash<QToolBar *, ToolBarSaveState> toolbarSaveState; - QHash<QString, QToolBar *> cocoaItemIDToToolbarHash; - void insertIntoMacToolbar(QToolBar *before, QToolBar *after); - void removeFromMacToolbar(QToolBar *toolbar); - void cleanUpMacToolbarItems(); - void fixSizeInUnifiedToolbar(QToolBar *tb) const; - bool useHIToolBar; - bool activateUnifiedToolbarAfterFullScreen; - void syncUnifiedToolbarVisibility(); - bool blockVisiblityCheck; - - QUnifiedToolbarSurface *unifiedSurface; - void updateUnifiedToolbarOffset(); - -#endif }; #if !defined(QT_NO_DOCKWIDGET) && !defined(QT_NO_DEBUG_STREAM) diff --git a/src/widgets/widgets/qmdiarea.cpp b/src/widgets/widgets/qmdiarea.cpp index 18cb823702..0dc45ddbc3 100644 --- a/src/widgets/widgets/qmdiarea.cpp +++ b/src/widgets/widgets/qmdiarea.cpp @@ -160,9 +160,6 @@ #include <QApplication> #include <QStyle> -#if 0 /* Used to be included in Qt4 for Q_WS_MAC */ && QT_CONFIG(style_mac) -#include <private/qmacstyle_mac_p.h> -#endif #include <QChildEvent> #include <QResizeEvent> #include <QScrollBar> diff --git a/src/widgets/widgets/qmdisubwindow.cpp b/src/widgets/widgets/qmdisubwindow.cpp index a8cdca1719..c2dcacc6ba 100644 --- a/src/widgets/widgets/qmdisubwindow.cpp +++ b/src/widgets/widgets/qmdisubwindow.cpp @@ -158,9 +158,6 @@ #include <QMainWindow> #include <QScrollBar> #include <QDebug> -#if QT_CONFIG(style_mac) -#include <private/qmacstyle_mac_p.h> -#endif #include <QMdiArea> #include <QScopedValueRollback> @@ -194,6 +191,11 @@ static const Qt::WindowFlags CustomizeWindowFlags = static const int BoundaryMargin = 5; +static inline bool isMacStyle(QStyle *style) +{ + return style->inherits("QMacStyle"); +} + static inline int getMoveDeltaComponent(uint cflags, uint moveFlag, uint resizeFlag, int delta, int maxDelta, int minDelta) { @@ -295,11 +297,8 @@ static void showToolTip(QHelpEvent *helpEvent, QWidget *widget, const QStyleOpti Q_ASSERT(helpEvent->type() == QEvent::ToolTip); Q_ASSERT(widget); -#if QT_CONFIG(style_mac) - // Native Mac windows don't show tool tip. - if (qobject_cast<QMacStyle *>(widget->style())) + if (widget->style()->styleHint(QStyle::SH_TitleBar_ShowToolTipsOnButtons, &opt, widget)) return; -#endif // Convert CC_MdiControls to CC_TitleBar. Sub controls of different complex // controls cannot be in the same switch as they might have the same value. @@ -1076,10 +1075,8 @@ void QMdiSubWindowPrivate::updateCursor() { #ifndef QT_NO_CURSOR Q_Q(QMdiSubWindow); -#if QT_CONFIG(style_mac) - if (qobject_cast<QMacStyle *>(q->style())) + if (isMacStyle(q->style())) return; -#endif if (currentOperation == None) { q->unsetCursor(); @@ -1504,15 +1501,14 @@ void QMdiSubWindowPrivate::processClickedSubControl() q->showNormal(); break; case QStyle::SC_TitleBarMinButton: -#if QT_CONFIG(style_mac) - if (qobject_cast<QMacStyle *>(q->style())) { + if (isMacStyle(q->style())) { if (q->isMinimized()) q->showNormal(); else q->showMinimized(); break; } -#endif + q->showMinimized(); break; case QStyle::SC_TitleBarNormalButton: @@ -1521,15 +1517,14 @@ void QMdiSubWindowPrivate::processClickedSubControl() q->showNormal(); break; case QStyle::SC_TitleBarMaxButton: -#if QT_CONFIG(style_mac) - if (qobject_cast<QMacStyle *>(q->style())) { + if (isMacStyle(q->style())) { if (q->isMaximized()) q->showNormal(); else q->showMaximized(); break; } -#endif + q->showMaximized(); break; case QStyle::SC_TitleBarCloseButton: @@ -1568,10 +1563,8 @@ QRegion QMdiSubWindowPrivate::getRegion(Operation operation) const } QRegion region; -#if QT_CONFIG(style_mac) - if (qobject_cast<QMacStyle *>(q->style())) + if (isMacStyle(q->style())) return region; -#endif switch (operation) { case TopResize: @@ -1775,10 +1768,6 @@ bool QMdiSubWindowPrivate::drawTitleBarWhenMaximized() const if (isChildOfTabbedQMdiArea(q)) return false; -#if QT_CONFIG(style_mac) - Q_UNUSED(isChildOfQMdiSubWindow); - return true; -#else if (q->style()->styleHint(QStyle::SH_Workspace_FillSpaceOnMaximize, 0, q)) return true; #if defined(QT_NO_MENUBAR) || defined(QT_NO_MAINWINDOW) @@ -1792,7 +1781,6 @@ bool QMdiSubWindowPrivate::drawTitleBarWhenMaximized() const return isChildOfQMdiSubWindow(q); #endif -#endif } #ifndef QT_NO_MENUBAR @@ -2191,10 +2179,8 @@ void QMdiSubWindowPrivate::setSizeGrip(QSizeGrip *newSizeGrip) return; newSizeGrip->setFixedSize(newSizeGrip->sizeHint()); bool putSizeGripInLayout = layout ? true : false; -#if QT_CONFIG(style_mac) - if (qobject_cast<QMacStyle *>(q->style())) + if (isMacStyle(q->style())) putSizeGripInLayout = false; -#endif if (putSizeGripInLayout) { layout->addWidget(newSizeGrip); layout->setAlignment(newSizeGrip, Qt::AlignBottom | Qt::AlignRight); @@ -2843,8 +2829,8 @@ bool QMdiSubWindow::event(QEvent *event) d->isMaximizeMode = false; d->isWidgetHiddenByUs = false; if (!parent()) { -#if !defined(QT_NO_SIZEGRIP) && QT_CONFIG(style_mac) - if (qobject_cast<QMacStyle *>(style())) +#if !defined(QT_NO_SIZEGRIP) + if (isMacStyle(style())) delete d->sizeGrip; #endif setOption(RubberBandResize, false); @@ -2938,8 +2924,8 @@ void QMdiSubWindow::showEvent(QShowEvent *showEvent) return; } -#if !defined(QT_NO_SIZEGRIP) && QT_CONFIG(style_mac) - if (qobject_cast<QMacStyle *>(style()) && !d->sizeGrip +#if !defined(QT_NO_SIZEGRIP) + if (isMacStyle(style()) && !d->sizeGrip && !(windowFlags() & Qt::FramelessWindowHint)) { d->setSizeGrip(new QSizeGrip(this)); Q_ASSERT(d->sizeGrip); @@ -3333,10 +3319,10 @@ void QMdiSubWindow::mouseMoveEvent(QMouseEvent *mouseEvent) hoverRegion += style()->subControlRect(QStyle::CC_TitleBar, &options, d->hoveredSubControl, this); } -#if QT_CONFIG(style_mac) - if (qobject_cast<QMacStyle *>(style()) && !hoverRegion.isEmpty()) + + if (isMacStyle(style()) && !hoverRegion.isEmpty()) hoverRegion += QRegion(0, 0, width(), d->titleBarHeight(options)); -#endif + if (!hoverRegion.isEmpty()) update(hoverRegion); } @@ -3543,10 +3529,8 @@ QSize QMdiSubWindow::minimumSizeHint() const int sizeGripHeight = 0; if (d->sizeGrip && d->sizeGrip->isVisibleTo(const_cast<QMdiSubWindow *>(this))) sizeGripHeight = d->sizeGrip->height(); -#if QT_CONFIG(style_mac) - else if (parent() && qobject_cast<QMacStyle *>(style()) && !d->sizeGrip) + else if (parent() && isMacStyle(style()) && !d->sizeGrip) sizeGripHeight = style()->pixelMetric(QStyle::PM_SizeGripSize, 0, this); -#endif minHeight = qMax(minHeight, decorationHeight + sizeGripHeight); #endif diff --git a/src/widgets/widgets/qmenu.cpp b/src/widgets/widgets/qmenu.cpp index 2cafe462b1..4567f7c2a3 100644 --- a/src/widgets/widgets/qmenu.cpp +++ b/src/widgets/widgets/qmenu.cpp @@ -383,7 +383,7 @@ void QMenuPrivate::updateActionRects(const QRect &screen) const tabWidth = qMax(int(tabWidth), qfm.width(s.mid(t+1))); s = s.left(t); #ifndef QT_NO_SHORTCUT - } else { + } else if (action->isShortcutVisibleInContextMenu()) { QKeySequence seq = action->shortcut(); if (!seq.isEmpty()) tabWidth = qMax(int(tabWidth), qfm.width(seq.toString(QKeySequence::NativeText))); @@ -1513,7 +1513,8 @@ void QMenu::initStyleOption(QStyleOptionMenuItem *option, const QAction *action) option->icon = action->icon(); QString textAndAccel = action->text(); #ifndef QT_NO_SHORTCUT - if (textAndAccel.indexOf(QLatin1Char('\t')) == -1) { + if (action->isShortcutVisibleInContextMenu() + && textAndAccel.indexOf(QLatin1Char('\t')) == -1) { QKeySequence seq = action->shortcut(); if (!seq.isEmpty()) textAndAccel += QLatin1Char('\t') + seq.toString(QKeySequence::NativeText); @@ -1548,11 +1549,9 @@ void QMenu::initStyleOption(QStyleOptionMenuItem *option, const QAction *action) \table 100% \row \li \inlineimage fusion-menu.png - \li \inlineimage windowsxp-menu.png \li \inlineimage macintosh-menu.png \endtable - \caption Fig. A menu shown in \l{Fusion Style Widget Gallery}{Fusion widget style}, - \l{Windows XP Style Widget Gallery}{Windows XP widget style}, + \caption Fig. A menu shown in \l{Fusion Style Widget Gallery}{Fusion widget style} and \l{Macintosh Style Widget Gallery}{Macintosh widget style}. \section1 Actions @@ -2664,7 +2663,8 @@ void QMenu::hideEvent(QHideEvent *) if (QMenuBar *mb = qobject_cast<QMenuBar*>(d->causedPopup.widget)) mb->d_func()->setCurrentAction(0); #endif - d->mouseDown = 0; + if (d->mouseDown == this) + d->mouseDown = 0; d->hasHadMouse = false; if (d->activeMenu) d->hideMenu(d->activeMenu); diff --git a/src/widgets/widgets/qmenu.h b/src/widgets/widgets/qmenu.h index e9a5db1112..dbfd12124c 100644 --- a/src/widgets/widgets/qmenu.h +++ b/src/widgets/widgets/qmenu.h @@ -108,7 +108,7 @@ public: #else result->setShortcut(shortcut); #endif - connect(result, &QAction::triggered, object, slot); + connect(result, &QAction::triggered, object, std::move(slot)); return result; } // addAction(QString): Connect to a functor or function pointer (without context) @@ -121,7 +121,7 @@ public: #else result->setShortcut(shortcut); #endif - connect(result, &QAction::triggered, slot); + connect(result, &QAction::triggered, std::move(slot)); return result; } // addAction(QIcon, QString): Connect to a QObject slot / functor or function pointer (with context) @@ -136,7 +136,7 @@ public: #else result->setShortcut(shortcut); #endif - connect(result, &QAction::triggered, object, slot); + connect(result, &QAction::triggered, object, std::move(slot)); return result; } // addAction(QIcon, QString): Connect to a functor or function pointer (without context) @@ -149,7 +149,7 @@ public: #else result->setShortcut(shortcut); #endif - connect(result, &QAction::triggered, slot); + connect(result, &QAction::triggered, std::move(slot)); return result; } #endif // !Q_QDOC diff --git a/src/widgets/widgets/qprogressbar.cpp b/src/widgets/widgets/qprogressbar.cpp index 2b228cdb2c..39faf2e458 100644 --- a/src/widgets/widgets/qprogressbar.cpp +++ b/src/widgets/widgets/qprogressbar.cpp @@ -220,7 +220,7 @@ bool QProgressBarPrivate::repaintRequired() const Note that whether or not the text is drawn is dependent on the style. Currently CleanLooks and Plastique draw the text. Mac, Windows - and WindowsXP style do not. + and WindowsVista style do not. \sa textDirection */ diff --git a/src/widgets/widgets/qpushbutton.cpp b/src/widgets/widgets/qpushbutton.cpp index 5b1e10eb32..a4318681c9 100644 --- a/src/widgets/widgets/qpushbutton.cpp +++ b/src/widgets/widgets/qpushbutton.cpp @@ -59,10 +59,6 @@ #if QT_CONFIG(dialogbuttonbox) #include "qdialogbuttonbox.h" #endif -#if 0 // Used to be included in Qt4 for Q_WS_MAC -#include "private/qmacstyle_mac_p.h" -#include "private/qmacstyle_mac_p_p.h" -#endif #ifndef QT_NO_ACCESSIBILITY #include "qaccessible.h" diff --git a/src/widgets/widgets/qtabbar_p.h b/src/widgets/widgets/qtabbar_p.h index 7c653a95e9..7b14b636d1 100644 --- a/src/widgets/widgets/qtabbar_p.h +++ b/src/widgets/widgets/qtabbar_p.h @@ -81,7 +81,7 @@ private: QPixmap m_pixmap; }; -class QTabBarPrivate : public QWidgetPrivate +class Q_WIDGETS_EXPORT QTabBarPrivate : public QWidgetPrivate { Q_DECLARE_PUBLIC(QTabBar) public: diff --git a/src/widgets/widgets/qtoolbar.h b/src/widgets/widgets/qtoolbar.h index e0f2d9b073..9ffb472c76 100644 --- a/src/widgets/widgets/qtoolbar.h +++ b/src/widgets/widgets/qtoolbar.h @@ -121,7 +121,7 @@ public: addAction(const QString &text, const Obj *object, Func1 slot) { QAction *result = addAction(text); - connect(result, &QAction::triggered, object, slot); + connect(result, &QAction::triggered, object, std::move(slot)); return result; } // addAction(QString): Connect to a functor or function pointer (without context) @@ -139,7 +139,7 @@ public: addAction(const QIcon &actionIcon, const QString &text, const Obj *object, Func1 slot) { QAction *result = addAction(actionIcon, text); - connect(result, &QAction::triggered, object, slot); + connect(result, &QAction::triggered, object, std::move(slot)); return result; } // addAction(QIcon, QString): Connect to a functor or function pointer (without context) diff --git a/src/widgets/widgets/qwidgettextcontrol.cpp b/src/widgets/widgets/qwidgettextcontrol.cpp index 815cc8736b..116855c8d3 100644 --- a/src/widgets/widgets/qwidgettextcontrol.cpp +++ b/src/widgets/widgets/qwidgettextcontrol.cpp @@ -85,7 +85,10 @@ #include "private/qapplication_p.h" #include "private/qshortcutmap_p.h" #include <qkeysequence.h> -#define ACCEL_KEY(k) (!qApp->d_func()->shortcutMap.hasShortcutForKeySequence(k) ? \ +#define ACCEL_KEY(k) ((qApp->testAttribute(Qt::AA_DontShowIconsInMenus) \ + ? false \ + : qApp->styleHints()->showShortcutsInContextMenus()) \ + && !qApp->d_func()->shortcutMap.hasShortcutForKeySequence(k) ? \ QLatin1Char('\t') + QKeySequence(k).toString(QKeySequence::NativeText) : QString()) #else |