2016-12-25 09:25:27 +02:00
/*
* Copyright 2016 Smith AR < audoban @ openmailbox . org >
2017-01-02 17:05:30 -05:00
* Michail Vourlakos < mvourlakos @ gmail . com >
2016-12-25 09:25:27 +02:00
*
2017-01-02 17:05:30 -05:00
* This file is part of Latte - Dock
2016-12-25 09:25:27 +02:00
*
2017-01-02 17:05:30 -05:00
* Latte - Dock is free software ; you can redistribute it and / or
2016-12-25 09:25:27 +02:00
* modify it under the terms of the GNU General Public License as
2017-01-02 17:05:30 -05:00
* published by the Free Software Foundation ; either version 2 of
2016-12-25 09:25:27 +02:00
* the License , or ( at your option ) any later version .
*
2017-01-02 17:05:30 -05:00
* Latte - Dock is distributed in the hope that it will be useful ,
2016-12-25 09:25:27 +02:00
* 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-30 16:25:27 -05:00
# include "dockconfigview.h"
# include "dockview.h"
# include "dockcorona.h"
2016-12-25 09:25:27 +02:00
# include <QQuickItem>
# include <QQmlContext>
2016-12-28 18:01:25 +02:00
# include <QQmlEngine>
2016-12-25 09:25:27 +02:00
# include <QScreen>
2016-12-28 18:01:25 +02:00
# include <KLocalizedContext>
2016-12-25 09:25:27 +02:00
# include <KWindowSystem>
# include <KWindowEffects>
2016-12-30 16:25:27 -05:00
# include <Plasma/Package>
2016-12-25 09:25:27 +02:00
2016-12-30 02:20:06 -05:00
namespace Latte {
2016-12-30 16:25:27 -05:00
DockConfigView : : DockConfigView ( Plasma : : Containment * containment , DockView * dockView , QWindow * parent )
2017-01-04 01:35:22 +02:00
: PlasmaQuick : : ConfigView ( containment , parent ) ,
m_containment ( containment ) ,
m_dockView ( dockView ) ,
m_blockFocusLost ( false )
2016-12-25 09:25:27 +02:00
{
m_deleterTimer . setSingleShot ( true ) ;
m_deleterTimer . setInterval ( 10 * 1000 ) ;
connect ( & m_deleterTimer , & QTimer : : timeout , this , & QObject : : deleteLater ) ;
connect ( dockView , & QObject : : destroyed , this , & QObject : : deleteLater ) ;
m_screenSyncTimer . setSingleShot ( true ) ;
m_screenSyncTimer . setInterval ( 100 ) ;
connect ( dockView , SIGNAL ( screenChanged ( QScreen * ) ) , & m_screenSyncTimer , SLOT ( start ( ) ) ) ;
connect ( & m_screenSyncTimer , & QTimer : : timeout , this , [ this ] ( ) {
setScreen ( m_dockView - > screen ( ) ) ;
setFlags ( wFlags ( ) ) ;
syncGeometry ( ) ;
syncSlideEffect ( ) ;
} ) ;
2016-12-30 16:25:27 -05:00
connect ( containment , & Plasma : : Containment : : immutabilityChanged , this , & DockConfigView : : immutabilityChanged ) ;
2016-12-25 09:25:27 +02:00
}
2016-12-30 16:25:27 -05:00
DockConfigView : : ~ DockConfigView ( )
2016-12-25 09:25:27 +02:00
{
}
2016-12-30 16:25:27 -05:00
void DockConfigView : : init ( )
2016-12-25 09:25:27 +02:00
{
setDefaultAlphaBuffer ( true ) ;
setColor ( Qt : : transparent ) ;
rootContext ( ) - > setContextProperty ( QStringLiteral ( " dock " ) , m_dockView ) ;
2017-01-04 01:35:22 +02:00
rootContext ( ) - > setContextProperty ( QStringLiteral ( " dockConfig " ) , this ) ;
2016-12-28 18:01:25 +02:00
engine ( ) - > rootContext ( ) - > setContextObject ( new KLocalizedContext ( this ) ) ;
2016-12-30 16:25:27 -05:00
auto source = QUrl : : fromLocalFile ( m_containment - > corona ( ) - > kPackage ( ) . filePath ( " lattedockconfigurationui " ) ) ;
2016-12-25 09:25:27 +02:00
setSource ( source ) ;
syncSlideEffect ( ) ;
}
2016-12-30 16:25:27 -05:00
inline Qt : : WindowFlags DockConfigView : : wFlags ( ) const
2016-12-25 09:25:27 +02:00
{
return ( flags ( ) | Qt : : FramelessWindowHint | Qt : : WindowStaysOnTopHint ) & ~ Qt : : WindowDoesNotAcceptFocus ;
}
2016-12-30 16:25:27 -05:00
void DockConfigView : : syncGeometry ( )
2016-12-25 09:25:27 +02:00
{
if ( ! m_containment | | ! rootObject ( ) )
return ;
2016-12-29 00:43:26 -05:00
2016-12-25 09:25:27 +02:00
const auto location = m_containment - > location ( ) ;
const auto sGeometry = screen ( ) - > geometry ( ) ;
2017-01-03 19:52:31 -05:00
qDebug ( ) < < " sync geometry " ;
2016-12-25 09:25:27 +02:00
switch ( m_containment - > formFactor ( ) ) {
case Plasma : : Types : : Horizontal : {
const QSize size ( rootObject ( ) - > width ( ) , rootObject ( ) - > height ( ) ) ;
setMaximumSize ( size ) ;
setMinimumSize ( size ) ;
resize ( size ) ;
2016-12-29 00:43:26 -05:00
2016-12-25 09:25:27 +02:00
if ( location = = Plasma : : Types : : TopEdge ) {
2017-01-03 19:52:31 -05:00
setPosition ( sGeometry . center ( ) . x ( ) - size . width ( ) / 2 - 1
2016-12-25 09:25:27 +02:00
, m_dockView - > currentThickness ( ) ) ;
} else if ( location = = Plasma : : Types : : BottomEdge ) {
2017-01-03 19:52:31 -05:00
setPosition ( sGeometry . center ( ) . x ( ) - size . width ( ) / 2 - 1
, sGeometry . height ( ) - m_dockView - > currentThickness ( ) - size . height ( ) - 1 ) ;
2016-12-25 09:25:27 +02:00
}
}
break ;
case Plasma : : Types : : Vertical : {
const QSize size ( rootObject ( ) - > width ( ) , rootObject ( ) - > height ( ) ) ;
setMaximumSize ( size ) ;
setMinimumSize ( size ) ;
resize ( size ) ;
2016-12-29 00:43:26 -05:00
2016-12-25 09:25:27 +02:00
if ( location = = Plasma : : Types : : LeftEdge ) {
setPosition ( m_dockView - > currentThickness ( )
, sGeometry . center ( ) . y ( ) - size . height ( ) / 2 ) ;
} else if ( location = = Plasma : : Types : : RightEdge ) {
2017-01-03 19:52:31 -05:00
setPosition ( sGeometry . width ( ) - m_dockView - > currentThickness ( ) - size . width ( ) - 1
, sGeometry . center ( ) . y ( ) - size . height ( ) / 2 - 1 ) ;
2016-12-25 09:25:27 +02:00
}
}
break ;
default :
qWarning ( ) < < " no sync geometry, wrong formFactor " ;
//<< qEnumToStr(m_containment->formFactor());
break ;
}
}
2016-12-30 16:25:27 -05:00
void DockConfigView : : syncSlideEffect ( )
2016-12-25 09:25:27 +02:00
{
if ( ! m_containment )
return ;
2016-12-29 00:43:26 -05:00
2016-12-25 09:25:27 +02:00
KWindowEffects : : SlideFromLocation slideLocation { KWindowEffects : : NoEdge } ;
switch ( m_containment - > location ( ) ) {
case Plasma : : Types : : TopEdge :
slideLocation = KWindowEffects : : TopEdge ;
break ;
2016-12-29 00:43:26 -05:00
2016-12-25 09:25:27 +02:00
case Plasma : : Types : : RightEdge :
slideLocation = KWindowEffects : : RightEdge ;
break ;
2016-12-29 00:43:26 -05:00
2016-12-25 09:25:27 +02:00
case Plasma : : Types : : BottomEdge :
slideLocation = KWindowEffects : : BottomEdge ;
break ;
2016-12-29 00:43:26 -05:00
2016-12-25 09:25:27 +02:00
case Plasma : : Types : : LeftEdge :
slideLocation = KWindowEffects : : LeftEdge ;
break ;
2016-12-29 00:43:26 -05:00
2016-12-25 09:25:27 +02:00
default :
qDebug ( ) < < staticMetaObject . className ( ) < < " wrong location " ; // << qEnumToStr(m_containment->location());
break ;
}
KWindowEffects : : slideWindow ( winId ( ) , slideLocation , - 1 ) ;
}
2016-12-30 16:25:27 -05:00
void DockConfigView : : showEvent ( QShowEvent * ev )
2016-12-25 09:25:27 +02:00
{
KWindowSystem : : setType ( winId ( ) , NET : : Dock ) ;
setFlags ( wFlags ( ) ) ;
KWindowSystem : : setState ( winId ( ) , NET : : KeepAbove | NET : : SkipPager | NET : : SkipTaskbar ) ;
KWindowSystem : : forceActiveWindow ( winId ( ) ) ;
KWindowEffects : : enableBlurBehind ( winId ( ) , true ) ;
syncGeometry ( ) ;
syncSlideEffect ( ) ;
if ( m_containment )
m_containment - > setUserConfiguring ( true ) ;
2016-12-29 00:43:26 -05:00
2016-12-25 09:25:27 +02:00
m_screenSyncTimer . start ( ) ;
m_deleterTimer . stop ( ) ;
2016-12-30 16:32:48 -05:00
2016-12-25 09:25:27 +02:00
ConfigView : : showEvent ( ev ) ;
}
2016-12-30 16:25:27 -05:00
void DockConfigView : : hideEvent ( QHideEvent * ev )
2016-12-25 09:25:27 +02:00
{
m_deleterTimer . start ( ) ;
if ( m_containment ) {
m_dockView - > saveConfig ( ) ;
m_containment - > setUserConfiguring ( false ) ;
}
ConfigView : : hideEvent ( ev ) ;
}
2016-12-30 16:25:27 -05:00
void DockConfigView : : focusOutEvent ( QFocusEvent * ev )
2016-12-25 09:25:27 +02:00
{
Q_UNUSED ( ev ) ;
const auto * focusWindow = qGuiApp - > focusWindow ( ) ;
if ( focusWindow & & focusWindow - > flags ( ) . testFlag ( Qt : : Popup ) )
return ;
2016-12-29 00:43:26 -05:00
2017-01-04 01:35:22 +02:00
if ( ! m_blockFocusLost ) {
hide ( ) ;
}
2016-12-25 09:25:27 +02:00
}
2016-12-29 00:25:42 +02:00
2016-12-30 16:25:27 -05:00
void DockConfigView : : immutabilityChanged ( Plasma : : Types : : ImmutabilityType type )
2016-12-29 00:25:42 +02:00
{
if ( type ! = Plasma : : Types : : Mutable & & isVisible ( ) ) {
hide ( ) ;
}
}
2017-01-04 01:35:22 +02:00
void DockConfigView : : setSticker ( bool blockFocusLost )
{
if ( m_blockFocusLost = = blockFocusLost ) {
return ;
}
m_blockFocusLost = blockFocusLost ;
}
2016-12-30 02:20:06 -05:00
}
2016-12-25 09:25:27 +02:00
// kate: indent-mode cstyle; indent-width 4; replace-tabs on;