- enhancement: use svg icons for class browser

This commit is contained in:
Roy Qu 2021-12-21 07:38:49 +08:00
parent cf4118d911
commit a806fe9389
7 changed files with 111 additions and 90 deletions

View File

@ -5,6 +5,7 @@ Version 0.11.4 For Dev-C++ 7 Beta
- fix: left and right gutter offset settings not correctly saved - fix: left and right gutter offset settings not correctly saved
- enhancement: use svg icons for editor gutter, and they can zoom with font now - enhancement: use svg icons for editor gutter, and they can zoom with font now
- fix: symbol completion for '<>' in the preprocessor line not work - fix: symbol completion for '<>' in the preprocessor line not work
- enhancement: use svg icons for class browser
Version 0.11.3 For Dev-C++ 7 Beta Version 0.11.3 For Dev-C++ 7 Beta
- fix: use pixel size for fonts, to fit different dpi in multiple displays - fix: use pixel size for fonts, to fit different dpi in multiple displays

View File

@ -785,14 +785,12 @@ void Editor::keyPressEvent(QKeyEvent *event)
void Editor::onGutterPaint(QPainter &painter, int aLine, int X, int Y) void Editor::onGutterPaint(QPainter &painter, int aLine, int X, int Y)
{ {
// Get point where to draw marks IconsManager::PIcon icon;
//X := (fText.Gutter.RealGutterWidth(fText.CharWidth) - fText.Gutter.RightOffset) div 2 - 3;
PIcon icon;
if (mActiveBreakpointLine == aLine) { if (mActiveBreakpointLine == aLine) {
icon = pIconsManager->activeBreakpoint(); icon = pIconsManager->getIcon(IconsManager::GUTTER_ACTIVEBREAKPOINT);
} else if (hasBreakpoint(aLine)) { } else if (hasBreakpoint(aLine)) {
icon = pIconsManager->breakpoint(); icon = pIconsManager->getIcon(IconsManager::GUTTER_BREAKPOINT);
} else { } else {
PSyntaxIssueList lst = getSyntaxIssuesAtLine(aLine); PSyntaxIssueList lst = getSyntaxIssuesAtLine(aLine);
if (lst) { if (lst) {
@ -804,12 +802,12 @@ void Editor::onGutterPaint(QPainter &painter, int aLine, int X, int Y)
} }
} }
if (hasError) { if (hasError) {
icon = pIconsManager->syntaxError(); icon = pIconsManager->getIcon(IconsManager::GUTTER_SYNTAX_ERROR);
} else { } else {
icon = pIconsManager->syntaxWarning(); icon = pIconsManager->getIcon(IconsManager::GUTTER_SYNTAX_WARNING);
} }
} else if (hasBookmark(aLine)) { } else if (hasBookmark(aLine)) {
icon = pIconsManager->bookmark(); icon = pIconsManager->getIcon(IconsManager::GUTTER_BOOKMARK);
} }
} }
if (icon) { if (icon) {

View File

@ -463,25 +463,6 @@
<file>images/associations/obj.ico</file> <file>images/associations/obj.ico</file>
<file>images/associations/rc.ico</file> <file>images/associations/rc.ico</file>
<file>images/associations/template.ico</file> <file>images/associations/template.ico</file>
<file>images/classparser/class.ico</file>
<file>images/classparser/define.ico</file>
<file>images/classparser/enum.ico</file>
<file>images/classparser/global.ico</file>
<file>images/classparser/global_method.ico</file>
<file>images/classparser/method_inherited.ico</file>
<file>images/classparser/method_inherited_protected.ico</file>
<file>images/classparser/method_private.ico</file>
<file>images/classparser/method_protected.ico</file>
<file>images/classparser/method_public.ico</file>
<file>images/classparser/namespace.ico</file>
<file>images/classparser/static_method.ico</file>
<file>images/classparser/static_var.ico</file>
<file>images/classparser/type.ico</file>
<file>images/classparser/var_inherited.ico</file>
<file>images/classparser/var_inherited_protected.ico</file>
<file>images/classparser/var_private.ico</file>
<file>images/classparser/var_protected.ico</file>
<file>images/classparser/var_public.ico</file>
<file>images/newlook24/091-openproblemanswer.png</file> <file>images/newlook24/091-openproblemanswer.png</file>
<file>images/newlook24/092-runallproblemcases.png</file> <file>images/newlook24/092-runallproblemcases.png</file>
<file>images/newlook24/093-pause.png</file> <file>images/newlook24/093-pause.png</file>
@ -490,5 +471,24 @@
<file>images/editor/currentline.svg</file> <file>images/editor/currentline.svg</file>
<file>images/editor/syntaxerror.svg</file> <file>images/editor/syntaxerror.svg</file>
<file>images/editor/syntaxwarning.svg</file> <file>images/editor/syntaxwarning.svg</file>
<file>images/classparser/class.svg</file>
<file>images/classparser/define.svg</file>
<file>images/classparser/enum.svg</file>
<file>images/classparser/global.svg</file>
<file>images/classparser/global_method.svg</file>
<file>images/classparser/method_inherited.svg</file>
<file>images/classparser/method_inherited_protected.svg</file>
<file>images/classparser/method_private.svg</file>
<file>images/classparser/method_protected.svg</file>
<file>images/classparser/method_public.svg</file>
<file>images/classparser/namespace.svg</file>
<file>images/classparser/static_method.svg</file>
<file>images/classparser/static_var.svg</file>
<file>images/classparser/type.svg</file>
<file>images/classparser/var_inherited.svg</file>
<file>images/classparser/var_inherited_protected.svg</file>
<file>images/classparser/var_private.svg</file>
<file>images/classparser/var_protected.svg</file>
<file>images/classparser/var_public.svg</file>
</qresource> </qresource>
</RCC> </RCC>

View File

@ -7,51 +7,56 @@ IconsManager* pIconsManager;
IconsManager::IconsManager(QObject *parent) : QObject(parent) IconsManager::IconsManager(QObject *parent) : QObject(parent)
{ {
updateEditorGuttorIcons(24); mDefaultIcon = PIcon();
//updateEditorGuttorIcons(24);
mFolder = std::make_shared<QPixmap>(":/icons/images/newlook24/090-explorer.png"); mFolder = std::make_shared<QPixmap>(":/icons/images/newlook24/090-explorer.png");
} }
void IconsManager::updateEditorGuttorIcons(int size) void IconsManager::updateEditorGuttorIcons(const QString& iconSet,int size)
{ {
mBreakpoint = createSVGIcon(":/icons/images/editor/breakpoint.svg",size,size); QString iconFolder = QString(":/icons/images/%1/").arg(iconSet);
mSyntaxError = createSVGIcon(":/icons/images/editor/syntaxerror.svg",size,size); mIcons.insert(GUTTER_BREAKPOINT, createSVGIcon(iconFolder+"breakpoint.svg",size,size));
mSyntaxWarning = createSVGIcon(":/icons/images/editor/syntaxwarning.svg",size,size); mIcons.insert(GUTTER_SYNTAX_ERROR, createSVGIcon(iconFolder+"syntaxerror.svg",size,size));
mActiveBreakpoint = createSVGIcon(":/icons/images/editor/currentline.svg",size,size); mIcons.insert(GUTTER_SYNTAX_WARNING,createSVGIcon(iconFolder+"syntaxwarning.svg",size,size));
mBookmark = createSVGIcon(":/icons/images/editor/bookmark.svg",size,size); mIcons.insert(GUTTER_ACTIVEBREAKPOINT,createSVGIcon(iconFolder+"currentline.svg",size,size));
mIcons.insert(GUTTER_BOOKMARK, createSVGIcon(iconFolder+"bookmark.svg",size,size));
} }
const PIcon &IconsManager::syntaxError() const void IconsManager::updateParserIcons(const QString &iconSet, int size)
{ {
return mSyntaxError; QString iconFolder = QString(":/icons/images/%1/").arg(iconSet);
mIcons.insert(PARSER_TYPE, createSVGIcon(iconFolder+"type.svg",size,size));
mIcons.insert(PARSER_CLASS, createSVGIcon(iconFolder+"class.svg",size,size));
mIcons.insert(PARSER_NAMESPACE, createSVGIcon(iconFolder+"namespace.svg",size,size));
mIcons.insert(PARSER_DEFINE, createSVGIcon(iconFolder+"define.svg",size,size));
mIcons.insert(PARSER_ENUM, createSVGIcon(iconFolder+"enum.svg",size,size));;
mIcons.insert(PARSER_GLOBAL_METHOD, createSVGIcon(iconFolder+"global_method.svg",size,size));
mIcons.insert(PARSER_INHERITED_PROTECTED_METHOD, createSVGIcon(iconFolder+"method_inherited_protected.svg",size,size));
mIcons.insert(PARSER_INHERITED_METHOD, createSVGIcon(iconFolder+"method_inherited.svg",size,size));
mIcons.insert(PARSER_PROTECTED_METHOD, createSVGIcon(iconFolder+"method_protected.svg",size,size));
mIcons.insert(PARSER_PUBLIC_METHOD, createSVGIcon(iconFolder+"method_public.svg",size,size));
mIcons.insert(PARSER_PRIVATE_METHOD, createSVGIcon(iconFolder+"method_private.svg",size,size));
mIcons.insert(PARSER_GLOBAL_VAR, createSVGIcon(iconFolder+"global.svg",size,size));
mIcons.insert(PARSER_INHERITED_PROTECTD_VAR, createSVGIcon(iconFolder+"var_inherited_protected.svg",size,size));
mIcons.insert(PARSER_INHERITED_VAR, createSVGIcon(iconFolder+"var_inherited.svg",size,size));
mIcons.insert(PARSER_PROTECTED_VAR, createSVGIcon(iconFolder+"var_protected.svg",size,size));
mIcons.insert(PARSER_PUBLIC_VAR, createSVGIcon(iconFolder+"var_public.svg",size,size));
mIcons.insert(PARSER_PRIVATE_VAR, createSVGIcon(iconFolder+"var_private.svg",size,size));
} }
const PIcon &IconsManager::syntaxWarning() const IconsManager::PIcon IconsManager::getIcon(IconName iconName) const
{ {
return mSyntaxWarning; return mIcons.value(iconName, mDefaultIcon);
} }
const PIcon &IconsManager::breakpoint() const const IconsManager::PIcon &IconsManager::folder() const
{
return mBreakpoint;
}
const PIcon &IconsManager::activeBreakpoint() const
{
return mActiveBreakpoint;
}
const PIcon &IconsManager::bookmark() const
{
return mBookmark;
}
const PIcon &IconsManager::folder() const
{ {
return mFolder; return mFolder;
} }
PIcon IconsManager::createSVGIcon(const QString &filename, int width, int height) IconsManager::PIcon IconsManager::createSVGIcon(const QString &filename, int width, int height)
{ {
QSvgRenderer renderer(filename); QSvgRenderer renderer(filename);
PIcon icon = std::make_shared<QPixmap>(width,height); PIcon icon = std::make_shared<QPixmap>(width,height);

View File

@ -1,38 +1,53 @@
#ifndef ICONSMANAGER_H #ifndef ICONSMANAGER_H
#define ICONSMANAGER_H #define ICONSMANAGER_H
#include <QMap>
#include <QObject> #include <QObject>
#include <QPixmap> #include <QPixmap>
#include <memory> #include <memory>
using PIcon = std::shared_ptr<QPixmap>;
class IconsManager : public QObject class IconsManager : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
using PIcon = std::shared_ptr<QPixmap>;
enum IconName {
GUTTER_SYNTAX_ERROR,
GUTTER_SYNTAX_WARNING,
GUTTER_BREAKPOINT,
GUTTER_ACTIVEBREAKPOINT,
GUTTER_BOOKMARK,
PARSER_TYPE, //":/icons/images/classparser/type.svg"
PARSER_CLASS, //":/icons/images/classparser/class.svg"
PARSER_NAMESPACE, //":/icons/images/classparser/namespace.svg"
PARSER_DEFINE, // ":/icons/images/classparser/define.svg"
PARSER_ENUM, // ":/icons/images/classparser/enum.svg";
PARSER_GLOBAL_METHOD, // ":/icons/images/classparser/global_method.svg"
PARSER_INHERITED_PROTECTED_METHOD, //":/icons/images/classparser/method_inherited_protected.svg"
PARSER_INHERITED_METHOD, // ":/icons/images/classparser/method_inherited.svg"
PARSER_PROTECTED_METHOD, // ":/icons/images/classparser/method_protected.svg"
PARSER_PUBLIC_METHOD, //":/icons/images/classparser/method_public.svg")
PARSER_PRIVATE_METHOD, //":/icons/images/classparser/method_private.svg"
PARSER_GLOBAL_VAR, // ":/icons/images/classparser/global.svg"
PARSER_INHERITED_PROTECTD_VAR, //":/icons/images/classparser/var_inherited_protected.svg"
PARSER_INHERITED_VAR, //":/icons/images/classparser/var_inherited.svg"
PARSER_PROTECTED_VAR, //":/icons/images/classparser/var_protected.svg"
PARSER_PUBLIC_VAR, //":/icons/images/classparser/var_public.svg"
PARSER_PRIVATE_VAR //":/icons/images/classparser/var_private.svg"
};
explicit IconsManager(QObject *parent = nullptr); explicit IconsManager(QObject *parent = nullptr);
void updateEditorGuttorIcons(int size); void updateEditorGuttorIcons(const QString& iconSet, int size);
void updateParserIcons(const QString& iconSet, int size);
const PIcon &syntaxError() const; PIcon getIcon(IconName iconName) const;
const PIcon &syntaxWarning() const;
const PIcon &breakpoint() const;
const PIcon &activeBreakpoint() const;
const PIcon &bookmark() const;
const PIcon &folder() const; const PIcon &folder() const;
PIcon createSVGIcon(const QString& filename, int width, int height); PIcon createSVGIcon(const QString& filename, int width, int height);
private: private:
PIcon mSyntaxError; QMap<IconName,PIcon> mIcons;
PIcon mSyntaxWarning; PIcon mDefaultIcon;
PIcon mBreakpoint;
PIcon mActiveBreakpoint;
PIcon mBookmark;
PIcon mFolder; PIcon mFolder;
}; };

View File

@ -321,7 +321,7 @@ void MainWindow::updateForEncodingInfo() {
void MainWindow::updateEditorSettings() void MainWindow::updateEditorSettings()
{ {
pIconsManager->updateEditorGuttorIcons(pointToPixel(pSettings->editor().fontSize())); pIconsManager->updateEditorGuttorIcons("editor",pointToPixel(pSettings->editor().fontSize()));
mEditorList->applySettings(); mEditorList->applySettings();
} }
@ -546,6 +546,7 @@ void MainWindow::applySettings()
font.setStyleStrategy(QFont::PreferAntialias); font.setStyleStrategy(QFont::PreferAntialias);
qApp->setFont(font); qApp->setFont(font);
this->setFont(font); this->setFont(font);
pIconsManager->updateParserIcons("classparser",pointToPixel(pSettings->environment().interfaceFontSize()));
QFont caseEditorFont(pSettings->executor().caseEditorFontName()); QFont caseEditorFont(pSettings->executor().caseEditorFontName());
caseEditorFont.setPixelSize(pointToPixel(pSettings->executor().caseEditorFontSize())); caseEditorFont.setPixelSize(pointToPixel(pSettings->executor().caseEditorFontSize()));

View File

@ -7,6 +7,7 @@
#include "../settings.h" #include "../settings.h"
#include "../colorscheme.h" #include "../colorscheme.h"
#include "../utils.h" #include "../utils.h"
#include "../iconsmanager.h"
ClassBrowserModel::ClassBrowserModel(QObject *parent):QAbstractItemModel(parent) ClassBrowserModel::ClassBrowserModel(QObject *parent):QAbstractItemModel(parent)
{ {
@ -159,57 +160,57 @@ QVariant ClassBrowserModel::data(const QModelIndex &index, int role) const
} }
switch (kind) { switch (kind) {
case StatementKind::skTypedef: case StatementKind::skTypedef:
return QIcon(":/icons/images/classparser/type.ico"); return *(pIconsManager->getIcon(IconsManager::PARSER_TYPE));
case StatementKind::skClass: case StatementKind::skClass:
return QIcon(":/icons/images/classparser/class.ico"); return *(pIconsManager->getIcon(IconsManager::PARSER_CLASS));
case StatementKind::skNamespace: case StatementKind::skNamespace:
case StatementKind::skNamespaceAlias: case StatementKind::skNamespaceAlias:
return QIcon(":/icons/images/classparser/namespace.ico"); return *(pIconsManager->getIcon(IconsManager::PARSER_NAMESPACE));
case StatementKind::skPreprocessor: case StatementKind::skPreprocessor:
return QIcon(":/icons/images/classparser/define.ico"); return *(pIconsManager->getIcon(IconsManager::PARSER_DEFINE));
case StatementKind::skEnumClassType: case StatementKind::skEnumClassType:
case StatementKind::skEnumType: case StatementKind::skEnumType:
case StatementKind::skEnum: case StatementKind::skEnum:
return QIcon(":/icons/images/classparser/enum.ico"); return *(pIconsManager->getIcon(IconsManager::PARSER_ENUM));
case StatementKind::skFunction: case StatementKind::skFunction:
case StatementKind::skConstructor: case StatementKind::skConstructor:
case StatementKind::skDestructor: case StatementKind::skDestructor:
if (statement->scope == StatementScope::ssGlobal) if (statement->scope == StatementScope::ssGlobal)
return QIcon(":/icons/images/classparser/global_method.ico"); return *(pIconsManager->getIcon(IconsManager::PARSER_GLOBAL_METHOD));
if (statement->isInherited) { if (statement->isInherited) {
if (statement->classScope == StatementClassScope::scsProtected) { if (statement->classScope == StatementClassScope::scsProtected) {
return QIcon(":/icons/images/classparser/method_inherited_protected.ico"); return *(pIconsManager->getIcon(IconsManager::PARSER_INHERITED_PROTECTED_METHOD));
} else if (statement->classScope == StatementClassScope::scsPublic) { } else if (statement->classScope == StatementClassScope::scsPublic) {
return QIcon(":/icons/images/classparser/method_inherited.ico"); return *(pIconsManager->getIcon(IconsManager::PARSER_INHERITED_METHOD));
} }
} else { } else {
if (statement->classScope == StatementClassScope::scsProtected) { if (statement->classScope == StatementClassScope::scsProtected) {
return QIcon(":/icons/images/classparser/method_protected.ico"); return *(pIconsManager->getIcon(IconsManager::PARSER_PROTECTED_METHOD));
} else if (statement->classScope == StatementClassScope::scsPublic) { } else if (statement->classScope == StatementClassScope::scsPublic) {
return QIcon(":/icons/images/classparser/method_public.ico"); return *(pIconsManager->getIcon(IconsManager::PARSER_PUBLIC_METHOD));
} else { } else {
return QIcon(":/icons/images/classparser/method_private.ico"); return *(pIconsManager->getIcon(IconsManager::PARSER_PRIVATE_METHOD));
} }
} }
break; break;
case StatementKind::skGlobalVariable: case StatementKind::skGlobalVariable:
return QIcon(":/icons/images/classparser/global.ico"); return *(pIconsManager->getIcon(IconsManager::PARSER_GLOBAL_VAR));
case StatementKind::skVariable: case StatementKind::skVariable:
// if (statement->scope == StatementScope::ssGlobal) // if (statement->scope == StatementScope::ssGlobal)
// return QIcon(":/icons/images/classparser/global.ico"); // return QIcon(":/icons/images/classparser/global.ico");
if (statement->isInherited) { if (statement->isInherited) {
if (statement->classScope == StatementClassScope::scsProtected) { if (statement->classScope == StatementClassScope::scsProtected) {
return QIcon(":/icons/images/classparser/var_inherited_protected.ico"); return *(pIconsManager->getIcon(IconsManager::PARSER_INHERITED_PROTECTD_VAR));
} else if (statement->classScope == StatementClassScope::scsPublic) { } else if (statement->classScope == StatementClassScope::scsPublic) {
return QIcon(":/icons/images/classparser/var_inherited.ico"); return *(pIconsManager->getIcon(IconsManager::PARSER_INHERITED_VAR));
} }
} else { } else {
if (statement->classScope == StatementClassScope::scsProtected) { if (statement->classScope == StatementClassScope::scsProtected) {
return QIcon(":/icons/images/classparser/var_protected.ico"); return *(pIconsManager->getIcon(IconsManager::PARSER_PROTECTED_VAR));
} else if (statement->classScope == StatementClassScope::scsPublic) { } else if (statement->classScope == StatementClassScope::scsPublic) {
return QIcon(":/icons/images/classparser/var_public.ico"); return *(pIconsManager->getIcon(IconsManager::PARSER_PUBLIC_VAR));
} else { } else {
return QIcon(":/icons/images/classparser/var_private.ico"); return *(pIconsManager->getIcon(IconsManager::PARSER_PRIVATE_VAR));
} }
} }
break; break;