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;
36 QString copyrightText;
41 QString authorEmailAddress;
43 QString pixmapCacheNameFromElementId(
const QString &elementid,
short width,
short height);
44 QPixmap renderBG(
short width,
short height);
46 QPixmap backgroundPixmap;
47 QBrush backgroundBrush;
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)
83 Q_D(KMahjonggBackground);
98 KConfigGroup group = bgconfig.group(QStringLiteral(
"KMahjonggBackground"));
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();
125 QString graphName = group.
readEntry(
"FileName");
129 qCDebug(LIBKMAHJONGG_LOG) <<
"Using background at" << d->graphicspath;
131 if (d->graphicspath.isEmpty()) {
144 d->graphicsLoaded =
false;
149bool KMahjonggBackground::loadGraphics()
151 Q_D(KMahjonggBackground);
153 if (d->graphicsLoaded || d->isPlain) {
157 d->svg.load(d->graphicspath);
158 if (d->svg.isValid()) {
167void KMahjonggBackground::sizeChanged(
int newW,
int newH)
169 Q_D(KMahjonggBackground);
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)
190 QPixmap qiRend(width, height);
200QBrush &KMahjonggBackground::getBackground()
202 Q_D(KMahjonggBackground);
205 d->backgroundBrush = QBrush(QPixmap());
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
225 Q_D(
const KMahjonggBackground);
230QString KMahjonggBackground::name()
const
232 Q_D(
const KMahjonggBackground);
237QString KMahjonggBackground::description()
const
239 Q_D(
const KMahjonggBackground);
241 return d->description;
244QString KMahjonggBackground::license()
const
246 Q_D(
const KMahjonggBackground);
251QString KMahjonggBackground::copyrightText()
const
253 Q_D(
const KMahjonggBackground);
255 return d->copyrightText;
258QString KMahjonggBackground::version()
const
260 Q_D(
const KMahjonggBackground);
265QString KMahjonggBackground::website()
const
267 Q_D(
const KMahjonggBackground);
272QString KMahjonggBackground::bugReportUrl()
const
274 Q_D(
const KMahjonggBackground);
276 return d->bugReportUrl;
279QString KMahjonggBackground::authorName()
const
281 Q_D(
const KMahjonggBackground);
283 return d->authorName;
286QString KMahjonggBackground::authorEmailAddress()
const
288 Q_D(
const KMahjonggBackground);
290 return d->authorEmailAddress;
293bool KMahjonggBackground::isPlain()
const
295 Q_D(
const KMahjonggBackground);
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