2009-11-15 03:24:04 +00:00
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
// oxygenclientgroupitemdata.cpp
|
|
|
|
// -------------------
|
|
|
|
//
|
|
|
|
// Copyright (c) 2009 Hugo Pereira Da Costa <hugo.pereira@free.fr>
|
|
|
|
// Copyright (c) 2003, 2004 David Johnson <david@usermode.org>
|
|
|
|
// Copyright (c) 2006, 2007 Riccardo Iaconelli <ruphy@fsfe.org>
|
|
|
|
//
|
|
|
|
// 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
|
|
|
|
// IN THE SOFTWARE.
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include "oxygenclientgroupitemdata.h"
|
|
|
|
#include "oxygenclientgroupitemdata.moc"
|
|
|
|
#include "oxygenclient.h"
|
|
|
|
|
|
|
|
namespace Oxygen
|
|
|
|
{
|
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
//____________________________________________________________________________
|
|
|
|
ClientGroupItemDataList::ClientGroupItemDataList( Client* parent ):
|
|
|
|
QObject( parent ),
|
|
|
|
QList<ClientGroupItemData>(),
|
|
|
|
client_( *parent ),
|
|
|
|
dirty_( false ),
|
|
|
|
animationsEnabled_( true ),
|
|
|
|
animation_( new Animation( 150, this ) ),
|
|
|
|
animationType_( AnimationNone ),
|
|
|
|
progress_(0),
|
|
|
|
draggedItem_( NoItem ),
|
|
|
|
targetItem_( NoItem )
|
2009-11-15 03:24:04 +00:00
|
|
|
{
|
2010-05-02 18:34:08 +00:00
|
|
|
|
|
|
|
// setup animation
|
|
|
|
animation().data()->setStartValue( 0 );
|
|
|
|
animation().data()->setEndValue( 1.0 );
|
|
|
|
animation().data()->setTargetObject( this );
|
|
|
|
animation().data()->setPropertyName( "progress" );
|
|
|
|
|
|
|
|
// setup connections
|
|
|
|
connect( animation().data(), SIGNAL( valueChanged( const QVariant& ) ), SLOT( updateBoundingRects( void ) ) );
|
|
|
|
connect( animation().data(), SIGNAL( finished( void ) ), SLOT( updateBoundingRects( void ) ) );
|
|
|
|
|
2009-11-15 03:24:04 +00:00
|
|
|
}
|
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
//________________________________________________________________
|
|
|
|
int ClientGroupItemDataList::itemAt( const QPoint& point, bool between ) const
|
|
|
|
{
|
2009-11-15 03:24:04 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
for( int i=0; i < count(); i++ )
|
|
|
|
{
|
|
|
|
QRect rect = at(i).activeRect_;
|
|
|
|
if( between ) rect.translate( -rect.width() / 2, 0 );
|
|
|
|
if( rect.adjusted(0,0,0,2).contains( point ) )
|
|
|
|
{ return i; }
|
|
|
|
}
|
2009-11-15 03:24:04 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
return NoItem;
|
2009-11-15 03:24:04 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
}
|
2009-11-15 03:24:04 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
//____________________________________________________________________________
|
|
|
|
void ClientGroupItemDataList::animate( AnimationTypes type, int target )
|
2009-11-15 03:24:04 +00:00
|
|
|
{
|
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
// store animation type
|
|
|
|
animationType_ = type;
|
2009-11-15 03:24:04 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
if( type == AnimationNone )
|
|
|
|
{
|
2009-11-15 03:24:04 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
if( isAnimationRunning() ) animation().data()->stop();
|
|
|
|
targetItem_ = NoItem;
|
|
|
|
draggedItem_ = NoItem;
|
|
|
|
targetRect_ = QRect();
|
2009-11-15 07:27:49 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
} else if( type & (AnimationEnter|AnimationMove ) ) {
|
2009-11-15 07:27:49 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
// store dragged item
|
|
|
|
bool animate( true );
|
2009-11-15 07:27:49 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
if( (type&AnimationSameTarget) && draggedItem_ == NoItem )
|
|
|
|
{
|
2009-11-15 03:24:04 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
animate = false;
|
|
|
|
draggedItem_ = target;
|
2009-11-15 03:24:04 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
} else if( (type&AnimationMove) && targetItem_ == target ) return;
|
2009-11-15 03:24:04 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
// check animation state
|
|
|
|
if( isAnimationRunning() ) animation().data()->stop();
|
2009-11-15 03:24:04 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
targetItem_ = target;
|
|
|
|
targetRect_ = QRect();
|
|
|
|
QRect titleRect( client_.titleRect() );
|
|
|
|
int left( titleRect.left() );
|
|
|
|
int width = (type&AnimationSameTarget) ?
|
|
|
|
titleRect.width()/count():
|
|
|
|
titleRect.width()/(count()+1);
|
2009-11-15 03:24:04 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
if( (type&AnimationSameTarget) && draggedItem_ < target )
|
|
|
|
{
|
|
|
|
target++;
|
|
|
|
if( target >= count() ) target = NoItem;
|
|
|
|
}
|
2009-11-15 03:24:04 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
// loop over items and update bounding rects
|
|
|
|
for( int index = 0; index < count(); index++ )
|
|
|
|
{
|
2009-11-15 03:24:04 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
ClientGroupItemData& item( ClientGroupItemDataList::operator[](index) );
|
|
|
|
if( index == target )
|
|
|
|
{
|
|
|
|
targetRect_ = item.refBoundingRect_;
|
|
|
|
targetRect_.setLeft( left );
|
|
|
|
targetRect_.setWidth( width );
|
|
|
|
left+=width;
|
|
|
|
}
|
2009-11-15 03:24:04 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
item.startBoundingRect_ = item.boundingRect_;
|
|
|
|
item.endBoundingRect_ = item.refBoundingRect_;
|
|
|
|
item.endBoundingRect_.setLeft( left );
|
2009-11-15 03:24:04 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
if( (type&AnimationSameTarget) && index == draggedItem_ )
|
|
|
|
{
|
2009-11-15 03:24:04 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
item.endBoundingRect_.setWidth( 0 );
|
2009-11-15 03:24:04 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
} else {
|
2009-11-15 03:24:04 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
item.endBoundingRect_.setWidth( width );
|
|
|
|
left+=width;
|
2009-11-15 03:24:04 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
}
|
2009-11-15 03:24:04 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
}
|
2010-02-12 01:14:43 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
if( targetRect_.isNull() )
|
|
|
|
{
|
|
|
|
targetRect_ = back().refBoundingRect_;
|
|
|
|
targetRect_.setLeft( left );
|
|
|
|
targetRect_.setWidth( width );
|
|
|
|
}
|
2010-02-12 01:14:43 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
if( animate )
|
|
|
|
{
|
2010-02-12 01:14:43 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
if( animationsEnabled() ) animation().data()->start();
|
|
|
|
else {
|
2010-02-12 01:14:43 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
// change progress to maximum
|
|
|
|
progress_ = 1;
|
|
|
|
updateBoundingRects();
|
2009-11-15 07:27:49 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
}
|
2009-11-15 07:27:49 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
} else {
|
2009-11-15 07:27:49 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
for( int index = 0; index < count(); index++ )
|
|
|
|
{
|
|
|
|
ClientGroupItemData& item( ClientGroupItemDataList::operator[](index) );
|
|
|
|
item.boundingRect_ = item.endBoundingRect_;
|
|
|
|
}
|
2009-11-15 07:27:49 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
updateButtons( true );
|
2009-11-15 03:24:04 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
}
|
2009-11-15 03:24:04 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
} else if( type & AnimationLeave ) {
|
2009-11-15 03:24:04 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
// stop animation state
|
|
|
|
if( isAnimationRunning() ) animation().data()->stop();
|
2009-11-15 03:24:04 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
// reset target
|
|
|
|
targetItem_ = NoItem;
|
|
|
|
targetRect_ = QRect();
|
2009-11-15 03:24:04 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
if( type & AnimationSameTarget )
|
|
|
|
{
|
2009-11-15 03:24:04 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
// store dragged item
|
|
|
|
draggedItem_ = target;
|
2009-11-15 03:24:04 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
// do nothing if only one item
|
|
|
|
if( count() <= 1 ) return;
|
2009-11-15 03:24:04 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
QRect titleRect( client_.titleRect() );
|
|
|
|
int left( titleRect.left() );
|
|
|
|
int width = titleRect.width()/(count()-1);
|
2009-11-15 03:24:04 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
// loop over items and update bounding rects
|
|
|
|
for( int index = 0; index < count(); index++ )
|
|
|
|
{
|
2009-11-15 07:27:49 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
ClientGroupItemData& item( ClientGroupItemDataList::operator[](index) );
|
|
|
|
item.startBoundingRect_ = item.boundingRect_;
|
|
|
|
item.endBoundingRect_ = item.refBoundingRect_;
|
|
|
|
item.endBoundingRect_.setLeft( left );
|
|
|
|
if( index != target )
|
|
|
|
{
|
2009-11-15 07:27:49 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
if( count() <= 2 )
|
|
|
|
{
|
2009-11-15 07:27:49 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
item.endBoundingRect_ = client_.defaultTitleRect( index == client_.visibleClientGroupItem() );
|
2009-11-15 07:27:49 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
} else {
|
2009-11-15 03:24:04 +00:00
|
|
|
|
2009-11-15 07:27:49 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
item.endBoundingRect_.setWidth( width );
|
|
|
|
left+=width;
|
2009-11-15 03:24:04 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
}
|
2009-11-15 03:24:04 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
} else {
|
2009-11-15 03:24:04 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
item.endBoundingRect_.setWidth( 0 );
|
2009-11-15 03:24:04 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
}
|
2009-11-15 03:24:04 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
}
|
2009-11-15 03:24:04 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
} else {
|
2009-11-15 03:24:04 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
// loop over items and update bounding rects
|
|
|
|
for( int index = 0; index < count(); index++ )
|
|
|
|
{
|
|
|
|
ClientGroupItemData& item( ClientGroupItemDataList::operator[](index) );
|
|
|
|
item.startBoundingRect_ = item.boundingRect_;
|
|
|
|
item.endBoundingRect_ = item.refBoundingRect_;
|
|
|
|
}
|
2009-11-15 03:24:04 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
}
|
2009-11-15 03:24:04 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
if( animationsEnabled() ) animation().data()->start();
|
|
|
|
else {
|
2009-11-15 03:24:04 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
// change progress to maximum
|
|
|
|
progress_ = 1;
|
|
|
|
updateBoundingRects();
|
2009-11-15 03:24:04 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
}
|
2009-11-15 03:24:04 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
}
|
2009-11-15 03:24:04 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
return;
|
2009-11-15 03:24:04 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
//____________________________________________________________________________
|
|
|
|
void ClientGroupItemDataList::updateButtonActivity( int visibleItem ) const
|
|
|
|
{
|
|
|
|
|
|
|
|
for( int index = 0; index < count(); index++ )
|
|
|
|
{
|
|
|
|
|
|
|
|
const ClientGroupItemData& item( at(index) );
|
|
|
|
if( item.closeButton_ )
|
|
|
|
{ item.closeButton_.data()->setForceInactive( index != visibleItem ); }
|
2009-11-15 03:24:04 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
}
|
2009-11-15 03:24:04 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//____________________________________________________________________________
|
|
|
|
void ClientGroupItemDataList::updateButtons( bool alsoUpdate ) const
|
2009-11-15 03:24:04 +00:00
|
|
|
{
|
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
// move close buttons
|
|
|
|
// this should move to ClientGroupItemDataList
|
|
|
|
if( alsoUpdate ) client_.widget()->setUpdatesEnabled( false );
|
|
|
|
for( int index = 0; index < count(); index++ )
|
|
|
|
{
|
2009-11-15 03:24:04 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
const ClientGroupItemData& item( at(index) );
|
|
|
|
if( !item.closeButton_ ) continue;
|
2009-11-15 03:24:04 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
if( (!item.boundingRect_.isValid()) || ((animationType_ & AnimationSameTarget)&&count()<=2 ) )
|
|
|
|
{
|
2009-11-15 03:24:04 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
item.closeButton_.data()->hide();
|
2009-11-15 03:24:04 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
} else {
|
2009-11-15 03:24:04 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
QPoint position(
|
|
|
|
item.boundingRect_.right() - client_.configuration().buttonSize() - client_.layoutMetric(KCommonDecoration::LM_TitleEdgeRight),
|
|
|
|
item.boundingRect_.top() + client_.layoutMetric( KCommonDecoration::LM_TitleEdgeTop ) );
|
2009-11-15 03:24:04 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
if( item.closeButton_.data()->isHidden() ) item.closeButton_.data()->show();
|
|
|
|
item.closeButton_.data()->move( position );
|
2009-11-15 03:24:04 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
}
|
2009-11-15 03:24:04 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
}
|
2009-11-15 03:24:04 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
if( alsoUpdate )
|
|
|
|
{
|
|
|
|
client_.widget()->setUpdatesEnabled( true );
|
|
|
|
client_.widget()->update();
|
|
|
|
}
|
2009-11-15 03:24:04 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
}
|
2009-11-15 03:24:04 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
//____________________________________________________________________________
|
|
|
|
void ClientGroupItemDataList::updateBoundingRects( bool alsoUpdate )
|
2009-11-15 03:24:04 +00:00
|
|
|
{
|
|
|
|
|
2010-05-20 22:00:13 +00:00
|
|
|
qreal ratio( progress() );
|
2010-05-02 18:34:08 +00:00
|
|
|
for( iterator iter = begin(); iter != end(); ++iter )
|
|
|
|
{
|
|
|
|
|
|
|
|
// left
|
|
|
|
if( iter->endBoundingRect_.left() == iter->startBoundingRect_.left() )
|
|
|
|
{
|
2009-11-15 03:24:04 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
iter->boundingRect_.setLeft( iter->startBoundingRect_.left() );
|
2009-11-15 03:24:04 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
} else {
|
2009-11-15 03:24:04 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
iter->boundingRect_.setLeft( (1.0-ratio)*iter->startBoundingRect_.left() + ratio*iter->endBoundingRect_.left() );
|
2009-11-15 03:24:04 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
}
|
2009-11-15 03:24:04 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
// right
|
|
|
|
if( iter->endBoundingRect_.right() == iter->startBoundingRect_.right() )
|
|
|
|
{
|
2009-11-15 03:24:04 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
iter->boundingRect_.setRight( iter->startBoundingRect_.right() );
|
2009-11-15 03:24:04 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
} else {
|
2009-11-15 03:24:04 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
iter->boundingRect_.setRight( (1.0-ratio)*iter->startBoundingRect_.right() + ratio*iter->endBoundingRect_.right() );
|
2009-11-15 03:24:04 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
}
|
2009-11-15 03:24:04 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
}
|
2009-11-15 03:24:04 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
// update button position
|
|
|
|
updateButtons( alsoUpdate );
|
2009-11-15 03:24:04 +00:00
|
|
|
|
2010-05-02 18:34:08 +00:00
|
|
|
}
|
2009-11-15 03:24:04 +00:00
|
|
|
}
|