]> git.lyx.org Git - features.git/commitdiff
Introduce class PaletteButton in order to delay the icon palette initialisation up...
authorAbdelrazak Younes <younes@lyx.org>
Wed, 16 Jan 2008 18:27:24 +0000 (18:27 +0000)
committerAbdelrazak Younes <younes@lyx.org>
Wed, 16 Jan 2008 18:27:24 +0000 (18:27 +0000)
I think the same thing should be done for POPUPMENU.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@22603 a592a061-630c-0410-9148-cb99ea01b6c8

src/frontends/qt4/GuiToolbar.cpp
src/frontends/qt4/GuiToolbar.h

index 6b819695518ee47e192d8eb5f77acc315f297cab..77039830ba40a6935c3251b5f6beb0aae4268f87 100644 (file)
@@ -389,6 +389,62 @@ Action * GuiToolbar::addItem(ToolbarItem const & item)
        return act;
 }
 
+namespace {
+
+class PaletteButton : public QToolButton
+{
+private:
+       GuiToolbar * bar_;
+       ToolbarItem const & tbitem_;
+       IconPalette * panel_;
+       bool initialized_;
+public:
+       PaletteButton(GuiToolbar * bar, ToolbarItem const & item)
+               : QToolButton(bar), bar_(bar), tbitem_(item), initialized_(false)
+       {
+               setToolTip(qt_(to_ascii(tbitem_.label_)));
+               setStatusTip(qt_(to_ascii(tbitem_.label_)));
+               setText(qt_(to_ascii(tbitem_.label_)));
+               connect(bar_, SIGNAL(iconSizeChanged(QSize)),
+                       this, SLOT(setIconSize(QSize)));
+               panel_ = new IconPalette(this);
+               panel_->setWindowTitle(qt_(to_ascii(tbitem_.label_)));
+               connect(bar_, SIGNAL(updated()), panel_, SLOT(updateParent()));
+               setCheckable(true);
+               connect(this, SIGNAL(clicked(bool)), panel_, SLOT(setVisible(bool)));
+               connect(panel_, SIGNAL(visible(bool)), this, SLOT(setChecked(bool)));
+       }
+
+       void showEvent(QShowEvent * e)
+       {
+               if (initialized_) {
+                       QToolButton::showEvent(e);
+                       return;
+               }
+
+               initialized_ = true;
+
+               ToolbarInfo const * tbinfo = 
+                       toolbarbackend.getDefinedToolbarInfo(tbitem_.name_);
+               if (!tbinfo) {
+                       lyxerr << "Unknown toolbar " << tbitem_.name_ << endl;
+                       return;
+               }
+               ToolbarInfo::item_iterator it = tbinfo->items.begin();
+               ToolbarInfo::item_iterator const end = tbinfo->items.end();
+               for (; it != end; ++it) {
+                       if (!getStatus(it->func_).unknown()) {
+                               panel_->addButton(bar_->addItem(*it));
+                               // use the icon of first action for the toolbar button
+                               if (it == tbinfo->items.begin())
+                                       setIcon(getIcon(it->func_, true));
+                       }
+               }
+               QToolButton::showEvent(e);
+       }
+};
+
+}
 
 void GuiToolbar::add(ToolbarItem const & item)
 {
@@ -420,36 +476,10 @@ void GuiToolbar::add(ToolbarItem const & item)
                addWidget(tb);
                break;
                }
-       case ToolbarItem::ICONPALETTE: {
-               QToolButton * tb = new QToolButton(this);
-               tb->setToolTip(qt_(to_ascii(item.label_)));
-               tb->setStatusTip(qt_(to_ascii(item.label_)));
-               tb->setText(qt_(to_ascii(item.label_)));
-               connect(this, SIGNAL(iconSizeChanged(QSize)),
-                       tb, SLOT(setIconSize(QSize)));
-               IconPalette * panel = new IconPalette(tb);
-               panel->setWindowTitle(qt_(to_ascii(item.label_)));
-               connect(this, SIGNAL(updated()), panel, SLOT(updateParent()));
-               ToolbarInfo const * tbinfo = toolbarbackend.getDefinedToolbarInfo(item.name_);
-               if (!tbinfo) {
-                       lyxerr << "Unknown toolbar " << item.name_ << endl;
-                       break;
-               }
-               ToolbarInfo::item_iterator it = tbinfo->items.begin();
-               ToolbarInfo::item_iterator const end = tbinfo->items.end();
-               for (; it != end; ++it)
-                       if (!getStatus(it->func_).unknown()) {
-                               panel->addButton(addItem(*it));
-                               // use the icon of first action for the toolbar button
-                               if (it == tbinfo->items.begin())
-                                       tb->setIcon(getIcon(it->func_, true));
-                       }
-               tb->setCheckable(true);
-               connect(tb, SIGNAL(clicked(bool)), panel, SLOT(setVisible(bool)));
-               connect(panel, SIGNAL(visible(bool)), tb, SLOT(setChecked(bool)));
-               addWidget(tb);
+       case ToolbarItem::ICONPALETTE:
+               addWidget(new PaletteButton(this, item));
                break;
-               }
+
        case ToolbarItem::POPUPMENU: {
                QToolButton * tb = new QToolButton;
                tb->setPopupMode(QToolButton::InstantPopup);
index 0d0dceffba54d34cc59f3391da04bb10b94811d4..3d0dfc810531f1b5925cd1f87ea0c743829cd882 100644 (file)
@@ -73,11 +73,12 @@ public:
        ///
        GuiCommandBuffer * commandBuffer() { return command_buffer_; }
 
+       Action * addItem(ToolbarItem const & item);
+
 Q_SIGNALS:
        void updated();
 
 private:
-       Action * addItem(ToolbarItem const & item);
 
        QList<Action *> actions_;
        GuiView & owner_;