C++ / fmt (pull_request) Failing after 5s
C++ / build (pull_request) Failing after 9s
C++ / clang-tidy (pull_request) Failing after 10s
JS/TS / fmt (pull_request) Successful in 10s
JS/TS / lint (pull_request) Successful in 8s
Python / static (pull_request) Failing after 28s
Python / verify (pull_request) Failing after 1m29s
Rust / build (pull_request) Successful in 53s
Rust / fmt (pull_request) Successful in 42s
Rust / clippy (pull_request) Successful in 1m4s
122 lines
2.6 KiB
C++
122 lines
2.6 KiB
C++
#include "wallpaperobject.hpp"
|
|
|
|
namespace ZShell::internal {
|
|
|
|
WallpaperObject::WallpaperObject(QObject* parent) : QObject(parent) {}
|
|
|
|
WallpaperObject::~WallpaperObject() {
|
|
if (m_service && !m_screen.isEmpty()) m_service->removeScreen(m_screen);
|
|
}
|
|
|
|
void WallpaperObject::registerScreen() {
|
|
if (!m_service || m_screen.isEmpty()) return;
|
|
|
|
m_service->addScreen(m_screen);
|
|
}
|
|
|
|
void WallpaperObject::setService(WallpaperService* service) {
|
|
if (m_service == service) return;
|
|
m_service = service;
|
|
emit serviceChanged();
|
|
|
|
registerScreen();
|
|
push();
|
|
}
|
|
|
|
void WallpaperObject::setScreen(const QString& screen) {
|
|
if (m_screen == screen) return;
|
|
m_screen = screen;
|
|
emit screenChanged();
|
|
|
|
registerScreen();
|
|
push();
|
|
}
|
|
|
|
void WallpaperObject::setCropX(qreal x) {
|
|
if (qFuzzyCompare(m_cropX, x)) return;
|
|
m_cropX = x;
|
|
emit cropXChanged();
|
|
push();
|
|
}
|
|
|
|
void WallpaperObject::setCropY(qreal y) {
|
|
if (qFuzzyCompare(m_cropY, y)) return;
|
|
m_cropY = y;
|
|
emit cropYChanged();
|
|
push();
|
|
}
|
|
|
|
void WallpaperObject::setCropWidth(qreal w) {
|
|
if (qFuzzyCompare(m_cropWidth, w)) return;
|
|
m_cropWidth = w;
|
|
emit cropWidthChanged();
|
|
push();
|
|
}
|
|
|
|
void WallpaperObject::setCropHeight(qreal h) {
|
|
if (qFuzzyCompare(m_cropHeight, h)) return;
|
|
m_cropHeight = h;
|
|
emit cropHeightChanged();
|
|
push();
|
|
}
|
|
|
|
void WallpaperObject::setZoom(qreal zoom) {
|
|
if (qFuzzyCompare(m_zoom, zoom)) return;
|
|
m_zoom = zoom;
|
|
emit zoomChanged();
|
|
push();
|
|
}
|
|
|
|
void WallpaperObject::syncCrop(const QVariantMap& crop) {
|
|
const qreal x = crop.value("x").toDouble();
|
|
const qreal y = crop.value("y").toDouble();
|
|
const qreal width = crop.contains("width") ? crop.value("width").toDouble()
|
|
: 1.0;
|
|
const qreal height = crop.contains("height")
|
|
? crop.value("height").toDouble()
|
|
: 1.0;
|
|
const qreal z =
|
|
crop.contains("zoom") ? crop.value("zoom").toDouble() : 1.0;
|
|
|
|
const bool prev = m_pushEnabled;
|
|
m_pushEnabled = false;
|
|
|
|
if (!qFuzzyCompare(m_cropX, x)) {
|
|
m_cropX = x;
|
|
emit cropXChanged();
|
|
}
|
|
if (!qFuzzyCompare(m_cropY, y)) {
|
|
m_cropY = y;
|
|
emit cropYChanged();
|
|
}
|
|
if (!qFuzzyCompare(m_cropWidth, width)) {
|
|
m_cropWidth = width;
|
|
emit cropWidthChanged();
|
|
}
|
|
if (!qFuzzyCompare(m_cropHeight, height)) {
|
|
m_cropHeight = height;
|
|
emit cropHeightChanged();
|
|
}
|
|
if (!qFuzzyCompare(m_zoom, z)) {
|
|
m_zoom = z;
|
|
emit zoomChanged();
|
|
}
|
|
|
|
m_pushEnabled = prev;
|
|
}
|
|
|
|
void WallpaperObject::push() {
|
|
if (!m_pushEnabled || !m_service || m_screen.isEmpty()) return;
|
|
|
|
QVariantMap crop;
|
|
crop.insert("x", m_cropX);
|
|
crop.insert("y", m_cropY);
|
|
crop.insert("width", m_cropWidth);
|
|
crop.insert("height", m_cropHeight);
|
|
crop.insert("zoom", m_zoom);
|
|
|
|
m_service->setCrop(m_screen, crop);
|
|
}
|
|
|
|
} // namespace ZShell::internal
|