fix: icon size in menu size not correct

This commit is contained in:
Roy Qu 2021-12-21 11:57:23 +08:00
parent 283a6db961
commit 1a6e365e42
12 changed files with 291 additions and 21 deletions

View File

@ -128,6 +128,7 @@ SOURCES += \
widgets/headercompletionpopup.cpp \
widgets/issuestable.cpp \
widgets/labelwithmenu.cpp \
widgets/lightfusionstyle.cpp \
widgets/macroinfomodel.cpp \
widgets/newprojectdialog.cpp \
widgets/ojproblempropertywidget.cpp \
@ -254,6 +255,7 @@ HEADERS += \
widgets/headercompletionpopup.h \
widgets/issuestable.h \
widgets/labelwithmenu.h \
widgets/lightfusionstyle.h \
widgets/macroinfomodel.h \
widgets/newprojectdialog.h \
widgets/ojproblempropertywidget.h \

View File

@ -490,5 +490,7 @@
<file>images/classparser/var_private.svg</file>
<file>images/classparser/var_protected.svg</file>
<file>images/classparser/var_public.svg</file>
<file>images/newlook/01File-01New.svg</file>
<file>images/newlook/01File-02Open.svg</file>
</qresource>
</RCC>

View File

@ -2,6 +2,7 @@
#include <QPainter>
#include <QSvgRenderer>
#include <QDebug>
IconsManager* pIconsManager;
@ -16,6 +17,7 @@ IconsManager::IconsManager(QObject *parent) : QObject(parent)
void IconsManager::updateEditorGuttorIcons(const QString& iconSet,int size)
{
QString iconFolder = QString(":/icons/images/%1/").arg(iconSet);
qDebug()<<iconFolder;
mIcons.insert(GUTTER_BREAKPOINT, createSVGIcon(iconFolder+"breakpoint.svg",size,size));
mIcons.insert(GUTTER_SYNTAX_ERROR, createSVGIcon(iconFolder+"syntaxerror.svg",size,size));
mIcons.insert(GUTTER_SYNTAX_WARNING,createSVGIcon(iconFolder+"syntaxwarning.svg",size,size));
@ -46,6 +48,13 @@ void IconsManager::updateParserIcons(const QString &iconSet, int size)
}
void IconsManager::updateActionIcons(const QString iconSet, int size)
{
QString iconFolder = QString(":/icons/images/%1/").arg(iconSet);
mIcons.insert(ACTION_FILE_NEW, createSVGIcon(iconFolder+"01File-01New.svg",size,size));
mIcons.insert(ACTION_FILE_OPEN, createSVGIcon(iconFolder+"01File-02Open.svg",size,size));
}
IconsManager::PIcon IconsManager::getIcon(IconName iconName) const
{
return mIcons.value(iconName, mDefaultIcon);

View File

@ -17,28 +17,43 @@ public:
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"
PARSER_TYPE,
PARSER_CLASS,
PARSER_NAMESPACE,
PARSER_DEFINE,
PARSER_ENUM,
PARSER_GLOBAL_METHOD,
PARSER_INHERITED_PROTECTED_METHOD,
PARSER_INHERITED_METHOD,
PARSER_PROTECTED_METHOD,
PARSER_PUBLIC_METHOD,
PARSER_PRIVATE_METHOD,
PARSER_GLOBAL_VAR,
PARSER_INHERITED_PROTECTD_VAR,
PARSER_INHERITED_VAR,
PARSER_PROTECTED_VAR,
PARSER_PUBLIC_VAR,
PARSER_PRIVATE_VAR,
ACTION_FILE_NEW,
ACTION_FILE_OPEN,
ACTION_FILE_SAVE,
ACTION_FILE_SAVE_AS,
ACTION_FILE_SAVE_ALL,
ACTION_FILE_CLOSE,
ACTION_FILE_CLOSE_ALL,
ACTION_FILE_PRINT,
ACTION_PROJECT_NEW,
ACTION_PROJECT_SAVE,
ACTION_PROJECT_CLOSE,
ACTION_FOLDER_OPEN
};
explicit IconsManager(QObject *parent = nullptr);
void updateEditorGuttorIcons(const QString& iconSet, int size);
void updateParserIcons(const QString& iconSet, int size);
void updateActionIcons(const QString iconSet, int size);
PIcon getIcon(IconName iconName) const;

View File

