Changeset View
Changeset View
Standalone View
Standalone View
src/kfontchooser.cpp
Show First 20 Lines • Show All 83 Lines • ▼ Show 20 Line(s) | 81 | public: | |||
---|---|---|---|---|---|
84 | { | 84 | { | ||
85 | m_palette.setColor(QPalette::Active, QPalette::Text, Qt::black); | 85 | m_palette.setColor(QPalette::Active, QPalette::Text, Qt::black); | ||
86 | m_palette.setColor(QPalette::Active, QPalette::Base, Qt::white); | 86 | m_palette.setColor(QPalette::Active, QPalette::Base, Qt::white); | ||
87 | signalsAllowed = true; | 87 | signalsAllowed = true; | ||
88 | selectedSize = -1; | 88 | selectedSize = -1; | ||
89 | customSizeRow = -1; | 89 | customSizeRow = -1; | ||
90 | } | 90 | } | ||
91 | 91 | | |||
92 | // pointer to an optinally supplied list of fonts to | | |||
93 | // inserted into the fontdialog font-family combo-box | | |||
94 | // QStringList fontList; | | |||
95 | | ||||
96 | void setFamilyBoxItems(const QStringList &fonts); | 92 | void setFamilyBoxItems(const QStringList &fonts); | ||
97 | void fillFamilyListBox(bool onlyFixedFonts = false); | 93 | void fillFamilyListBox(bool onlyFixedFonts = false); | ||
98 | int nearestSizeRow(qreal val, bool customize); | 94 | int nearestSizeRow(qreal val, bool customize); | ||
99 | qreal fillSizeList(const QList<qreal> &sizes = QList<qreal>()); | 95 | qreal fillSizeList(const QList<qreal> &sizes = QList<qreal>()); | ||
100 | qreal setupSizeListBox(const QString &family, const QString &style); | 96 | qreal setupSizeListBox(const QString &family, const QString &style); | ||
101 | 97 | | |||
102 | void setupDisplay(); | 98 | void setupDisplay(); | ||
103 | QString styleIdentifier(const QFont &font); | 99 | QString styleIdentifier(const QFont &font); | ||
104 | 100 | | |||
105 | void _k_toggled_checkbox(); | | |||
106 | void _k_family_chosen_slot(const QString &); | 101 | void _k_family_chosen_slot(const QString &); | ||
107 | void _k_size_chosen_slot(const QString &); | 102 | void _k_size_chosen_slot(const QString &); | ||
108 | void _k_style_chosen_slot(const QString &); | 103 | void _k_style_chosen_slot(const QString &); | ||
109 | void _k_displaySample(const QFont &font); | 104 | void _k_displaySample(const QFont &font); | ||
110 | void _k_size_value_slot(double); | 105 | void _k_size_value_slot(double); | ||
111 | 106 | | |||
112 | KFontChooser *q; | 107 | KFontChooser *q; | ||
113 | 108 | | |||
114 | QPalette m_palette; | 109 | QPalette m_palette; | ||
115 | 110 | | |||
116 | QDoubleSpinBox *sizeOfFont = nullptr; | 111 | QFontDatabase fdb; | ||
117 | | ||||
118 | QTextEdit *sampleEdit = nullptr; | | |||
119 | 112 | | |||
120 | QLabel *familyLabel = nullptr; | 113 | QLabel *familyLabel = nullptr; | ||
121 | QLabel *styleLabel = nullptr; | 114 | QLabel *styleLabel = nullptr; | ||
115 | QLabel *sizeLabel = nullptr; | ||||
116 | | ||||
122 | QCheckBox *familyCheckbox = nullptr; | 117 | QCheckBox *familyCheckbox = nullptr; | ||
123 | QCheckBox *styleCheckbox = nullptr; | 118 | QCheckBox *styleCheckbox = nullptr; | ||
124 | QCheckBox *sizeCheckbox = nullptr; | 119 | QCheckBox *sizeCheckbox = nullptr; | ||
125 | QLabel *sizeLabel = nullptr; | 120 | | ||
126 | QListWidget *familyListBox = nullptr; | 121 | QListWidget *familyListBox = nullptr; | ||
127 | QListWidget *styleListBox = nullptr; | 122 | QListWidget *styleListBox = nullptr; | ||
128 | QListWidget *sizeListBox = nullptr; | 123 | QListWidget *sizeListBox = nullptr; | ||
124 | | ||||
125 | QDoubleSpinBox *sizeOfFont = nullptr; | ||||
126 | | ||||
129 | QCheckBox *sizeIsRelativeCheckBox = nullptr; | 127 | QCheckBox *sizeIsRelativeCheckBox = nullptr; | ||
130 | 128 | | |||
129 | QTextEdit *sampleEdit = nullptr; | ||||
130 | | ||||
131 | QFont selFont; | 131 | QFont selFont; | ||
132 | 132 | | |||
133 | QString selectedStyle; | 133 | QString selectedStyle; | ||
134 | qreal selectedSize; | 134 | qreal selectedSize; | ||
135 | 135 | | |||
136 | QString standardSizeAtCustom; | 136 | QString standardSizeAtCustom; | ||
137 | int customSizeRow; | 137 | int customSizeRow; | ||
138 | 138 | | |||
▲ Show 20 Lines • Show All 53 Lines • ▼ Show 20 Line(s) | 158 | { | |||
192 | 192 | | |||
193 | // | 193 | // | ||
194 | // first, create the labels across the top | 194 | // first, create the labels across the top | ||
195 | // | 195 | // | ||
196 | QHBoxLayout *familyLayout = new QHBoxLayout(); | 196 | QHBoxLayout *familyLayout = new QHBoxLayout(); | ||
197 | familyLayout->addSpacing(checkBoxGap); | 197 | familyLayout->addSpacing(checkBoxGap); | ||
198 | if (flags & ShowDifferences) { | 198 | if (flags & ShowDifferences) { | ||
199 | d->familyCheckbox = new QCheckBox(KFontChooser::tr("Font", "@option:check"), page); | 199 | d->familyCheckbox = new QCheckBox(KFontChooser::tr("Font", "@option:check"), page); | ||
200 | connect(d->familyCheckbox, SIGNAL(toggled(bool)), | 200 | connect(d->familyCheckbox, &QAbstractButton::toggled, | ||
201 | this, SLOT(_k_toggled_checkbox())); | 201 | this, [this](const bool state) { d->familyListBox->setEnabled(state); }); | ||
202 | familyLayout->addWidget(d->familyCheckbox, 0, Qt::AlignLeft); | 202 | familyLayout->addWidget(d->familyCheckbox, 0, Qt::AlignLeft); | ||
203 | d->familyCheckbox->setWhatsThis(KFontChooser::tr("Enable this checkbox to change the font family settings.", "@info:whatsthis")); | 203 | d->familyCheckbox->setWhatsThis(KFontChooser::tr("Enable this checkbox to change the font family settings.", "@info:whatsthis")); | ||
204 | d->familyCheckbox->setToolTip(KFontChooser::tr("Change font family?", "@info:tooltip")); | 204 | d->familyCheckbox->setToolTip(KFontChooser::tr("Change font family?", "@info:tooltip")); | ||
205 | d->familyLabel = nullptr; | 205 | d->familyLabel = nullptr; | ||
206 | } else { | 206 | } else { | ||
207 | d->familyCheckbox = nullptr; | 207 | d->familyCheckbox = nullptr; | ||
208 | d->familyLabel = new QLabel(KFontChooser::tr("Font:", "@label"), page); | 208 | d->familyLabel = new QLabel(KFontChooser::tr("Font:", "@label"), page); | ||
209 | familyLayout->addWidget(d->familyLabel, 1, Qt::AlignLeft); | 209 | familyLayout->addWidget(d->familyLabel, 1, Qt::AlignLeft); | ||
210 | } | 210 | } | ||
211 | gridLayout->addLayout(familyLayout, row, 0); | 211 | gridLayout->addLayout(familyLayout, row, 0); | ||
212 | 212 | | |||
213 | QHBoxLayout *styleLayout = new QHBoxLayout(); | 213 | QHBoxLayout *styleLayout = new QHBoxLayout(); | ||
214 | if (flags & ShowDifferences) { | 214 | if (flags & ShowDifferences) { | ||
215 | d->styleCheckbox = new QCheckBox(KFontChooser::tr("Font style", "@option:check"), page); | 215 | d->styleCheckbox = new QCheckBox(KFontChooser::tr("Font style", "@option:check"), page); | ||
216 | connect(d->styleCheckbox, SIGNAL(toggled(bool)), | 216 | connect(d->styleCheckbox, &QAbstractButton::toggled, | ||
217 | this, SLOT(_k_toggled_checkbox())); | 217 | this, [this](const bool state) { d->styleListBox->setEnabled(state); }); | ||
218 | styleLayout->addWidget(d->styleCheckbox, 0, Qt::AlignLeft); | 218 | styleLayout->addWidget(d->styleCheckbox, 0, Qt::AlignLeft); | ||
219 | d->styleCheckbox->setWhatsThis(KFontChooser::tr("Enable this checkbox to change the font style settings.", "@info:whatsthis")); | 219 | d->styleCheckbox->setWhatsThis(KFontChooser::tr("Enable this checkbox to change the font style settings.", "@info:whatsthis")); | ||
220 | d->styleCheckbox->setToolTip(KFontChooser::tr("Change font style?", "@info:tooltip")); | 220 | d->styleCheckbox->setToolTip(KFontChooser::tr("Change font style?", "@info:tooltip")); | ||
221 | d->styleLabel = nullptr; | 221 | d->styleLabel = nullptr; | ||
222 | } else { | 222 | } else { | ||
223 | d->styleCheckbox = nullptr; | 223 | d->styleCheckbox = nullptr; | ||
224 | d->styleLabel = new QLabel(KFontChooser::tr("Font style:"), page); | 224 | d->styleLabel = new QLabel(KFontChooser::tr("Font style:"), page); | ||
225 | styleLayout->addWidget(d->styleLabel, 1, Qt::AlignLeft); | 225 | styleLayout->addWidget(d->styleLabel, 1, Qt::AlignLeft); | ||
226 | } | 226 | } | ||
227 | styleLayout->addSpacing(checkBoxGap); | 227 | styleLayout->addSpacing(checkBoxGap); | ||
228 | gridLayout->addLayout(styleLayout, row, 1); | 228 | gridLayout->addLayout(styleLayout, row, 1); | ||
229 | 229 | | |||
230 | QHBoxLayout *sizeLayout = new QHBoxLayout(); | 230 | QHBoxLayout *sizeLayout = new QHBoxLayout(); | ||
231 | if (flags & ShowDifferences) { | 231 | if (flags & ShowDifferences) { | ||
232 | d->sizeCheckbox = new QCheckBox(KFontChooser::tr("Size", "@option:check"), page); | 232 | d->sizeCheckbox = new QCheckBox(KFontChooser::tr("Size", "@option:check"), page); | ||
233 | connect(d->sizeCheckbox, SIGNAL(toggled(bool)), | 233 | | ||
234 | this, SLOT(_k_toggled_checkbox())); | 234 | connect(d->sizeCheckbox, &QAbstractButton::toggled, this, [this](const bool state) { | ||
235 | d->sizeListBox->setEnabled(state); | ||||
236 | d->sizeOfFont->setEnabled(state); | ||||
237 | }); | ||||
238 | | ||||
235 | sizeLayout->addWidget(d->sizeCheckbox, 0, Qt::AlignLeft); | 239 | sizeLayout->addWidget(d->sizeCheckbox, 0, Qt::AlignLeft); | ||
236 | d->sizeCheckbox->setWhatsThis(KFontChooser::tr("Enable this checkbox to change the font size settings.", "@info:whatsthis")); | 240 | d->sizeCheckbox->setWhatsThis(KFontChooser::tr("Enable this checkbox to change the font size settings.", "@info:whatsthis")); | ||
237 | d->sizeCheckbox->setToolTip(KFontChooser::tr("Change font size?", "@info:tooltip")); | 241 | d->sizeCheckbox->setToolTip(KFontChooser::tr("Change font size?", "@info:tooltip")); | ||
238 | d->sizeLabel = nullptr; | 242 | d->sizeLabel = nullptr; | ||
239 | } else { | 243 | } else { | ||
240 | d->sizeCheckbox = nullptr; | 244 | d->sizeCheckbox = nullptr; | ||
241 | d->sizeLabel = new QLabel(KFontChooser::tr("Size:", "@label:listbox Font size"), page); | 245 | d->sizeLabel = new QLabel(KFontChooser::tr("Size:", "@label:listbox Font size"), page); | ||
242 | sizeLayout->addWidget(d->sizeLabel, 1, Qt::AlignLeft); | 246 | sizeLayout->addWidget(d->sizeLabel, 1, Qt::AlignLeft); | ||
243 | } | 247 | } | ||
244 | sizeLayout->addSpacing(checkBoxGap); | 248 | sizeLayout->addSpacing(checkBoxGap); | ||
245 | sizeLayout->addSpacing(checkBoxGap); // prevent label from eating border | 249 | sizeLayout->addSpacing(checkBoxGap); // prevent label from eating border | ||
246 | gridLayout->addLayout(sizeLayout, row, 2); | 250 | gridLayout->addLayout(sizeLayout, row, 2); | ||
247 | 251 | | |||
248 | row ++; | 252 | ++row; | ||
249 | 253 | | |||
250 | // | 254 | // | ||
251 | // now create the actual boxes that hold the info | 255 | // now create the actual boxes that hold the info | ||
252 | // | 256 | // | ||
253 | d->familyListBox = new QListWidget(page); | 257 | d->familyListBox = new QListWidget(page); | ||
254 | d->familyListBox->setEnabled(flags ^ ShowDifferences); | 258 | d->familyListBox->setEnabled(flags ^ ShowDifferences); | ||
255 | gridLayout->addWidget(d->familyListBox, row, 0); | 259 | gridLayout->addWidget(d->familyListBox, row, 0); | ||
256 | QString fontFamilyWhatsThisText( | 260 | QString fontFamilyWhatsThisText( | ||
257 | KFontChooser::tr("Here you can choose the font family to be used.", "@info:whatsthis")); | 261 | KFontChooser::tr("Here you can choose the font family to be used.", "@info:whatsthis")); | ||
258 | d->familyListBox->setWhatsThis(fontFamilyWhatsThisText); | 262 | d->familyListBox->setWhatsThis(fontFamilyWhatsThisText); | ||
259 | 263 | | |||
260 | if (flags & ShowDifferences) { | 264 | if (flags & ShowDifferences) { | ||
261 | d->familyCheckbox->setWhatsThis(fontFamilyWhatsThisText); | 265 | d->familyCheckbox->setWhatsThis(fontFamilyWhatsThisText); | ||
262 | } else { | 266 | } else { | ||
263 | d->familyLabel->setWhatsThis(fontFamilyWhatsThisText); | 267 | d->familyLabel->setWhatsThis(fontFamilyWhatsThisText); | ||
264 | } | 268 | } | ||
265 | 269 | | |||
266 | connect(d->familyListBox, SIGNAL(currentTextChanged(QString)), | 270 | connect(d->familyListBox, &QListWidget::currentTextChanged, | ||
267 | this, SLOT(_k_family_chosen_slot(QString))); | 271 | this, [this](const QString &family) { d->_k_family_chosen_slot(family); }); | ||
272 | | ||||
268 | if (!fontList.isEmpty()) { | 273 | if (!fontList.isEmpty()) { | ||
269 | d->setFamilyBoxItems(fontList); | 274 | d->setFamilyBoxItems(fontList); | ||
270 | } else { | 275 | } else { | ||
271 | d->fillFamilyListBox(flags & FixedFontsOnly); | 276 | d->fillFamilyListBox(flags & FixedFontsOnly); | ||
272 | } | 277 | } | ||
273 | 278 | | |||
274 | d->familyListBox->setMinimumWidth(minimumListWidth(d->familyListBox)); | 279 | d->familyListBox->setMinimumWidth(minimumListWidth(d->familyListBox)); | ||
275 | d->familyListBox->setMinimumHeight( | 280 | d->familyListBox->setMinimumHeight(minimumListHeight(d->familyListBox, visibleListSize)); | ||
276 | minimumListHeight(d->familyListBox, visibleListSize)); | | |||
277 | 281 | | |||
278 | d->styleListBox = new QListWidget(page); | 282 | d->styleListBox = new QListWidget(page); | ||
279 | d->styleListBox->setEnabled(flags ^ ShowDifferences); | 283 | d->styleListBox->setEnabled(flags ^ ShowDifferences); | ||
280 | gridLayout->addWidget(d->styleListBox, row, 1); | 284 | gridLayout->addWidget(d->styleListBox, row, 1); | ||
281 | d->styleListBox->setWhatsThis(KFontChooser::tr("Here you can choose the font style to be used.", "@info:whatsthis")); | 285 | d->styleListBox->setWhatsThis(KFontChooser::tr("Here you can choose the font style to be used.", "@info:whatsthis")); | ||
282 | if (flags & ShowDifferences) { | 286 | if (flags & ShowDifferences) { | ||
283 | ((QWidget *)d->styleCheckbox)->setWhatsThis(fontFamilyWhatsThisText); | 287 | ((QWidget *)d->styleCheckbox)->setWhatsThis(fontFamilyWhatsThisText); | ||
284 | } else { | 288 | } else { | ||
285 | ((QWidget *)d->styleLabel)->setWhatsThis(fontFamilyWhatsThisText); | 289 | ((QWidget *)d->styleLabel)->setWhatsThis(fontFamilyWhatsThisText); | ||
286 | } | 290 | } | ||
287 | // Populate usual styles, to determine minimum list width; | 291 | // Populate usual styles, to determine minimum list width; | ||
288 | // will be replaced later with correct styles. | 292 | // will be replaced later with correct styles. | ||
289 | d->styleListBox->addItem(KFontChooser::tr("Normal", "QFontDatabase")); | 293 | d->styleListBox->addItem(KFontChooser::tr("Normal", "QFontDatabase")); | ||
290 | d->styleListBox->addItem(KFontChooser::tr("Italic", "@item font")); | 294 | d->styleListBox->addItem(KFontChooser::tr("Italic", "@item font")); | ||
291 | d->styleListBox->addItem(KFontChooser::tr("Oblique", "@item font")); | 295 | d->styleListBox->addItem(KFontChooser::tr("Oblique", "@item font")); | ||
292 | d->styleListBox->addItem(KFontChooser::tr("Bold", "@item font")); | 296 | d->styleListBox->addItem(KFontChooser::tr("Bold", "@item font")); | ||
293 | d->styleListBox->addItem(KFontChooser::tr("Bold Italic", "@item font")); | 297 | d->styleListBox->addItem(KFontChooser::tr("Bold Italic", "@item font")); | ||
294 | d->styleListBox->setMinimumWidth(minimumListWidth(d->styleListBox)); | 298 | d->styleListBox->setMinimumWidth(minimumListWidth(d->styleListBox)); | ||
295 | d->styleListBox->setMinimumHeight( | 299 | d->styleListBox->setMinimumHeight(minimumListHeight(d->styleListBox, visibleListSize)); | ||
296 | minimumListHeight(d->styleListBox, visibleListSize)); | | |||
297 | 300 | | |||
298 | connect(d->styleListBox, SIGNAL(currentTextChanged(QString)), | 301 | connect(d->styleListBox, &QListWidget::currentTextChanged, | ||
299 | this, SLOT(_k_style_chosen_slot(QString))); | 302 | this, [this](const QString &style) { d->_k_style_chosen_slot(style); }); | ||
300 | 303 | | |||
301 | d->sizeListBox = new QListWidget(page); | 304 | d->sizeListBox = new QListWidget(page); | ||
302 | d->sizeOfFont = new QDoubleSpinBox(page); | 305 | d->sizeOfFont = new QDoubleSpinBox(page); | ||
303 | d->sizeOfFont->setMinimum(4); | 306 | d->sizeOfFont->setMinimum(4); | ||
304 | d->sizeOfFont->setMaximum(999); | 307 | d->sizeOfFont->setMaximum(999); | ||
305 | d->sizeOfFont->setDecimals(1); | 308 | d->sizeOfFont->setDecimals(1); | ||
306 | d->sizeOfFont->setSingleStep(1); | 309 | d->sizeOfFont->setSingleStep(1); | ||
307 | 310 | | |||
Show All 36 Lines | 346 | if (flags & ShowDifferences) { | |||
344 | ((QWidget *)d->sizeCheckbox)->setWhatsThis(fontSizeWhatsThisText); | 347 | ((QWidget *)d->sizeCheckbox)->setWhatsThis(fontSizeWhatsThisText); | ||
345 | } else { | 348 | } else { | ||
346 | ((QWidget *)d->sizeLabel)->setWhatsThis(fontSizeWhatsThisText); | 349 | ((QWidget *)d->sizeLabel)->setWhatsThis(fontSizeWhatsThisText); | ||
347 | } | 350 | } | ||
348 | 351 | | |||
349 | // Populate with usual sizes, to determine minimum list width; | 352 | // Populate with usual sizes, to determine minimum list width; | ||
350 | // will be replaced later with correct sizes. | 353 | // will be replaced later with correct sizes. | ||
351 | d->fillSizeList(); | 354 | d->fillSizeList(); | ||
352 | d->sizeListBox->setMinimumWidth(minimumListWidth(d->sizeListBox) + | 355 | d->sizeListBox->setMinimumWidth(minimumListWidth(d->sizeListBox) | ||
353 | d->sizeListBox->fontMetrics().maxWidth()); | 356 | + d->sizeListBox->fontMetrics().maxWidth()); | ||
354 | d->sizeListBox->setMinimumHeight( | 357 | d->sizeListBox->setMinimumHeight(minimumListHeight(d->sizeListBox, visibleListSize)); | ||
355 | minimumListHeight(d->sizeListBox, visibleListSize)); | | |||
356 | 358 | | |||
357 | connect(d->sizeOfFont, SIGNAL(valueChanged(double)), | 359 | connect(d->sizeOfFont, QOverload<double>::of(&QDoubleSpinBox::valueChanged), | ||
358 | this, SLOT(_k_size_value_slot(double))); | 360 | this, [this](const double size) { d->_k_size_value_slot(size); }); | ||
359 | 361 | | |||
360 | connect(d->sizeListBox, SIGNAL(currentTextChanged(QString)), | 362 | connect(d->sizeListBox, &QListWidget::currentTextChanged, | ||
361 | this, SLOT(_k_size_chosen_slot(QString))); | 363 | this, [this](const QString &size) { d->_k_size_chosen_slot(size); }); | ||
362 | 364 | | |||
363 | row ++; | 365 | ++row; | ||
364 | // | 366 | // | ||
365 | // Completed the font attribute grid. | 367 | // Completed the font attribute grid. | ||
366 | 368 | | |||
367 | // Add the font preview into the lower part of the splitter. | 369 | // Add the font preview into the lower part of the splitter. | ||
368 | // | 370 | // | ||
369 | d->sampleEdit = new QTextEdit(page); | 371 | d->sampleEdit = new QTextEdit(page); | ||
370 | d->sampleEdit->setAcceptRichText(false); | 372 | d->sampleEdit->setAcceptRichText(false); | ||
371 | QFont tmpFont(font().family(), 64, QFont::Black); | 373 | QFont tmpFont(font().family(), 64, QFont::Black); | ||
372 | d->sampleEdit->setFont(tmpFont); | 374 | d->sampleEdit->setFont(tmpFont); | ||
373 | d->sampleEdit->setMinimumHeight(d->sampleEdit->fontMetrics().lineSpacing()); | 375 | d->sampleEdit->setMinimumHeight(d->sampleEdit->fontMetrics().lineSpacing()); | ||
374 | // tr: A classical test phrase, with all letters of the English alphabet. | 376 | // tr: A classical test phrase, with all letters of the English alphabet. | ||
375 | // Replace it with a sample text in your language, such that it is | 377 | // Replace it with a sample text in your language, such that it is | ||
376 | // representative of language's writing system. | 378 | // representative of language's writing system. | ||
377 | // If you wish, you can input several lines of text separated by \n. | 379 | // If you wish, you can input several lines of text separated by \n. | ||
378 | setSampleText(KFontChooser::tr("The Quick Brown Fox Jumps Over The Lazy Dog")); | 380 | setSampleText(KFontChooser::tr("The Quick Brown Fox Jumps Over The Lazy Dog")); | ||
379 | d->sampleEdit->setTextCursor(QTextCursor(d->sampleEdit->document())); | 381 | d->sampleEdit->setTextCursor(QTextCursor(d->sampleEdit->document())); | ||
380 | QString sampleEditWhatsThisText = | 382 | QString sampleEditWhatsThisText = | ||
381 | KFontChooser::tr("This sample text illustrates the current settings. " | 383 | KFontChooser::tr("This sample text illustrates the current settings. " | ||
382 | "You may edit it to test special characters."); | 384 | "You may edit it to test special characters."); | ||
383 | d->sampleEdit->setWhatsThis(sampleEditWhatsThisText); | 385 | d->sampleEdit->setWhatsThis(sampleEditWhatsThisText); | ||
384 | 386 | | |||
385 | connect(this, SIGNAL(fontSelected(QFont)), | 387 | connect(this, &KFontChooser::fontSelected, | ||
386 | this, SLOT(_k_displaySample(QFont))); | 388 | this, [this](const QFont &font) { d->_k_displaySample(font); }); | ||
387 | 389 | | |||
388 | splitter->addWidget(d->sampleEdit); | 390 | splitter->addWidget(d->sampleEdit); | ||
389 | // | 391 | // | ||
390 | // Finished setting up the splitter. | 392 | // Finished setting up the splitter. | ||
391 | 393 | | |||
392 | // | 394 | // | ||
393 | // Finished setting up the chooser layout. | 395 | // Finished setting up the chooser layout. | ||
394 | 396 | | |||
▲ Show 20 Lines • Show All 135 Lines • ▼ Show 20 Line(s) | 517 | { | |||
530 | return diffFlags; | 532 | return diffFlags; | ||
531 | } | 533 | } | ||
532 | 534 | | |||
533 | QFont KFontChooser::font() const | 535 | QFont KFontChooser::font() const | ||
534 | { | 536 | { | ||
535 | return d->selFont; | 537 | return d->selFont; | ||
536 | } | 538 | } | ||
537 | 539 | | |||
538 | void KFontChooser::Private::_k_toggled_checkbox() | | |||
539 | { | | |||
540 | familyListBox->setEnabled(familyCheckbox->isChecked()); | | |||
541 | styleListBox->setEnabled(styleCheckbox->isChecked()); | | |||
542 | sizeListBox->setEnabled(sizeCheckbox->isChecked()); | | |||
543 | sizeOfFont->setEnabled(sizeCheckbox->isChecked()); | | |||
544 | } | | |||
545 | | ||||
546 | void KFontChooser::Private::_k_family_chosen_slot(const QString &family) | 540 | void KFontChooser::Private::_k_family_chosen_slot(const QString &family) | ||
547 | { | 541 | { | ||
548 | if (!signalsAllowed) { | 542 | if (!signalsAllowed) { | ||
549 | return; | 543 | return; | ||
550 | } | 544 | } | ||
551 | signalsAllowed = false; | 545 | signalsAllowed = false; | ||
552 | 546 | | |||
553 | QString currentFamily; | 547 | QString currentFamily; | ||
554 | if (family.isEmpty()) { | 548 | if (family.isEmpty()) { | ||
555 | Q_ASSERT(familyListBox->currentItem()); | 549 | Q_ASSERT(familyListBox->currentItem()); | ||
556 | if (familyListBox->currentItem()) { | 550 | if (familyListBox->currentItem()) { | ||
557 | currentFamily = qtFamilies[familyListBox->currentItem()->text()]; | 551 | currentFamily = qtFamilies[familyListBox->currentItem()->text()]; | ||
558 | } | 552 | } | ||
559 | } else { | 553 | } else { | ||
560 | currentFamily = qtFamilies[family]; | 554 | currentFamily = qtFamilies[family]; | ||
561 | } | 555 | } | ||
562 | 556 | | |||
563 | // Get the list of styles available in this family. | 557 | // Get the list of styles available in this family. | ||
564 | QFontDatabase dbase; | 558 | QStringList styles = fdb.styles(currentFamily); | ||
565 | QStringList styles = dbase.styles(currentFamily); | | |||
566 | if (styles.isEmpty()) { | 559 | if (styles.isEmpty()) { | ||
567 | // Avoid extraction, it is in kdeqt.po | 560 | // Avoid extraction, it is in kdeqt.po | ||
568 | styles.append(TR_NOX("Normal", "QFontDatabase")); | 561 | styles.append(TR_NOX("Normal", "QFontDatabase")); | ||
569 | } | 562 | } | ||
570 | 563 | | |||
571 | // Filter style strings and add to the listbox. | 564 | // Filter style strings and add to the listbox. | ||
572 | QString pureFamily; | 565 | QString pureFamily; | ||
573 | splitFontString(family, &pureFamily); | 566 | splitFontString(family, &pureFamily); | ||
574 | QStringList filteredStyles; | 567 | QStringList filteredStyles; | ||
575 | qtStyles.clear(); | 568 | qtStyles.clear(); | ||
576 | styleIDs.clear(); | 569 | styleIDs.clear(); | ||
577 | Q_FOREACH (const QString &style, styles) { | 570 | | ||
571 | const QStringList origStyles = styles; | ||||
572 | for (const QString &style : origStyles) { | ||||
578 | // Sometimes the font database will report an invalid style, | 573 | // Sometimes the font database will report an invalid style, | ||
579 | // that falls back back to another when set. | 574 | // that falls back back to another when set. | ||
580 | // Remove such styles, by checking set/get round-trip. | 575 | // Remove such styles, by checking set/get round-trip. | ||
581 | QFont testFont = dbase.font(currentFamily, style, 10); | 576 | QFont testFont = fdb.font(currentFamily, style, 10); | ||
582 | if (dbase.styleString(testFont) != style) { | 577 | if (fdb.styleString(testFont) != style) { | ||
583 | styles.removeAll(style); | 578 | styles.removeAll(style); | ||
584 | continue; | 579 | continue; | ||
585 | } | 580 | } | ||
586 | 581 | | |||
587 | QString fstyle = tr("%1", "@item Font style").arg(style); | 582 | QString fstyle = tr("%1", "@item Font style").arg(style); | ||
588 | if (!filteredStyles.contains(fstyle)) { | 583 | if (!filteredStyles.contains(fstyle)) { | ||
589 | filteredStyles.append(fstyle); | 584 | filteredStyles.append(fstyle); | ||
590 | qtStyles.insert(fstyle, style); | 585 | qtStyles.insert(fstyle, style); | ||
Show All 25 Lines | |||||
616 | } | 611 | } | ||
617 | styleListBox->setCurrentRow(listPos >= 0 ? listPos : 0); | 612 | styleListBox->setCurrentRow(listPos >= 0 ? listPos : 0); | ||
618 | QString currentStyle = qtStyles[styleListBox->currentItem()->text()]; | 613 | QString currentStyle = qtStyles[styleListBox->currentItem()->text()]; | ||
619 | 614 | | |||
620 | // Recompute the size listbox for this family/style. | 615 | // Recompute the size listbox for this family/style. | ||
621 | qreal currentSize = setupSizeListBox(currentFamily, currentStyle); | 616 | qreal currentSize = setupSizeListBox(currentFamily, currentStyle); | ||
622 | sizeOfFont->setValue(currentSize); | 617 | sizeOfFont->setValue(currentSize); | ||
623 | 618 | | |||
624 | selFont = dbase.font(currentFamily, currentStyle, int(currentSize)); | 619 | selFont = fdb.font(currentFamily, currentStyle, int(currentSize)); | ||
625 | if (dbase.isSmoothlyScalable(currentFamily, currentStyle) && selFont.pointSize() == floor(currentSize)) { | 620 | if (fdb.isSmoothlyScalable(currentFamily, currentStyle) && selFont.pointSize() == floor(currentSize)) { | ||
626 | selFont.setPointSizeF(currentSize); | 621 | selFont.setPointSizeF(currentSize); | ||
627 | } | 622 | } | ||
628 | emit q->fontSelected(selFont); | 623 | emit q->fontSelected(selFont); | ||
629 | 624 | | |||
630 | signalsAllowed = true; | 625 | signalsAllowed = true; | ||
631 | } | 626 | } | ||
632 | 627 | | |||
633 | void KFontChooser::Private::_k_style_chosen_slot(const QString &style) | 628 | void KFontChooser::Private::_k_style_chosen_slot(const QString &style) | ||
634 | { | 629 | { | ||
635 | if (!signalsAllowed) { | 630 | if (!signalsAllowed) { | ||
636 | return; | 631 | return; | ||
637 | } | 632 | } | ||
638 | signalsAllowed = false; | 633 | signalsAllowed = false; | ||
639 | 634 | | |||
640 | QFontDatabase dbase; | | |||
641 | QString currentFamily = qtFamilies[familyListBox->currentItem()->text()]; | 635 | QString currentFamily = qtFamilies[familyListBox->currentItem()->text()]; | ||
642 | QString currentStyle; | 636 | QString currentStyle; | ||
643 | if (style.isEmpty()) { | 637 | if (style.isEmpty()) { | ||
644 | currentStyle = qtStyles[styleListBox->currentItem()->text()]; | 638 | currentStyle = qtStyles[styleListBox->currentItem()->text()]; | ||
645 | } else { | 639 | } else { | ||
646 | currentStyle = qtStyles[style]; | 640 | currentStyle = qtStyles[style]; | ||
647 | } | 641 | } | ||
648 | 642 | | |||
649 | // Recompute the size listbox for this family/style. | 643 | // Recompute the size listbox for this family/style. | ||
650 | qreal currentSize = setupSizeListBox(currentFamily, currentStyle); | 644 | qreal currentSize = setupSizeListBox(currentFamily, currentStyle); | ||
651 | sizeOfFont->setValue(currentSize); | 645 | sizeOfFont->setValue(currentSize); | ||
652 | 646 | | |||
653 | selFont = dbase.font(currentFamily, currentStyle, int(currentSize)); | 647 | selFont = fdb.font(currentFamily, currentStyle, int(currentSize)); | ||
654 | if (dbase.isSmoothlyScalable(currentFamily, currentStyle) && selFont.pointSize() == floor(currentSize)) { | 648 | if (fdb.isSmoothlyScalable(currentFamily, currentStyle) && selFont.pointSize() == floor(currentSize)) { | ||
655 | selFont.setPointSizeF(currentSize); | 649 | selFont.setPointSizeF(currentSize); | ||
656 | } | 650 | } | ||
657 | emit q->fontSelected(selFont); | 651 | emit q->fontSelected(selFont); | ||
658 | 652 | | |||
659 | if (!style.isEmpty()) { | 653 | if (!style.isEmpty()) { | ||
660 | selectedStyle = currentStyle; | 654 | selectedStyle = currentStyle; | ||
661 | } | 655 | } | ||
662 | 656 | | |||
Show All 37 Lines | 693 | { | |||
700 | if (!signalsAllowed) { | 694 | if (!signalsAllowed) { | ||
701 | return; | 695 | return; | ||
702 | } | 696 | } | ||
703 | signalsAllowed = false; | 697 | signalsAllowed = false; | ||
704 | 698 | | |||
705 | // We compare with qreal, so convert for platforms where qreal != double. | 699 | // We compare with qreal, so convert for platforms where qreal != double. | ||
706 | qreal val = qreal(dval); | 700 | qreal val = qreal(dval); | ||
707 | 701 | | |||
708 | QFontDatabase dbase; | | |||
709 | QString family = qtFamilies[familyListBox->currentItem()->text()]; | 702 | QString family = qtFamilies[familyListBox->currentItem()->text()]; | ||
710 | QString style = qtStyles[styleListBox->currentItem()->text()]; | 703 | QString style = qtStyles[styleListBox->currentItem()->text()]; | ||
711 | 704 | | |||
712 | // Reset current size slot in list if it was customized. | 705 | // Reset current size slot in list if it was customized. | ||
713 | if (customSizeRow >= 0 && sizeListBox->currentRow() == customSizeRow) { | 706 | if (customSizeRow >= 0 && sizeListBox->currentRow() == customSizeRow) { | ||
714 | sizeListBox->item(customSizeRow)->setText(standardSizeAtCustom); | 707 | sizeListBox->item(customSizeRow)->setText(standardSizeAtCustom); | ||
715 | customSizeRow = -1; | 708 | customSizeRow = -1; | ||
716 | } | 709 | } | ||
717 | 710 | | |||
718 | bool canCustomize = true; | 711 | bool canCustomize = true; | ||
719 | 712 | | |||
720 | // For Qt-bad-sizes workaround: skip this block unconditionally | 713 | // For Qt-bad-sizes workaround: skip this block unconditionally | ||
721 | if (!dbase.isSmoothlyScalable(family, style)) { | 714 | if (!fdb.isSmoothlyScalable(family, style)) { | ||
722 | // Bitmap font, allow only discrete sizes. | 715 | // Bitmap font, allow only discrete sizes. | ||
723 | // Determine the nearest in the direction of change. | 716 | // Determine the nearest in the direction of change. | ||
724 | canCustomize = false; | 717 | canCustomize = false; | ||
725 | int nrows = sizeListBox->count(); | 718 | int nrows = sizeListBox->count(); | ||
726 | int row = sizeListBox->currentRow(); | 719 | int row = sizeListBox->currentRow(); | ||
727 | int nrow; | 720 | int nrow; | ||
728 | if (val - selFont.pointSizeF() > 0) { | 721 | if (val - selFont.pointSizeF() > 0) { | ||
729 | for (nrow = row + 1; nrow < nrows; ++nrow) | 722 | for (nrow = row + 1; nrow < nrows; ++nrow) | ||
▲ Show 20 Lines • Show All 95 Lines • ▼ Show 20 Line(s) | 781 | { | |||
825 | // thus size slot customization is not allowed. | 818 | // thus size slot customization is not allowed. | ||
826 | customSizeRow = -1; | 819 | customSizeRow = -1; | ||
827 | int row = nearestSizeRow(selectedSize, canCustomize); | 820 | int row = nearestSizeRow(selectedSize, canCustomize); | ||
828 | return QLocale::system().toDouble(sizeListBox->item(row)->text()); | 821 | return QLocale::system().toDouble(sizeListBox->item(row)->text()); | ||
829 | } | 822 | } | ||
830 | 823 | | |||
831 | qreal KFontChooser::Private::setupSizeListBox(const QString &family, const QString &style) | 824 | qreal KFontChooser::Private::setupSizeListBox(const QString &family, const QString &style) | ||
832 | { | 825 | { | ||
833 | QFontDatabase dbase; | | |||
834 | QList<qreal> sizes; | 826 | QList<qreal> sizes; | ||
835 | if (dbase.isSmoothlyScalable(family, style)) { | 827 | const bool smoothlyScalable = fdb.isSmoothlyScalable(family, style); | ||
836 | // A vector font. | 828 | if (!smoothlyScalable) { | ||
837 | //>sampleEdit->setPaletteBackgroundPixmap( VectorPixmap ); // TODO | 829 | const QList<int> smoothSizes = fdb.smoothSizes(family, style); | ||
838 | } else { | | |||
839 | // A bitmap font. | | |||
840 | //sampleEdit->setPaletteBackgroundPixmap( BitmapPixmap ); // TODO | | |||
841 | const QList<int> smoothSizes = dbase.smoothSizes(family, style); | | |||
842 | for (int size : smoothSizes) { | 830 | for (int size : smoothSizes) { | ||
843 | sizes.append(size); | 831 | sizes.append(size); | ||
844 | } | 832 | } | ||
845 | } | 833 | } | ||
846 | 834 | | |||
847 | // Fill the listbox (uses default list of sizes if the given is empty). | 835 | // Fill the listbox (uses default list of sizes if the given is empty). | ||
848 | // Collect the best fitting size to selected size, to use if not smooth. | 836 | // Collect the best fitting size to selected size, to use if not smooth. | ||
849 | qreal bestFitSize = fillSizeList(sizes); | 837 | qreal bestFitSize = fillSizeList(sizes); | ||
850 | 838 | | |||
851 | // Set the best fit size as current in the listbox if available. | 839 | // Set the best fit size as current in the listbox if available. | ||
852 | const QList<QListWidgetItem *> selectedSizeList = | 840 | const QList<QListWidgetItem *> selectedSizeList = sizeListBox->findItems( | ||
853 | sizeListBox->findItems(formatFontSize(bestFitSize), | 841 | formatFontSize(bestFitSize), Qt::MatchExactly); | ||
854 | Qt::MatchExactly); | | |||
855 | if (!selectedSizeList.isEmpty()) { | 842 | if (!selectedSizeList.isEmpty()) { | ||
856 | sizeListBox->setCurrentItem(selectedSizeList.first()); | 843 | sizeListBox->setCurrentItem(selectedSizeList.first()); | ||
857 | } | 844 | } | ||
858 | 845 | | |||
859 | return bestFitSize; | 846 | return bestFitSize; | ||
860 | } | 847 | } | ||
861 | 848 | | |||
862 | void KFontChooser::Private::setupDisplay() | 849 | void KFontChooser::Private::setupDisplay() | ||
863 | { | 850 | { | ||
864 | QFontDatabase dbase; | | |||
865 | QString family = selFont.family().toLower(); | 851 | QString family = selFont.family().toLower(); | ||
866 | QString styleID = styleIdentifier(selFont); | 852 | QString styleID = styleIdentifier(selFont); | ||
867 | qreal size = selFont.pointSizeF(); | 853 | qreal size = selFont.pointSizeF(); | ||
868 | if (size == -1) { | 854 | if (size == -1) { | ||
869 | size = QFontInfo(selFont).pointSizeF(); | 855 | size = QFontInfo(selFont).pointSizeF(); | ||
870 | } | 856 | } | ||
871 | 857 | | |||
872 | int numEntries, i; | 858 | int numEntries, i; | ||
▲ Show 20 Lines • Show All 64 Lines • ▼ Show 20 Line(s) | 921 | if (i == numEntries) { | |||
937 | styleListBox->setCurrentRow(0); | 923 | styleListBox->setCurrentRow(0); | ||
938 | } | 924 | } | ||
939 | 925 | | |||
940 | // Set current size in the listbox. | 926 | // Set current size in the listbox. | ||
941 | // If smoothly scalable, allow customizing one of the standard size slots, | 927 | // If smoothly scalable, allow customizing one of the standard size slots, | ||
942 | // otherwise just select the nearest available size. | 928 | // otherwise just select the nearest available size. | ||
943 | QString currentFamily = qtFamilies[familyListBox->currentItem()->text()]; | 929 | QString currentFamily = qtFamilies[familyListBox->currentItem()->text()]; | ||
944 | QString currentStyle = qtStyles[styleListBox->currentItem()->text()]; | 930 | QString currentStyle = qtStyles[styleListBox->currentItem()->text()]; | ||
945 | bool canCustomize = dbase.isSmoothlyScalable(currentFamily, currentStyle); | 931 | bool canCustomize = fdb.isSmoothlyScalable(currentFamily, currentStyle); | ||
946 | sizeListBox->setCurrentRow(nearestSizeRow(size, canCustomize)); | 932 | sizeListBox->setCurrentRow(nearestSizeRow(size, canCustomize)); | ||
947 | 933 | | |||
948 | // Set current size in the spinbox. | 934 | // Set current size in the spinbox. | ||
949 | sizeOfFont->setValue(QLocale::system().toDouble(sizeListBox->currentItem()->text())); | 935 | sizeOfFont->setValue(QLocale::system().toDouble(sizeListBox->currentItem()->text())); | ||
950 | } | 936 | } | ||
951 | 937 | | |||
952 | void KFontChooser::getFontList(QStringList &list, uint fontListCriteria) | 938 | void KFontChooser::getFontList(QStringList &list, uint fontListCriteria) | ||
953 | { | 939 | { | ||
954 | QFontDatabase dbase; | 940 | QFontDatabase dbase; | ||
955 | QStringList lstSys(dbase.families()); | 941 | QStringList lstSys(dbase.families()); | ||
956 | 942 | | |||
957 | // if we have criteria; then check fonts before adding | 943 | // if we have criteria; then check fonts before adding | ||
958 | if (fontListCriteria) { | 944 | if (fontListCriteria) { | ||
959 | QStringList lstFonts; | 945 | QStringList lstFonts; | ||
960 | for (QStringList::const_iterator it = lstSys.constBegin(); it != lstSys.constEnd(); ++it) { | 946 | for (const QString &family : qAsConst(lstSys)) { | ||
961 | if ((fontListCriteria & FixedWidthFonts) > 0 && !dbase.isFixedPitch(*it)) { | 947 | if ((fontListCriteria & FixedWidthFonts) > 0 && !dbase.isFixedPitch(family)) { | ||
962 | continue; | 948 | continue; | ||
963 | } | 949 | } | ||
964 | if (((fontListCriteria & (SmoothScalableFonts | ScalableFonts)) == ScalableFonts) && | 950 | if (((fontListCriteria & (SmoothScalableFonts | ScalableFonts)) == ScalableFonts) && | ||
965 | !dbase.isBitmapScalable(*it)) { | 951 | !dbase.isBitmapScalable(family)) { | ||
966 | continue; | 952 | continue; | ||
967 | } | 953 | } | ||
968 | if ((fontListCriteria & SmoothScalableFonts) > 0 && !dbase.isSmoothlyScalable(*it)) { | 954 | if ((fontListCriteria & SmoothScalableFonts) > 0 && !dbase.isSmoothlyScalable(family)) { | ||
969 | continue; | 955 | continue; | ||
970 | } | 956 | } | ||
971 | lstFonts.append(*it); | 957 | lstFonts.append(family); | ||
972 | } | 958 | } | ||
973 | 959 | | |||
974 | if ((fontListCriteria & FixedWidthFonts) > 0) { | 960 | if ((fontListCriteria & FixedWidthFonts) > 0) { | ||
975 | // Fallback.. if there are no fixed fonts found, it's probably a | 961 | // Fallback.. if there are no fixed fonts found, it's probably a | ||
976 | // bug in the font server or Qt. In this case, just use 'fixed' | 962 | // bug in the font server or Qt. In this case, just use 'fixed' | ||
977 | if (lstFonts.isEmpty()) { | 963 | if (lstFonts.isEmpty()) { | ||
978 | lstFonts.append(QStringLiteral("fixed")); | 964 | lstFonts.append(QStringLiteral("fixed")); | ||
979 | } | 965 | } | ||
▲ Show 20 Lines • Show All 43 Lines • Show Last 20 Lines |