KDELibs4Support

kpushbutton.h
1 /* This file is part of the KDE libraries
2  Copyright (C) 2000 Carsten Pfeiffer <[email protected]>
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License as published by the Free Software Foundation; either
7  version 2 of the License, or (at your option) any later version.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Library General Public License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to
16  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  Boston, MA 02110-1301, USA.
18 */
19 
20 #ifndef KPUSHBUTTON_H
21 #define KPUSHBUTTON_H
22 
23 #include <QPushButton>
24 
25 #include <kstandardguiitem.h>
26 
27 #include <kauth/action.h>
28 
29 #include <kdelibs4support_export.h>
30 
31 class QDrag;
32 class QMenu;
33 
34 /**
35  * @deprecated since 5.0, use QPushButton instead
36  *
37  * @brief A QPushButton with drag-support and KGuiItem support
38  *
39  * This is nothing but a QPushButton with drag-support and KGuiItem support.
40  * You must call #setDragEnabled (true) and override the virtual method
41  * dragObject() to specify the QDragObject to be used.
42  *
43  * \image html kpushbutton.png "KDE Push Button"
44  *
45  * @author Carsten Pfeiffer <[email protected]>
46  */
47 class KDELIBS4SUPPORT_DEPRECATED_EXPORT KPushButton : public QPushButton
48 {
49  Q_OBJECT
50  Q_PROPERTY(bool isDragEnabled READ isDragEnabled WRITE setDragEnabled)
51 
52 public:
53 
54  /**
55  * Default constructor.
56  */
57  KDELIBS4SUPPORT_DEPRECATED explicit KPushButton(QWidget *parent = nullptr);
58 
59  /**
60  * Constructor, that sets the button-text to @p text
61  */
62  KDELIBS4SUPPORT_DEPRECATED explicit KPushButton(const QString &text, QWidget *parent = nullptr);
63 
64  /**
65  * Constructor, that sets an icon and the button-text to @p text
66  */
67  KPushButton(const QIcon &icon, const QString &text, QWidget *parent = nullptr);
68 
69  /**
70  * Constructor that takes a KGuiItem for the text, the icon, the tooltip
71  * and the what's this help
72  * @deprecated since 5.0, use QPushButton and KGuiItem::assign(QPushButton *button, const KGuiItem &item).
73  */
74  KDELIBS4SUPPORT_DEPRECATED explicit KPushButton(const KGuiItem &item, QWidget *parent = nullptr);
75 
76  /**
77  * Destructs the button.
78  */
79  ~KPushButton() override;
80 
81  /**
82  * Enables/disables drag-support. Default is disabled.
83  */
84  void setDragEnabled(bool enable);
85 
86  /**
87  * @returns if drag support is enabled or not.
88  */
89  bool isDragEnabled() const;
90 
91  /**
92  * Sets the KGuiItem for this button.
93  */
94  void setGuiItem(const KGuiItem &item);
95 
96  /**
97  * Sets the standard KGuiItem for this button.
98  */
99  void setGuiItem(KStandardGuiItem::StandardItem item);
100 
101  /**
102  * Reads the standard KGuiItem for this button.
103  */
104  KStandardGuiItem::StandardItem guiItem() const;
105 
106  /**
107  * Sets the Icon Set for this button. It also takes into account the
108  * "show icons on push buttons" user setting.
109  */
110  void setIcon(const QIcon &icon);
111 
112  /**
113  * Sets the text of the button
114  */
115  void setText(const QString &text);
116 
117  /**
118  * Sets a delayed popup menu
119  * for consistency, since menu() isn't virtual
120  */
121  void setDelayedMenu(QMenu *delayed_menu);
122 
123  /**
124  * returns a delayed popup menu
125  * since menu() isn't virtual
126  */
127  QMenu *delayedMenu();
128 
129  /**
130  * Reimplemented to add arrow for delayed menu
131  * @since 4.4
132  */
133  QSize sizeHint() const override;
134 
135  /**
136  * Returns the action object associated with this button, or 0 if it does not have one
137  *
138  * @returns the KAuth::Action associated with this button.
139  */
140  KAuth::Action authAction() const;
141 
142  /**
143  * Sets the action object associated with this button
144  *
145  * By setting a KAuth::Action, this button will become associated with it, and
146  * whenever it gets clicked, it will trigger the authorization and execution process
147  * for the action. The signal activated will also be emitted whenever the button gets
148  * clicked and the action gets authorized. Pass 0 to this function to disassociate the button
149  *
150  * @param action the KAuth::Action to associate with this button.
151  */
152  void setAuthAction(const KAuth::Action &action);
153 
154  /**
155  * Sets the action object associated with this button
156  *
157  * Overloaded member to allow creating the action by name
158  *
159  * @param actionName the name of the action to associate
160  */
161  void setAuthAction(const QString &actionName);
162 
163 protected:
164  /**
165  * Reimplement this and return the QDrag object that should be used
166  * for the drag. Remember to give it "this" as parent.
167  *
168  * Default implementation returns 0, so that no drag is initiated.
169  */
170  virtual QDrag *dragObject();
171 
172  /**
173  * Reimplemented to add drag-support
174  */
175  void mousePressEvent(QMouseEvent *) override;
176  /**
177  * Reimplemented to add drag-support
178  */
179  void mouseMoveEvent(QMouseEvent *) override;
180 
181  /**
182  * Reimplemented to add arrow for delayed menu
183  * @since 4.4
184  */
185  void paintEvent(QPaintEvent *) override;
186 
187  /**
188  * Starts a drag (dragCopy() by default) using dragObject()
189  */
190  virtual void startDrag();
191 
192 Q_SIGNALS:
193  /**
194  * Signal emitted when the button is triggered and authorized
195  *
196  * If the button needs authorization, whenever the user triggers it,
197  * the authorization process automatically begins.
198  * If it succeeds, this signal is emitted. The KAuth::Action object is provided for convenience
199  * if you have multiple Action objects, but of course it's always the same set with
200  * setAuthAction().
201  *
202  * WARNING: If your button needs authorization you should connect eventual slots processing
203  * stuff to this signal, and NOT clicked. Clicked will be emitted even if the user has not
204  * been authorized
205  *
206  * @param action The object set with setAuthAction()
207  */
208  void authorized(const KAuth::Action &action);
209 
210 private:
211  /**
212  * Internal.
213  * Initialize the KPushButton instance
214  */
215  void initWidget(const KGuiItem &item);
216 
217 private:
218  class KPushButtonPrivate;
219  KPushButtonPrivate *const d;
220 
221  Q_PRIVATE_SLOT(d, void slotPressedInternal())
222  Q_PRIVATE_SLOT(d, void slotClickedInternal())
223  Q_PRIVATE_SLOT(d, void slotDelayedMenuTimeout())
224 };
225 
226 #endif // KPUSHBUTTON_H
Q_PROPERTY(...)
virtual QSize sizeHint() const const override
A QPushButton with drag-support and KGuiItem support.
Definition: kpushbutton.h:47
virtual void paintEvent(QPaintEvent *) override
Q_SIGNALSQ_SIGNALS
void setIcon(const QIcon &icon)
virtual void mousePressEvent(QMouseEvent *e) override
virtual void mouseMoveEvent(QMouseEvent *e) override
void setText(const QString &text)
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Sep 25 2023 03:53:00 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.