]>
cloud.milkyroute.net Git - dolphin.git/blob - src/settings/viewmodes/dolphinfontrequester.cpp
1 /***************************************************************************
2 * Copyright (C) 2008 by Peter Penz <peter.penz19@gmail.com> *
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. *
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. *
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 ***************************************************************************/
20 #include "dolphinfontrequester.h"
22 #include <KFontDialog>
23 #include <KGlobalSettings>
24 #include <KLocalizedString>
28 #include <QHBoxLayout>
29 #include <QPushButton>
30 #include <QFontDatabase>
32 DolphinFontRequester::DolphinFontRequester(QWidget
* parent
) :
35 m_chooseFontButton(0),
39 QHBoxLayout
* topLayout
= new QHBoxLayout(this);
40 topLayout
->setMargin(0);
42 m_modeCombo
= new KComboBox(this);
43 m_modeCombo
->addItem(i18nc("@item:inlistbox Font", "System Font"));
44 m_modeCombo
->addItem(i18nc("@item:inlistbox Font", "Custom Font"));
45 connect(m_modeCombo
, static_cast<void(KComboBox::*)(int)>(&KComboBox::activated
),
46 this, &DolphinFontRequester::changeMode
);
48 m_chooseFontButton
= new QPushButton(i18nc("@action:button Choose font", "Choose..."), this);
49 connect(m_chooseFontButton
, &QPushButton::clicked
,
50 this, &DolphinFontRequester::openFontDialog
);
52 changeMode(m_modeCombo
->currentIndex());
54 topLayout
->addWidget(m_modeCombo
);
55 topLayout
->addWidget(m_chooseFontButton
);
58 DolphinFontRequester::~DolphinFontRequester()
62 void DolphinFontRequester::setMode(Mode mode
)
65 m_modeCombo
->setCurrentIndex(m_mode
);
66 m_chooseFontButton
->setEnabled(m_mode
== CustomFont
);
69 DolphinFontRequester::Mode
DolphinFontRequester::mode() const
74 QFont
DolphinFontRequester::currentFont() const
76 return (m_mode
== CustomFont
) ? m_customFont
: QFontDatabase::systemFont(QFontDatabase::GeneralFont
);
79 void DolphinFontRequester::setCustomFont(const QFont
& font
)
84 QFont
DolphinFontRequester::customFont() const
89 void DolphinFontRequester::openFontDialog()
91 QFont font
= m_customFont
;
92 const int result
= KFontDialog::getFont(font
,
93 KFontChooser::NoDisplayFlags
,
95 if (result
== KFontDialog::Accepted
) {
97 m_modeCombo
->setFont(m_customFont
);
102 void DolphinFontRequester::changeMode(int index
)
104 setMode((index
== CustomFont
) ? CustomFont
: SystemFont
);