@ -0,0 +1,98 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
width="100"
height="100"
viewBox="0 0 26.458333 26.458333"
version="1.1"
id="svg5"
inkscape:version="1.1.1 (3bf5ae0d25, 2021-09-20)"
sodipodi:docname="01File-01New.svg"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns="http://www.w3.org/2000/svg"
xmlns:svg="http://www.w3.org/2000/svg">
<sodipodi:namedview
id="namedview7"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageshadow="2"
inkscape:pageopacity="0.0"
inkscape:pagecheckerboard="0"
inkscape:document-units="px"
showgrid="false"
inkscape:zoom="5.786981"
inkscape:cx="21.427407"
inkscape:cy="58.147763"
inkscape:window-width="1920"
inkscape:window-height="1001"
inkscape:window-x="-9"
inkscape:window-y="-9"
inkscape:window-maximized="1"
inkscape:current-layer="layer1"
units="px"
width="100px" />
<defs
id="defs2">
<linearGradient
inkscape:collect="always"
id="linearGradient1420">
<stop
style="stop-color:#e0e0e0;stop-opacity:1;"
offset="0"
id="stop1416" />
<stop
style="stop-color:#ffffff;stop-opacity:1"
offset="1"
id="stop1418" />
</linearGradient>
<linearGradient
id="linearGradient3056"
inkscape:swatch="gradient">
<stop
style="stop-color:#45c200;stop-opacity:1"
offset="0"
id="stop826" />
<stop
style="stop-color:#53e900;stop-opacity:1"
offset="1"
id="stop828" />
</linearGradient>
<linearGradient
id="linearGradient3056-2">
<stop
style="stop-color:#45c200;stop-opacity:1"
offset="0"
id="stop3052" />
<stop
style="stop-color:#5fff07;stop-opacity:1"
offset="1"
id="stop3054" />
</linearGradient>
<linearGradient
inkscape:collect="always"
xlink:href="#linearGradient1420"
id="linearGradient1422"
x1="7.8442378"
y1="11.269956"
x2="1.9260681"
y2="11.269956"
gradientUnits="userSpaceOnUse" />
</defs>
<g
inkscape:label="图层 1"
inkscape:groupmode="layer"
id="layer1">
<rect
style="fill:url(#linearGradient1422);fill-opacity:1;stroke:#000000;stroke-width:0.7215909;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="rect848-1"
width="15.520367"
height="19.932112"
x="1.8840514"
y="1.3039001"
transform="matrix(1.1,0,0,1.1,2.6932117,0.93042432)" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 2.8 KiB

View File

@ -0,0 +1,82 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
width="100"
height="100"
viewBox="0 0 26.458333 26.458333"
version="1.1"
id="svg5"
inkscape:version="1.1.1 (3bf5ae0d25, 2021-09-20)"
sodipodi:docname="01File-02Open.svg"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns="http://www.w3.org/2000/svg"
xmlns:svg="http://www.w3.org/2000/svg">
<sodipodi:namedview
id="namedview7"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageshadow="2"
inkscape:pageopacity="0.0"
inkscape:pagecheckerboard="0"
inkscape:document-units="px"
showgrid="false"
inkscape:zoom="2.8934905"
inkscape:cx="88.82006"
inkscape:cy="87.610448"
inkscape:window-width="1920"
inkscape:window-height="1001"
inkscape:window-x="-9"
inkscape:window-y="-9"
inkscape:window-maximized="1"
inkscape:current-layer="layer1"
units="px"
width="100px" />
<defs
id="defs2">
<linearGradient
id="linearGradient3056"
inkscape:swatch="gradient">
<stop
style="stop-color:#45c200;stop-opacity:1"
offset="0"
id="stop826" />
<stop
style="stop-color:#53e900;stop-opacity:1"
offset="1"
id="stop828" />
</linearGradient>
<linearGradient
id="linearGradient3056-2">
<stop
style="stop-color:#45c200;stop-opacity:1"
offset="0"
id="stop3052" />
<stop
style="stop-color:#5fff07;stop-opacity:1"
offset="1"
id="stop3054" />
</linearGradient>
</defs>
<g
inkscape:label="图层 1"
inkscape:groupmode="layer"
id="layer1">
<g
id="g6809"
transform="matrix(0.97787538,0,0,1,0.54974946,0)">
<path
id="rect934"
style="fill:#fcbc4c;fill-opacity:1;stroke:#000000;stroke-width:0.921453"
d="M 1.9339449,5.328133 3.1281067,4.7507401 c 0.4565462,-0.2546989 1.4914566,0.03536 1.6805687,0.4753376 L 5.454469,6.2915253 17.286268,2.9556176 24.615666,17.423231 7.1394603,23.255992 1.0329163,7.1246955 C 0.67521119,6.3718456 1.2635181,5.6055194 1.9339449,5.328133 Z"
sodipodi:nodetypes="ccccccccc" />
<path
style="fill:#fcbc4c;fill-opacity:1;stroke:#000000;stroke-width:0.921453;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="M 7.1394603,23.255992 24.615666,17.423231 24.847858,6.6835956 7.0800062,12.127359 Z"
id="path6014"
sodipodi:nodetypes="ccccc" />
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 2.7 KiB

View File

