- Change: Change background color for highlighted buttons in the default theme.

- enhancement: Make matched contents more obvious in the code suggestion popup.
  - enhancement: Make matched contents more obvious in the header suggestion popup.
This commit is contained in:
Roy Qu 2024-03-31 17:23:16 +08:00
parent a071057842
commit 8eee3de831
7 changed files with 132 additions and 29 deletions

View File

@ -107,7 +107,9 @@ Red Panda C++ Version 2.27
- fix: If there are only 1 line in the editor, shift+down can't select it. - fix: If there are only 1 line in the editor, shift+down can't select it.
- enhancement: By default, use monospaced font to display register values in the CPU Info dialog. - enhancement: By default, use monospaced font to display register values in the CPU Info dialog.
- fix: Negative values in register like AH/AL are wrongs displayed as 32/64-bit number. - fix: Negative values in register like AH/AL are wrongs displayed as 32/64-bit number.
- Change: Background color for highlighted buttons in the default theme. - Change: Change background color for highlighted buttons in the default theme.
- enhancement: Make matched contents more obvious in the code suggestion popup.
- enhancement: Make matched contents more obvious in the header suggestion popup.
Red Panda C++ Version 2.26 Red Panda C++ Version 2.26
- enhancement: Code suggestion for embedded std::vectors. - enhancement: Code suggestion for embedded std::vectors.

View File

@ -480,14 +480,12 @@ void GDBMIDebuggerClient::handleRegisterValue(const QList<GDBMIResultParser::Par
QString value = obj["value"].value(); QString value = obj["value"].value();
if (hexValue) { if (hexValue) {
bool ok; bool ok;
long long intVal; value.toLongLong(&ok,16);
intVal = value.toLongLong(&ok,16);
if (ok) if (ok)
result.insert(number,value); result.insert(number,value);
} else { } else {
bool ok; bool ok;
long long intVal; value.toLongLong(&ok,10);
intVal = value.toLongLong(&ok,10);
if (!ok) if (!ok)
result.insert(number,value); result.insert(number,value);
} }

View File

@ -30,7 +30,7 @@
"PaletteTextDisabled":"#bebebe", "PaletteTextDisabled":"#bebebe",
"PaletteButtonDisabled": "#efefef", "PaletteButtonDisabled": "#efefef",
"PaletteButtonTextDisabled":"#bebebe", "PaletteButtonTextDisabled":"#bebebe",
"PaletteHighlight":"#ff678cb1", "PaletteHighlight":"#ff688DB2",
"PaletteHighlightedText":"#ffeeeeee" "PaletteHighlightedText":"#fff0f0f0"
} }
} }

View File

