File indexing completed on 2024-04-21 14:55:58
0001 /* This file is part of the KDE libraries 0002 Copyright (C) 2000 Carsten Pfeiffer <pfeiffer@kde.org> 0003 0004 This library is free software; you can redistribute it and/or 0005 modify it under the terms of the GNU Library General Public 0006 License as published by the Free Software Foundation; either 0007 version 2 of the License, or (at your option) any later version. 0008 0009 This library is distributed in the hope that it will be useful, 0010 but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0012 Library General Public License for more details. 0013 0014 You should have received a copy of the GNU Library General Public License 0015 along with this library; see the file COPYING.LIB. If not, write to 0016 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0017 Boston, MA 02110-1301, USA. 0018 */ 0019 0020 #ifndef KPUSHBUTTON_H 0021 #define KPUSHBUTTON_H 0022 0023 #include <QPushButton> 0024 0025 #include <kstandardguiitem.h> 0026 0027 #include <kauth/action.h> 0028 0029 #include <kdelibs4support_export.h> 0030 0031 class QDrag; 0032 class QMenu; 0033 0034 /** 0035 * @deprecated since 5.0, use QPushButton instead 0036 * 0037 * @brief A QPushButton with drag-support and KGuiItem support 0038 * 0039 * This is nothing but a QPushButton with drag-support and KGuiItem support. 0040 * You must call #setDragEnabled (true) and override the virtual method 0041 * dragObject() to specify the QDragObject to be used. 0042 * 0043 * \image html kpushbutton.png "KDE Push Button" 0044 * 0045 * @author Carsten Pfeiffer <pfeiffer@kde.org> 0046 */ 0047 class KDELIBS4SUPPORT_DEPRECATED_EXPORT KPushButton : public QPushButton 0048 { 0049 Q_OBJECT 0050 Q_PROPERTY(bool isDragEnabled READ isDragEnabled WRITE setDragEnabled) 0051 0052 public: 0053 0054 /** 0055 * Default constructor. 0056 */ 0057 KDELIBS4SUPPORT_DEPRECATED explicit KPushButton(QWidget *parent = nullptr); 0058 0059 /** 0060 * Constructor, that sets the button-text to @p text 0061 */ 0062 KDELIBS4SUPPORT_DEPRECATED explicit KPushButton(const QString &text, QWidget *parent = nullptr); 0063 0064 /** 0065 * Constructor, that sets an icon and the button-text to @p text 0066 */ 0067 KPushButton(const QIcon &icon, const QString &text, QWidget *parent = nullptr); 0068 0069 /** 0070 * Constructor that takes a KGuiItem for the text, the icon, the tooltip 0071 * and the what's this help 0072 * @deprecated since 5.0, use QPushButton and KGuiItem::assign(QPushButton *button, const KGuiItem &item). 0073 */ 0074 KDELIBS4SUPPORT_DEPRECATED explicit KPushButton(const KGuiItem &item, QWidget *parent = nullptr); 0075 0076 /** 0077 * Destructs the button. 0078 */ 0079 ~KPushButton() override; 0080 0081 /** 0082 * Enables/disables drag-support. Default is disabled. 0083 */ 0084 void setDragEnabled(bool enable); 0085 0086 /** 0087 * @returns if drag support is enabled or not. 0088 */ 0089 bool isDragEnabled() const; 0090 0091 /** 0092 * Sets the KGuiItem for this button. 0093 */ 0094 void setGuiItem(const KGuiItem &item); 0095 0096 /** 0097 * Sets the standard KGuiItem for this button. 0098 */ 0099 void setGuiItem(KStandardGuiItem::StandardItem item); 0100 0101 /** 0102 * Reads the standard KGuiItem for this button. 0103 */ 0104 KStandardGuiItem::StandardItem guiItem() const; 0105 0106 /** 0107 * Sets the Icon Set for this button. It also takes into account the 0108 * "show icons on push buttons" user setting. 0109 */ 0110 void setIcon(const QIcon &icon); 0111 0112 /** 0113 * Sets the text of the button 0114 */ 0115 void setText(const QString &text); 0116 0117 /** 0118 * Sets a delayed popup menu 0119 * for consistency, since menu() isn't virtual 0120 */ 0121 void setDelayedMenu(QMenu *delayed_menu); 0122 0123 /** 0124 * returns a delayed popup menu 0125 * since menu() isn't virtual 0126 */ 0127 QMenu *delayedMenu(); 0128 0129 /** 0130 * Reimplemented to add arrow for delayed menu 0131 * @since 4.4 0132 */ 0133 QSize sizeHint() const override; 0134 0135 /** 0136 * Returns the action object associated with this button, or 0 if it does not have one 0137 * 0138 * @returns the KAuth::Action associated with this button. 0139 */ 0140 KAuth::Action authAction() const; 0141 0142 /** 0143 * Sets the action object associated with this button 0144 * 0145 * By setting a KAuth::Action, this button will become associated with it, and 0146 * whenever it gets clicked, it will trigger the authorization and execution process 0147 * for the action. The signal activated will also be emitted whenever the button gets 0148 * clicked and the action gets authorized. Pass 0 to this function to disassociate the button 0149 * 0150 * @param action the KAuth::Action to associate with this button. 0151 */ 0152 void setAuthAction(const KAuth::Action &action); 0153 0154 /** 0155 * Sets the action object associated with this button 0156 * 0157 * Overloaded member to allow creating the action by name 0158 * 0159 * @param actionName the name of the action to associate 0160 */ 0161 void setAuthAction(const QString &actionName); 0162 0163 protected: 0164 /** 0165 * Reimplement this and return the QDrag object that should be used 0166 * for the drag. Remember to give it "this" as parent. 0167 * 0168 * Default implementation returns 0, so that no drag is initiated. 0169 */ 0170 virtual QDrag *dragObject(); 0171 0172 /** 0173 * Reimplemented to add drag-support 0174 */ 0175 void mousePressEvent(QMouseEvent *) override; 0176 /** 0177 * Reimplemented to add drag-support 0178 */ 0179 void mouseMoveEvent(QMouseEvent *) override; 0180 0181 /** 0182 * Reimplemented to add arrow for delayed menu 0183 * @since 4.4 0184 */ 0185 void paintEvent(QPaintEvent *) override; 0186 0187 /** 0188 * Starts a drag (dragCopy() by default) using dragObject() 0189 */ 0190 virtual void startDrag(); 0191 0192 Q_SIGNALS: 0193 /** 0194 * Signal emitted when the button is triggered and authorized 0195 * 0196 * If the button needs authorization, whenever the user triggers it, 0197 * the authorization process automatically begins. 0198 * If it succeeds, this signal is emitted. The KAuth::Action object is provided for convenience 0199 * if you have multiple Action objects, but of course it's always the same set with 0200 * setAuthAction(). 0201 * 0202 * WARNING: If your button needs authorization you should connect eventual slots processing 0203 * stuff to this signal, and NOT clicked. Clicked will be emitted even if the user has not 0204 * been authorized 0205 * 0206 * @param action The object set with setAuthAction() 0207 */ 0208 void authorized(const KAuth::Action &action); 0209 0210 private: 0211 /** 0212 * Internal. 0213 * Initialize the KPushButton instance 0214 */ 0215 void initWidget(const KGuiItem &item); 0216 0217 private: 0218 class KPushButtonPrivate; 0219 KPushButtonPrivate *const d; 0220 0221 Q_PRIVATE_SLOT(d, void slotPressedInternal()) 0222 Q_PRIVATE_SLOT(d, void slotClickedInternal()) 0223 Q_PRIVATE_SLOT(d, void slotDelayedMenuTimeout()) 0224 }; 0225 0226 #endif // KPUSHBUTTON_H