2021-03-02 20:33:24 +03:00
/*
2021-05-27 18:01:00 +03:00
SPDX - FileCopyrightText : 2021 Michail Vourlakos < mvourlakos @ gmail . com >
SPDX - License - Identifier : GPL - 2.0 - or - later
2021-03-02 20:33:24 +03:00
*/
# ifndef CONTAINMENTLAYOUTMANAGER_H
# define CONTAINMENTLAYOUTMANAGER_H
//Qt
2021-03-06 13:44:08 +03:00
# include <QHash>
2021-03-05 12:11:12 +03:00
# include <QMetaMethod>
2021-03-02 20:33:24 +03:00
# include <QObject>
2021-03-03 21:17:58 +03:00
# include <QQmlPropertyMap>
2021-03-02 20:33:24 +03:00
# include <QQuickItem>
2021-05-05 22:27:30 +03:00
# include <QTimer>
2021-03-02 20:33:24 +03:00
2021-03-05 12:11:12 +03:00
namespace KDeclarative {
class ConfigPropertyMap ;
}
2021-03-02 20:33:24 +03:00
namespace Latte {
namespace Containment {
class LayoutManager : public QObject
{
2021-12-11 18:39:44 +03:00
Q_OBJECT
2021-03-03 21:17:58 +03:00
Q_PROPERTY ( QObject * plasmoidObj READ plasmoid ( ) WRITE setPlasmoid NOTIFY plasmoidChanged )
Q_PROPERTY ( QQuickItem * rootItem READ rootItem WRITE setRootItem NOTIFY rootItemChanged )
2021-03-02 20:33:24 +03:00
Q_PROPERTY ( QQuickItem * mainLayout READ mainLayout WRITE setMainLayout NOTIFY mainLayoutChanged )
Q_PROPERTY ( QQuickItem * startLayout READ startLayout WRITE setStartLayout NOTIFY startLayoutChanged )
Q_PROPERTY ( QQuickItem * endLayout READ endLayout WRITE setEndLayout NOTIFY endLayoutChanged )
2021-03-04 20:39:11 +03:00
Q_PROPERTY ( QQuickItem * dndSpacerItem READ dndSpacer WRITE setDndSpacer NOTIFY dndSpacerChanged )
2021-03-03 21:17:58 +03:00
Q_PROPERTY ( QQuickItem * metrics READ metrics WRITE setMetrics NOTIFY metricsChanged )
2021-05-05 22:27:30 +03:00
Q_PROPERTY ( bool hasRestoredApplets READ hasRestoredApplets NOTIFY hasRestoredAppletsChanged )
2021-03-05 12:11:12 +03:00
//! this is the only way I have found to write their values properly in the configuration file in Multiple mode
//! if they are not used from qml side in the form of plasmoid.configuration..... then
//! appletsOrder is not stored when needed and applets additions/removals are not valid on next startup
Q_PROPERTY ( int splitterPosition READ splitterPosition NOTIFY splitterPositionChanged )
Q_PROPERTY ( int splitterPosition2 READ splitterPosition2 NOTIFY splitterPosition2Changed )
2021-12-11 18:39:44 +03:00
Q_PROPERTY ( QList < int > appletOrder READ appletOrder NOTIFY appletOrderChanged )
Q_PROPERTY ( QList < int > order READ order NOTIFY orderChanged ) //includes also splitters
Q_PROPERTY ( QList < int > lockedZoomApplets READ lockedZoomApplets NOTIFY lockedZoomAppletsChanged )
Q_PROPERTY ( QList < int > userBlocksColorizingApplets READ userBlocksColorizingApplets NOTIFY userBlocksColorizingAppletsChanged )
Q_PROPERTY ( QList < int > appletsInScheduledDestruction READ appletsInScheduledDestruction NOTIFY appletsInScheduledDestructionChanged )
2021-03-05 12:11:12 +03:00
2021-03-02 20:33:24 +03:00
public :
2021-12-11 18:39:44 +03:00
static const int JUSTIFYSPLITTERID = - 10 ;
2021-03-02 20:33:24 +03:00
LayoutManager ( QObject * parent = nullptr ) ;
2021-05-05 22:27:30 +03:00
bool hasRestoredApplets ( ) const ;
2021-03-05 12:11:12 +03:00
int splitterPosition ( ) const ;
int splitterPosition2 ( ) const ;
2021-12-11 18:39:44 +03:00
QList < int > appletOrder ( ) const ;
QList < int > lockedZoomApplets ( ) const ;
QList < int > order ( ) const ;
QList < int > userBlocksColorizingApplets ( ) const ;
QList < int > appletsInScheduledDestruction ( ) const ;
2021-03-05 12:11:12 +03:00
2021-03-03 21:17:58 +03:00
QObject * plasmoid ( ) const ;
void setPlasmoid ( QObject * plasmoid ) ;
QQuickItem * rootItem ( ) const ;
void setRootItem ( QQuickItem * root ) ;
2021-03-02 20:33:24 +03:00
QQuickItem * mainLayout ( ) const ;
void setMainLayout ( QQuickItem * main ) ;
QQuickItem * startLayout ( ) const ;
void setStartLayout ( QQuickItem * start ) ;
QQuickItem * endLayout ( ) const ;
void setEndLayout ( QQuickItem * end ) ;
2021-03-04 20:39:11 +03:00
QQuickItem * dndSpacer ( ) const ;
void setDndSpacer ( QQuickItem * dnd ) ;
2021-03-03 21:17:58 +03:00
QQuickItem * metrics ( ) const ;
void setMetrics ( QQuickItem * metrics ) ;
2021-03-02 20:33:24 +03:00
public slots :
2021-03-05 12:11:12 +03:00
Q_INVOKABLE void restore ( ) ;
Q_INVOKABLE void save ( ) ;
2021-03-06 13:44:08 +03:00
Q_INVOKABLE void saveOptions ( ) ;
2021-12-11 18:39:44 +03:00
Q_INVOKABLE void setOption ( const int & appletId , const QString & property , const QVariant & value ) ;
2021-03-06 13:44:08 +03:00
2021-03-06 14:20:32 +03:00
Q_INVOKABLE void addAppletItem ( QObject * applet , int x , int y ) ;
2021-12-11 18:39:44 +03:00
Q_INVOKABLE void addAppletItem ( QObject * applet , int index ) ;
2021-03-06 13:44:08 +03:00
Q_INVOKABLE void removeAppletItem ( QObject * applet ) ;
2021-03-05 12:11:12 +03:00
2021-03-06 12:01:14 +03:00
Q_INVOKABLE void addJustifySplittersInMainLayout ( ) ;
Q_INVOKABLE void moveAppletsBasedOnJustifyAlignment ( ) ;
2021-03-04 11:50:20 +03:00
Q_INVOKABLE void joinLayoutsToMainLayout ( ) ;
2021-03-03 21:28:46 +03:00
Q_INVOKABLE void insertBefore ( QQuickItem * hoveredItem , QQuickItem * item ) ;
Q_INVOKABLE void insertAfter ( QQuickItem * hoveredItem , QQuickItem * item ) ;
2021-03-03 21:17:58 +03:00
Q_INVOKABLE void insertAtCoordinates ( QQuickItem * item , const int & x , const int & y ) ;
2021-03-02 20:33:24 +03:00
2021-12-11 18:39:44 +03:00
Q_INVOKABLE int dndSpacerIndex ( ) ;
Q_INVOKABLE bool isMasqueradedIndex ( const int & x , const int & y ) ;
Q_INVOKABLE int masquearadedIndex ( const int & x , const int & y ) ;
Q_INVOKABLE QPoint indexToMasquearadedPoint ( const int & index ) ;
void requestAppletsOrder ( const QList < int > & order ) ;
void requestAppletsInLockedZoom ( const QList < int > & applets ) ;
void requestAppletsDisabledColoring ( const QList < int > & applets ) ;
void setAppletInScheduledDestruction ( const int & id , const bool & enabled ) ;
2021-03-02 20:33:24 +03:00
signals :
2021-03-05 12:11:12 +03:00
void appletOrderChanged ( ) ;
2021-12-11 18:39:44 +03:00
void appletsInScheduledDestructionChanged ( ) ;
2021-05-05 22:27:30 +03:00
void hasRestoredAppletsChanged ( ) ;
2021-03-03 21:17:58 +03:00
void plasmoidChanged ( ) ;
void rootItemChanged ( ) ;
2021-03-04 20:39:11 +03:00
void dndSpacerChanged ( ) ;
2021-03-06 12:32:26 +03:00
void lockedZoomAppletsChanged ( ) ;
2021-03-06 12:46:43 +03:00
void userBlocksColorizingAppletsChanged ( ) ;
2021-03-02 20:33:24 +03:00
void mainLayoutChanged ( ) ;
2021-03-03 21:17:58 +03:00
void metricsChanged ( ) ;
2021-12-11 18:39:44 +03:00
void orderChanged ( ) ;
2021-03-05 12:11:12 +03:00
void splitterPositionChanged ( ) ;
void splitterPosition2Changed ( ) ;
2021-03-02 20:33:24 +03:00
void startLayoutChanged ( ) ;
void endLayoutChanged ( ) ;
2021-03-05 12:11:12 +03:00
private slots :
void onRootItemChanged ( ) ;
2021-03-06 11:28:28 +03:00
void destroyJustifySplitters ( ) ;
2021-12-11 18:39:44 +03:00
void updateOrder ( ) ;
void cleanupOptions ( ) ;
2022-02-27 11:26:53 +03:00
void reorderParabolicSpacers ( ) ;
2021-12-11 18:39:44 +03:00
2021-03-02 20:33:24 +03:00
private :
2021-03-06 12:46:43 +03:00
void restoreOptions ( ) ;
2021-03-06 13:44:08 +03:00
void restoreOption ( const char * option ) ;
void saveOption ( const char * option ) ;
2021-03-06 12:46:43 +03:00
2021-12-11 18:39:44 +03:00
void destroyAppletContainer ( QObject * applet ) ;
void initSaveConnections ( ) ;
2021-04-15 19:05:19 +03:00
void insertAtLayoutTail ( QQuickItem * layout , QQuickItem * item ) ;
void insertAtLayoutHead ( QQuickItem * layout , QQuickItem * item ) ;
2022-02-27 11:26:53 +03:00
void insertAtLayoutIndex ( QQuickItem * layout , QQuickItem * item , const int & index ) ;
2021-04-15 19:05:19 +03:00
2021-03-05 12:11:12 +03:00
void setSplitterPosition ( const int & position ) ;
void setSplitterPosition2 ( const int & position ) ;
2021-12-11 18:39:44 +03:00
void setAppletOrder ( const QList < int > & order ) ;
void setOrder ( const QList < int > & order ) ;
void setLockedZoomApplets ( const QList < int > & applets ) ;
void setUserBlocksColorizingApplets ( const QList < int > & applets ) ;
2021-03-05 12:11:12 +03:00
2021-03-06 14:20:32 +03:00
void reorderSplitterInStartLayout ( ) ;
void reorderSplitterInEndLayout ( ) ;
2021-12-11 18:39:44 +03:00
bool isJustifySplitter ( const QQuickItem * item ) const ;
2021-03-05 13:54:53 +03:00
bool isValidApplet ( const int & id ) ;
2021-03-03 21:17:58 +03:00
bool insertAtLayoutCoordinates ( QQuickItem * layout , QQuickItem * item , int x , int y ) ;
2021-04-15 19:05:19 +03:00
int distanceFromTail ( QQuickItem * layout , QPointF pos ) const ;
int distanceFromHead ( QQuickItem * layout , QPointF pos ) const ;
2021-12-11 18:39:44 +03:00
QQuickItem * firstSplitter ( ) ;
QQuickItem * lastSplitter ( ) ;
QQuickItem * appletItem ( const int & id ) ;
QQuickItem * appletItemInLayout ( QQuickItem * layout , const int & id ) ;
2022-02-27 11:26:53 +03:00
void printAppletList ( QList < QQuickItem * > list ) ;
2021-12-11 18:39:44 +03:00
QList < int > toIntList ( const QString & serialized ) ;
QString toStr ( const QList < int > & list ) ;
2021-03-03 21:17:58 +03:00
private :
2021-12-11 18:39:44 +03:00
//! This is needed in order to overcome plasma frameworks limitations and instead of adding dropped widgets
//! based on coordinates, to be able to add them directly at the correct index
static const int MASQUERADEDINDEXTOPOINTBASE = - 23456 ;
2021-03-05 12:11:12 +03:00
int m_splitterPosition { - 1 } ;
int m_splitterPosition2 { - 1 } ;
2021-12-11 18:39:44 +03:00
QList < int > m_appletOrder ;
QList < int > m_lockedZoomApplets ;
QList < int > m_order ;
QList < int > m_userBlocksColorizingApplets ;
2021-03-05 12:11:12 +03:00
2021-03-03 21:17:58 +03:00
QQuickItem * m_rootItem { nullptr } ;
2021-03-04 20:39:11 +03:00
QQuickItem * m_dndSpacer { nullptr } ;
2021-03-03 21:17:58 +03:00
2021-03-02 20:33:24 +03:00
QQuickItem * m_mainLayout { nullptr } ;
QQuickItem * m_startLayout { nullptr } ;
QQuickItem * m_endLayout { nullptr } ;
2021-03-03 21:17:58 +03:00
QQuickItem * m_metrics { nullptr } ;
2021-03-02 20:33:24 +03:00
2021-03-03 21:17:58 +03:00
QObject * m_plasmoid { nullptr } ;
2021-03-05 12:11:12 +03:00
KDeclarative : : ConfigPropertyMap * m_configuration { nullptr } ;
2021-12-11 18:39:44 +03:00
QHash < int , QQuickItem * > m_appletsInScheduledDestruction ;
2021-03-05 12:11:12 +03:00
QMetaMethod m_createAppletItemMethod ;
QMetaMethod m_createJustifySplitterMethod ;
2021-12-11 18:39:44 +03:00
QMetaMethod m_initAppletContainerMethod ;
2021-03-06 13:44:08 +03:00
2021-05-05 22:27:30 +03:00
bool m_hasRestoredApplets { false } ;
QTimer m_hasRestoredAppletsTimer ;
2021-03-06 13:44:08 +03:00
//! first QString is the option in AppletItem
//! second QString is how the option is stored in
QHash < QString , QString > m_option ;
2021-03-02 20:33:24 +03:00
} ;
}
}
# endif // CONTAINMENTLAYOUTMANAGER_H