1
0
mirror of https://github.com/KDE/latte-dock.git synced 2025-01-03 21:17:49 +03:00
latte-dock/app/layout/genericlayout.h

225 lines
7.8 KiB
C
Raw Normal View History

/*
2021-05-27 18:01:00 +03:00
SPDX-FileCopyrightText: 2019 Michail Vourlakos <mvourlakos@gmail.com>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#ifndef GENERICLAYOUT_H
#define GENERICLAYOUT_H
// local
#include <coretypes.h>
#include "abstractlayout.h"
#include "../data/errordata.h"
#include "../data/viewdata.h"
2021-03-21 17:54:58 +03:00
#include "../data/viewstable.h"
// Qt
#include <QObject>
#include <QQuickView>
#include <QPointer>
#include <QScreen>
// Plasma
#include <Plasma>
namespace Plasma {
class Applet;
class Containment;
class Types;
}
namespace Latte {
class Corona;
class ScreenPool;
class View;
}
namespace Latte {
namespace Layout {
//! This is views map in the following structure:
//! SCREEN_NAME -> EDGE -> VIEWID
typedef QHash<QString, QHash<Plasma::Types::Location, QList<uint>>> ViewsMap;
class GenericLayout : public AbstractLayout
{
Q_OBJECT
Q_PROPERTY(int viewsCount READ viewsCount NOTIFY viewsCountChanged)
2019-05-02 12:58:56 +03:00
public:
GenericLayout(QObject *parent, QString layoutFile, QString assignedName = QString());
~GenericLayout() override;
QString background() const override;
QString textColor() const override;
virtual const QStringList appliedActivities() = 0; // to move at an interface
fix #96,FEATURE:AllScreens and AllSecondaryScreens --This is a HUGE FEATURE and so important for multi-screens users. It is introduced as one single commit because it reimplements plenty of infrastructure changes and it will be easier to identify newly introduced bugs. --Users can now choose for their docks and panels to belong at various screen groups. The first two screen groups introduced are AllScreens and AllSecondayScreens. In the future it might be possible to provide CustomScreensGroup that the user will be able to define specific screens in which a dock or panel should be always present. --Current solution specifies an Original dock or panel and clones/copies itself automatically to other screens. So docks and panels in other screens are just real docks and panels that reference themselves to original docks and panels. --Clones are destroyed during layout startup and are automaticaly recreated. It is suggested to export your layouts through the official Layouts Editor in order to share them because in that case clones are not included in the new generated layout file. If in any case you do not this and you share your layout with any previous versions then your clones will just appear as separate docks and panels that belong to specific screens. --Automatic syncing was introduced in order to keep up-to-date the configuration of Original docks and panels with their referenced Clones. --Automatic syncing currently works for all docks and panels settings, for all normal applets configurations and for all subcontaiments configuration such as systrays. --Automatic syncing does not work for applets inside subcontainments such as Group Plasmoid. In such case it is suggested to configure your applets inside your Group Plasmoid in the original dock or panel and afterwards to trigger a recreation for the relevant clones --Manual recreation of clones is easily possible by just choosing the dock or panel to be OnPrimary or OnSpecificScreen and rechoosing afterwards the AllScreensGroup or AllSecondaryScreensGroup
2021-12-11 18:39:44 +03:00
virtual bool initCorona();
void importToCorona();
fix #96,FEATURE:AllScreens and AllSecondaryScreens --This is a HUGE FEATURE and so important for multi-screens users. It is introduced as one single commit because it reimplements plenty of infrastructure changes and it will be easier to identify newly introduced bugs. --Users can now choose for their docks and panels to belong at various screen groups. The first two screen groups introduced are AllScreens and AllSecondayScreens. In the future it might be possible to provide CustomScreensGroup that the user will be able to define specific screens in which a dock or panel should be always present. --Current solution specifies an Original dock or panel and clones/copies itself automatically to other screens. So docks and panels in other screens are just real docks and panels that reference themselves to original docks and panels. --Clones are destroyed during layout startup and are automaticaly recreated. It is suggested to export your layouts through the official Layouts Editor in order to share them because in that case clones are not included in the new generated layout file. If in any case you do not this and you share your layout with any previous versions then your clones will just appear as separate docks and panels that belong to specific screens. --Automatic syncing was introduced in order to keep up-to-date the configuration of Original docks and panels with their referenced Clones. --Automatic syncing currently works for all docks and panels settings, for all normal applets configurations and for all subcontaiments configuration such as systrays. --Automatic syncing does not work for applets inside subcontainments such as Group Plasmoid. In such case it is suggested to configure your applets inside your Group Plasmoid in the original dock or panel and afterwards to trigger a recreation for the relevant clones --Manual recreation of clones is easily possible by just choosing the dock or panel to be OnPrimary or OnSpecificScreen and rechoosing afterwards the AllScreensGroup or AllSecondaryScreensGroup
2021-12-11 18:39:44 +03:00
bool initContainments();
void setCorona(Latte::Corona *corona);
bool isActive() const; //! is loaded and running
virtual bool isCurrent();
bool isWritable() const;
fix #96,FEATURE:AllScreens and AllSecondaryScreens --This is a HUGE FEATURE and so important for multi-screens users. It is introduced as one single commit because it reimplements plenty of infrastructure changes and it will be easier to identify newly introduced bugs. --Users can now choose for their docks and panels to belong at various screen groups. The first two screen groups introduced are AllScreens and AllSecondayScreens. In the future it might be possible to provide CustomScreensGroup that the user will be able to define specific screens in which a dock or panel should be always present. --Current solution specifies an Original dock or panel and clones/copies itself automatically to other screens. So docks and panels in other screens are just real docks and panels that reference themselves to original docks and panels. --Clones are destroyed during layout startup and are automaticaly recreated. It is suggested to export your layouts through the official Layouts Editor in order to share them because in that case clones are not included in the new generated layout file. If in any case you do not this and you share your layout with any previous versions then your clones will just appear as separate docks and panels that belong to specific screens. --Automatic syncing was introduced in order to keep up-to-date the configuration of Original docks and panels with their referenced Clones. --Automatic syncing currently works for all docks and panels settings, for all normal applets configurations and for all subcontaiments configuration such as systrays. --Automatic syncing does not work for applets inside subcontainments such as Group Plasmoid. In such case it is suggested to configure your applets inside your Group Plasmoid in the original dock or panel and afterwards to trigger a recreation for the relevant clones --Manual recreation of clones is easily possible by just choosing the dock or panel to be OnPrimary or OnSpecificScreen and rechoosing afterwards the AllScreensGroup or AllSecondaryScreensGroup
2021-12-11 18:39:44 +03:00
bool hasCorona() const;
virtual int viewsCount(int screen) const;
virtual int viewsCount(QScreen *screen) const;
virtual int viewsCount() const;
2019-05-02 12:58:56 +03:00
Type type() const override;
Latte::Corona *corona() const;
QStringList unloadedContainmentsIds();
2020-03-14 15:41:07 +03:00
virtual Types::ViewType latteViewType(uint containmentId) const;
const QList<Plasma::Containment *> *containments() const;
bool contains(Plasma::Containment *containment) const;
bool containsView(const int &containmentId) const;
int screenForContainment(Plasma::Containment *containment);
Latte::View *highestPriorityView();
2020-08-25 19:30:33 +03:00
Latte::View *viewForContainment(uint id) const;
Latte::View *viewForContainment(Plasma::Containment *containment) const;
Plasma::Containment *containmentForId(uint id) const;
QList<Plasma::Containment *> subContainmentsOf(uint id) const;
2020-08-25 19:30:33 +03:00
static bool viewAtLowerScreenPriority(Latte::View *test, Latte::View *base, QScreen *primaryScreen);
2020-08-25 19:30:33 +03:00
static bool viewAtLowerEdgePriority(Latte::View *test, Latte::View *base);
static QList<Latte::View *> sortedLatteViews(QList<Latte::View *> views, QScreen *primaryScreen);
2020-08-25 19:30:33 +03:00
QList<Latte::View *> sortedLatteViews();
virtual QList<Latte::View *> viewsWithPlasmaShortcuts();
virtual QList<Latte::View *> latteViews();
fix #96,FEATURE:AllScreens and AllSecondaryScreens --This is a HUGE FEATURE and so important for multi-screens users. It is introduced as one single commit because it reimplements plenty of infrastructure changes and it will be easier to identify newly introduced bugs. --Users can now choose for their docks and panels to belong at various screen groups. The first two screen groups introduced are AllScreens and AllSecondayScreens. In the future it might be possible to provide CustomScreensGroup that the user will be able to define specific screens in which a dock or panel should be always present. --Current solution specifies an Original dock or panel and clones/copies itself automatically to other screens. So docks and panels in other screens are just real docks and panels that reference themselves to original docks and panels. --Clones are destroyed during layout startup and are automaticaly recreated. It is suggested to export your layouts through the official Layouts Editor in order to share them because in that case clones are not included in the new generated layout file. If in any case you do not this and you share your layout with any previous versions then your clones will just appear as separate docks and panels that belong to specific screens. --Automatic syncing was introduced in order to keep up-to-date the configuration of Original docks and panels with their referenced Clones. --Automatic syncing currently works for all docks and panels settings, for all normal applets configurations and for all subcontaiments configuration such as systrays. --Automatic syncing does not work for applets inside subcontainments such as Group Plasmoid. In such case it is suggested to configure your applets inside your Group Plasmoid in the original dock or panel and afterwards to trigger a recreation for the relevant clones --Manual recreation of clones is easily possible by just choosing the dock or panel to be OnPrimary or OnSpecificScreen and rechoosing afterwards the AllScreensGroup or AllSecondaryScreensGroup
2021-12-11 18:39:44 +03:00
virtual QList<Latte::View *> onlyOriginalViews();
ViewsMap validViewsMap();
virtual void syncLatteViewsToScreens();
void syncToLayoutFile(bool removeLayoutId = false);
void lock(); //! make it only read-only
void renameLayout(QString newName);
virtual void unloadContainments();
void unloadLatteViews();
void unlock(); //! make it writable which it should be the default
virtual void setLastConfigViewFor(Latte::View *view);
virtual Latte::View *lastConfigViewFor();
fix #96,FEATURE:AllScreens and AllSecondaryScreens --This is a HUGE FEATURE and so important for multi-screens users. It is introduced as one single commit because it reimplements plenty of infrastructure changes and it will be easier to identify newly introduced bugs. --Users can now choose for their docks and panels to belong at various screen groups. The first two screen groups introduced are AllScreens and AllSecondayScreens. In the future it might be possible to provide CustomScreensGroup that the user will be able to define specific screens in which a dock or panel should be always present. --Current solution specifies an Original dock or panel and clones/copies itself automatically to other screens. So docks and panels in other screens are just real docks and panels that reference themselves to original docks and panels. --Clones are destroyed during layout startup and are automaticaly recreated. It is suggested to export your layouts through the official Layouts Editor in order to share them because in that case clones are not included in the new generated layout file. If in any case you do not this and you share your layout with any previous versions then your clones will just appear as separate docks and panels that belong to specific screens. --Automatic syncing was introduced in order to keep up-to-date the configuration of Original docks and panels with their referenced Clones. --Automatic syncing currently works for all docks and panels settings, for all normal applets configurations and for all subcontaiments configuration such as systrays. --Automatic syncing does not work for applets inside subcontainments such as Group Plasmoid. In such case it is suggested to configure your applets inside your Group Plasmoid in the original dock or panel and afterwards to trigger a recreation for the relevant clones --Manual recreation of clones is easily possible by just choosing the dock or panel to be OnPrimary or OnSpecificScreen and rechoosing afterwards the AllScreensGroup or AllSecondaryScreensGroup
2021-12-11 18:39:44 +03:00
//! this function needs the layout to have first set the corona through setCorona() function
virtual void addView(Plasma::Containment *containment);
void recreateView(Plasma::Containment *containment, bool delayed = true);
fix #96,FEATURE:AllScreens and AllSecondaryScreens --This is a HUGE FEATURE and so important for multi-screens users. It is introduced as one single commit because it reimplements plenty of infrastructure changes and it will be easier to identify newly introduced bugs. --Users can now choose for their docks and panels to belong at various screen groups. The first two screen groups introduced are AllScreens and AllSecondayScreens. In the future it might be possible to provide CustomScreensGroup that the user will be able to define specific screens in which a dock or panel should be always present. --Current solution specifies an Original dock or panel and clones/copies itself automatically to other screens. So docks and panels in other screens are just real docks and panels that reference themselves to original docks and panels. --Clones are destroyed during layout startup and are automaticaly recreated. It is suggested to export your layouts through the official Layouts Editor in order to share them because in that case clones are not included in the new generated layout file. If in any case you do not this and you share your layout with any previous versions then your clones will just appear as separate docks and panels that belong to specific screens. --Automatic syncing was introduced in order to keep up-to-date the configuration of Original docks and panels with their referenced Clones. --Automatic syncing currently works for all docks and panels settings, for all normal applets configurations and for all subcontaiments configuration such as systrays. --Automatic syncing does not work for applets inside subcontainments such as Group Plasmoid. In such case it is suggested to configure your applets inside your Group Plasmoid in the original dock or panel and afterwards to trigger a recreation for the relevant clones --Manual recreation of clones is easily possible by just choosing the dock or panel to be OnPrimary or OnSpecificScreen and rechoosing afterwards the AllScreensGroup or AllSecondaryScreensGroup
2021-12-11 18:39:44 +03:00
bool hasLatteView(Plasma::Containment *containment);
bool newView(const QString &templateName);
Data::View newView(const Latte::Data::View &nextViewData);
void removeView(const Latte::Data::View &viewData);
void updateView(const Latte::Data::View &viewData);
QString storedView(const int &containmentId); //returns temp filepath containing all view data
void removeOrphanedSubContainment(const int &containmentId);
//! Available edges for specific view in that screen
virtual QList<Plasma::Types::Location> availableEdgesForView(QScreen *scr, Latte::View *forView) const;
//! All free edges in that screen
virtual QList<Plasma::Types::Location> freeEdges(QScreen *scr) const;
virtual QList<Plasma::Types::Location> freeEdges(int screen) const;
//! Bind this latteView and its relevant containments(including subcontainments)
//! to this layout. It is used for moving a Latte::View from layout to layout)
void assignToLayout(Latte::View *latteView, QList<Plasma::Containment *> containments);
//! Unassign that latteView from this layout (this is used for moving a latteView
//! from layout to layout) and returns all the containments relevant to
//! that latteView
QList<Plasma::Containment *> unassignFromLayout(Plasma::Containment *latteContainment);
2021-06-03 20:36:54 +03:00
QList<int> viewsExplicitScreens();
2021-03-21 17:54:58 +03:00
Latte::Data::ViewsTable viewsTable() const;
//! errors/warnings
Data::ErrorsList errors() const;
Data::WarningsList warnings() const;
public slots:
Q_INVOKABLE int viewsWithTasks() const;
virtual Q_INVOKABLE QList<int> qmlFreeEdges(int screen) const; //change <Plasma::Types::Location> to <int> types
void toggleHiddenState(QString viewName, QString screenName, Plasma::Types::Location edge);
signals:
void activitiesChanged(); // to move at an interface
void viewsCountChanged();
void viewEdgeChanged();
//! used from ConfigView(s) in order to be informed which is one should be shown
void lastConfigViewForChanged(Latte::View *view);
//! used from LatteView(s) in order to exist only one each time that has the highest priority
//! to use the global shortcuts activations
void preferredViewForShortcutsChanged(Latte::View *view);
2019-04-07 19:07:24 +03:00
protected:
void updateLastUsedActivity();
protected:
Latte::Corona *m_corona{nullptr};
QList<Plasma::Containment *> m_containments;
QHash<const Plasma::Containment *, Latte::View *> m_latteViews;
QHash<const Plasma::Containment *, Latte::View *> m_waitingLatteViews;
2019-04-07 19:07:24 +03:00
private slots:
void addContainment(Plasma::Containment *containment);
void appletCreated(Plasma::Applet *applet);
void destroyedChanged(bool destroyed);
void containmentDestroyed(QObject *cont);
void onLastConfigViewChangedFrom(Latte::View *view);
2019-04-07 19:07:24 +03:00
private:
//! It can be used in order for LatteViews to not be created automatically when
//! their corresponding containments are created e.g. copyView functionality
bool blockAutomaticLatteViewCreation() const;
void setBlockAutomaticLatteViewCreation(bool block);
bool explicitDockOccupyEdge(int screen, Plasma::Types::Location location) const;
bool primaryDockOccupyEdge(Plasma::Types::Location location) const;
bool viewDataAtLowerEdgePriority(const Latte::Data::View &test, const Latte::Data::View &base) const;
bool viewDataAtLowerScreenPriority(const Latte::Data::View &test, const Latte::Data::View &base) const;
bool viewDataAtLowerStatePriority(const Latte::Data::View &test, const Latte::Data::View &base) const;
2019-07-14 18:23:52 +03:00
bool mapContainsId(const ViewsMap *map, uint viewId) const;
fix #96,FEATURE:AllScreens and AllSecondaryScreens --This is a HUGE FEATURE and so important for multi-screens users. It is introduced as one single commit because it reimplements plenty of infrastructure changes and it will be easier to identify newly introduced bugs. --Users can now choose for their docks and panels to belong at various screen groups. The first two screen groups introduced are AllScreens and AllSecondayScreens. In the future it might be possible to provide CustomScreensGroup that the user will be able to define specific screens in which a dock or panel should be always present. --Current solution specifies an Original dock or panel and clones/copies itself automatically to other screens. So docks and panels in other screens are just real docks and panels that reference themselves to original docks and panels. --Clones are destroyed during layout startup and are automaticaly recreated. It is suggested to export your layouts through the official Layouts Editor in order to share them because in that case clones are not included in the new generated layout file. If in any case you do not this and you share your layout with any previous versions then your clones will just appear as separate docks and panels that belong to specific screens. --Automatic syncing was introduced in order to keep up-to-date the configuration of Original docks and panels with their referenced Clones. --Automatic syncing currently works for all docks and panels settings, for all normal applets configurations and for all subcontaiments configuration such as systrays. --Automatic syncing does not work for applets inside subcontainments such as Group Plasmoid. In such case it is suggested to configure your applets inside your Group Plasmoid in the original dock or panel and afterwards to trigger a recreation for the relevant clones --Manual recreation of clones is easily possible by just choosing the dock or panel to be OnPrimary or OnSpecificScreen and rechoosing afterwards the AllScreensGroup or AllSecondaryScreensGroup
2021-12-11 18:39:44 +03:00
QString mapScreenName(const ViewsMap *map, uint viewId) const;
QList<int> subContainmentsOf(Plasma::Containment *containment) const;
2019-07-14 18:23:52 +03:00
QList<Latte::Data::View> sortedViewsData(const QList<Latte::Data::View> &viewsData);
2019-07-14 18:23:52 +03:00
void destroyContainment(Plasma::Containment *containment);
private:
bool m_blockAutomaticLatteViewCreation{false};
fix #96,FEATURE:AllScreens and AllSecondaryScreens --This is a HUGE FEATURE and so important for multi-screens users. It is introduced as one single commit because it reimplements plenty of infrastructure changes and it will be easier to identify newly introduced bugs. --Users can now choose for their docks and panels to belong at various screen groups. The first two screen groups introduced are AllScreens and AllSecondayScreens. In the future it might be possible to provide CustomScreensGroup that the user will be able to define specific screens in which a dock or panel should be always present. --Current solution specifies an Original dock or panel and clones/copies itself automatically to other screens. So docks and panels in other screens are just real docks and panels that reference themselves to original docks and panels. --Clones are destroyed during layout startup and are automaticaly recreated. It is suggested to export your layouts through the official Layouts Editor in order to share them because in that case clones are not included in the new generated layout file. If in any case you do not this and you share your layout with any previous versions then your clones will just appear as separate docks and panels that belong to specific screens. --Automatic syncing was introduced in order to keep up-to-date the configuration of Original docks and panels with their referenced Clones. --Automatic syncing currently works for all docks and panels settings, for all normal applets configurations and for all subcontaiments configuration such as systrays. --Automatic syncing does not work for applets inside subcontainments such as Group Plasmoid. In such case it is suggested to configure your applets inside your Group Plasmoid in the original dock or panel and afterwards to trigger a recreation for the relevant clones --Manual recreation of clones is easily possible by just choosing the dock or panel to be OnPrimary or OnSpecificScreen and rechoosing afterwards the AllScreensGroup or AllSecondaryScreensGroup
2021-12-11 18:39:44 +03:00
bool m_hasInitializedContainments{false};
QPointer<Latte::View> m_lastConfigViewFor;
QStringList m_unloadedContainmentsIds;
2019-06-20 11:21:12 +03:00
//! try to avoid crashes from recreating the same views all the time
QList<const Plasma::Containment *> m_viewsToRecreate;
//! Containments that are pending screen/state updates
Latte::Data::ViewsTable m_pendingContainmentUpdates;
friend class Latte::View;
};
}
}
#endif