[LyX/master] #10571 improved handling of WM's signal when switching from or to full-screen window
Stephan Witt
switt at lyx.org
Tue Aug 4 13:07:07 UTC 2020
commit 6dcd4ca4f168df0cd49295fdfff3d75f1f70ba95
Author: Stephan Witt <switt at lyx.org>
Date: Tue Aug 4 15:23:53 2020 +0200
#10571 improved handling of WM's signal when switching from or to full-screen window
---
src/frontends/qt/GuiToolbar.cpp | 16 ++++++++
src/frontends/qt/GuiToolbar.h | 4 ++
src/frontends/qt/GuiView.cpp | 75 +++++++++++++++++++++++---------------
src/frontends/qt/GuiWorkArea.cpp | 9 ++---
4 files changed, 68 insertions(+), 36 deletions(-)
diff --git a/src/frontends/qt/GuiToolbar.cpp b/src/frontends/qt/GuiToolbar.cpp
index 4b3ebf4..f58069b 100644
--- a/src/frontends/qt/GuiToolbar.cpp
+++ b/src/frontends/qt/GuiToolbar.cpp
@@ -84,6 +84,16 @@ void GuiToolbar::setVisible(bool visible)
// MainWindow::restoreState and which toolbars should be initialized
// by us (i.e., new toolbars)
restored_ = true;
+ // Record the actual visibility in toolbar state visibility_.
+ // This is useful to restore the visibility of toolbars when
+ // returning from full-screen. Therefore the recording is disabled
+ // while LyX is in full-screen state.
+ if (!owner_.isFullScreen()) {
+ if (visible)
+ visibility_ |= Toolbars::ON;
+ else
+ visibility_ &= ~Toolbars::ON;
+ }
QToolBar::setVisible(visible);
}
@@ -595,6 +605,12 @@ void GuiToolbar::restoreSession()
}
+bool GuiToolbar::isVisibiltyOn() const
+{
+ return visibility_ & Toolbars::ON;
+}
+
+
void GuiToolbar::toggle()
{
docstring state;
diff --git a/src/frontends/qt/GuiToolbar.h b/src/frontends/qt/GuiToolbar.h
index 24d11e3..eccd05a 100644
--- a/src/frontends/qt/GuiToolbar.h
+++ b/src/frontends/qt/GuiToolbar.h
@@ -145,6 +145,10 @@ public:
///
bool isRestored() const;
+ ///
+ bool isVisibiltyOn() const;
+ int visibility() const { return visibility_; }
+
/// Refresh the contents of the bar.
void update(int context = 0);
diff --git a/src/frontends/qt/GuiView.cpp b/src/frontends/qt/GuiView.cpp
index f939573..3160a1f 100644
--- a/src/frontends/qt/GuiView.cpp
+++ b/src/frontends/qt/GuiView.cpp
@@ -117,7 +117,7 @@
#include <QTimer>
#include <QToolBar>
#include <QUrl>
-
+#include <QWindowStateChangeEvent>
// sync with GuiAlert.cpp
@@ -1401,6 +1401,49 @@ bool GuiView::event(QEvent * e)
//case QEvent::Drop:
// break;
+ case QEvent::WindowStateChange: {
+ QWindowStateChangeEvent * ev = (QWindowStateChangeEvent*)e;
+ bool ofstate = (ev->oldState() & Qt::WindowFullScreen);
+ bool result = QMainWindow::event(e);
+ bool nfstate = (windowState() & Qt::WindowFullScreen);
+ if (!ofstate && nfstate) {
+ LYXERR(Debug::DEBUG, "GuiView: WindowStateChange(): full-screen " << nfstate);
+ // switch to full-screen state
+ if (lyxrc.full_screen_statusbar)
+ statusBar()->hide();
+ if (lyxrc.full_screen_menubar)
+ menuBar()->hide();
+ if (lyxrc.full_screen_toolbars) {
+ ToolbarMap::iterator end = d.toolbars_.end();
+ for (ToolbarMap::iterator it = d.toolbars_.begin(); it != end; ++it)
+ if (it->second->isVisibiltyOn() && it->second->isVisible())
+ it->second->hide();
+ }
+ for (int i = 0; i != d.splitter_->count(); ++i)
+ d.tabWorkArea(i)->setFullScreen(true);
+ setContentsMargins(-2, -2, -2, -2);
+ // bug 5274
+ hideDialogs("prefs", nullptr);
+ } else if (ofstate && !nfstate) {
+ LYXERR(Debug::DEBUG, "GuiView: WindowStateChange(): full-screen " << nfstate);
+ // switch back from full-screen state
+ if (lyxrc.full_screen_statusbar && !statusBar()->isVisible())
+ statusBar()->show();
+ if (lyxrc.full_screen_menubar && !menuBar()->isVisible())
+ menuBar()->show();
+ if (lyxrc.full_screen_toolbars) {
+ ToolbarMap::iterator end = d.toolbars_.end();
+ for (ToolbarMap::iterator it = d.toolbars_.begin(); it != end; ++it)
+ if (it->second->isVisibiltyOn() && !it->second->isVisible())
+ it->second->show();
+ //updateToolbars();
+ }
+ for (int i = 0; i != d.splitter_->count(); ++i)
+ d.tabWorkArea(i)->setFullScreen(false);
+ setContentsMargins(0, 0, 0, 0);
+ }
+ return result;
+ }
case QEvent::WindowActivate: {
GuiView * old_view = guiApp->currentView();
if (this == old_view) {
@@ -4641,35 +4684,7 @@ bool GuiView::lfunUiToggle(string const & ui_component)
void GuiView::toggleFullScreen()
{
- if (isFullScreen()) {
- for (int i = 0; i != d.splitter_->count(); ++i)
- d.tabWorkArea(i)->setFullScreen(false);
- setContentsMargins(0, 0, 0, 0);
- setWindowState(windowState() ^ Qt::WindowFullScreen);
- restoreLayout();
- menuBar()->show();
- statusBar()->show();
- } else {
- // bug 5274
- hideDialogs("prefs", nullptr);
- for (int i = 0; i != d.splitter_->count(); ++i)
- d.tabWorkArea(i)->setFullScreen(true);
- setContentsMargins(-2, -2, -2, -2);
- saveLayout();
- setWindowState(windowState() ^ Qt::WindowFullScreen);
- if (lyxrc.full_screen_statusbar)
- statusBar()->hide();
- if (lyxrc.full_screen_menubar)
- menuBar()->hide();
- if (lyxrc.full_screen_toolbars) {
- ToolbarMap::iterator end = d.toolbars_.end();
- for (ToolbarMap::iterator it = d.toolbars_.begin(); it != end; ++it)
- it->second->hide();
- }
- }
-
- // give dialogs like the TOC a chance to adapt
- updateDialogs();
+ setWindowState(windowState() ^ Qt::WindowFullScreen);
}
diff --git a/src/frontends/qt/GuiWorkArea.cpp b/src/frontends/qt/GuiWorkArea.cpp
index 23d6efa..a2af82d 100644
--- a/src/frontends/qt/GuiWorkArea.cpp
+++ b/src/frontends/qt/GuiWorkArea.cpp
@@ -408,12 +408,9 @@ void GuiWorkArea::close()
void GuiWorkArea::setFullScreen(bool full_screen)
{
d->buffer_view_->setFullScreen(full_screen);
- setFrameStyle(QFrame::NoFrame);
- if (full_screen) {
- setFrameStyle(QFrame::NoFrame);
- if (lyxrc.full_screen_scrollbar)
- setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
- } else
+ if (full_screen && lyxrc.full_screen_scrollbar)
+ setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+ else
setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
}
More information about the lyx-cvs
mailing list