2009-08-24 16:17:15 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
2009-09-15 07:12:54 +00:00
|
|
|
// oxygensizegrip.cpp
|
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>
|
|
|
|
#include <QtCore/QTimer>
|
2009-08-22 08:24:06 +00:00
|
|
|
|
2009-09-20 07:42:03 +00:00
|
|
|
#include <QtGui/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
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
//_____________________________________________
|
2009-09-15 07:12:54 +00:00
|
|
|
OxygenSizeGrip::OxygenSizeGrip( OxygenClient* client ):
|
2009-10-19 22:51:31 +00:00
|
|
|
QWidget(0),
|
2009-09-09 20:11:05 +00:00
|
|
|
client_( client )
|
2009-09-09 00:55:55 +00:00
|
|
|
{
|
2009-08-22 08:24:06 +00:00
|
|
|
|
2009-09-01 14:05:56 +00:00
|
|
|
setAttribute(Qt::WA_NoSystemBackground );
|
|
|
|
setAutoFillBackground( false );
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
// cursor
|
|
|
|
setCursor( Qt::SizeFDiagCursor );
|
|
|
|
|
|
|
|
// size
|
|
|
|
setFixedSize( QSize( GRIP_SIZE, GRIP_SIZE ) );
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
// mask
|
|
|
|
QPolygon p;
|
|
|
|
p << QPoint( 0, GRIP_SIZE )
|
|
|
|
<< QPoint( GRIP_SIZE, 0 )
|
|
|
|
<< QPoint( GRIP_SIZE, GRIP_SIZE )
|
|
|
|
<< QPoint( 0, GRIP_SIZE );
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
setMask( QRegion( p ) );
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
// embed
|
|
|
|
embed();
|
|
|
|
updatePosition();
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
// event filter
|
|
|
|
client->widget()->installEventFilter( this );
|
|
|
|
|
|
|
|
// show
|
|
|
|
show();
|
|
|
|
|
|
|
|
}
|
2009-10-19 22:51:31 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
//_____________________________________________
|
2009-09-15 07:12:54 +00:00
|
|
|
OxygenSizeGrip::~OxygenSizeGrip( void )
|
2009-08-22 08:24:06 +00:00
|
|
|
{}
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
//_____________________________________________
|
2009-09-15 07:12:54 +00:00
|
|
|
void OxygenSizeGrip::activeChange( void )
|
2009-09-01 14:05:56 +00:00
|
|
|
{ XMapRaised( QX11Info::display(), winId() ); }
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
//_____________________________________________
|
2009-09-15 07:12:54 +00:00
|
|
|
void OxygenSizeGrip::embed( void )
|
2009-08-22 08:24:06 +00:00
|
|
|
{
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
WId window_id = client().windowId();
|
2009-10-19 22:51:31 +00:00
|
|
|
if( client().isPreview() ) {
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-10-19 22:51:31 +00:00
|
|
|
setParent( client().widget() );
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-10-19 22:51:31 +00:00
|
|
|
} else if( window_id ) {
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
// reparent
|
|
|
|
XReparentWindow( QX11Info::display(), winId(), current, 0, 0 );
|
|
|
|
} else {
|
|
|
|
|
|
|
|
hide();
|
|
|
|
|
|
|
|
}
|
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-22 08:24:06 +00:00
|
|
|
//_____________________________________________
|
2009-09-15 07:12:54 +00:00
|
|
|
bool OxygenSizeGrip::eventFilter( QObject* object, QEvent* event )
|
2009-08-22 08:24:06 +00:00
|
|
|
{
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
if( object != client().widget() ) return false;
|
|
|
|
if ( event->type() == QEvent::Resize) updatePosition();
|
|
|
|
return false;
|
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-22 08:24:06 +00:00
|
|
|
//_____________________________________________
|
2009-09-15 07:12:54 +00:00
|
|
|
void OxygenSizeGrip::paintEvent( QPaintEvent* )
|
2009-08-22 08:24:06 +00:00
|
|
|
{
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
// get relevant colors
|
2009-10-15 17:47:55 +00:00
|
|
|
QColor base( client().backgroundColor( this, palette(), client().isActive() ) );
|
|
|
|
QColor light( client().helper().calcDarkColor( base ) );
|
|
|
|
QColor dark( client().helper().calcDarkColor( base.darker(150) ) );
|
2009-08-22 08:24:06 +00:00
|
|
|
|
|
|
|
// create and configure painter
|
|
|
|
QPainter painter(this);
|
|
|
|
painter.setRenderHints(QPainter::Antialiasing );
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
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 );
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
// diagonal border
|
|
|
|
painter.setBrush( Qt::NoBrush );
|
|
|
|
painter.setPen( QPen( dark, 3 ) );
|
|
|
|
painter.drawLine( QPoint( 0, GRIP_SIZE ), QPoint( GRIP_SIZE, 0 ) );
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
// 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
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
}
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
//_____________________________________________
|
2009-09-15 07:12:54 +00:00
|
|
|
void OxygenSizeGrip::mousePressEvent( QMouseEvent* event )
|
2009-08-22 08:24:06 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
switch (event->button())
|
|
|
|
{
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
case Qt::RightButton:
|
|
|
|
{
|
2009-09-09 00:55:55 +00:00
|
|
|
hide();
|
2009-08-22 08:24:06 +00:00
|
|
|
QTimer::singleShot(5000, this, SLOT(show()));
|
|
|
|
break;
|
|
|
|
}
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
case Qt::MidButton:
|
|
|
|
{
|
|
|
|
hide();
|
|
|
|
break;
|
|
|
|
}
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
case Qt::LeftButton:
|
|
|
|
if( rect().contains( event->pos() ) )
|
|
|
|
{
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
// check client window id
|
|
|
|
if( !client().windowId() ) break;
|
|
|
|
client().widget()->setFocus();
|
2009-10-19 22:51:31 +00:00
|
|
|
if( client().decoration() )
|
|
|
|
{ client().decoration()->performWindowOperation( KDecorationDefines::ResizeOp ); }
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
}
|
|
|
|
break;
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
default: break;
|
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-22 08:24:06 +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
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
//_______________________________________________________________________________
|
2009-09-15 07:12:54 +00:00
|
|
|
void OxygenSizeGrip::updatePosition( void )
|
2009-08-22 08:24:06 +00:00
|
|
|
{
|
2009-09-09 00:55:55 +00:00
|
|
|
|
|
|
|
QPoint position(
|
2009-08-22 08:24:06 +00:00
|
|
|
client().width() - GRIP_SIZE - OFFSET,
|
|
|
|
client().height() - GRIP_SIZE - OFFSET );
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-09-01 14:05:56 +00:00
|
|
|
if( client().isPreview() )
|
|
|
|
{
|
2009-09-09 00:55:55 +00:00
|
|
|
|
|
|
|
position -= QPoint(
|
2009-09-15 07:12:54 +00:00
|
|
|
client().layoutMetric( OxygenClient::LM_BorderRight )+
|
|
|
|
client().layoutMetric( OxygenClient::LM_OuterPaddingRight ),
|
|
|
|
client().layoutMetric( OxygenClient::LM_OuterPaddingBottom )+
|
|
|
|
client().layoutMetric( OxygenClient::LM_BorderBottom )
|
2009-09-02 04:26:59 +00:00
|
|
|
);
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-09-01 14:05:56 +00:00
|
|
|
} else {
|
2009-09-09 00:55:55 +00:00
|
|
|
|
|
|
|
position -= QPoint(
|
2009-09-15 07:12:54 +00:00
|
|
|
client().layoutMetric( OxygenClient::LM_BorderRight ),
|
|
|
|
client().layoutMetric( OxygenClient::LM_BorderBottom ) );
|
2009-08-22 08:24:06 +00:00
|
|
|
}
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
move( position );
|
|
|
|
|
|
|
|
}
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-24 06:27:49 +00:00
|
|
|
}
|