File indexing completed on 2024-05-12 16:02:29

0001 /*
0002  *  SPDX-FileCopyrightText: 2007 Cyrille Berger <cberger@cberger.net>
0003  *
0004  *  SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 
0007 #ifndef _KIS_POPUP_BUTTON_H_
0008 #define _KIS_POPUP_BUTTON_H_
0009 
0010 #include <QToolButton>
0011 
0012 #include <kritawidgetutils_export.h>
0013 
0014 /**
0015  * This class is a convenience class for a button that
0016  * when clicked displays a popup widget.
0017  */
0018 class KRITAWIDGETUTILS_EXPORT KisPopupButton : public QToolButton
0019 {
0020 
0021     Q_OBJECT
0022 
0023 public:
0024 
0025     KisPopupButton(QWidget* parent);
0026     ~KisPopupButton() override;
0027 
0028     /**
0029      * Set the popup widget, the KisPopupButton becomes
0030      * the owner and parent of the widget.
0031      */
0032     void setPopupWidget(QWidget* widget);
0033 
0034     /**
0035      * Set the width of the popup widget.
0036      * @return new width of the popup widget
0037      */
0038     void setPopupWidgetWidth(int w);
0039 
0040     /**
0041      * @brief adjustPosition
0042      * adjusts the position of the popup widget based on the position
0043      * of this button and the size of the widget
0044      */
0045     void adjustPosition();
0046 
0047     /**
0048      * This function allows to show or hide the arrow.
0049      * @param v set to true to draw the arrow, else set to false
0050      */
0051     void setArrowVisible(bool v);
0052 
0053     bool isPopupWidgetVisible();
0054 
0055 public Q_SLOTS:
0056 
0057     void showPopupWidget();
0058 
0059     void hidePopupWidget();
0060 
0061     void setPopupWidgetVisible(bool visible);
0062 
0063     /**
0064      * Set whether the popup is detached as a dialog.
0065      * @param v set to true to cause the popup to be detached
0066      */
0067     void setPopupWidgetDetached(bool detach);
0068 
0069 protected:
0070     void paintEvent(QPaintEvent* event) override;
0071 
0072     void paintPopupArrow();
0073 private:
0074     struct Private;
0075     Private* const m_d;
0076 };
0077 
0078 #endif