- function tips done

This commit is contained in:
royqh1979@gmail.com 2021-09-25 21:34:10 +08:00
parent 168cb49218
commit dc807f527c
9 changed files with 682 additions and 488 deletions

View File

@ -1,4 +1,5 @@
Version 0.2
- enhancement: function tips
- enhancement: project support
- enhancement: paint color editor use system palette's disabled group color
- fix: add watch not work when there's no editor openned;

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@ -464,6 +464,7 @@ void Editor::focusOutEvent(QFocusEvent *event)
pMainWindow->updateEditorActions();
pMainWindow->updateStatusbarForLineCol();
pMainWindow->updateForStatusbarModeInfo();
pMainWindow->functionTip()->hide();
}
void Editor::keyPressEvent(QKeyEvent *event)
@ -1784,6 +1785,7 @@ void Editor::showCompletion(bool autoComplete)
});
mCompletionPopup->setParser(mParser);
mCompletionPopup->setUseCppKeyword(mUseCppSyntax);
pMainWindow->functionTip()->hide();
mCompletionPopup->show();
// Scan the current function body
@ -1842,6 +1844,7 @@ void Editor::showHeaderCompletion(bool autoComplete)
if (word.lastIndexOf('"')>0 || word.lastIndexOf('>')>0)
return;
pMainWindow->functionTip()->hide();
mHeaderCompletionPopup->show();
mHeaderCompletionPopup->setSearchLocal(word.startsWith('"'));
word.remove(0,1);
@ -2246,6 +2249,10 @@ QString Editor::getHintForFunction(const PStatement &statement, const PStatement
void Editor::updateFunctionTip()
{
if (pMainWindow->completionPopup()->isVisible()) {
pMainWindow->functionTip()->hide();
return;
}
BufferCoord caretPos = caretXY();
ContentsCoord curPos = fromBufferCoord(caretPos);
ContentsCoord cursorPos = curPos;
@ -2257,6 +2264,7 @@ void Editor::updateFunctionTip()
// Stopping characters...
QChar ch = *curPos;
if (ch == '\0' || ch == ';') {
pMainWindow->functionTip()->hide();
return;
// Opening brace, increase count
}
@ -2299,14 +2307,17 @@ void Editor::updateFunctionTip()
curPos += 1;
}
//qDebug()<<"first pass:"<<nBraces<<" "<<curPos.line()<<":"<<curPos.ch()<<" - '"<<*curPos<<"'";
// If we couldn't find the closing brace or reached the FMaxScanLength...
if (nBraces!=-1) {
pMainWindow->functionTip()->hide();
return;
}
ContentsCoord FFunctionEnd = curPos;
int paramPos = 0;
bool paramPosFounded = false;
// We've stopped at the ending ), start walking backwards )*here* with nBraces = -1
for (int i=0;i<FMaxScanLength;i++) {
QChar ch = *curPos;
@ -2316,8 +2327,10 @@ void Editor::updateFunctionTip()
curPos -= 1;
ch = *(curPos);
prevCh = *(curPos-1);
if (prevCh == '\0')
if (prevCh == '\0') {
pMainWindow->functionTip()->hide();
return;
}
if (prevCh == '/' && ch == '*' ) {
curPos -= 1;
break;
@ -2331,8 +2344,9 @@ void Editor::updateFunctionTip()
break;;
} else if (ch == ',') {
if (nBraces == 0) {
if (curPos <= cursorPos) {
if (curPos <= cursorPos && !paramPosFounded) {
paramPos = nCommas;
paramPosFounded = true;
}
nCommas++;
}
@ -2341,10 +2355,13 @@ void Editor::updateFunctionTip()
if (curPos.atStart())
break;
}
paramPos = nCommas - paramPos;
if (paramPosFounded)
paramPos = nCommas - paramPos;
//qDebug()<<"second pass:"<<nBraces<<","<<nCommas<<","<<paramPos<<" "<<curPos.line()<<":"<<curPos.ch()<<" - '"<<*curPos<<"'";
// If we couldn't find the closing brace or reached the FMaxScanLength...
if (nBraces!=-1) {
pMainWindow->functionTip()->hide();
return;
}
@ -2362,22 +2379,31 @@ void Editor::updateFunctionTip()
}
ContentsCoord prevPos = curPos-1;
if (prevPos.atStart())
if (prevPos.atStart()) {
pMainWindow->functionTip()->hide();
return;
}
// Get the name of the function we're about to show
BufferCoord FuncStartXY = prevPos.toBufferCoord();
QString token;
PSynHighlighterAttribute HLAttr;
if (!getHighlighterAttriAtRowCol(FuncStartXY,token,HLAttr)) {
pMainWindow->functionTip()->hide();
return;
}
if (HLAttr->name()!=SYNS_AttrIdentifier)
if (HLAttr->name()!=SYNS_AttrIdentifier) {
pMainWindow->functionTip()->hide();
return;
}
BufferCoord pWordBegin, pWordEnd;
QString s = getWordAtPosition(this, FuncStartXY, pWordBegin,pWordEnd, WordPurpose::wpInformation);
// qDebug()<<QString("find word at %1:%2 - '%3'")
// .arg(FuncStartXY.Line)
// .arg(FuncStartXY.Char)
// .arg(s);
// Don't bother scanning the database when there's no identifier to scan for
// Only do the cumbersome list filling when showing a new tooltip...
@ -2401,8 +2427,13 @@ void Editor::updateFunctionTip()
// If we can't find it in our database, hide
if (pMainWindow->functionTip()->tipCount()<=0) {
pMainWindow->functionTip()->hide();
return;
}
// Position it at the top of the next line
QPoint p = rowColumnToPixels(displayXY());
p+=QPoint(0,textHeight()+2);
pMainWindow->functionTip()->move(mapToGlobal(p));
pMainWindow->functionTip()->setFunctioFullName(s);
pMainWindow->functionTip()->guessFunction(nCommas);
@ -2410,32 +2441,6 @@ void Editor::updateFunctionTip()
paramPos
);
pMainWindow->functionTip()->show();
//// // get the current token position in the text
//// // this is where the prototype name usually starts
//// FTokenPos := CurPos - Length(S);
//// Search for the best possible overload match according to comma count
//if (shoFindBestMatchingToolTip in FOptions) then
// // Only do so when the user didn't select his own
// if not FCustomSelIndex then
// S := FindClosestToolTip(S, nCommas);
//// Select the current one
//if (FSelIndex < FToolTips.Count) then
// S := FToolTips.Strings[FSelIndex];
//// set the hint caption
//Caption := Trim(S);
//// we use the LookupEditor to get the highlighter-attributes
//// from. check the DrawAdvanced method!
//FLookupEditor.Text := Caption;
//FLookupEditor.Highlighter := FEditor.Highlighter;
//// get the index of the current argument (where the cursor is)
//FCurParamIndex := GetCommaIndex(P, FFunctionStart + 1, CaretPos - 1);
//RethinkCoordAndActivate;
}
void Editor::setInProject(bool newInProject)

