-
Notifications
You must be signed in to change notification settings - Fork 0
/
QTopMenuGridGroupPopup.hpp
91 lines (75 loc) · 2.84 KB
/
QTopMenuGridGroupPopup.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*
* This file is part of Escain QTopMenu library
*
* QTopMenu library is free software: you can redistribute it and/or modify
* it under ther terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* Escain Documentor is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this library. If not, see <https://www.gnu.org/licenses/>.
*
* Author: Adrian Maire escain (at) gmail.com
*/
#ifndef QTOPMENUGRIDGROUPPOPUP_HPP
#define QTOPMENUGRIDGROUPPOPUP_HPP
#include <QStaticText>
#include <QWidget>
#include <QPaletteExt.hpp>
#include "QTopMenuWidgetTypes.hpp"
namespace Escain
{
/// StyleOption, allowing static painting of the widget (and thus easy customization).
struct QTopMenuGridGroupPopupStyleOptions
{
bool isHover = false;
bool isEnabled = true;
QPaletteExt palette;
const QStaticText* staticText=nullptr;
QRect widgetRect;
DisplaySide direction;
qreal margin;
};
/// This class allows the painting of the Popup frame, for a QTopMenuGridGroup
class QTopMenuGridGroupPopup: public QWidget
{
Q_OBJECT
public:
explicit QTopMenuGridGroupPopup( QWidget* parent = nullptr);
virtual ~QTopMenuGridGroupPopup() = default;
/// overridable call to the static equivalent
virtual void drawControl( const QTopMenuGridGroupPopupStyleOptions& opt, QPainter& p) const { staticDrawControl(opt, p); }
static void staticDrawControl( const QTopMenuGridGroupPopupStyleOptions& opt, QPainter& p);
///Direction: Set if the widget are arranged horizontally or vertically
virtual DisplaySide direction() const;
virtual void direction( const DisplaySide d );
/// Label
virtual const std::string& label() const;
virtual void label( const std::string_view& label );
/// Space between cells, in Pts
virtual qreal margin() const;
virtual void margin( qreal margin );
signals:
virtual void fade();
protected:
/// Fill QTopMenuGridGroupPopupStyleOptions with current configuration for static drawing.
virtual void initStyleOption(QTopMenuGridGroupPopupStyleOptions&) const;
/// Returns the rect where to draw the Group Label. In vertical mode, the rect
/// expects the QPainter to be rotated CW 90º (the rect is rotated CCW 90º)
static QRect textRect(const QRect& widgetRect, qreal margin, const QStaticText& staticText, DisplaySide dir);
static void setupFontForLabel( QFont& );
void prepareText();
void paintEvent(QPaintEvent* e) override;
void closeEvent(QCloseEvent* e) override;
void resizeEvent(QResizeEvent*) override;
QStaticText m_staticText;
qreal m_margin = 4.0;
std::string m_label;
DisplaySide m_direction = DisplaySide::Top;
};
}
#endif