2023-11-05 05:14:39 +00:00
|
|
|
// SPDX-FileCopyrightText: 2023 Devin Lin <devin@kde.org>
|
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2024-06-21 04:42:14 +00:00
|
|
|
#include "homescreen.h"
|
|
|
|
|
|
2023-11-05 05:14:39 +00:00
|
|
|
#include <QObject>
|
|
|
|
|
|
|
|
|
|
#include <Plasma/Applet>
|
|
|
|
|
#include <PlasmaQuick/AppletQuickItem>
|
|
|
|
|
|
2024-06-21 04:42:14 +00:00
|
|
|
class HomeScreen;
|
|
|
|
|
|
2023-11-05 05:14:39 +00:00
|
|
|
struct GridPosition {
|
|
|
|
|
Q_GADGET
|
|
|
|
|
public:
|
|
|
|
|
int row;
|
|
|
|
|
int column;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @short Object that represents a widget on the homescreen.
|
|
|
|
|
*/
|
2025-02-21 18:06:24 +00:00
|
|
|
class FolioWidget : public QObject, public std::enable_shared_from_this<FolioWidget>
|
2023-11-05 05:14:39 +00:00
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
2025-07-16 17:02:18 +00:00
|
|
|
QML_ELEMENT
|
|
|
|
|
QML_UNCREATABLE("")
|
|
|
|
|
|
2023-11-05 05:14:39 +00:00
|
|
|
Q_PROPERTY(int id READ id NOTIFY idChanged)
|
|
|
|
|
Q_PROPERTY(int gridWidth READ gridWidth NOTIFY gridWidthChanged)
|
|
|
|
|
Q_PROPERTY(int gridHeight READ gridHeight NOTIFY gridHeightChanged)
|
|
|
|
|
Q_PROPERTY(Plasma::Applet *applet READ applet NOTIFY appletChanged)
|
|
|
|
|
Q_PROPERTY(PlasmaQuick::AppletQuickItem *visualApplet READ visualApplet NOTIFY visualAppletChanged)
|
|
|
|
|
|
|
|
|
|
public:
|
2025-02-21 18:06:24 +00:00
|
|
|
typedef std::shared_ptr<FolioWidget> Ptr;
|
|
|
|
|
|
2025-07-15 00:50:02 +00:00
|
|
|
FolioWidget(HomeScreen *homeScreen = nullptr, int id = -1, int gridWidth = 0, int gridHeight = 0, QObject *parent = nullptr);
|
|
|
|
|
FolioWidget(HomeScreen *homeScreen, Plasma::Applet *applet, int gridWidth, int gridHeight, QObject *parent = nullptr);
|
2023-11-05 05:14:39 +00:00
|
|
|
|
2025-07-15 00:50:02 +00:00
|
|
|
static std::shared_ptr<FolioWidget> fromJson(QJsonObject &obj, HomeScreen *homeScreen);
|
2023-11-05 05:14:39 +00:00
|
|
|
QJsonObject toJson() const;
|
|
|
|
|
|
|
|
|
|
int id() const;
|
|
|
|
|
|
|
|
|
|
int gridWidth() const;
|
|
|
|
|
void setGridWidth(int gridWidth);
|
|
|
|
|
|
|
|
|
|
int gridHeight() const;
|
|
|
|
|
void setGridHeight(int gridHeight);
|
|
|
|
|
|
|
|
|
|
int realGridWidth() const;
|
|
|
|
|
void setRealGridWidth(int gridWidth);
|
|
|
|
|
|
|
|
|
|
int realGridHeight() const;
|
|
|
|
|
void setRealGridHeight(int gridHeight);
|
|
|
|
|
|
|
|
|
|
// takes in the stored position of the widget (top left when in portrait orientation)
|
|
|
|
|
// returns the position of the widget corners on a page grid, factoring in the current page orientation
|
|
|
|
|
GridPosition topLeftCorner(int row, int column);
|
|
|
|
|
|
|
|
|
|
// query whether (row, column) is inside this widget, if it was at position (widgetRow, widgetColumn)
|
|
|
|
|
bool isInBounds(int widgetRow, int widgetColumn, int row, int column);
|
|
|
|
|
|
2025-02-21 18:06:24 +00:00
|
|
|
bool overlapsWidget(int widgetRow, int widgetColumn, std::shared_ptr<FolioWidget> otherWidget, int otherWidgetRow, int otherWidgetColumn);
|
2023-11-05 05:14:39 +00:00
|
|
|
|
|
|
|
|
Plasma::Applet *applet() const;
|
|
|
|
|
void setApplet(Plasma::Applet *applet);
|
|
|
|
|
|
|
|
|
|
PlasmaQuick::AppletQuickItem *visualApplet() const;
|
|
|
|
|
|
|
|
|
|
Q_INVOKABLE void destroyApplet();
|
|
|
|
|
|
|
|
|
|
Q_SIGNALS:
|
|
|
|
|
void idChanged();
|
|
|
|
|
void appletChanged();
|
|
|
|
|
void visualAppletChanged();
|
|
|
|
|
void gridWidthChanged();
|
|
|
|
|
void gridHeightChanged();
|
|
|
|
|
void saveRequested();
|
|
|
|
|
|
|
|
|
|
// when we resize while the screen is rotated, the stored top left position
|
|
|
|
|
// changes, so we need to notify the model
|
|
|
|
|
void realTopLeftPositionChanged(int offsetRows, int offsetColumns);
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
void init();
|
|
|
|
|
void setVisualApplet(PlasmaQuick::AppletQuickItem *quickApplet);
|
|
|
|
|
|
2024-06-21 04:42:14 +00:00
|
|
|
HomeScreen *m_homeScreen{nullptr};
|
|
|
|
|
|
|
|
|
|
int m_id{-1};
|
|
|
|
|
int m_realGridWidth{1};
|
|
|
|
|
int m_realGridHeight{1};
|
2023-11-05 05:14:39 +00:00
|
|
|
|
2024-06-21 04:42:14 +00:00
|
|
|
Plasma::Applet *m_applet{nullptr};
|
|
|
|
|
PlasmaQuick::AppletQuickItem *m_quickApplet{nullptr};
|
2023-11-05 05:14:39 +00:00
|
|
|
};
|