Falkon
Develop
Cross-platform Qt-based web browser
buttonwithmenu.h
Go to the documentation of this file.
1
/* ============================================================
2
* Falkon - Qt web browser
3
* Copyright (C) 2010-2017 David Rosca <nowrep@gmail.com>
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation, either version 3 of the License, or
8
* (at your option) any later version.
9
*
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
14
*
15
* You should have received a copy of the GNU General Public License
16
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17
* ============================================================ */
18
#ifndef BUTTONWITHMENU_H
19
#define BUTTONWITHMENU_H
20
21
#include <QVariant>
22
23
#include "
toolbutton.h
"
24
#include "
wheelhelper.h
"
25
26
// Only to be used in WebSearchBar
27
class
ButtonWithMenu
:
public
ToolButton
28
{
29
Q_OBJECT
30
public
:
31
struct
Item
{
32
QString
text
;
33
QIcon
icon
;
34
QVariant
userData
;
35
36
Item
(
const
QString &a = QString(),
const
QIcon &b = QIcon()) {
37
text
= a;
38
icon
= b;
39
}
40
41
bool
operator==
(
const
Item
&a)
const
{
42
return
(a.
text
==
text
) && (a.
icon
.pixmap(16).toImage() ==
icon
.pixmap(16).toImage());
43
}
44
45
bool
isEmpty
() {
46
return
(
text
.isEmpty() &&
icon
.isNull());
47
}
48
49
void
clear
() {
50
text
= QString();
51
icon
= QIcon();
52
userData
= QVariant();
53
}
54
};
55
56
explicit
ButtonWithMenu
(QWidget* parent =
nullptr
);
57
~ButtonWithMenu
()
override
;
58
59
void
addItem
(
const
Item
&item);
60
void
addItems
(
const
QVector<Item> &items);
61
void
removeItem
(
const
Item
&item);
62
void
setCurrentItem
(
const
Item
&item,
bool
emitSignal =
true
);
63
void
setCurrentIndex
(
int
index,
bool
emitSignal =
true
);
64
65
Item
currentItem
();
66
QVector<Item>
allItems
() {
return
m_items; }
67
QMenu*
menu
()
const
;
68
69
Q_SIGNALS:
70
void
activeItemChanged
(
const
ButtonWithMenu::Item
&item);
71
void
itemAdded
(
const
ButtonWithMenu::Item
&item);
72
void
itemRemoved
(
const
ButtonWithMenu::Item
&item);
73
74
public
Q_SLOTS:
75
void
clearItems
();
76
77
void
selectNextItem
();
78
void
selectPreviousItem
();
79
80
private
Q_SLOTS:
81
void
setCurrentItem
();
82
void
generateMenu();
83
84
private
:
85
void
mousePressEvent(QMouseEvent *event)
override
;
86
void
wheelEvent(QWheelEvent* event)
override
;
87
88
QMenu* m_menu;
89
QVector<Item> m_items;
90
Item
m_currentItem;
91
WheelHelper
m_wheelHelper;
92
};
93
94
// Hint to QVector to use std::realloc on item moving
95
Q_DECLARE_TYPEINFO
(
ButtonWithMenu::Item
, Q_MOVABLE_TYPE);
96
97
Q_DECLARE_METATYPE
(
ButtonWithMenu::Item
)
98
99
#endif
// BUTTONWITHMENU_H
Q_DECLARE_TYPEINFO
Q_DECLARE_TYPEINFO(ButtonWithMenu::Item, Q_MOVABLE_TYPE)
ButtonWithMenu
Definition:
buttonwithmenu.h:28
ButtonWithMenu::selectNextItem
void selectNextItem()
Definition:
buttonwithmenu.cpp:48
ButtonWithMenu::menu
QMenu * menu() const
Definition:
buttonwithmenu.cpp:152
ButtonWithMenu::clearItems
void clearItems()
Definition:
buttonwithmenu.cpp:42
ButtonWithMenu::selectPreviousItem
void selectPreviousItem()
Definition:
buttonwithmenu.cpp:57
ButtonWithMenu::addItem
void addItem(const Item &item)
Definition:
buttonwithmenu.cpp:66
ButtonWithMenu::setCurrentIndex
void setCurrentIndex(int index, bool emitSignal=true)
Definition:
buttonwithmenu.cpp:120
ButtonWithMenu::itemAdded
void itemAdded(const ButtonWithMenu::Item &item)
ButtonWithMenu::allItems
QVector< Item > allItems()
Definition:
buttonwithmenu.h:66
ButtonWithMenu::currentItem
Item currentItem()
Definition:
buttonwithmenu.cpp:147
ButtonWithMenu::addItems
void addItems(const QVector< Item > &items)
Definition:
buttonwithmenu.cpp:77
ButtonWithMenu::removeItem
void removeItem(const Item &item)
Definition:
buttonwithmenu.cpp:84
ButtonWithMenu::~ButtonWithMenu
~ButtonWithMenu() override
ButtonWithMenu::activeItemChanged
void activeItemChanged(const ButtonWithMenu::Item &item)
ButtonWithMenu::setCurrentItem
void setCurrentItem(const Item &item, bool emitSignal=true)
Definition:
buttonwithmenu.cpp:103
ButtonWithMenu::ButtonWithMenu
ButtonWithMenu(QWidget *parent=nullptr)
Definition:
buttonwithmenu.cpp:23
ButtonWithMenu::itemRemoved
void itemRemoved(const ButtonWithMenu::Item &item)
ToolButton
Definition:
toolbutton.h:27
WheelHelper
Definition:
wheelhelper.h:28
Q_DECLARE_METATYPE
Q_DECLARE_METATYPE(FlashCookie)
ButtonWithMenu::Item
Definition:
buttonwithmenu.h:31
ButtonWithMenu::Item::userData
QVariant userData
Definition:
buttonwithmenu.h:34
ButtonWithMenu::Item::icon
QIcon icon
Definition:
buttonwithmenu.h:33
ButtonWithMenu::Item::isEmpty
bool isEmpty()
Definition:
buttonwithmenu.h:45
ButtonWithMenu::Item::text
QString text
Definition:
buttonwithmenu.h:32
ButtonWithMenu::Item::operator==
bool operator==(const Item &a) const
Definition:
buttonwithmenu.h:41
ButtonWithMenu::Item::clear
void clear()
Definition:
buttonwithmenu.h:49
ButtonWithMenu::Item::Item
Item(const QString &a=QString(), const QIcon &b=QIcon())
Definition:
buttonwithmenu.h:36
toolbutton.h
wheelhelper.h
src
lib
tools
buttonwithmenu.h
Generated by
1.9.3