]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinfontrequester.cpp
KDE 4.1 requires Qt4.4 -> remove the #ifdefs...
[dolphin.git] / src / 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.h>
23 #include <kglobalsettings.h>
24 #include <klocale.h>
25
26 #include <QComboBox>
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 m_modeCombo = new QComboBox(this);
38 m_modeCombo->addItem(i18nc("@item:inlistbox Font", "System Font"));
39 m_modeCombo->addItem(i18nc("@item:inlistbox Font", "Custom Font"));
40 connect(m_modeCombo, SIGNAL(activated(int)),
41 this, SLOT(changeMode(int)));
42
43 m_chooseFontButton = new QPushButton(i18n("Choose..."), this);
44 connect(m_chooseFontButton, SIGNAL(clicked()),
45 this, SLOT(openFontDialog()));
46
47 changeMode(m_modeCombo->currentIndex());
48 }
49
50 DolphinFontRequester::~DolphinFontRequester()
51 {
52 }
53
54 void DolphinFontRequester::setMode(Mode mode)
55 {
56 m_mode = mode;
57 m_modeCombo->setCurrentIndex(m_mode);
58 m_modeCombo->setFont(font());
59 m_chooseFontButton->setEnabled(m_mode == CustomFont);
60 }
61
62 DolphinFontRequester::Mode DolphinFontRequester::mode() const
63 {
64 return m_mode;
65 }
66
67 QFont DolphinFontRequester::font() const
68 {
69 return (m_mode == CustomFont) ? m_customFont : KGlobalSettings::generalFont();
70 }
71
72 void DolphinFontRequester::setCustomFont(const QFont& font)
73 {
74 m_customFont = font;
75 }
76
77 QFont DolphinFontRequester::customFont() const
78 {
79 return m_customFont;
80 }
81
82 bool DolphinFontRequester::event(QEvent* event)
83 {
84 if (event->type() == QEvent::Polish) {
85 m_modeCombo->setFont(font());
86 }
87 return KHBox::event(event);
88 }
89
90 void DolphinFontRequester::openFontDialog()
91 {
92 QFont font;
93 const int result = KFontDialog::getFont(font,
94 KFontChooser::NoDisplayFlags,
95 this);
96 if (result == KFontDialog::Accepted) {
97 m_customFont = font;
98 m_modeCombo->setFont(m_customFont);
99 }
100 }
101
102 void DolphinFontRequester::changeMode(int index)
103 {
104 setMode((index == CustomFont) ? CustomFont : SystemFont);
105 }
106
107 #include "dolphinfontrequester.moc"