View File

@ -926,7 +926,7 @@
<widget class="QStatusBar" name="statusbar"/>
<widget class="QToolBar" name="toolbarMain">
<property name="windowTitle">
<string>toolBar</string>
<string>Main</string>
</property>
<property name="iconSize">
<size>
@ -947,7 +947,7 @@
</widget>
<widget class="QToolBar" name="toolbarCode">
<property name="windowTitle">
<string>toolBar</string>
<string>Code</string>
</property>
<attribute name="toolBarArea">
<enum>TopToolBarArea</enum>
@ -962,7 +962,7 @@
</widget>
<widget class="QToolBar" name="toolbarCompile">
<property name="windowTitle">
<string>toolBar</string>
<string>Compile</string>
</property>
<property name="iconSize">
<size>
@ -983,7 +983,7 @@
</widget>
<widget class="QToolBar" name="toolbarDebug">
<property name="windowTitle">
<string>toolBar</string>
<string>Debug</string>
</property>
<property name="iconSize">
<size>
@ -1008,7 +1008,7 @@
</widget>
<widget class="QToolBar" name="toolbarCompilerSet">
<property name="windowTitle">
<string>toolBar_2</string>
<string>Compiler Set</string>
</property>
<property name="iconSize">
<size>

View File

@ -594,7 +594,6 @@ void CppTokenizer::advance()
mCurrent++;
break;
case '\\':
if (isLineChar(*(mCurrent + 1)))
skipSplitLine();
else

