ui: font dropdown
added font dropdown in preferences
This commit is contained in:
@@ -20,6 +20,8 @@ add_files(
|
||||
qt/element/QtCodeSnippet.h
|
||||
qt/element/QtDirectoryListBox.cpp
|
||||
qt/element/QtDirectoryListBox.h
|
||||
qt/element/QtFontPicker.cpp
|
||||
qt/element/QtFontPicker.h
|
||||
qt/element/QtLineEdit.cpp
|
||||
qt/element/QtLineEdit.h
|
||||
qt/element/QtLocationPicker.cpp
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
#include "qt/element/QtFontPicker.h"
|
||||
|
||||
#include <QFileDialog>
|
||||
#include <QFontDialog>
|
||||
#include <QHBoxLayout>
|
||||
#include <QLabel>
|
||||
#include <QPainter>
|
||||
#include <QPushButton>
|
||||
#include <QStyleOption>
|
||||
#include <QComboBox>
|
||||
#include <QFontDatabase>
|
||||
|
||||
#include "qt/element/QtLineEdit.h"
|
||||
|
||||
|
||||
QtFontPicker::QtFontPicker(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
{
|
||||
setObjectName("picker");
|
||||
|
||||
QBoxLayout* layout = new QHBoxLayout();
|
||||
layout->setSpacing(0);
|
||||
layout->setContentsMargins(1, 1, 1, 1);
|
||||
layout->setAlignment(Qt::AlignTop);
|
||||
|
||||
m_box = new QComboBox();
|
||||
QFontDatabase database;
|
||||
m_box->setFont(QFont("Roboto"));
|
||||
for( QString fam : database.families() )
|
||||
{
|
||||
m_box->addItem(fam);
|
||||
}
|
||||
|
||||
QLabel* sampleLabel = new QLabel("Font preview:");
|
||||
m_sampleLabel = new QLabel("AaBbCcXxYyZz");
|
||||
layout->addWidget(sampleLabel);
|
||||
layout->addWidget(m_sampleLabel);
|
||||
QBoxLayout* layout1 = new QVBoxLayout();
|
||||
layout1->addWidget(m_box);
|
||||
layout1->addLayout(layout);
|
||||
|
||||
connect(m_box, static_cast<void(QComboBox::*)(const QString &)>(&QComboBox::currentIndexChanged),
|
||||
[=](const QString &family)
|
||||
{
|
||||
if (!family.isEmpty())
|
||||
{
|
||||
m_sampleLabel->setFont(QFont(family));
|
||||
}
|
||||
});
|
||||
|
||||
setLayout(layout1);
|
||||
setSizePolicy(sizePolicy().horizontalPolicy(), QSizePolicy::Fixed);
|
||||
}
|
||||
|
||||
void QtFontPicker::paintEvent(QPaintEvent*)
|
||||
{
|
||||
QStyleOption opt;
|
||||
opt.init(this);
|
||||
|
||||
QPainter p(this);
|
||||
style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
|
||||
}
|
||||
|
||||
QString QtFontPicker::getText()
|
||||
{
|
||||
return m_box->currentText();
|
||||
}
|
||||
|
||||
void QtFontPicker::setText(QString text)
|
||||
{
|
||||
m_box->setCurrentText(text);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
#ifndef QT_FONT_PICKER_H
|
||||
#define QT_FONT_PICKER_H
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
class QPushButton;
|
||||
class QtLineEdit;
|
||||
class QComboBox;
|
||||
class QLabel;
|
||||
|
||||
class QtFontPicker
|
||||
: public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
QtFontPicker(QWidget *parent);
|
||||
|
||||
virtual void paintEvent(QPaintEvent*) override;
|
||||
|
||||
QString getText();
|
||||
void setText(QString text);
|
||||
|
||||
private:
|
||||
QLabel* m_sampleLabel;
|
||||
QComboBox* m_box;
|
||||
};
|
||||
|
||||
#endif // QT_FONT_PICKER_H
|
||||
@@ -39,7 +39,7 @@ void QtProjectWizzardContentPreferences::populate(QGridLayout* layout, int& row)
|
||||
row++;
|
||||
|
||||
// font face
|
||||
m_fontFace = new QLineEdit();
|
||||
m_fontFace = new QtFontPicker(this);
|
||||
m_fontFace->setObjectName("name");
|
||||
m_fontFace->setAttribute(Qt::WA_MacShowFocusRect, 0);
|
||||
|
||||
@@ -278,7 +278,7 @@ void QtProjectWizzardContentPreferences::save()
|
||||
{
|
||||
ApplicationSettings* appSettings = ApplicationSettings::getInstance().get();
|
||||
|
||||
appSettings->setFontName(m_fontFace->text().toStdString());
|
||||
appSettings->setFontName(m_fontFace->getText().toStdString());
|
||||
|
||||
appSettings->setFontSize(m_fontSize->currentIndex() + appSettings->getFontSizeMin());
|
||||
appSettings->setCodeTabWidth(m_tabWidth->currentIndex() + 1);
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <QComboBox>
|
||||
#include <QLineEdit>
|
||||
|
||||
#include "qt/element/QtFontPicker.h"
|
||||
#include "qt/element/QtLocationPicker.h"
|
||||
#include "qt/window/project_wizzard/QtProjectWizzardContent.h"
|
||||
#include "utility/path_detector/CombinedPathDetector.h"
|
||||
@@ -32,7 +33,7 @@ private slots:
|
||||
private:
|
||||
void addJavaPathDetection(QGridLayout* layout, int& row);
|
||||
|
||||
QLineEdit* m_fontFace;
|
||||
QtFontPicker* m_fontFace;
|
||||
QComboBox* m_fontSize;
|
||||
QComboBox* m_tabWidth;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user