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