- fix: can't differentiate disabled and enabled buttons, when using contrast icon set
This commit is contained in:
parent
1574ddd743
commit
494832220a
1
NEWS.md
1
NEWS.md
|
@ -13,6 +13,7 @@ Red Panda C++ Version 0.14.1
|
|||
- fix: wrong icons for file associations
|
||||
- fix: editor's font size set by ctrl+mouse wheel will be reset by open the option dialog
|
||||
- fix: actions not correctly disabled when compile
|
||||
- fix: can't differentiate disabled and enabled buttons, when using contrast icon set
|
||||
|
||||
Red Panda C++ Version 0.14.0
|
||||
- enhancement: custom icon set ( in the configuration folder)
|
||||
|
|
|
@ -134,6 +134,7 @@ SOURCES += \
|
|||
utils.cpp \
|
||||
widgets/coloredit.cpp \
|
||||
widgets/consolewidget.cpp \
|
||||
widgets/customdisablediconengine.cpp \
|
||||
widgets/custommakefileinfodialog.cpp \
|
||||
widgets/darkfusionstyle.cpp \
|
||||
widgets/editorstabwidget.cpp \
|
||||
|
@ -260,6 +261,7 @@ HEADERS += \
|
|||
common.h \
|
||||
widgets/coloredit.h \
|
||||
widgets/consolewidget.h \
|
||||
widgets/customdisablediconengine.h \
|
||||
widgets/custommakefileinfodialog.h \
|
||||
widgets/darkfusionstyle.h \
|
||||
widgets/editorstabwidget.h \
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
#include <QJsonObject>
|
||||
#include "utils.h"
|
||||
#include "settings.h"
|
||||
#include "widgets/customdisablediconengine.h"
|
||||
|
||||
IconsManager* pIconsManager;
|
||||
|
||||
|
@ -36,11 +37,13 @@ IconsManager::IconsManager(QObject *parent) : QObject(parent)
|
|||
{
|
||||
mDefaultIconPixmap = std::make_shared<QPixmap>();
|
||||
mIconSetTemplate = "%1/%2/%3/";
|
||||
mMakeDisabledIconDarker = false;
|
||||
}
|
||||
|
||||
void IconsManager::updateEditorGuttorIcons(const QString& iconSet,int size)
|
||||
{
|
||||
QString iconFolder = mIconSetTemplate.arg( iconSetsFolder(),iconSet,"editor");
|
||||
updateMakeDisabledIconDarker(iconSet);
|
||||
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_WARNING,createSVGIcon(iconFolder+"syntaxwarning.svg",size,size));
|
||||
|
@ -51,6 +54,7 @@ void IconsManager::updateEditorGuttorIcons(const QString& iconSet,int size)
|
|||
void IconsManager::updateParserIcons(const QString &iconSet, int size)
|
||||
{
|
||||
QString iconFolder = mIconSetTemplate.arg( iconSetsFolder(),iconSet,"classparser");
|
||||
updateMakeDisabledIconDarker(iconSet);
|
||||
mIconPixmaps.insert(PARSER_TYPE, createSVGIcon(iconFolder+"type.svg",size,size));
|
||||
mIconPixmaps.insert(PARSER_CLASS, createSVGIcon(iconFolder+"class.svg",size,size));
|
||||
mIconPixmaps.insert(PARSER_NAMESPACE, createSVGIcon(iconFolder+"namespace.svg",size,size));
|
||||
|
@ -77,6 +81,7 @@ void IconsManager::updateParserIcons(const QString &iconSet, int size)
|
|||
void IconsManager::updateActionIcons(const QString& iconSet, int size)
|
||||
{
|
||||
QString iconFolder = mIconSetTemplate.arg( iconSetsFolder(),iconSet,"actions");
|
||||
updateMakeDisabledIconDarker(iconSet);
|
||||
mActionIconSize = QSize(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));
|
||||
|
@ -177,7 +182,12 @@ IconsManager::PPixmap IconsManager::getPixmap(IconName iconName) const
|
|||
|
||||
QIcon IconsManager::getIcon(IconName iconName) const
|
||||
{
|
||||
return QIcon(*getPixmap(iconName));
|
||||
if (mMakeDisabledIconDarker) {
|
||||
QIcon icon(new CustomDisabledIconEngine());
|
||||
icon.addPixmap(*getPixmap(iconName));
|
||||
return icon;
|
||||
} else
|
||||
return QIcon(*getPixmap(iconName));
|
||||
}
|
||||
|
||||
void IconsManager::setIcon(QToolButton *btn, IconName iconName) const
|
||||
|
@ -326,3 +336,8 @@ QList<PIconSet> IconsManager::listIconSets()
|
|||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void IconsManager::updateMakeDisabledIconDarker(const QString& iconset )
|
||||
{
|
||||
mMakeDisabledIconDarker = (iconset == "contrast");
|
||||
}
|
||||
|
|
|
@ -178,7 +178,8 @@ public:
|
|||
void setIconSetsFolder(const QString &newIconSetsFolder);
|
||||
|
||||
QList<PIconSet> listIconSets();
|
||||
|
||||
private:
|
||||
void updateMakeDisabledIconDarker(const QString& iconset);
|
||||
signals:
|
||||
void actionIconsUpdated();
|
||||
private:
|
||||
|
@ -187,6 +188,7 @@ private:
|
|||
QSize mActionIconSize;
|
||||
QString mIconSetTemplate;
|
||||
QString mIconSetsFolder;
|
||||
bool mMakeDisabledIconDarker;
|
||||
};
|
||||
|
||||
extern IconsManager* pIconsManager;
|
||||
|
|
|
@ -0,0 +1,64 @@
|
|||
#include "customdisablediconengine.h"
|
||||
|
||||
#include <QImage>
|
||||
#include <QPainter>
|
||||
#include <QPixmap>
|
||||
#include <QDebug>
|
||||
|
||||
CustomDisabledIconEngine::CustomDisabledIconEngine()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CustomDisabledIconEngine::paint(QPainter *painter, const QRect &rect, QIcon::Mode mode, QIcon::State state)
|
||||
{
|
||||
// if (mode == QIcon::Active && state == QIcon::On)
|
||||
// painter->drawPixmap(rect,mPixmap);
|
||||
// else
|
||||
// painter->drawPixmap(rect,mDisabledPixmap);
|
||||
}
|
||||
|
||||
QIconEngine *CustomDisabledIconEngine::clone() const
|
||||
{
|
||||
return new CustomDisabledIconEngine();
|
||||
}
|
||||
|
||||
QPixmap CustomDisabledIconEngine::pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state)
|
||||
{
|
||||
if (mode == QIcon::Mode::Disabled)
|
||||
return mDisabledPixmap;
|
||||
else
|
||||
return mPixmap;
|
||||
}
|
||||
|
||||
void CustomDisabledIconEngine::addPixmap(const QPixmap &pixmap, QIcon::Mode mode, QIcon::State state)
|
||||
{
|
||||
setPixmap(pixmap);
|
||||
}
|
||||
|
||||
void CustomDisabledIconEngine::addFile(const QString &fileName, const QSize &size, QIcon::Mode mode, QIcon::State state)
|
||||
{
|
||||
setPixmap(QPixmap(fileName));
|
||||
}
|
||||
|
||||
void CustomDisabledIconEngine::setPixmap(const QPixmap &pixmap)
|
||||
{
|
||||
mPixmap = pixmap;
|
||||
if (pixmap.isNull())
|
||||
mDisabledPixmap = pixmap;
|
||||
else {
|
||||
QImage oldImage = mPixmap.toImage();
|
||||
QImage image(mPixmap.size(), QImage::Format_ARGB32);
|
||||
for (int x=0;x<image.width();x++) {
|
||||
for (int y=0;y<image.height();y++) {
|
||||
QColor c = oldImage.pixelColor(x,y);
|
||||
int gray = 0.299 * c.red() + 0.587 * c.green() + 0.114 * c.blue();
|
||||
QColor c2(gray,gray,gray,c.alpha());
|
||||
c2 = c2.darker();
|
||||
image.setPixelColor(x,y,c2);
|
||||
}
|
||||
}
|
||||
mDisabledPixmap = QPixmap::fromImage(image);
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
#ifndef CUSTOMDISABLEDICONENGINE_H
|
||||
#define CUSTOMDISABLEDICONENGINE_H
|
||||
|
||||
#include <QIconEngine>
|
||||
|
||||
class CustomDisabledIconEngine : public QIconEngine
|
||||
{
|
||||
public:
|
||||
CustomDisabledIconEngine();
|
||||
|
||||
// QIconEngine interface
|
||||
public:
|
||||
void paint(QPainter *painter, const QRect &rect, QIcon::Mode mode, QIcon::State state) override;
|
||||
QIconEngine *clone() const override;
|
||||
QPixmap pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state) override;
|
||||
void addPixmap(const QPixmap &pixmap, QIcon::Mode mode, QIcon::State state) override;
|
||||
void addFile(const QString &fileName, const QSize &size, QIcon::Mode mode, QIcon::State state) override;
|
||||
|
||||
private:
|
||||
void setPixmap(const QPixmap& pixmap);
|
||||
private:
|
||||
QPixmap mPixmap;
|
||||
QPixmap mDisabledPixmap;
|
||||
};
|
||||
|
||||
#endif // CUSTOMDISABLEDICONENGINE_H
|
Loading…
Reference in New Issue