]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiToolbar.cpp
Properly track the lifetime of signals2::slots (#8261)
[lyx.git] / src / frontends / qt4 / GuiToolbar.cpp
index 6b5170d481974484e387c7c76c0b5c4274633685..bc720d5edd55f0263541832603f57307e9696265 100644 (file)
@@ -61,8 +61,6 @@ GuiToolbar::GuiToolbar(ToolbarInfo const & tbinfo, GuiView & owner)
        connect(&owner, SIGNAL(iconSizeChanged(QSize)), this,
                SLOT(setIconSize(QSize)));
 
-       // Toolbar dragging is allowed.
-       setMovable(true);
        // This is used by QMainWindow::restoreState for proper main window state
        // restauration.
        setObjectName(toqstr(tbinfo.name));
@@ -116,12 +114,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_);
+       KeyMap::Bindings bindings = theTopLevelKeymap().findBindings(*item.func_);
        if (!bindings.empty())
                text += " [" + toqstr(bindings.begin()->print(KeySequence::ForGui)) + "]";
 
-       Action * act = new Action(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;
 }
@@ -148,7 +146,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)
@@ -173,7 +171,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);
@@ -196,10 +194,10 @@ MenuButton::MenuButton(GuiToolbar * bar, ToolbarItem const & item, bool const st
        imagedirs << "images/math/" << "images/";
        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;
                }
        }
@@ -228,7 +226,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);
 }
@@ -311,7 +309,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;
                }
@@ -321,16 +319,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
@@ -361,6 +355,7 @@ void GuiToolbar::saveSession() const
 {
        QSettings settings;
        settings.setValue(sessionKey() + "/visibility", visibility_);
+       settings.setValue(sessionKey() + "/movability", isMovable());
 }
 
 
@@ -377,6 +372,9 @@ void GuiToolbar::restoreSession()
                        guiApp->toolbars().defaultVisibility(fromqstr(objectName()));
        }
        setVisibility(visibility);
+
+       int movability = settings.value(sessionKey() + "/movability", true).toBool();
+       setMovable(movability);
 }
 
 
@@ -412,6 +410,27 @@ void GuiToolbar::toggle()
                qstring_to_ucs4(windowTitle()), state));
 }
 
+void GuiToolbar::movable(bool silent)
+{
+       // toggle movability
+       setMovable(!isMovable());
+
+       // manual update avoids bug in qt that the drag handle is not removed
+       // properly, e.g. in Windows
+       Q_EMIT update();
+
+       // silence for toggling of many toolbars for performance
+       if (!silent) {
+               docstring state;
+               if (isMovable())
+                       state = _("movable");
+               else
+                       state = _("immovable");
+               owner_.message(bformat(_("Toolbar \"%1$s\" state set to %2$s"),
+                       qstring_to_ucs4(windowTitle()), state));
+       }
+}
+
 } // namespace frontend
 } // namespace lyx