File: fontedit.cpp

package info (click to toggle)
sqlitestudio 3.4.21%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 54,880 kB
  • sloc: ansic: 406,208; cpp: 123,872; yacc: 2,692; tcl: 497; sh: 462; xml: 426; makefile: 19
file content (68 lines) | stat: -rw-r--r-- 1,287 bytes parent folder | download
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include "fontedit.h"
#include "ui_fontedit.h"
#include "iconmanager.h"
#include <QDebug>
#include <QFontDialog>

FontEdit::FontEdit(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::FontEdit)
{
    init();
}

FontEdit::~FontEdit()
{
    delete ui;
}

QFont FontEdit::getFont() const
{
    return font;
}

void FontEdit::setFont(QFont arg)
{
    font = arg;
    updateFont();
}

void FontEdit::changeEvent(QEvent *e)
{
    QWidget::changeEvent(e);
    switch (e->type()) {
        case QEvent::LanguageChange:
            ui->retranslateUi(this);
            break;
        default:
            break;
    }
}

void FontEdit::init()
{
    ui->setupUi(this);
    ui->button->setIcon(ICONS.FONT_BROWSE);
    connect(ui->button, SIGNAL(clicked()), this, SLOT(browse()));
    updateFont();
}

void FontEdit::updateFont()
{
    static const QString text = "%1, %2";
    ui->label->setFont(font);
    int size = font.pointSize() > -1 ? font.pointSize() : font.pixelSize();
    ui->label->setText(text.arg(font.family()).arg(size));
}

void FontEdit::browse()
{
    bool ok;
    QFont newFont = QFontDialog::getFont(&ok, ui->label->font(), this, tr("Choose font", "font configuration"));
    if (!ok)
        return;

    font = newFont;
    updateFont();
    emit fontChanged(newFont);
}