2016-12-31 00:22:28 +03:00
/*
2017-01-03 01:05:30 +03:00
* Copyright 2016 Smith AR < audoban @ openmailbox . org >
* 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/>.
*/
2016-12-31 00:22:28 +03:00
2016-12-31 00:25:27 +03:00
# include "dockview.h"
# include "dockconfigview.h"
2016-12-31 03:26:48 +03:00
# include "dockcorona.h"
2017-03-18 14:21:17 +03:00
# include "globalsettings.h"
2017-01-31 22:25:00 +03:00
# include "panelshadows_p.h"
2017-03-18 14:21:17 +03:00
# include "visibilitymanager.h"
2017-01-13 10:07:27 +03:00
# include "../liblattedock/extras.h"
2016-12-31 00:22:28 +03:00
# include <QAction>
# include <QQmlContext>
# include <QQmlEngine>
# include <QQmlProperty>
# include <QQuickItem>
2017-01-03 16:33:30 +03:00
# include <QMenu>
2016-12-31 00:22:28 +03:00
# include <QMetaEnum>
# include <KActionCollection>
2017-01-03 16:33:30 +03:00
# include <KAuthorized>
2016-12-31 00:22:28 +03:00
# include <KLocalizedContext>
2017-01-03 16:33:30 +03:00
# include <KLocalizedString>
2017-03-04 13:49:48 +03:00
# include <KWindowEffects>
2017-03-12 21:18:18 +03:00
# include <KWindowSystem>
2017-01-03 16:33:30 +03:00
# include <Plasma/Containment>
# include <Plasma/ContainmentActions>
# include <PlasmaQuick/AppletQuickItem>
2016-12-31 00:22:28 +03:00
namespace Latte {
2017-03-19 00:32:27 +03:00
//! both alwaysVisible and dockWinBehavior are passed through corona because
//! during the dock window creation containment hasnt been set, but these variables
//! are needed in order for window flags to be set correctly
2017-04-09 21:42:39 +03:00
DockView : : DockView ( Plasma : : Corona * corona , QScreen * targetScreen , bool dockWindowBehavior )
2017-01-03 16:33:30 +03:00
: PlasmaQuick : : ContainmentView ( corona ) ,
2017-01-13 09:27:26 +03:00
m_contextMenu ( nullptr )
2017-02-27 10:36:30 +03:00
{
2016-12-31 00:22:28 +03:00
setVisible ( false ) ;
setTitle ( corona - > kPackage ( ) . metadata ( ) . name ( ) ) ;
2017-03-11 21:36:43 +03:00
setIcon ( qGuiApp - > windowIcon ( ) ) ;
2016-12-31 00:22:28 +03:00
setResizeMode ( QuickViewSharedEngine : : SizeRootObjectToView ) ;
2017-03-12 21:18:18 +03:00
setColor ( QColor ( Qt : : transparent ) ) ;
2016-12-31 00:22:28 +03:00
setClearBeforeRendering ( true ) ;
2017-03-08 22:00:09 +03:00
2017-04-09 21:42:39 +03:00
const auto flags = Qt : : FramelessWindowHint
2017-04-11 12:10:54 +03:00
| Qt : : WindowStaysOnTopHint
| Qt : : NoDropShadowWindowHint
| Qt : : WindowDoesNotAcceptFocus ;
2017-04-09 21:42:39 +03:00
if ( dockWindowBehavior ) {
setFlags ( flags ) ;
2017-03-08 22:00:09 +03:00
} else {
2017-04-09 21:42:39 +03:00
setFlags ( flags | Qt : : BypassWindowManagerHint ) ;
2017-03-08 22:00:09 +03:00
}
2017-01-16 22:07:49 +03:00
2017-03-29 14:32:32 +03:00
KWindowSystem : : setOnAllDesktops ( winId ( ) , true ) ;
2016-12-31 00:22:28 +03:00
if ( targetScreen )
2017-02-25 16:29:05 +03:00
setScreenToFollow ( targetScreen ) ;
2016-12-31 00:22:28 +03:00
else
2017-02-25 16:29:05 +03:00
setScreenToFollow ( qGuiApp - > primaryScreen ( ) ) ;
2017-01-16 22:07:49 +03:00
2016-12-31 00:25:27 +03:00
connect ( this , & DockView : : containmentChanged
2017-02-27 13:44:51 +03:00
, this , [ & ] ( ) {
2017-02-12 11:02:01 +03:00
if ( ! this - > containment ( ) )
2016-12-31 00:22:28 +03:00
return ;
2017-02-27 01:53:27 +03:00
restoreConfig ( ) ;
reconsiderScreen ( ) ;
2017-01-16 22:07:49 +03:00
2016-12-31 00:22:28 +03:00
if ( ! m_visibility ) {
m_visibility = new VisibilityManager ( this ) ;
}
2017-01-16 22:07:49 +03:00
2017-02-12 11:02:01 +03:00
QAction * lockWidgetsAction = this - > containment ( ) - > actions ( ) - > action ( " lock widgets " ) ;
this - > containment ( ) - > actions ( ) - > removeAction ( lockWidgetsAction ) ;
2017-01-05 01:28:25 +03:00
QAction * removeAction = containment ( ) - > actions ( ) - > action ( " remove " ) ;
removeAction - > setVisible ( false ) ;
//containment()->actions()->removeAction(removeAction);
2017-01-03 17:17:28 +03:00
//FIX: hide and not delete in order to disable a nasty behavior from
//ContainmentInterface. If only one action exists for containment the
//this action is triggered directly
2017-02-12 11:02:01 +03:00
QAction * addWidgetsAction = this - > containment ( ) - > actions ( ) - > action ( " add widgets " ) ;
2017-01-03 17:17:28 +03:00
addWidgetsAction - > setVisible ( false ) ;
//containment()->actions()->removeAction(addWidgetsAction);
2017-02-12 11:02:01 +03:00
connect ( this - > containment ( ) , SIGNAL ( statusChanged ( Plasma : : Types : : ItemStatus ) ) , SLOT ( statusChanged ( Plasma : : Types : : ItemStatus ) ) ) ;
2016-12-31 00:22:28 +03:00
} , Qt : : DirectConnection ) ;
2017-01-16 21:24:46 +03:00
auto * dockCorona = qobject_cast < DockCorona * > ( this - > corona ( ) ) ;
2017-01-16 22:07:49 +03:00
2017-01-22 14:29:40 +03:00
if ( dockCorona ) {
2017-01-16 21:24:46 +03:00
connect ( dockCorona , & DockCorona : : docksCountChanged , this , & DockView : : docksCountChanged ) ;
2017-01-22 14:29:40 +03:00
connect ( dockCorona , & DockCorona : : dockLocationChanged , this , & DockView : : dockLocationChanged ) ;
2017-02-28 00:21:14 +03:00
connect ( dockCorona , & DockCorona : : dockLocationChanged , this , [ & ] ( ) {
2017-03-02 19:07:29 +03:00
//! check if an edge has been freed for a primary dock
//! from another screen
2017-03-01 17:59:04 +03:00
if ( m_onPrimary ) {
2017-02-28 00:21:14 +03:00
m_screenSyncTimer . start ( ) ;
}
} ) ;
2017-01-22 14:29:40 +03:00
}
2017-02-26 20:15:20 +03:00
m_screenSyncTimer . setSingleShot ( true ) ;
2017-03-01 21:49:21 +03:00
m_screenSyncTimer . setInterval ( 2000 ) ;
2017-02-26 20:15:20 +03:00
connect ( & m_screenSyncTimer , & QTimer : : timeout , this , & DockView : : reconsiderScreen ) ;
2016-12-31 00:22:28 +03:00
}
2016-12-31 00:25:27 +03:00
DockView : : ~ DockView ( )
2016-12-31 00:22:28 +03:00
{
2017-02-28 00:24:13 +03:00
m_screenSyncTimer . stop ( ) ;
2017-03-18 02:53:44 +03:00
2017-01-05 18:48:27 +03:00
qDebug ( ) < < " dock view deleting... " ;
2017-01-22 01:40:16 +03:00
rootContext ( ) - > setContextProperty ( QStringLiteral ( " dock " ) , nullptr ) ;
2017-01-16 22:07:49 +03:00
2017-03-13 21:58:31 +03:00
//! this disconnect does not free up connections correctly when
//! dockView is deleted. A crash for this example is the following:
//! switch to Alternative Session and disable compositing,
//! the signal creating the crash was probably from deleted
//! windows.
//! this->disconnect();
2017-01-17 21:09:43 +03:00
2017-04-02 08:24:28 +03:00
if ( m_configView )
m_configView - > hide ( ) ;
2017-03-12 20:05:02 +03:00
if ( m_visibility )
delete m_visibility ;
2016-12-31 00:22:28 +03:00
}
2016-12-31 00:25:27 +03:00
void DockView : : init ( )
2016-12-31 00:22:28 +03:00
{
2017-02-25 16:29:05 +03:00
connect ( this , & QQuickWindow : : screenChanged , this , & DockView : : screenChanged ) ;
2017-02-26 16:49:50 +03:00
connect ( qGuiApp , & QGuiApplication : : screenAdded , this , & DockView : : screenChanged ) ;
connect ( qGuiApp , & QGuiApplication : : primaryScreenChanged , this , & DockView : : screenChanged ) ;
2017-02-08 21:48:46 +03:00
connect ( this , & DockView : : screenGeometryChanged , this , & DockView : : syncGeometry ) ;
2017-02-26 16:49:50 +03:00
connect ( this , & QQuickWindow : : xChanged , this , & DockView : : xChanged ) ;
2017-03-08 22:00:09 +03:00
connect ( this , & QQuickWindow : : xChanged , this , & DockView : : updateAbsDockGeometry ) ;
2017-02-26 16:49:50 +03:00
connect ( this , & QQuickWindow : : yChanged , this , & DockView : : yChanged ) ;
2017-03-08 22:00:09 +03:00
connect ( this , & QQuickWindow : : yChanged , this , & DockView : : updateAbsDockGeometry ) ;
2017-01-13 02:55:43 +03:00
connect ( this , & QQuickWindow : : widthChanged , this , & DockView : : widthChanged ) ;
2017-03-08 22:00:09 +03:00
connect ( this , & QQuickWindow : : widthChanged , this , & DockView : : updateAbsDockGeometry ) ;
2017-01-13 02:55:43 +03:00
connect ( this , & QQuickWindow : : heightChanged , this , & DockView : : heightChanged ) ;
2017-03-08 22:00:09 +03:00
connect ( this , & QQuickWindow : : heightChanged , this , & DockView : : updateAbsDockGeometry ) ;
2017-02-12 02:59:09 +03:00
connect ( corona ( ) , & Plasma : : Corona : : availableScreenRectChanged , this , [ & ] ( ) {
2017-02-11 06:12:17 +03:00
if ( formFactor ( ) = = Plasma : : Types : : Vertical )
syncGeometry ( ) ;
} ) ;
2017-01-31 22:25:00 +03:00
connect ( this , & DockView : : drawShadowsChanged , this , & DockView : : syncGeometry ) ;
connect ( this , & DockView : : maxLengthChanged , this , & DockView : : syncGeometry ) ;
2017-04-09 01:06:48 +03:00
connect ( this , & DockView : : offsetChanged , this , & DockView : : syncGeometry ) ;
2017-02-04 17:41:12 +03:00
connect ( this , & DockView : : alignmentChanged , this , & DockView : : updateEnabledBorders ) ;
2017-03-19 00:32:27 +03:00
connect ( this , & DockView : : dockWinBehaviorChanged , this , & DockView : : saveConfig ) ;
2017-02-27 01:53:27 +03:00
connect ( this , & DockView : : onPrimaryChanged , this , & DockView : : saveConfig ) ;
connect ( this , & DockView : : onPrimaryChanged , this , & DockView : : reconsiderScreen ) ;
2017-03-10 23:41:13 +03:00
connect ( this , & DockView : : sessionChanged , this , & DockView : : saveConfig ) ;
2017-01-13 09:27:26 +03:00
connect ( this , & DockView : : locationChanged , this , [ & ] ( ) {
updateFormFactor ( ) ;
syncGeometry ( ) ;
} ) ;
2017-03-17 17:58:57 +03:00
connect ( this , & DockView : : drawEffectsChanged , this , & DockView : : updateEffects ) ;
connect ( this , & DockView : : effectsAreaChanged , this , & DockView : : updateEffects ) ;
connect ( & m_theme , & Plasma : : Theme : : themeChanged , this , & DockView : : updateEffects ) ;
2017-03-05 17:38:17 +03:00
connect ( this , SIGNAL ( normalThicknessChanged ( ) ) , corona ( ) , SIGNAL ( availableScreenRectChanged ( ) ) ) ;
connect ( this , SIGNAL ( shadowChanged ( ) ) , corona ( ) , SIGNAL ( availableScreenRectChanged ( ) ) ) ;
2017-01-13 02:55:43 +03:00
rootContext ( ) - > setContextProperty ( QStringLiteral ( " dock " ) , this ) ;
2017-03-18 14:21:17 +03:00
auto * dockCorona = qobject_cast < DockCorona * > ( this - > corona ( ) ) ;
if ( dockCorona ) {
rootContext ( ) - > setContextProperty ( QStringLiteral ( " globalSettings " ) , dockCorona - > globalSettings ( ) ) ;
}
2016-12-31 00:25:27 +03:00
setSource ( corona ( ) - > kPackage ( ) . filePath ( " lattedockui " ) ) ;
2017-01-13 02:55:43 +03:00
setVisible ( true ) ;
2017-01-12 21:04:27 +03:00
syncGeometry ( ) ;
qDebug ( ) < < " SOURCE: " < < source ( ) ;
2016-12-31 00:22:28 +03:00
}
2017-02-27 20:46:10 +03:00
bool DockView : : setCurrentScreen ( const QString id )
2017-02-25 16:29:05 +03:00
{
2017-02-27 20:46:10 +03:00
QScreen * nextScreen { qGuiApp - > primaryScreen ( ) } ;
2017-02-25 16:29:05 +03:00
2017-02-27 20:46:10 +03:00
if ( id ! = " primary " ) {
foreach ( auto scr , qGuiApp - > screens ( ) ) {
if ( scr & & scr - > name ( ) = = id ) {
nextScreen = scr ;
break ;
}
}
}
2017-02-27 21:27:32 +03:00
if ( m_screenToFollow = = nextScreen ) {
return true ;
}
2017-02-27 20:46:10 +03:00
if ( nextScreen ) {
auto * dockCorona = qobject_cast < DockCorona * > ( this - > corona ( ) ) ;
if ( dockCorona ) {
auto freeEdges = dockCorona - > freeEdges ( nextScreen ) ;
if ( ! freeEdges . contains ( location ( ) ) ) {
return false ;
} else {
setScreenToFollow ( nextScreen ) ;
}
2017-02-25 16:29:05 +03:00
}
}
2017-02-27 21:27:32 +03:00
return true ;
2017-02-25 16:29:05 +03:00
}
2017-03-02 19:07:29 +03:00
//! this function updates the dock's associated screen.
//! updateScreenId = true, update also the m_screenToFollowId
//! updateScreenId = false, do not update the m_screenToFollowId
//! that way an explicit dock can be shown in another screen when
//! there isnt a tasks dock running in the system and for that
//! dock its first origin screen is stored and that way when
//! that screen is reconnected the dock will return to its original
//! place
2017-03-01 17:59:04 +03:00
void DockView : : setScreenToFollow ( QScreen * screen , bool updateScreenId )
2017-02-25 16:29:05 +03:00
{
if ( ! screen | | m_screenToFollow = = screen ) {
return ;
}
m_screenToFollow = screen ;
2017-03-01 17:59:04 +03:00
if ( updateScreenId ) {
m_screenToFollowId = screen - > name ( ) ;
}
2017-02-25 16:29:05 +03:00
qDebug ( ) < < " adapting to screen... " ;
setScreen ( screen ) ;
2017-02-12 11:02:01 +03:00
if ( this - > containment ( ) )
this - > containment ( ) - > reactToScreenChange ( ) ;
2017-01-16 22:07:49 +03:00
2017-01-12 21:04:27 +03:00
syncGeometry ( ) ;
2017-03-09 17:49:51 +03:00
emit screenGeometryChanged ( ) ;
2016-12-31 00:22:28 +03:00
}
2017-03-02 19:07:29 +03:00
//! the main function which decides if this dock is at the
//! correct screen
2017-02-26 03:43:41 +03:00
void DockView : : reconsiderScreen ( )
{
qDebug ( ) < < " Delayer " ;
2017-02-27 13:44:51 +03:00
foreach ( auto scr , qGuiApp - > screens ( ) ) {
qDebug ( ) < < " D, found screen: " < < scr - > name ( ) ;
2017-02-26 03:43:41 +03:00
}
2017-03-01 17:59:04 +03:00
auto * dockCorona = qobject_cast < DockCorona * > ( this - > corona ( ) ) ;
bool screenExists { false } ;
2017-03-01 22:03:51 +03:00
2017-03-02 19:07:29 +03:00
//!check if the associated screen is running
2017-03-01 22:03:51 +03:00
foreach ( auto scr , qGuiApp - > screens ( ) ) {
2017-03-01 17:59:04 +03:00
if ( m_screenToFollowId = = scr - > name ( ) )
screenExists = true ;
}
2017-02-28 00:06:03 +03:00
2017-03-01 22:03:51 +03:00
qDebug ( ) < < " dock screen exists ::: " < < screenExists ;
2017-03-01 17:59:04 +03:00
2017-03-02 19:07:29 +03:00
//! 1.a primary dock must be always on the primary screen
//! 2.the last tasks dock must also always on the primary screen
//! even though it has been configured as an explicit
2017-03-01 17:59:04 +03:00
if ( ( m_onPrimary | | ( tasksPresent ( ) & & dockCorona - > noDocksWithTasks ( ) = = 1 ) & & ! screenExists )
2017-03-01 22:03:51 +03:00
& & m_screenToFollowId ! = qGuiApp - > primaryScreen ( ) - > name ( )
& & m_screenToFollow ! = qGuiApp - > primaryScreen ( ) ) {
2017-02-28 00:06:03 +03:00
//change to primary screen only if the specific edge is free
if ( dockCorona - > freeEdges ( qGuiApp - > primaryScreen ( ) ) . contains ( location ( ) ) ) {
connect ( qGuiApp - > primaryScreen ( ) , & QScreen : : geometryChanged , this , & DockView : : screenGeometryChanged ) ;
2017-03-01 17:59:04 +03:00
2017-03-02 19:07:29 +03:00
//! case 2
2017-03-01 17:59:04 +03:00
if ( ! m_onPrimary & & ! screenExists & & tasksPresent ( ) & & ( dockCorona - > noDocksWithTasks ( ) = = 1 ) ) {
setScreenToFollow ( qGuiApp - > primaryScreen ( ) , false ) ;
} else {
2017-03-02 19:07:29 +03:00
//! case 1
2017-03-01 17:59:04 +03:00
setScreenToFollow ( qGuiApp - > primaryScreen ( ) ) ;
}
2017-02-28 00:06:03 +03:00
syncGeometry ( ) ;
}
2017-02-27 01:53:27 +03:00
} else {
2017-03-02 19:07:29 +03:00
//! 3.an explicit dock must be always on the correct associated screen
//! there are cases that window manager misplaces the dock, this function
//! ensures that this dock will return at its correct screen
2017-02-27 13:44:51 +03:00
foreach ( auto scr , qGuiApp - > screens ( ) ) {
if ( scr & & scr - > name ( ) = = m_screenToFollowId ) {
2017-02-27 01:53:27 +03:00
connect ( scr , & QScreen : : geometryChanged , this , & DockView : : screenGeometryChanged ) ;
setScreenToFollow ( scr ) ;
syncGeometry ( ) ;
}
2017-02-26 03:43:41 +03:00
}
}
emit docksCountChanged ( ) ;
}
2017-02-25 16:29:05 +03:00
void DockView : : screenChanged ( QScreen * scr )
{
2017-02-26 20:15:20 +03:00
m_screenSyncTimer . start ( ) ;
2017-02-25 16:29:05 +03:00
}
2016-12-31 00:25:27 +03:00
void DockView : : addNewDock ( )
2016-12-31 00:22:28 +03:00
{
2017-01-16 21:24:46 +03:00
auto * dockCorona = qobject_cast < DockCorona * > ( this - > corona ( ) ) ;
2017-01-16 22:07:49 +03:00
2017-01-16 21:24:46 +03:00
if ( dockCorona ) {
dockCorona - > loadDefaultLayout ( ) ;
2016-12-31 00:22:28 +03:00
}
}
2016-12-31 00:25:27 +03:00
void DockView : : removeDock ( )
2016-12-31 00:22:28 +03:00
{
2017-01-16 21:24:46 +03:00
if ( docksCount ( ) > 1 ) {
2017-02-12 11:02:01 +03:00
QAction * removeAct = this - > containment ( ) - > actions ( ) - > action ( QStringLiteral ( " remove " ) ) ;
2017-01-16 22:07:49 +03:00
2016-12-31 00:22:28 +03:00
if ( removeAct ) {
removeAct - > trigger ( ) ;
}
}
}
2016-12-31 00:25:27 +03:00
QQmlListProperty < QScreen > DockView : : screens ( )
2016-12-31 00:22:28 +03:00
{
return QQmlListProperty < QScreen > ( this , nullptr , & countScreens , & atScreens ) ;
}
2016-12-31 00:25:27 +03:00
int DockView : : countScreens ( QQmlListProperty < QScreen > * property )
2016-12-31 00:22:28 +03:00
{
Q_UNUSED ( property )
return qGuiApp - > screens ( ) . count ( ) ;
}
2016-12-31 00:25:27 +03:00
QScreen * DockView : : atScreens ( QQmlListProperty < QScreen > * property , int index )
2016-12-31 00:22:28 +03:00
{
Q_UNUSED ( property )
return qGuiApp - > screens ( ) . at ( index ) ;
}
2017-02-25 16:29:05 +03:00
QString DockView : : currentScreen ( ) const
{
2017-02-26 03:43:41 +03:00
return m_screenToFollowId ;
2017-02-25 16:29:05 +03:00
}
2016-12-31 00:25:27 +03:00
void DockView : : showConfigurationInterface ( Plasma : : Applet * applet )
2016-12-31 00:22:28 +03:00
{
if ( ! applet | | ! applet - > containment ( ) )
return ;
2017-01-16 22:07:49 +03:00
2016-12-31 00:22:28 +03:00
Plasma : : Containment * c = qobject_cast < Plasma : : Containment * > ( applet ) ;
2017-01-16 22:07:49 +03:00
2017-02-12 11:02:01 +03:00
if ( m_configView & & c & & c - > isContainment ( ) & & c = = this - > containment ( ) ) {
2016-12-31 00:22:28 +03:00
if ( m_configView - > isVisible ( ) ) {
m_configView - > hide ( ) ;
} else {
m_configView - > show ( ) ;
}
2017-01-16 22:07:49 +03:00
2016-12-31 00:22:28 +03:00
return ;
} else if ( m_configView ) {
if ( m_configView - > applet ( ) = = applet ) {
m_configView - > show ( ) ;
m_configView - > requestActivate ( ) ;
return ;
} else {
m_configView - > hide ( ) ;
m_configView - > deleteLater ( ) ;
}
}
2017-01-16 22:07:49 +03:00
2017-01-11 17:29:11 +03:00
bool delayConfigView = false ;
2017-01-16 22:07:49 +03:00
2017-02-12 11:02:01 +03:00
if ( c & & containment ( ) & & c - > isContainment ( ) & & c - > id ( ) = = this - > containment ( ) - > id ( ) ) {
2016-12-31 00:22:28 +03:00
m_configView = new DockConfigView ( c , this ) ;
2017-01-11 17:29:11 +03:00
delayConfigView = true ;
2016-12-31 00:22:28 +03:00
} else {
m_configView = new PlasmaQuick : : ConfigView ( applet ) ;
}
2017-01-16 22:07:49 +03:00
2017-01-11 02:04:41 +03:00
m_configView . data ( ) - > init ( ) ;
2017-01-16 22:07:49 +03:00
2017-01-11 17:29:11 +03:00
if ( ! delayConfigView ) {
m_configView . data ( ) - > show ( ) ;
} else {
2017-01-11 17:33:10 +03:00
//add a timer for showing the configuration window the first time it is
//created in order to give the containmnent's layouts the time to
//calculate the window's height
QTimer : : singleShot ( 150 , m_configView , SLOT ( show ( ) ) ) ;
2017-01-11 17:29:11 +03:00
}
2016-12-31 00:22:28 +03:00
}
2017-03-02 23:10:26 +03:00
//! this is used mainly from vertical panels in order to
//! to get the maximum geometry that can be used from the dock
//! based on their alignment type and the location dock
QRect DockView : : maximumNormalGeometry ( )
{
int xPos = 0 ;
int yPos = 0 ;
int maxHeight = maxLength ( ) * screen ( ) - > geometry ( ) . height ( ) ;
int maxWidth = normalThickness ( ) ;
QRect maxGeometry ;
maxGeometry . setRect ( 0 , 0 , maxWidth , maxHeight ) ;
switch ( location ( ) ) {
case Plasma : : Types : : LeftEdge :
xPos = screen ( ) - > geometry ( ) . x ( ) ;
switch ( alignment ( ) ) {
case Latte : : Dock : : Top :
yPos = screen ( ) - > geometry ( ) . y ( ) ;
break ;
case Latte : : Dock : : Center :
case Latte : : Dock : : Justify :
yPos = qMax ( screen ( ) - > geometry ( ) . center ( ) . y ( ) - maxHeight / 2 , screen ( ) - > geometry ( ) . y ( ) ) ;
break ;
case Latte : : Dock : : Bottom :
yPos = screen ( ) - > geometry ( ) . bottom ( ) - maxHeight + 1 ;
break ;
}
maxGeometry . setRect ( xPos , yPos , maxWidth , maxHeight ) ;
break ;
case Plasma : : Types : : RightEdge :
xPos = screen ( ) - > geometry ( ) . right ( ) - maxWidth + 1 ;
switch ( alignment ( ) ) {
case Latte : : Dock : : Top :
yPos = screen ( ) - > geometry ( ) . y ( ) ;
break ;
case Latte : : Dock : : Center :
case Latte : : Dock : : Justify :
yPos = qMax ( screen ( ) - > geometry ( ) . center ( ) . y ( ) - maxHeight / 2 , screen ( ) - > geometry ( ) . y ( ) ) ;
break ;
case Latte : : Dock : : Bottom :
yPos = screen ( ) - > geometry ( ) . bottom ( ) - maxHeight + 1 ;
break ;
}
maxGeometry . setRect ( xPos , yPos , maxWidth , maxHeight ) ;
break ;
}
2017-03-18 21:08:56 +03:00
//! this is needed in order to preserve that the top dock will be above
//! the others in case flag bypasswindowmanagerhint hasnt be set,
//! such a case is the AlwaysVisible mode
if ( location ( ) = = Plasma : : Types : : TopEdge ) {
KWindowSystem : : setState ( winId ( ) , NET : : KeepAbove ) ;
} else {
KWindowSystem : : clearState ( winId ( ) , NET : : KeepAbove ) ;
}
2017-03-02 23:10:26 +03:00
return maxGeometry ;
}
2017-03-03 18:35:37 +03:00
void DockView : : resizeWindow ( QRect availableScreenRect )
2016-12-31 00:22:28 +03:00
{
if ( formFactor ( ) = = Plasma : : Types : : Vertical ) {
2017-03-02 23:10:26 +03:00
//qDebug() << "MAXIMUM RECT :: " << maximumRect << " - AVAILABLE RECT :: " << availableRect;
2017-03-03 18:35:37 +03:00
QSize size { maxThickness ( ) , availableScreenRect . height ( ) } ;
2017-01-31 22:25:00 +03:00
if ( m_drawShadows ) {
size . setWidth ( normalThickness ( ) ) ;
2017-03-03 18:35:37 +03:00
size . setHeight ( static_cast < int > ( maxLength ( ) * availableScreenRect . height ( ) ) ) ;
2017-01-31 22:25:00 +03:00
}
2016-12-31 00:22:28 +03:00
setMinimumSize ( size ) ;
setMaximumSize ( size ) ;
resize ( size ) ;
} else {
2017-02-13 19:53:54 +03:00
QSize screenSize = this - > screen ( ) - > size ( ) ;
2017-01-31 22:25:00 +03:00
QSize size { screenSize . width ( ) , maxThickness ( ) } ;
if ( m_drawShadows ) {
2017-02-06 04:55:41 +03:00
size . setWidth ( static_cast < int > ( maxLength ( ) * screenSize . width ( ) ) ) ;
2017-01-31 22:25:00 +03:00
size . setHeight ( normalThickness ( ) ) ;
}
2016-12-31 00:22:28 +03:00
setMinimumSize ( size ) ;
setMaximumSize ( size ) ;
resize ( size ) ;
2017-02-11 06:12:17 +03:00
if ( corona ( ) )
emit corona ( ) - > availableScreenRectChanged ( ) ;
2016-12-31 00:22:28 +03:00
}
}
2017-03-09 16:49:24 +03:00
QRect DockView : : localGeometry ( ) const
{
return m_localGeometry ;
}
void DockView : : setLocalGeometry ( const QRect & geometry )
2016-12-31 03:26:48 +03:00
{
2017-03-08 22:00:09 +03:00
if ( m_localGeometry = = geometry ) {
return ;
}
m_localGeometry = geometry ;
2017-03-09 16:49:24 +03:00
emit localGeometryChanged ( ) ;
2017-03-08 22:00:09 +03:00
updateAbsDockGeometry ( ) ;
2016-12-31 03:26:48 +03:00
}
2017-03-08 22:00:09 +03:00
void DockView : : updateAbsDockGeometry ( )
2016-12-31 03:26:48 +03:00
{
2017-03-08 22:00:09 +03:00
QRect absGeometry { x ( ) + m_localGeometry . x ( ) , y ( ) + m_localGeometry . y ( )
, m_localGeometry . width ( ) - 1 , m_localGeometry . height ( ) - 1 } ;
2017-02-11 06:12:17 +03:00
if ( m_absGeometry = = absGeometry )
2017-01-13 02:55:43 +03:00
return ;
2017-01-16 22:07:49 +03:00
2017-02-11 06:12:17 +03:00
m_absGeometry = absGeometry ;
syncGeometry ( ) ;
emit absGeometryChanged ( m_absGeometry ) ;
2016-12-31 03:26:48 +03:00
}
2017-03-03 18:35:37 +03:00
void DockView : : updatePosition ( QRect availableScreenRect )
2016-12-31 00:22:28 +03:00
{
2017-02-11 06:12:17 +03:00
QRect screenGeometry ;
2016-12-31 00:22:28 +03:00
QPoint position ;
position = { 0 , 0 } ;
2017-04-09 01:59:21 +03:00
2017-02-11 07:55:25 +03:00
const auto length = [ & ] ( int length ) - > int {
2017-04-09 01:59:21 +03:00
float offs = static_cast < float > ( offset ( ) ) ;
return static_cast < int > ( length * ( ( 1 - maxLength ( ) ) / 2 ) + length * ( offs / 100 ) ) ;
2017-02-11 07:55:25 +03:00
} ;
2017-01-31 22:25:00 +03:00
int cleanThickness = normalThickness ( ) - shadow ( ) ;
2016-12-31 00:22:28 +03:00
switch ( location ( ) ) {
2017-02-27 13:44:51 +03:00
case Plasma : : Types : : TopEdge :
screenGeometry = this - > screen ( ) - > geometry ( ) ;
2017-02-12 02:59:09 +03:00
2017-02-27 13:44:51 +03:00
if ( m_drawShadows ) {
position = { screenGeometry . x ( ) + length ( screenGeometry . width ( ) ) , screenGeometry . y ( ) } ;
} else {
position = { screenGeometry . x ( ) , screenGeometry . y ( ) } ;
}
2017-01-31 22:25:00 +03:00
2017-02-27 13:44:51 +03:00
break ;
2017-01-31 22:25:00 +03:00
2017-02-27 13:44:51 +03:00
case Plasma : : Types : : BottomEdge :
screenGeometry = this - > screen ( ) - > geometry ( ) ;
2017-02-12 02:59:09 +03:00
2017-02-27 13:44:51 +03:00
if ( m_drawShadows ) {
position = { screenGeometry . x ( ) + length ( screenGeometry . width ( ) ) ,
screenGeometry . y ( ) + screenGeometry . height ( ) - cleanThickness
} ;
} else {
position = { screenGeometry . x ( ) , screenGeometry . y ( ) + screenGeometry . height ( ) - height ( ) } ;
}
2017-01-31 22:25:00 +03:00
2017-02-27 13:44:51 +03:00
break ;
2017-01-31 22:25:00 +03:00
2017-02-27 13:44:51 +03:00
case Plasma : : Types : : RightEdge :
if ( m_drawShadows & & ! mask ( ) . isNull ( ) ) {
2017-03-03 18:35:37 +03:00
position = { availableScreenRect . right ( ) - cleanThickness + 1 ,
availableScreenRect . y ( ) + length ( availableScreenRect . height ( ) )
2017-02-27 13:44:51 +03:00
} ;
} else {
2017-03-03 18:35:37 +03:00
position = { availableScreenRect . right ( ) - width ( ) + 1 , availableScreenRect . y ( ) } ;
2017-02-27 13:44:51 +03:00
}
2017-01-31 22:25:00 +03:00
2017-02-27 13:44:51 +03:00
break ;
2017-01-31 22:25:00 +03:00
2017-02-27 13:44:51 +03:00
case Plasma : : Types : : LeftEdge :
if ( m_drawShadows & & ! mask ( ) . isNull ( ) ) {
2017-03-03 18:35:37 +03:00
position = { availableScreenRect . x ( ) , availableScreenRect . y ( ) + length ( availableScreenRect . height ( ) ) } ;
2017-02-27 13:44:51 +03:00
} else {
2017-03-03 18:35:37 +03:00
position = { availableScreenRect . x ( ) , availableScreenRect . y ( ) } ;
2017-02-27 13:44:51 +03:00
}
2017-01-31 22:25:00 +03:00
2017-02-27 13:44:51 +03:00
break ;
2017-01-31 22:25:00 +03:00
2017-02-27 13:44:51 +03:00
default :
qWarning ( ) < < " wrong location, couldn't update the panel position "
< < location ( ) ;
2016-12-31 00:22:28 +03:00
}
2017-01-16 22:07:49 +03:00
2017-01-13 02:55:43 +03:00
setPosition ( position ) ;
2016-12-31 00:22:28 +03:00
}
2017-01-12 21:04:27 +03:00
inline void DockView : : syncGeometry ( )
{
2017-02-13 19:53:54 +03:00
if ( ! ( this - > screen ( ) & & this - > containment ( ) ) )
2017-02-11 06:12:17 +03:00
return ;
2017-02-26 03:43:41 +03:00
bool found { false } ;
2017-02-27 13:44:51 +03:00
2017-03-02 19:07:29 +03:00
//! before updating the positioning and geometry of the dock
//! we make sure that the dock is at the correct screen
2017-02-26 03:43:41 +03:00
if ( this - > screen ( ) ! = m_screenToFollow ) {
qDebug ( ) < < " Sync Geometry screens incosistent!!!! " ;
2017-02-26 20:15:20 +03:00
m_screenSyncTimer . start ( ) ;
2017-02-26 03:43:41 +03:00
} else {
found = true ;
2017-02-24 22:24:12 +03:00
}
2017-03-02 19:07:29 +03:00
//! if the dock isnt at the correct screen the calculations
//! are not executed
2017-02-26 03:43:41 +03:00
if ( found ) {
2017-03-03 18:35:37 +03:00
//! compute the free screen rectangle for vertical panels only once
//! this way the costly QRegion computations are calculated only once
//! instead of two times (both inside the resizeWindow and the updatePosition)
QRegion freeRegion ; ;
QRect maximumRect ;
QRect availableScreenRect ;
if ( formFactor ( ) = = Plasma : : Types : : Vertical ) {
freeRegion = corona ( ) - > availableScreenRegion ( this - > containment ( ) - > screen ( ) ) ;
maximumRect = maximumNormalGeometry ( ) ;
2017-03-07 19:29:37 +03:00
QRegion availableRegion = freeRegion . intersected ( maximumRect ) ;
2017-03-03 18:35:37 +03:00
availableScreenRect = freeRegion . intersected ( maximumRect ) . boundingRect ( ) ;
2017-03-07 19:29:37 +03:00
float area = 0 ;
//! it is used to choose which or the availableRegion rectangles will
//! be the one representing dock geometry
for ( int i = 0 ; i < availableRegion . rectCount ( ) ; + + i ) {
QRect rect = availableRegion . rects ( ) . at ( i ) ;
//! the area of each rectangle in calculated in squares of 50x50
//! this is a way to avoid enourmous numbers for area value
float tempArea = ( float ) ( rect . width ( ) * rect . height ( ) ) / 2500 ;
if ( tempArea > area ) {
availableScreenRect = rect ;
area = tempArea ;
}
}
if ( availableRegion . rectCount ( ) > 1 & & m_drawShadows )
m_forceDrawCenteredBorders = true ;
else
m_forceDrawCenteredBorders = false ;
} else {
m_forceDrawCenteredBorders = false ;
2017-03-03 18:35:37 +03:00
}
2017-02-26 03:43:41 +03:00
updateEnabledBorders ( ) ;
2017-03-03 18:35:37 +03:00
resizeWindow ( availableScreenRect ) ;
updatePosition ( availableScreenRect ) ;
2017-02-26 03:43:41 +03:00
}
2017-02-27 13:44:51 +03:00
2017-01-28 20:34:03 +03:00
// qDebug() << "dock geometry:" << qRectToStr(geometry());
2017-01-12 21:04:27 +03:00
}
2017-01-14 02:59:25 +03:00
void DockView : : statusChanged ( Plasma : : Types : : ItemStatus status )
{
2017-02-18 11:28:40 +03:00
if ( containment ( ) ) {
if ( containment ( ) - > status ( ) > = Plasma : : Types : : NeedsAttentionStatus & &
2017-02-27 13:44:51 +03:00
containment ( ) - > status ( ) ! = Plasma : : Types : : HiddenStatus ) {
2017-02-18 11:28:40 +03:00
m_visibility - > setBlockHiding ( true ) ;
} else {
m_visibility - > setBlockHiding ( false ) ;
}
2017-01-14 02:59:25 +03:00
}
}
2016-12-31 00:25:27 +03:00
int DockView : : currentThickness ( ) const
2016-12-31 00:22:28 +03:00
{
2017-01-13 02:55:43 +03:00
if ( formFactor ( ) = = Plasma : : Types : : Vertical ) {
2017-01-13 17:51:56 +03:00
return m_maskArea . isNull ( ) ? width ( ) : m_maskArea . width ( ) - m_shadow ;
2016-12-31 00:22:28 +03:00
} else {
2017-01-13 17:51:56 +03:00
return m_maskArea . isNull ( ) ? height ( ) : m_maskArea . height ( ) - m_shadow ;
2016-12-31 00:22:28 +03:00
}
}
2017-01-27 21:31:41 +03:00
int DockView : : normalThickness ( ) const
{
return m_normalThickness ;
}
void DockView : : setNormalThickness ( int thickness )
{
if ( m_normalThickness = = thickness ) {
return ;
}
m_normalThickness = thickness ;
emit normalThicknessChanged ( ) ;
}
2017-01-05 01:28:25 +03:00
int DockView : : docksCount ( ) const
{
2017-01-16 00:59:15 +03:00
auto dockCorona = qobject_cast < DockCorona * > ( corona ( ) ) ;
2017-01-16 22:07:49 +03:00
2017-02-12 11:02:01 +03:00
if ( ! dockCorona | | ! this - > containment ( ) )
2017-01-16 00:59:15 +03:00
return 0 ;
2017-01-16 22:07:49 +03:00
2017-03-03 18:23:37 +03:00
return dockCorona - > docksCount ( ) ;
}
int DockView : : docksWithTasks ( )
{
auto dockCorona = qobject_cast < DockCorona * > ( corona ( ) ) ;
if ( ! dockCorona )
return 0 ;
return dockCorona - > noDocksWithTasks ( ) ;
2017-01-05 01:28:25 +03:00
}
2017-01-13 02:55:43 +03:00
void DockView : : updateFormFactor ( )
2016-12-31 00:22:28 +03:00
{
2017-02-12 11:02:01 +03:00
if ( ! this - > containment ( ) )
2017-01-13 02:55:43 +03:00
return ;
2017-01-16 22:07:49 +03:00
2017-01-13 02:55:43 +03:00
switch ( location ( ) ) {
2017-02-27 13:44:51 +03:00
case Plasma : : Types : : TopEdge :
case Plasma : : Types : : BottomEdge :
this - > containment ( ) - > setFormFactor ( Plasma : : Types : : Horizontal ) ;
break ;
case Plasma : : Types : : LeftEdge :
case Plasma : : Types : : RightEdge :
this - > containment ( ) - > setFormFactor ( Plasma : : Types : : Vertical ) ;
break ;
default :
qWarning ( ) < < " wrong location, couldn't update the panel position " < < location ( ) ;
2017-01-13 02:55:43 +03:00
}
}
2016-12-31 00:22:28 +03:00
2017-03-19 00:32:27 +03:00
bool DockView : : dockWinBehavior ( ) const
{
return m_dockWinBehavior ;
}
void DockView : : setDockWinBehavior ( bool dock )
{
if ( m_dockWinBehavior = = dock ) {
return ;
}
m_dockWinBehavior = dock ;
emit dockWinBehaviorChanged ( ) ;
}
2017-01-31 22:25:00 +03:00
bool DockView : : drawShadows ( ) const
{
return m_drawShadows ;
}
void DockView : : setDrawShadows ( bool draw )
{
if ( m_drawShadows = = draw ) {
return ;
}
m_drawShadows = draw ;
if ( m_drawShadows ) {
PanelShadows : : self ( ) - > addWindow ( this , enabledBorders ( ) ) ;
} else {
PanelShadows : : self ( ) - > removeWindow ( this ) ;
m_enabledBorders = Plasma : : FrameSvg : : AllBorders ;
emit enabledBordersChanged ( ) ;
}
2017-03-17 17:58:57 +03:00
updateEffects ( ) ;
2017-01-31 22:25:00 +03:00
emit drawShadowsChanged ( ) ;
}
2017-03-17 17:58:57 +03:00
bool DockView : : drawEffects ( ) const
{
2017-03-18 00:59:50 +03:00
return m_drawEffects ;
2017-03-17 17:58:57 +03:00
}
void DockView : : setDrawEffects ( bool draw )
{
if ( m_drawEffects = = draw ) {
return ;
}
m_drawEffects = draw ;
emit drawEffectsChanged ( ) ;
}
2017-02-27 01:53:27 +03:00
bool DockView : : onPrimary ( ) const
{
return m_onPrimary ;
}
void DockView : : setOnPrimary ( bool flag )
{
2017-02-27 13:44:51 +03:00
if ( m_onPrimary = = flag ) {
2017-02-27 01:53:27 +03:00
return ;
}
m_onPrimary = flag ;
emit onPrimaryChanged ( ) ;
}
2017-03-10 23:41:13 +03:00
Dock : : SessionType DockView : : session ( ) const
{
return m_session ;
}
void DockView : : setSession ( Dock : : SessionType type )
{
if ( m_session = = type ) {
return ;
}
m_session = type ;
emit sessionChanged ( ) ;
}
2017-01-31 22:25:00 +03:00
float DockView : : maxLength ( ) const
{
return m_maxLength ;
}
void DockView : : setMaxLength ( float length )
{
if ( m_maxLength = = length ) {
return ;
}
m_maxLength = length ;
emit maxLengthChanged ( ) ;
}
2016-12-31 00:25:27 +03:00
int DockView : : maxThickness ( ) const
2016-12-31 00:22:28 +03:00
{
return m_maxThickness ;
}
2016-12-31 00:25:27 +03:00
void DockView : : setMaxThickness ( int thickness )
2016-12-31 00:22:28 +03:00
{
if ( m_maxThickness = = thickness )
return ;
2017-01-16 22:07:49 +03:00
2016-12-31 00:22:28 +03:00
m_maxThickness = thickness ;
2017-01-12 21:04:27 +03:00
syncGeometry ( ) ;
2016-12-31 00:22:28 +03:00
emit maxThicknessChanged ( ) ;
}
2017-02-04 17:41:12 +03:00
int DockView : : alignment ( ) const
{
2017-02-11 06:12:17 +03:00
return m_alignment ;
2017-02-04 17:41:12 +03:00
}
void DockView : : setAlignment ( int alignment )
{
2017-02-11 06:12:17 +03:00
Dock : : Alignment align = static_cast < Dock : : Alignment > ( alignment ) ;
2017-02-04 17:41:12 +03:00
2017-02-11 06:12:17 +03:00
if ( m_alignment = = alignment ) {
2017-02-04 17:41:12 +03:00
return ;
}
m_alignment = align ;
emit alignmentChanged ( ) ;
}
2016-12-31 00:25:27 +03:00
QRect DockView : : maskArea ( ) const
2016-12-31 00:22:28 +03:00
{
return m_maskArea ;
}
2016-12-31 00:25:27 +03:00
void DockView : : setMaskArea ( QRect area )
2016-12-31 00:22:28 +03:00
{
2017-01-13 02:55:43 +03:00
if ( m_maskArea = = area )
2016-12-31 00:22:28 +03:00
return ;
2017-01-16 22:07:49 +03:00
2016-12-31 00:22:28 +03:00
m_maskArea = area ;
2017-03-12 21:18:18 +03:00
if ( KWindowSystem : : compositingActive ( ) ) {
setMask ( m_maskArea ) ;
} else {
//! this is used when compositing is disabled and provides
//! the correct way for the mask to be painted in order for
//! rounded corners to be shown correctly
if ( ! m_background ) {
m_background = new Plasma : : FrameSvg ( this ) ;
2017-03-17 17:58:57 +03:00
}
if ( m_background - > imagePath ( ) ! = " opaque/dialogs/background " ) {
2017-03-12 21:18:18 +03:00
m_background - > setImagePath ( QStringLiteral ( " opaque/dialogs/background " ) ) ;
}
m_background - > setEnabledBorders ( enabledBorders ( ) ) ;
m_background - > resizeFrame ( area . size ( ) ) ;
QRegion fixedMask = m_background - > mask ( ) ;
2017-03-21 21:58:01 +03:00
fixedMask . translate ( m_maskArea . x ( ) , m_maskArea . y ( ) ) ;
//! fix for KF5.32 that return empty QRegion's for the mask
if ( fixedMask . isEmpty ( ) ) {
fixedMask = QRegion ( m_maskArea ) ;
}
2017-03-12 21:18:18 +03:00
setMask ( fixedMask ) ;
}
2016-12-31 00:22:28 +03:00
//qDebug() << "dock mask set:" << m_maskArea;
emit maskAreaChanged ( ) ;
}
2017-03-17 17:58:57 +03:00
QRect DockView : : effectsArea ( ) const
{
return m_effectsArea ;
}
void DockView : : setEffectsArea ( QRect area )
{
if ( m_effectsArea = = area ) {
return ;
}
m_effectsArea = area ;
emit effectsAreaChanged ( ) ;
}
2017-02-11 06:12:17 +03:00
QRect DockView : : absGeometry ( ) const
{
return m_absGeometry ;
}
2017-02-26 16:49:50 +03:00
QRect DockView : : screenGeometry ( ) const
{
if ( this - > screen ( ) ) {
QRect geom = this - > screen ( ) - > geometry ( ) ;
return geom ;
}
return QRect ( ) ;
}
2017-04-09 01:06:48 +03:00
int DockView : : offset ( ) const
{
return m_offset ;
}
void DockView : : setOffset ( int offset )
{
if ( m_offset = = offset ) {
return ;
}
m_offset = offset ;
emit offsetChanged ( ) ;
}
2017-01-13 17:51:56 +03:00
int DockView : : shadow ( ) const
{
return m_shadow ;
}
void DockView : : setShadow ( int shadow )
{
2017-01-16 21:24:46 +03:00
if ( m_shadow = = shadow )
2017-01-13 17:51:56 +03:00
return ;
2017-01-16 22:07:49 +03:00
2017-01-13 17:51:56 +03:00
m_shadow = shadow ;
2017-01-31 22:25:00 +03:00
if ( m_drawShadows ) {
syncGeometry ( ) ;
}
2017-01-13 17:51:56 +03:00
emit shadowChanged ( ) ;
}
2017-03-17 17:58:57 +03:00
void DockView : : updateEffects ( )
2017-03-04 13:49:48 +03:00
{
if ( ! m_drawShadows ) {
2017-03-17 17:58:57 +03:00
if ( m_drawEffects & & ! m_effectsArea . isNull ( ) & & ! m_effectsArea . isEmpty ( ) ) {
//! this is used when compositing is disabled and provides
//! the correct way for the mask to be painted in order for
//! rounded corners to be shown correctly
if ( ! m_background ) {
m_background = new Plasma : : FrameSvg ( this ) ;
}
if ( m_background - > imagePath ( ) ! = " widgets/panel-background " ) {
m_background - > setImagePath ( QStringLiteral ( " widgets/panel-background " ) ) ;
}
m_background - > setEnabledBorders ( enabledBorders ( ) ) ;
m_background - > resizeFrame ( m_effectsArea . size ( ) ) ;
QRegion fixedMask = m_background - > mask ( ) ;
fixedMask . translate ( m_effectsArea . x ( ) , m_effectsArea . y ( ) ) ;
2017-03-21 21:58:01 +03:00
//! fix for KF5.32 that return empty QRegion's for the mask
if ( fixedMask . isEmpty ( ) ) {
fixedMask = QRegion ( m_effectsArea ) ;
}
2017-03-17 17:58:57 +03:00
KWindowEffects : : enableBlurBehind ( winId ( ) , true , fixedMask ) ;
KWindowEffects : : enableBackgroundContrast ( winId ( ) , m_theme . backgroundContrastEnabled ( ) ,
m_theme . backgroundContrast ( ) ,
m_theme . backgroundIntensity ( ) ,
m_theme . backgroundSaturation ( ) ,
fixedMask ) ;
} else {
KWindowEffects : : enableBlurBehind ( winId ( ) , false ) ;
KWindowEffects : : enableBackgroundContrast ( winId ( ) , false ) ;
}
} else if ( m_drawShadows & & m_drawEffects ) {
2017-03-04 13:49:48 +03:00
KWindowEffects : : enableBlurBehind ( winId ( ) , true ) ;
KWindowEffects : : enableBackgroundContrast ( winId ( ) , m_theme . backgroundContrastEnabled ( ) ,
m_theme . backgroundContrast ( ) ,
m_theme . backgroundIntensity ( ) ,
m_theme . backgroundSaturation ( ) ) ;
2017-03-17 17:58:57 +03:00
} else {
KWindowEffects : : enableBlurBehind ( winId ( ) , false ) ;
KWindowEffects : : enableBackgroundContrast ( winId ( ) , false ) ;
2017-03-04 13:49:48 +03:00
}
}
2017-04-11 12:10:54 +03:00
//! remove latte tasks plasmoid
void DockView : : removeTasksPlasmoid ( )
{
if ( ! tasksPresent ( ) | | ! containment ( ) ) {
return ;
}
foreach ( Plasma : : Applet * applet , containment ( ) - > applets ( ) ) {
KPluginMetaData meta = applet - > kPackage ( ) . metadata ( ) ;
if ( meta . pluginId ( ) = = " org.kde.latte.plasmoid " ) {
QAction * closeApplet = applet - > actions ( ) - > action ( QStringLiteral ( " remove " ) ) ;
if ( closeApplet ) {
closeApplet - > trigger ( ) ;
//! remove only the first found
return ;
}
}
}
}
2017-03-02 19:07:29 +03:00
//! check if the tasks plasmoid exist in the dock
2017-01-02 23:26:10 +03:00
bool DockView : : tasksPresent ( )
{
2017-03-05 17:30:50 +03:00
if ( ! this - > containment ( ) ) {
return false ;
}
2017-02-12 11:02:01 +03:00
foreach ( Plasma : : Applet * applet , this - > containment ( ) - > applets ( ) ) {
2017-01-03 20:02:51 +03:00
KPluginMetaData meta = applet - > kPackage ( ) . metadata ( ) ;
2017-01-16 22:07:49 +03:00
2017-01-16 21:24:46 +03:00
if ( meta . pluginId ( ) = = " org.kde.latte.plasmoid " )
2017-01-02 23:26:10 +03:00
return true ;
}
2017-01-16 22:07:49 +03:00
2017-01-02 23:26:10 +03:00
return false ;
}
2017-02-12 02:59:09 +03:00
VisibilityManager * DockView : : visibility ( ) const
2016-12-31 00:22:28 +03:00
{
return m_visibility ;
}
2016-12-31 00:25:27 +03:00
bool DockView : : event ( QEvent * e )
2016-12-31 00:22:28 +03:00
{
emit eventTriggered ( e ) ;
2017-01-31 22:25:00 +03:00
2016-12-31 00:22:28 +03:00
return ContainmentView : : event ( e ) ;
}
2016-12-31 00:25:27 +03:00
QList < int > DockView : : freeEdges ( ) const
2016-12-31 00:22:28 +03:00
{
2017-02-12 11:02:01 +03:00
if ( ! this - > corona ( ) | | ! this - > containment ( ) ) {
2017-01-17 21:09:43 +03:00
const QList < int > emptyEdges ;
return emptyEdges ;
}
2017-02-12 11:02:01 +03:00
const auto edges = corona ( ) - > freeEdges ( this - > containment ( ) - > screen ( ) ) ;
2016-12-31 00:22:28 +03:00
QList < int > edgesInt ;
2017-01-16 22:07:49 +03:00
2016-12-31 00:22:28 +03:00
foreach ( Plasma : : Types : : Location edge , edges ) {
2016-12-31 03:26:48 +03:00
edgesInt . append ( static_cast < int > ( edge ) ) ;
2016-12-31 00:22:28 +03:00
}
2017-01-16 22:07:49 +03:00
2016-12-31 00:22:28 +03:00
return edgesInt ;
}
2017-01-05 01:28:25 +03:00
void DockView : : closeApplication ( )
{
2017-01-16 21:24:46 +03:00
DockCorona * dockCorona = qobject_cast < DockCorona * > ( this - > corona ( ) ) ;
2017-01-16 22:07:49 +03:00
2017-03-12 21:30:54 +03:00
if ( m_configView )
m_configView - > close ( ) ;
2017-01-17 21:09:43 +03:00
if ( dockCorona )
2017-01-16 21:24:46 +03:00
dockCorona - > closeApplication ( ) ;
2017-01-05 01:28:25 +03:00
}
2017-03-20 21:40:27 +03:00
void DockView : : deactivateApplets ( )
{
if ( ! containment ( ) ) {
return ;
}
foreach ( auto applet , containment ( ) - > applets ( ) ) {
PlasmaQuick : : AppletQuickItem * ai = applet - > property ( " _plasma_graphicObject " ) . value < PlasmaQuick : : AppletQuickItem * > ( ) ;
if ( ai ) {
ai - > setExpanded ( false ) ;
}
}
}
2017-01-02 13:02:35 +03:00
QVariantList DockView : : containmentActions ( )
{
QVariantList actions ;
/*if (containment()->corona()->immutability() != Plasma::Types::Mutable) {
return actions ;
} */
//FIXME: the trigger string it should be better to be supported this way
//const QString trigger = Plasma::ContainmentActions::eventToString(event);
const QString trigger = " RightButton;NoModifier " ;
2017-02-12 11:02:01 +03:00
Plasma : : ContainmentActions * plugin = this - > containment ( ) - > containmentActions ( ) . value ( trigger ) ;
2017-01-16 22:07:49 +03:00
2017-01-02 13:02:35 +03:00
if ( ! plugin ) {
return actions ;
}
2017-01-16 22:07:49 +03:00
2017-02-12 11:02:01 +03:00
if ( plugin - > containment ( ) ! = this - > containment ( ) ) {
plugin - > setContainment ( this - > containment ( ) ) ;
2017-01-02 13:02:35 +03:00
// now configure it
2017-02-12 11:02:01 +03:00
KConfigGroup cfg ( this - > containment ( ) - > corona ( ) - > config ( ) , " ActionPlugins " ) ;
cfg = KConfigGroup ( & cfg , QString : : number ( this - > containment ( ) - > containmentType ( ) ) ) ;
2017-01-02 13:02:35 +03:00
KConfigGroup pluginConfig = KConfigGroup ( & cfg , trigger ) ;
plugin - > restore ( pluginConfig ) ;
}
2017-01-16 22:07:49 +03:00
2017-01-02 13:02:35 +03:00
foreach ( QAction * ac , plugin - > contextualActions ( ) ) {
actions < < QVariant : : fromValue < QAction * > ( ac ) ;
}
2017-01-16 22:07:49 +03:00
2017-01-02 13:02:35 +03:00
return actions ;
}
2017-01-13 02:55:43 +03:00
2017-01-03 16:33:30 +03:00
//!BEGIN overriding context menus behavior
void DockView : : menuAboutToHide ( )
{
m_contextMenu = 0 ;
m_visibility - > setBlockHiding ( false ) ;
}
void DockView : : mouseReleaseEvent ( QMouseEvent * event )
{
2017-02-12 11:02:01 +03:00
if ( ! event | | ! this - > containment ( ) ) {
2017-01-03 16:33:30 +03:00
return ;
}
2017-01-16 22:07:49 +03:00
2017-01-03 16:33:30 +03:00
PlasmaQuick : : ContainmentView : : mouseReleaseEvent ( event ) ;
2017-02-12 11:02:01 +03:00
event - > setAccepted ( this - > containment ( ) - > containmentActions ( ) . contains ( Plasma : : ContainmentActions : : eventToString ( event ) ) ) ;
2017-01-03 16:33:30 +03:00
}
void DockView : : mousePressEvent ( QMouseEvent * event )
{
2017-02-19 20:49:19 +03:00
//qDebug() << "Step -1 ...";
2017-02-12 11:02:01 +03:00
if ( ! event | | ! this - > containment ( ) ) {
2017-01-03 16:33:30 +03:00
return ;
}
2017-01-16 22:07:49 +03:00
2017-02-19 20:49:19 +03:00
//qDebug() << "Step 0...";
2017-01-16 22:07:49 +03:00
2017-01-03 16:33:30 +03:00
//even if the menu is executed synchronously, other events may be processed
//by the qml incubator when plasma is loading, so we need to guard there
if ( m_contextMenu ) {
2017-02-19 21:17:24 +03:00
//qDebug() << "Step 0.5 ...";
2017-01-03 16:33:30 +03:00
m_contextMenu - > close ( ) ;
2017-01-28 21:30:21 +03:00
m_contextMenu = 0 ;
2017-01-03 16:33:30 +03:00
PlasmaQuick : : ContainmentView : : mousePressEvent ( event ) ;
return ;
}
2017-01-16 22:07:49 +03:00
2017-02-19 20:49:19 +03:00
//qDebug() << "1 ...";
2017-01-03 16:33:30 +03:00
const QString trigger = Plasma : : ContainmentActions : : eventToString ( event ) ;
2017-01-16 22:07:49 +03:00
2017-01-03 16:33:30 +03:00
if ( trigger = = " RightButton;NoModifier " ) {
2017-02-12 11:02:01 +03:00
Plasma : : ContainmentActions * plugin = this - > containment ( ) - > containmentActions ( ) . value ( trigger ) ;
2017-01-16 22:07:49 +03:00
2017-01-03 16:33:30 +03:00
if ( ! plugin | | plugin - > contextualActions ( ) . isEmpty ( ) ) {
event - > setAccepted ( false ) ;
return ;
}
2017-01-16 22:07:49 +03:00
2017-02-19 20:49:19 +03:00
//qDebug() << "2 ...";
2017-01-03 16:33:30 +03:00
//the plugin can be a single action or a context menu
//Don't have an action list? execute as single action
//and set the event position as action data
/*if (plugin->contextualActions().length() == 1) {
QAction * action = plugin - > contextualActions ( ) . at ( 0 ) ;
action - > setData ( event - > pos ( ) ) ;
action - > trigger ( ) ;
event - > accept ( ) ;
return ;
} */
//FIXME: very inefficient appletAt() implementation
Plasma : : Applet * applet = 0 ;
2017-01-27 21:03:24 +03:00
bool inSystray = false ;
2017-01-16 22:07:49 +03:00
2017-02-12 11:02:01 +03:00
foreach ( Plasma : : Applet * appletTemp , this - > containment ( ) - > applets ( ) ) {
2017-01-26 21:28:04 +03:00
PlasmaQuick : : AppletQuickItem * ai = appletTemp - > property ( " _plasma_graphicObject " ) . value < PlasmaQuick : : AppletQuickItem * > ( ) ;
2017-01-03 16:33:30 +03:00
if ( ai & & ai - > isVisible ( ) & & ai - > contains ( ai - > mapFromItem ( contentItem ( ) , event - > pos ( ) ) ) ) {
applet = ai - > applet ( ) ;
2017-01-27 21:03:24 +03:00
KPluginMetaData meta = applet - > kPackage ( ) . metadata ( ) ;
2017-01-26 22:18:27 +03:00
2017-01-27 21:03:24 +03:00
//Try to find applets inside a systray
if ( meta . pluginId ( ) = = " org.kde.plasma.systemtray " ) {
auto systrayId = applet - > config ( ) . readEntry ( " SystrayContainmentId " ) ;
applet = 0 ;
inSystray = true ;
Plasma : : Containment * cont = containmentById ( systrayId . toInt ( ) ) ;
2017-01-26 22:18:27 +03:00
2017-01-27 21:03:24 +03:00
if ( cont ) {
foreach ( Plasma : : Applet * appletCont , cont - > applets ( ) ) {
PlasmaQuick : : AppletQuickItem * ai2 = appletCont - > property ( " _plasma_graphicObject " ) . value < PlasmaQuick : : AppletQuickItem * > ( ) ;
if ( ai2 & & ai2 - > isVisible ( ) & & ai2 - > contains ( ai2 - > mapFromItem ( contentItem ( ) , event - > pos ( ) ) ) ) {
applet = ai2 - > applet ( ) ;
break ;
}
2017-01-26 22:18:27 +03:00
}
}
break ;
} else {
ai = 0 ;
}
2017-01-03 16:33:30 +03:00
}
}
2017-01-16 22:07:49 +03:00
2017-01-27 21:03:24 +03:00
if ( ! applet & & ! inSystray ) {
2017-02-12 11:02:01 +03:00
applet = this - > containment ( ) ;
2017-01-26 22:56:46 +03:00
}
2017-02-19 20:49:19 +03:00
//qDebug() << "3 ...";
2017-02-19 20:06:37 +03:00
2017-01-03 16:33:30 +03:00
if ( applet ) {
2017-01-03 21:44:14 +03:00
KPluginMetaData meta = applet - > kPackage ( ) . metadata ( ) ;
2017-01-16 22:07:49 +03:00
2017-02-19 20:49:19 +03:00
//qDebug() << "3.5 ...";
2017-02-19 20:06:37 +03:00
2017-01-26 22:18:27 +03:00
if ( meta . pluginId ( ) ! = " org.kde.latte.plasmoid " ) {
2017-02-19 21:25:05 +03:00
//qDebug() << "4...";
2017-01-03 16:33:30 +03:00
QMenu * desktopMenu = new QMenu ;
desktopMenu - > setAttribute ( Qt : : WA_DeleteOnClose ) ;
m_contextMenu = desktopMenu ;
2017-01-16 22:07:49 +03:00
2017-01-03 16:33:30 +03:00
if ( this - > mouseGrabberItem ( ) ) {
//workaround, this fixes for me most of the right click menu behavior
2017-01-26 22:18:27 +03:00
this - > mouseGrabberItem ( ) - > ungrabMouse ( ) ;
2017-01-03 16:33:30 +03:00
return ;
}
2017-01-16 22:07:49 +03:00
2017-02-19 20:49:19 +03:00
//qDebug() << "5 ...";
2017-01-16 22:07:49 +03:00
2017-01-03 16:33:30 +03:00
if ( applet ) {
2017-02-19 20:49:19 +03:00
//qDebug() << "5.3 ...";
2017-01-03 16:33:30 +03:00
emit applet - > contextualActionsAboutToShow ( ) ;
addAppletActions ( desktopMenu , applet , event ) ;
} else {
2017-02-19 20:49:19 +03:00
//qDebug() << "5.6 ...";
2017-02-12 11:02:01 +03:00
emit this - > containment ( ) - > contextualActionsAboutToShow ( ) ;
2017-01-03 16:33:30 +03:00
addContainmentActions ( desktopMenu , event ) ;
}
2017-01-16 22:07:49 +03:00
2017-01-03 16:33:30 +03:00
//this is a workaround where Qt now creates the menu widget
//in .exec before oxygen can polish it and set the following attribute
desktopMenu - > setAttribute ( Qt : : WA_TranslucentBackground ) ;
//end workaround
QPoint pos = event - > globalPos ( ) ;
2017-01-16 22:07:49 +03:00
2017-01-03 16:33:30 +03:00
if ( applet ) {
2017-02-19 20:49:19 +03:00
//qDebug() << "6 ...";
2017-01-03 16:33:30 +03:00
desktopMenu - > adjustSize ( ) ;
2017-01-16 22:07:49 +03:00
2017-02-08 21:48:46 +03:00
if ( this - > screen ( ) ) {
const QRect scr = this - > screen ( ) - > geometry ( ) ;
2017-01-03 16:33:30 +03:00
int smallStep = 3 ;
int x = event - > globalPos ( ) . x ( ) + smallStep ;
int y = event - > globalPos ( ) . y ( ) + smallStep ;
2017-01-16 22:07:49 +03:00
2017-01-03 16:33:30 +03:00
//qDebug()<<x << " - "<<y;
2017-01-16 22:07:49 +03:00
2017-01-03 16:33:30 +03:00
if ( event - > globalPos ( ) . x ( ) > scr . center ( ) . x ( ) ) {
x = event - > globalPos ( ) . x ( ) - desktopMenu - > width ( ) - smallStep ;
}
2017-01-16 22:07:49 +03:00
2017-01-03 16:33:30 +03:00
if ( event - > globalPos ( ) . y ( ) > scr . center ( ) . y ( ) ) {
y = event - > globalPos ( ) . y ( ) - desktopMenu - > height ( ) - smallStep ;
}
2017-01-16 22:07:49 +03:00
2017-01-03 16:33:30 +03:00
pos = QPoint ( x , y ) ;
}
}
2017-01-16 22:07:49 +03:00
2017-02-19 20:49:19 +03:00
//qDebug() << "7...";
2017-01-16 22:07:49 +03:00
2017-01-03 16:33:30 +03:00
if ( desktopMenu - > isEmpty ( ) ) {
2017-02-19 20:49:19 +03:00
//qDebug() << "7.5 ...";
2017-01-03 16:33:30 +03:00
delete desktopMenu ;
event - > accept ( ) ;
return ;
}
2017-01-16 22:07:49 +03:00
2017-01-03 16:33:30 +03:00
connect ( desktopMenu , SIGNAL ( aboutToHide ( ) ) , this , SLOT ( menuAboutToHide ( ) ) ) ;
m_visibility - > setBlockHiding ( true ) ;
desktopMenu - > popup ( pos ) ;
event - > setAccepted ( true ) ;
return ;
}
2017-02-19 20:06:37 +03:00
2017-02-19 20:49:19 +03:00
//qDebug() << "8 ...";
2017-01-03 16:33:30 +03:00
}
2017-02-19 20:06:37 +03:00
2017-02-19 20:49:19 +03:00
//qDebug() << "9 ...";
2017-01-03 16:33:30 +03:00
}
2017-01-16 22:07:49 +03:00
2017-02-19 20:49:19 +03:00
//qDebug() << "10 ...";
2017-01-03 16:33:30 +03:00
PlasmaQuick : : ContainmentView : : mousePressEvent ( event ) ;
}
void DockView : : addAppletActions ( QMenu * desktopMenu , Plasma : : Applet * applet , QEvent * event )
{
2017-02-12 11:02:01 +03:00
if ( ! this - > containment ( ) ) {
2017-01-03 16:33:30 +03:00
return ;
}
2017-01-16 22:07:49 +03:00
2017-01-03 16:33:30 +03:00
foreach ( QAction * action , applet - > contextualActions ( ) ) {
if ( action ) {
desktopMenu - > addAction ( action ) ;
}
}
2017-01-16 22:07:49 +03:00
2017-01-03 16:33:30 +03:00
if ( ! applet - > failedToLaunch ( ) ) {
QAction * runAssociatedApplication = applet - > actions ( ) - > action ( QStringLiteral ( " run associated application " ) ) ;
2017-01-16 22:07:49 +03:00
2017-01-03 16:33:30 +03:00
if ( runAssociatedApplication & & runAssociatedApplication - > isEnabled ( ) ) {
desktopMenu - > addAction ( runAssociatedApplication ) ;
}
2017-01-16 22:07:49 +03:00
2017-01-03 16:33:30 +03:00
QAction * configureApplet = applet - > actions ( ) - > action ( QStringLiteral ( " configure " ) ) ;
2017-01-16 22:07:49 +03:00
2017-01-03 16:33:30 +03:00
if ( configureApplet & & configureApplet - > isEnabled ( ) ) {
desktopMenu - > addAction ( configureApplet ) ;
}
2017-01-16 22:07:49 +03:00
2017-01-03 16:33:30 +03:00
QAction * appletAlternatives = applet - > actions ( ) - > action ( QStringLiteral ( " alternatives " ) ) ;
2017-01-16 22:07:49 +03:00
2017-01-03 16:33:30 +03:00
if ( appletAlternatives & & appletAlternatives - > isEnabled ( ) ) {
desktopMenu - > addAction ( appletAlternatives ) ;
}
}
2017-01-16 22:07:49 +03:00
2017-02-12 11:02:01 +03:00
QMenu * containmentMenu = new QMenu ( i18nc ( " %1 is the name of the containment " , " %1 Options " , this - > containment ( ) - > title ( ) ) , desktopMenu ) ;
2017-01-03 16:33:30 +03:00
addContainmentActions ( containmentMenu , event ) ;
2017-01-16 22:07:49 +03:00
2017-01-03 16:33:30 +03:00
if ( ! containmentMenu - > isEmpty ( ) ) {
int enabled = 0 ;
//count number of real actions
QListIterator < QAction * > actionsIt ( containmentMenu - > actions ( ) ) ;
2017-01-16 22:07:49 +03:00
2017-01-03 16:33:30 +03:00
while ( enabled < 3 & & actionsIt . hasNext ( ) ) {
QAction * action = actionsIt . next ( ) ;
2017-01-16 22:07:49 +03:00
2017-01-03 16:33:30 +03:00
if ( action - > isVisible ( ) & & ! action - > isSeparator ( ) ) {
+ + enabled ;
}
}
2017-01-16 22:07:49 +03:00
2017-01-03 17:21:59 +03:00
desktopMenu - > addSeparator ( ) ;
2017-01-16 22:07:49 +03:00
2017-01-03 16:33:30 +03:00
if ( enabled ) {
//if there is only one, don't create a submenu
2017-03-18 02:53:44 +03:00
// if (enabled < 2) {
foreach ( QAction * action , containmentMenu - > actions ( ) ) {
if ( action - > isVisible ( ) ) {
desktopMenu - > addAction ( action ) ;
2017-01-03 16:33:30 +03:00
}
}
2017-03-18 02:53:44 +03:00
// } else {
// desktopMenu->addMenu(containmentMenu);
// }
2017-01-03 16:33:30 +03:00
}
}
2017-01-16 22:07:49 +03:00
2017-02-12 11:02:01 +03:00
if ( this - > containment ( ) - > immutability ( ) = = Plasma : : Types : : Mutable & &
2017-02-27 13:44:51 +03:00
( this - > containment ( ) - > containmentType ( ) ! = Plasma : : Types : : PanelContainment | | this - > containment ( ) - > isUserConfiguring ( ) ) ) {
2017-01-03 16:33:30 +03:00
QAction * closeApplet = applet - > actions ( ) - > action ( QStringLiteral ( " remove " ) ) ;
2017-01-16 22:07:49 +03:00
2017-01-03 16:33:30 +03:00
//qDebug() << "checking for removal" << closeApplet;
if ( closeApplet ) {
if ( ! desktopMenu - > isEmpty ( ) ) {
desktopMenu - > addSeparator ( ) ;
}
2017-01-16 22:07:49 +03:00
2017-01-03 16:33:30 +03:00
//qDebug() << "adding close action" << closeApplet->isEnabled() << closeApplet->isVisible();
desktopMenu - > addAction ( closeApplet ) ;
}
}
}
void DockView : : addContainmentActions ( QMenu * desktopMenu , QEvent * event )
{
2017-02-12 11:02:01 +03:00
if ( ! this - > containment ( ) ) {
2017-01-03 16:33:30 +03:00
return ;
}
2017-01-16 22:07:49 +03:00
2017-02-12 11:02:01 +03:00
if ( this - > containment ( ) - > corona ( ) - > immutability ( ) ! = Plasma : : Types : : Mutable & &
2017-02-27 13:44:51 +03:00
! KAuthorized : : authorizeAction ( QStringLiteral ( " plasma/containment_actions " ) ) ) {
2017-01-03 16:33:30 +03:00
//qDebug() << "immutability";
return ;
}
2017-01-16 22:07:49 +03:00
2017-01-03 16:33:30 +03:00
//this is what ContainmentPrivate::prepareContainmentActions was
const QString trigger = Plasma : : ContainmentActions : : eventToString ( event ) ;
//"RightButton;NoModifier"
2017-02-12 11:02:01 +03:00
Plasma : : ContainmentActions * plugin = this - > containment ( ) - > containmentActions ( ) . value ( trigger ) ;
2017-01-16 22:07:49 +03:00
2017-01-03 16:33:30 +03:00
if ( ! plugin ) {
return ;
}
2017-01-16 22:07:49 +03:00
2017-02-12 11:02:01 +03:00
if ( plugin - > containment ( ) ! = this - > containment ( ) ) {
plugin - > setContainment ( this - > containment ( ) ) ;
2017-01-03 16:33:30 +03:00
// now configure it
2017-02-12 11:02:01 +03:00
KConfigGroup cfg ( this - > containment ( ) - > corona ( ) - > config ( ) , " ActionPlugins " ) ;
cfg = KConfigGroup ( & cfg , QString : : number ( this - > containment ( ) - > containmentType ( ) ) ) ;
2017-01-03 16:33:30 +03:00
KConfigGroup pluginConfig = KConfigGroup ( & cfg , trigger ) ;
plugin - > restore ( pluginConfig ) ;
}
2017-01-16 22:07:49 +03:00
2017-01-03 16:33:30 +03:00
QList < QAction * > actions = plugin - > contextualActions ( ) ;
2017-01-16 22:07:49 +03:00
2017-01-03 16:33:30 +03:00
if ( actions . isEmpty ( ) ) {
//it probably didn't bother implementing the function. give the user a chance to set
//a better plugin. note that if the user sets no-plugin this won't happen...
2017-02-12 11:02:01 +03:00
if ( ( this - > containment ( ) - > containmentType ( ) ! = Plasma : : Types : : PanelContainment & &
this - > containment ( ) - > containmentType ( ) ! = Plasma : : Types : : CustomPanelContainment ) & &
2017-02-27 13:44:51 +03:00
this - > containment ( ) - > actions ( ) - > action ( QStringLiteral ( " configure " ) ) ) {
2017-02-12 11:02:01 +03:00
desktopMenu - > addAction ( this - > containment ( ) - > actions ( ) - > action ( QStringLiteral ( " configure " ) ) ) ;
2017-01-03 16:33:30 +03:00
}
} else {
2017-03-18 02:53:44 +03:00
auto * dockCorona = qobject_cast < DockCorona * > ( this - > corona ( ) ) ;
2017-03-18 14:21:17 +03:00
if ( dockCorona & & dockCorona - > globalSettings ( ) - > exposeAltSession ( ) ) {
2017-03-18 02:53:44 +03:00
desktopMenu - > addSeparator ( ) ;
2017-03-18 14:21:17 +03:00
desktopMenu - > addAction ( dockCorona - > globalSettings ( ) - > altSessionAction ( ) ) ;
2017-03-18 02:53:44 +03:00
}
2017-01-03 16:33:30 +03:00
desktopMenu - > addActions ( actions ) ;
}
2017-01-16 22:07:49 +03:00
2017-01-03 16:33:30 +03:00
return ;
}
2017-01-27 21:03:24 +03:00
2017-02-06 04:55:41 +03:00
Plasma : : Containment * DockView : : containmentById ( uint id )
2017-01-27 21:03:24 +03:00
{
foreach ( auto containment , corona ( ) - > containments ( ) ) {
if ( id = = containment - > id ( ) ) {
return containment ;
}
}
return 0 ;
}
2017-01-03 16:33:30 +03:00
//!END overriding context menus behavior
2017-01-02 13:02:35 +03:00
2017-01-31 22:25:00 +03:00
//!BEGIN draw panel shadows outside the dock window
Plasma : : FrameSvg : : EnabledBorders DockView : : enabledBorders ( ) const
{
return m_enabledBorders ;
}
void DockView : : updateEnabledBorders ( )
{
// qDebug() << "draw shadow!!!! :" << m_drawShadows;
2017-02-08 21:48:46 +03:00
if ( ! this - > screen ( ) ) {
2017-01-31 22:25:00 +03:00
return ;
}
Plasma : : FrameSvg : : EnabledBorders borders = Plasma : : FrameSvg : : AllBorders ;
2017-02-04 17:41:12 +03:00
switch ( location ( ) ) {
2017-02-27 13:44:51 +03:00
case Plasma : : Types : : TopEdge :
borders & = ~ Plasma : : FrameSvg : : TopBorder ;
break ;
2017-01-31 22:25:00 +03:00
2017-02-27 13:44:51 +03:00
case Plasma : : Types : : LeftEdge :
borders & = ~ Plasma : : FrameSvg : : LeftBorder ;
break ;
2017-01-31 22:25:00 +03:00
2017-02-27 13:44:51 +03:00
case Plasma : : Types : : RightEdge :
borders & = ~ Plasma : : FrameSvg : : RightBorder ;
break ;
2017-01-31 22:25:00 +03:00
2017-02-27 13:44:51 +03:00
case Plasma : : Types : : BottomEdge :
borders & = ~ Plasma : : FrameSvg : : BottomBorder ;
break ;
2017-01-31 22:25:00 +03:00
2017-02-27 13:44:51 +03:00
default :
break ;
2017-02-04 17:41:12 +03:00
}
2017-01-31 22:25:00 +03:00
2017-02-04 17:41:12 +03:00
if ( ( location ( ) = = Plasma : : Types : : LeftEdge | | location ( ) = = Plasma : : Types : : RightEdge ) ) {
2017-03-07 19:29:37 +03:00
if ( maxLength ( ) = = 1 & & m_alignment = = Dock : : Justify & & ! m_forceDrawCenteredBorders ) {
2017-02-04 17:41:12 +03:00
borders & = ~ Plasma : : FrameSvg : : TopBorder ;
borders & = ~ Plasma : : FrameSvg : : BottomBorder ;
2017-01-31 22:25:00 +03:00
}
2017-04-09 01:06:48 +03:00
if ( m_alignment = = Dock : : Top & & ! m_forceDrawCenteredBorders & & m_offset = = 0 ) {
2017-01-31 22:25:00 +03:00
borders & = ~ Plasma : : FrameSvg : : TopBorder ;
}
2017-04-09 01:06:48 +03:00
if ( m_alignment = = Dock : : Bottom & & ! m_forceDrawCenteredBorders & & m_offset = = 0 ) {
2017-01-31 22:25:00 +03:00
borders & = ~ Plasma : : FrameSvg : : BottomBorder ;
}
}
2017-02-04 17:41:12 +03:00
if ( location ( ) = = Plasma : : Types : : TopEdge | | location ( ) = = Plasma : : Types : : BottomEdge ) {
if ( maxLength ( ) = = 1 & & m_alignment = = Dock : : Justify ) {
borders & = ~ Plasma : : FrameSvg : : LeftBorder ;
borders & = ~ Plasma : : FrameSvg : : RightBorder ;
}
2017-01-31 22:25:00 +03:00
2017-04-09 01:06:48 +03:00
if ( m_alignment = = Dock : : Left & & m_offset = = 0 ) {
2017-02-04 17:41:12 +03:00
borders & = ~ Plasma : : FrameSvg : : LeftBorder ;
}
2017-04-09 01:06:48 +03:00
if ( m_alignment = = Dock : : Right & & m_offset = = 0 ) {
2017-02-04 17:41:12 +03:00
borders & = ~ Plasma : : FrameSvg : : RightBorder ;
}
}
2017-01-31 22:25:00 +03:00
2017-02-04 17:41:12 +03:00
if ( m_enabledBorders ! = borders ) {
2017-01-31 22:25:00 +03:00
m_enabledBorders = borders ;
emit enabledBordersChanged ( ) ;
}
2017-02-04 17:41:12 +03:00
if ( ! m_drawShadows ) {
PanelShadows : : self ( ) - > removeWindow ( this ) ;
} else {
PanelShadows : : self ( ) - > setEnabledBorders ( this , borders ) ;
}
2017-01-31 22:25:00 +03:00
}
//!END draw panel shadows outside the dock window
2017-02-27 01:53:27 +03:00
//!BEGIN configuration functions
void DockView : : saveConfig ( )
{
if ( ! this - > containment ( ) )
return ;
auto config = this - > containment ( ) - > config ( ) ;
config . writeEntry ( " onPrimary " , m_onPrimary ) ;
2017-03-10 23:41:13 +03:00
config . writeEntry ( " session " , ( int ) m_session ) ;
2017-03-19 00:32:27 +03:00
config . writeEntry ( " dockWindowBehavior " , m_dockWinBehavior ) ;
2017-02-27 01:53:27 +03:00
this - > containment ( ) - > configNeedsSaving ( ) ;
}
void DockView : : restoreConfig ( )
{
if ( ! this - > containment ( ) )
return ;
auto config = this - > containment ( ) - > config ( ) ;
setOnPrimary ( config . readEntry ( " onPrimary " , true ) ) ;
2017-03-10 23:41:13 +03:00
setSession ( ( Dock : : SessionType ) config . readEntry ( " session " , ( int ) Dock : : DefaultSession ) ) ;
2017-03-19 00:32:27 +03:00
setDockWinBehavior ( config . readEntry ( " dockWindowBehavior " , false ) ) ;
2017-02-27 01:53:27 +03:00
}
//!END configuration functions
2016-12-31 00:22:28 +03:00
}
//!END namespace