MuseScore/mstyle/dockseparatordata.h

171 lines
5.7 KiB
C
Raw Normal View History

2012-05-26 14:49:10 +02:00
#ifndef oxygendockseparatordata_h
#define oxygendockseparatordata_h
//////////////////////////////////////////////////////////////////////////////
// oxygendockseparatordata.h
// generic data container for widgetstate hover (mouse-over) animations
// -------------------
//
// Copyright (c) 2009 Hugo Pereira Da Costa <hugo@oxygen-icons.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 "genericdata.h"
#include "animation.h"
2013-02-15 22:47:54 +01:00
//! dock widget splitters hover effect
class DockSeparatorData: public AnimationData {
2012-05-26 14:49:10 +02:00
2013-02-15 22:47:54 +01:00
Q_OBJECT
2012-05-26 14:49:10 +02:00
2013-02-15 22:47:54 +01:00
//! declare opacity property
Q_PROPERTY( qreal verticalOpacity READ verticalOpacity WRITE setVerticalOpacity )
Q_PROPERTY( qreal horizontalOpacity READ horizontalOpacity WRITE setHorizontalOpacity )
2012-05-26 14:49:10 +02:00
2013-02-15 22:47:54 +01:00
public:
2012-05-26 14:49:10 +02:00
2013-02-15 22:47:54 +01:00
//! constructor
DockSeparatorData( QObject* parent, QWidget* target, int duration );
2012-05-26 14:49:10 +02:00
2013-02-15 22:47:54 +01:00
//! destructor
virtual ~DockSeparatorData( void )
{}
2012-05-26 14:49:10 +02:00
2013-02-15 22:47:54 +01:00
//@}
2012-05-26 14:49:10 +02:00
2013-02-15 22:47:54 +01:00
/*!
returns true if hover has Changed
and starts timer accordingly
*/
virtual void updateRect( const QRect&, const Qt::Orientation&, bool hovered );
2012-05-26 14:49:10 +02:00
2013-02-15 22:47:54 +01:00
//! returns true if current splitter is animated
virtual bool isAnimated( QRect r, const Qt::Orientation& orientation ) const {
return orientation == Qt::Vertical ? verticalData_.isAnimated( r ) : horizontalData_.isAnimated( r );
}
2012-05-26 14:49:10 +02:00
2013-02-15 22:47:54 +01:00
//! opacity for given orientation
qreal opacity( const Qt::Orientation& orientation ) const {
return orientation == Qt::Vertical ? verticalOpacity() : horizontalOpacity();
}
2012-05-26 14:49:10 +02:00
2013-02-15 22:47:54 +01:00
//! duration
virtual void setDuration( int duration ) {
horizontalAnimation().data()->setDuration( duration );
verticalAnimation().data()->setDuration( duration );
}
2012-05-26 14:49:10 +02:00
2013-02-15 22:47:54 +01:00
//!@name horizontal splitter data
//@{
2012-05-26 14:49:10 +02:00
2013-02-15 22:47:54 +01:00
Animation::Pointer horizontalAnimation( void ) const {
return horizontalData_.animation_;
}
2012-05-26 14:49:10 +02:00
2013-02-15 22:47:54 +01:00
const QRect& horizontalRect( void ) const {
return horizontalData_.rect_;
}
2012-05-26 14:49:10 +02:00
2013-02-15 22:47:54 +01:00
void setHorizontalRect( const QRect& r ) {
horizontalData_.rect_ = r;
}
2012-05-26 14:49:10 +02:00
2013-02-15 22:47:54 +01:00
qreal horizontalOpacity( void ) const {
return horizontalData_.opacity_;
}
2012-05-26 14:49:10 +02:00
2013-02-15 22:47:54 +01:00
void setHorizontalOpacity( qreal value ) {
2012-05-26 14:49:10 +02:00
2013-02-15 22:47:54 +01:00
if ( horizontalData_.opacity_ == value ) return;
2012-05-26 14:49:10 +02:00
2013-02-15 22:47:54 +01:00
horizontalData_.opacity_ = value;
if ( target() && !horizontalRect().isEmpty() ) target().data()->update( horizontalRect() );
2012-05-26 14:49:10 +02:00
2013-02-15 22:47:54 +01:00
}
2012-05-26 14:49:10 +02:00
2013-02-15 22:47:54 +01:00
//@}
2012-05-26 14:49:10 +02:00
2013-02-15 22:47:54 +01:00
//!@name vertical splitter data
//@{
2012-05-26 14:49:10 +02:00
2013-02-15 22:47:54 +01:00
Animation::Pointer verticalAnimation( void ) const {
return verticalData_.animation_;
}
2012-05-26 14:49:10 +02:00
2013-02-15 22:47:54 +01:00
const QRect& verticalRect( void ) const {
return verticalData_.rect_;
}
2012-05-26 14:49:10 +02:00
2013-02-15 22:47:54 +01:00
void setVerticalRect( const QRect& r ) {
verticalData_.rect_ = r;
}
2012-05-26 14:49:10 +02:00
2013-02-15 22:47:54 +01:00
qreal verticalOpacity( void ) const {
return verticalData_.opacity_;
}
2012-05-26 14:49:10 +02:00
2013-02-15 22:47:54 +01:00
void setVerticalOpacity( qreal value ) {
if ( verticalData_.opacity_ == value ) return;
verticalData_.opacity_ = value;
if ( target() && !verticalRect().isEmpty() ) target().data()->update( verticalRect() );
}
2012-05-26 14:49:10 +02:00
2013-02-15 22:47:54 +01:00
//@}
2012-05-26 14:49:10 +02:00
2013-02-15 22:47:54 +01:00
private:
2012-05-26 14:49:10 +02:00
2013-02-15 22:47:54 +01:00
//! stores data needed for animation
class Data {
2012-05-26 14:49:10 +02:00
2013-02-15 22:47:54 +01:00
public:
2012-05-26 14:49:10 +02:00
2013-02-15 22:47:54 +01:00
//! constructor
Data( void ):
opacity_( AnimationData::OpacityInvalid )
{}
2012-05-26 14:49:10 +02:00
2013-02-15 22:47:54 +01:00
//! true if is animated
bool isAnimated( QRect r ) const {
return r == rect_ && animation_.data()->isRunning();
}
2012-05-26 14:49:10 +02:00
2013-02-15 22:47:54 +01:00
//! animation pointer
Animation::Pointer animation_;
2012-05-26 14:49:10 +02:00
2013-02-15 22:47:54 +01:00
//! opacity variable
qreal opacity_;
2012-05-26 14:49:10 +02:00
2013-02-15 22:47:54 +01:00
//! stores active separator rect
QRect rect_;
2012-05-26 14:49:10 +02:00
2013-02-15 22:47:54 +01:00
};
2012-05-26 14:49:10 +02:00
2013-02-15 22:47:54 +01:00
//! horizontal
Data horizontalData_;
2012-05-26 14:49:10 +02:00
2013-02-15 22:47:54 +01:00
//! vertical
Data verticalData_;
2012-05-26 14:49:10 +02:00
2013-02-15 22:47:54 +01:00
};
2012-05-26 14:49:10 +02:00
#endif