blob: e443f8aeb991a01640327b2e69226f81ef5a4bf1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
/*********
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
* Copyright 1999-2014 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
#include "frontend/displaywindow/bttoolbarpopupaction.h"
#include <QAction>
#include <QEvent>
#include <QMenu>
#include <QToolButton>
namespace {
class BtToolButton: public QToolButton {
public:
inline BtToolButton(QWidget *parent = 0)
: QToolButton(parent) {}
private:
virtual inline void nextCheckState() {}
};
} // anonymous namespace
// This class provides a toolbar widget that has a icon plus a right side down arrow
// The icon is typically set to a back or forward arrow and the down arrow has a popup
// menu when clicked. The menu is typicallly populated with history actions.
BtToolBarPopupAction::BtToolBarPopupAction(const QIcon& icon, const QString& text, QObject* parent)
: QWidgetAction(parent), m_icon(icon), m_text(text) {
setText(text);
m_menu = new QMenu();
}
BtToolBarPopupAction::~BtToolBarPopupAction() {
delete m_menu;
}
// return the QMenu object so a popup menu can be constructed
QMenu* BtToolBarPopupAction::popupMenu() const {
return m_menu;
}
QWidget* BtToolBarPopupAction::createWidget(QWidget* parent) {
m_button = new BtToolButton(parent);
setIcon(m_icon);
setToolTip(m_text);
m_button->setDefaultAction(this);
m_button->setPopupMode(QToolButton::MenuButtonPopup);
m_button->setMenu(m_menu);
bool ok = connect(m_button, SIGNAL(pressed()), this, SLOT(buttonPressed()));
Q_ASSERT(ok);;
return m_button;
}
// Slot to emit a triggered signal when the toolbar button is pressed
void BtToolBarPopupAction::buttonPressed() {
emit triggered();
}
// Function to catch the Shortcut event and emit the triggered signal
bool BtToolBarPopupAction::event(QEvent *event) {
if (event->type() == QEvent::Shortcut) {
emit triggered();
return true;
}
return QWidgetAction::event(event);
}
|