maxLibQt
ActionPushButton.h
Go to the documentation of this file.
1 /*
2  ActionPushButton
3  https://github.com/mpaperno/maxLibQt
4 
5  COPYRIGHT: (c)2019 Maxim Paperno; All Right Reserved.
6  Contact: http://www.WorldDesign.com/contact
7 
8  LICENSE:
9 
10  Commercial License Usage
11  Licensees holding valid commercial licenses may use this file in
12  accordance with the terms contained in a written agreement between
13  you and the copyright holder.
14 
15  GNU General Public License Usage
16  Alternatively, this file may be used under the terms of the GNU
17  General Public License as published by the Free Software Foundation,
18  either version 3 of the License, or (at your option) any later version.
19 
20  This program is distributed in the hope that it will be useful,
21  but WITHOUT ANY WARRANTY; without even the implied warranty of
22  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23  GNU General Public License for more details.
24 
25  A copy of the GNU General Public License is available at <http://www.gnu.org/licenses/>.
26 */
27 
28 #ifndef ACTIONPUSHBUTTON_H
29 #define ACTIONPUSHBUTTON_H
30 
31 #include <QPushButton>
32 
33 class QAction;
34 class QEvent;
35 
45 {
46  Q_OBJECT
49 
50  public:
54  explicit ActionPushButton(QAction *defaultAction, QWidget *parent = nullptr);
55 
57  inline QAction *defaultAction() const { return m_defaultAction; }
58 
59  public slots:
64  void setDefaultAction(QAction *action);
65 
66  signals:
68  void triggered(QAction *);
69 
70  protected:
71  bool event(QEvent *e) override;
72  void nextCheckState() override;
73 
74  private slots:
75  void updateFromAction(QAction *action);
76  void onActionTriggered();
77 
78  private:
79  QAction *m_defaultAction = nullptr;
80 
81  Q_DISABLE_COPY(ActionPushButton)
82 
83 #ifdef DOXYGEN_SHOULD_INCLUDE_THIS
84  public:
86  ActionPushButton(QWidget *parent = nullptr);
87  ActionPushButton(const QString &text, QWidget *parent = nullptr);
88  ActionPushButton(const QIcon &icon, const QString &text, QWidget *parent = nullptr);
90 #endif
91 };
92 
93 #endif // ACTIONPUSHBUTTON_H
void triggered(QAction *)
Signal emitted whenever any QAction added to this button (with QWidget::addAction() or setDefaultActi...
The ActionPushButton class is a QPushButton which takes a default QAction, just like a QToolButton ca...
void setDefaultAction(QAction *action)
Sets the default action to action.
QIcon icon() const const
void nextCheckState() override
ActionPushButton(QAction *defaultAction, QWidget *parent=nullptr)
Construct using defaultAction as the default action.
QPushButton(QWidget *parent)
bool event(QEvent *e) override
QString text() const const
QObject * parent() const const
QAction * defaultAction() const
Current default action, if any. Returns nullptr if no default action has been set.