Changeset View
Changeset View
Standalone View
Standalone View
src/FontDialog.cpp
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | Copyright 2018 by Mariusz Glebocki <mglb@arccos-1.net> | ||||
3 | | ||||
4 | This program is free software; you can redistribute it and/or modify | ||||
5 | it under the terms of the GNU General Public License as published by | ||||
6 | the Free Software Foundation; either version 2 of the License, or | ||||
7 | (at your option) any later version. | ||||
8 | | ||||
9 | This program is distributed in the hope that it will be useful, | ||||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
12 | GNU General Public License for more details. | ||||
13 | | ||||
14 | You should have received a copy of the GNU General Public License | ||||
15 | along with this program; if not, write to the Free Software | ||||
16 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||||
17 | 02110-1301 USA. | ||||
18 | */ | ||||
19 | | ||||
20 | // Own | ||||
21 | #include "FontDialog.h" | ||||
22 | | ||||
23 | // Qt | ||||
24 | #include <QBoxLayout> | ||||
25 | #include <QWhatsThis> | ||||
26 | | ||||
27 | // KDE | ||||
28 | #include <KLocalizedString> | ||||
29 | #include <KMessageBox> | ||||
30 | | ||||
31 | using namespace Konsole; | ||||
32 | | ||||
33 | FontDialog::FontDialog(QWidget *parent) : | ||||
34 | QDialog(parent) | ||||
35 | , _fontChooser(nullptr) | ||||
36 | , _showAllFonts(nullptr) | ||||
37 | , _buttonBox(nullptr) | ||||
38 | { | ||||
39 | setWindowTitle(i18nc("@title:window", "Select font")); | ||||
40 | | ||||
41 | _fontChooser = new KFontChooser(this, KFontChooser::FixedFontsOnly); | ||||
42 | _showAllFonts = new QCheckBox(i18n("Show all fonts"), this); | ||||
43 | _showAllFontsWarningButton = new QToolButton(this); | ||||
44 | _buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | | ||||
45 | QDialogButtonBox::Cancel, | ||||
46 | Qt::Horizontal, this); | ||||
47 | | ||||
48 | _fontChooser->setSampleText(QStringLiteral( | ||||
49 | "0OQ 1Il!| 5S 8B rnm :; ,. \"'` ~-= ({[<>]})\n" | ||||
50 | "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~\n" | ||||
51 | "ABCDEFGHIJKLMNOPQRSTUVWXYZ 0123456789\n" | ||||
52 | "abcdefghijklmnopqrstuvwxyz" | ||||
53 | )); | ||||
54 | _showAllFontsWarningButton->setIcon(QIcon::fromTheme(QStringLiteral("emblem-warning"))); | ||||
55 | _showAllFontsWarningButton->setAutoRaise(true); | ||||
56 | | ||||
57 | connect(_fontChooser, &KFontChooser::fontSelected, this, &FontDialog::fontChanged); | ||||
58 | connect(_showAllFonts, &QCheckBox::toggled, this, [this](bool enable) { | ||||
59 | _fontChooser->setFont(_fontChooser->font(), !enable); | ||||
60 | }); | ||||
61 | connect(_showAllFontsWarningButton, &QToolButton::clicked, this, [this](bool) { | ||||
62 | const QString message = i18n("By its very nature, a terminal program requires font characters that are equal width (monospace). Any non monospaced font may cause display issues. This should not be necessary except in rare cases."); | ||||
63 | const QPoint pos = QPoint(_showAllFonts->width() / 2, _showAllFonts->height()); | ||||
64 | QWhatsThis::showText(_showAllFonts->mapToGlobal(pos), message, _showAllFonts); | ||||
65 | }); | ||||
66 | connect(_buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept); | ||||
67 | connect(_buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject); | ||||
68 | | ||||
69 | auto *showAllFontsLayout = new QHBoxLayout(); | ||||
70 | showAllFontsLayout->addWidget(_showAllFonts); | ||||
71 | showAllFontsLayout->addWidget(_showAllFontsWarningButton); | ||||
72 | showAllFontsLayout->addSpacerItem(new QSpacerItem(0, 0, QSizePolicy::Expanding)); | ||||
73 | showAllFontsLayout->setContentsMargins(0, 0, 0, 0); | ||||
74 | showAllFontsLayout->setSpacing(0); | ||||
75 | | ||||
76 | auto *layout = new QVBoxLayout(this); | ||||
77 | layout->addWidget(_fontChooser, 1); | ||||
78 | layout->addLayout(showAllFontsLayout); | ||||
79 | layout->addWidget(_buttonBox); | ||||
80 | } | ||||
81 | | ||||
82 | void FontDialog::setFont(const QFont &font) | ||||
83 | { | ||||
84 | _fontChooser->setFont(font, !_showAllFonts->isChecked()); | ||||
85 | } |