- fix: failed to show function tip, when there are parameters having '[' and ']'

- refactor iconmanager
This commit is contained in:
Roy Qu 2022-01-28 19:30:50 +08:00
parent 458b87ea64
commit e58ca80282
5 changed files with 33 additions and 39 deletions

View File

@ -1,5 +1,6 @@
Red Panda C++ Version 0.14.1 Red Panda C++ Version 0.14.1
- enhancement: custom theme - enhancement: custom theme
- fix: failed to show function tip, when there are parameters having '[' and ']'
Red Panda C++ Version 0.14.0 Red Panda C++ Version 0.14.0
- enhancement: custom icon set ( in the configuration folder) - enhancement: custom icon set ( in the configuration folder)

View File

@ -3313,9 +3313,9 @@ void Editor::updateFunctionTip()
} }
} else if (bracketLevel>0) { } else if (bracketLevel>0) {
if (tokens[i]=="[") { if (tokens[i]=="[") {
braceLevel--; bracketLevel--;
} else if (tokens[i]=="]") { } else if (tokens[i]=="]") {
braceLevel++; bracketLevel++;
} }
}else if (parenthesisLevel>0){ }else if (parenthesisLevel>0){
if (tokens[i]==")") { if (tokens[i]==")") {
@ -3345,10 +3345,10 @@ void Editor::updateFunctionTip()
parenthesisLevel++; parenthesisLevel++;
} else if (tokens[i]=="}") { } else if (tokens[i]=="}") {
braceLevel++; braceLevel++;
} else if (tokens[i]=="}") { } else if (tokens[i]=="]") {
bracketLevel++; bracketLevel++;
} else if (tokens[i]==",") { } else if (tokens[i]==",") {
paramsCount++; paramsCount++;
} }
} }
} }

View File

