diff options
author | Norwegian Rock Cat <qt-info@nokia.com> | 2009-07-08 15:21:51 (GMT) |
---|---|---|
committer | Norwegian Rock Cat <qt-info@nokia.com> | 2009-07-09 17:01:26 (GMT) |
commit | 5c11a5a38bcc68c17da8fe59e8db03d43ea55ac1 (patch) | |
tree | 3b87cc860a08393c42aaf6d0adde692d2da3ce4b /src/gui/widgets/qmainwindowlayout.cpp | |
parent | 020ed5b7caaba5cf877cdb9ebaa575db1d15b7f0 (diff) | |
download | Qt-5c11a5a38bcc68c17da8fe59e8db03d43ea55ac1.zip Qt-5c11a5a38bcc68c17da8fe59e8db03d43ea55ac1.tar.gz Qt-5c11a5a38bcc68c17da8fe59e8db03d43ea55ac1.tar.bz2 |
Ensure that when we hide QToolBar in unified, unified follows.
Basically if you would hide a toolbar in the unified toolbar, you
would still see a little bit of area at the top instead of having
everything flush with the titlebar. This change basically unsures that
the unified toolbar makes a decision to hide itself if all the toolbars
inside it are hidden. It makes the behavior of clicking on the toolbar
button behave more or less correctly since we are going to show the
unified toolbar whether we want to or not.
This all will get the toolbar button switch event to be dispatched in
Cocoa as well.
Also add an optimization for checking if we need to change the geometry.
If we don't have any items the other toolbar areas, we can skip the set
geometry call, which wrecks havoc with things in Cocoa.
We still don't solve the case of someone who has hidden the items with
the toolbar button then goes full-screen, then goes back out. I'm not
motivated to solve it as is because we need to keep track of the
hides we do on the button press vs. other hides from the user and still
people can workaround it easy enough by handling window state change and
doing what is recommended in the docs.
Task-number: 208439
Rev-by: Denis
Diffstat (limited to 'src/gui/widgets/qmainwindowlayout.cpp')
-rw-r--r-- | src/gui/widgets/qmainwindowlayout.cpp | 76 |
1 files changed, 67 insertions, 9 deletions
diff --git a/src/gui/widgets/qmainwindowlayout.cpp b/src/gui/widgets/qmainwindowlayout.cpp index aba9120..541907e 100644 --- a/src/gui/widgets/qmainwindowlayout.cpp +++ b/src/gui/widgets/qmainwindowlayout.cpp @@ -939,15 +939,70 @@ void QMainWindowLayout::getStyleOptionInfo(QStyleOptionToolBar *option, QToolBar void QMainWindowLayout::toggleToolBarsVisible() { - 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(); + bool updateNonUnifiedParts = true; +#ifdef Q_WS_MAC + if (layoutState.mainWindow->unifiedTitleAndToolBarOnMac()) { + // If we hit this case, someone has pressed the "toolbar button" which will + // toggle the unified toolbar visiblity, 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(); + } } } @@ -1641,6 +1696,9 @@ QMainWindowLayout::QMainWindowLayout(QMainWindow *mainwindow) #ifndef QT_NO_RUBBERBAND , gapIndicator(new QRubberBand(QRubberBand::Rectangle, mainwindow)) #endif //QT_NO_RUBBERBAND +#ifdef Q_WS_MAC + , blockVisiblityCheck(false) +#endif { #ifndef QT_NO_DOCKWIDGET #ifndef QT_NO_TABBAR |