-
Notifications
You must be signed in to change notification settings - Fork 0
/
QTopMenuButton.cpp
133 lines (112 loc) · 3.05 KB
/
QTopMenuButton.cpp
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/*
* 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
*/
#include "QTopMenuButton.hpp"
#include <QWidget>
#include <QPainter>
#include <QTopMenuButtonWidget.hpp>
using namespace Escain;
QTopMenuButton::QTopMenuButton(): QObject(), QTopMenuAction()
{
m_icon.forgetId(0); // by default 0 is added.
}
QTopMenuButton::~QTopMenuButton()
{
// Free icons, so there is no double deletion.
for (auto& butPtr: m_widgetVector)
{
auto ptr = std::static_pointer_cast<QTopMenuButtonWidget>(butPtr);
assert(ptr);
ptr->icon(nullptr);
}
}
std::shared_ptr<QTopMenuWidget> QTopMenuButton::createWidget( QWidget* parent )
{
auto id=m_idAutocounter++;
auto but = std::make_shared<QTopMenuButtonWidget>(nameId(), id, parent);
//but->connect(but.get(), &QTopMenuButtonWidget::clicked, this, &QTopMenuButton::triggered); //TODO recover and remove next
but->connect(but.get(), &QTopMenuButtonWidget::clicked, this, [this](const QPointF& , const std::unordered_set<size_t>&, QTopMenuButtonWidget* me){ emit triggered(me);});
but->connect(but.get(), &QTopMenuButtonWidget::bestSizeChanged, this, &QTopMenuButton::bestSizeChanged);
m_widgetVector.push_back(but);
but->label(m_label);
but->margin(m_margin);
but->icon(&m_icon);
return std::static_pointer_cast<QTopMenuWidget>(but);
}
void QTopMenuButton::icon(const QSvgIcon& ic)
{
m_icon = ic;
for (auto& butPtr: m_widgetVector)
{
auto ptr = std::static_pointer_cast<QTopMenuButtonWidget>(butPtr);
assert(ptr);
ptr->icon(&m_icon);
}
}
const QSvgIcon& QTopMenuButton::icon() const
{
return m_icon;
}
void QTopMenuButton::label( const std::string& label)
{
if( m_label != label)
{
m_label = label;
for (auto& butPtr: m_widgetVector)
{
auto ptr = std::static_pointer_cast<QTopMenuButtonWidget>(butPtr);
assert(ptr);
ptr->label(m_label);
}
}
}
const std::string& QTopMenuButton::label() const
{
return m_label;
}
void QTopMenuButton::margin( const qreal margin)
{
if( m_margin != margin)
{
m_margin = margin;
for (auto& butPtr: m_widgetVector)
{
auto ptr = std::static_pointer_cast<QTopMenuButtonWidget>(butPtr);
assert(ptr);
ptr->margin(m_margin);
}
}
}
const qreal QTopMenuButton::margin() const
{
return m_margin;
}
void QTopMenuButton::enable( bool enabled)
{
if (m_enabled!=enabled)
{
m_enabled=enabled;
for (auto& butPtr: m_widgetVector)
{
butPtr->setEnabled(enabled);
}
}
}
bool QTopMenuButton::enable() const
{
return m_enabled;
}