mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-22 13:18:28 +00:00
Fix zombie toolbars (bug 8520)
If there is a new toolbar, it will not be restored by Qt and we need to initialize it ourselves. However, it is not so easy to find out which toolbars are restored by Qt and which are not. For this, the setVisible function of GuiToolbar is 'misused'. If the visibility is set, the toolbar must have been restored by Qt and we should leave it alone.
This commit is contained in:
parent
97405fa623
commit
c8d685c665
@ -53,7 +53,8 @@ namespace frontend {
|
||||
|
||||
GuiToolbar::GuiToolbar(ToolbarInfo const & tbinfo, GuiView & owner)
|
||||
: QToolBar(toqstr(tbinfo.gui_name), &owner), visibility_(0),
|
||||
owner_(owner), command_buffer_(0), tbinfo_(tbinfo), filled_(false)
|
||||
owner_(owner), command_buffer_(0), tbinfo_(tbinfo), filled_(false),
|
||||
restored_(false)
|
||||
{
|
||||
setIconSize(owner.iconSize());
|
||||
connect(&owner, SIGNAL(iconSizeChanged(QSize)), this,
|
||||
@ -68,6 +69,22 @@ GuiToolbar::GuiToolbar(ToolbarInfo const & tbinfo, GuiView & owner)
|
||||
}
|
||||
|
||||
|
||||
void GuiToolbar::setVisible(bool visible)
|
||||
{
|
||||
// This is a hack to find out which toolbars have been restored by
|
||||
// MainWindow::restoreState and which toolbars should be initialized
|
||||
// by us (i.e., new toolbars)
|
||||
restored_ = true;
|
||||
QToolBar::setVisible(visible);
|
||||
}
|
||||
|
||||
|
||||
bool GuiToolbar::isRestored() const
|
||||
{
|
||||
return restored_;
|
||||
}
|
||||
|
||||
|
||||
void GuiToolbar::fill()
|
||||
{
|
||||
if (filled_)
|
||||
|
@ -70,6 +70,10 @@ public:
|
||||
///
|
||||
GuiToolbar(ToolbarInfo const &, GuiView &);
|
||||
|
||||
/// Reimplemented from QToolbar to detect whether the
|
||||
/// toolbar is restored with MainWindow::restoreState().
|
||||
void setVisible(bool visible);
|
||||
|
||||
///
|
||||
void setVisibility(int visibility);
|
||||
|
||||
@ -86,6 +90,9 @@ public:
|
||||
/// Restore session settings.
|
||||
void restoreSession();
|
||||
|
||||
///
|
||||
bool isRestored() const;
|
||||
|
||||
/// Refresh the contents of the bar.
|
||||
void update(bool in_math, bool in_table, bool review,
|
||||
bool in_mathmacrotemplate, bool in_ipa);
|
||||
@ -123,6 +130,8 @@ private:
|
||||
ToolbarInfo const & tbinfo_;
|
||||
///
|
||||
bool filled_;
|
||||
///
|
||||
bool restored_;
|
||||
};
|
||||
|
||||
} // namespace frontend
|
||||
|
@ -674,6 +674,16 @@ bool GuiView::restoreLayout()
|
||||
|
||||
if (!restoreState(settings.value("layout").toByteArray(), 0))
|
||||
initToolbars();
|
||||
|
||||
// init the toolbars that have not been restored
|
||||
Toolbars::Infos::iterator cit = guiApp->toolbars().begin();
|
||||
Toolbars::Infos::iterator end = guiApp->toolbars().end();
|
||||
for (; cit != end; ++cit) {
|
||||
GuiToolbar * tb = toolbar(cit->name);
|
||||
if (tb && !tb->isRestored())
|
||||
initToolbar(cit->name);
|
||||
}
|
||||
|
||||
updateDialogs();
|
||||
return true;
|
||||
}
|
||||
@ -716,42 +726,47 @@ void GuiView::initToolbars()
|
||||
// extracts the toolbars from the backend
|
||||
Toolbars::Infos::iterator cit = guiApp->toolbars().begin();
|
||||
Toolbars::Infos::iterator end = guiApp->toolbars().end();
|
||||
for (; cit != end; ++cit) {
|
||||
GuiToolbar * tb = toolbar(cit->name);
|
||||
if (!tb)
|
||||
continue;
|
||||
int const visibility = guiApp->toolbars().defaultVisibility(cit->name);
|
||||
bool newline = !(visibility & Toolbars::SAMEROW);
|
||||
tb->setVisible(false);
|
||||
tb->setVisibility(visibility);
|
||||
for (; cit != end; ++cit)
|
||||
initToolbar(cit->name);
|
||||
}
|
||||
|
||||
if (visibility & Toolbars::TOP) {
|
||||
if (newline)
|
||||
addToolBarBreak(Qt::TopToolBarArea);
|
||||
addToolBar(Qt::TopToolBarArea, tb);
|
||||
}
|
||||
|
||||
if (visibility & Toolbars::BOTTOM) {
|
||||
if (newline)
|
||||
addToolBarBreak(Qt::BottomToolBarArea);
|
||||
addToolBar(Qt::BottomToolBarArea, tb);
|
||||
}
|
||||
void GuiView::initToolbar(string const & name)
|
||||
{
|
||||
GuiToolbar * tb = toolbar(name);
|
||||
if (!tb)
|
||||
return;
|
||||
int const visibility = guiApp->toolbars().defaultVisibility(name);
|
||||
bool newline = !(visibility & Toolbars::SAMEROW);
|
||||
tb->setVisible(false);
|
||||
tb->setVisibility(visibility);
|
||||
|
||||
if (visibility & Toolbars::LEFT) {
|
||||
if (newline)
|
||||
addToolBarBreak(Qt::LeftToolBarArea);
|
||||
addToolBar(Qt::LeftToolBarArea, tb);
|
||||
}
|
||||
|
||||
if (visibility & Toolbars::RIGHT) {
|
||||
if (newline)
|
||||
addToolBarBreak(Qt::RightToolBarArea);
|
||||
addToolBar(Qt::RightToolBarArea, tb);
|
||||
}
|
||||
|
||||
if (visibility & Toolbars::ON)
|
||||
tb->setVisible(true);
|
||||
if (visibility & Toolbars::TOP) {
|
||||
if (newline)
|
||||
addToolBarBreak(Qt::TopToolBarArea);
|
||||
addToolBar(Qt::TopToolBarArea, tb);
|
||||
}
|
||||
|
||||
if (visibility & Toolbars::BOTTOM) {
|
||||
if (newline)
|
||||
addToolBarBreak(Qt::BottomToolBarArea);
|
||||
addToolBar(Qt::BottomToolBarArea, tb);
|
||||
}
|
||||
|
||||
if (visibility & Toolbars::LEFT) {
|
||||
if (newline)
|
||||
addToolBarBreak(Qt::LeftToolBarArea);
|
||||
addToolBar(Qt::LeftToolBarArea, tb);
|
||||
}
|
||||
|
||||
if (visibility & Toolbars::RIGHT) {
|
||||
if (newline)
|
||||
addToolBarBreak(Qt::RightToolBarArea);
|
||||
addToolBar(Qt::RightToolBarArea, tb);
|
||||
}
|
||||
|
||||
if (visibility & Toolbars::ON)
|
||||
tb->setVisible(true);
|
||||
}
|
||||
|
||||
|
||||
|
@ -344,6 +344,8 @@ private:
|
||||
///
|
||||
void initToolbars();
|
||||
///
|
||||
void initToolbar(std::string const & name);
|
||||
///
|
||||
bool lfunUiToggle(std::string const & ui_component);
|
||||
///
|
||||
void toggleFullScreen();
|
||||
|
Loading…
Reference in New Issue
Block a user