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 "Update Master Document" "master-buffer-update"
Separator
PopupMenu "view-others" "View Other Formats"
PopupMenu "update-others" "Update Other Formats"
StickyPopupMenu "view-others" "View Other Formats"
StickyPopupMenu "update-others" "Update Other Formats"
End
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:
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(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);
setPopupMode(QToolButton::InstantPopup);
QString const label = qt_(to_ascii(tbitem_.label_));
setToolTip(label);
setStatusTip(label);
setText(label);
setIcon(QIcon(getPixmap("images/math/", toqstr(tbitem_.name_), "png")));
if (sticky)
connect(this, SIGNAL(triggered(QAction *)),
this, SLOT(actionTriggered(QAction *)));
connect(bar, SIGNAL(iconSizeChanged(QSize)),
this, SLOT(setIconSize(QSize)));
}
void MenuButton::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);
}
void MenuButton::actionTriggered(QAction * action)
{
QToolButton::setDefaultAction(action);
setPopupMode(QToolButton::DelayedPopup);
}
@ -879,7 +882,11 @@ void GuiToolbar::add(ToolbarItem const & item)
break;
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;
}
case ToolbarItem::COMMAND: {

View File

@ -22,6 +22,7 @@
#include <QComboBox>
#include <QList>
#include <QToolBar>
#include <QToolButton>
class QSortFilterProxyModel;
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
{
Q_OBJECT

View File

@ -71,6 +71,7 @@ ToolbarInfo & ToolbarInfo::read(Lexer & lex)
TO_MINIBUFFER,
TO_TABLEINSERT,
TO_POPUPMENU,
TO_STICKYPOPUPMENU,
TO_ICONPALETTE,
};
@ -82,6 +83,7 @@ ToolbarInfo & ToolbarInfo::read(Lexer & lex)
{ "minibuffer", TO_MINIBUFFER },
{ "popupmenu", TO_POPUPMENU },
{ "separator", TO_SEPARATOR },
{ "stickypopupmenu", TO_STICKYPOPUPMENU },
{ "tableinsert", TO_TABLEINSERT }
};
@ -146,6 +148,15 @@ ToolbarInfo & ToolbarInfo::read(Lexer & lex)
}
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:
if (lex.next(true)) {
string const name = lex.getString();

View File

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