thedesk/platform/iconloaderengine.cpp

123 lines
4.5 KiB
C++
Raw Normal View History

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-07-10 08:04:09 -04:00
QString iconName;
2022-06-05 03:22:27 -04:00
QIconEngine* parentEngine;
2023-04-07 04:33:44 -04:00
// QIconEngine* rtlParentEngine;
2020-07-20 03:40:48 -04:00
};
2022-07-10 08:04:09 -04:00
IconLoaderEngine::IconLoaderEngine(QString iconName, QIconEngine* parentEngine, QIconEngine* rtlParentEngine) {
2020-07-20 03:40:48 -04:00
d = new IconLoaderEnginePrivate();
2022-07-10 08:04:09 -04:00
d->iconName = iconName;
2020-07-20 03:40:48 -04:00
d->parentEngine = parentEngine;
2023-04-07 04:33:44 -04: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;
2023-04-07 04:33:44 -04:00
// 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) {
2023-04-07 04:33:44 -04: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) {
2023-04-07 04:33:44 -04: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);
2023-04-07 04:33:44 -04: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);
2023-04-07 04:33:44 -04: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 {
2023-04-07 04:33:44 -04:00
// return new IconLoaderEngine(d->iconName, d->parentEngine->clone(), d->rtlParentEngine->clone());
return new IconLoaderEngine(d->iconName, d->parentEngine->clone(), nullptr);
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);
}
2022-07-10 08:04:09 -04:00
QList<QSize> IconLoaderEngine::availableSizes(QIcon::Mode mode, QIcon::State state) {
2023-04-07 04:33:44 -04: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
}
2022-07-10 08:04:09 -04:00
QString IconLoaderEngine::iconName() {
return d->iconName;
2020-07-20 03:40:48 -04:00
}
void IconLoaderEngine::virtual_hook(int id, void* data) {
d->parentEngine->virtual_hook(id, data);
}
2022-07-10 08:04:09 -04:00
bool IconLoaderEngine::isNull() {
return d->parentEngine->isNull();
}
QPixmap IconLoaderEngine::scaledPixmap(const QSize& size, QIcon::Mode mode, QIcon::State state, qreal scale) {
2023-04-07 04:33:44 -04:00
// if (QApplication::layoutDirection() == Qt::RightToLeft && d->rtlParentEngine->availableSizes(mode, state).length() > 0) {
// return d->rtlParentEngine->scaledPixmap(size, mode, state, scale);
// } else {
return d->parentEngine->scaledPixmap(size, mode, state, scale);
// }
2022-07-10 08:04:09 -04:00
}