2009-08-24 16:17:15 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
2009-09-15 07:12:54 +00:00
|
|
|
// oxygensizegrip.cpp
|
2010-05-22 05:40:39 +00:00
|
|
|
// bottom right size grip for borderless windows
|
2009-08-24 16:17:15 +00:00
|
|
|
// -------------------
|
2009-09-09 00:55:55 +00:00
|
|
|
//
|
2009-08-25 04:15:13 +00:00
|
|
|
// Copyright (c) 2009 Hugo Pereira Da Costa <hugo.pereira@free.fr>
|
2009-08-24 16:17:15 +00:00
|
|
|
//
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
// of this software and associated documentation files (the "Software"), to
|
|
|
|
// deal in the Software without restriction, including without limitation the
|
|
|
|
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
|
|
// sell copies of the Software, and to permit persons to whom the Software is
|
|
|
|
// furnished to do so, subject to the following conditions:
|
|
|
|
//
|
|
|
|
// The above copyright notice and this permission notice shall be included in
|
|
|
|
// all copies or substantial portions of the Software.
|
|
|
|
//
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
2009-09-09 00:55:55 +00:00
|
|
|
// IN THE SOFTWARE.
|
2009-08-24 16:17:15 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
2009-08-22 08:24:06 +00:00
|
|
|
|
2009-09-16 06:09:31 +00:00
|
|
|
|
|
|
|
#include "oxygensizegrip.h"
|
|
|
|
#include "oxygenbutton.h"
|
|
|
|
#include "oxygenclient.h"
|
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
#include <cassert>
|
2009-09-20 07:42:03 +00:00
|
|
|
#include <QtGui/QPainter>
|
|
|
|
#include <QtGui/QPolygon>
|
2013-02-26 08:00:51 +00:00
|
|
|
#include <QTimer>
|
2009-08-22 08:24:06 +00:00
|
|
|
|
2013-07-30 04:57:02 +00:00
|
|
|
#include <QtX11Extras/QX11Info>
|
2009-08-22 08:24:06 +00:00
|
|
|
#include <X11/Xlib.h>
|
|
|
|
|
2009-09-15 07:12:54 +00:00
|
|
|
namespace Oxygen
|
2009-08-22 08:24:06 +00:00
|
|
|
{
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
//_____________________________________________
|
|
|
|
SizeGrip::SizeGrip( Client* client ):
|
|
|
|
QWidget(0),
|
2011-02-24 16:37:04 +00:00
|
|
|
_client( client )
|
2010-05-02 18:34:08 +00:00
|
|
|
{
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
setAttribute(Qt::WA_NoSystemBackground );
|
|
|
|
setAutoFillBackground( false );
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
// cursor
|
|
|
|
setCursor( Qt::SizeFDiagCursor );
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
// size
|
|
|
|
setFixedSize( QSize( GRIP_SIZE, GRIP_SIZE ) );
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
// mask
|
|
|
|
QPolygon p;
|
|
|
|
p << QPoint( 0, GRIP_SIZE )
|
|
|
|
<< QPoint( GRIP_SIZE, 0 )
|
|
|
|
<< QPoint( GRIP_SIZE, GRIP_SIZE )
|
|
|
|
<< QPoint( 0, GRIP_SIZE );
|
2009-08-22 08:24:06 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
setMask( QRegion( p ) );
|
2009-08-22 08:24:06 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
// embed
|
|
|
|
embed();
|
|
|
|
updatePosition();
|
2009-10-19 22:51:31 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
// event filter
|
|
|
|
client->widget()->installEventFilter( this );
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
// show
|
|
|
|
show();
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
}
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
//_____________________________________________
|
|
|
|
SizeGrip::~SizeGrip( void )
|
|
|
|
{}
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
//_____________________________________________
|
|
|
|
void SizeGrip::activeChange( void )
|
|
|
|
{ XMapRaised( QX11Info::display(), winId() ); }
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
//_____________________________________________
|
|
|
|
void SizeGrip::embed( void )
|
|
|
|
{
|
2009-10-19 22:51:31 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
WId window_id = client().windowId();
|
|
|
|
if( client().isPreview() ) {
|
2009-10-19 22:51:31 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
setParent( client().widget() );
|
2009-10-19 22:51:31 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
} else if( window_id ) {
|
2009-10-19 22:51:31 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
WId current = window_id;
|
|
|
|
while( true )
|
|
|
|
{
|
|
|
|
WId root, parent = 0;
|
|
|
|
WId *children = 0L;
|
|
|
|
uint child_count = 0;
|
|
|
|
XQueryTree(QX11Info::display(), current, &root, &parent, &children, &child_count);
|
|
|
|
if( parent && parent != root && parent != current ) current = parent;
|
|
|
|
else break;
|
|
|
|
}
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
// reparent
|
|
|
|
XReparentWindow( QX11Info::display(), winId(), current, 0, 0 );
|
|
|
|
} else {
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
hide();
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
}
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
}
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
//_____________________________________________
|
2010-07-05 17:34:44 +00:00
|
|
|
bool SizeGrip::eventFilter( QObject*, QEvent* event )
|
2010-05-02 18:34:08 +00:00
|
|
|
{
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
if ( event->type() == QEvent::Resize) updatePosition();
|
|
|
|
return false;
|
2009-08-22 08:24:06 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
}
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
//_____________________________________________
|
|
|
|
void SizeGrip::paintEvent( QPaintEvent* )
|
|
|
|
{
|
2009-08-22 08:24:06 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
// get relevant colors
|
|
|
|
QColor base( client().backgroundColor( this, palette(), client().isActive() ) );
|
|
|
|
QColor light( client().helper().calcDarkColor( base ) );
|
|
|
|
QColor dark( client().helper().calcDarkColor( base.darker(150) ) );
|
|
|
|
|
|
|
|
// create and configure painter
|
|
|
|
QPainter painter(this);
|
|
|
|
painter.setRenderHints(QPainter::Antialiasing );
|
|
|
|
|
|
|
|
painter.setPen( Qt::NoPen );
|
|
|
|
painter.setBrush( base );
|
|
|
|
|
|
|
|
// polygon
|
|
|
|
QPolygon p;
|
|
|
|
p << QPoint( 0, GRIP_SIZE )
|
|
|
|
<< QPoint( GRIP_SIZE, 0 )
|
|
|
|
<< QPoint( GRIP_SIZE, GRIP_SIZE )
|
|
|
|
<< QPoint( 0, GRIP_SIZE );
|
|
|
|
painter.drawPolygon( p );
|
|
|
|
|
|
|
|
// diagonal border
|
|
|
|
painter.setBrush( Qt::NoBrush );
|
|
|
|
painter.setPen( QPen( dark, 3 ) );
|
|
|
|
painter.drawLine( QPoint( 0, GRIP_SIZE ), QPoint( GRIP_SIZE, 0 ) );
|
|
|
|
|
|
|
|
// side borders
|
|
|
|
painter.setPen( QPen( light, 1.5 ) );
|
|
|
|
painter.drawLine( QPoint( 1, GRIP_SIZE ), QPoint( GRIP_SIZE, GRIP_SIZE ) );
|
|
|
|
painter.drawLine( QPoint( GRIP_SIZE, 1 ), QPoint( GRIP_SIZE, GRIP_SIZE ) );
|
|
|
|
painter.end();
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
}
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
//_____________________________________________
|
|
|
|
void SizeGrip::mousePressEvent( QMouseEvent* event )
|
|
|
|
{
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
switch (event->button())
|
|
|
|
{
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
case Qt::RightButton:
|
|
|
|
{
|
|
|
|
hide();
|
|
|
|
QTimer::singleShot(5000, this, SLOT(show()));
|
|
|
|
break;
|
|
|
|
}
|
2009-08-22 08:24:06 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
case Qt::MidButton:
|
|
|
|
{
|
|
|
|
hide();
|
|
|
|
break;
|
|
|
|
}
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
case Qt::LeftButton:
|
|
|
|
if( rect().contains( event->pos() ) )
|
|
|
|
{
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
// check client window id
|
|
|
|
if( !client().windowId() ) break;
|
|
|
|
client().widget()->setFocus();
|
|
|
|
if( client().decoration() )
|
|
|
|
{ client().decoration()->performWindowOperation( KDecorationDefines::ResizeOp ); }
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
}
|
|
|
|
break;
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
default: break;
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
}
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
return;
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
}
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
//_______________________________________________________________________________
|
|
|
|
void SizeGrip::updatePosition( void )
|
|
|
|
{
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
QPoint position(
|
|
|
|
client().width() - GRIP_SIZE - OFFSET,
|
|
|
|
client().height() - GRIP_SIZE - OFFSET );
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
if( client().isPreview() )
|
|
|
|
{
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
position -= QPoint(
|
|
|
|
client().layoutMetric( Client::LM_BorderRight )+
|
|
|
|
client().layoutMetric( Client::LM_OuterPaddingRight ),
|
|
|
|
client().layoutMetric( Client::LM_OuterPaddingBottom )+
|
|
|
|
client().layoutMetric( Client::LM_BorderBottom )
|
|
|
|
);
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
} else {
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
position -= QPoint(
|
|
|
|
client().layoutMetric( Client::LM_BorderRight ),
|
|
|
|
client().layoutMetric( Client::LM_BorderBottom ) );
|
|
|
|
}
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
move( position );
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
}
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-24 06:27:49 +00:00
|
|
|
}
|