]> cloud.milkyroute.net Git - dolphin.git/blob - src/settings/viewmodes/dolphinfontrequester.cpp
Don't use the submodule-path for Qt-includes on application-level
[dolphin.git] / src / settings / viewmodes / dolphinfontrequester.cpp
1 /***************************************************************************
2 * Copyright (C) 2008 by Peter Penz <peter.penz@gmx.at> *
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 <KFontDialog>
23 #include <KGlobalSettings>
24 #include <KLocale>
25 #include <KComboBox>
26
27 #include <QEvent>
28 #include <QPushButton>
29
30 DolphinFontRequester::DolphinFontRequester(QWidget* parent) :
31 KHBox(parent),
32 m_modeCombo(0),
33 m_chooseFontButton(0),
34 m_mode(SystemFont),
35 m_customFont()
36 {
37 setSpacing(KDialog::spacingHint());
38
39 m_modeCombo = new KComboBox(this);
40 m_modeCombo->addItem(i18nc("@item:inlistbox Font", "System Font"));
41 m_modeCombo->addItem(i18nc("@item:inlistbox Font", "Custom Font"));
42 connect(m_modeCombo, SIGNAL(activated(int)),
43 this, SLOT(changeMode(int)));
44
45 m_chooseFontButton = new QPushButton(i18nc("@action:button Choose font", "Choose..."), this);
46 connect(m_chooseFontButton, SIGNAL(clicked()),
47 this, SLOT(openFontDialog()));
48
49 changeMode(m_modeCombo->currentIndex());
50 }
51
52 DolphinFontRequester::~DolphinFontRequester()
53 {
54 }
55
56 void DolphinFontRequester::setMode(Mode mode)
57 {
58 m_mode = mode;
59 m_modeCombo->setCurrentIndex(m_mode);
60 m_modeCombo->setFont(font());
61 m_chooseFontButton->setEnabled(m_mode == CustomFont);
62 }
63
64 DolphinFontRequester::Mode DolphinFontRequester::mode() const
65 {
66 return m_mode;
67 }
68
69 QFont DolphinFontRequester::font() const
70 {
71 return (m_mode == CustomFont) ? m_customFont : KGlobalSettings::generalFont();
72 }
73
74 void DolphinFontRequester::setCustomFont(const QFont& font)
75 {
76 m_customFont = font;
77 }
78
79 QFont DolphinFontRequester::customFont() const
80 {
81 return m_customFont;
82 }
83
84 bool DolphinFontRequester::event(QEvent* event)
85 {
86 if (event->type() == QEvent::Polish) {
87 m_modeCombo->setFont(font());
88 }
89 return KHBox::event(event);
90 }
91
92 void DolphinFontRequester::openFontDialog()
93 {
94 QFont font = m_customFont;
95 const int result = KFontDialog::getFont(font,
96 KFontChooser::NoDisplayFlags,
97 this);
98 if (result == KFontDialog::Accepted) {
99 m_customFont = font;
100 m_modeCombo->setFont(m_customFont);
101 emit changed();
102 }
103 }
104
105 void DolphinFontRequester::changeMode(int index)
106 {
107 setMode((index == CustomFont) ? CustomFont : SystemFont);
108 emit changed();
109 }
110
111 #include "dolphinfontrequester.moc"