Changeset View
Changeset View
Standalone View
Standalone View
src/kfontchooser.cpp
Show First 20 Lines • Show All 96 Lines • ▼ Show 20 Line(s) | 94 | // QStringList fontList; | |||
---|---|---|---|---|---|
97 | void fillFamilyListBox(bool onlyFixedFonts = false); | 97 | void fillFamilyListBox(bool onlyFixedFonts = false); | ||
98 | int nearestSizeRow(qreal val, bool customize); | 98 | int nearestSizeRow(qreal val, bool customize); | ||
99 | qreal fillSizeList(const QList<qreal> &sizes = QList<qreal>()); | 99 | qreal fillSizeList(const QList<qreal> &sizes = QList<qreal>()); | ||
100 | qreal setupSizeListBox(const QString &family, const QString &style); | 100 | qreal setupSizeListBox(const QString &family, const QString &style); | ||
101 | 101 | | |||
102 | void setupDisplay(); | 102 | void setupDisplay(); | ||
103 | QString styleIdentifier(const QFont &font); | 103 | QString styleIdentifier(const QFont &font); | ||
104 | 104 | | |||
105 | void _k_toggled_checkbox(); | | |||
106 | void _k_family_chosen_slot(const QString &); | 105 | void _k_family_chosen_slot(const QString &); | ||
107 | void _k_size_chosen_slot(const QString &); | 106 | void _k_size_chosen_slot(const QString &); | ||
108 | void _k_style_chosen_slot(const QString &); | 107 | void _k_style_chosen_slot(const QString &); | ||
109 | void _k_displaySample(const QFont &font); | 108 | void _k_displaySample(const QFont &font); | ||
110 | void _k_size_value_slot(double); | 109 | void _k_size_value_slot(double); | ||
111 | 110 | | |||
112 | KFontChooser *q; | 111 | KFontChooser *q; | ||
113 | 112 | | |||
▲ Show 20 Lines • Show All 78 Lines • ▼ Show 20 Line(s) | 157 | { | |||
192 | 191 | | |||
193 | // | 192 | // | ||
194 | // first, create the labels across the top | 193 | // first, create the labels across the top | ||
195 | // | 194 | // | ||
196 | QHBoxLayout *familyLayout = new QHBoxLayout(); | 195 | QHBoxLayout *familyLayout = new QHBoxLayout(); | ||
197 | familyLayout->addSpacing(checkBoxGap); | 196 | familyLayout->addSpacing(checkBoxGap); | ||
198 | if (flags & ShowDifferences) { | 197 | if (flags & ShowDifferences) { | ||
199 | d->familyCheckbox = new QCheckBox(KFontChooser::tr("Font", "@option:check"), page); | 198 | d->familyCheckbox = new QCheckBox(KFontChooser::tr("Font", "@option:check"), page); | ||
200 | connect(d->familyCheckbox, SIGNAL(toggled(bool)), | 199 | connect(d->familyCheckbox, &QAbstractButton::toggled, | ||
201 | this, SLOT(_k_toggled_checkbox())); | 200 | this, [this](const bool state) { d->familyListBox->setEnabled(state); }); | ||
202 | familyLayout->addWidget(d->familyCheckbox, 0, Qt::AlignLeft); | 201 | familyLayout->addWidget(d->familyCheckbox, 0, Qt::AlignLeft); | ||
203 | d->familyCheckbox->setWhatsThis(KFontChooser::tr("Enable this checkbox to change the font family settings.", "@info:whatsthis")); | 202 | 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")); | 203 | d->familyCheckbox->setToolTip(KFontChooser::tr("Change font family?", "@info:tooltip")); | ||
205 | d->familyLabel = nullptr; | 204 | d->familyLabel = nullptr; | ||
206 | } else { | 205 | } else { | ||
207 | d->familyCheckbox = nullptr; | 206 | d->familyCheckbox = nullptr; | ||
208 | d->familyLabel = new QLabel(KFontChooser::tr("Font:", "@label"), page); | 207 | d->familyLabel = new QLabel(KFontChooser::tr("Font:", "@label"), page); | ||
209 | familyLayout->addWidget(d->familyLabel, 1, Qt::AlignLeft); | 208 | familyLayout->addWidget(d->familyLabel, 1, Qt::AlignLeft); | ||
210 | } | 209 | } | ||
211 | gridLayout->addLayout(familyLayout, row, 0); | 210 | gridLayout->addLayout(familyLayout, row, 0); | ||
212 | 211 | | |||
213 | QHBoxLayout *styleLayout = new QHBoxLayout(); | 212 | QHBoxLayout *styleLayout = new QHBoxLayout(); | ||
214 | if (flags & ShowDifferences) { | 213 | if (flags & ShowDifferences) { | ||
215 | d->styleCheckbox = new QCheckBox(KFontChooser::tr("Font style", "@option:check"), page); | 214 | d->styleCheckbox = new QCheckBox(KFontChooser::tr("Font style", "@option:check"), page); | ||
216 | connect(d->styleCheckbox, SIGNAL(toggled(bool)), | 215 | connect(d->styleCheckbox, &QAbstractButton::toggled, | ||
217 | this, SLOT(_k_toggled_checkbox())); | 216 | this, [this](const bool state) { d->styleListBox->setEnabled(state); }); | ||
218 | styleLayout->addWidget(d->styleCheckbox, 0, Qt::AlignLeft); | 217 | styleLayout->addWidget(d->styleCheckbox, 0, Qt::AlignLeft); | ||
219 | d->styleCheckbox->setWhatsThis(KFontChooser::tr("Enable this checkbox to change the font style settings.", "@info:whatsthis")); | 218 | 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")); | 219 | d->styleCheckbox->setToolTip(KFontChooser::tr("Change font style?", "@info:tooltip")); | ||
221 | d->styleLabel = nullptr; | 220 | d->styleLabel = nullptr; | ||
222 | } else { | 221 | } else { | ||
223 | d->styleCheckbox = nullptr; | 222 | d->styleCheckbox = nullptr; | ||
224 | d->styleLabel = new QLabel(KFontChooser::tr("Font style:"), page); | 223 | d->styleLabel = new QLabel(KFontChooser::tr("Font style:"), page); | ||
225 | styleLayout->addWidget(d->styleLabel, 1, Qt::AlignLeft); | 224 | styleLayout->addWidget(d->styleLabel, 1, Qt::AlignLeft); | ||
226 | } | 225 | } | ||
227 | styleLayout->addSpacing(checkBoxGap); | 226 | styleLayout->addSpacing(checkBoxGap); | ||
228 | gridLayout->addLayout(styleLayout, row, 1); | 227 | gridLayout->addLayout(styleLayout, row, 1); | ||
229 | 228 | | |||
230 | QHBoxLayout *sizeLayout = new QHBoxLayout(); | 229 | QHBoxLayout *sizeLayout = new QHBoxLayout(); | ||
231 | if (flags & ShowDifferences) { | 230 | if (flags & ShowDifferences) { | ||
232 | d->sizeCheckbox = new QCheckBox(KFontChooser::tr("Size", "@option:check"), page); | 231 | d->sizeCheckbox = new QCheckBox(KFontChooser::tr("Size", "@option:check"), page); | ||
233 | connect(d->sizeCheckbox, SIGNAL(toggled(bool)), | 232 | | ||
234 | this, SLOT(_k_toggled_checkbox())); | 233 | connect(d->sizeCheckbox, &QAbstractButton::toggled, this, [this](const bool state) { | ||
234 | d->sizeListBox->setEnabled(state); | ||||
235 | d->sizeOfFont->setEnabled(state); | ||||
236 | }); | ||||
237 | | ||||
235 | sizeLayout->addWidget(d->sizeCheckbox, 0, Qt::AlignLeft); | 238 | sizeLayout->addWidget(d->sizeCheckbox, 0, Qt::AlignLeft); | ||
236 | d->sizeCheckbox->setWhatsThis(KFontChooser::tr("Enable this checkbox to change the font size settings.", "@info:whatsthis")); | 239 | 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")); | 240 | d->sizeCheckbox->setToolTip(KFontChooser::tr("Change font size?", "@info:tooltip")); | ||
238 | d->sizeLabel = nullptr; | 241 | d->sizeLabel = nullptr; | ||
239 | } else { | 242 | } else { | ||
240 | d->sizeCheckbox = nullptr; | 243 | d->sizeCheckbox = nullptr; | ||
241 | d->sizeLabel = new QLabel(KFontChooser::tr("Size:", "@label:listbox Font size"), page); | 244 | d->sizeLabel = new QLabel(KFontChooser::tr("Size:", "@label:listbox Font size"), page); | ||
242 | sizeLayout->addWidget(d->sizeLabel, 1, Qt::AlignLeft); | 245 | sizeLayout->addWidget(d->sizeLabel, 1, Qt::AlignLeft); | ||
243 | } | 246 | } | ||
244 | sizeLayout->addSpacing(checkBoxGap); | 247 | sizeLayout->addSpacing(checkBoxGap); | ||
245 | sizeLayout->addSpacing(checkBoxGap); // prevent label from eating border | 248 | sizeLayout->addSpacing(checkBoxGap); // prevent label from eating border | ||
246 | gridLayout->addLayout(sizeLayout, row, 2); | 249 | gridLayout->addLayout(sizeLayout, row, 2); | ||
247 | 250 | | |||
248 | row ++; | 251 | ++row; | ||
249 | 252 | | |||
250 | // | 253 | // | ||
251 | // now create the actual boxes that hold the info | 254 | // now create the actual boxes that hold the info | ||
252 | // | 255 | // | ||
253 | d->familyListBox = new QListWidget(page); | 256 | d->familyListBox = new QListWidget(page); | ||
254 | d->familyListBox->setEnabled(flags ^ ShowDifferences); | 257 | d->familyListBox->setEnabled(flags ^ ShowDifferences); | ||
255 | gridLayout->addWidget(d->familyListBox, row, 0); | 258 | gridLayout->addWidget(d->familyListBox, row, 0); | ||
256 | QString fontFamilyWhatsThisText( | 259 | QString fontFamilyWhatsThisText( | ||
257 | KFontChooser::tr("Here you can choose the font family to be used.", "@info:whatsthis")); | 260 | KFontChooser::tr("Here you can choose the font family to be used.", "@info:whatsthis")); | ||
258 | d->familyListBox->setWhatsThis(fontFamilyWhatsThisText); | 261 | d->familyListBox->setWhatsThis(fontFamilyWhatsThisText); | ||
259 | 262 | | |||
260 | if (flags & ShowDifferences) { | 263 | if (flags & ShowDifferences) { | ||
261 | d->familyCheckbox->setWhatsThis(fontFamilyWhatsThisText); | 264 | d->familyCheckbox->setWhatsThis(fontFamilyWhatsThisText); | ||
262 | } else { | 265 | } else { | ||
263 | d->familyLabel->setWhatsThis(fontFamilyWhatsThisText); | 266 | d->familyLabel->setWhatsThis(fontFamilyWhatsThisText); | ||
264 | } | 267 | } | ||
265 | 268 | | |||
266 | connect(d->familyListBox, SIGNAL(currentTextChanged(QString)), | 269 | connect(d->familyListBox, &QListWidget::currentTextChanged, | ||
267 | this, SLOT(_k_family_chosen_slot(QString))); | 270 | this, [this](const QString &family) { d->_k_family_chosen_slot(family); }); | ||
271 | | ||||
268 | if (!fontList.isEmpty()) { | 272 | if (!fontList.isEmpty()) { | ||
269 | d->setFamilyBoxItems(fontList); | 273 | d->setFamilyBoxItems(fontList); | ||
270 | } else { | 274 | } else { | ||
271 | d->fillFamilyListBox(flags & FixedFontsOnly); | 275 | d->fillFamilyListBox(flags & FixedFontsOnly); | ||
272 | } | 276 | } | ||
273 | 277 | | |||
274 | d->familyListBox->setMinimumWidth(minimumListWidth(d->familyListBox)); | 278 | d->familyListBox->setMinimumWidth(minimumListWidth(d->familyListBox)); | ||
275 | d->familyListBox->setMinimumHeight( | 279 | d->familyListBox->setMinimumHeight(minimumListHeight(d->familyListBox, visibleListSize)); | ||
276 | minimumListHeight(d->familyListBox, visibleListSize)); | | |||
277 | 280 | | |||
278 | d->styleListBox = new QListWidget(page); | 281 | d->styleListBox = new QListWidget(page); | ||
279 | d->styleListBox->setEnabled(flags ^ ShowDifferences); | 282 | d->styleListBox->setEnabled(flags ^ ShowDifferences); | ||
280 | gridLayout->addWidget(d->styleListBox, row, 1); | 283 | gridLayout->addWidget(d->styleListBox, row, 1); | ||
281 | d->styleListBox->setWhatsThis(KFontChooser::tr("Here you can choose the font style to be used.", "@info:whatsthis")); | 284 | d->styleListBox->setWhatsThis(KFontChooser::tr("Here you can choose the font style to be used.", "@info:whatsthis")); | ||
282 | if (flags & ShowDifferences) { | 285 | if (flags & ShowDifferences) { | ||
283 | ((QWidget *)d->styleCheckbox)->setWhatsThis(fontFamilyWhatsThisText); | 286 | ((QWidget *)d->styleCheckbox)->setWhatsThis(fontFamilyWhatsThisText); | ||
284 | } else { | 287 | } else { | ||
285 | ((QWidget *)d->styleLabel)->setWhatsThis(fontFamilyWhatsThisText); | 288 | ((QWidget *)d->styleLabel)->setWhatsThis(fontFamilyWhatsThisText); | ||
286 | } | 289 | } | ||
287 | // Populate usual styles, to determine minimum list width; | 290 | // Populate usual styles, to determine minimum list width; | ||
288 | // will be replaced later with correct styles. | 291 | // will be replaced later with correct styles. | ||
289 | d->styleListBox->addItem(KFontChooser::tr("Normal", "QFontDatabase")); | 292 | d->styleListBox->addItem(KFontChooser::tr("Normal", "QFontDatabase")); | ||
290 | d->styleListBox->addItem(KFontChooser::tr("Italic", "@item font")); | 293 | d->styleListBox->addItem(KFontChooser::tr("Italic", "@item font")); | ||
291 | d->styleListBox->addItem(KFontChooser::tr("Oblique", "@item font")); | 294 | d->styleListBox->addItem(KFontChooser::tr("Oblique", "@item font")); | ||
292 | d->styleListBox->addItem(KFontChooser::tr("Bold", "@item font")); | 295 | d->styleListBox->addItem(KFontChooser::tr("Bold", "@item font")); | ||
293 | d->styleListBox->addItem(KFontChooser::tr("Bold Italic", "@item font")); | 296 | d->styleListBox->addItem(KFontChooser::tr("Bold Italic", "@item font")); | ||
294 | d->styleListBox->setMinimumWidth(minimumListWidth(d->styleListBox)); | 297 | d->styleListBox->setMinimumWidth(minimumListWidth(d->styleListBox)); | ||
295 | d->styleListBox->setMinimumHeight( | 298 | d->styleListBox->setMinimumHeight(minimumListHeight(d->styleListBox, visibleListSize)); | ||
296 | minimumListHeight(d->styleListBox, visibleListSize)); | | |||
297 | 299 | | |||
298 | connect(d->styleListBox, SIGNAL(currentTextChanged(QString)), | 300 | connect(d->styleListBox, &QListWidget::currentTextChanged, | ||
299 | this, SLOT(_k_style_chosen_slot(QString))); | 301 | this, [this](const QString &style) { d->_k_style_chosen_slot(style); }); | ||
300 | 302 | | |||
301 | d->sizeListBox = new QListWidget(page); | 303 | d->sizeListBox = new QListWidget(page); | ||
302 | d->sizeOfFont = new QDoubleSpinBox(page); | 304 | d->sizeOfFont = new QDoubleSpinBox(page); | ||
303 | d->sizeOfFont->setMinimum(4); | 305 | d->sizeOfFont->setMinimum(4); | ||
304 | d->sizeOfFont->setMaximum(999); | 306 | d->sizeOfFont->setMaximum(999); | ||
305 | d->sizeOfFont->setDecimals(1); | 307 | d->sizeOfFont->setDecimals(1); | ||
306 | d->sizeOfFont->setSingleStep(1); | 308 | d->sizeOfFont->setSingleStep(1); | ||
307 | 309 | | |||
Show All 36 Lines | 345 | if (flags & ShowDifferences) { | |||
344 | ((QWidget *)d->sizeCheckbox)->setWhatsThis(fontSizeWhatsThisText); | 346 | ((QWidget *)d->sizeCheckbox)->setWhatsThis(fontSizeWhatsThisText); | ||
345 | } else { | 347 | } else { | ||
346 | ((QWidget *)d->sizeLabel)->setWhatsThis(fontSizeWhatsThisText); | 348 | ((QWidget *)d->sizeLabel)->setWhatsThis(fontSizeWhatsThisText); | ||
347 | } | 349 | } | ||
348 | 350 | | |||
349 | // Populate with usual sizes, to determine minimum list width; | 351 | // Populate with usual sizes, to determine minimum list width; | ||
350 | // will be replaced later with correct sizes. | 352 | // will be replaced later with correct sizes. | ||
351 | d->fillSizeList(); | 353 | d->fillSizeList(); | ||
352 | d->sizeListBox->setMinimumWidth(minimumListWidth(d->sizeListBox) + | 354 | d->sizeListBox->setMinimumWidth(minimumListWidth(d->sizeListBox) | ||
353 | d->sizeListBox->fontMetrics().maxWidth()); | 355 | + d->sizeListBox->fontMetrics().maxWidth()); | ||
354 | d->sizeListBox->setMinimumHeight( | 356 | d->sizeListBox->setMinimumHeight(minimumListHeight(d->sizeListBox, visibleListSize)); | ||
355 | minimumListHeight(d->sizeListBox, visibleListSize)); | | |||
356 | 357 | | |||
357 | connect(d->sizeOfFont, SIGNAL(valueChanged(double)), | 358 | connect(d->sizeOfFont, QOverload<double>::of(&QDoubleSpinBox::valueChanged), | ||
358 | this, SLOT(_k_size_value_slot(double))); | 359 | this, [this](const double size) { d->_k_size_value_slot(size); }); | ||
359 | 360 | | |||
360 | connect(d->sizeListBox, SIGNAL(currentTextChanged(QString)), | 361 | connect(d->sizeListBox, &QListWidget::currentTextChanged, | ||
361 | this, SLOT(_k_size_chosen_slot(QString))); | 362 | this, [this](const QString &size) { d->_k_size_chosen_slot(size); }); | ||
362 | 363 | | |||
363 | row ++; | 364 | ++row; | ||
364 | // | 365 | // | ||
365 | // Completed the font attribute grid. | 366 | // Completed the font attribute grid. | ||
366 | 367 | | |||
367 | // Add the font preview into the lower part of the splitter. | 368 | // Add the font preview into the lower part of the splitter. | ||
368 | // | 369 | // | ||
369 | d->sampleEdit = new QTextEdit(page); | 370 | d->sampleEdit = new QTextEdit(page); | ||
370 | d->sampleEdit->setAcceptRichText(false); | 371 | d->sampleEdit->setAcceptRichText(false); | ||
371 | QFont tmpFont(font().family(), 64, QFont::Black); | 372 | QFont tmpFont(font().family(), 64, QFont::Black); | ||
372 | d->sampleEdit->setFont(tmpFont); | 373 | d->sampleEdit->setFont(tmpFont); | ||
373 | d->sampleEdit->setMinimumHeight(d->sampleEdit->fontMetrics().lineSpacing()); | 374 | d->sampleEdit->setMinimumHeight(d->sampleEdit->fontMetrics().lineSpacing()); | ||
374 | // tr: A classical test phrase, with all letters of the English alphabet. | 375 | // 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 | 376 | // Replace it with a sample text in your language, such that it is | ||
376 | // representative of language's writing system. | 377 | // representative of language's writing system. | ||
377 | // If you wish, you can input several lines of text separated by \n. | 378 | // 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")); | 379 | setSampleText(KFontChooser::tr("The Quick Brown Fox Jumps Over The Lazy Dog")); | ||
379 | d->sampleEdit->setTextCursor(QTextCursor(d->sampleEdit->document())); | 380 | d->sampleEdit->setTextCursor(QTextCursor(d->sampleEdit->document())); | ||
380 | QString sampleEditWhatsThisText = | 381 | QString sampleEditWhatsThisText = | ||
381 | KFontChooser::tr("This sample text illustrates the current settings. " | 382 | KFontChooser::tr("This sample text illustrates the current settings. " | ||
382 | "You may edit it to test special characters."); | 383 | "You may edit it to test special characters."); | ||
383 | d->sampleEdit->setWhatsThis(sampleEditWhatsThisText); | 384 | d->sampleEdit->setWhatsThis(sampleEditWhatsThisText); | ||
384 | 385 | | |||
385 | connect(this, SIGNAL(fontSelected(QFont)), | 386 | connect(this, &KFontChooser::fontSelected, | ||
386 | this, SLOT(_k_displaySample(QFont))); | 387 | this, [this](const QFont &font) { d->_k_displaySample(font); }); | ||
387 | 388 | | |||
388 | splitter->addWidget(d->sampleEdit); | 389 | splitter->addWidget(d->sampleEdit); | ||
389 | // | 390 | // | ||
390 | // Finished setting up the splitter. | 391 | // Finished setting up the splitter. | ||
391 | 392 | | |||
392 | // | 393 | // | ||
393 | // Finished setting up the chooser layout. | 394 | // Finished setting up the chooser layout. | ||
394 | 395 | | |||
▲ Show 20 Lines • Show All 135 Lines • ▼ Show 20 Line(s) | 516 | { | |||
530 | return diffFlags; | 531 | return diffFlags; | ||
531 | } | 532 | } | ||
532 | 533 | | |||
533 | QFont KFontChooser::font() const | 534 | QFont KFontChooser::font() const | ||
534 | { | 535 | { | ||
535 | return d->selFont; | 536 | return d->selFont; | ||
536 | } | 537 | } | ||
537 | 538 | | |||
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) | 539 | void KFontChooser::Private::_k_family_chosen_slot(const QString &family) | ||
547 | { | 540 | { | ||
548 | if (!signalsAllowed) { | 541 | if (!signalsAllowed) { | ||
549 | return; | 542 | return; | ||
550 | } | 543 | } | ||
551 | signalsAllowed = false; | 544 | signalsAllowed = false; | ||
552 | 545 | | |||
553 | QString currentFamily; | 546 | QString currentFamily; | ||
Show All 15 Lines | |||||
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 = dbase.font(currentFamily, style, 10); | ||
582 | if (dbase.styleString(testFont) != style) { | 577 | if (dbase.styleString(testFont) != style) { | ||
583 | styles.removeAll(style); | 578 | styles.removeAll(style); | ||
584 | continue; | 579 | continue; | ||
585 | } | 580 | } | ||
▲ Show 20 Lines • Show All 241 Lines • ▼ Show 20 Line(s) | 783 | { | |||
827 | int row = nearestSizeRow(selectedSize, canCustomize); | 822 | int row = nearestSizeRow(selectedSize, canCustomize); | ||
828 | return QLocale::system().toDouble(sizeListBox->item(row)->text()); | 823 | return QLocale::system().toDouble(sizeListBox->item(row)->text()); | ||
829 | } | 824 | } | ||
830 | 825 | | |||
831 | qreal KFontChooser::Private::setupSizeListBox(const QString &family, const QString &style) | 826 | qreal KFontChooser::Private::setupSizeListBox(const QString &family, const QString &style) | ||
832 | { | 827 | { | ||
833 | QFontDatabase dbase; | 828 | QFontDatabase dbase; | ||
834 | QList<qreal> sizes; | 829 | QList<qreal> sizes; | ||
835 | if (dbase.isSmoothlyScalable(family, style)) { | 830 | const bool smoothlyScalable = dbase.isSmoothlyScalable(family, style); | ||
836 | // A vector font. | 831 | if (!smoothlyScalable) { | ||
837 | //>sampleEdit->setPaletteBackgroundPixmap( VectorPixmap ); // TODO | | |||
838 | } else { | | |||
839 | // A bitmap font. | | |||
840 | //sampleEdit->setPaletteBackgroundPixmap( BitmapPixmap ); // TODO | | |||
841 | const QList<int> smoothSizes = dbase.smoothSizes(family, style); | 832 | const QList<int> smoothSizes = dbase.smoothSizes(family, style); | ||
842 | for (int size : smoothSizes) { | 833 | for (int size : smoothSizes) { | ||
843 | sizes.append(size); | 834 | sizes.append(size); | ||
844 | } | 835 | } | ||
845 | } | 836 | } | ||
846 | 837 | | |||
847 | // Fill the listbox (uses default list of sizes if the given is empty). | 838 | // 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. | 839 | // Collect the best fitting size to selected size, to use if not smooth. | ||
849 | qreal bestFitSize = fillSizeList(sizes); | 840 | qreal bestFitSize = fillSizeList(sizes); | ||
850 | 841 | | |||
851 | // Set the best fit size as current in the listbox if available. | 842 | // Set the best fit size as current in the listbox if available. | ||
852 | const QList<QListWidgetItem *> selectedSizeList = | 843 | const QList<QListWidgetItem *> selectedSizeList = sizeListBox->findItems( | ||
853 | sizeListBox->findItems(formatFontSize(bestFitSize), | 844 | formatFontSize(bestFitSize), Qt::MatchExactly); | ||
854 | Qt::MatchExactly); | | |||
855 | if (!selectedSizeList.isEmpty()) { | 845 | if (!selectedSizeList.isEmpty()) { | ||
856 | sizeListBox->setCurrentItem(selectedSizeList.first()); | 846 | sizeListBox->setCurrentItem(selectedSizeList.first()); | ||
857 | } | 847 | } | ||
858 | 848 | | |||
859 | return bestFitSize; | 849 | return bestFitSize; | ||
860 | } | 850 | } | ||
861 | 851 | | |||
862 | void KFontChooser::Private::setupDisplay() | 852 | void KFontChooser::Private::setupDisplay() | ||
▲ Show 20 Lines • Show All 89 Lines • ▼ Show 20 Line(s) | |||||
952 | void KFontChooser::getFontList(QStringList &list, uint fontListCriteria) | 942 | void KFontChooser::getFontList(QStringList &list, uint fontListCriteria) | ||
953 | { | 943 | { | ||
954 | QFontDatabase dbase; | 944 | QFontDatabase dbase; | ||
955 | QStringList lstSys(dbase.families()); | 945 | QStringList lstSys(dbase.families()); | ||
956 | 946 | | |||
957 | // if we have criteria; then check fonts before adding | 947 | // if we have criteria; then check fonts before adding | ||
958 | if (fontListCriteria) { | 948 | if (fontListCriteria) { | ||
959 | QStringList lstFonts; | 949 | QStringList lstFonts; | ||
960 | for (QStringList::const_iterator it = lstSys.constBegin(); it != lstSys.constEnd(); ++it) { | 950 | for (const QString &family : qAsConst(lstSys)) { | ||
961 | if ((fontListCriteria & FixedWidthFonts) > 0 && !dbase.isFixedPitch(*it)) { | 951 | if ((fontListCriteria & FixedWidthFonts) > 0 && !dbase.isFixedPitch(family)) { | ||
962 | continue; | 952 | continue; | ||
963 | } | 953 | } | ||
964 | if (((fontListCriteria & (SmoothScalableFonts | ScalableFonts)) == ScalableFonts) && | 954 | if (((fontListCriteria & (SmoothScalableFonts | ScalableFonts)) == ScalableFonts) && | ||
965 | !dbase.isBitmapScalable(*it)) { | 955 | !dbase.isBitmapScalable(family)) { | ||
966 | continue; | 956 | continue; | ||
967 | } | 957 | } | ||
968 | if ((fontListCriteria & SmoothScalableFonts) > 0 && !dbase.isSmoothlyScalable(*it)) { | 958 | if ((fontListCriteria & SmoothScalableFonts) > 0 && !dbase.isSmoothlyScalable(family)) { | ||
969 | continue; | 959 | continue; | ||
970 | } | 960 | } | ||
971 | lstFonts.append(*it); | 961 | lstFonts.append(family); | ||
972 | } | 962 | } | ||
973 | 963 | | |||
974 | if ((fontListCriteria & FixedWidthFonts) > 0) { | 964 | if ((fontListCriteria & FixedWidthFonts) > 0) { | ||
975 | // Fallback.. if there are no fixed fonts found, it's probably a | 965 | // 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' | 966 | // bug in the font server or Qt. In this case, just use 'fixed' | ||
977 | if (lstFonts.isEmpty()) { | 967 | if (lstFonts.isEmpty()) { | ||
978 | lstFonts.append(QStringLiteral("fixed")); | 968 | lstFonts.append(QStringLiteral("fixed")); | ||
979 | } | 969 | } | ||
▲ Show 20 Lines • Show All 43 Lines • Show Last 20 Lines |