enhancement: Auto check "only monospace font" when modify the first editor font.

This commit is contained in:
Roy Qu 2024-03-25 17:40:19 +08:00
parent 0339baf069
commit b2d88e27e0
4 changed files with 14 additions and 12 deletions

View File

@ -72,7 +72,7 @@ void EditorFontWidget::on_btnAddFont_clicked()
{ {
QModelIndex index = ui->lstFontList->currentIndex(); QModelIndex index = ui->lstFontList->currentIndex();
int insertPos = index.isValid() ? index.row() + 1 : mModel.rowCount(); int insertPos = index.isValid() ? index.row() + 1 : mModel.rowCount();
EditorFontDialog dlg(this); EditorFontDialog dlg(insertPos==0, this);
if (dlg.exec() == QDialog::Accepted) { if (dlg.exec() == QDialog::Accepted) {
mModel.insertRow(insertPos); mModel.insertRow(insertPos);
mModel.setData(mModel.index(insertPos), dlg.fontFamily()); mModel.setData(mModel.index(insertPos), dlg.fontFamily());
@ -91,13 +91,7 @@ void EditorFontWidget::on_btnRemoveFont_clicked()
void EditorFontWidget::on_btnModifyFont_clicked() void EditorFontWidget::on_btnModifyFont_clicked()
{ {
QModelIndex index = ui->lstFontList->currentIndex(); QModelIndex index = ui->lstFontList->currentIndex();
if (!index.isValid()) modifyFont(index);
return;
EditorFontDialog dlg(this);
dlg.setFontFamily(mModel.data(index, Qt::DisplayRole).toString());
if (dlg.exec() == QDialog::Accepted) {
mModel.setData(index, dlg.fontFamily());
}
} }
void EditorFontWidget::on_btnResetFonts_clicked() void EditorFontWidget::on_btnResetFonts_clicked()
@ -216,10 +210,15 @@ void EditorFontWidget::updateIcons(const QSize &/*size*/) {
} }
void EditorFontWidget::on_lstFontList_doubleClicked(const QModelIndex &index) void EditorFontWidget::on_lstFontList_doubleClicked(const QModelIndex &index)
{
modifyFont(index);
}
void EditorFontWidget::modifyFont(const QModelIndex &index)
{ {
if (!index.isValid()) if (!index.isValid())
return; return;
EditorFontDialog dlg(this); EditorFontDialog dlg(index.row()==0, this);
dlg.setFontFamily(mModel.data(index, Qt::DisplayRole).toString()); dlg.setFontFamily(mModel.data(index, Qt::DisplayRole).toString());
if (dlg.exec() == QDialog::Accepted) { if (dlg.exec() == QDialog::Accepted) {
mModel.setData(index, dlg.fontFamily()); mModel.setData(index, dlg.fontFamily());

View File

@ -58,7 +58,8 @@ private slots:
// void on_chkForceFixedFontWidth_toggled(bool checked); // void on_chkForceFixedFontWidth_toggled(bool checked);
void on_lstFontList_doubleClicked(const QModelIndex &index); void on_lstFontList_doubleClicked(const QModelIndex &index);
private:
void modifyFont(const QModelIndex &index);
private: private:
Ui::EditorFontWidget *ui; Ui::EditorFontWidget *ui;
EditorFontModel mModel; EditorFontModel mModel;

View File

@ -2,11 +2,13 @@
#include "ui_editorfontdialog.h" #include "ui_editorfontdialog.h"
#include <QAbstractItemView> #include <QAbstractItemView>
EditorFontDialog::EditorFontDialog(QWidget *parent) EditorFontDialog::EditorFontDialog(bool onlyMonospaceFont, QWidget *parent)
: QDialog(parent) : QDialog(parent)
, ui(new Ui::EditorFontDialog) , ui(new Ui::EditorFontDialog)
{ {
ui->setupUi(this); ui->setupUi(this);
ui->chkMonoOnly->setChecked(onlyMonospaceFont);
ui->fontComboBox->setFontFilters(onlyMonospaceFont ? QFontComboBox::MonospacedFonts : QFontComboBox::AllFonts);
} }
EditorFontDialog::~EditorFontDialog() EditorFontDialog::~EditorFontDialog()

View File

@ -12,7 +12,7 @@ class EditorFontDialog : public QDialog
Q_OBJECT Q_OBJECT
public: public:
explicit EditorFontDialog(QWidget *parent = nullptr); explicit EditorFontDialog(bool onlyMonospaceFont, QWidget *parent = nullptr);
~EditorFontDialog(); ~EditorFontDialog();
QString fontFamily() const; QString fontFamily() const;