Falkon Develop
Cross-platform Qt-based web browser
toolbutton.h
Go to the documentation of this file.
1/* ============================================================
2* Falkon - Qt web browser
3* Copyright (C) 2010-2018 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 TOOLBUTTON_H
19#define TOOLBUTTON_H
20
21#include <QToolButton>
22#include <QTimer>
23
24#include "qzcommon.h"
25
26class FALKON_EXPORT ToolButton : public QToolButton
27{
28 Q_OBJECT
29
30 Q_PROPERTY(QSize fixedsize READ size WRITE setFixedSize)
31 Q_PROPERTY(int fixedwidth READ width WRITE setFixedWidth)
32 Q_PROPERTY(int fixedheight READ height WRITE setFixedHeight)
33 Q_PROPERTY(QImage multiIcon READ multiIcon WRITE setMultiIcon)
34 Q_PROPERTY(QIcon icon READ icon WRITE setIcon)
35 Q_PROPERTY(QString themeIcon READ themeIcon WRITE setThemeIcon)
36 Q_PROPERTY(QIcon fallbackIcon READ fallbackIcon WRITE setFallbackIcon)
37
38public:
39 explicit ToolButton(QWidget* parent = nullptr);
40
41 // MultiIcon - Image containing pixmaps for all button states
42 QImage multiIcon() const;
43 void setMultiIcon(const QImage &image);
44
45 // ThemeIcon - Standard QToolButton with theme icon
46 QString themeIcon() const;
47 void setThemeIcon(const QString &icon);
48
49 // FallbackIcon - In case theme doesn't contain ThemeIcon
50 QIcon fallbackIcon() const;
51 void setFallbackIcon(const QIcon &fallbackIcon);
52
53 // Icon - Standard QToolButton with icon
54 QIcon icon() const;
55 void setIcon(const QIcon &icon);
56
57 // Menu - Menu is handled in ToolButton and is not passed to QToolButton
58 // There won't be menu indicator shown in the button
59 // QToolButton::MenuButtonPopup is not supported
60 QMenu* menu() const;
61 void setMenu(QMenu* menu);
62
63 // Align the right corner of menu to the right corner of button
64 bool showMenuInside() const;
65 void setShowMenuInside(bool enable);
66
67 // Show button menu on right click
68 bool showMenuOnRightClick() const;
69 void setShowMenuOnRightClick(bool enable);
70
71 // Set the button to look as it was in toolbar
72 // (it now only sets the correct icon size)
73 bool toolbarButtonLook() const;
74 void setToolbarButtonLook(bool enable);
75
76Q_SIGNALS:
80
81 // It is needed to use these signals with ShowMenuInside
84
85private Q_SLOTS:
86 void menuAboutToHide();
87 void showMenu();
88
89protected:
90 void mousePressEvent(QMouseEvent* e) override;
91 void mouseReleaseEvent(QMouseEvent* e) override;
92 void mouseDoubleClickEvent(QMouseEvent* e) override;
93 void contextMenuEvent(QContextMenuEvent *e) override;
94 void paintEvent(QPaintEvent* e) override;
95
96private:
97 QImage m_multiIcon;
98 QString m_themeIcon;
99 QTimer m_pressTimer;
100 QMenu* m_menu;
101
102 enum Options {
103 MultiIconOption = 1,
104 ShowMenuInsideOption = 2,
105 ToolBarLookOption = 4,
106 ShowMenuOnRightClick = 8
107 };
108 Q_DECLARE_FLAGS(OptionsFlags, Options)
109 OptionsFlags m_options;
110};
111
112
113#endif // TOOLBUTTON_H
void doubleClicked()
void controlClicked()
void aboutToShowMenu()
void aboutToHideMenu()
void middleMouseClicked()
#define FALKON_EXPORT
Definition: qzcommon.h:28