From 57c4b4d64645e1f1c6effd2d497045a94ef58bd9 Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Wed, 10 Apr 2024 21:43:28 +0800 Subject: [PATCH] - enhancement: Function tip's width changes with editor width. - fix: '<' / '>' not shown in function tips. --- NEWS.md | 2 ++ RedPandaIDE/editor.cpp | 1 + RedPandaIDE/parser/cppparser.cpp | 7 +++-- RedPandaIDE/widgets/functiontooltipwidget.cpp | 30 +++++++++++++++---- RedPandaIDE/widgets/functiontooltipwidget.h | 4 +++ 5 files changed, 37 insertions(+), 7 deletions(-) diff --git a/NEWS.md b/NEWS.md index 592f2068..1dc4676e 100644 --- a/NEWS.md +++ b/NEWS.md @@ -131,6 +131,8 @@ Red Panda C++ Version 2.27 - fix: Can't find the correct type if current symbol is member of a class that has constructors. - fix: Alias a namespace to itself will create infinite loop. - fix: Can't find symbols indirectly included by other files. + - enhancement: Function tip's width changes with editor width. + - fix: '<' / '>' not shown in function tips. Red Panda C++ Version 2.26 - enhancement: Code suggestion for embedded std::vectors. diff --git a/RedPandaIDE/editor.cpp b/RedPandaIDE/editor.cpp index 896e1d44..f10a5866 100644 --- a/RedPandaIDE/editor.cpp +++ b/RedPandaIDE/editor.cpp @@ -1640,6 +1640,7 @@ void Editor::hideEvent(QHideEvent */*event*/) void Editor::resizeEvent(QResizeEvent *event) { QSynedit::QSynEdit::resizeEvent(event); + pMainWindow->functionTip()->setMinWidth(width()*3/4); pMainWindow->functionTip()->hide(); } diff --git a/RedPandaIDE/parser/cppparser.cpp b/RedPandaIDE/parser/cppparser.cpp index 7cc6e741..4dfce160 100644 --- a/RedPandaIDE/parser/cppparser.cpp +++ b/RedPandaIDE/parser/cppparser.cpp @@ -1524,11 +1524,13 @@ PStatement CppParser::addStatement(const PStatement &parent, QChar ch=mTokenizer[i]->text[0]; if (this->isIdentChar(ch)) { QString spaces=(i>argStart)?" ":""; - if (args.length()>0 && isWordChar(args.back())) + if (args.length()>0 && (isWordChar(args.back()) || args.back()=='>')) args+=spaces; word += mTokenizer[i]->text; if (!typeGetted) { - noNameArgs+=spaces+word; + if (noNameArgs.length()>0 && isWordChar(noNameArgs.back())) + noNameArgs+=spaces; + noNameArgs+=word; if (mCppTypeKeywords.contains(word) || !isCppKeyword(word)) typeGetted = true; } else { @@ -1541,6 +1543,7 @@ PStatement CppParser::addStatement(const PStatement &parent, } else if (mTokenizer[i]->text=="::") { if (braceLevel==0) { noNameArgs+= mTokenizer[i]->text; + typeGetted = false; } } else { switch(ch.unicode()) { diff --git a/RedPandaIDE/widgets/functiontooltipwidget.cpp b/RedPandaIDE/widgets/functiontooltipwidget.cpp index 699b5529..9b75899b 100644 --- a/RedPandaIDE/widgets/functiontooltipwidget.cpp +++ b/RedPandaIDE/widgets/functiontooltipwidget.cpp @@ -18,9 +18,11 @@ #include #include +#include FunctionTooltipWidget::FunctionTooltipWidget(QWidget *parent) : - QFrame(parent, Qt::ToolTip | Qt::WindowStaysOnTopHint | Qt::WindowDoesNotAcceptFocus) + QFrame{parent, Qt::ToolTip | Qt::WindowStaysOnTopHint | Qt::WindowDoesNotAcceptFocus}, + mMinWidth{410} { setFocusPolicy(Qt::NoFocus); mInfoLabel = new QLabel(this); @@ -120,12 +122,19 @@ void FunctionTooltipWidget::updateTip() return; PFunctionInfo info = mInfos[mInfoIndex]; QString text = info->returnType+ " " + info->name; + QString originText = text; if (info->params.length()==0) { text += "()"; + originText += "()"; } else { QStringList displayList; + QStringList originList; for (int i=0;iparams.length();i++){ - const QString& param = info->params[i]; + QString param = info->params[i]; + originList.append(param); + + param.replace("<","<"); + param.replace(">",">"); if (mParamIndex == i) { displayList.append(QString("%1").arg(param)); } else { @@ -133,13 +142,14 @@ void FunctionTooltipWidget::updateTip() } } text += "( "+displayList.join(", ") + ") "; + originText += "( "+originList.join(", ") + ") "; } if (mInfos.length()>1) { mTotalLabel->setText(QString("%1/%2").arg(mInfoIndex+1).arg(mInfos.length())); } - int width = mInfoLabel->fontMetrics().horizontalAdvance(text); - if (width > 400) { - mInfoLabel->setMinimumWidth(410); + int width = mInfoLabel->fontMetrics().horizontalAdvance(originText)+10; + if (width > mMinWidth) { + mInfoLabel->setMinimumWidth(mMinWidth); } else { mInfoLabel->setMinimumWidth(width); } @@ -192,6 +202,16 @@ QStringList FunctionTooltipWidget::splitArgs(QString argStr) return result; } +int FunctionTooltipWidget::minWidth() const +{ + return mMinWidth; +} + +void FunctionTooltipWidget::setMinWidth(int newMinWidth) +{ + mMinWidth = newMinWidth; +} + const QString &FunctionTooltipWidget::functionFullName() const { return mFunctioFullName; diff --git a/RedPandaIDE/widgets/functiontooltipwidget.h b/RedPandaIDE/widgets/functiontooltipwidget.h index 3ea5ac09..86f971e2 100644 --- a/RedPandaIDE/widgets/functiontooltipwidget.h +++ b/RedPandaIDE/widgets/functiontooltipwidget.h @@ -54,6 +54,9 @@ public: const QString &functionFullName() const; void setFunctioFullName(const QString &newFunctioFullName); + int minWidth() const; + void setMinWidth(int newMinWidth); + private: QStringList splitArgs(QString args); private: @@ -67,6 +70,7 @@ private: QString mFunctioFullName; QList mInfos; + int mMinWidth; // QWidget interface protected: