Editor: Adding QFontComboBox to texteditor font settings.

Replacing the QComboBox with a combo box that is capable of
previewing the fonts.

Change-Id: Iff70e4464a99bfa07b0bcf333c2aff402ef5ce28
Reviewed-by: Leena Miettinen <riitta-leena.miettinen@theqtcompany.com>
Reviewed-by: Christian Stenger <christian.stenger@theqtcompany.com>
This commit is contained in:
David Schulz
2015-04-22 15:09:42 +02:00
parent 7195bf8559
commit f02e09f60e
3 changed files with 99 additions and 100 deletions

View File

@@ -337,11 +337,7 @@ QWidget *FontSettingsPage::widget()
d_ptr->m_ui->setupUi(d_ptr->m_widget);
d_ptr->m_ui->schemeComboBox->setModel(d_ptr->m_schemeListModel);
QFontDatabase db;
const QStringList families = db.families();
d_ptr->m_ui->familyComboBox->addItems(families);
const int idx = families.indexOf(d_ptr->m_value.family());
d_ptr->m_ui->familyComboBox->setCurrentIndex(idx);
d_ptr->m_ui->fontComboBox->setCurrentFont(d_ptr->m_value.family());
d_ptr->m_ui->antialias->setChecked(d_ptr->m_value.antialias());
d_ptr->m_ui->zoomSpinBox->setValue(d_ptr->m_value.fontZoom());
@@ -350,13 +346,23 @@ QWidget *FontSettingsPage::widget()
d_ptr->m_ui->schemeEdit->setBaseFont(d_ptr->m_value.font());
d_ptr->m_ui->schemeEdit->setColorScheme(d_ptr->m_value.colorScheme());
connect(d_ptr->m_ui->familyComboBox, SIGNAL(currentIndexChanged(QString)), this, SLOT(fontFamilySelected(QString)));
connect(d_ptr->m_ui->sizeComboBox, SIGNAL(currentIndexChanged(QString)), this, SLOT(fontSizeSelected(QString)));
connect(d_ptr->m_ui->zoomSpinBox, SIGNAL(valueChanged(int)), this, SLOT(fontZoomChanged()));
connect(d_ptr->m_ui->antialias, SIGNAL(toggled(bool)), this, SLOT(antialiasChanged()));
connect(d_ptr->m_ui->schemeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(colorSchemeSelected(int)));
connect(d_ptr->m_ui->copyButton, SIGNAL(clicked()), this, SLOT(copyColorScheme()));
connect(d_ptr->m_ui->deleteButton, SIGNAL(clicked()), this, SLOT(confirmDeleteColorScheme()));
connect(d_ptr->m_ui->fontComboBox, &QFontComboBox::currentFontChanged,
this, &FontSettingsPage::fontSelected);
connect(d_ptr->m_ui->sizeComboBox,
static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::currentIndexChanged),
this, &FontSettingsPage::fontSizeSelected);
connect(d_ptr->m_ui->zoomSpinBox,
static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged),
this, &FontSettingsPage::fontZoomChanged);
connect(d_ptr->m_ui->antialias, &QCheckBox::toggled,
this, &FontSettingsPage::antialiasChanged);
connect(d_ptr->m_ui->schemeComboBox,
static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
this, &FontSettingsPage::colorSchemeSelected);
connect(d_ptr->m_ui->copyButton, &QPushButton::clicked,
this, &FontSettingsPage::openCopyColorSchemeDialog);
connect(d_ptr->m_ui->deleteButton, &QPushButton::clicked,
this, &FontSettingsPage::confirmDeleteColorScheme);
updatePointSizes();
@@ -366,10 +372,10 @@ QWidget *FontSettingsPage::widget()
return d_ptr->m_widget;
}
void FontSettingsPage::fontFamilySelected(const QString &family)
void FontSettingsPage::fontSelected(const QFont &font)
{
d_ptr->m_value.setFamily(family);
d_ptr->m_ui->schemeEdit->setBaseFont(d_ptr->m_value.font());
d_ptr->m_value.setFamily(font.family());
d_ptr->m_ui->schemeEdit->setBaseFont(font);
updatePointSizes();
}
@@ -393,7 +399,7 @@ void FontSettingsPage::updatePointSizes()
QList<int> FontSettingsPage::pointSizesForSelectedFont() const
{
QFontDatabase db;
const QString familyName = d_ptr->m_ui->familyComboBox->currentText();
const QString familyName = d_ptr->m_ui->fontComboBox->currentFont().family();
QList<int> sizeLst = db.pointSizes(familyName);
if (!sizeLst.isEmpty())
return sizeLst;
@@ -446,7 +452,7 @@ void FontSettingsPage::colorSchemeSelected(int index)
d_ptr->m_ui->schemeEdit->setReadOnly(readOnly);
}
void FontSettingsPage::copyColorScheme()
void FontSettingsPage::openCopyColorSchemeDialog()
{
QInputDialog *dialog = new QInputDialog(d_ptr->m_ui->copyButton->window());
dialog->setAttribute(Qt::WA_DeleteOnClose);

View File

@@ -107,12 +107,12 @@ signals:
private slots:
void delayedChange();
void fontFamilySelected(const QString &family);
void fontSelected(const QFont &font);
void fontSizeSelected(const QString &sizeString);
void fontZoomChanged();
void antialiasChanged();
void colorSchemeSelected(int index);
void copyColorScheme();
void openCopyColorSchemeDialog();
void copyColorScheme(const QString &name);
void confirmDeleteColorScheme();
void deleteColorScheme();

View File

@@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>521</width>
<width>547</width>
<height>306</height>
</rect>
</property>
@@ -17,6 +17,45 @@
<string>Font</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="6">
<spacer>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Preferred</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="0" colspan="3">
<widget class="QCheckBox" name="antialias">
<property name="text">
<string>Antialias</string>
</property>
</widget>
</item>
<item row="0" column="3">
<spacer>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Preferred</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="0">
<widget class="QLabel" name="familyLabel">
<property name="sizePolicy">
@@ -30,79 +69,7 @@
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="familyComboBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>2</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="0" column="2">
<spacer>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Preferred</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="3">
<widget class="QLabel" name="sizeLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Size:</string>
</property>
</widget>
</item>
<item row="0" column="4">
<widget class="QComboBox" name="sizeComboBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="0" column="5">
<spacer>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Preferred</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="0" colspan="2">
<widget class="QCheckBox" name="antialias">
<property name="text">
<string>Antialias</string>
</property>
</widget>
</item>
<item row="0" column="7">
<item row="0" column="8">
<widget class="QSpinBox" name="zoomSpinBox">
<property name="suffix">
<string>%</string>
@@ -121,7 +88,37 @@
</property>
</widget>
</item>
<item row="0" column="8">
<item row="0" column="7">
<widget class="QLabel" name="zoomLabel">
<property name="text">
<string>Zoom:</string>
</property>
</widget>
</item>
<item row="0" column="4">
<widget class="QLabel" name="sizeLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Size:</string>
</property>
</widget>
</item>
<item row="0" column="5">
<widget class="QComboBox" name="sizeComboBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="0" column="9">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
@@ -134,12 +131,8 @@
</property>
</spacer>
</item>
<item row="0" column="6">
<widget class="QLabel" name="zoomLabel">
<property name="text">
<string>Zoom:</string>
</property>
</widget>
<item row="0" column="1">
<widget class="QFontComboBox" name="fontComboBox"/>
</item>
</layout>
</widget>