1 /*
2 * This file is part of Licq, an instant messaging client for UNIX.
3 * Copyright (C) 2008-2009 Licq developers
4 *
5 * Licq is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * Licq is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with Licq; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20 #include "config.h"
21
22 #include "fontedit.h"
23
24 #ifndef USE_KDE
25 #include <QFontDialog>
26 #include <QLineEdit>
27 #include <QHBoxLayout>
28 #include <QToolButton>
29 #endif
30
31 #include "config/general.h"
32
33 using namespace LicqQtGui;
34 /* TRANSLATOR LicqQtGui::FontEdit */
35
FontEdit(QWidget * parent)36 FontEdit::FontEdit(QWidget* parent)
37 : FONTEDIT_BASE(parent)
38 {
39 #ifndef USE_KDE
40 QHBoxLayout* lay = new QHBoxLayout(this);
41 lay->setContentsMargins(0, 0, 0, 0);
42
43 // Input field
44 myEditor = new QLineEdit();
45 lay->addWidget(myEditor);
46
47 // Button to open file dialog
48 QToolButton* browseButton = new QToolButton();
49 // TODO: Use a font icon instead of text for browseButton
50 browseButton->setText(tr("Choose..."));
51 browseButton->setToolTip(tr("Select a font from the system list."));
52 connect(browseButton, SIGNAL(clicked()), SLOT(browse()));
53 lay->addWidget(browseButton);
54 #endif
55 }
56
setFont(const QFont & font,bool)57 void FontEdit::setFont(const QFont& font, bool /* onlyFixed */)
58 {
59 QString s;
60 if (font == Config::General::instance()->defaultFont())
61 s = tr("default (%1)").arg(font.toString());
62 #ifndef USE_KDE
63 else
64 s = font.toString();
65
66 myEditor->setFont(font);
67 myEditor->setText(s);
68 myEditor->setCursorPosition(0);
69 #else
70 KFontRequester::setFont(font);
71 setSampleText(s);
72 #endif
73 }
74
75 #ifndef USE_KDE
font() const76 QFont FontEdit::font() const
77 {
78 return myEditor->font();
79 }
80
browse()81 void FontEdit::browse()
82 {
83 bool fontOk;
84 QFont f = QFontDialog::getFont(&fontOk, myEditor->font(), this);
85
86 if (fontOk)
87 {
88 setFont(f);
89 emit fontSelected(f);
90 }
91 }
92 #endif
93