1 /*
2  *  Copyright (c) 2007 Cyrille Berger <cberger@cberger.net>
3  *
4  *  This program is free software; you can redistribute it and/or modify
5  *  it under the terms of the GNU General Public License as published by
6  *  the Free Software Foundation; either version 2 of the License, or
7  *  (at your option) any later version.
8  *
9  *  This program 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
12  *  GNU General Public License for more details.
13  *
14  *  You should have received a copy of the GNU General Public License
15  *  along with this program; if not, write to the Free Software
16  *  Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  */
19 
20 #ifndef _KIS_POPUP_BUTTON_H_
21 #define _KIS_POPUP_BUTTON_H_
22 
23 #include <QPushButton>
24 
25 #include <kritawidgets_export.h>
26 
27 /**
28  * This class is a convenience class for a button that
29  * when clicked displays a popup widget.
30  */
31 class KRITAWIDGETS_EXPORT KisPopupButton : public QPushButton
32 {
33 
34     Q_OBJECT
35 
36 public:
37 
38     KisPopupButton(QWidget* parent);
39     ~KisPopupButton() override;
40 
41     /**
42      * Set the popup widget, the KisPopupButton becomes
43      * the owner and parent of the widget.
44      */
45     void setPopupWidget(QWidget* widget);
46 
47     /**
48      * This function allow to force the popup to be visible.
49      * @param v set to true to force the popup to be visible, set to false
50      *          to allow the popup to be hidden
51      */
52     void setAlwaysVisible(bool v);
53 
54     /**
55      * Set the width of the popup widget.
56      * @return new width of the popup widget
57      */
58     void setPopupWidgetWidth(int w);
59 
60     /**
61      * @brief adjustPosition
62      * adjusts the position of the popup widget based on the position
63      * of this button and the size of the widget
64      */
65     void adjustPosition();
66 
67 public Q_SLOTS:
68 
69     void showPopupWidget();
70 
71     void hidePopupWidget();
72 
73 protected:
74     void paintEvent(QPaintEvent* event) override;
75 
76     void paintPopupArrow();
77 private:
78     struct Private;
79     Private* const m_d;
80 };
81 
82 #endif
83