forked from easysoft/zenshot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpencombobox.cpp
111 lines (89 loc) · 2.78 KB
/
pencombobox.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
/* Copyright (C) 2021 Nature Easy Soft Network Technology Co., LTD
*
* This file is part of Zenshot (https://github.com/easysoft/zenshot/).
*
* Zenshot is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Zenshot 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 Zenshot. If not, see <https://www.gnu.org/licenses/>.
*/
#include "pencombobox.h"
#include <QWidgetAction>
PenCombobox::PenCombobox(QWidget *parent):QPushButton(parent)
{
setMinimumWidth(ts(62));
m_styleList.append(Qt::SolidLine);
m_styleList.append(Qt::DashLine);
m_styleList.append(Qt::DotLine);
m_styleList.append(Qt::DashDotLine);
m_styleList.append(Qt::DashDotDotLine);
this->m_renderer = new PenRenderer(this,Qt::SolidLine,10,25);
m_menu = new QMenu();
setMenu(m_menu);
connect(m_menu, SIGNAL(aboutToShow()), this, SLOT(menuAboutToShow()));
connect(m_menu, SIGNAL(triggered(QAction*)), this, SLOT(menuTriggered(QAction*)));
m_menu->setStyleSheet("QLabel {padding: 3px 0 3px 0; background-color: transparent;}"
"QLabel:hover {background-color: rgb(0, 122, 255);}");
createSelect();
}
PenCombobox::~PenCombobox()
{
m_styleList.clear();
qDeleteAll(m_itemWidgetList);
m_itemWidgetList.clear();
}
Qt::PenStyle PenCombobox::penStyle() const
{
return m_penStyle;
}
void PenCombobox::setPenStyle(const Qt::PenStyle &style)
{
m_penStyle = style;
m_renderer->setPenStyle(style);
update();
}
void PenCombobox::createSelect()
{
foreach(Qt::PenStyle mStyle,m_styleList)
{
QWidgetAction* wa1 = new QWidgetAction(m_menu);
PenItemWidget *item = new PenItemWidget(mStyle);
wa1->setDefaultWidget(item);
m_menu->addAction(wa1);
m_itemWidgetList.append(item);
}
}
void PenCombobox::paintEvent(QPaintEvent *event)
{
QPushButton::paintEvent(event);
m_renderer->draw();
}
void PenCombobox::menuAboutToShow()
{
if(m_menu)
{
m_menu->setFixedWidth(this->width());
}
}
void PenCombobox::menuTriggered(QAction *action)
{
if(!action)
return;
QWidgetAction* qwa = dynamic_cast<QWidgetAction*>(action);
if(!qwa)
return;
PenItemWidget* item = dynamic_cast<PenItemWidget*>(qwa->defaultWidget());
if(!item)
return;
Qt::PenStyle selected = item->penStyle();
setPenStyle(selected);
emit penStyleChanged();
}