- enhancement: options for editor tooltips

This commit is contained in:
royqh1979@gmail.com 2021-09-21 20:36:43 +08:00
parent f59d67e5f0
commit 95cb5ea52e
11 changed files with 273 additions and 40 deletions

View File

@ -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
- enhancement: options for editor tooltips

View File

@ -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 \

View File

@ -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<QHoverEvent *>(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,10 +800,12 @@ bool Editor::event(QEvent *event)
switch (reason) {
case TipType::Preprocessor:
if (isIncludeLine) {
if (pSettings->editor().enableHeaderToolTips())
hint = getFileHint(s);
} else if (//devEditor.ParserHints and
!mCompletionPopup->isVisible()
&& !mHeaderCompletionPopup->isVisible()) {
if (pSettings->editor().enableIdentifierToolTips())
hint = getParserHint(s,p.Line);
}
break;
@ -810,14 +813,16 @@ bool Editor::event(QEvent *event)
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:
if (pSettings->editor().enableIssueToolTips())
hint = getErrorHint(pError);
}
// qDebug()<<"hint:"<<hint;

View File

@ -470,6 +470,66 @@ void Settings::Editor::setRainbowParenthesis(bool newRainbowParenthesis)
mRainbowParenthesis = newRainbowParenthesis;
}
bool Editor::showFunctionTips() const
{
return mShowFunctionTips;
}
void Editor::setShowFunctionTips(bool newShowFunctionTips)
{
mShowFunctionTips = newShowFunctionTips;
}
bool Editor::enableTooltips() const
{
return mEnableTooltips;
}
void Editor::setEnableTooltips(bool newEnableTooltips)
{
mEnableTooltips = newEnableTooltips;
}
bool Editor::enableDebugTooltips() const
{
return mEnableDebugTooltips;
}
void Editor::setEnableDebugTooltips(bool newEnableDebugTooltips)
{
mEnableDebugTooltips = newEnableDebugTooltips;
}
bool Editor::enableIdentifierToolTips() const
{
return mEnableIdentifierToolTips;
}
void Editor::setEnableIdentifierToolTips(bool newEnableIdentifierToolTips)
{
mEnableIdentifierToolTips = newEnableIdentifierToolTips;
}
bool Editor::enableHeaderToolTips() const
{
return mEnableHeaderToolTips;
}
void Editor::setEnableHeaderToolTips(bool newEnableHeaderToolTips)
{
mEnableHeaderToolTips = newEnableHeaderToolTips;
}
bool Editor::enableIssueToolTips() const
{
return mEnableIssueToolTips;
}
void Editor::setEnableIssueToolTips(bool newEnableIssueToolTips)
{
mEnableIssueToolTips = newEnableIssueToolTips;
}
int Settings::Editor::rightEdgeWidth() const
{
return mRightEdgeWidth;
@ -976,6 +1036,14 @@ void Settings::Editor::doSave()
saveValue("readonly_system_header",mReadOnlySytemHeader);
saveValue("auto_load_last_files",mAutoLoadLastFiles);
saveValue("default_file_cpp",mDefaultFileCpp);
//tooltips
saveValue("enable_tooltips",mEnableTooltips);
saveValue("enable_debug_tooltips",mEnableDebugTooltips);
saveValue("enable_identifier_tooltips",mEnableIdentifierToolTips);
saveValue("enable_header_tooltips",mEnableHeaderToolTips);
saveValue("enable_issue_tooltips",mEnableIssueToolTips);
saveValue("show_function_tips",mShowFunctionTips);
}
void Settings::Editor::doLoad()
@ -1078,6 +1146,14 @@ void Settings::Editor::doLoad()
mReadOnlySytemHeader = boolValue("readonly_system_header",true);
mAutoLoadLastFiles = boolValue("auto_load_last_files",true);
mDefaultFileCpp = boolValue("default_file_cpp",true);
//tooltips
mEnableTooltips = boolValue("enable_tooltips",true);
mEnableDebugTooltips = boolValue("enable_debug_tooltips",true);
mEnableIdentifierToolTips = boolValue("enable_identifier_tooltips",true);
mEnableHeaderToolTips = boolValue("enable_header_tooltips", true);
mEnableIssueToolTips = boolValue("enable_issue_tooltips", true);
mShowFunctionTips = boolValue("show_function_tips",true);
}
SynEditCaretType Settings::Editor::caretForOverwrite() const

View File

@ -305,6 +305,20 @@ public:
bool rainbowParenthesis() const;
void setRainbowParenthesis(bool newRainbowParenthesis);
bool enableTooltips() const;
void setEnableTooltips(bool newEnableTooltips);
bool enableDebugTooltips() const;
void setEnableDebugTooltips(bool newEnableDebugTooltips);
bool enableIdentifierToolTips() const;
void setEnableIdentifierToolTips(bool newEnableIdentifierToolTips);
bool enableHeaderToolTips() const;
void setEnableHeaderToolTips(bool newEnableHeaderToolTips);
bool enableIssueToolTips() const;
void setEnableIssueToolTips(bool newEnableIssueToolTips);
bool showFunctionTips() const;
void setShowFunctionTips(bool newShowFunctionTips);
private:
//General
// indents
@ -403,6 +417,14 @@ public:
bool mAutoLoadLastFiles;
bool mDefaultFileCpp;
//hints tooltip
bool mEnableTooltips;
bool mEnableDebugTooltips;
bool mEnableIdentifierToolTips;
bool mEnableHeaderToolTips;
bool mEnableIssueToolTips;
bool mShowFunctionTips;
// _Base interface
protected:
void doSave() override;

View File

@ -134,19 +134,6 @@
</layout>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>

View File

@ -14,15 +14,15 @@
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="1">
<spacer name="horizontalSpacer">
<item row="1" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
@ -53,19 +53,6 @@
</layout>
</widget>
</item>
<item row="1" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<resources/>

View File

@ -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();
}

View File

@ -0,0 +1,28 @@
#ifndef EDITORTOOLTIPSWIDGET_H
#define EDITORTOOLTIPSWIDGET_H
#include <QWidget>
#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

View File

@ -0,0 +1,81 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>EditorTooltipsWidget</class>
<widget class="QWidget" name="EditorTooltipsWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>637</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QCheckBox" name="chkShowFunctionTips">
<property name="text">
<string>Show function tips</string>
</property>
</widget>
</item>
<item>
<widget class="QGroupBox" name="grpEnableTooltips">
<property name="title">
<string>Enable mouse hover tooltips</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QCheckBox" name="chkIssueTooltips">
<property name="text">
<string>Show syntax issue tooltips</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="chkHeaderTooltips">
<property name="text">
<string>Show full header filename tooltips</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="chkIdentifierTooltips">
<property name="text">
<string>Show identifier definition tooltips</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="chkDebugTooltips">
<property name="text">
<string>Show expression value tooltips when debugging</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -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);