FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
ghostwriter/src/SimpleFontDialog.cpp at master · jackcoolpython/ghostwriter · GitHub
jackcoolpython
ghostwriter
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
ghostwriter
/
src
/
SimpleFontDialog.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
178 lines (146 loc) · 5.16 KB
Breadcrumbs
ghostwriter
/
src
/
SimpleFontDialog.cpp
Copy path
File metadata and controls
178 lines (146 loc) · 5.16 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
/*
**********************************************************************
*
* Copyright (C) 2014-2017 wereturtle
*
* 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
<
QGridLayout
>
#
include
<
QLineEdit
>
#
include
<
QList
>
#
include
<
QLabel
>
#
include
<
QDialogButtonBox
>
#
include
<
QComboBox
>
#
include
<
QFontComboBox
>
#
include
<
QFontInfo
>
#
include
"
SimpleFontDialog.h
"
SimpleFontDialog::SimpleFontDialog
(QWidget* parent)
{
SimpleFontDialog
(
QFont
(), parent);
}
SimpleFontDialog::SimpleFontDialog
(
const
QFont& initial, QWidget* parent)
: QDialog(parent)
{
QFontComboBox* fontComboBox =
new
QFontComboBox
(
this
);
fontComboBox->
setCurrentFont
(initial);
font = initial;
QVBoxLayout* familyLayout =
new
QVBoxLayout
();
familyLayout->
addWidget
(
new
QLabel
(
tr
(
"
Family
"
)));
familyLayout->
addWidget
(fontComboBox);
QList<
int
> sizes =
QFontDatabase::standardSizes
();
QComboBox* sizeComboBox =
new
QComboBox
(
this
);
sizeComboBox->
setEditable
(
true
);
QIntValidator* sizeValidator =
new
QIntValidator
(
1
,
512
,
this
);
sizeComboBox->
setValidator
(sizeValidator);
int
currentSizeIndex =
0
;
QFontInfo
fontInfo
(initial);
bool
currentFontInserted =
false
;
for
(
int
i =
0
; i < sizes.
size
(); i++)
{
int
size = sizes[i];
//
If the current font size is a non-standard size, then insert
//
it in the appropriate place in the sorted list of fonts.
//
if
((fontInfo.
pointSize
() < size) && !currentFontInserted)
{
currentSizeIndex = i;
sizeComboBox->
addItem
(
QString
(
"
%1
"
).
arg
(fontInfo.
pointSize
()), fontInfo.
pointSize
());
currentFontInserted =
true
;
}
//
Else current font size is in the standard font sizes list. Set
//
the index in the combo box to its position in the list.
//
else
{
if
(fontInfo.
pointSize
() == size)
{
currentSizeIndex = i;
currentFontInserted =
true
;
}
}
sizeComboBox->
addItem
(
QString
(
"
%1
"
).
arg
(size), size);
}
if
(!currentFontInserted)
{
sizeComboBox->
addItem
(
QString
(
"
%1
"
).
arg
(fontInfo.
pointSize
()), fontInfo.
pointSize
());
currentSizeIndex = sizeComboBox->
count
() -
1
;
}
sizeComboBox->
setCurrentIndex
(currentSizeIndex);
QVBoxLayout* sizeLayout =
new
QVBoxLayout
();
sizeLayout->
addWidget
(
new
QLabel
(
tr
(
"
Size
"
)));
sizeLayout->
addWidget
(sizeComboBox);
fontPreview =
new
QLineEdit
(
tr
(
"
AaBbCcXxYyZz
"
),
this
);
fontPreview->
setFont
(initial);
QVBoxLayout* previewLayout =
new
QVBoxLayout
();
previewLayout->
addWidget
(
new
QLabel
(
tr
(
"
Preview
"
)));
previewLayout->
addWidget
(fontPreview);
QDialogButtonBox* buttonBox =
new
QDialogButtonBox
(Qt::Horizontal,
this
);
buttonBox->
addButton
(QDialogButtonBox::Ok);
buttonBox->
addButton
(QDialogButtonBox::Cancel);
QGridLayout* layout =
new
QGridLayout
();
layout->
addItem
(familyLayout,
0
,
0
);
layout->
addItem
(sizeLayout,
0
,
1
);
layout->
addItem
(previewLayout,
1
,
0
,
1
,
2
, Qt::AlignCenter);
layout->
addWidget
(buttonBox,
2
,
0
,
1
,
2
);
setLayout
(layout);
connect
(buttonBox,
SIGNAL
(
accepted
()),
this
,
SLOT
(
accept
()));
connect
(buttonBox,
SIGNAL
(
rejected
()),
this
,
SLOT
(
reject
()));
connect
(fontComboBox,
SIGNAL
(
currentFontChanged
(QFont)),
this
,
SLOT
(
onFontFamilyChanged
(
const
QFont&)));
connect
(sizeComboBox,
SIGNAL
(
currentIndexChanged
(QString)),
this
,
SLOT
(
onFontSizeChanged
(
const
QString&)));
connect
(sizeComboBox,
SIGNAL
(
editTextChanged
(QString)),
this
,
SLOT
(
onFontSizeChanged
(
const
QString&)));
}
SimpleFontDialog::~SimpleFontDialog
()
{
}
QFont
SimpleFontDialog::getSelectedFont
()
const
{
return
font;
}
QFont SimpleFontDialog::getFont
(
bool
* ok,
const
QFont& initial,
QWidget* parent
)
{
*ok =
false
;
SimpleFontDialog* dlg =
new
SimpleFontDialog
(initial, parent);
int
result = dlg->
exec
();
if
(QDialog::Accepted == result)
{
*ok =
true
;
}
return
dlg->
getSelectedFont
();
}
QFont
SimpleFontDialog::getFont
(
bool
* ok, QWidget* parent)
{
return
getFont
(ok,
QFont
(), parent);
}
void
SimpleFontDialog::onFontFamilyChanged
(
const
QFont& font)
{
int
size =
this
->
font
.
pointSize
();
this
->
font
= font;
this
->
font
.
setPointSize
(size);
fontPreview->
setFont
(
this
->
font
);
}
void
SimpleFontDialog::onFontSizeChanged
(
const
QString& sizeText)
{
bool
ok =
false
;
int
size = sizeText.
toInt
(&ok);
if
(ok)
{
font.
setPointSize
(size);
fontPreview->
setFont
(font);
}
}
Back
|
FazBrowse Home
|
New Git URL