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
|
// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include "pccbrushtool.h"
#include <QColorDialog>
#include <QComboBox>
#include <QFormLayout>
#include <QPushButton>
PccBrushTool::PccBrushTool(const QString &title, QWidget *parent)
: QWidget(parent)
{
setWindowTitle(title);
setWindowFlags(Qt::Tool);
m_colorButton = new QPushButton();
m_styleCombo = new QComboBox();
m_styleCombo->addItem("Nobrush", (int) Qt::NoBrush);
m_styleCombo->addItem("Solidpattern", (int) Qt::SolidPattern);
m_styleCombo->addItem("Dense1pattern", (int) Qt::Dense1Pattern);
m_styleCombo->addItem("Dense2attern", (int) Qt::Dense2Pattern);
m_styleCombo->addItem("Dense3Pattern", (int) Qt::Dense3Pattern);
m_styleCombo->addItem("Dense4Pattern", (int) Qt::Dense4Pattern);
m_styleCombo->addItem("Dense5Pattern", (int) Qt::Dense5Pattern);
m_styleCombo->addItem("Dense6Pattern", (int) Qt::Dense6Pattern);
m_styleCombo->addItem("Dense7Pattern", (int) Qt::Dense7Pattern);
m_styleCombo->addItem("HorPattern", (int) Qt::HorPattern);
m_styleCombo->addItem("VerPattern", (int) Qt::VerPattern);
m_styleCombo->addItem("CrossPattern", (int) Qt::CrossPattern);
m_styleCombo->addItem("BDiagPattern", (int) Qt::BDiagPattern);
m_styleCombo->addItem("FDiagPattern", (int) Qt::FDiagPattern);
m_styleCombo->addItem("DiagCrossPattern", (int) Qt::DiagCrossPattern);
auto layout = new QFormLayout;
layout->addRow("Color", m_colorButton);
layout->addRow("Style", m_styleCombo);
setLayout(layout);
connect(m_colorButton, &QPushButton::clicked, this, &PccBrushTool::showColorDialog);
connect(m_styleCombo, &QComboBox::currentIndexChanged, this, &PccBrushTool::updateStyle);
}
void PccBrushTool::setBrush(const QBrush &brush)
{
m_brush = brush;
m_colorButton->setText(m_brush.color().name());
m_styleCombo->setCurrentIndex(m_brush.style()); // index matches the enum
}
QBrush PccBrushTool::brush() const
{
return m_brush;
}
QString PccBrushTool::name() const
{
return name(m_brush);
}
QString PccBrushTool::name(const QBrush &brush)
{
return brush.color().name();
}
void PccBrushTool::showColorDialog()
{
QColorDialog dialog(m_brush.color());
dialog.show();
dialog.exec();
m_brush.setColor(dialog.selectedColor());
m_colorButton->setText(m_brush.color().name());
emit changed();
}
void PccBrushTool::updateStyle()
{
Qt::BrushStyle style = (Qt::BrushStyle) m_styleCombo->itemData(m_styleCombo->currentIndex()).toInt();
if (m_brush.style() != style) {
m_brush.setStyle(style);
emit changed();
}
}
|