-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTextInputDialog.cpp
123 lines (97 loc) · 3.51 KB
/
TextInputDialog.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
#include <TextInputDialog.hpp>
#include <QPainter>
#include <QVBoxLayout>
#include <QPlainTextEdit>
#include <QDialogButtonBox>
#include <QPushButton>
#include <QFontDialog>
#include <QColorDialog>
#include <QCheckBox>
TextInputDialog::TextInputDialog(QColor color, QWidget *parent) : QDialog(parent)
{
color_ = color;
outline_ = false;
outlineColor_ = Qt::white;
QVBoxLayout* baseLayout = new QVBoxLayout(this);
QHBoxLayout* buttonLayout = new QHBoxLayout();
textEdit_ = new QPlainTextEdit(this);
baseLayout -> addWidget(textEdit_);
QPushButton* fontButton = new QPushButton(font_.family() + ":" + QString::number(font_.pointSize()));
buttonLayout -> addWidget(fontButton);
connect(fontButton, &QPushButton::clicked,
[=] {
bool ok;
QFont font = QFontDialog::getFont(&ok, font_, this);
if(ok) {
font_ = font;
fontButton -> setText(font_.family() + ":" + QString::number(font_.pointSize()));
}
});
QPushButton* colorButton = new QPushButton("");
buttonLayout -> addWidget(colorButton);
colorButton -> setIcon(QIcon(CreateColorPixmap(color_)));
connect(colorButton, &QPushButton::clicked,
[=] {
int alpha = color_.alpha();
auto color = QColorDialog::getColor(color_, this);
if(color.isValid()) color_ = color;
color_.setAlpha(alpha);
colorButton -> setIcon(QIcon(CreateColorPixmap(color_)));
});
outlineCheckBox_ = new QCheckBox("Outline");
QPushButton* outlineColorButton = new QPushButton("");
outlineColorButton -> setDisabled(true);
buttonLayout -> addWidget(outlineCheckBox_);
connect(outlineCheckBox_, &QCheckBox::toggled,
[=] (bool visible) {
outlineColorButton -> setDisabled(!visible);
outline_ = visible;
});
buttonLayout -> addWidget(outlineColorButton);
outlineColorButton -> setIcon(QIcon(CreateColorPixmap(outlineColor_)));
buttonLayout -> addWidget(outlineColorButton);
connect(outlineColorButton, &QPushButton::clicked,
[=] {
int alpha = color_.alpha();
auto color = QColorDialog::getColor(outlineColor_, this);
if(color.isValid()) outlineColor_ = color;
color_.setAlpha(alpha);
outlineColorButton -> setIcon(QIcon(CreateColorPixmap(outlineColor_)));
});
QDialogButtonBox* buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok |
QDialogButtonBox::Cancel,
Qt::Horizontal);
connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
buttonLayout -> addWidget(buttonBox);
baseLayout -> addLayout(buttonLayout);
this -> setLayout(baseLayout);
}
void TextInputDialog::accept() {
text_ = textEdit_ -> toPlainText();
QDialog::accept();
}
QColor TextInputDialog::getColor() {
return color_;
}
QFont TextInputDialog::getFont() {
return font_;
}
QString TextInputDialog::getText() {
return text_;
}
bool TextInputDialog::getOutline() {
return outline_;
}
QColor TextInputDialog::getOutlineColor() {
return outlineColor_;
}
QPixmap TextInputDialog::CreateColorPixmap(const QColor& color)
{
QPixmap pixmap(100, 100);
pixmap.fill(color);
QPainter painter(&pixmap);
painter.setPen(QColor(100,100,100,255));
painter.drawRect(0, 0, pixmap.height() - 1, pixmap.width() - 1);
return pixmap;
}