-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmainwnd.cpp
214 lines (192 loc) · 6.03 KB
/
mainwnd.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
/***************************************************************************
* Copyright (C) 2018-2021 by Chernov A.A. *
* *
* This program 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. *
* *
* This program 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 program. If not, see <http://www.gnu.org/licenses/>. *
***************************************************************************/
#include "mainwnd.h"
#include "ui_mainwnd.h"
#include <QtGui/QShowEvent>
#include <QtGui/QScreen>
#include <QtWidgets/QFileDialog>
#include <QtWidgets/QCheckBox>
GMainWindow::GMainWindow(QWidget *parent)
: QMainWindow(parent),
ui(new Ui::GMainWindow)
{
ui->setupUi(this);
// signals of custom widget not available in design editor
connect(ui->textColorBox, SIGNAL(colorChanged(QColor)), this, SLOT(slot_textColorChanged(QColor)));
connect(ui->backgroundColorBox, SIGNAL(colorChanged(QColor)), this, SLOT(slot_backgroundColorChanged(QColor)));
ui->textColorBox->setDefaultColor(QColor(Qt::black));
ui->backgroundColorBox->setDefaultColor(QColor::fromRgb(200, 240, 255));
#ifdef _WIN32
// Override default font file
ui->fontLineEdit->setText("c:/Windows/Fonts/NotoSerif-Regular.ttf");
#endif
qreal dpr = screen()->devicePixelRatio();
ui->fontSizeBox->setValue(ui->fontSizeBox->value()*dpr);
ui->fontSizeBox->setMaximum(ui->fontSizeBox->maximum()*dpr);
onFontChanged();
}
GMainWindow::~GMainWindow()
{
delete ui;
}
void GMainWindow::showEvent(QShowEvent* event)
{
static bool firstShow = true;
QMainWindow::showEvent(event);
if (firstShow)
{
ui->previewWidget->setFontFace(ui->fontLineEdit->text());
ui->previewWidget->setFontPointSize(ui->fontSizeBox->value());
slot_antialiasingChanged(ui->antialiasBox->currentIndex());
slot_hintingChanged(ui->hintingBox->currentIndex());
ui->previewWidget->setGammaCorrection(ui->gammaBox->value());
ui->previewWidget->setKerning(ui->kerningBox->isChecked());
ui->previewWidget->renderText(ui->sampleTextLineEdit->text());
#ifndef USE_HARFBUZZ
ui->ligaturesBox->setEnabled(false);
#endif
firstShow = false;
}
}
void GMainWindow::slot_textEdited(const QString& text)
{
ui->previewWidget->renderText(text);
}
void GMainWindow::slot_fontSizeChanged(double size)
{
ui->previewWidget->setFontPointSize(size);
}
void GMainWindow::slot_fontFileEdited(const QString& text)
{
ui->previewWidget->setFontFace(text);
}
void GMainWindow::slot_browseFont()
{
QString dir = ui->fontLineEdit->text();
QString filter = tr("Font files (*.ttf *.otf *.pfa *.pfb *.pcf *.pcf.gz)");
QString path = QFileDialog::getOpenFileName(this, tr("Select font file..."), dir, filter);
if (!path.isEmpty())
{
ui->fontLineEdit->setText(path);
if (ui->previewWidget->setFontFace(path))
onFontChanged();
}
}
void GMainWindow::slot_antialiasingChanged(int index)
{
GLowLevelTextRender::AntialiasingMode mode;
switch (index)
{
case 0:
mode = GLowLevelTextRender::AntialiasNone;
ui->gammaBox->setEnabled(false);
break;
case 1:
mode = GLowLevelTextRender::AntialiasGray;
ui->gammaBox->setEnabled(true);
break;
case 2:
mode = GLowLevelTextRender::AntialiasLCD_RGB;
ui->gammaBox->setEnabled(true);
break;
case 3:
mode = GLowLevelTextRender::AntialiasLCD_BGR;
ui->gammaBox->setEnabled(true);
break;
case 4:
mode = GLowLevelTextRender::AntialiasLCD_PenTile;
ui->gammaBox->setEnabled(true);
break;
case 5:
mode = GLowLevelTextRender::AntialiasLCD_V_RGB;
ui->gammaBox->setEnabled(true);
break;
case 6:
mode = GLowLevelTextRender::AntialiasLCD_V_BGR;
ui->gammaBox->setEnabled(true);
break;
case 7:
mode = GLowLevelTextRender::AntialiasLCD_V_PenTile;
ui->gammaBox->setEnabled(true);
break;
default:
mode = GLowLevelTextRender::AntialiasGray;
ui->gammaBox->setEnabled(true);
break;
}
ui->previewWidget->setAntialiasingMode(mode);
}
void GMainWindow::slot_hintingChanged(int index)
{
GLowLevelTextRender::HintingMode mode;
switch (index)
{
case 0:
mode = GLowLevelTextRender::HintingNone;
break;
case 1:
mode = GLowLevelTextRender::HintingByteCode;
break;
case 2:
mode = GLowLevelTextRender::HintingAuto;
break;
default:
mode = GLowLevelTextRender::HintingByteCode;
break;
}
ui->previewWidget->setHintingMode(mode);
}
void GMainWindow::slot_gammaChanged(double gamma)
{
ui->previewWidget->setGammaCorrection(gamma);
}
void GMainWindow::slot_kerningChanged(int state)
{
ui->previewWidget->setKerning(ui->kerningBox->isChecked());
}
void GMainWindow::slot_ligaturesChanged(int state)
{
ui->previewWidget->setAllowLigatures(ui->ligaturesBox->isChecked());
}
void GMainWindow::slot_textColorChanged(const QColor& c)
{
ui->previewWidget->setTextColor(c);
}
void GMainWindow::slot_backgroundColorChanged(const QColor& c)
{
ui->previewWidget->setBackgroundColor(c);
}
void GMainWindow::onFontChanged()
{
QStringList langList = ui->previewWidget->getSupportedLanguages();
QString langListStr;
QStringList::const_iterator it = langList.begin();
while (true)
{
if (it != langList.end())
langListStr += *it;
else
break;
++it;
if (it != langList.end())
langListStr += QString(",");
else
break;
}
ui->langList->setPlainText(langListStr);
}