From: Abdelrazak Younes Date: Tue, 27 May 2008 11:15:17 +0000 (+0000) Subject: Re-engineer the toolbar support code: X-Git-Tag: 1.6.10~4662 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=7bb8a5f183808b2801df176b8626dccb282f97d4;p=features.git Re-engineer the toolbar support code: - We now rely more upon Qt features, - the initial toolbar positioning defined in "lib/ui/default.ui" is now only used if there is no session or if session handling is disabled, - The session saving/restoring is window dependent. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@24954 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/development/scons/scons_manifest.py b/development/scons/scons_manifest.py index e17bcc25ce..d91d2ec10d 100644 --- a/development/scons/scons_manifest.py +++ b/development/scons/scons_manifest.py @@ -746,7 +746,6 @@ src_frontends_qt4_header_files = Split(''' GuiThesaurus.h GuiToc.h GuiToolbar.h - GuiToolbars.h GuiView.h GuiViewSource.h GuiVSpace.h @@ -837,7 +836,6 @@ src_frontends_qt4_files = Split(''' GuiThesaurus.cpp GuiToc.cpp GuiToolbar.cpp - GuiToolbars.cpp GuiView.cpp GuiViewSource.cpp GuiVSpace.cpp diff --git a/lib/ui/default.ui b/lib/ui/default.ui index dec4723642..3cb14ec6c3 100644 --- a/lib/ui/default.ui +++ b/lib/ui/default.ui @@ -32,6 +32,7 @@ Include "stdtoolbars.inc" # math: the toolbar is visible only when in math # mathmacrotemplate: the toolbar is visible only when in a macro definition # table: the toolbar is visible only when in a table +# review: the toolbar is visible only when inside a tracked change # # top: the toolbar should be at the top of the window # bottom: the toolbar should be at the bottom of the window diff --git a/src/Session.cpp b/src/Session.cpp index 2d05a0e7fe..8bd1bc92de 100644 --- a/src/Session.cpp +++ b/src/Session.cpp @@ -291,96 +291,6 @@ BookmarksSection::Bookmark const & BookmarksSection::bookmark(unsigned int i) co } -void ToolbarSection::read(istream & is) -{ - string tmp; - do { - char c = is.peek(); - if (c == '[') - break; - getline(is, tmp); - if (tmp == "" || tmp[0] == '#' || tmp[0] == ' ') - continue; - - try { - // Read session info, saved as key/value pairs - // would better yell if pos returns npos - size_t pos = tmp.find_first_of(" = "); - // silently ignore lines without " = " - if (pos != string::npos) { - ToolbarItem item; - item.key = tmp.substr(0, pos); - int state; - int location; - istringstream value(tmp.substr(pos + 3)); - value >> state; - value >> location; - value >> item.info.posx; - value >> item.info.posy; - item.info.state = ToolbarInfo::State(state); - item.info.location = ToolbarInfo::Location(location); - toolbars.push_back(item); - } else - LYXERR(Debug::INIT, "LyX: Warning: Ignore toolbar info: " << tmp); - } catch (...) { - LYXERR(Debug::INIT, "LyX: Warning: unknown Toolbar info: " << tmp); - } - } while (is.good()); - // sort the toolbars by location, line and position - sort(toolbars.begin(), toolbars.end()); -} - - -void ToolbarSection::write(ostream & os) const -{ - os << '\n' << sec_toolbars << '\n'; - for (ToolbarList::const_iterator tb = toolbars.begin(); - tb != toolbars.end(); ++tb) { - os << tb->key << " = " - << static_cast(tb->info.state) << " " - << static_cast(tb->info.location) << " " - << tb->info.posx << " " - << tb->info.posy << '\n'; - } -} - - -ToolbarSection::ToolbarInfo & ToolbarSection::load(string const & name) -{ - for (ToolbarList::iterator tb = toolbars.begin(); - tb != toolbars.end(); ++tb) - if (tb->key == name) - return tb->info; - - // add a new item - ToolbarItem item; - item.key = name; - toolbars.push_back(item); - return toolbars.back().info; -} - - -bool operator<(ToolbarSection::ToolbarItem const & a, ToolbarSection::ToolbarItem const & b) -{ - ToolbarSection::ToolbarInfo lhs = a.info; - ToolbarSection::ToolbarInfo rhs = b.info; - // on if before off - if (lhs.state != rhs.state) - return static_cast(lhs.state) < static_cast(rhs.state); - // order of dock does not really matter - if (lhs.location != rhs.location) - return static_cast(lhs.location) < static_cast(rhs.location); - // if the same dock, the order depends on position - if (lhs.location == ToolbarSection::ToolbarInfo::TOP || - lhs.location == ToolbarSection::ToolbarInfo::BOTTOM) - return lhs.posy < rhs.posy || (lhs.posy == rhs.posy && lhs.posx < rhs.posx); - else if (lhs.location == ToolbarSection::ToolbarInfo::LEFT || - lhs.location == ToolbarSection::ToolbarInfo::RIGHT) - return lhs.posx < rhs.posx || (lhs.posx == rhs.posx && lhs.posy < rhs.posy); - return true; -} - - void SessionInfoSection::read(istream & is) { string tmp; @@ -470,8 +380,6 @@ void Session::readFile() lastFilePos().read(is); else if (tmp == sec_bookmarks) bookmarks().read(is); - else if (tmp == sec_toolbars) - toolbars().read(is); else if (tmp == sec_session) sessionInfo().read(is); else @@ -491,7 +399,6 @@ void Session::writeFile() const lastOpened().write(os); lastFilePos().write(os); bookmarks().write(os); - toolbars().write(os); sessionInfo().write(os); } else LYXERR(Debug::INIT, "LyX: Warning: unable to save Session: " diff --git a/src/Session.h b/src/Session.h index 8e18885259..c66bf30e9e 100644 --- a/src/Session.h +++ b/src/Session.h @@ -263,93 +263,6 @@ private: }; -class ToolbarSection : SessionSection -{ -public: - /// information about a toolbar, not all information can be - /// saved/restored by all frontends, but this class provides - /// a superset of things that can be managed by session. - class ToolbarInfo - { - public: - /// - ToolbarInfo() - : state(ON), location(NOTSET), posx(0), posy(0) - {} - /// - //ToolbarInfo(int s, int loc, int x = 0, int y = 0) - // : state(State(s)), location(Location(loc)), posx(x), posy(y) - // {} - - public: - enum State { - ON, - OFF, - AUTO - }; - - /// on/off/auto - State state; - - /// location: this can be intepreted differently. - enum Location { - TOP, - BOTTOM, - LEFT, - RIGHT, - NOTSET - }; - - Location location; - - /// x-position of the toolbar - int posx; - - /// y-position of the toolbar - int posy; - - /// potentially, icons - }; - - struct ToolbarItem { - std::string key; - ToolbarInfo info; - }; - - /// info for each toolbar - typedef std::vector ToolbarList; - - -public: - /// - void read(std::istream & is); - - /// - void write(std::ostream & os) const; - - /// return reference to toolbar info, create a new one if needed - ToolbarInfo & load(std::string const & name); - - /// toolbar begin - ToolbarList::const_iterator begin() { return toolbars.begin(); } - - /// toolbar end - ToolbarList::const_iterator end() { return toolbars.end(); } - -private: - /// toolbar information - ToolbarList toolbars; -}; - -/// comparison operator to sort toolbars, the rules are: -/// ON before OFF -/// TOP < BOTTOM < LEFT < RIGHT -/// Line at each side -/// order in each line -bool operator<(ToolbarSection::ToolbarItem const & a, - ToolbarSection::ToolbarItem const & b); - - class SessionInfoSection : SessionSection { public: @@ -406,10 +319,6 @@ public: /// BookmarksSection const & bookmarks() const { return bookmarks_; } /// - ToolbarSection & toolbars() { return toolbars_; } - /// - ToolbarSection const & toolbars() const { return toolbars_; } - /// SessionInfoSection & sessionInfo() { return session_info; } /// SessionInfoSection const & sessionInfo() const { return session_info; } @@ -438,8 +347,6 @@ private: /// BookmarksSection bookmarks_; /// - ToolbarSection toolbars_; - /// SessionInfoSection session_info; }; diff --git a/src/frontends/qt4/GuiToolbar.cpp b/src/frontends/qt4/GuiToolbar.cpp index f83d2ec46c..6fc2d1ae79 100644 --- a/src/frontends/qt4/GuiToolbar.cpp +++ b/src/frontends/qt4/GuiToolbar.cpp @@ -57,9 +57,11 @@ #include #include #include +#include #include #include #include +#include #include #include #include @@ -839,8 +841,8 @@ void GuiLayoutBox::selected(int index) GuiToolbar::GuiToolbar(ToolbarInfo const & tbinfo, GuiView & owner) - : QToolBar(qt_(tbinfo.gui_name), &owner), owner_(owner), - layout_(0), command_buffer_(0) + : QToolBar(qt_(tbinfo.gui_name), &owner), visibility_(0), + allowauto_(false), owner_(owner), layout_(0), command_buffer_(0) { // give visual separation between adjacent toolbars addSeparator(); @@ -848,10 +850,22 @@ GuiToolbar::GuiToolbar(ToolbarInfo const & tbinfo, GuiView & owner) // TODO: save toolbar position setMovable(true); + // + setObjectName(toqstr(tbinfo.name)); + ToolbarInfo::item_iterator it = tbinfo.items.begin(); ToolbarInfo::item_iterator end = tbinfo.items.end(); for (; it != end; ++it) add(*it); + + restoreSession(); +} + + +void GuiToolbar::setVisibility(int visibility) +{ + visibility_ = visibility; + allowauto_ = visibility_ >= Toolbars::MATH; } @@ -882,8 +896,7 @@ public: connect(bar_, SIGNAL(iconSizeChanged(QSize)), this, SLOT(setIconSize(QSize))); setCheckable(true); - ToolbarInfo const * tbinfo = - guiApp->toolbars().getDefinedToolbarInfo(tbitem_.name_); + ToolbarInfo const * tbinfo = guiApp->toolbars().info(tbitem_.name_); if (tbinfo) // use the icon of first action for the toolbar button setIcon(getIcon(tbinfo->items.begin()->func_, true)); @@ -898,8 +911,7 @@ public: initialized_ = true; - ToolbarInfo const * tbinfo = - guiApp->toolbars().getDefinedToolbarInfo(tbitem_.name_); + ToolbarInfo const * tbinfo = guiApp->toolbars().info(tbitem_.name_); if (!tbinfo) { lyxerr << "Unknown toolbar " << tbitem_.name_ << endl; return; @@ -953,8 +965,7 @@ public: m->setWindowTitle(label); m->setTearOffEnabled(true); connect(bar_, SIGNAL(updated()), m, SLOT(updateParent())); - ToolbarInfo const * tbinfo = - guiApp->toolbars().getDefinedToolbarInfo(tbitem_.name_); + ToolbarInfo const * tbinfo = guiApp->toolbars().info(tbitem_.name_); if (!tbinfo) { lyxerr << "Unknown toolbar " << tbitem_.name_ << endl; return; @@ -1023,42 +1034,21 @@ void GuiToolbar::add(ToolbarItem const & item) } -void GuiToolbar::saveInfo(ToolbarSection::ToolbarInfo & tbinfo) +void GuiToolbar::update(bool in_math, bool in_table, bool in_review, + bool in_mathmacrotemplate) { - // if tbinfo.state == auto *do not* set on/off - if (tbinfo.state != ToolbarSection::ToolbarInfo::AUTO) { - if (GuiToolbar::isVisible()) - tbinfo.state = ToolbarSection::ToolbarInfo::ON; - else - tbinfo.state = ToolbarSection::ToolbarInfo::OFF; + if (visibility_ & Toolbars::AUTO) { + bool show_it = in_math && (visibility_ & Toolbars::MATH) + || in_table && (visibility_ & Toolbars::TABLE) + || in_review && (visibility_ & Toolbars::REVIEW) + || in_mathmacrotemplate && (visibility_ & Toolbars::MATHMACROTEMPLATE); + setVisible(show_it); } - // - // no need to save it here. - Qt::ToolBarArea loc = owner_.toolBarArea(this); - - if (loc == Qt::TopToolBarArea) - tbinfo.location = ToolbarSection::ToolbarInfo::TOP; - else if (loc == Qt::BottomToolBarArea) - tbinfo.location = ToolbarSection::ToolbarInfo::BOTTOM; - else if (loc == Qt::RightToolBarArea) - tbinfo.location = ToolbarSection::ToolbarInfo::RIGHT; - else if (loc == Qt::LeftToolBarArea) - tbinfo.location = ToolbarSection::ToolbarInfo::LEFT; - else - tbinfo.location = ToolbarSection::ToolbarInfo::NOTSET; - - // save toolbar position. They are not used to restore toolbar position - // now because move(x,y) does not work for toolbar. - tbinfo.posx = pos().x(); - tbinfo.posy = pos().y(); -} - -void GuiToolbar::updateContents() -{ // update visible toolbars only if (!isVisible()) return; + // This is a speed bottleneck because this is called on every keypress // and update calls getStatus, which copies the cursor at least two times for (int i = 0; i < actions_.size(); ++i) @@ -1072,6 +1062,58 @@ void GuiToolbar::updateContents() } +QString GuiToolbar::sessionKey() const +{ + return "view-" + QString::number(owner_.id()) + "/" + objectName(); +} + + +void GuiToolbar::saveSession() const +{ + QSettings settings; + settings.setValue(sessionKey() + "/visibility", visibility_); +} + + +void GuiToolbar::restoreSession() +{ + QSettings settings; + setVisibility(settings.value(sessionKey() + "/visibility").toInt()); +} + + +void GuiToolbar::toggle() +{ + docstring state; + if (allowauto_) { + if (!(visibility_ & Toolbars::AUTO)) { + visibility_ |= Toolbars::AUTO; + hide(); + state = _("auto"); + } else { + visibility_ &= ~Toolbars::AUTO; + if (isVisible()) { + hide(); + state = _("off"); + } else { + show(); + state = _("on"); + } + } + } else { + if (isVisible()) { + hide(); + state = _("off"); + } else { + show(); + state = _("on"); + } + } + + owner_.message(bformat(_("Toolbar \"%1$s\" state set to %2$s"), + qstring_to_ucs4(windowTitle()), state)); +} + } // namespace frontend } // namespace lyx diff --git a/src/frontends/qt4/GuiToolbar.h b/src/frontends/qt4/GuiToolbar.h index 382440bf90..caa50156e7 100644 --- a/src/frontends/qt4/GuiToolbar.h +++ b/src/frontends/qt4/GuiToolbar.h @@ -112,16 +112,32 @@ class GuiToolbar : public QToolBar { Q_OBJECT public: + /// GuiToolbar(ToolbarInfo const &, GuiView &); + /// + void setVisibility(int visibility); + /// Add a button to the bar. void add(ToolbarItem const & item); - /** update toolbar information - * ToolbarInfo will then be saved by session - */ - void saveInfo(ToolbarSection::ToolbarInfo & info); + + /// Session key. + /** + * This key must be used for any session setting. + **/ + QString sessionKey() const; + /// Save session settings. + void saveSession() const; + /// Restore session settings. + void restoreSession(); + /// Refresh the contents of the bar. - void updateContents(); + void update(bool in_math, bool in_table, bool review, + bool in_mathmacrotemplate); + + /// + void toggle(); + /// GuiCommandBuffer * commandBuffer() { return command_buffer_; } @@ -133,11 +149,18 @@ Q_SIGNALS: void updated(); private: + // load flags with saved values + void initFlags(); + /// + QString name_; /// QList actions_; + /// initial visibility flags + int visibility_; + /// + bool allowauto_; /// GuiView & owner_; - /// GuiLayoutBox * layout_; /// diff --git a/src/frontends/qt4/GuiToolbars.cpp b/src/frontends/qt4/GuiToolbars.cpp deleted file mode 100644 index de07ffea49..0000000000 --- a/src/frontends/qt4/GuiToolbars.cpp +++ /dev/null @@ -1,387 +0,0 @@ -/** - * \file GuiToolbars.cpp - * This file is part of LyX, the document processor. - * Licence details can be found in the file COPYING. - * - * \author Lars Gullik Bjønnes - * \author Angus Leeming - * \author Abdelrazak Younes - * - * Full author contact details are available in file CREDITS. - */ - -#include - -#include "GuiToolbars.h" - -#include "GuiApplication.h" -#include "GuiCommandBuffer.h" -#include "GuiToolbar.h" -#include "GuiView.h" -#include "Toolbars.h" - -#include "Buffer.h" -#include "BufferParams.h" -#include "FuncRequest.h" -#include "FuncStatus.h" -#include "Layout.h" -#include "LyX.h" -#include "LyXFunc.h" -#include "TextClass.h" - -#include "support/debug.h" -#include "support/gettext.h" - -#include "support/lassert.h" - - -using namespace std; - -namespace lyx { -namespace frontend { - -#define TurnOnFlag(x) flags |= ToolbarInfo::x -#define TurnOffFlag(x) flags &= ~ToolbarInfo::x - -GuiToolbars::GuiToolbars(GuiView & owner) - : owner_(owner) -{ - init(); -} - - -void GuiToolbars::initFlags(ToolbarInfo & tbinfo) -{ - ToolbarSection::ToolbarInfo & info = LyX::ref().session().toolbars().load(tbinfo.name); - - unsigned int flags = static_cast(tbinfo.flags); - - // Remove default.ui positions. Only when a valid postion is stored - // in the session file the default.ui value will be overwritten - unsigned int save = flags; - TurnOffFlag(TOP); - TurnOffFlag(BOTTOM); - TurnOffFlag(RIGHT); - TurnOffFlag(LEFT); - - bool valid_location = true; - // init tbinfo.flags with saved location - if (info.location == ToolbarSection::ToolbarInfo::TOP) - TurnOnFlag(TOP); - else if (info.location == ToolbarSection::ToolbarInfo::BOTTOM) - TurnOnFlag(BOTTOM); - else if (info.location == ToolbarSection::ToolbarInfo::RIGHT) - TurnOnFlag(RIGHT); - else if (info.location == ToolbarSection::ToolbarInfo::LEFT) - TurnOnFlag(LEFT); - else { - // use setting from default.ui - flags = save; - valid_location = false; - } - - // invalid location is for a new toolbar that has no saved information, - // so info.visible is not used for this case. - if (valid_location) { - // init tbinfo.flags with saved visibility, - TurnOffFlag(ON); - TurnOffFlag(OFF); - TurnOffFlag(AUTO); - if (info.state == ToolbarSection::ToolbarInfo::ON) - TurnOnFlag(ON); - else if (info.state == ToolbarSection::ToolbarInfo::OFF) - TurnOnFlag(OFF); - else - TurnOnFlag(AUTO); - } - /* - cout << "State " << info.state << " FLAGS: " << flags - << " ON:" << (flags & Toolbars::ON) - << " OFF:" << (flags & Toolbars::OFF) - << " L:" << (flags & Toolbars::LEFT) - << " R:" << (flags & Toolbars::RIGHT) - << " T:" << (flags & Toolbars::TOP) - << " B:" << (flags & Toolbars::BOTTOM) - << " MA:" << (flags & Toolbars::MATH) - << " RE:" << (flags & Toolbars::REVIEW) - << " TB:" << (flags & Toolbars::TABLE) - << " AU:" << (flags & Toolbars::AUTO) - << endl; - */ - // now set the flags - tbinfo.flags = static_cast(flags); -} - - -void GuiToolbars::init() -{ - ToolbarsMap::iterator it = toolbars_.begin(); - for (; it != toolbars_.end(); ++it) - delete it->second; - toolbars_.clear(); - - // extracts the toolbars from the backend - Toolbars::Infos::iterator cit = guiApp->toolbars().begin(); - Toolbars::Infos::iterator end = guiApp->toolbars().end(); - - // init flags will also add these toolbars to session if they - // are not already there (e.g. first run of lyx). - for (; cit != end; ++cit) - initFlags(*cit); - - // add toolbars according the order in session - ToolbarSection::ToolbarList::const_iterator tb = - LyX::ref().session().toolbars().begin(); - ToolbarSection::ToolbarList::const_iterator te = - LyX::ref().session().toolbars().end(); - ToolbarSection::ToolbarInfo::Location last_loc = - ToolbarSection::ToolbarInfo::NOTSET; - int last_posx = 0; - int last_posy = 0; - for (; tb != te; ++tb) { - LYXERR(Debug::INIT, "Adding " << tb->key << " at position " - << tb->info.posx << " " << tb->info.posy); - // add toolbar break if posx or posy changes - bool newline = tb->info.location == last_loc && ( - // if two toolbars at the same location, assume uninitialized and add toolbar break - (tb->info.posx == last_posx && tb->info.posy == last_posy) || - (last_loc == ToolbarSection::ToolbarInfo::TOP && tb->info.posy != last_posy) || - (last_loc == ToolbarSection::ToolbarInfo::BOTTOM && tb->info.posy != last_posy) || - (last_loc == ToolbarSection::ToolbarInfo::LEFT && tb->info.posx != last_posx) || - (last_loc == ToolbarSection::ToolbarInfo::RIGHT && tb->info.posx != last_posx) ); - // find the backend item and add - for (cit = guiApp->toolbars().begin(); cit != end; ++cit) - if (cit->name == tb->key) { - add(*cit, newline); - last_loc = tb->info.location; - last_posx = tb->info.posx; - last_posy = tb->info.posy; - break; - } - } -} - - -void GuiToolbars::display(string const & name, bool show) -{ - Toolbars::Infos::iterator cit = guiApp->toolbars().begin(); - Toolbars::Infos::iterator end = guiApp->toolbars().end(); - - for (; cit != end; ++cit) { - if (cit->name == name) { - unsigned int flags = cit->flags; - TurnOffFlag(ON); - TurnOffFlag(OFF); - TurnOffFlag(AUTO); - if (show) - TurnOnFlag(ON); - else - TurnOnFlag(OFF); - cit->flags = static_cast(flags); - displayToolbar(*cit, show); - } - } - - LYXERR(Debug::GUI, "Toolbar::display: no toolbar named " << name); -} - - -ToolbarInfo * GuiToolbars::getToolbarInfo(string const & name) -{ - return guiApp->toolbars().getUsedToolbarInfo(name); -} - - -void GuiToolbars::toggleToolbarState(string const & name, bool allowauto) -{ - ToolbarInfo * tbi = guiApp->toolbars().getUsedToolbarInfo(name); - - if (!tbi) { - LYXERR(Debug::GUI, "Toolbar::display: no toolbar named " << name); - return; - } - - int flags = tbi->flags; - // off -> on - if (flags & ToolbarInfo::OFF) { - TurnOffFlag(OFF); - TurnOnFlag(ON); - // auto -> off - } else if (flags & ToolbarInfo::AUTO) { - TurnOffFlag(AUTO); - TurnOnFlag(OFF); - } else if (allowauto - && ((flags & ToolbarInfo::MATH) - || (flags & ToolbarInfo::TABLE) - || (flags & ToolbarInfo::REVIEW) - || (flags & ToolbarInfo::MATHMACROTEMPLATE))) { - // for math etc, toggle from on -> auto - TurnOffFlag(ON); - TurnOnFlag(AUTO); - } else { - // for others, toggle from on -> off - TurnOffFlag(ON); - TurnOnFlag(OFF); - } - tbi->flags = static_cast(flags); -} - - -void GuiToolbars::toggleFullScreen(bool start_full_screen) -{ - // we need to know number of fullscreens until every - // LyXView has its own toolbar configuration - guiApp->toolbars().fullScreenWindows += start_full_screen ? 1 : -1; - - // extracts the toolbars from the backend - Toolbars::Infos::iterator cit = guiApp->toolbars().begin(); - Toolbars::Infos::iterator end = guiApp->toolbars().end(); - int flags = 0; - - for (; cit != end; ++cit) { - - if (start_full_screen) { - if (guiApp->toolbars().fullScreenWindows == 1) - flags = cit->before_fullscreen = cit->flags; - TurnOffFlag(ON); - TurnOffFlag(AUTO); - TurnOnFlag(OFF); - } else - flags = cit->before_fullscreen; - - cit->flags = static_cast(flags); - } -} -#undef TurnOnFlag -#undef TurnOffFlag - - -void GuiToolbars::update(bool in_math, bool in_table, bool review, - bool in_mathmacrotemplate) -{ - updateIcons(); - - // extracts the toolbars from the backend - Toolbars::Infos::const_iterator cit = guiApp->toolbars().begin(); - Toolbars::Infos::const_iterator end = guiApp->toolbars().end(); - - for (; cit != end; ++cit) { - if (cit->flags & ToolbarInfo::ON) - displayToolbar(*cit, true); - else if (cit->flags & ToolbarInfo::OFF) - displayToolbar(*cit, false); - else if ((cit->flags & ToolbarInfo::AUTO) && (cit->flags & ToolbarInfo::MATH)) - displayToolbar(*cit, in_math); - else if ((cit->flags & ToolbarInfo::AUTO) && (cit->flags & ToolbarInfo::TABLE)) - displayToolbar(*cit, in_table); - else if ((cit->flags & ToolbarInfo::AUTO) && (cit->flags & ToolbarInfo::REVIEW)) - displayToolbar(*cit, review); - else if ((cit->flags & ToolbarInfo::AUTO) && (cit->flags & ToolbarInfo::MATHMACROTEMPLATE)) - displayToolbar(*cit, in_mathmacrotemplate); - } -} - - -bool GuiToolbars::visible(string const & name) const -{ - map::const_iterator it = - toolbars_.find(name); - if (it == toolbars_.end()) - return false; - return it->second->isVisible(); -} - - -void GuiToolbars::saveToolbarInfo() -{ - ToolbarSection & tb = LyX::ref().session().toolbars(); - - for (Toolbars::Infos::iterator cit = guiApp->toolbars().begin(); - cit != guiApp->toolbars().end(); ++cit) { - ToolbarsMap::iterator it = toolbars_.find(cit->name); - LASSERT(it != toolbars_.end(), /**/); - // get toolbar info from session. - ToolbarSection::ToolbarInfo & info = tb.load(cit->name); - if (cit->flags & ToolbarInfo::ON) - info.state = ToolbarSection::ToolbarInfo::ON; - else if (cit->flags & ToolbarInfo::OFF) - info.state = ToolbarSection::ToolbarInfo::OFF; - else if (cit->flags & ToolbarInfo::AUTO) - info.state = ToolbarSection::ToolbarInfo::AUTO; - // save other information - // if auto, frontend should *not* set on/off - it->second->saveInfo(info); - // maybe it is useful to update flags with real status. I do not know - /* - if (!(cit->flags & ToolbarInfo::AUTO)) { - unsigned int flags = static_cast(cit->flags); - flags &= ~(info.state == ToolbarSection::ToolbarInfo::ON ? ToolbarInfo::OFF : ToolbarInfo::ON); - flags |= (info.state == ToolbarSection::ToolbarInfo::ON ? ToolbarInfo::ON : ToolbarInfo::OFF); - if (info.state == ToolbarSection::ToolbarInfo::ON) - cit->flags = static_cast(flags); - } - */ - } -} - - -void GuiToolbars::add(ToolbarInfo const & tbinfo, bool newline) -{ - GuiToolbar * tb_ptr = owner_.makeToolbar(tbinfo, newline); - toolbars_[tbinfo.name] = tb_ptr; - - if (tbinfo.flags & ToolbarInfo::ON) - tb_ptr->show(); - else - tb_ptr->hide(); -} - - -void GuiToolbars::displayToolbar(ToolbarInfo const & tbinfo, - bool show_it) -{ - ToolbarsMap::iterator it = toolbars_.find(tbinfo.name); - LASSERT(it != toolbars_.end(), /**/); - - if (show_it) { - if (it->second->isVisible()) - return; - it->second->show(); - } - else if (it->second->isVisible()) - it->second->hide(); -} - - -void GuiToolbars::updateIcons() -{ - ToolbarsMap::const_iterator it = toolbars_.begin(); - ToolbarsMap::const_iterator const end = toolbars_.end(); - for (; it != end; ++it) - it->second->updateContents(); -} - - -void GuiToolbars::showCommandBuffer(bool show_it) -{ - ToolbarsMap::const_iterator it = toolbars_.begin(); - ToolbarsMap::const_iterator const end = toolbars_.end(); - for (; it != end; ++it) { - GuiCommandBuffer * cb = it->second->commandBuffer(); - if (!cb) - continue; - if (!show_it) { - // FIXME: this is a hack, "minibuffer" should not be - // hardcoded. - display("minibuffer", false); - return; - } - if (!it->second->isVisible()) - display("minibuffer", true); - cb->setFocus(); - return; - } -} - -} // namespace frontend -} // namespace lyx diff --git a/src/frontends/qt4/GuiToolbars.h b/src/frontends/qt4/GuiToolbars.h deleted file mode 100644 index 1afad34ee3..0000000000 --- a/src/frontends/qt4/GuiToolbars.h +++ /dev/null @@ -1,95 +0,0 @@ -// -*- C++ -*- -/** - * \file GuiToolbars.h - * This file is part of LyX, the document processor. - * Licence details can be found in the file COPYING. - * - * \author Lars Gullik Bjønnes - * \author Angus Leeming - * \author Abdelrazak Younes - * - * Full author contact details are available in file CREDITS. - */ - -#ifndef GUI_TOOLBARS_H -#define GUI_TOOLBARS_H - -#include "support/docstring.h" - -#include - -namespace lyx { - -class DocumentClass; - -namespace frontend { - -class GuiToolbar; -class GuiView; -class ToolbarInfo; - -class GuiToolbars -{ -public: - /// - GuiToolbars(GuiView & owner); - - /// Initialize the toolbars using the backend database. - void init(); - - /// Show/hide the named toolbar. - void display(std::string const & name, bool show); - - /// get toolbar info - ToolbarInfo * getToolbarInfo(std::string const & name); - - /** toggle the state of toolbars (on/off/auto). Skip "auto" - * when allowauto is false. - */ - void toggleToolbarState(std::string const & name, bool allowauto); - - /// Update the state of the toolbars. - void update(bool in_math, bool in_table, bool review, - bool in_mathmacrotemplate); - - /// Is the Toolbar currently visible? - bool visible(std::string const & name) const; - - /// save toolbar information - void saveToolbarInfo(); - - /// Show or hide the command buffer. - void showCommandBuffer(bool show_it); - - /// toggle visibility of toolbars and save its flags for return - void toggleFullScreen(bool start_full_screen); - -private: - /// Add a new toolbar. if newline==true, start from a new line - void add(ToolbarInfo const & tbinfo, bool newline); - - /// Show or hide a toolbar. - void displayToolbar(ToolbarInfo const & tbinfo, bool show); - - /// Update the state of the icons - void updateIcons(); - - // load flags with saved values - void initFlags(ToolbarInfo & tbinfo); - - /// The parent window. - GuiView & owner_; - - /// Toolbar store providing access to individual toolbars by name. - typedef std::map ToolbarsMap; - ToolbarsMap toolbars_; - - /// The last textclass layout list in the layout choice selector - DocumentClass * last_textclass_; -}; - - -} // namespace frontend -} // namespace lyx - -#endif // GUI_TOOLBARS_H diff --git a/src/frontends/qt4/GuiView.cpp b/src/frontends/qt4/GuiView.cpp index 323f61646a..bc01a1c716 100644 --- a/src/frontends/qt4/GuiView.cpp +++ b/src/frontends/qt4/GuiView.cpp @@ -141,11 +141,14 @@ private: QPixmap splash_; }; -} // namespace anon - +/// Toolbar store providing access to individual toolbars by name. +typedef std::map ToolbarMap; typedef boost::shared_ptr DialogPtr; +} // namespace anon + + struct GuiView::GuiViewPrivate { GuiViewPrivate() @@ -170,7 +173,6 @@ struct GuiView::GuiViewPrivate delete splitter_; delete bg_widget_; delete stack_widget_; - delete toolbars_; } QMenu * toolBarPopup(GuiView * parent) @@ -244,7 +246,7 @@ public: QStackedWidget * stack_widget_; BackgroundWidget * bg_widget_; /// view's toolbars - GuiToolbars * toolbars_; + ToolbarMap toolbars_; /// The main layout box. /** * \warning Don't Delete! The layout box is actually owned by @@ -281,7 +283,7 @@ GuiView::GuiView(int id) : d(*new GuiViewPrivate), id_(id) { // GuiToolbars *must* be initialised before the menu bar. - d.toolbars_ = new GuiToolbars(*this); + constructToolbars(); // set ourself as the current view. This is needed for the menu bar // filling, at least for the static special menu item on Mac. Otherwise @@ -320,12 +322,17 @@ GuiView::GuiView(int id) // with some window manager under X11. setMinimumSize(300, 200); - if (!lyxrc.allow_geometry_session) + // Now take care of session management. + QSettings settings; + + if (!lyxrc.allow_geometry_session) { // No session handling, default to a sane size. setGeometry(50, 50, 690, 510); + initToolbars(); + settings.clear(); + return; + } - // Now take care of session management. - QSettings settings; QString const key = "view-" + QString::number(id_); #ifdef Q_WS_X11 QPoint pos = settings.value(key + "/pos", QPoint(50, 50)).toPoint(); @@ -336,6 +343,9 @@ GuiView::GuiView(int id) if (!restoreGeometry(settings.value(key + "/geometry").toByteArray())) setGeometry(50, 50, 690, 510); #endif + if (!restoreState(settings.value(key + "/layout").toByteArray(), 0)) + initToolbars(); + setIconSize(settings.value(key + "/icon_size").toSize()); } @@ -346,6 +356,83 @@ GuiView::~GuiView() } +GuiToolbar * GuiView::toolbar(string const & name) +{ + ToolbarMap::iterator it = d.toolbars_.find(name); + if (it != d.toolbars_.end()) + return it->second; + + LYXERR(Debug::GUI, "Toolbar::display: no toolbar named " << name); + message(bformat(_("Unknown toolbar \"%1$s\""), from_utf8(name))); + return 0; +} + + +void GuiView::constructToolbars() +{ + ToolbarMap::iterator it = d.toolbars_.begin(); + for (; it != d.toolbars_.end(); ++it) + delete it->second; + d.toolbars_.clear(); + + // extracts the toolbars from the backend + Toolbars::Infos::iterator cit = guiApp->toolbars().begin(); + Toolbars::Infos::iterator end = guiApp->toolbars().end(); + for (; cit != end; ++cit) + d.toolbars_[cit->name] = new GuiToolbar(*cit, *this); +} + + +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 = true; + tb->setVisible(false); + tb->setVisibility(visibility); + + if (visibility & Toolbars::TOP) { + if (newline) + addToolBarBreak(Qt::TopToolBarArea); + addToolBar(Qt::TopToolBarArea, tb); + } + + if (visibility & Toolbars::BOTTOM) { + // Qt < 4.2.2 cannot handle ToolBarBreak on non-TOP dock. +#if (QT_VERSION >= 0x040202) + addToolBarBreak(Qt::BottomToolBarArea); +#endif + addToolBar(Qt::BottomToolBarArea, tb); + } + + if (visibility & Toolbars::LEFT) { + // Qt < 4.2.2 cannot handle ToolBarBreak on non-TOP dock. +#if (QT_VERSION >= 0x040202) + addToolBarBreak(Qt::LeftToolBarArea); +#endif + addToolBar(Qt::LeftToolBarArea, tb); + } + + if (visibility & Toolbars::RIGHT) { + // Qt < 4.2.2 cannot handle ToolBarBreak on non-TOP dock. +#if (QT_VERSION >= 0x040202) + addToolBarBreak(Qt::RightToolBarArea); +#endif + addToolBar(Qt::RightToolBarArea, tb); + } + + if (visibility & Toolbars::ON) + tb->setVisible(true); + } +} + + TocModels & GuiView::tocModels() { return d.toc_models_; @@ -428,7 +515,7 @@ void GuiView::closeEvent(QCloseEvent * close_event) // Save toolbars configuration if (isFullScreen()) { - d.toolbars_->toggleFullScreen(!isFullScreen()); +// d.toolbars_->toggleFullScreen(!isFullScreen()); updateDialogs(); } @@ -447,7 +534,11 @@ void GuiView::closeEvent(QCloseEvent * close_event) settings.setValue(key + "/geometry", saveGeometry()); #endif settings.setValue(key + "/icon_size", iconSize()); - d.toolbars_->saveToolbarInfo(); + settings.setValue(key + "/layout", saveState(0)); + + ToolbarMap::iterator end = d.toolbars_.end(); + for (ToolbarMap::iterator it = d.toolbars_.begin(); it != end; ++it) + it->second->saveSession(); // Now take care of all other dialogs: map::const_iterator it = d.dialogs_.begin(); for (; it!= d.dialogs_.end(); ++it) @@ -699,53 +790,6 @@ void GuiView::setBusy(bool busy) } -GuiToolbar * GuiView::makeToolbar(ToolbarInfo const & tbinfo, bool newline) -{ - GuiToolbar * toolBar = new GuiToolbar(tbinfo, *this); - - if (tbinfo.flags & ToolbarInfo::TOP) { - if (newline) - addToolBarBreak(Qt::TopToolBarArea); - addToolBar(Qt::TopToolBarArea, toolBar); - } - - if (tbinfo.flags & ToolbarInfo::BOTTOM) { -// Qt < 4.2.2 cannot handle ToolBarBreak on non-TOP dock. -#if (QT_VERSION >= 0x040202) - if (newline) - addToolBarBreak(Qt::BottomToolBarArea); -#endif - addToolBar(Qt::BottomToolBarArea, toolBar); - } - - if (tbinfo.flags & ToolbarInfo::LEFT) { -// Qt < 4.2.2 cannot handle ToolBarBreak on non-TOP dock. -#if (QT_VERSION >= 0x040202) - if (newline) - addToolBarBreak(Qt::LeftToolBarArea); -#endif - addToolBar(Qt::LeftToolBarArea, toolBar); - } - - if (tbinfo.flags & ToolbarInfo::RIGHT) { -// Qt < 4.2.2 cannot handle ToolBarBreak on non-TOP dock. -#if (QT_VERSION >= 0x040202) - if (newline) - addToolBarBreak(Qt::RightToolBarArea); -#endif - addToolBar(Qt::RightToolBarArea, toolBar); - } - - // The following does not work so I cannot restore to exact toolbar location - /* - ToolbarSection::ToolbarInfo & tbinfo = LyX::ref().session().toolbars().load(tbinfo.name); - toolBar->move(tbinfo.posx, tbinfo.posy); - */ - - return toolBar; -} - - GuiWorkArea * GuiView::workArea(Buffer & buffer) { if (TabWorkArea * twa = d.currentTabWorkArea()) @@ -846,6 +890,7 @@ void GuiView::updateLayoutList() void GuiView::updateToolbars() { + ToolbarMap::iterator end = d.toolbars_.end(); if (d.current_work_area_) { bool const math = d.current_work_area_->bufferView().cursor().inMathed(); @@ -857,9 +902,11 @@ void GuiView::updateToolbars() bool const mathmacrotemplate = lyx::getStatus(FuncRequest(LFUN_IN_MATHMACROTEMPLATE)).enabled(); - d.toolbars_->update(math, table, review, mathmacrotemplate); + for (ToolbarMap::iterator it = d.toolbars_.begin(); it != end; ++it) + it->second->update(math, table, review, mathmacrotemplate); } else - d.toolbars_->update(false, false, false, false); + for (ToolbarMap::iterator it = d.toolbars_.begin(); it != end; ++it) + it->second->update(false, false, false, false); } @@ -1014,7 +1061,8 @@ bool GuiView::getStatus(FuncRequest const & cmd, FuncStatus & flag) break; case LFUN_TOOLBAR_TOGGLE: - flag.setOnOff(d.toolbars_->visible(cmd.getArg(0))); + if (GuiToolbar * t = toolbar(cmd.getArg(0))) + flag.setOnOff(t->isVisible()); break; case LFUN_UI_TOGGLE: @@ -1693,7 +1741,10 @@ bool GuiView::dispatch(FuncRequest const & cmd) case LFUN_COMMAND_EXECUTE: { bool const show_it = cmd.argument() != "off"; - d.toolbars_->showCommandBuffer(show_it); + // FIXME: this is a hack, "minibuffer" should not be + // hardcoded. + if (GuiToolbar * t = toolbar("minibuffer")) + t->setVisible(show_it); break; } case LFUN_DROP_LAYOUTS_CHOICE: @@ -1747,32 +1798,8 @@ bool GuiView::dispatch(FuncRequest const & cmd) case LFUN_TOOLBAR_TOGGLE: { string const name = cmd.getArg(0); - bool const allowauto = cmd.getArg(1) == "allowauto"; - // it is possible to get current toolbar status like this,... - // but I decide to obey the order of Toolbars::flags - // and disregard real toolbar status. - // toolbars_->saveToolbarInfo(); - // - // toggle state on/off/auto - d.toolbars_->toggleToolbarState(name, allowauto); - // update toolbar - updateToolbars(); - - ToolbarInfo * tbi = d.toolbars_->getToolbarInfo(name); - if (!tbi) { - message(bformat(_("Unknown toolbar \"%1$s\""), from_utf8(name))); - break; - } - docstring state; - if (tbi->flags & ToolbarInfo::ON) - state = _("on"); - else if (tbi->flags & ToolbarInfo::OFF) - state = _("off"); - else if (tbi->flags & ToolbarInfo::AUTO) - state = _("auto"); - - message(bformat(_("Toolbar \"%1$s\" state set to %2$s"), - _(tbi->gui_name), state)); + if (GuiToolbar * t = toolbar(name)) + t->toggle(); break; } @@ -1959,8 +1986,12 @@ void GuiView::lfunUiToggle(FuncRequest const & cmd) return; } - if (lyxrc.full_screen_toolbars) - d.toolbars_->toggleFullScreen(!isFullScreen()); + if (lyxrc.full_screen_toolbars) { + ToolbarMap::iterator end = d.toolbars_.end(); + for (ToolbarMap::iterator it = d.toolbars_.begin(); it != end; ++it) + ; //it->second->toggleFullScreen(!isFullScreen()); + } +// d.toolbars_->toggleFullScreen(!isFullScreen()); if (isFullScreen()) { for (int i = 0; i != d.splitter_->count(); ++i) @@ -2063,7 +2094,7 @@ void GuiView::resetDialogs() theLyXFunc().setLyXView(0); // FIXME: the "math panels" toolbar takes an awful lot of time to // initialise so we don't do that for the time being. - //d.toolbars_->init(); + //initToolbars(); guiApp->menus().fillMenuBar(menuBar(), this); if (d.layout_) d.layout_->updateContents(true); diff --git a/src/frontends/qt4/GuiView.h b/src/frontends/qt4/GuiView.h index dee533fec7..c0530c78fa 100644 --- a/src/frontends/qt4/GuiView.h +++ b/src/frontends/qt4/GuiView.h @@ -245,6 +245,12 @@ public: void updateCompletion(Cursor & cur, bool start, bool keep); private: + /// + GuiToolbar * toolbar(std::string const & name); + /// + void constructToolbars(); + /// + void initToolbars(); /// void lfunUiToggle(FuncRequest const & cmd); diff --git a/src/frontends/qt4/Makefile.am b/src/frontends/qt4/Makefile.am index cb7bf6770c..1ad2e1e5d2 100644 --- a/src/frontends/qt4/Makefile.am +++ b/src/frontends/qt4/Makefile.am @@ -116,7 +116,6 @@ SOURCEFILES = \ GuiThesaurus.cpp \ GuiToc.cpp \ GuiToolbar.cpp \ - GuiToolbars.cpp \ GuiView.cpp \ GuiViewSource.cpp \ GuiVSpace.cpp \ @@ -149,7 +148,6 @@ NOMOCHEADER = \ GuiKeySymbol.h \ GuiMath.h \ GuiPainter.h \ - GuiToolbars.h \ LaTeXHighlighter.h \ qt_i18n.h \ qt_helpers.h \ diff --git a/src/frontends/qt4/Menus.cpp b/src/frontends/qt4/Menus.cpp index 505167b805..f72582dc41 100644 --- a/src/frontends/qt4/Menus.cpp +++ b/src/frontends/qt4/Menus.cpp @@ -1004,27 +1004,12 @@ void MenuDefinition::expandPasteRecent() void MenuDefinition::expandToolbars() { - // // extracts the toolbars from the backend Toolbars::Infos::const_iterator cit = guiApp->toolbars().begin(); Toolbars::Infos::const_iterator end = guiApp->toolbars().end(); - for (; cit != end; ++cit) { - QString label = qt_(cit->gui_name); - // frontends are not supposed to turn on/off toolbars, - // if they cannot update Toolbars::flags. That - // is to say, ToolbarsBackend::flags should reflect - // the true state of toolbars. - // - // menu is displayed as - // on/off review - // and - // review (auto) - // in the case of auto. - if (cit->flags & ToolbarInfo::AUTO) - label += qt_(" (auto)"); - add(MenuItem(MenuItem::Command, label, - FuncRequest(LFUN_TOOLBAR_TOGGLE, cit->name + " allowauto"))); + add(MenuItem(MenuItem::Command, qt_(cit->gui_name), + FuncRequest(LFUN_TOOLBAR_TOGGLE, cit->name))); } } diff --git a/src/frontends/qt4/Toolbars.cpp b/src/frontends/qt4/Toolbars.cpp index 99ece2f2b1..33c444d0e5 100644 --- a/src/frontends/qt4/Toolbars.cpp +++ b/src/frontends/qt4/Toolbars.cpp @@ -32,18 +32,6 @@ namespace frontend { namespace { -class ToolbarNamesEqual -{ -public: - ToolbarNamesEqual(string const & name) : name_(name) {} - bool operator()(ToolbarInfo const & tbinfo) const - { - return tbinfo.name == name_; - } -private: - string name_; -}; - } // namespace anon @@ -65,10 +53,6 @@ ToolbarItem::ToolbarItem(Type type, string const & name, docstring const & label } -ToolbarItem::~ToolbarItem() -{} - - void ToolbarInfo::add(ToolbarItem const & item) { items.push_back(item); @@ -207,12 +191,6 @@ ToolbarInfo & ToolbarInfo::read(Lexer & lex) ///////////////////////////////////////////////////////////////////////// -Toolbars::Toolbars() -{ - fullScreenWindows = 0; -} - - void Toolbars::readToolbars(Lexer & lex) { enum { @@ -242,7 +220,7 @@ void Toolbars::readToolbars(Lexer & lex) case TO_TOOLBAR: { ToolbarInfo tbinfo; tbinfo.read(lex); - toolbars.push_back(tbinfo); + toolbar_info_.push_back(tbinfo); break; } case TO_ENDTOOLBARSET: @@ -276,19 +254,7 @@ void Toolbars::readToolbarSettings(Lexer & lex) if (!compare_ascii_no_case(name, "end")) return; - Infos::iterator tcit = toolbars.begin(); - Infos::iterator tend = toolbars.end(); - for (; tcit != tend; ++tcit) { - if (tcit->name == name) - break; - } - - if (tcit == tend) { - LYXERR0("Toolbars: undefined toolbar " << name); - return; - } - - tcit->flags = static_cast(0); + int visibility = 0; string flagstr = lex.getString(); lex.next(true); vector flags = getVectorFromString(flagstr); @@ -297,58 +263,65 @@ void Toolbars::readToolbarSettings(Lexer & lex) vector::const_iterator end = flags.end(); for (; cit != end; ++cit) { - int flag = 0; + Visibility flag = ON; if (!compare_ascii_no_case(*cit, "off")) - flag = ToolbarInfo::OFF; + flag = OFF; else if (!compare_ascii_no_case(*cit, "on")) - flag = ToolbarInfo::ON; + flag = ON; else if (!compare_ascii_no_case(*cit, "math")) - flag = ToolbarInfo::MATH; + flag = MATH; else if (!compare_ascii_no_case(*cit, "table")) - flag = ToolbarInfo::TABLE; + flag = TABLE; else if (!compare_ascii_no_case(*cit, "mathmacrotemplate")) - flag = ToolbarInfo::MATHMACROTEMPLATE; + flag = MATHMACROTEMPLATE; else if (!compare_ascii_no_case(*cit, "review")) - flag = ToolbarInfo::REVIEW; + flag = REVIEW; else if (!compare_ascii_no_case(*cit, "top")) - flag = ToolbarInfo::TOP; + flag = TOP; else if (!compare_ascii_no_case(*cit, "bottom")) - flag = ToolbarInfo::BOTTOM; + flag = BOTTOM; else if (!compare_ascii_no_case(*cit, "left")) - flag = ToolbarInfo::LEFT; + flag = LEFT; else if (!compare_ascii_no_case(*cit, "right")) - flag = ToolbarInfo::RIGHT; + flag = RIGHT; else if (!compare_ascii_no_case(*cit, "auto")) - flag = ToolbarInfo::AUTO; + flag = AUTO; else { LYXERR(Debug::ANY, "Toolbars::readToolbarSettings: unrecognised token:`" << *cit << '\''); + continue; } - tcit->flags = static_cast(tcit->flags | flag); + visibility |= flag; } + toolbar_visibility_[name] = visibility; - usedtoolbars.push_back(*tcit); + if (visibility >= MATH) { + if (ToolbarInfo const * ti = info(name)) + const_cast(ti)->gui_name += " (auto)"; + } } } -ToolbarInfo const * Toolbars::getDefinedToolbarInfo(string const & name) const +ToolbarInfo const * Toolbars::info(std::string const & name) const { - Infos::const_iterator it = find_if(toolbars.begin(), toolbars.end(), ToolbarNamesEqual(name)); - if (it == toolbars.end()) - return 0; - return &(*it); + Infos::const_iterator end = toolbar_info_.end(); + for (Infos::const_iterator it = toolbar_info_.begin(); it != end; ++it) + if (it->name == name) + return &(*it); + return 0; } -ToolbarInfo * Toolbars::getUsedToolbarInfo(string const &name) +int Toolbars::defaultVisibility(std::string const & name) const { - Infos::iterator it = find_if(usedtoolbars.begin(), usedtoolbars.end(), ToolbarNamesEqual(name)); - if (it == usedtoolbars.end()) - return 0; - return &(*it); + map::const_iterator it = toolbar_visibility_.find(name); + if (it != toolbar_visibility_.end()) + return it->second; + return OFF | BOTTOM; } + } // namespace frontend } // namespace lyx diff --git a/src/frontends/qt4/Toolbars.h b/src/frontends/qt4/Toolbars.h index b4a9182e64..07e1e47ff8 100644 --- a/src/frontends/qt4/Toolbars.h +++ b/src/frontends/qt4/Toolbars.h @@ -51,8 +51,6 @@ public: std::string const & name = std::string(), docstring const & label = docstring()); - ~ToolbarItem(); - /// item type Type type_; /// action @@ -67,20 +65,6 @@ public: /// class ToolbarInfo { public: - /// toolbar flags - enum Flags { - ON = 1, //< show - OFF = 2, //< do not show - MATH = 4, //< show when in math - TABLE = 8, //< show when in table - TOP = 16, //< show at top - BOTTOM = 32, //< show at bottom - LEFT = 64, //< show at left - RIGHT = 128, //< show at right - REVIEW = 256, //< show when change tracking is enabled - AUTO = 512, //< only if AUTO is set, when MATH, TABLE and REVIEW is used - MATHMACROTEMPLATE = 1024 //< show in math macro template - }; /// the toolbar items typedef std::vector Items; @@ -95,10 +79,6 @@ public: std::string gui_name; /// toolbar contents Items items; - /// flags - Flags flags; - /// store flags when coming to fullscreen mode - Flags before_fullscreen; /// read a toolbar from the file ToolbarInfo & read(Lexer &); @@ -112,18 +92,33 @@ private: /// class Toolbars { public: + /// toolbar visibility flags + enum Visibility { + ON = 1, //< show + OFF = 2, //< do not show + TOP = 4, //< show at top + BOTTOM = 8, //< show at bottom + LEFT = 16, //< show at left + RIGHT = 32, //< show at right + AUTO = 64, //< only if AUTO is set, when MATH, TABLE and REVIEW is used + MATH = 128, //< show when in math + TABLE = 256, //< show when in table + REVIEW = 512, //< show when change tracking is enabled + MATHMACROTEMPLATE = 1024 //< show in math macro template + }; + typedef std::vector Infos; - Toolbars(); + Toolbars() {} /// iterator for all toolbars - Infos::const_iterator begin() const { return usedtoolbars.begin(); } + Infos::const_iterator begin() const { return toolbar_info_.begin(); } - Infos::const_iterator end() const { return usedtoolbars.end(); } + Infos::const_iterator end() const { return toolbar_info_.end(); } - Infos::iterator begin() { return usedtoolbars.begin(); } + Infos::iterator begin() { return toolbar_info_.begin(); } - Infos::iterator end() { return usedtoolbars.end(); } + Infos::iterator end() { return toolbar_info_.end(); } /// read toolbars from the file void readToolbars(Lexer &); @@ -132,20 +127,15 @@ public: void readToolbarSettings(Lexer &); /// - ToolbarInfo const * getDefinedToolbarInfo(std::string const & name) const; + ToolbarInfo const * info(std::string const & name) const; /// - ToolbarInfo * getUsedToolbarInfo(std::string const & name); - - // FIXME should be deleted when every window has its own toolbar config. - /// number of toggleFullScreen calls, i.e. number of FullScreen windows. - int fullScreenWindows; + int defaultVisibility(std::string const & name) const; private: /// all the defined toolbars - Infos toolbars; - - /// toolbars listed - Infos usedtoolbars; + Infos toolbar_info_; + /// + std::map toolbar_visibility_; }; } // namespace frontend