From 95cb5ea52e0a133558a2b62cf15149ba25506142 Mon Sep 17 00:00:00 2001 From: "royqh1979@gmail.com" Date: Tue, 21 Sep 2021 20:36:43 +0800 Subject: [PATCH] - enhancement: options for editor tooltips --- NEWS.md | 4 +- RedPandaIDE/RedPandaIDE.pro | 3 + RedPandaIDE/editor.cpp | 21 +++-- RedPandaIDE/settings.cpp | 76 +++++++++++++++++ RedPandaIDE/settings.h | 22 +++++ .../editorsymbolcompletionwidget.ui | 13 --- .../settingsdialog/editorsyntaxcheckwidget.ui | 23 ++---- .../settingsdialog/editortooltipswidget.cpp | 37 +++++++++ .../settingsdialog/editortooltipswidget.h | 28 +++++++ .../settingsdialog/editortooltipswidget.ui | 81 +++++++++++++++++++ RedPandaIDE/settingsdialog/settingsdialog.cpp | 5 ++ 11 files changed, 273 insertions(+), 40 deletions(-) create mode 100644 RedPandaIDE/settingsdialog/editortooltipswidget.cpp create mode 100644 RedPandaIDE/settingsdialog/editortooltipswidget.h create mode 100644 RedPandaIDE/settingsdialog/editortooltipswidget.ui diff --git a/NEWS.md b/NEWS.md index e4fcce41..ea164dfd 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,8 @@ Version 0.2 + - 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; - enhancement: rainbow parenthesis - enhancement: run executable with parameters - - add: widget for function tips \ No newline at end of file + - add: widget for function tips + - enhancement: options for editor tooltips \ No newline at end of file diff --git a/RedPandaIDE/RedPandaIDE.pro b/RedPandaIDE/RedPandaIDE.pro index 7db73e97..40fc560d 100644 --- a/RedPandaIDE/RedPandaIDE.pro +++ b/RedPandaIDE/RedPandaIDE.pro @@ -44,6 +44,7 @@ SOURCES += \ settingsdialog/editorautosavewidget.cpp \ settingsdialog/editorcodecompletionwidget.cpp \ settingsdialog/editormiscwidget.cpp \ + settingsdialog/editortooltipswidget.cpp \ settingsdialog/formattergeneralwidget.cpp \ settingsdialog/projectcompileparamaterswidget.cpp \ settingsdialog/projectcompilerwidget.cpp \ @@ -141,6 +142,7 @@ HEADERS += \ settingsdialog/editorautosavewidget.h \ settingsdialog/editorcodecompletionwidget.h \ settingsdialog/editormiscwidget.h \ + settingsdialog/editortooltipswidget.h \ settingsdialog/formattergeneralwidget.h \ settingsdialog/projectcompileparamaterswidget.h \ settingsdialog/projectcompilerwidget.h \ @@ -212,6 +214,7 @@ FORMS += \ settingsdialog/editorautosavewidget.ui \ settingsdialog/editorcodecompletionwidget.ui \ settingsdialog/editormiscwidget.ui \ + settingsdialog/editortooltipswidget.ui \ settingsdialog/formattergeneralwidget.ui \ settingsdialog/projectcompileparamaterswidget.ui \ settingsdialog/projectcompilerwidget.ui \ diff --git a/RedPandaIDE/editor.cpp b/RedPandaIDE/editor.cpp index ee804a66..03168ce4 100644 --- a/RedPandaIDE/editor.cpp +++ b/RedPandaIDE/editor.cpp @@ -722,7 +722,9 @@ void Editor::onPreparePaintHighlightToken(int line, int aChar, const QString &to bool Editor::event(QEvent *event) { - if (event->type() == QEvent::HoverEnter || event->type() == QEvent::HoverMove) { + if ((event->type() == QEvent::HoverEnter || event->type() == QEvent::HoverMove) + && pSettings->editor().enableTooltips() + ) { QHoverEvent *helpEvent = static_cast(event); BufferCoord p; TipType reason = getTipType(helpEvent->pos(),p); @@ -731,8 +733,7 @@ bool Editor::event(QEvent *event) if (reason == TipType::Error) { pError = getSyntaxIssueAtPosition(p); } else if (pointToLine(helpEvent->pos(),line)) { - //it's on gutter - //see if its error; + //issue tips is prefered PSyntaxIssueList issues = getSyntaxIssuesAtLine(line); if (issues && !issues->isEmpty()) { reason = TipType::Error; @@ -799,26 +800,30 @@ bool Editor::event(QEvent *event) switch (reason) { case TipType::Preprocessor: if (isIncludeLine) { - hint = getFileHint(s); + if (pSettings->editor().enableHeaderToolTips()) + hint = getFileHint(s); } else if (//devEditor.ParserHints and !mCompletionPopup->isVisible() && !mHeaderCompletionPopup->isVisible()) { - hint = getParserHint(s,p.Line); + if (pSettings->editor().enableIdentifierToolTips()) + hint = getParserHint(s,p.Line); } break; case TipType::Identifier: case TipType::Selection: if (!mCompletionPopup->isVisible() && !mHeaderCompletionPopup->isVisible()) { - if (pMainWindow->debugger()->executing()) { + if (pMainWindow->debugger()->executing() + && (pSettings->editor().enableDebugTooltips())) { showDebugHint(s,p.Line); - } else { //if devEditor.ParserHints { + } else if (pSettings->editor().enableIdentifierToolTips()) { //if devEditor.ParserHints { hint = getParserHint(s, p.Line); } } break; case TipType::Error: - hint = getErrorHint(pError); + if (pSettings->editor().enableIssueToolTips()) + hint = getErrorHint(pError); } // qDebug()<<"hint:"< - - - - Qt::Horizontal - - - - 40 - 20 - - - - diff --git a/RedPandaIDE/settingsdialog/editorsyntaxcheckwidget.ui b/RedPandaIDE/settingsdialog/editorsyntaxcheckwidget.ui index 8d06fdb3..aafa69e9 100644 --- a/RedPandaIDE/settingsdialog/editorsyntaxcheckwidget.ui +++ b/RedPandaIDE/settingsdialog/editorsyntaxcheckwidget.ui @@ -14,15 +14,15 @@ Form - - + + - Qt::Horizontal + Qt::Vertical - 40 - 20 + 20 + 40 @@ -53,19 +53,6 @@ - - - - Qt::Vertical - - - - 20 - 40 - - - - diff --git a/RedPandaIDE/settingsdialog/editortooltipswidget.cpp b/RedPandaIDE/settingsdialog/editortooltipswidget.cpp new file mode 100644 index 00000000..c2fdff44 --- /dev/null +++ b/RedPandaIDE/settingsdialog/editortooltipswidget.cpp @@ -0,0 +1,37 @@ +#include "editortooltipswidget.h" +#include "ui_editortooltipswidget.h" +#include "../settings.h" + +EditorTooltipsWidget::EditorTooltipsWidget(const QString &name, const QString &group, QWidget *parent) : + SettingsWidget(name,group,parent), + ui(new Ui::EditorTooltipsWidget) +{ + ui->setupUi(this); +} + +EditorTooltipsWidget::~EditorTooltipsWidget() +{ + delete ui; +} + +void EditorTooltipsWidget::doLoad() +{ + ui->chkShowFunctionTips->setChecked(pSettings->editor().showFunctionTips()); + ui->grpEnableTooltips->setChecked(pSettings->editor().enableTooltips()); + ui->chkIssueTooltips->setChecked(pSettings->editor().enableIssueToolTips()); + ui->chkIdentifierTooltips->setChecked(pSettings->editor().enableIdentifierToolTips()); + ui->chkHeaderTooltips->setChecked(pSettings->editor().enableHeaderToolTips()); + ui->chkDebugTooltips->setChecked(pSettings->editor().enableDebugTooltips()); + +} + +void EditorTooltipsWidget::doSave() +{ + pSettings->editor().setShowFunctionTips(ui->chkShowFunctionTips->isChecked()); + pSettings->editor().setEnableTooltips(ui->grpEnableTooltips->isChecked()); + pSettings->editor().setEnableIssueToolTips(ui->chkIssueTooltips->isChecked()); + pSettings->editor().setEnableIdentifierToolTips(ui->chkIdentifierTooltips->isChecked()); + pSettings->editor().setEnableHeaderToolTips(ui->chkHeaderTooltips->isChecked()); + pSettings->editor().setEnableDebugTooltips(ui->chkDebugTooltips->isChecked()); + pSettings->editor().save(); +} diff --git a/RedPandaIDE/settingsdialog/editortooltipswidget.h b/RedPandaIDE/settingsdialog/editortooltipswidget.h new file mode 100644 index 00000000..7cdf8bdc --- /dev/null +++ b/RedPandaIDE/settingsdialog/editortooltipswidget.h @@ -0,0 +1,28 @@ +#ifndef EDITORTOOLTIPSWIDGET_H +#define EDITORTOOLTIPSWIDGET_H + +#include +#include "settingswidget.h" + +namespace Ui { +class EditorTooltipsWidget; +} + +class EditorTooltipsWidget : public SettingsWidget +{ + Q_OBJECT + +public: + explicit EditorTooltipsWidget(const QString& name, const QString& group, QWidget *parent = nullptr); + ~EditorTooltipsWidget(); + +private: + Ui::EditorTooltipsWidget *ui; + + // SettingsWidget interface +protected: + void doLoad() override; + void doSave() override; +}; + +#endif // EDITORTOOLTIPSWIDGET_H diff --git a/RedPandaIDE/settingsdialog/editortooltipswidget.ui b/RedPandaIDE/settingsdialog/editortooltipswidget.ui new file mode 100644 index 00000000..5f32703b --- /dev/null +++ b/RedPandaIDE/settingsdialog/editortooltipswidget.ui @@ -0,0 +1,81 @@ + + + EditorTooltipsWidget + + + + 0 + 0 + 637 + 300 + + + + Form + + + + + + Show function tips + + + + + + + Enable mouse hover tooltips + + + true + + + + + + Show syntax issue tooltips + + + + + + + Show full header filename tooltips + + + + + + + Show identifier definition tooltips + + + + + + + Show expression value tooltips when debugging + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + diff --git a/RedPandaIDE/settingsdialog/settingsdialog.cpp b/RedPandaIDE/settingsdialog/settingsdialog.cpp index c8131116..18b0ecc0 100644 --- a/RedPandaIDE/settingsdialog/settingsdialog.cpp +++ b/RedPandaIDE/settingsdialog/settingsdialog.cpp @@ -10,6 +10,7 @@ #include "editorcodecompletionwidget.h" #include "editorsyntaxcheckwidget.h" #include "editorsymbolcompletionwidget.h" +#include "editortooltipswidget.h" #include "editorautosavewidget.h" #include "editormiscwidget.h" #include "environmentappearencewidget.h" @@ -129,6 +130,10 @@ PSettingsDialog SettingsDialog::optionDialog() widget->init(); dialog->addWidget(widget); + widget = new EditorTooltipsWidget(tr("Tooltips"),tr("Editor")); + widget->init(); + dialog->addWidget(widget); + widget = new EditorAutoSaveWidget(tr("Auto save"),tr("Editor")); widget->init(); dialog->addWidget(widget);