Skip to content

Commit

Permalink
Github Issue #39: The text preview now gets updated with the font sel…
Browse files Browse the repository at this point in the history
…ection. Also added weight, stretch and size options to the font. QSpinbox has bug so had to use QLineEdit for font size
  • Loading branch information
AngryFender committed Feb 16, 2024
1 parent e2ddf4b commit 44e8cfc
Show file tree
Hide file tree
Showing 3 changed files with 146 additions and 22 deletions.
91 changes: 87 additions & 4 deletions settingsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,48 @@ SettingsDialog::SettingsDialog(QWidget *parent) :
previewHighligher.setDocument(&this->previewDocument) ;
ui->txt_preview->setDocument(&this->previewDocument);

ui->cmb_theme->addItem("Light Theme");
ui->cmb_theme->addItem("Dark Theme");

ui->cmb_stretch->addItem("AnyStretch");
ui->cmb_stretch->addItem("UltraCondensed");
ui->cmb_stretch->addItem("ExtraCondensed");
ui->cmb_stretch->addItem("Condensed");
ui->cmb_stretch->addItem("SemiCondensed");
ui->cmb_stretch->addItem("Unstretched");
ui->cmb_stretch->addItem("SemiExpanded");
ui->cmb_stretch->addItem("Expanded");
ui->cmb_stretch->addItem("ExtraExpanded");
ui->cmb_stretch->addItem("UltraExpanded");

ui->cmb_weight->addItem("Thin");
ui->cmb_weight->addItem("ExtraLight");
ui->cmb_weight->addItem("Light");
ui->cmb_weight->addItem("Normal");
ui->cmb_weight->addItem("Medium");
ui->cmb_weight->addItem("DemiBold");
ui->cmb_weight->addItem("Bold");
ui->cmb_weight->addItem("ExtraBold");
ui->cmb_weight->addItem("Black");

ui->ledit_font_size->setValidator(new QIntValidator(6,30,ui->ledit_font_size));
QObject::connect(ui->btn_vaultRootPath, &QPushButton::pressed,
this, &SettingsDialog::executeFolderDialog);
this, &SettingsDialog::executeFolderDialog);

QObject::connect(this,&SettingsDialog::syntaxColorUpdate,
&previewHighligher,&Highlighter::syntaxColorUpdateHandler);
&previewHighligher,&Highlighter::syntaxColorUpdateHandler);

ui->cmb_theme->addItem("Light Theme");
ui->cmb_theme->addItem("Dark Theme");
QObject::connect(ui->cmb_font,&QFontComboBox::currentFontChanged,
this, &SettingsDialog::updateFontHandler);

QObject::connect(ui->ledit_font_size,&QLineEdit::textChanged,
this, &SettingsDialog::updateFontSizeHandler);

QObject::connect(ui->cmb_stretch,&QComboBox::currentIndexChanged,
this, &SettingsDialog::updateStretchHandler);

QObject::connect(ui->cmb_weight,&QComboBox::currentIndexChanged,
this, &SettingsDialog::updateWeightHandler);
}

SettingsDialog::~SettingsDialog()
Expand All @@ -40,6 +74,55 @@ void SettingsDialog::executeFolderDialog()
}
}

void SettingsDialog::updateFontHandler(const QFont &f)
{
ui->txt_preview->setFont(f);
ui->txt_preview->update();
}

void SettingsDialog::updateFontSizeHandler(const QString &text)
{
QFont font = ui->txt_preview->font();
font.setPointSize(text.toInt());
ui->txt_preview->setFont(font);
}

void SettingsDialog::updateStretchHandler(const int index)
{
QFont font = ui->txt_preview->font();
switch(index){
case 0: font.setStretch(QFont::AnyStretch);break;
case 1: font.setStretch(QFont::UltraCondensed);break;
case 2: font.setStretch(QFont::ExtraCondensed);break;
case 3: font.setStretch(QFont::Condensed);break;
case 4: font.setStretch(QFont::SemiCondensed);break;
case 5: font.setStretch(QFont::Unstretched);break;
case 6: font.setStretch(QFont::SemiExpanded);break;
case 7: font.setStretch(QFont::Expanded);break;
case 8: font.setStretch(QFont::ExtraExpanded);break;
case 9: font.setStretch(QFont::UltraExpanded);break;
default: break;
}
ui->txt_preview->setFont(font);
}

void SettingsDialog::updateWeightHandler(const int weight)
{
QFont font = ui->txt_preview->font();
switch(weight){
case 0: font.setWeight(QFont::Thin);break;
case 1: font.setWeight(QFont::Light);break;
case 2: font.setWeight(QFont::Normal);break;
case 3: font.setWeight(QFont::Medium);break;
case 4: font.setWeight(QFont::DemiBold);break;
case 5: font.setWeight(QFont::Bold);break;
case 6: font.setWeight(QFont::ExtraBold);break;
case 7: font.setWeight(QFont::Black);break;
default: break;
}
ui->txt_preview->setFont(font);
}

void SettingsDialog::syntaxColorUpdateHandler(HighlightColor &colors)
{
this->previewColors = colors;
Expand Down
4 changes: 4 additions & 0 deletions settingsdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ class SettingsDialog : public QDialog
void syntaxColorUpdate(HighlightColor &colors);
private slots:
void executeFolderDialog();
void updateFontHandler(const QFont &f);
void updateFontSizeHandler(const QString &text );
void updateStretchHandler(const int index);
void updateWeightHandler(const int index);
public slots:
void syntaxColorUpdateHandler(HighlightColor &colors);
void show();
Expand Down
73 changes: 55 additions & 18 deletions settingsdialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,60 @@
</layout>
</item>
<item row="1" column="0">
<widget class="QLabel" name="lbl_font">
<widget class="QLabel" name="lbl_theme">
<property name="text">
<string>Font </string>
<string>Theme</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="cmb_theme"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="lbl_theme">
<widget class="QLabel" name="lbl_font">
<property name="text">
<string>Theme</string>
<string>Font </string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QComboBox" name="cmb_theme"/>
<widget class="QFontComboBox" name="cmb_font"/>
</item>
<item row="3" column="1">
<item row="3" column="0">
<widget class="QLabel" name="lbl_font_size">
<property name="text">
<string>Font Size</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="lbl_stretch">
<property name="text">
<string>Stretch</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QComboBox" name="cmb_stretch"/>
</item>
<item row="5" column="0">
<widget class="QLabel" name="lbl_weight">
<property name="text">
<string>Weight</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QComboBox" name="cmb_weight"/>
</item>
<item row="6" column="0">
<widget class="QLabel" name="lbl_preview">
<property name="text">
<string>Preview</string>
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="QTextEdit" name="txt_preview">
<property name="html">
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
Expand All @@ -71,21 +108,21 @@ li.checked::marker { content: &quot;\2612&quot;; }
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QFontComboBox" name="cmb_font"/>
<item row="7" column="1">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLineEdit" name="ledit_font_size"/>
</item>
</layout>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
Expand Down

0 comments on commit 44e8cfc

Please sign in to comment.