Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build/depends.py
Original file line number Diff line number Diff line change
Expand Up @@ -845,6 +845,7 @@ def sources(self, build):
"widget/wskincolor.cpp",
"widget/wsearchlineedit.cpp",
"widget/wpixmapstore.cpp",
"widget/paintable.cpp",
"widget/wimagestore.cpp",
"widget/hexspinbox.cpp",
"widget/wtrackproperty.cpp",
Expand Down
6 changes: 5 additions & 1 deletion src/skin/imgsource.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class ImgSource {
virtual QImage* getImage(const QString& fileName, double scaleFactor) const = 0;
virtual QColor getCorrectColor(const QColor& c) const { return c; }
virtual void correctImageColors(QImage* p) const { (void)p; };
virtual bool willCorrectColors() const { return false; };
};

class ImgProcessor : public ImgSource {
Expand All @@ -41,7 +42,8 @@ class ImgProcessor : public ImgSource {
QColor getCorrectColor(const QColor& c) const override {
return doColorCorrection(m_parent->getCorrectColor(c));
}
void correctImageColors(QImage* p) const override { (void)p; };
void correctImageColors(QImage* p) const override { (void)p; }
bool willCorrectColors() const override { return false; }

protected:
ImgSource* m_parent;
Expand Down Expand Up @@ -131,6 +133,8 @@ class ImgColorProcessor : public ImgProcessor {
}
}
}

bool willCorrectColors() const override { return true; }
};

#endif
33 changes: 14 additions & 19 deletions src/skin/pixmapsource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,29 @@

#include "skin/pixmapsource.h"

PixmapSource::PixmapSource():
m_eType(SVG) {
PixmapSource::PixmapSource()
: m_eType(SVG) {
}

PixmapSource::PixmapSource(const QString& filepath) {
setPath(filepath);
PixmapSource::PixmapSource(const QString& filepath)
: m_path(filepath) {
if (m_path.endsWith(".svg", Qt::CaseInsensitive)) {
m_eType = SVG;
} else {
m_eType = BITMAP;
}
}

QByteArray PixmapSource::getData() const {
return m_baData;
return m_svgSourceData;
}

QString PixmapSource::getPath() const {
return m_path;
}

void PixmapSource::setPath(const QString& newPath) {
m_baData.truncate(0);
m_path = newPath;
if (m_path.endsWith(".svg", Qt::CaseInsensitive)) {
m_eType = SVG;
} else {
m_eType = BITMAP;
}
}

bool PixmapSource::isEmpty() const {
return m_path.isEmpty() && m_baData.isEmpty() ;
return m_path.isEmpty() && m_svgSourceData.isEmpty() ;
}

bool PixmapSource::isSVG() const {
Expand All @@ -41,16 +36,16 @@ bool PixmapSource::isBitmap() const {
}

void PixmapSource::setSVG(const QByteArray& content) {
m_baData = content;
m_svgSourceData = content;
m_eType = SVG;
}

QString PixmapSource::getId() const {
quint16 checksum;
if (m_baData.isEmpty()) {
if (m_svgSourceData.isEmpty()) {
checksum = qChecksum(m_path.toAscii().constData(), m_path.length());
} else {
checksum = qChecksum(m_baData.constData(), m_baData.length());
checksum = qChecksum(m_svgSourceData.constData(), m_svgSourceData.length());
}
return m_path + QString::number(checksum);
}
3 changes: 1 addition & 2 deletions src/skin/pixmapsource.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ class PixmapSource final {
bool isSVG() const;
bool isBitmap() const;
void setSVG(const QByteArray& content);
void setPath(const QString& newPath);
QString getPath() const;
QByteArray getData() const;
QString getId() const;
Expand All @@ -27,7 +26,7 @@ class PixmapSource final {
};

QString m_path;
QByteArray m_baData;
QByteArray m_svgSourceData;
enum Type m_eType;
};

Expand Down
24 changes: 7 additions & 17 deletions src/skin/skincontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,6 @@ QString SkinContext::nodeToString(const QDomNode& node) const {
}

PixmapSource SkinContext::getPixmapSource(const QDomNode& pixmapNode) const {
PixmapSource source;

const SvgParser svgParser(*this);

if (!pixmapNode.isNull()) {
Expand All @@ -177,19 +175,19 @@ PixmapSource SkinContext::getPixmapSource(const QDomNode& pixmapNode) const {
// inline svg
const QByteArray rslt = svgParser.saveToQByteArray(
svgParser.parseSvgTree(svgNode, m_xmlPath));
PixmapSource source;
source.setSVG(rslt);
} else {
// filename.
source = getPixmapSourceInner(nodeToString(pixmapNode), svgParser);
return getPixmapSourceInner(nodeToString(pixmapNode));
}
}

return source;
return PixmapSource();
}

PixmapSource SkinContext::getPixmapSource(const QString& filename) const {
const SvgParser svgParser(*this);
return getPixmapSourceInner(filename, svgParser);
return getPixmapSourceInner(filename);
}

QDomElement SkinContext::loadSvg(const QString& filename) const {
Expand All @@ -208,19 +206,11 @@ QDomElement SkinContext::loadSvg(const QString& filename) const {
return cachedSvg;
}

PixmapSource SkinContext::getPixmapSourceInner(const QString& filename,
const SvgParser& svgParser) const {
PixmapSource source;
PixmapSource SkinContext::getPixmapSourceInner(const QString& filename) const {
if (!filename.isEmpty()) {
source.setPath(getSkinPath(filename));
if (source.isSVG()) {
QDomElement svgElement = loadSvg(filename);
const QByteArray rslt = svgParser.saveToQByteArray(
svgParser.parseSvgTree(svgElement, filename));
source.setSVG(rslt);
}
return PixmapSource(getSkinPath(filename));
}
return source;
return PixmapSource();
}

/**
Expand Down
3 changes: 1 addition & 2 deletions src/skin/skincontext.h
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,7 @@ class SkinContext {
}

private:
PixmapSource getPixmapSourceInner(const QString& filename,
const SvgParser& svgParser) const;
PixmapSource getPixmapSourceInner(const QString& filename) const;

QDomElement loadSvg(const QString& filename) const;

Expand Down
Loading