9#include "kmahjonggbackground.h"
15#include <QPixmapCache>
16#include <QSvgRenderer>
17#include <QGuiApplication>
21#include <KConfigGroup>
22#include <KLocalizedString>
25#include "libkmahjongg_debug.h"
27class KMahjonggBackgroundPrivate
30 KMahjonggBackgroundPrivate() =
default;
43 QString pixmapCacheNameFromElementId(
const QString &elementid,
short width,
short height);
44 QPixmap renderBG(
short width,
short height);
55 bool graphicsLoaded =
false;
61KMahjonggBackground::KMahjonggBackground()
62 : d_ptr(new KMahjonggBackgroundPrivate)
66KMahjonggBackground::~KMahjonggBackground() =
default;
68bool KMahjonggBackground::loadDefault()
72 qCDebug(LIBKMAHJONGG_LOG) <<
"Inside LoadDefault(), located background at" << bgPath;
76 return load(bgPath, 0, 0);
79#define kBGVersionFormat 1
81bool KMahjonggBackground::load(
const QString &file,
short width,
short height)
100 d->isPlain = group.
readEntry(
"Plain", 0) != 0;
102 d->description = group.
readEntry(
"Description");
104 d->copyrightText = group.
readEntry(
"Copyright");
107 d->bugReportUrl = group.
readEntry(
"BugReportUrl");
108 d->authorName = group.
readEntry(
"Author");
109 d->authorEmailAddress = group.
readEntry(
"AuthorEmail");
112 int bgversion = group.
readEntry(
"VersionFormat", 0);
114 if (bgversion > kBGVersionFormat) {
120 d->graphicspath.clear();
129 qCDebug(LIBKMAHJONGG_LOG) <<
"Using background at" << d->graphicspath;
131 if (d->graphicspath.isEmpty()) {
144 d->graphicsLoaded =
false;
149bool KMahjonggBackground::loadGraphics()
153 if (d->graphicsLoaded || d->isPlain) {
157 d->svg.load(d->graphicspath);
158 if (d->svg.isValid()) {
167void KMahjonggBackground::sizeChanged(
int newW,
int newH)
172 if (d->isTiled || d->isPlain) {
176 if (newW == d->w && newH == d->h) {
183QString KMahjonggBackgroundPrivate::pixmapCacheNameFromElementId(
const QString &elementid,
short width,
short height)
185 return name + elementid + QStringLiteral(
"W%1H%2").
arg(width).
arg(height);
188QPixmap KMahjonggBackgroundPrivate::renderBG(
short width,
short height)
200QBrush &KMahjonggBackground::getBackground()
207 const qreal dpr = qApp->devicePixelRatio();
208 const short width = d->w * dpr;
209 const short height = d->h * dpr;
212 const QString pixmapCacheName = d->pixmapCacheNameFromElementId(d->filename, width, height);
214 d->backgroundPixmap = d->renderBG(width, height);
215 d->backgroundPixmap.setDevicePixelRatio(dpr);
218 d->backgroundBrush =
QBrush(d->backgroundPixmap);
220 return d->backgroundBrush;
223QString KMahjonggBackground::path()
const
230QString KMahjonggBackground::name()
const
237QString KMahjonggBackground::description()
const
241 return d->description;
244QString KMahjonggBackground::license()
const
251QString KMahjonggBackground::copyrightText()
const
255 return d->copyrightText;
258QString KMahjonggBackground::version()
const
265QString KMahjonggBackground::website()
const
272QString KMahjonggBackground::bugReportUrl()
const
276 return d->bugReportUrl;
279QString KMahjonggBackground::authorName()
const
283 return d->authorName;
286QString KMahjonggBackground::authorEmailAddress()
const
290 return d->authorEmailAddress;
293bool KMahjonggBackground::isPlain()
const
KConfigGroup group(const QString &group)
QString readEntry(const char *key, const char *aDefault=nullptr) const
bool find(const Key &key, QPixmap *pixmap)
Key insert(const QPixmap &pixmap)
QString locate(StandardLocation type, const QString &fileName, LocateOptions options)
QString arg(Args &&... args) const const
bool isEmpty() const const
bool isValid() const const
void render(QPainter *painter)