@ -1326,12 +1326,28 @@ void CodeCompletionListItemDelegate::paint(QPainter *painter, const QStyleOption
{ {
PStatement statement; PStatement statement;
if (mModel && (statement = mModel->statement(index)) ) { if (mModel && (statement = mModel->statement(index)) ) {
QFont normalFont{font()};
QFont matchedFont{font()};
normalFont.setBold(false);
normalFont.setUnderline(false);
matchedFont.setBold(true);
matchedFont.setUnderline(true);
painter->save(); painter->save();
painter->setFont(font()); painter->setFont(normalFont);
QColor normalColor = mNormalColor; QColor normalColor = mNormalColor;
QColor matchedColor = mMatchedColor;
if (option.state & QStyle::State_Selected) { if (option.state & QStyle::State_Selected) {
painter->fillRect(option.rect, option.palette.highlight()); painter->fillRect(option.rect, option.palette.highlight());
normalColor = option.palette.color(QPalette::HighlightedText); normalColor = option.palette.color(QPalette::HighlightedText);
float h = mMatchedColor.hslHueF();
float s = mMatchedColor.hslSaturationF();
float l = normalColor.lightnessF();
if (l>0.85) {
l = 0.85;
} else if (l<0.15) {
l = 0.15;
}
matchedColor = QColor::fromHslF(h,s,l);
} }
QPixmap icon = mModel->statementIcon(index); QPixmap icon = mModel->statementIcon(index);
int x=option.rect.left(); int x=option.rect.left();
@ -1349,11 +1365,13 @@ void CodeCompletionListItemDelegate::paint(QPainter *painter, const QStyleOption
if (pos<matchPosition->start) { if (pos<matchPosition->start) {
QString t = text.mid(pos,matchPosition->start-pos); QString t = text.mid(pos,matchPosition->start-pos);
painter->setPen(normalColor); painter->setPen(normalColor);
painter->setFont(normalFont);
painter->drawText(x,y,t); painter->drawText(x,y,t);
x+=painter->fontMetrics().horizontalAdvance(t); x+=painter->fontMetrics().horizontalAdvance(t);
} }
QString t = text.mid(matchPosition->start, matchPosition->end-matchPosition->start); QString t = text.mid(matchPosition->start, matchPosition->end-matchPosition->start);
painter->setPen(mMatchedColor); painter->setPen(matchedColor);
painter->setFont(matchedFont);
painter->drawText(x,y,t); painter->drawText(x,y,t);
x+=painter->fontMetrics().horizontalAdvance(t); x+=painter->fontMetrics().horizontalAdvance(t);
pos=matchPosition->end; pos=matchPosition->end;
@ -1361,6 +1379,7 @@ void CodeCompletionListItemDelegate::paint(QPainter *painter, const QStyleOption
if (pos<text.length()) { if (pos<text.length()) {
QString t = text.mid(pos,text.length()-pos); QString t = text.mid(pos,text.length()-pos);
painter->setPen(normalColor); painter->setPen(normalColor);
painter->setFont(normalFont);
painter->drawText(x,y,t); painter->drawText(x,y,t);
x+=painter->fontMetrics().horizontalAdvance(t); x+=painter->fontMetrics().horizontalAdvance(t);
} }
@ -1370,16 +1389,6 @@ void CodeCompletionListItemDelegate::paint(QPainter *painter, const QStyleOption
} }
} }
CodeCompletionListModel *CodeCompletionListItemDelegate::model() const
{
return mModel;
}
void CodeCompletionListItemDelegate::setModel(CodeCompletionListModel *newModel)
{
mModel = newModel;
}
const QColor &CodeCompletionListItemDelegate::normalColor() const const QColor &CodeCompletionListItemDelegate::normalColor() const
{ {
return mNormalColor; return mNormalColor;

View File

@ -56,8 +56,6 @@ public:
// QAbstractItemDelegate interface // QAbstractItemDelegate interface
public: public:
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override; void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
CodeCompletionListModel *model() const;
void setModel(CodeCompletionListModel *newModel);
const QColor &normalColor() const; const QColor &normalColor() const;
void setNormalColor(const QColor &newNormalColor); void setNormalColor(const QColor &newNormalColor);

View File

@ -15,11 +15,12 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
#include "headercompletionpopup.h" #include "headercompletionpopup.h"
#include "codecompletionpopup.h"
#include <QCoreApplication> #include <QCoreApplication>
#include <QFileInfo> #include <QFileInfo>
#include <QVBoxLayout> #include <QVBoxLayout>
#include <QDebug> #include <QDebug>
#include "qpainter.h"
#include "systemconsts.h" #include "systemconsts.h"
#include "../utils.h" #include "../utils.h"
@ -27,10 +28,12 @@ HeaderCompletionPopup::HeaderCompletionPopup(QWidget* parent):QWidget(parent)
{ {
setWindowFlags(Qt::Popup); setWindowFlags(Qt::Popup);
mListView = new CodeCompletionListView(this); mListView = new CodeCompletionListView(this);
mModel=new HeaderCompletionListModel(&mCompletionList); mModel=new HeaderCompletionListModel(&mCompletionList, 0);
QItemSelectionModel *m=mListView->selectionModel(); QItemSelectionModel *m=mListView->selectionModel();
mListView->setModel(mModel); mListView->setModel(mModel);
delete m; delete m;
mDelegate = new HeaderCompletionListItemDelegate(mModel,this);
mListView->setItemDelegate(mDelegate);
setLayout(new QVBoxLayout()); setLayout(new QVBoxLayout());
layout()->addWidget(mListView); layout()->addWidget(mListView);
layout()->setMargin(0); layout()->setMargin(0);
@ -158,6 +161,7 @@ void HeaderCompletionPopup::filterList(const QString &member)
{ {
Qt::CaseSensitivity caseSensitivity=mIgnoreCase?Qt::CaseInsensitive:Qt::CaseSensitive; Qt::CaseSensitivity caseSensitivity=mIgnoreCase?Qt::CaseInsensitive:Qt::CaseSensitive;
mCompletionList.clear(); mCompletionList.clear();
mModel->setMatched(0);
if (member.isEmpty()) { if (member.isEmpty()) {
foreach (const PHeaderCompletionListItem& item,mFullCompletionList.values()) { foreach (const PHeaderCompletionListItem& item,mFullCompletionList.values()) {
mCompletionList.append(item); mCompletionList.append(item);
@ -170,6 +174,7 @@ void HeaderCompletionPopup::filterList(const QString &member)
} }
} }
std::sort(mCompletionList.begin(),mCompletionList.end(), sortByUsage); std::sort(mCompletionList.begin(),mCompletionList.end(), sortByUsage);
mModel->setMatched(member.length());
} }
@ -286,6 +291,7 @@ void HeaderCompletionPopup::setParser(const PCppParser &newParser)
void HeaderCompletionPopup::hideEvent(QHideEvent *) void HeaderCompletionPopup::hideEvent(QHideEvent *)
{ {
mCompletionList.clear(); mCompletionList.clear();
mModel->setMatched(0);
mFullCompletionList.clear(); mFullCompletionList.clear();
mParser = nullptr; mParser = nullptr;
} }
@ -296,6 +302,7 @@ bool HeaderCompletionPopup::event(QEvent *event)
switch (event->type()) { switch (event->type()) {
case QEvent::FontChange: case QEvent::FontChange:
mListView->setFont(font()); mListView->setFont(font());
mDelegate->setFont(font());
break; break;
default: default:
break; break;
@ -303,9 +310,10 @@ bool HeaderCompletionPopup::event(QEvent *event)
return result; return result;
} }
HeaderCompletionListModel::HeaderCompletionListModel(const QList<PHeaderCompletionListItem> *files, QObject *parent): HeaderCompletionListModel::HeaderCompletionListModel(const QList<PHeaderCompletionListItem> *files, int matched, QObject *parent):
QAbstractListModel(parent), QAbstractListModel{parent},
mFiles(files) mFiles{files},
mMatched{matched}
{ {
} }
@ -350,6 +358,11 @@ void HeaderCompletionListModel::notifyUpdated()
endResetModel(); endResetModel();
} }
void HeaderCompletionListModel::setLocalColor(const QColor &newColor)
{
mLocalColor = newColor;
}
void HeaderCompletionListModel::setSystemColor(const QColor &newColor) void HeaderCompletionListModel::setSystemColor(const QColor &newColor)
{ {
mSystemColor = newColor; mSystemColor = newColor;
@ -365,7 +378,66 @@ void HeaderCompletionListModel::setFolderColor(const QColor &newFolderColor)
mFolderColor = newFolderColor; mFolderColor = newFolderColor;
} }
void HeaderCompletionListModel::setLocalColor(const QColor &newColor) int HeaderCompletionListModel::matched() const
{ {
mLocalColor = newColor; return mMatched;
}
void HeaderCompletionListModel::setMatched(int newMatched)
{
mMatched = newMatched;
}
HeaderCompletionListItemDelegate::HeaderCompletionListItemDelegate(HeaderCompletionListModel *model, QWidget *parent):
QStyledItemDelegate{parent},
mModel{model}
{
}
void HeaderCompletionListItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
if (!mModel) {
QStyledItemDelegate::paint(painter, option, index);
return;
}
QString text = mModel->data(index, Qt::DisplayRole).toString();
if (text.isEmpty()) {
QStyledItemDelegate::paint(painter, option, index);
return;
}
painter->save();
QFont normalFont{font()};
QFont matchedFont{font()};
normalFont.setBold(false);
normalFont.setUnderline(false);
matchedFont.setBold(true);
matchedFont.setUnderline(true);
painter->setFont(normalFont);
QColor normalColor = mModel->data(index, Qt::ForegroundRole).value<QColor>();
if (option.state & QStyle::State_Selected) {
painter->fillRect(option.rect, option.palette.highlight());
normalColor = option.palette.color(QPalette::HighlightedText);
}
painter->setPen(normalColor);
int y=option.rect.bottom()-painter->fontMetrics().descent();
int x=0;
QString t = text.left(mModel->matched());
painter->setFont(matchedFont);
painter->drawText(x,y,t);
x+=painter->fontMetrics().horizontalAdvance(t);
t = text.mid(mModel->matched());
painter->setFont(normalFont);
painter->drawText(x,y,t);
painter->restore();
}
const QFont &HeaderCompletionListItemDelegate::font() const
{
return mFont;
}
void HeaderCompletionListItemDelegate::setFont(const QFont &newFont)
{
mFont=newFont;
} }

View File

@ -43,7 +43,7 @@ using PHeaderCompletionListItem=std::shared_ptr<HeaderCompletionListItem>;
class HeaderCompletionListModel: public QAbstractListModel { class HeaderCompletionListModel: public QAbstractListModel {
Q_OBJECT Q_OBJECT
public: public:
explicit HeaderCompletionListModel(const QList<PHeaderCompletionListItem>* files,QObject *parent = nullptr); explicit HeaderCompletionListModel(const QList<PHeaderCompletionListItem>* files, int matched, QObject *parent = nullptr);
int rowCount(const QModelIndex &parent) const override; int rowCount(const QModelIndex &parent) const override;
QVariant data(const QModelIndex &index, int role) const override; QVariant data(const QModelIndex &index, int role) const override;
void notifyUpdated(); void notifyUpdated();
@ -53,12 +53,34 @@ public:
void setFolderColor(const QColor &newFolderColor); void setFolderColor(const QColor &newFolderColor);
int matched() const;
void setMatched(int newMatched);
private: private:
const QList<PHeaderCompletionListItem> *mFiles; const QList<PHeaderCompletionListItem> *mFiles;
QColor mLocalColor; QColor mLocalColor;
QColor mSystemColor; QColor mSystemColor;
QColor mProjectColor; QColor mProjectColor;
QColor mFolderColor; QColor mFolderColor;
int mMatched;
};
class HeaderCompletionListItemDelegate: public QStyledItemDelegate {
Q_OBJECT
public:
HeaderCompletionListItemDelegate(HeaderCompletionListModel *model=nullptr, QWidget *parent = nullptr);
// QAbstractItemDelegate interface
public:
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
const QFont &font() const;
void setFont(const QFont &newFont);
private:
HeaderCompletionListModel *mModel;
QFont mFont;
}; };
class HeaderCompletionPopup : public QWidget class HeaderCompletionPopup : public QWidget
@ -98,6 +120,8 @@ private:
bool mSearchLocal; bool mSearchLocal;
QString mCurrentFile; QString mCurrentFile;
HeaderCompletionListItemDelegate* mDelegate;
// QWidget interface // QWidget interface
protected: protected:
void hideEvent(QHideEvent *event) override; void hideEvent(QHideEvent *event) override;