]> cloud.milkyroute.net Git - dolphin.git/blob - src/settings/viewmodes/dolphinfontrequester.cpp
b9c5d97cf8e899600faf32c221a37ef496f74494
[dolphin.git] / src / settings / viewmodes / dolphinfontrequester.cpp
1 /***************************************************************************
2 * Copyright (C) 2008 by Peter Penz <peter.penz19@gmail.com> *
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 *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
19
20 #include "dolphinfontrequester.h"
21
22 #include <KLocalizedString>
23 #include <KComboBox>
24
25 #include <QHBoxLayout>
26 #include <QPushButton>
27 #include <QFontDatabase>
28 #include <QFontDialog>
29
30 DolphinFontRequester::DolphinFontRequester(QWidget* parent) :
31 QWidget(parent),
32 m_modeCombo(0),
33 m_chooseFontButton(0),
34 m_mode(SystemFont),
35 m_customFont()
36 {
37 QHBoxLayout* topLayout = new QHBoxLayout(this);
38 topLayout->setMargin(0);
39
40 m_modeCombo = new KComboBox(this);
41 m_modeCombo->addItem(i18nc("@item:inlistbox Font", "System Font"));
42 m_modeCombo->addItem(i18nc("@item:inlistbox Font", "Custom Font"));
43 connect(m_modeCombo, static_cast<void(KComboBox::*)(int)>(&KComboBox::activated),
44 this, &DolphinFontRequester::changeMode);
45
46 m_chooseFontButton = new QPushButton(i18nc("@action:button Choose font", "Choose..."), this);
47 connect(m_chooseFontButton, &QPushButton::clicked,
48 this, &DolphinFontRequester::openFontDialog);
49
50 changeMode(m_modeCombo->currentIndex());
51
52 topLayout->addWidget(m_modeCombo);
53 topLayout->addWidget(m_chooseFontButton);
54 }
55
56 DolphinFontRequester::~DolphinFontRequester()
57 {
58 }
59
60 void DolphinFontRequester::setMode(Mode mode)
61 {
62 m_mode = mode;
63 m_modeCombo->setCurrentIndex(m_mode);
64 m_chooseFontButton->setEnabled(m_mode == CustomFont);
65 }
66
67 DolphinFontRequester::Mode DolphinFontRequester::mode() const
68 {
69 return m_mode;
70 }
71
72 QFont DolphinFontRequester::currentFont() const
73 {
74 return (m_mode == CustomFont) ? m_customFont : QFontDatabase::systemFont(QFontDatabase::GeneralFont);
75 }
76
77 void DolphinFontRequester::setCustomFont(const QFont& font)
78 {
79 m_customFont = font;
80 }
81
82 QFont DolphinFontRequester::customFont() const
83 {
84 return m_customFont;
85 }
86
87 void DolphinFontRequester::openFontDialog()
88 {
89 bool ok = false;
90 const QFont font = QFontDialog::getFont(&ok, this);
91 if (ok) {
92 m_customFont = font;
93 m_modeCombo->setFont(m_customFont);
94 emit changed();
95 }
96 }
97
98 void DolphinFontRequester::changeMode(int index)
99 {
100 setMode((index == CustomFont) ? CustomFont : SystemFont);
101 emit changed();
102 }
103