From c3a9c1566d73a8dbc3cec56914ab506a0beb4b10 Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Thu, 30 May 2024 18:03:30 +0800 Subject: [PATCH] - fix: All color scheme names are incorrectly displayed as bold, if the current one is a customed one. --- NEWS.md | 1 + .../editorcolorschemewidget.cpp | 25 +++++++++++++++++-- .../settingsdialog/editorcolorschemewidget.h | 13 ++++++++++ .../widgets/codecompletionlistview.cpp | 1 - RedPandaIDE/widgets/codecompletionlistview.h | 1 - RedPandaIDE/widgets/codecompletionpopup.h | 1 + RedPandaIDE/widgets/headercompletionpopup.h | 1 + 7 files changed, 39 insertions(+), 4 deletions(-) diff --git a/NEWS.md b/NEWS.md index 4e5c19b7..c1783f5c 100644 --- a/NEWS.md +++ b/NEWS.md @@ -13,6 +13,7 @@ Red Panda C++ Version 3.1 - fix: Layout for function tips. - enhancement: More elements in the demo of editor color theme optiont page. - fix: Mingw32-make doesn't work correctly if there are bash in the path. + - fix: All color scheme names are incorrectly displayed as bold, if the current one is a customed one. Red Panda C++ Version 3.0 diff --git a/RedPandaIDE/settingsdialog/editorcolorschemewidget.cpp b/RedPandaIDE/settingsdialog/editorcolorschemewidget.cpp index b20d09ce..c130c646 100644 --- a/RedPandaIDE/settingsdialog/editorcolorschemewidget.cpp +++ b/RedPandaIDE/settingsdialog/editorcolorschemewidget.cpp @@ -34,6 +34,9 @@ EditorColorSchemeWidget::EditorColorSchemeWidget(const QString& name, const QStr ui->setupUi(this); mStatementColors = std::make_shared >>(); + mItemDelegate = new ColorSchemeItemDelegate(this); + ui->cbScheme->setItemDelegate(mItemDelegate); + mDefaultSchemeComboFont = ui->cbScheme->font(); mModifiedSchemeComboFont = mDefaultSchemeComboFont; mModifiedSchemeComboFont.setBold(true); @@ -45,12 +48,14 @@ EditorColorSchemeWidget::EditorColorSchemeWidget(const QString& name, const QStr ui->cbScheme->addItem(schemeName); if (scheme->customed()) ui->cbScheme->setItemData(schemeCount,mModifiedSchemeComboFont,Qt::FontRole); + else + ui->cbScheme->setItemData(schemeCount,mDefaultSchemeComboFont,Qt::FontRole); schemeCount++; } QItemSelectionModel *m = ui->treeItems->selectionModel(); ui->treeItems->setModel(&mDefinesModel); delete m; - mDefinesModel.setHorizontalHeaderLabels(QStringList()); + mDefinesModel.setHorizontalHeaderLabels(QStringList()); for (QString defineName : pColorManager->getDefines()) { addDefine(defineName, pColorManager->getDefine(defineName)); } @@ -433,7 +438,7 @@ void EditorColorSchemeWidget::on_actionReset_Scheme_triggered() if (pColorManager->restoreToDefault(ui->cbScheme->currentText())) { ui->cbScheme->setItemData( ui->cbScheme->currentIndex(), - QVariant(), + mDefaultSchemeComboFont, Qt::FontRole); ui->cbScheme->setFont(mDefaultSchemeComboFont); //ui->cbScheme->view()->setFont(mDefaultSchemeComboFont); @@ -482,3 +487,19 @@ void EditorColorSchemeWidget::on_actionDelete_Scheme_triggered() } + +ColorSchemeItemDelegate::ColorSchemeItemDelegate(QObject *parent): + QStyledItemDelegate{parent} +{ + +} + +void ColorSchemeItemDelegate::initStyleOption(QStyleOptionViewItem *option, const QModelIndex &index) const +{ + QStyledItemDelegate::initStyleOption(option,index); + QVariant value = index.data(Qt::FontRole); + if (value.isValid() && !value.isNull()) { + option->font = qvariant_cast(value); + option->fontMetrics = QFontMetrics(option->font); + } +} diff --git a/RedPandaIDE/settingsdialog/editorcolorschemewidget.h b/RedPandaIDE/settingsdialog/editorcolorschemewidget.h index aa7b8b1f..99ecca27 100644 --- a/RedPandaIDE/settingsdialog/editorcolorschemewidget.h +++ b/RedPandaIDE/settingsdialog/editorcolorschemewidget.h @@ -22,11 +22,23 @@ #include #include +#include namespace Ui { class EditorColorSchemeWidget; } +class ColorSchemeItemDelegate : public QStyledItemDelegate { + Q_OBJECT +public: + ColorSchemeItemDelegate(QObject *parent=nullptr); + + + // QStyledItemDelegate interface +protected: + void initStyleOption(QStyleOptionViewItem *option, const QModelIndex &index) const override; +}; + class EditorColorSchemeWidget : public SettingsWidget { Q_OBJECT @@ -61,6 +73,7 @@ private: QFont mModifiedSchemeComboFont; QSet mModifiedSchemes; QMenu mMenu; + QStyledItemDelegate *mItemDelegate; std::shared_ptr > > mStatementColors; // SettingsWidget interface diff --git a/RedPandaIDE/widgets/codecompletionlistview.cpp b/RedPandaIDE/widgets/codecompletionlistview.cpp index 4d40dd30..95eb9e12 100644 --- a/RedPandaIDE/widgets/codecompletionlistview.cpp +++ b/RedPandaIDE/widgets/codecompletionlistview.cpp @@ -23,7 +23,6 @@ CodeCompletionListView::CodeCompletionListView(QWidget *parent) : QListView(parent) { setUniformItemSizes(true); -// setItemDelegate(&mDelegate); } void CodeCompletionListView::keyPressEvent(QKeyEvent *event) diff --git a/RedPandaIDE/widgets/codecompletionlistview.h b/RedPandaIDE/widgets/codecompletionlistview.h index 1c6aa271..94eb6179 100644 --- a/RedPandaIDE/widgets/codecompletionlistview.h +++ b/RedPandaIDE/widgets/codecompletionlistview.h @@ -19,7 +19,6 @@ #include #include -#include #include "../parser/parserutils.h" using KeyPressedCallback = std::function; using InputMethodCallback = std::function; diff --git a/RedPandaIDE/widgets/codecompletionpopup.h b/RedPandaIDE/widgets/codecompletionpopup.h index 331e6ace..8dcbe8e8 100644 --- a/RedPandaIDE/widgets/codecompletionpopup.h +++ b/RedPandaIDE/widgets/codecompletionpopup.h @@ -19,6 +19,7 @@ #include #include +#include #include "parser/cppparser.h" #include "codecompletionlistview.h" diff --git a/RedPandaIDE/widgets/headercompletionpopup.h b/RedPandaIDE/widgets/headercompletionpopup.h index da7a1632..fd781c59 100644 --- a/RedPandaIDE/widgets/headercompletionpopup.h +++ b/RedPandaIDE/widgets/headercompletionpopup.h @@ -18,6 +18,7 @@ #define HEADERCOMPLETIONPOPUP_H #include +#include #include #include "codecompletionlistview.h" #include "../parser/cppparser.h"