summaryrefslogtreecommitdiff
path: root/src/frontend/display/btfontsizewidget.cpp
blob: 116d0d7109a82632118474e6647e3c476220ccd2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*********
*
* This file is part of BtFontSizeWidget's source code, http://www.bibletime.info/.
*
* Copyright 1999-2008 by the BtFontSizeWidget developers.
* The BtFontSizeWidget source code is licensed under the GNU General Public License version 2.0.
*
**********/

#include "frontend/display/btfontsizewidget.h"

#include <QCompleter>
#include <QFontDatabase>


BtFontSizeWidget::BtFontSizeWidget(QWidget* parent)
        : QComboBox(parent) {
    setEditable(true);
    completer()->setCompletionMode(QCompleter::PopupCompletion);

    QFontDatabase database;
    const QList<int> sizes = database.standardSizes();
    QStringList list;
    for ( QList<int>::ConstIterator it = sizes.begin(); it != sizes.end(); ++it )
        list.append( QString::number( *it ) );
    addItems(list);

    bool ok = connect(this, SIGNAL(currentIndexChanged(const QString&)),
                      this, SLOT(changed(const QString&)));
    Q_ASSERT(ok);
}

BtFontSizeWidget::~BtFontSizeWidget() {
}

void BtFontSizeWidget::changed(const QString& text) {
    emit fontSizeChanged(text.toInt());
}

void BtFontSizeWidget::setFontSize(int size) {
    int index = findText(QString::number(size));
    if (index >= 0)
        setCurrentIndex(index);
}

int BtFontSizeWidget::fontSize() const {
    return currentText().toInt();
}