]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiToolbar.cpp
Merge branch 'biblatex2' of git.lyx.org:features into biblatex2
[lyx.git] / src / frontends / qt4 / GuiToolbar.cpp
index ec80a0b4300dc7c1912d829c86ad341df19cc533..36a7326a5e60850bfbd1932b036689b10c2625d3 100644 (file)
@@ -32,6 +32,7 @@
 #include "KeyMap.h"
 #include "LyX.h"
 #include "LyXRC.h"
+#include "Session.h"
 
 #include "support/debug.h"
 #include "support/gettext.h"
@@ -53,7 +54,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 +70,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_)
@@ -98,12 +116,12 @@ Action * GuiToolbar::addItem(ToolbarItem const & item)
        QString text = toqstr(item.label_);
        // Get the keys bound to this action, but keep only the
        // first one later
-       KeyMap::Bindings bindings = theTopLevelKeymap().findBindings(item.func_);
-       if (bindings.size())
+       KeyMap::Bindings bindings = theTopLevelKeymap().findBindings(*item.func_);
+       if (!bindings.empty())
                text += " [" + toqstr(bindings.begin()->print(KeySequence::ForGui)) + "]";
 
-       Action * act = new Action(&owner_, getIcon(item.func_, false),
-               text, item.func_, text, this);
+       Action * act = new Action(item.func_, getIcon(*item.func_, false), text,
+                                 text, this);
        actions_.append(act);
        return act;
 }
@@ -130,7 +148,7 @@ public:
                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));
+                       setIcon(getIcon(*tbinfo->items.begin()->func_, true));
        }
 
        void mousePressEvent(QMouseEvent * e)
@@ -155,7 +173,7 @@ public:
                ToolbarInfo::item_iterator it = tbinfo->items.begin();
                ToolbarInfo::item_iterator const end = tbinfo->items.end();
                for (; it != end; ++it)
-                       if (!getStatus(it->func_).unknown())
+                       if (!getStatus(*it->func_).unknown())
                                panel->addButton(bar_->addItem(*it));
 
                QToolButton::mousePressEvent(e);
@@ -176,11 +194,12 @@ MenuButton::MenuButton(GuiToolbar * bar, ToolbarItem const & item, bool const st
        QString const name = toqstr(tbitem_.name_);
        QStringList imagedirs;
        imagedirs << "images/math/" << "images/";
-       for (int i = 0; i < imagedirs.size(); ++i) { 
+       for (int i = 0; i < imagedirs.size(); ++i) {
                QString imagedir = imagedirs.at(i);
-               FileName const fname = imageLibFileSearch(imagedir, name, "png");
+               FileName const fname = imageLibFileSearch(imagedir, name, "svgz,png",
+                       theGuiApp()->imageSearchMode());
                if (fname.exists()) {
-                       setIcon(QIcon(getPixmap(imagedir, name, "png")));
+                       setIcon(QIcon(getPixmap(imagedir, name, "svgz,png")));
                        break;
                }
        }
@@ -209,7 +228,7 @@ void MenuButton::initialize()
        ToolbarInfo::item_iterator it = tbinfo->items.begin();
        ToolbarInfo::item_iterator const end = tbinfo->items.end();
        for (; it != end; ++it)
-               if (!getStatus(it->func_).unknown())
+               if (!getStatus(*it->func_).unknown())
                        m->add(bar_->addItem(*it));
        setMenu(m);
 }
@@ -272,7 +291,7 @@ void GuiToolbar::add(ToolbarItem const & item)
                tb->setToolTip(label);
                tb->setStatusTip(label);
                tb->setText(label);
-               InsertTableWidget * iv = new InsertTableWidget(owner_, tb);
+               InsertTableWidget * iv = new InsertTableWidget(tb);
                connect(tb, SIGNAL(clicked(bool)), iv, SLOT(show(bool)));
                connect(iv, SIGNAL(visible(bool)), tb, SLOT(setChecked(bool)));
                connect(this, SIGNAL(updated()), iv, SLOT(updateParent()));
@@ -292,7 +311,7 @@ void GuiToolbar::add(ToolbarItem const & item)
                break;
                }
        case ToolbarItem::COMMAND: {
-               if (!getStatus(item.func_).unknown())
+               if (!getStatus(*item.func_).unknown())
                        addAction(addItem(item));
                break;
                }
@@ -302,16 +321,12 @@ void GuiToolbar::add(ToolbarItem const & item)
 }
 
 
-void GuiToolbar::update(bool in_math, bool in_table, bool in_review, 
-       bool in_mathmacrotemplate, bool in_ipa)
+void GuiToolbar::update(int context)
 {
        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))
-                       || (in_ipa && (visibility_ & Toolbars::IPA));
-               setVisible(show_it);
+               setVisible(visibility_ & context & Toolbars::ALLOWAUTO);
+               if (isVisible() && commandBuffer() && (context & Toolbars::MINIBUFFER_FOCUS))
+                       commandBuffer()->setFocus();
        }
 
        // update visible toolbars only