@ -25,19 +25,19 @@
#include <QFile> #include <QFile>
#include <QDir> #include <QDir>
#include "utils.h" #include "utils.h"
#include "settings.h"
IconsManager* pIconsManager; IconsManager* pIconsManager;
IconsManager::IconsManager(QObject *parent) : QObject(parent) IconsManager::IconsManager(QObject *parent) : QObject(parent)
{ {
mDefaultIconPixmap = std::make_shared<QPixmap>(); mDefaultIconPixmap = std::make_shared<QPixmap>();
mIconSetTemplate = "%1/%2/%3/";
} }
void IconsManager::updateEditorGuttorIcons(const QString& iconSet,int size) void IconsManager::updateEditorGuttorIcons(const QString& iconSet,int size)
{ {
QString iconFolder = QString(":/resources/iconsets/%1/editor/").arg(iconSet); QString iconFolder = mIconSetTemplate.arg( iconSetsFolder(),iconSet,"editor");
if (!mIconSetPathTemplate.isEmpty())
iconFolder = mIconSetPathTemplate.arg(iconSet,"editor");
mIconPixmaps.insert(GUTTER_BREAKPOINT, createSVGIcon(iconFolder+"breakpoint.svg",size,size)); mIconPixmaps.insert(GUTTER_BREAKPOINT, createSVGIcon(iconFolder+"breakpoint.svg",size,size));
mIconPixmaps.insert(GUTTER_SYNTAX_ERROR, createSVGIcon(iconFolder+"syntaxerror.svg",size,size)); mIconPixmaps.insert(GUTTER_SYNTAX_ERROR, createSVGIcon(iconFolder+"syntaxerror.svg",size,size));
mIconPixmaps.insert(GUTTER_SYNTAX_WARNING,createSVGIcon(iconFolder+"syntaxwarning.svg",size,size)); mIconPixmaps.insert(GUTTER_SYNTAX_WARNING,createSVGIcon(iconFolder+"syntaxwarning.svg",size,size));
@ -47,9 +47,7 @@ void IconsManager::updateEditorGuttorIcons(const QString& iconSet,int size)
void IconsManager::updateParserIcons(const QString &iconSet, int size) void IconsManager::updateParserIcons(const QString &iconSet, int size)
{ {
QString iconFolder = QString(":/resources/iconsets/%1/classparser/").arg(iconSet); QString iconFolder = mIconSetTemplate.arg( iconSetsFolder(),iconSet,"classparser");
if (!mIconSetPathTemplate.isEmpty())
iconFolder = mIconSetPathTemplate.arg(iconSet,"classparser");
mIconPixmaps.insert(PARSER_TYPE, createSVGIcon(iconFolder+"type.svg",size,size)); mIconPixmaps.insert(PARSER_TYPE, createSVGIcon(iconFolder+"type.svg",size,size));
mIconPixmaps.insert(PARSER_CLASS, createSVGIcon(iconFolder+"class.svg",size,size)); mIconPixmaps.insert(PARSER_CLASS, createSVGIcon(iconFolder+"class.svg",size,size));
mIconPixmaps.insert(PARSER_NAMESPACE, createSVGIcon(iconFolder+"namespace.svg",size,size)); mIconPixmaps.insert(PARSER_NAMESPACE, createSVGIcon(iconFolder+"namespace.svg",size,size));
@ -73,11 +71,9 @@ void IconsManager::updateParserIcons(const QString &iconSet, int size)
} }
void IconsManager::updateActionIcons(const QString iconSet, int size) void IconsManager::updateActionIcons(const QString& iconSet, int size)
{ {
QString iconFolder = QString(":/resources/iconsets/%1/actions/").arg(iconSet); QString iconFolder = mIconSetTemplate.arg( iconSetsFolder(),iconSet,"actions");
if (!mIconSetPathTemplate.isEmpty())
iconFolder = mIconSetPathTemplate.arg(iconSet,"actions");
mActionIconSize = QSize(size,size); mActionIconSize = QSize(size,size);
mIconPixmaps.insert(ACTION_MISC_BACK, createSVGIcon(iconFolder+"00Misc-01Back.svg",size,size)); mIconPixmaps.insert(ACTION_MISC_BACK, createSVGIcon(iconFolder+"00Misc-01Back.svg",size,size));
mIconPixmaps.insert(ACTION_MISC_FORWARD, createSVGIcon(iconFolder+"00Misc-02Forward.svg",size,size)); mIconPixmaps.insert(ACTION_MISC_FORWARD, createSVGIcon(iconFolder+"00Misc-02Forward.svg",size,size));
@ -208,21 +204,11 @@ const QSize &IconsManager::actionIconSize() const
return mActionIconSize; return mActionIconSize;
} }
const QString &IconsManager::iconSetPathTemplate() const
{
return mIconSetPathTemplate;
}
void IconsManager::setIconSetPathTemplate(const QString &newIconSetPathTemplate)
{
mIconSetPathTemplate = newIconSetPathTemplate;
}
void IconsManager::prepareCustomIconSet(const QString &customIconSet) void IconsManager::prepareCustomIconSet(const QString &customIconSet)
{ {
if (QFile(customIconSet).exists()) if (QFile(customIconSet).exists())
return; return;
copyFolder(":/resources/iconsets",customIconSet); copyFolder(pSettings->dirs().data(Settings::Dirs::DataType::IconSet),customIconSet);
} }
QPixmap IconsManager::getPixmapForStatement(PStatement statement) QPixmap IconsManager::getPixmapForStatement(PStatement statement)
@ -270,8 +256,6 @@ QPixmap IconsManager::getPixmapForStatement(PStatement statement)
case StatementKind::skLocalVariable: case StatementKind::skLocalVariable:
return *(pIconsManager->getPixmap(IconsManager::PARSER_LOCAL_VAR)); return *(pIconsManager->getPixmap(IconsManager::PARSER_LOCAL_VAR));
case StatementKind::skVariable: case StatementKind::skVariable:
// if (statement->scope == StatementScope::ssGlobal)
// return QIcon(":/icons/images/classparser/global.ico");
if (statement->isInherited) { if (statement->isInherited) {
if (statement->classScope == StatementClassScope::scsProtected) { if (statement->classScope == StatementClassScope::scsProtected) {
return *(pIconsManager->getPixmap(IconsManager::PARSER_INHERITED_PROTECTD_VAR)); return *(pIconsManager->getPixmap(IconsManager::PARSER_INHERITED_PROTECTD_VAR));
@ -297,3 +281,15 @@ QPixmap IconsManager::getPixmapForStatement(PStatement statement)
} }
return QPixmap(); return QPixmap();
} }
const QString IconsManager::iconSetsFolder() const
{
if (mIconSetsFolder.isEmpty())
return pSettings->dirs().data(Settings::Dirs::DataType::IconSet);
return mIconSetsFolder;
}
void IconsManager::setIconSetsFolder(const QString &newIconSetsFolder)
{
mIconSetsFolder = newIconSetsFolder;
}

View File

@ -151,7 +151,7 @@ public:
void updateEditorGuttorIcons(const QString& iconSet, int size); void updateEditorGuttorIcons(const QString& iconSet, int size);
void updateParserIcons(const QString& iconSet, int size); void updateParserIcons(const QString& iconSet, int size);
void updateActionIcons(const QString iconSet, int size); void updateActionIcons(const QString& iconSet, int size);
PPixmap getPixmap(IconName iconName) const; PPixmap getPixmap(IconName iconName) const;
@ -163,21 +163,21 @@ public:
PPixmap createSVGIcon(const QString& filename, int width, int height); PPixmap createSVGIcon(const QString& filename, int width, int height);
const QSize &actionIconSize() const; const QSize &actionIconSize() const;
const QString &iconSetPathTemplate() const;
void setIconSetPathTemplate(const QString &newIconSetPathTemplate);
void prepareCustomIconSet(const QString &customIconSet); void prepareCustomIconSet(const QString &customIconSet);
QPixmap getPixmapForStatement(PStatement statement); QPixmap getPixmapForStatement(PStatement statement);
const QString iconSetsFolder() const;
void setIconSetsFolder(const QString &newIconSetsFolder);
signals: signals:
void actionIconsUpdated(); void actionIconsUpdated();
private: private:
QMap<IconName,PPixmap> mIconPixmaps; QMap<IconName,PPixmap> mIconPixmaps;
PPixmap mDefaultIconPixmap; PPixmap mDefaultIconPixmap;
QSize mActionIconSize; QSize mActionIconSize;
QString mIconSetPathTemplate; QString mIconSetTemplate;
QString mIconSetsFolder;
}; };
extern IconsManager* pIconsManager; extern IconsManager* pIconsManager;

View File

@ -599,12 +599,9 @@ void MainWindow::applySettings()
p->setFont(font); p->setFont(font);
} }
if (pSettings->environment().useCustomIconSet()) { if (pSettings->environment().useCustomIconSet()) {
QString customIconSetPath = pSettings->dirs().config(Settings::Dirs::DataType::IconSet); QString customIconSetFolder = pSettings->dirs().config(Settings::Dirs::DataType::IconSet);
pIconsManager->prepareCustomIconSet(customIconSetPath); pIconsManager->prepareCustomIconSet(customIconSetFolder);
pIconsManager->setIconSetPathTemplate( pIconsManager->setIconSetsFolder(customIconSetFolder);
includeTrailingPathDelimiter(customIconSetPath)
+"%1/%2/"
);
} }
pIconsManager->updateParserIcons(pSettings->environment().iconSet(),pointToPixel(pSettings->environment().interfaceFontSize())); pIconsManager->updateParserIcons(pSettings->environment().iconSet(),pointToPixel(pSettings->environment().interfaceFontSize()));