View File

@ -204,9 +204,10 @@ QChar ContentsCoord::operator*() const
return QChar('\0');
}
QString s = mEdit->lines()->getString(mLine-1);
if (mChar > s.length()+1 ) {
if (mChar >= s.length()+1 ) {
return QChar('\n');
}
//qDebug()<<mLine<<":"<<mChar<<" '"<<s<<"'";
return s[mChar-1];
}

View File

@ -1,10 +1,11 @@
#include "functiontooltipwidget.h"
#include <QHBoxLayout>
#include <QPushButton>
FunctionTooltipWidget::FunctionTooltipWidget(QWidget *parent) : QWidget(parent)
FunctionTooltipWidget::FunctionTooltipWidget(QWidget *parent) :
QFrame(parent, Qt::ToolTip | Qt::WindowStaysOnTopHint | Qt::WindowDoesNotAcceptFocus)
{
setWindowFlags(Qt::Popup);
setFocusPolicy(Qt::NoFocus);
mInfoLabel = new QLabel(this);
mInfoLabel->setWordWrap(true);
@ -21,12 +22,17 @@ FunctionTooltipWidget::FunctionTooltipWidget(QWidget *parent) : QWidget(parent)
mDownButton->setFixedSize(16, 16);
mDownButton->setAutoRaise(true);
this->setLayout(new QHBoxLayout());
layout()->setContentsMargins(0,0,0,0);
layout()->setSpacing(0);
layout()->addWidget(mUpButton);
layout()->addWidget(mTotalLabel);
layout()->addWidget(mDownButton);
layout()->addWidget(mInfoLabel);
connect(mUpButton,&QPushButton::clicked,
this,&FunctionTooltipWidget::previousTip);
connect(mDownButton,&QPushButton::clicked,
this,&FunctionTooltipWidget::nextTip);
}
void FunctionTooltipWidget::addTip(const QString &name, const QString& fullname,
@ -102,11 +108,23 @@ void FunctionTooltipWidget::updateTip()
}
text += "( "+displayList.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);
} else {
mInfoLabel->setMinimumWidth(width);
}
mInfoLabel->setText(text);
}
void FunctionTooltipWidget::guessFunction(int commas)
{
if (mInfoIndex>=0 && mInfoIndex<mInfos.count()
&& mInfos[mInfoIndex]->params.count()>commas)
return;
for (int i=0;i<mInfos.size();i++) {
if (mInfos[i]->params.count()>commas) {
mInfoIndex = i;
@ -141,6 +159,8 @@ QStringList FunctionTooltipWidget::splitArgs(QString argStr)
QString s = argStr.mid(paramStart,i-paramStart);
s=s.trimmed();
if (!s.isEmpty()) {
if (s.endsWith(')'))
s.truncate(s.length()-1);
result.append(s);
}
return result;
@ -164,6 +184,7 @@ int FunctionTooltipWidget::paramIndex() const
void FunctionTooltipWidget::setParamIndex(int newParamIndex)
{
mParamIndex = newParamIndex;
updateTip();
}
void FunctionTooltipWidget::closeEvent(QCloseEvent *)
@ -179,7 +200,8 @@ void FunctionTooltipWidget::showEvent(QShowEvent *)
updateTip();
}
void FunctionTooltipWidget::hideEvent(QHideEvent *event)
void FunctionTooltipWidget::hideEvent(QHideEvent *)
{
mInfos.clear();
mFunctioFullName = "";
}

View File

@ -14,7 +14,7 @@ struct FunctionInfo {
using PFunctionInfo = std::shared_ptr<FunctionInfo>;
class FunctionTooltipWidget : public QWidget
class FunctionTooltipWidget : public QFrame
{
Q_OBJECT
public: