- fix: All color scheme names are incorrectly displayed as bold, if the current one is a customed one.

This commit is contained in:
Roy Qu 2024-05-30 18:03:30 +08:00
parent 7593f3fe64
commit c3a9c1566d
7 changed files with 39 additions and 4 deletions

View File

@ -13,6 +13,7 @@ Red Panda C++ Version 3.1
- fix: Layout for function tips. - fix: Layout for function tips.
- enhancement: More elements in the demo of editor color theme optiont page. - 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: 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 Red Panda C++ Version 3.0

View File

@ -34,6 +34,9 @@ EditorColorSchemeWidget::EditorColorSchemeWidget(const QString& name, const QStr
ui->setupUi(this); ui->setupUi(this);
mStatementColors = std::make_shared<QHash<StatementKind, std::shared_ptr<ColorSchemeItem> >>(); mStatementColors = std::make_shared<QHash<StatementKind, std::shared_ptr<ColorSchemeItem> >>();
mItemDelegate = new ColorSchemeItemDelegate(this);
ui->cbScheme->setItemDelegate(mItemDelegate);
mDefaultSchemeComboFont = ui->cbScheme->font(); mDefaultSchemeComboFont = ui->cbScheme->font();
mModifiedSchemeComboFont = mDefaultSchemeComboFont; mModifiedSchemeComboFont = mDefaultSchemeComboFont;
mModifiedSchemeComboFont.setBold(true); mModifiedSchemeComboFont.setBold(true);
@ -45,6 +48,8 @@ EditorColorSchemeWidget::EditorColorSchemeWidget(const QString& name, const QStr
ui->cbScheme->addItem(schemeName); ui->cbScheme->addItem(schemeName);
if (scheme->customed()) if (scheme->customed())
ui->cbScheme->setItemData(schemeCount,mModifiedSchemeComboFont,Qt::FontRole); ui->cbScheme->setItemData(schemeCount,mModifiedSchemeComboFont,Qt::FontRole);
else
ui->cbScheme->setItemData(schemeCount,mDefaultSchemeComboFont,Qt::FontRole);
schemeCount++; schemeCount++;
} }
QItemSelectionModel *m = ui->treeItems->selectionModel(); QItemSelectionModel *m = ui->treeItems->selectionModel();
@ -433,7 +438,7 @@ void EditorColorSchemeWidget::on_actionReset_Scheme_triggered()
if (pColorManager->restoreToDefault(ui->cbScheme->currentText())) { if (pColorManager->restoreToDefault(ui->cbScheme->currentText())) {
ui->cbScheme->setItemData( ui->cbScheme->setItemData(
ui->cbScheme->currentIndex(), ui->cbScheme->currentIndex(),
QVariant(), mDefaultSchemeComboFont,
Qt::FontRole); Qt::FontRole);
ui->cbScheme->setFont(mDefaultSchemeComboFont); ui->cbScheme->setFont(mDefaultSchemeComboFont);
//ui->cbScheme->view()->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<QFont>(value);
option->fontMetrics = QFontMetrics(option->font);
}
}

View File

@ -22,11 +22,23 @@
#include <QMenu> #include <QMenu>
#include <QStandardItemModel> #include <QStandardItemModel>
#include <QStyledItemDelegate>
namespace Ui { namespace Ui {
class EditorColorSchemeWidget; 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 class EditorColorSchemeWidget : public SettingsWidget
{ {
Q_OBJECT Q_OBJECT
@ -61,6 +73,7 @@ private:
QFont mModifiedSchemeComboFont; QFont mModifiedSchemeComboFont;
QSet<QString> mModifiedSchemes; QSet<QString> mModifiedSchemes;
QMenu mMenu; QMenu mMenu;
QStyledItemDelegate *mItemDelegate;
std::shared_ptr<QHash<StatementKind, std::shared_ptr<ColorSchemeItem> > > mStatementColors; std::shared_ptr<QHash<StatementKind, std::shared_ptr<ColorSchemeItem> > > mStatementColors;
// SettingsWidget interface // SettingsWidget interface

View File

@ -23,7 +23,6 @@
CodeCompletionListView::CodeCompletionListView(QWidget *parent) : QListView(parent) CodeCompletionListView::CodeCompletionListView(QWidget *parent) : QListView(parent)
{ {
setUniformItemSizes(true); setUniformItemSizes(true);
// setItemDelegate(&mDelegate);
} }
void CodeCompletionListView::keyPressEvent(QKeyEvent *event) void CodeCompletionListView::keyPressEvent(QKeyEvent *event)

View File

@ -19,7 +19,6 @@
#include <QListView> #include <QListView>
#include <QKeyEvent> #include <QKeyEvent>
#include <QStyledItemDelegate>
#include "../parser/parserutils.h" #include "../parser/parserutils.h"
using KeyPressedCallback = std::function<bool (QKeyEvent *)>; using KeyPressedCallback = std::function<bool (QKeyEvent *)>;
using InputMethodCallback = std::function<bool (QInputMethodEvent*)>; using InputMethodCallback = std::function<bool (QInputMethodEvent*)>;

View File

@ -19,6 +19,7 @@
#include <QListView> #include <QListView>
#include <QWidget> #include <QWidget>
#include <QStyledItemDelegate>
#include "parser/cppparser.h" #include "parser/cppparser.h"
#include "codecompletionlistview.h" #include "codecompletionlistview.h"

View File

@ -18,6 +18,7 @@
#define HEADERCOMPLETIONPOPUP_H #define HEADERCOMPLETIONPOPUP_H
#include <QDir> #include <QDir>
#include <QStyledItemDelegate>
#include <QWidget> #include <QWidget>
#include "codecompletionlistview.h" #include "codecompletionlistview.h"
#include "../parser/cppparser.h" #include "../parser/cppparser.h"