2019-04-05 19:59:15 +03:00
/*
* Copyright 2019 Michail Vourlakos < mvourlakos @ gmail . com >
*
* This file is part of Latte - Dock
*
* Latte - Dock is free software ; you can redistribute it and / or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation ; either version 2 of
* the License , or ( at your option ) any later version .
*
* Latte - Dock is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program . If not , see < http : //www.gnu.org/licenses/>.
*/
# ifndef GENERICLAYOUT_H
# define GENERICLAYOUT_H
// local
2020-04-24 14:52:16 +03:00
# include <coretypes.h>
2019-04-05 19:59:15 +03:00
# include "abstractlayout.h"
// Qt
# include <QObject>
2019-04-06 02:00:37 +03:00
# include <QQuickView>
2019-04-06 18:56:24 +03:00
# include <QPointer>
2019-04-06 02:00:37 +03:00
# include <QScreen>
// Plasma
# include <Plasma>
namespace Plasma {
class Applet ;
class Containment ;
class Types ;
}
namespace Latte {
class Corona ;
2019-07-14 23:44:16 +03:00
class ScreenPool ;
2019-04-06 02:00:37 +03:00
class View ;
}
2019-04-05 19:59:15 +03:00
namespace Latte {
namespace Layout {
2019-07-14 18:23:52 +03:00
struct ViewData
{
int id ; //view id
bool active ; //is active
bool onPrimary ; //on primary
int screenId ; //explicit screen id
int location ; //edge location
2020-08-19 16:26:08 +03:00
QList < int > subContainments ;
2019-07-14 18:23:52 +03:00
} ;
2019-04-07 01:16:59 +03:00
//! This is views map in the following structure:
//! SCREEN_NAME -> EDGE -> VIEWID
2020-03-07 19:30:22 +03:00
typedef QHash < QString , QHash < Plasma : : Types : : Location , QList < uint > > > ViewsMap ;
2019-04-07 01:16:59 +03:00
2019-04-05 19:59:15 +03:00
class GenericLayout : public AbstractLayout
{
Q_OBJECT
2019-04-06 02:00:37 +03:00
Q_PROPERTY ( int viewsCount READ viewsCount NOTIFY viewsCountChanged )
2019-04-05 19:59:15 +03:00
2019-05-02 12:58:56 +03:00
public :
2019-04-05 20:39:19 +03:00
GenericLayout ( QObject * parent , QString layoutFile , QString assignedName = QString ( ) ) ;
2019-04-05 19:59:15 +03:00
~ GenericLayout ( ) override ;
2019-04-06 02:00:37 +03:00
2020-07-30 18:09:49 +03:00
QString background ( ) const override ;
QString textColor ( ) const override ;
2019-04-06 02:00:37 +03:00
virtual const QStringList appliedActivities ( ) = 0 ; // to move at an interface
void importToCorona ( ) ;
bool initToCorona ( Latte : : Corona * corona ) ;
2019-05-04 03:01:16 +03:00
bool isActive ( ) const ; //! is loaded and running
2020-08-26 00:15:06 +03:00
virtual bool isCurrent ( ) ;
2019-04-06 02:00:37 +03:00
bool isWritable ( ) const ;
2020-08-18 02:15:28 +03:00
bool isBroken ( ) const ;
2019-04-06 02:00:37 +03:00
2019-04-07 23:02:13 +03:00
virtual int viewsCount ( int screen ) const ;
virtual int viewsCount ( QScreen * screen ) const ;
virtual int viewsCount ( ) const ;
2019-04-06 02:00:37 +03:00
2019-05-02 12:58:56 +03:00
Type type ( ) const override ;
2020-08-18 01:44:10 +03:00
Latte : : Corona * corona ( ) const ;
2019-04-07 15:46:03 +03:00
2019-04-06 02:00:37 +03:00
QStringList unloadedContainmentsIds ( ) ;
2020-03-14 15:41:07 +03:00
virtual Types : : ViewType latteViewType ( uint containmentId ) const ;
2020-08-18 02:15:28 +03:00
const QList < Plasma : : Containment * > * containments ( ) const ;
2019-04-06 02:00:37 +03:00
Latte : : View * highestPriorityView ( ) ;
2020-08-25 19:30:33 +03:00
Latte : : View * viewForContainment ( uint id ) const ;
2020-08-18 02:56:33 +03:00
Latte : : View * viewForContainment ( Plasma : : Containment * containment ) const ;
2020-08-25 19:30:33 +03:00
static bool viewAtLowerScreenPriority ( Latte : : View * test , Latte : : View * base ) ;
static bool viewAtLowerEdgePriority ( Latte : : View * test , Latte : : View * base ) ;
static QList < Latte : : View * > sortedLatteViews ( QList < Latte : : View * > views ) ;
QList < Latte : : View * > sortedLatteViews ( ) ;
2019-04-07 23:02:13 +03:00
virtual QList < Latte : : View * > viewsWithPlasmaShortcuts ( ) ;
2019-04-07 19:35:55 +03:00
virtual QList < Latte : : View * > latteViews ( ) ;
2019-04-08 18:57:32 +03:00
ViewsMap validViewsMap ( ViewsMap * occupiedMap = nullptr ) ;
virtual void syncLatteViewsToScreens ( Layout : : ViewsMap * occupiedMap = nullptr ) ;
2019-04-06 02:00:37 +03:00
void syncToLayoutFile ( bool removeLayoutId = false ) ;
void lock ( ) ; //! make it only read-only
void renameLayout ( QString newName ) ;
2019-04-07 17:20:10 +03:00
virtual void unloadContainments ( ) ;
2019-04-06 02:00:37 +03:00
void unloadLatteViews ( ) ;
void unlock ( ) ; //! make it writable which it should be the default
2019-05-25 17:49:02 +03:00
virtual void setLastConfigViewFor ( Latte : : View * view ) ;
2019-05-25 18:05:24 +03:00
virtual Latte : : View * lastConfigViewFor ( ) ;
2019-05-25 17:40:29 +03:00
2019-04-06 02:00:37 +03:00
//! this function needs the layout to have first set the corona through initToCorona() function
2019-04-08 22:02:50 +03:00
virtual void addView ( Plasma : : Containment * containment , bool forceOnPrimary = false , int explicitScreen = - 1 , Layout : : ViewsMap * occupied = nullptr ) ;
2019-04-06 02:00:37 +03:00
void copyView ( Plasma : : Containment * containment ) ;
2019-06-20 17:42:49 +03:00
void recreateView ( Plasma : : Containment * containment , bool delayed = true ) ;
2019-04-06 02:00:37 +03:00
bool latteViewExists ( Plasma : : Containment * containment ) ;
//! Available edges for specific view in that screen
2019-04-07 23:02:13 +03:00
virtual QList < Plasma : : Types : : Location > availableEdgesForView ( QScreen * scr , Latte : : View * forView ) const ;
2019-04-06 02:00:37 +03:00
//! All free edges in that screen
2019-04-07 23:02:13 +03:00
virtual QList < Plasma : : Types : : Location > freeEdges ( QScreen * scr ) const ;
virtual QList < Plasma : : Types : : Location > freeEdges ( int screen ) const ;
2019-04-06 02:00:37 +03:00
2020-08-19 16:26:08 +03:00
//! Bind this latteView and its relevant containments(including subcontainments)
2019-04-06 02:00:37 +03:00
//! 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 ( Latte : : View * latteView ) ;
2019-07-14 23:44:16 +03:00
QString reportHtml ( const ScreenPool * screenPool ) ;
2019-07-14 13:59:02 +03:00
QList < int > viewsScreens ( ) ;
2019-04-06 02:00:37 +03:00
public slots :
2021-02-06 01:14:11 +03:00
Q_INVOKABLE void newView ( const QString & templateFile ) ;
2019-04-06 02:00:37 +03:00
Q_INVOKABLE int viewsWithTasks ( ) const ;
2019-04-07 23:02:13 +03:00
virtual Q_INVOKABLE QList < int > qmlFreeEdges ( int screen ) const ; //change <Plasma::Types::Location> to <int> types
2019-04-06 02:00:37 +03:00
2020-03-01 18:19:24 +03:00
void toggleHiddenState ( QString screenName , Plasma : : Types : : Location edge ) ;
2019-04-06 02:00:37 +03:00
signals :
void activitiesChanged ( ) ; // to move at an interface
void viewsCountChanged ( ) ;
2019-05-09 23:45:52 +03:00
void viewEdgeChanged ( ) ;
2019-04-06 02:00:37 +03:00
//! used from ConfigView(s) in order to be informed which is one should be shown
2019-05-25 17:40:29 +03:00
void lastConfigViewForChanged ( Latte : : View * view ) ;
2019-04-06 02:00:37 +03:00
//! 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 ( ) ;
2019-04-06 02:00:37 +03:00
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 ) ;
2020-08-26 00:41:13 +03:00
void onLastConfigViewChangedFrom ( Latte : : View * view ) ;
2019-04-07 15:46:03 +03:00
2019-04-07 19:07:24 +03:00
private :
2019-04-06 02:00:37 +03:00
//! 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 ;
2019-07-14 18:23:52 +03:00
bool viewDataAtLowerEdgePriority ( const ViewData & test , const ViewData & base ) const ;
bool viewDataAtLowerScreenPriority ( const ViewData & test , const ViewData & base ) const ;
bool viewDataAtLowerStatePriority ( const ViewData & test , const ViewData & base ) const ;
2019-04-07 01:16:59 +03:00
bool mapContainsId ( const ViewsMap * map , uint viewId ) const ;
2020-08-19 16:26:08 +03:00
QList < int > subContainmentsOf ( Plasma : : Containment * containment ) const ;
2019-07-14 18:23:52 +03:00
QList < ViewData > sortedViewsData ( const QList < ViewData > & viewsData ) ;
2019-04-06 02:00:37 +03:00
private :
bool m_blockAutomaticLatteViewCreation { false } ;
2019-05-25 17:40:29 +03:00
QPointer < Latte : : View > m_lastConfigViewFor ;
2019-04-06 02:00:37 +03:00
QStringList m_unloadedContainmentsIds ;
2019-04-06 18:56:24 +03:00
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 ;
2019-05-09 23:45:52 +03:00
friend class Latte : : View ;
2019-04-05 19:59:15 +03:00
} ;
}
}
# endif