- 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.
- 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

View File

@ -34,6 +34,9 @@ EditorColorSchemeWidget::EditorColorSchemeWidget(const QString& name, const QStr
ui->setupUi(this);
mStatementColors = std::make_shared<QHash<StatementKind, std::shared_ptr<ColorSchemeItem> >>();
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<QFont>(value);
option->fontMetrics = QFontMetrics(option->font);
}
}

View File

@ -22,11 +22,23 @@
#include <QMenu>
#include <QStandardItemModel>
#include <QStyledItemDelegate>
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<QString> mModifiedSchemes;
QMenu mMenu;
QStyledItemDelegate *mItemDelegate;
std::shared_ptr<QHash<StatementKind, std::shared_ptr<ColorSchemeItem> > > mStatementColors;
// SettingsWidget interface

View File

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

View File

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

View File

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

View File

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