2020-07-20 03:40:48 -04:00
|
|
|
/****************************************
|
|
|
|
*
|
|
|
|
* INSERT-PROJECT-NAME-HERE - INSERT-GENERIC-NAME-HERE
|
|
|
|
* Copyright (C) 2020 Victor Tran
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* *************************************/
|
|
|
|
#include "iconloaderengine.h"
|
|
|
|
|
2022-06-05 03:22:27 -04:00
|
|
|
#include <libcontemporary_global.h>
|
2020-07-20 03:40:48 -04:00
|
|
|
|
|
|
|
struct IconLoaderEnginePrivate {
|
2022-06-05 03:22:27 -04:00
|
|
|
QIconEngine* parentEngine;
|
|
|
|
QIconEngine* rtlParentEngine;
|
2020-07-20 03:40:48 -04:00
|
|
|
};
|
|
|
|
|
2022-02-08 07:58:28 -05:00
|
|
|
IconLoaderEngine::IconLoaderEngine(QIconEngine* parentEngine, QIconEngine* rtlParentEngine) {
|
2020-07-20 03:40:48 -04:00
|
|
|
d = new IconLoaderEnginePrivate();
|
|
|
|
d->parentEngine = parentEngine;
|
2022-02-08 07:58:28 -05:00
|
|
|
d->rtlParentEngine = rtlParentEngine;
|
2020-07-20 03:40:48 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
IconLoaderEngine::~IconLoaderEngine() {
|
|
|
|
delete d->parentEngine;
|
|
|
|
delete d;
|
|
|
|
}
|
|
|
|
|
|
|
|
QPixmap IconLoaderEngine::pixmap(const QSize& size, QIcon::Mode mode, QIcon::State state) {
|
2022-02-08 07:58:28 -05:00
|
|
|
QImage image;
|
|
|
|
if (QApplication::layoutDirection() == Qt::RightToLeft && d->rtlParentEngine->availableSizes(mode, state).length() > 0) {
|
|
|
|
image = d->rtlParentEngine->pixmap(size, mode, state).toImage();
|
|
|
|
} else {
|
|
|
|
image = d->parentEngine->pixmap(size, mode, state).toImage();
|
|
|
|
}
|
2022-06-05 03:22:27 -04:00
|
|
|
libContemporaryCommon::tintImage(image, QApplication::palette().color(QPalette::WindowText));
|
2020-07-20 03:40:48 -04:00
|
|
|
return QPixmap::fromImage(image);
|
|
|
|
}
|
|
|
|
|
|
|
|
void IconLoaderEngine::paint(QPainter* painter, const QRect& rect, QIcon::Mode mode, QIcon::State state) {
|
2022-02-08 07:58:28 -05:00
|
|
|
if (QApplication::layoutDirection() == Qt::RightToLeft && d->rtlParentEngine->availableSizes(mode, state).length() > 0) {
|
|
|
|
d->rtlParentEngine->paint(painter, rect, mode, state);
|
|
|
|
} else {
|
|
|
|
d->parentEngine->paint(painter, rect, mode, state);
|
|
|
|
}
|
2020-07-20 03:40:48 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
QSize IconLoaderEngine::actualSize(const QSize& size, QIcon::Mode mode, QIcon::State state) {
|
2022-02-08 07:58:28 -05:00
|
|
|
if (QApplication::layoutDirection() == Qt::RightToLeft) {
|
|
|
|
return d->rtlParentEngine->actualSize(size, mode, state);
|
|
|
|
} else {
|
|
|
|
return d->parentEngine->actualSize(size, mode, state);
|
|
|
|
}
|
2020-07-20 03:40:48 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void IconLoaderEngine::addPixmap(const QPixmap& pixmap, QIcon::Mode mode, QIcon::State state) {
|
|
|
|
d->parentEngine->addPixmap(pixmap, mode, state);
|
2022-02-08 07:58:28 -05:00
|
|
|
d->rtlParentEngine->addPixmap(pixmap, mode, state);
|
2020-07-20 03:40:48 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void IconLoaderEngine::addFile(const QString& fileName, const QSize& size, QIcon::Mode mode, QIcon::State state) {
|
|
|
|
d->parentEngine->addFile(fileName, size, mode, state);
|
2022-02-08 07:58:28 -05:00
|
|
|
d->rtlParentEngine->addFile(fileName, size, mode, state);
|
2020-07-20 03:40:48 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
QString IconLoaderEngine::key() const {
|
|
|
|
return d->parentEngine->key();
|
|
|
|
}
|
|
|
|
|
|
|
|
QIconEngine* IconLoaderEngine::clone() const {
|
2022-02-08 07:58:28 -05:00
|
|
|
return new IconLoaderEngine(d->parentEngine->clone(), d->rtlParentEngine->clone());
|
2020-07-20 03:40:48 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool IconLoaderEngine::read(QDataStream& in) {
|
|
|
|
return d->parentEngine->read(in);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IconLoaderEngine::write(QDataStream& out) const {
|
|
|
|
return d->parentEngine->write(out);
|
|
|
|
}
|
|
|
|
|
|
|
|
QList<QSize> IconLoaderEngine::availableSizes(QIcon::Mode mode, QIcon::State state) const {
|
2022-02-08 07:58:28 -05:00
|
|
|
if (QApplication::layoutDirection() == Qt::RightToLeft) {
|
|
|
|
return d->rtlParentEngine->availableSizes(mode, state);
|
|
|
|
} else {
|
|
|
|
return d->parentEngine->availableSizes(mode, state);
|
|
|
|
}
|
2020-07-20 03:40:48 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
QString IconLoaderEngine::iconName() const {
|
|
|
|
return d->parentEngine->iconName();
|
|
|
|
}
|
|
|
|
|
|
|
|
void IconLoaderEngine::virtual_hook(int id, void* data) {
|
|
|
|
d->parentEngine->virtual_hook(id, data);
|
|
|
|
}
|