summaryrefslogtreecommitdiffstats
path: root/SQLiteStudio3/guiSQLiteStudio/common/fontedit.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'SQLiteStudio3/guiSQLiteStudio/common/fontedit.cpp')
-rw-r--r--SQLiteStudio3/guiSQLiteStudio/common/fontedit.cpp68
1 files changed, 68 insertions, 0 deletions
diff --git a/SQLiteStudio3/guiSQLiteStudio/common/fontedit.cpp b/SQLiteStudio3/guiSQLiteStudio/common/fontedit.cpp
new file mode 100644
index 0000000..a70122b
--- /dev/null
+++ b/SQLiteStudio3/guiSQLiteStudio/common/fontedit.cpp
@@ -0,0 +1,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);
+}