From b2d88e27e0f46a7fe7c3799da438c359f0c6d7fa Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Mon, 25 Mar 2024 17:40:19 +0800 Subject: [PATCH] enhancement: Auto check "only monospace font" when modify the first editor font. --- RedPandaIDE/settingsdialog/editorfontwidget.cpp | 17 ++++++++--------- RedPandaIDE/settingsdialog/editorfontwidget.h | 3 ++- RedPandaIDE/widgets/editorfontdialog.cpp | 4 +++- RedPandaIDE/widgets/editorfontdialog.h | 2 +- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/RedPandaIDE/settingsdialog/editorfontwidget.cpp b/RedPandaIDE/settingsdialog/editorfontwidget.cpp index 082fdaef..d993d1ba 100644 --- a/RedPandaIDE/settingsdialog/editorfontwidget.cpp +++ b/RedPandaIDE/settingsdialog/editorfontwidget.cpp @@ -72,7 +72,7 @@ void EditorFontWidget::on_btnAddFont_clicked() { QModelIndex index = ui->lstFontList->currentIndex(); int insertPos = index.isValid() ? index.row() + 1 : mModel.rowCount(); - EditorFontDialog dlg(this); + EditorFontDialog dlg(insertPos==0, this); if (dlg.exec() == QDialog::Accepted) { mModel.insertRow(insertPos); mModel.setData(mModel.index(insertPos), dlg.fontFamily()); @@ -91,13 +91,7 @@ void EditorFontWidget::on_btnRemoveFont_clicked() void EditorFontWidget::on_btnModifyFont_clicked() { QModelIndex index = ui->lstFontList->currentIndex(); - if (!index.isValid()) - return; - EditorFontDialog dlg(this); - dlg.setFontFamily(mModel.data(index, Qt::DisplayRole).toString()); - if (dlg.exec() == QDialog::Accepted) { - mModel.setData(index, dlg.fontFamily()); - } + modifyFont(index); } void EditorFontWidget::on_btnResetFonts_clicked() @@ -216,10 +210,15 @@ void EditorFontWidget::updateIcons(const QSize &/*size*/) { } void EditorFontWidget::on_lstFontList_doubleClicked(const QModelIndex &index) +{ + modifyFont(index); +} + +void EditorFontWidget::modifyFont(const QModelIndex &index) { if (!index.isValid()) return; - EditorFontDialog dlg(this); + EditorFontDialog dlg(index.row()==0, this); dlg.setFontFamily(mModel.data(index, Qt::DisplayRole).toString()); if (dlg.exec() == QDialog::Accepted) { mModel.setData(index, dlg.fontFamily()); diff --git a/RedPandaIDE/settingsdialog/editorfontwidget.h b/RedPandaIDE/settingsdialog/editorfontwidget.h index 89531dcc..233d2b20 100644 --- a/RedPandaIDE/settingsdialog/editorfontwidget.h +++ b/RedPandaIDE/settingsdialog/editorfontwidget.h @@ -58,7 +58,8 @@ private slots: // void on_chkForceFixedFontWidth_toggled(bool checked); void on_lstFontList_doubleClicked(const QModelIndex &index); - +private: + void modifyFont(const QModelIndex &index); private: Ui::EditorFontWidget *ui; EditorFontModel mModel; diff --git a/RedPandaIDE/widgets/editorfontdialog.cpp b/RedPandaIDE/widgets/editorfontdialog.cpp index 431ef326..378d89f3 100644 --- a/RedPandaIDE/widgets/editorfontdialog.cpp +++ b/RedPandaIDE/widgets/editorfontdialog.cpp @@ -2,11 +2,13 @@ #include "ui_editorfontdialog.h" #include -EditorFontDialog::EditorFontDialog(QWidget *parent) +EditorFontDialog::EditorFontDialog(bool onlyMonospaceFont, QWidget *parent) : QDialog(parent) , ui(new Ui::EditorFontDialog) { ui->setupUi(this); + ui->chkMonoOnly->setChecked(onlyMonospaceFont); + ui->fontComboBox->setFontFilters(onlyMonospaceFont ? QFontComboBox::MonospacedFonts : QFontComboBox::AllFonts); } EditorFontDialog::~EditorFontDialog() diff --git a/RedPandaIDE/widgets/editorfontdialog.h b/RedPandaIDE/widgets/editorfontdialog.h index 1239e78d..f2f4023e 100644 --- a/RedPandaIDE/widgets/editorfontdialog.h +++ b/RedPandaIDE/widgets/editorfontdialog.h @@ -12,7 +12,7 @@ class EditorFontDialog : public QDialog Q_OBJECT public: - explicit EditorFontDialog(QWidget *parent = nullptr); + explicit EditorFontDialog(bool onlyMonospaceFont, QWidget *parent = nullptr); ~EditorFontDialog(); QString fontFamily() const;