formatter

This commit is contained in:
2026-06-30 15:35:25 +02:00
parent 951c31ab3d
commit 61019204d8
9 changed files with 222 additions and 189 deletions
+1 -2
View File
@@ -26,8 +26,7 @@ void BlobGroup::setColor(const QColor& c) {
} }
void BlobGroup::setCornerFill(bool e) { void BlobGroup::setCornerFill(bool e) {
if (m_cornerFill == e) if (m_cornerFill == e) return;
return;
m_cornerFill = e; m_cornerFill = e;
emit cornerFillChanged(); emit cornerFillChanged();
markDirty(); markDirty();
+7 -5
View File
@@ -11,9 +11,13 @@ class BlobInvertedRect;
class BlobGroup : public QObject { class BlobGroup : public QObject {
Q_OBJECT Q_OBJECT
QML_ELEMENT QML_ELEMENT
Q_PROPERTY(qreal smoothing READ smoothing WRITE setSmoothing NOTIFY smoothingChanged) Q_PROPERTY(
qreal smoothing READ smoothing WRITE setSmoothing NOTIFY
smoothingChanged)
Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged) Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
Q_PROPERTY(bool cornerFill READ cornerFill WRITE setCornerFill NOTIFY cornerFillChanged) Q_PROPERTY(
bool cornerFill READ cornerFill WRITE setCornerFill NOTIFY
cornerFillChanged)
public: public:
explicit BlobGroup(QObject* parent = nullptr); explicit BlobGroup(QObject* parent = nullptr);
@@ -27,9 +31,7 @@ Q_PROPERTY(bool cornerFill READ cornerFill WRITE setCornerFill NOTIFY cornerFill
void setColor(const QColor& c); void setColor(const QColor& c);
[[nodiscard]] bool cornerFill() const { [[nodiscard]] bool cornerFill() const { return m_cornerFill; }
return m_cornerFill;
}
void setCornerFill(bool e); void setCornerFill(bool e);
+26 -27
View File
@@ -32,11 +32,9 @@ void BlobRect::updatePolish() {
QMetaObject::invokeMethod( QMetaObject::invokeMethod(
this, this,
[this]() { [this]() {
if (m_group) if (m_group) m_group->markDirty();
m_group->markDirty();
}, },
Qt::QueuedConnection Qt::QueuedConnection);
);
} }
} else { } else {
QMetaObject::invokeMethod( QMetaObject::invokeMethod(
@@ -184,8 +182,7 @@ bool BlobRect::isExcluded(const BlobShape* other) const {
bool BlobRect::isCornerExcluded(const BlobShape* other) const { bool BlobRect::isCornerExcluded(const BlobShape* other) const {
for (const auto& ptr : m_excludeCorners) { for (const auto& ptr : m_excludeCorners) {
if (ptr == other) if (ptr == other) return true;
return true;
} }
return false; return false;
} }
@@ -203,8 +200,15 @@ QQmlListProperty<BlobRect> BlobRect::exclude() {
} }
QQmlListProperty<BlobRect> BlobRect::excludeCorners() { QQmlListProperty<BlobRect> BlobRect::excludeCorners() {
return QQmlListProperty<BlobRect>(this, nullptr, &excludeCornersAppend, &excludeCornersCount, &excludeCornersAt, return QQmlListProperty<BlobRect>(
&excludeCornersClear, &excludeCornersReplace, &excludeCornersRemoveLast); this,
nullptr,
&excludeCornersAppend,
&excludeCornersCount,
&excludeCornersAt,
&excludeCornersClear,
&excludeCornersReplace,
&excludeCornersRemoveLast);
} }
void BlobRect::excludeAppend(QQmlListProperty<BlobRect>* prop, BlobRect* rect) { void BlobRect::excludeAppend(QQmlListProperty<BlobRect>* prop, BlobRect* rect) {
@@ -249,11 +253,11 @@ void BlobRect::excludeRemoveLast(QQmlListProperty<BlobRect>* prop) {
emit self->excludeChanged(); emit self->excludeChanged();
} }
void BlobRect::excludeCornersAppend(QQmlListProperty<BlobRect>* prop, BlobRect* rect) { void BlobRect::excludeCornersAppend(
QQmlListProperty<BlobRect>* prop, BlobRect* rect) {
auto* self = static_cast<BlobRect*>(prop->object); auto* self = static_cast<BlobRect*>(prop->object);
self->m_excludeCorners.append(rect); self->m_excludeCorners.append(rect);
if (self->m_group) if (self->m_group) self->m_group->markDirty();
self->m_group->markDirty();
emit self->excludeCornersChanged(); emit self->excludeCornersChanged();
} }
@@ -262,36 +266,33 @@ qsizetype BlobRect::excludeCornersCount(QQmlListProperty<BlobRect>* prop) {
return self->m_excludeCorners.size(); return self->m_excludeCorners.size();
} }
BlobRect* BlobRect::excludeCornersAt(QQmlListProperty<BlobRect>* prop, qsizetype index) { BlobRect* BlobRect::excludeCornersAt(
QQmlListProperty<BlobRect>* prop, qsizetype index) {
auto* self = static_cast<BlobRect*>(prop->object); auto* self = static_cast<BlobRect*>(prop->object);
return self->m_excludeCorners.at(index); return self->m_excludeCorners.at(index);
} }
void BlobRect::excludeCornersClear(QQmlListProperty<BlobRect>* prop) { void BlobRect::excludeCornersClear(QQmlListProperty<BlobRect>* prop) {
auto* self = static_cast<BlobRect*>(prop->object); auto* self = static_cast<BlobRect*>(prop->object);
if (self->m_excludeCorners.isEmpty()) if (self->m_excludeCorners.isEmpty()) return;
return;
self->m_excludeCorners.clear(); self->m_excludeCorners.clear();
if (self->m_group) if (self->m_group) self->m_group->markDirty();
self->m_group->markDirty();
emit self->excludeCornersChanged(); emit self->excludeCornersChanged();
} }
void BlobRect::excludeCornersReplace(QQmlListProperty<BlobRect>* prop, qsizetype index, BlobRect* rect) { void BlobRect::excludeCornersReplace(
QQmlListProperty<BlobRect>* prop, qsizetype index, BlobRect* rect) {
auto* self = static_cast<BlobRect*>(prop->object); auto* self = static_cast<BlobRect*>(prop->object);
self->m_excludeCorners[index] = rect; self->m_excludeCorners[index] = rect;
if (self->m_group) if (self->m_group) self->m_group->markDirty();
self->m_group->markDirty();
emit self->excludeCornersChanged(); emit self->excludeCornersChanged();
} }
void BlobRect::excludeCornersRemoveLast(QQmlListProperty<BlobRect>* prop) { void BlobRect::excludeCornersRemoveLast(QQmlListProperty<BlobRect>* prop) {
auto* self = static_cast<BlobRect*>(prop->object); auto* self = static_cast<BlobRect*>(prop->object);
if (self->m_excludeCorners.isEmpty()) if (self->m_excludeCorners.isEmpty()) return;
return;
self->m_excludeCorners.removeLast(); self->m_excludeCorners.removeLast();
if (self->m_group) if (self->m_group) self->m_group->markDirty();
self->m_group->markDirty();
emit self->excludeCornersChanged(); emit self->excludeCornersChanged();
} }
@@ -319,11 +320,9 @@ void BlobRect::checkAtRest(float speed) {
QMetaObject::invokeMethod( QMetaObject::invokeMethod(
this, this,
[this]() { [this]() {
if (m_group) if (m_group) m_group->markDirty();
m_group->markDirty();
}, },
Qt::QueuedConnection Qt::QueuedConnection);
);
} }
} }
} }
+33 -14
View File
@@ -10,16 +10,30 @@
class BlobRect : public BlobShape { class BlobRect : public BlobShape {
Q_OBJECT Q_OBJECT
QML_ELEMENT QML_ELEMENT
Q_PROPERTY(qreal stiffness READ stiffness WRITE setStiffness NOTIFY stiffnessChanged)
Q_PROPERTY(qreal damping READ damping WRITE setDamping NOTIFY dampingChanged)
Q_PROPERTY(qreal deformScale READ deformScale WRITE setDeformScale NOTIFY deformScaleChanged)
Q_PROPERTY(QQmlListProperty<BlobRect> exclude READ exclude NOTIFY excludeChanged)
Q_PROPERTY(QQmlListProperty<BlobRect> excludeCorners READ excludeCorners NOTIFY excludeCornersChanged)
Q_PROPERTY(qreal topLeftRadius READ topLeftRadius WRITE setTopLeftRadius NOTIFY topLeftRadiusChanged)
Q_PROPERTY(qreal topRightRadius READ topRightRadius WRITE setTopRightRadius NOTIFY topRightRadiusChanged)
Q_PROPERTY(qreal bottomLeftRadius READ bottomLeftRadius WRITE setBottomLeftRadius NOTIFY bottomLeftRadiusChanged)
Q_PROPERTY( Q_PROPERTY(
qreal bottomRightRadius READ bottomRightRadius WRITE setBottomRightRadius NOTIFY bottomRightRadiusChanged) qreal stiffness READ stiffness WRITE setStiffness NOTIFY
stiffnessChanged)
Q_PROPERTY(qreal damping READ damping WRITE setDamping NOTIFY dampingChanged)
Q_PROPERTY(
qreal deformScale READ deformScale WRITE setDeformScale NOTIFY
deformScaleChanged)
Q_PROPERTY(
QQmlListProperty<BlobRect> exclude READ exclude NOTIFY excludeChanged)
Q_PROPERTY(
QQmlListProperty<BlobRect> excludeCorners READ excludeCorners NOTIFY
excludeCornersChanged)
Q_PROPERTY(
qreal topLeftRadius READ topLeftRadius WRITE setTopLeftRadius NOTIFY
topLeftRadiusChanged)
Q_PROPERTY(
qreal topRightRadius READ topRightRadius WRITE setTopRightRadius NOTIFY
topRightRadiusChanged)
Q_PROPERTY(
qreal bottomLeftRadius READ bottomLeftRadius WRITE setBottomLeftRadius
NOTIFY bottomLeftRadiusChanged)
Q_PROPERTY(
qreal bottomRightRadius READ bottomRightRadius WRITE
setBottomRightRadius NOTIFY bottomRightRadiusChanged)
public: public:
explicit BlobRect(QQuickItem* parent = nullptr); explicit BlobRect(QQuickItem* parent = nullptr);
@@ -126,15 +140,20 @@ QList<QPointer<BlobRect> > m_excludeCorners;
static void excludeAppend(QQmlListProperty<BlobRect>* prop, BlobRect* rect); static void excludeAppend(QQmlListProperty<BlobRect>* prop, BlobRect* rect);
static qsizetype excludeCount(QQmlListProperty<BlobRect>* prop); static qsizetype excludeCount(QQmlListProperty<BlobRect>* prop);
static BlobRect* excludeAt(QQmlListProperty<BlobRect>* prop, qsizetype index); static BlobRect* excludeAt(
QQmlListProperty<BlobRect>* prop, qsizetype index);
static void excludeClear(QQmlListProperty<BlobRect>* prop); static void excludeClear(QQmlListProperty<BlobRect>* prop);
static void excludeReplace(QQmlListProperty<BlobRect>* prop, qsizetype index, BlobRect* rect); static void excludeReplace(
QQmlListProperty<BlobRect>* prop, qsizetype index, BlobRect* rect);
static void excludeRemoveLast(QQmlListProperty<BlobRect>* prop); static void excludeRemoveLast(QQmlListProperty<BlobRect>* prop);
static void excludeCornersAppend(QQmlListProperty<BlobRect>* prop, BlobRect* rect); static void excludeCornersAppend(
QQmlListProperty<BlobRect>* prop, BlobRect* rect);
static qsizetype excludeCornersCount(QQmlListProperty<BlobRect>* prop); static qsizetype excludeCornersCount(QQmlListProperty<BlobRect>* prop);
static BlobRect* excludeCornersAt(QQmlListProperty<BlobRect>* prop, qsizetype index); static BlobRect* excludeCornersAt(
QQmlListProperty<BlobRect>* prop, qsizetype index);
static void excludeCornersClear(QQmlListProperty<BlobRect>* prop); static void excludeCornersClear(QQmlListProperty<BlobRect>* prop);
static void excludeCornersReplace(QQmlListProperty<BlobRect>* prop, qsizetype index, BlobRect* rect); static void excludeCornersReplace(
QQmlListProperty<BlobRect>* prop, qsizetype index, BlobRect* rect);
static void excludeCornersRemoveLast(QQmlListProperty<BlobRect>* prop); static void excludeCornersRemoveLast(QQmlListProperty<BlobRect>* prop);
}; };
+4 -8
View File
@@ -38,8 +38,7 @@ static float cornerFillFactor(float sd, float smoothFactor) {
return std::max(outside, inside); return std::max(outside, inside);
} }
BlobShape::BlobShape(QQuickItem* parent) BlobShape::BlobShape(QQuickItem* parent) : QQuickItem(parent) {
: QQuickItem(parent) {
setFlag(ItemHasContents); setFlag(ItemHasContents);
} }
@@ -312,13 +311,10 @@ void BlobShape::updatePolish() {
const float cTlX = ri.cx - ri.hw, cTlY = ri.cy - ri.hh; const float cTlX = ri.cx - ri.hw, cTlY = ri.cy - ri.hh;
for (qsizetype j = 0; cornerFill && j < rectCount; ++j) { for (qsizetype j = 0; cornerFill && j < rectCount; ++j) {
if (j == i) if (j == i) continue;
continue; if (riExcludeMask & (1 << j)) continue;
if (riExcludeMask & (1 << j))
continue;
BlobShape* const sj = rectShapes[j]; BlobShape* const sj = rectShapes[j];
if (si->isCornerExcluded(sj) || sj->isCornerExcluded(si)) if (si->isCornerExcluded(sj) || sj->isCornerExcluded(si)) continue;
continue;
const auto& rj = m_cachedRects[j]; const auto& rj = m_cachedRects[j];
const float sdTr = cpuSdBox(cTrX, cTrY, rj.cx, rj.cy, rj.hw, rj.hh); const float sdTr = cpuSdBox(cTrX, cTrY, rj.cx, rj.cy, rj.hw, rj.hh);
const float sdBr = cpuSdBox(cBrX, cBrY, rj.cx, rj.cy, rj.hw, rj.hh); const float sdBr = cpuSdBox(cBrX, cBrY, rj.cx, rj.cy, rj.hw, rj.hh);
+30 -17
View File
@@ -10,17 +10,22 @@ Q_LOGGING_CATEGORY(lcAppDb, "ZShell.appdb", QtInfoMsg)
namespace ZShell { namespace ZShell {
AppEntry::AppEntry(QObject* entry, unsigned int frequency, QObject* parent) AppEntry::AppEntry(QObject* entry, unsigned int frequency, QObject* parent)
: QObject(parent) : QObject(parent), m_entry(entry), m_frequency(frequency) {
, m_entry(entry)
, m_frequency(frequency) {
const auto mo = m_entry->metaObject(); const auto mo = m_entry->metaObject();
const auto tmo = &AppEntry::staticMetaObject; const auto tmo = &AppEntry::staticMetaObject;
for (const auto& prop : for (const auto& prop :
{ "name", "comment", "execString", "startupClass", "genericName", "categories", "keywords" }) { {"name",
"comment",
"execString",
"startupClass",
"genericName",
"categories",
"keywords"}) {
const auto metaProp = mo->property(mo->indexOfProperty(prop)); const auto metaProp = mo->property(mo->indexOfProperty(prop));
const auto thisMetaProp = tmo->property(tmo->indexOfProperty(prop)); const auto thisMetaProp = tmo->property(tmo->indexOfProperty(prop));
QObject::connect(m_entry, metaProp.notifySignal(), this, thisMetaProp.notifySignal()); QObject::connect(
m_entry, metaProp.notifySignal(), this, thisMetaProp.notifySignal());
} }
QObject::connect(m_entry, &QObject::destroyed, this, [this]() { QObject::connect(m_entry, &QObject::destroyed, this, [this]() {
@@ -118,7 +123,9 @@ AppDb::AppDb(QObject* parent)
db.open(); db.open();
QSqlQuery query(db); QSqlQuery query(db);
query.exec("CREATE TABLE IF NOT EXISTS frequencies (id TEXT PRIMARY KEY, frequency INTEGER)"); query.exec(
"CREATE TABLE IF NOT EXISTS frequencies (id TEXT PRIMARY KEY, "
"frequency INTEGER)");
} }
QString AppDb::uuid() const { QString AppDb::uuid() const {
@@ -145,7 +152,9 @@ void AppDb::setPath(const QString& path) {
db.open(); db.open();
QSqlQuery query(db); QSqlQuery query(db);
query.exec("CREATE TABLE IF NOT EXISTS frequencies (id TEXT PRIMARY KEY, frequency INTEGER)"); query.exec(
"CREATE TABLE IF NOT EXISTS frequencies (id TEXT PRIMARY KEY, "
"frequency INTEGER)");
updateAppFrequencies(); updateAppFrequencies();
} }
@@ -183,7 +192,9 @@ void AppDb::setFavoriteApps(const QStringList& favApps) {
if (re.isValid()) { if (re.isValid()) {
m_favoriteAppsRegex << re; m_favoriteAppsRegex << re;
} else { } else {
qCWarning(lcAppDb) << "setFavoriteApps: regular expression is not valid:" << re.pattern(); qCWarning(lcAppDb)
<< "setFavoriteApps: regular expression is not valid:"
<< re.pattern();
} }
} }
@@ -191,8 +202,7 @@ void AppDb::setFavoriteApps(const QStringList& favApps) {
} }
QString AppDb::regexifyString(const QString& original) const { QString AppDb::regexifyString(const QString& original) const {
if (original.startsWith('^') && original.endsWith('$')) if (original.startsWith('^') && original.endsWith('$')) return original;
return original;
const QString escaped = QRegularExpression::escape(original); const QString escaped = QRegularExpression::escape(original);
return QStringLiteral("^%1$").arg(escaped); return QStringLiteral("^%1$").arg(escaped);
@@ -206,7 +216,8 @@ void AppDb::incrementFrequency(const QString& id) {
auto db = QSqlDatabase::database(m_uuid); auto db = QSqlDatabase::database(m_uuid);
QSqlQuery query(db); QSqlQuery query(db);
query.prepare("INSERT INTO frequencies (id, frequency) " query.prepare(
"INSERT INTO frequencies (id, frequency) "
"VALUES (:id, 1) " "VALUES (:id, 1) "
"ON CONFLICT (id) DO UPDATE SET frequency = frequency + 1"); "ON CONFLICT (id) DO UPDATE SET frequency = frequency + 1");
query.bindValue(":id", id); query.bindValue(":id", id);
@@ -221,7 +232,8 @@ void AppDb::incrementFrequency(const QString& id) {
emit appsChanged(); emit appsChanged();
} }
} else { } else {
qCWarning(lcAppDb) << "incrementFrequency: could not find app with id" << id; qCWarning(lcAppDb) << "incrementFrequency: could not find app with id"
<< id;
} }
} }
@@ -232,15 +244,16 @@ QList<AppEntry*>& AppDb::getSortedApps() const {
QSet<QString> favSet; QSet<QString> favSet;
favSet.reserve(m_sortedApps.size()); favSet.reserve(m_sortedApps.size());
for (const auto* app : std::as_const(m_sortedApps)) { for (const auto* app : std::as_const(m_sortedApps)) {
if (isFavorite(app)) if (isFavorite(app)) favSet.insert(app->id());
favSet.insert(app->id());
} }
std::sort(m_sortedApps.begin(), m_sortedApps.end(), [&favSet](AppEntry* a, AppEntry* b) { std::sort(
m_sortedApps.begin(),
m_sortedApps.end(),
[&favSet](AppEntry* a, AppEntry* b) {
const bool aIsFav = favSet.contains(a->id()); const bool aIsFav = favSet.contains(a->id());
const bool bIsFav = favSet.contains(b->id()); const bool bIsFav = favSet.contains(b->id());
if (aIsFav != bIsFav) if (aIsFav != bIsFav) return aIsFav;
return aIsFav;
if (a->frequency() != b->frequency()) if (a->frequency() != b->frequency())
return a->frequency() > b->frequency(); return a->frequency() > b->frequency();
return a->name().localeAwareCompare(b->name()) < 0; return a->name().localeAwareCompare(b->name()) < 0;
+8 -3
View File
@@ -67,9 +67,14 @@ class AppDb : public QObject {
Q_PROPERTY(QString uuid READ uuid CONSTANT) Q_PROPERTY(QString uuid READ uuid CONSTANT)
Q_PROPERTY(QString path READ path WRITE setPath NOTIFY pathChanged REQUIRED) Q_PROPERTY(QString path READ path WRITE setPath NOTIFY pathChanged REQUIRED)
Q_PROPERTY(QObjectList entries READ entries WRITE setEntries NOTIFY entriesChanged REQUIRED) Q_PROPERTY(
Q_PROPERTY(QStringList favoriteApps READ favoriteApps WRITE setFavoriteApps NOTIFY favoriteAppsChanged REQUIRED) QObjectList entries READ entries WRITE setEntries NOTIFY entriesChanged
Q_PROPERTY(QQmlListProperty<ZShell::AppEntry> apps READ apps NOTIFY appsChanged) REQUIRED)
Q_PROPERTY(
QStringList favoriteApps READ favoriteApps WRITE setFavoriteApps NOTIFY
favoriteAppsChanged REQUIRED)
Q_PROPERTY(
QQmlListProperty<ZShell::AppEntry> apps READ apps NOTIFY appsChanged)
public: public:
explicit AppDb(QObject* parent = nullptr); explicit AppDb(QObject* parent = nullptr);