remember the last selection on the view/update popup button.

This introduces a new "sticky" popup button.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@29309 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Jürgen Spitzmüller 2009-04-18 10:44:44 +00:00
parent 30961c95d9
commit 051a50439d
5 changed files with 95 additions and 49 deletions

View File

@ -208,8 +208,8 @@ ToolbarSet
Item "View Master Document" "master-buffer-view" Item "View Master Document" "master-buffer-view"
Item "Update Master Document" "master-buffer-update" Item "Update Master Document" "master-buffer-update"
Separator Separator
PopupMenu "view-others" "View Other Formats" StickyPopupMenu "view-others" "View Other Formats"
PopupMenu "update-others" "Update Other Formats" StickyPopupMenu "update-others" "Update Other Formats"
End End
Toolbar "view-others" "View Other Formats" Toolbar "view-others" "View Other Formats"

View File

@ -790,56 +790,59 @@ public:
} }
}; };
class MenuButton : public QToolButton }
MenuButton::MenuButton(GuiToolbar * bar, ToolbarItem const & item, bool const sticky)
: QToolButton(bar), bar_(bar), tbitem_(item), initialized_(false)
{ {
private: setPopupMode(QToolButton::InstantPopup);
GuiToolbar * bar_; QString const label = qt_(to_ascii(tbitem_.label_));
ToolbarItem const & tbitem_; setToolTip(label);
bool initialized_; setStatusTip(label);
public: setText(label);
MenuButton(GuiToolbar * bar, ToolbarItem const & item) setIcon(QIcon(getPixmap("images/math/", toqstr(tbitem_.name_), "png")));
: QToolButton(bar), bar_(bar), tbitem_(item), initialized_(false) if (sticky)
{ connect(this, SIGNAL(triggered(QAction *)),
setPopupMode(QToolButton::InstantPopup); this, SLOT(actionTriggered(QAction *)));
QString const label = qt_(to_ascii(tbitem_.label_)); connect(bar, SIGNAL(iconSizeChanged(QSize)),
setToolTip(label); this, SLOT(setIconSize(QSize)));
setStatusTip(label); }
setText(label);
setIcon(QIcon(getPixmap("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);
void MenuButton::mousePressEvent(QMouseEvent * e)
{
if (initialized_) {
QToolButton::mousePressEvent(e); 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);
}
void MenuButton::actionTriggered(QAction * action)
{
QToolButton::setDefaultAction(action);
setPopupMode(QToolButton::DelayedPopup);
} }
@ -879,7 +882,11 @@ void GuiToolbar::add(ToolbarItem const & item)
break; break;
case ToolbarItem::POPUPMENU: { case ToolbarItem::POPUPMENU: {
addWidget(new MenuButton(this, item)); addWidget(new MenuButton(this, item, false));
break;
}
case ToolbarItem::STICKYPOPUPMENU: {
addWidget(new MenuButton(this, item, true));
break; break;
} }
case ToolbarItem::COMMAND: { case ToolbarItem::COMMAND: {

View File

@ -22,6 +22,7 @@
#include <QComboBox> #include <QComboBox>
#include <QList> #include <QList>
#include <QToolBar> #include <QToolBar>
#include <QToolButton>
class QSortFilterProxyModel; class QSortFilterProxyModel;
class QStandardItemModel; class QStandardItemModel;
@ -108,6 +109,31 @@ private:
}; };
class MenuButton : public QToolButton
{
Q_OBJECT
public:
///
MenuButton(GuiToolbar * bar, ToolbarItem const & item,
bool const sticky = false);
///
void mousePressEvent(QMouseEvent * e);
private:
///
GuiToolbar * bar_;
///
ToolbarItem const & tbitem_;
///
bool initialized_;
private Q_SLOTS:
///
void actionTriggered(QAction * action);
};
class GuiToolbar : public QToolBar class GuiToolbar : public QToolBar
{ {
Q_OBJECT Q_OBJECT

View File

@ -71,6 +71,7 @@ ToolbarInfo & ToolbarInfo::read(Lexer & lex)
TO_MINIBUFFER, TO_MINIBUFFER,
TO_TABLEINSERT, TO_TABLEINSERT,
TO_POPUPMENU, TO_POPUPMENU,
TO_STICKYPOPUPMENU,
TO_ICONPALETTE, TO_ICONPALETTE,
}; };
@ -82,6 +83,7 @@ ToolbarInfo & ToolbarInfo::read(Lexer & lex)
{ "minibuffer", TO_MINIBUFFER }, { "minibuffer", TO_MINIBUFFER },
{ "popupmenu", TO_POPUPMENU }, { "popupmenu", TO_POPUPMENU },
{ "separator", TO_SEPARATOR }, { "separator", TO_SEPARATOR },
{ "stickypopupmenu", TO_STICKYPOPUPMENU },
{ "tableinsert", TO_TABLEINSERT } { "tableinsert", TO_TABLEINSERT }
}; };
@ -146,6 +148,15 @@ ToolbarInfo & ToolbarInfo::read(Lexer & lex)
} }
break; break;
case TO_STICKYPOPUPMENU:
if (lex.next(true)) {
string const name = lex.getString();
lex.next(true);
docstring const label = lex.getDocString();
add(ToolbarItem(ToolbarItem::STICKYPOPUPMENU, name, label));
}
break;
case TO_ICONPALETTE: case TO_ICONPALETTE:
if (lex.next(true)) { if (lex.next(true)) {
string const name = lex.getString(); string const name = lex.getString();

View File

@ -38,8 +38,10 @@ public:
LAYOUTS, LAYOUTS,
/// a special widget to insert tabulars /// a special widget to insert tabulars
TABLEINSERT, TABLEINSERT,
/// /// a button that expands a menu
POPUPMENU, POPUPMENU,
/// a button that expands a menu but remembers the last choice
STICKYPOPUPMENU,
/// ///
ICONPALETTE ICONPALETTE
}; };