+namespace {
+
+class PaletteButton : public QToolButton
+{
+private:
+ GuiToolbar * bar_;
+ ToolbarItem const & tbitem_;
+ bool initialized_;
+public:
+ PaletteButton(GuiToolbar * bar, ToolbarItem const & item)
+ : QToolButton(bar), bar_(bar), tbitem_(item), initialized_(false)
+ {
+ QString const label = qt_(to_ascii(tbitem_.label_));
+ setToolTip(label);
+ setStatusTip(label);
+ setText(label);
+ connect(bar_, SIGNAL(iconSizeChanged(QSize)),
+ this, SLOT(setIconSize(QSize)));
+ setCheckable(true);
+ 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));
+ }
+
+ void mousePressEvent(QMouseEvent * e)
+ {
+ if (initialized_) {
+ QToolButton::mousePressEvent(e);
+ return;
+ }
+
+ initialized_ = true;
+
+ ToolbarInfo const * tbinfo = guiApp->toolbars().info(tbitem_.name_);
+ if (!tbinfo) {
+ LYXERR0("Unknown toolbar " << tbitem_.name_);
+ return;
+ }
+ IconPalette * panel = new IconPalette(this);
+ QString const label = qt_(to_ascii(tbitem_.label_));
+ panel->setWindowTitle(label);
+ connect(this, SIGNAL(clicked(bool)), panel, SLOT(setVisible(bool)));
+ connect(panel, SIGNAL(visible(bool)), this, SLOT(setChecked(bool)));
+ 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));
+
+ QToolButton::mousePressEvent(e);
+ }
+};
+
+class MenuButton : public QToolButton
+{
+private:
+ GuiToolbar * bar_;
+ ToolbarItem const & tbitem_;
+ bool initialized_;
+public:
+ MenuButton(GuiToolbar * bar, ToolbarItem const & item)
+ : QToolButton(bar), bar_(bar), tbitem_(item), initialized_(false)
+ {
+ setPopupMode(QToolButton::InstantPopup);
+ QString const label = qt_(to_ascii(tbitem_.label_));
+ setToolTip(label);
+ setStatusTip(label);
+ setText(label);
+ setIcon(QPixmap(":images/math/" + toqstr(tbitem_.name_) + ".png"));
+ connect(bar, SIGNAL(iconSizeChanged(QSize)),
+ this, SLOT(setIconSize(QSize)));
+ }
+
+ void mousePressEvent(QMouseEvent * e)
+ {
+ if (initialized_) {
+ QToolButton::mousePressEvent(e);
+ return;
+ }
+
+ initialized_ = true;
+
+ QString const label = qt_(to_ascii(tbitem_.label_));
+ ButtonMenu * m = new ButtonMenu(label, this);
+ m->setWindowTitle(label);
+ m->setTearOffEnabled(true);
+ connect(bar_, SIGNAL(updated()), m, SLOT(updateParent()));
+ ToolbarInfo const * tbinfo = guiApp->toolbars().info(tbitem_.name_);
+ if (!tbinfo) {
+ LYXERR0("Unknown toolbar " << tbitem_.name_);
+ 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())
+ m->add(bar_->addItem(*it));
+ setMenu(m);
+
+ QToolButton::mousePressEvent(e);
+ }
+};
+
+}
+