@ -18,6 +18,7 @@
#include "colorscheme.h"
#include "thememanager.h"
#include "widgets/darkfusionstyle.h"
#include "widgets/lightfusionstyle.h"
#include "problems/problemcasevalidator.h"
#include "widgets/ojproblempropertywidget.h"
#include "version.h"
@ -286,6 +287,8 @@ MainWindow::MainWindow(QWidget *parent)
updateShortcuts();
updateTools();
updateEditorSettings();
}
MainWindow::~MainWindow()
@ -533,7 +536,7 @@ void MainWindow::applySettings()
if (appTheme->isDark())
QApplication::setStyle(new DarkFusionStyle());
else
QApplication::setStyle("fusion");
QApplication::setStyle(new LightFusionStyle());
qApp->setPalette(appTheme->palette());
//fix for qstatusbar bug
mFileEncodingStatus->setPalette(appTheme->palette());
@ -583,6 +586,7 @@ void MainWindow::applySettings()
ui->tabInfos->removeTab(idxProblemSet);
}
updateDebuggerSettings();
updateActionIcons();
}
void MainWindow::applyUISettings()
@ -1092,6 +1096,19 @@ void MainWindow::updateDebuggerSettings()
}
void MainWindow::updateActionIcons()
{
int size = pointToPixel(pSettings->environment().interfaceFontSize());
pIconsManager->updateActionIcons("newlook", size);
QSize iconSize(size,size);
ui->toolbarMain->setIconSize(iconSize);
ui->toolbarCode->setIconSize(iconSize);
ui->toolbarCompile->setIconSize(iconSize);
ui->toolbarDebug->setIconSize(iconSize);
ui->actionNew->setIcon(QIcon(*(pIconsManager->getIcon(IconsManager::ACTION_FILE_NEW))));
ui->actionOpen->setIcon(QIcon(*(pIconsManager->getIcon(IconsManager::ACTION_FILE_OPEN))));
}
void MainWindow::checkSyntaxInBack(Editor *e)
{
if (e==nullptr)

View File

@ -89,6 +89,7 @@ public:
void updateEditorColorSchemes();
void updateCompilerSet();
void updateDebuggerSettings();
void updateActionIcons();
void checkSyntaxInBack(Editor* e);
bool compile(bool rebuild=false);
void runExecutable(const QString& exeName, const QString& filename=QString(),RunType runType = RunType::Normal);

View File

@ -8,6 +8,7 @@
#include <QCoreApplication>
#include <QPixmapCache>
#include <QApplication>
#include "../settings.h"
#define BEGIN_STYLE_PIXMAPCACHE(a) \
QRect rect = option->rect; \
@ -799,6 +800,16 @@ void DarkFusionStyle::drawComplexControl(ComplexControl control, const QStyleOpt
QProxyStyle::drawComplexControl(control,option,painter,widget);
}
int DarkFusionStyle::pixelMetric(PixelMetric metric, const QStyleOption *option, const QWidget *widget) const
{
switch ( metric ) {
case QStyle::PM_SmallIconSize:
return pointToPixel(pSettings->environment().interfaceFontSize());
default:
return QProxyStyle::pixelMetric( metric, option, widget );
}
}
void DarkFusionStyle::drawControl(ControlElement element, const QStyleOption *option, QPainter *painter,
const QWidget *widget) const
{

View File

@ -16,11 +16,9 @@ public:
const QWidget *widget) const override;
QIcon standardIcon(StandardPixmap standardIcon, const QStyleOption *option = nullptr,
const QWidget *widget = nullptr) const override;
// QStyle interface
public:
void drawComplexControl(ComplexControl control, const QStyleOptionComplex *option,
QPainter *painter, const QWidget *widget) const override;
int pixelMetric(PixelMetric metric, const QStyleOption *option, const QWidget *widget) const override;
};
#endif // DARKFUSIONSTYLE_H

View File

@ -0,0 +1,17 @@
#include "lightfusionstyle.h"
#include "../settings.h"
LightFusionStyle::LightFusionStyle():QProxyStyle("fusion")
{
}
int LightFusionStyle::pixelMetric(PixelMetric metric, const QStyleOption *option, const QWidget *widget) const
{
switch ( metric ) {
case QStyle::PM_SmallIconSize:
return pointToPixel(pSettings->environment().interfaceFontSize());
default:
return QProxyStyle::pixelMetric( metric, option, widget );
}
}

View File

@ -0,0 +1,18 @@
#ifndef LIGHTFUSIONSTYLE_H
#define LIGHTFUSIONSTYLE_H
#include <QProxyStyle>
#include <QObject>
class LightFusionStyle : public QProxyStyle
{
Q_OBJECT
public:
LightFusionStyle();
// QStyle interface
public:
int pixelMetric(PixelMetric metric, const QStyleOption *option, const QWidget *widget) const override;
};
#endif // LIGHTFUSIONSTYLE_H