mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-14 01:54:07 +02:00
* Added AnimatedWidget class for convenience.
* Optimizations in AnimatedSplitter (cancelling running animations). * Auto show / hide TransferView. * Remove completed items from TransferView.
This commit is contained in:
@@ -11,7 +11,7 @@ INCLUDE( ${QT_USE_FILE} )
|
|||||||
|
|
||||||
INCLUDE( ${CMAKE_MODULE_PATH}/AddAppIconMacro.cmake )
|
INCLUDE( ${CMAKE_MODULE_PATH}/AddAppIconMacro.cmake )
|
||||||
|
|
||||||
SET( CMAKE_BUILD_TYPE "debugfull" )
|
#SET( CMAKE_BUILD_TYPE "debugfull" )
|
||||||
SET( CMAKE_VERBOSE_MAKEFILE ON )
|
SET( CMAKE_VERBOSE_MAKEFILE ON )
|
||||||
SET( CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}" )
|
SET( CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}" )
|
||||||
SET( CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}" )
|
SET( CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}" )
|
||||||
|
@@ -17,9 +17,7 @@ DatabaseCommand_LoadPlaylistEntries::exec( DatabaseImpl* dbi )
|
|||||||
"FROM playlist_revision "
|
"FROM playlist_revision "
|
||||||
"WHERE guid = :guid");
|
"WHERE guid = :guid");
|
||||||
query_entries.bindValue( ":guid", m_guid );
|
query_entries.bindValue( ":guid", m_guid );
|
||||||
|
query_entries.exec();
|
||||||
bool aok = query_entries.exec();
|
|
||||||
Q_ASSERT( aok );
|
|
||||||
|
|
||||||
QStringList guids;
|
QStringList guids;
|
||||||
QMap< QString, plentry_ptr > entrymap;
|
QMap< QString, plentry_ptr > entrymap;
|
||||||
|
@@ -327,8 +327,7 @@ DatabaseImpl::searchTable( const QString& table, const QString& name_orig, uint
|
|||||||
// first check for exact matches:
|
// first check for exact matches:
|
||||||
query.prepare( QString( "SELECT id FROM %1 WHERE sortname = ?" ).arg( table ) );
|
query.prepare( QString( "SELECT id FROM %1 WHERE sortname = ?" ).arg( table ) );
|
||||||
query.addBindValue( name );
|
query.addBindValue( name );
|
||||||
bool exactok = query.exec();
|
query.exec();
|
||||||
Q_ASSERT( exactok );
|
|
||||||
|
|
||||||
while( query.next() )
|
while( query.next() )
|
||||||
results.append( query.value( 0 ).toInt() );
|
results.append( query.value( 0 ).toInt() );
|
||||||
|
@@ -66,6 +66,7 @@ DatabaseWorker::doWork( QSharedPointer<DatabaseCommand> cmd )
|
|||||||
{
|
{
|
||||||
bool transok = m_dbimpl->database().transaction();
|
bool transok = m_dbimpl->database().transaction();
|
||||||
Q_ASSERT( transok );
|
Q_ASSERT( transok );
|
||||||
|
Q_UNUSED( transok );
|
||||||
}
|
}
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@@ -101,14 +101,14 @@ void
|
|||||||
Connection::shutdown( bool waitUntilSentAll )
|
Connection::shutdown( bool waitUntilSentAll )
|
||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO << waitUntilSentAll;
|
qDebug() << Q_FUNC_INFO << waitUntilSentAll;
|
||||||
if(m_do_shutdown)
|
if ( m_do_shutdown )
|
||||||
{
|
{
|
||||||
//qDebug() << id() << " already shutting down";
|
//qDebug() << id() << " already shutting down";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_do_shutdown = true;
|
m_do_shutdown = true;
|
||||||
if( !waitUntilSentAll )
|
if ( !waitUntilSentAll )
|
||||||
{
|
{
|
||||||
qDebug() << "Shutting down immediately " << id();
|
qDebug() << "Shutting down immediately " << id();
|
||||||
actualShutdown();
|
actualShutdown();
|
||||||
@@ -255,12 +255,12 @@ Connection::socketDisconnected()
|
|||||||
<< "bytesRecvd" << bytesReceived();
|
<< "bytesRecvd" << bytesReceived();
|
||||||
|
|
||||||
m_peer_disconnected = true;
|
m_peer_disconnected = true;
|
||||||
|
|
||||||
emit socketClosed();
|
emit socketClosed();
|
||||||
|
|
||||||
if( m_msgprocessor_in.length() == 0 && m_sock->bytesAvailable() == 0 )
|
if( m_msgprocessor_in.length() == 0 && m_sock->bytesAvailable() == 0 )
|
||||||
{
|
{
|
||||||
handleIncomingQueueEmpty();
|
handleIncomingQueueEmpty();
|
||||||
|
actualShutdown();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -433,7 +433,7 @@ Connection::bytesWritten( qint64 i )
|
|||||||
{
|
{
|
||||||
m_tx_bytes += i;
|
m_tx_bytes += i;
|
||||||
// if we are waiting to shutdown, and have sent all queued data, do actual shutdown:
|
// if we are waiting to shutdown, and have sent all queued data, do actual shutdown:
|
||||||
if( m_do_shutdown && m_tx_bytes == m_tx_bytes_requested )
|
if ( m_do_shutdown && m_tx_bytes == m_tx_bytes_requested )
|
||||||
actualShutdown();
|
actualShutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -602,8 +602,7 @@ Servent::onFileTransferFinished( FileTransferConnection* ftc )
|
|||||||
qDebug() << "FileTransfer Finished, unregistering" << ftc->id();
|
qDebug() << "FileTransfer Finished, unregistering" << ftc->id();
|
||||||
|
|
||||||
QMutexLocker lock( &m_ftsession_mut );
|
QMutexLocker lock( &m_ftsession_mut );
|
||||||
int rem = m_ftsessions.removeAll( ftc );
|
m_ftsessions.removeAll( ftc );
|
||||||
Q_ASSERT( rem == 1 );
|
|
||||||
|
|
||||||
printCurrentTransfers();
|
printCurrentTransfers();
|
||||||
emit fileTransferFinished( ftc );
|
emit fileTransferFinished( ftc );
|
||||||
|
@@ -30,20 +30,19 @@ PlaylistManager::PlaylistManager( QObject* parent )
|
|||||||
{
|
{
|
||||||
m_stack = new QStackedWidget();
|
m_stack = new QStackedWidget();
|
||||||
|
|
||||||
m_queueView = new QueueView();
|
|
||||||
m_queueModel = new PlaylistModel( m_queueView );
|
|
||||||
m_queueView->queue()->setModel( m_queueModel );
|
|
||||||
APP->audioEngine()->setQueue( m_queueView->queue()->proxyModel() );
|
|
||||||
|
|
||||||
m_widget->setLayout( new QVBoxLayout() );
|
m_widget->setLayout( new QVBoxLayout() );
|
||||||
|
|
||||||
m_splitter = new AnimatedSplitter();
|
m_splitter = new AnimatedSplitter();
|
||||||
m_splitter->setOrientation( Qt::Vertical );
|
m_splitter->setOrientation( Qt::Vertical );
|
||||||
m_splitter->setChildrenCollapsible( false );
|
m_splitter->setChildrenCollapsible( false );
|
||||||
m_splitter->setGreedyWidget( 0 );
|
m_splitter->setGreedyWidget( 0 );
|
||||||
|
|
||||||
m_splitter->addWidget( m_stack );
|
m_splitter->addWidget( m_stack );
|
||||||
m_splitter->addWidget( m_queueView );
|
|
||||||
|
m_queueView = new QueueView( m_splitter );
|
||||||
|
m_queueModel = new PlaylistModel( m_queueView );
|
||||||
|
m_queueView->queue()->setModel( m_queueModel );
|
||||||
|
APP->audioEngine()->setQueue( m_queueView->queue()->proxyModel() );
|
||||||
|
|
||||||
m_splitter->hide( 1, false );
|
m_splitter->hide( 1, false );
|
||||||
|
|
||||||
m_widget->layout()->setMargin( 0 );
|
m_widget->layout()->setMargin( 0 );
|
||||||
|
@@ -5,12 +5,19 @@
|
|||||||
|
|
||||||
#include "playlist/queueproxymodel.h"
|
#include "playlist/queueproxymodel.h"
|
||||||
|
|
||||||
|
#ifdef Q_WS_MAC
|
||||||
|
#define MINIMUM_HEIGHT 38
|
||||||
|
#else
|
||||||
|
#define MINIMUM_HEIGHT 27
|
||||||
|
#endif
|
||||||
|
|
||||||
using namespace Tomahawk;
|
using namespace Tomahawk;
|
||||||
|
|
||||||
|
|
||||||
QueueView::QueueView( QWidget* parent )
|
QueueView::QueueView( AnimatedSplitter* parent )
|
||||||
: QWidget( parent )
|
: AnimatedWidget( parent )
|
||||||
{
|
{
|
||||||
|
setHiddenSize( QSize( 0, MINIMUM_HEIGHT ) );
|
||||||
setLayout( new QVBoxLayout() );
|
setLayout( new QVBoxLayout() );
|
||||||
|
|
||||||
m_queue = new PlaylistView( this );
|
m_queue = new PlaylistView( this );
|
||||||
|
@@ -3,14 +3,15 @@
|
|||||||
|
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
|
|
||||||
|
#include "utils/animatedsplitter.h"
|
||||||
#include "playlistview.h"
|
#include "playlistview.h"
|
||||||
|
|
||||||
class QueueView : public QWidget
|
class QueueView : public AnimatedWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit QueueView( QWidget* parent = 0 );
|
explicit QueueView( AnimatedSplitter* parent );
|
||||||
~QueueView();
|
~QueueView();
|
||||||
|
|
||||||
PlaylistView* queue() const { return m_queue; }
|
PlaylistView* queue() const { return m_queue; }
|
||||||
@@ -18,12 +19,8 @@ public:
|
|||||||
QSize sizeHint() const { return QSize( 0, 200 ); }
|
QSize sizeHint() const { return QSize( 0, 200 ); }
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void onShown( QWidget* );
|
virtual void onShown( QWidget* );
|
||||||
void onHidden( QWidget* );
|
virtual void onHidden( QWidget* );
|
||||||
|
|
||||||
signals:
|
|
||||||
void showWidget();
|
|
||||||
void hideWidget();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
PlaylistView* m_queue;
|
PlaylistView* m_queue;
|
||||||
|
@@ -65,8 +65,11 @@ TomahawkWindow::TomahawkWindow( QWidget* parent )
|
|||||||
ui->splitter->setStretchFactor( 0, 1 );
|
ui->splitter->setStretchFactor( 0, 1 );
|
||||||
ui->splitter->setStretchFactor( 1, 3 );
|
ui->splitter->setStretchFactor( 1, 3 );
|
||||||
|
|
||||||
ui->splitter_2->setStretchFactor( 0, 3 );
|
ui->sidebarSplitter->setChildrenCollapsible( false );
|
||||||
ui->splitter_2->setStretchFactor( 1, 1 );
|
ui->sidebarSplitter->setGreedyWidget( 0 );
|
||||||
|
ui->sidebarSplitter->setStretchFactor( 0, 3 );
|
||||||
|
ui->sidebarSplitter->setStretchFactor( 1, 1 );
|
||||||
|
ui->sidebarSplitter->hide( 1, false );
|
||||||
|
|
||||||
QToolBar* toolbar = addToolBar( "TomahawkToolbar" );
|
QToolBar* toolbar = addToolBar( "TomahawkToolbar" );
|
||||||
toolbar->setObjectName( "TomahawkToolbar" );
|
toolbar->setObjectName( "TomahawkToolbar" );
|
||||||
|
@@ -20,7 +20,7 @@
|
|||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Horizontal</enum>
|
<enum>Qt::Horizontal</enum>
|
||||||
</property>
|
</property>
|
||||||
<widget class="AnimatedSplitter" name="splitter_2">
|
<widget class="AnimatedSplitter" name="sidebarSplitter">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Vertical</enum>
|
<enum>Qt::Vertical</enum>
|
||||||
</property>
|
</property>
|
||||||
|
@@ -1,29 +1,40 @@
|
|||||||
#include "transferview.h"
|
#include "transferview.h"
|
||||||
|
|
||||||
#include <QHeaderView>
|
#include <QHeaderView>
|
||||||
|
#include <QVBoxLayout>
|
||||||
|
|
||||||
#include "tomahawk/tomahawkapp.h"
|
#include "tomahawk/tomahawkapp.h"
|
||||||
#include "network/filetransferconnection.h"
|
#include "network/filetransferconnection.h"
|
||||||
#include "network/servent.h"
|
#include "network/servent.h"
|
||||||
|
|
||||||
|
|
||||||
TransferView::TransferView( QWidget* parent )
|
TransferView::TransferView( AnimatedSplitter* parent )
|
||||||
: QTreeWidget( parent )
|
: AnimatedWidget( parent )
|
||||||
|
, m_parent( parent )
|
||||||
{
|
{
|
||||||
|
setHiddenSize( QSize( 0, 0 ) );
|
||||||
|
|
||||||
|
setLayout( new QVBoxLayout() );
|
||||||
|
m_tree = new QTreeWidget( this );
|
||||||
|
|
||||||
|
layout()->setMargin( 0 );
|
||||||
|
layout()->addWidget( m_tree );
|
||||||
|
|
||||||
connect( &APP->servent(), SIGNAL( fileTransferStarted( FileTransferConnection* ) ), SLOT( fileTransferRegistered( FileTransferConnection* ) ) );
|
connect( &APP->servent(), SIGNAL( fileTransferStarted( FileTransferConnection* ) ), SLOT( fileTransferRegistered( FileTransferConnection* ) ) );
|
||||||
connect( &APP->servent(), SIGNAL( fileTransferFinished( FileTransferConnection* ) ), SLOT( fileTransferFinished( FileTransferConnection* ) ) );
|
connect( &APP->servent(), SIGNAL( fileTransferFinished( FileTransferConnection* ) ), SLOT( fileTransferFinished( FileTransferConnection* ) ) );
|
||||||
|
|
||||||
QStringList headers;
|
QStringList headers;
|
||||||
headers << tr( "Peer" ) << tr( "Rate" ) << tr( "Track" );
|
headers << tr( "Peer" ) << tr( "Rate" ) << tr( "Track" );
|
||||||
setHeaderLabels( headers );
|
m_tree->setHeaderLabels( headers );
|
||||||
|
|
||||||
setColumnCount( 3 );
|
m_tree->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Ignored );
|
||||||
setColumnWidth( 0, 80 );
|
m_tree->setColumnCount( 3 );
|
||||||
setColumnWidth( 1, 65 );
|
m_tree->setColumnWidth( 0, 80 );
|
||||||
setColumnWidth( 2, 10 );
|
m_tree->setColumnWidth( 1, 65 );
|
||||||
|
m_tree->setColumnWidth( 2, 10 );
|
||||||
|
|
||||||
header()->setStretchLastSection( true );
|
m_tree->header()->setStretchLastSection( true );
|
||||||
setRootIsDecorated( false );
|
m_tree->setRootIsDecorated( false );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -40,14 +51,19 @@ TransferView::fileTransferFinished( FileTransferConnection* ftc )
|
|||||||
if ( !m_index.contains( ftc ) )
|
if ( !m_index.contains( ftc ) )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* int i = m_index.take( ftc );
|
int i = m_index.take( ftc );
|
||||||
delete invisibleRootItem()->takeChild( i ); */
|
delete m_tree->invisibleRootItem()->takeChild( i );
|
||||||
|
|
||||||
if ( m_index.contains( ftc ) )
|
if ( m_tree->invisibleRootItem()->childCount() > 0 )
|
||||||
|
emit showWidget();
|
||||||
|
else
|
||||||
|
emit hideWidget();
|
||||||
|
|
||||||
|
/* if ( m_index.contains( ftc ) )
|
||||||
{
|
{
|
||||||
int i = m_index.value( ftc );
|
int i = m_index.value( ftc );
|
||||||
invisibleRootItem()->child( i )->setText( 1, tr( "Finished" ) );
|
m_tree->invisibleRootItem()->child( i )->setText( 1, tr( "Finished" ) );
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -63,15 +79,34 @@ TransferView::onTransferUpdate()
|
|||||||
if ( m_index.contains( ftc ) )
|
if ( m_index.contains( ftc ) )
|
||||||
{
|
{
|
||||||
int i = m_index.value( ftc );
|
int i = m_index.value( ftc );
|
||||||
ti = invisibleRootItem()->child( i );
|
ti = m_tree->invisibleRootItem()->child( i );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ti = new QTreeWidgetItem( this );
|
ti = new QTreeWidgetItem( m_tree );
|
||||||
m_index.insert( ftc, invisibleRootItem()->childCount() - 1 );
|
m_index.insert( ftc, m_tree->invisibleRootItem()->childCount() - 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
ti->setText( 0, ftc->source()->friendlyName() );
|
ti->setText( 0, ftc->source()->friendlyName() );
|
||||||
ti->setText( 1, QString( "%1 kb/s" ).arg( ftc->transferRate() / 1024 ) );
|
ti->setText( 1, QString( "%1 kb/s" ).arg( ftc->transferRate() / 1024 ) );
|
||||||
ti->setText( 2, QString( "%1 - %2" ).arg( ftc->track()->artist()->name() ).arg( ftc->track()->track() ) );
|
ti->setText( 2, QString( "%1 - %2" ).arg( ftc->track()->artist()->name() ).arg( ftc->track()->track() ) );
|
||||||
|
|
||||||
|
emit showWidget();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QSize
|
||||||
|
TransferView::sizeHint() const
|
||||||
|
{
|
||||||
|
unsigned int y = 0;
|
||||||
|
y += m_tree->header()->height();
|
||||||
|
y += m_tree->contentsMargins().top() + m_tree->contentsMargins().bottom();
|
||||||
|
|
||||||
|
if ( m_tree->invisibleRootItem()->childCount() )
|
||||||
|
{
|
||||||
|
unsigned int rowheight = m_tree->sizeHintForRow( 0 );
|
||||||
|
y += rowheight * m_tree->invisibleRootItem()->childCount() + 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
return QSize( 0, y );
|
||||||
}
|
}
|
||||||
|
@@ -5,20 +5,23 @@
|
|||||||
#include <QTreeWidget>
|
#include <QTreeWidget>
|
||||||
|
|
||||||
#include "tomahawk/typedefs.h"
|
#include "tomahawk/typedefs.h"
|
||||||
|
#include "utils/animatedsplitter.h"
|
||||||
|
|
||||||
class FileTransferConnection;
|
class FileTransferConnection;
|
||||||
|
|
||||||
class TransferView : public QTreeWidget
|
class TransferView : public AnimatedWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit TransferView( QWidget* parent = 0 );
|
explicit TransferView( AnimatedSplitter* parent = 0 );
|
||||||
virtual ~TransferView()
|
virtual ~TransferView()
|
||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO;
|
qDebug() << Q_FUNC_INFO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QSize sizeHint() const;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
@@ -31,6 +34,8 @@ private slots:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
QHash< FileTransferConnection*, int > m_index;
|
QHash< FileTransferConnection*, int > m_index;
|
||||||
|
QTreeWidget* m_tree;
|
||||||
|
AnimatedSplitter* m_parent;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // TRANSFERVIEW_H
|
#endif // TRANSFERVIEW_H
|
||||||
|
@@ -1,51 +1,46 @@
|
|||||||
#include "animatedsplitter.h"
|
#include "animatedsplitter.h"
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QTimeLine>
|
|
||||||
|
|
||||||
#define ANIMATION_TIME 500
|
#define ANIMATION_TIME 500
|
||||||
|
|
||||||
#ifdef Q_WS_MAC
|
|
||||||
#define MINIMUM_HEIGHT 38
|
|
||||||
#else
|
|
||||||
#define MINIMUM_HEIGHT 27
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
AnimatedSplitter::AnimatedSplitter( QWidget* parent )
|
AnimatedSplitter::AnimatedSplitter( QWidget* parent )
|
||||||
: QSplitter( parent )
|
: QSplitter( parent )
|
||||||
, m_animateIndex( -1 )
|
, m_animateIndex( -1 )
|
||||||
, m_greedyIndex( -1 )
|
, m_greedyIndex( 0 )
|
||||||
, m_greedyHeight( -1 )
|
|
||||||
{
|
{
|
||||||
|
m_timeLine = new QTimeLine( ANIMATION_TIME, this );
|
||||||
|
m_timeLine->setUpdateInterval( 5 );
|
||||||
|
m_timeLine->setEasingCurve( QEasingCurve::OutBack );
|
||||||
|
|
||||||
|
connect( m_timeLine, SIGNAL( frameChanged( int ) ), SLOT( onAnimationStep( int ) ) );
|
||||||
|
connect( m_timeLine, SIGNAL( finished() ), SLOT( onAnimationFinished() ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
AnimatedSplitter::show( int index, bool animate )
|
AnimatedSplitter::show( int index, bool animate )
|
||||||
{
|
{
|
||||||
if ( m_greedyIndex < 0 || m_animateIndex != -1 )
|
|
||||||
return;
|
|
||||||
|
|
||||||
m_animateIndex = index;
|
m_animateIndex = index;
|
||||||
|
|
||||||
QWidget* w = widget( index );
|
QWidget* w = widget( index );
|
||||||
QSize size = w->sizeHint();
|
QSize size = w->sizeHint();
|
||||||
w->setMaximumHeight( QWIDGETSIZE_MAX );
|
w->setMaximumHeight( QWIDGETSIZE_MAX );
|
||||||
|
|
||||||
|
if ( w->height() == size.height() )
|
||||||
|
return;
|
||||||
|
qDebug() << "animating to:" << size.height() << "from" << w->height();
|
||||||
|
|
||||||
m_animateForward = true;
|
m_animateForward = true;
|
||||||
if ( animate )
|
if ( animate )
|
||||||
{
|
{
|
||||||
m_greedyHeight = widget( m_greedyIndex )->height();
|
if ( m_timeLine->state() == QTimeLine::Running )
|
||||||
|
m_timeLine->stop();
|
||||||
|
|
||||||
QTimeLine *timeLine = new QTimeLine( ANIMATION_TIME, this );
|
m_timeLine->setFrameRange( w->height(), size.height() );
|
||||||
timeLine->setFrameRange( w->height(), size.height() );
|
m_timeLine->setDirection( QTimeLine::Forward );
|
||||||
timeLine->setUpdateInterval( 5 );
|
m_timeLine->start();
|
||||||
timeLine->setEasingCurve( QEasingCurve::OutBack );
|
|
||||||
|
|
||||||
connect( timeLine, SIGNAL( frameChanged( int ) ), SLOT( onAnimationStep( int ) ) );
|
|
||||||
connect( timeLine, SIGNAL( finished() ), SLOT( onAnimationFinished() ) );
|
|
||||||
timeLine->start();
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -60,32 +55,29 @@ AnimatedSplitter::show( int index, bool animate )
|
|||||||
void
|
void
|
||||||
AnimatedSplitter::hide( int index, bool animate )
|
AnimatedSplitter::hide( int index, bool animate )
|
||||||
{
|
{
|
||||||
if ( m_greedyIndex < 0 || m_animateIndex != -1 )
|
|
||||||
return;
|
|
||||||
|
|
||||||
m_animateIndex = index;
|
m_animateIndex = index;
|
||||||
|
|
||||||
QWidget* w = widget( index );
|
QWidget* w = widget( index );
|
||||||
w->setMinimumHeight( MINIMUM_HEIGHT );
|
int minHeight = m_sizes.at( index ).height();
|
||||||
m_greedyHeight = widget( m_greedyIndex )->height();
|
w->setMinimumHeight( minHeight );
|
||||||
|
|
||||||
|
if ( w->height() == minHeight )
|
||||||
|
return;
|
||||||
|
qDebug() << "animating to:" << w->height() << "from" << minHeight;
|
||||||
|
|
||||||
m_animateForward = false;
|
m_animateForward = false;
|
||||||
if ( animate )
|
if ( animate )
|
||||||
{
|
{
|
||||||
|
if ( m_timeLine->state() == QTimeLine::Running )
|
||||||
|
m_timeLine->stop();
|
||||||
|
|
||||||
QTimeLine *timeLine = new QTimeLine( ANIMATION_TIME, this );
|
m_timeLine->setFrameRange( minHeight, w->height() );
|
||||||
timeLine->setFrameRange( MINIMUM_HEIGHT, w->height() );
|
m_timeLine->setDirection( QTimeLine::Backward );
|
||||||
timeLine->setUpdateInterval( 5 );
|
m_timeLine->start();
|
||||||
timeLine->setDirection( QTimeLine::Backward );
|
|
||||||
timeLine->setEasingCurve( QEasingCurve::OutBack );
|
|
||||||
|
|
||||||
connect( timeLine, SIGNAL( frameChanged( int ) ), SLOT( onAnimationStep( int ) ) );
|
|
||||||
connect( timeLine, SIGNAL( finished() ), SLOT( onAnimationFinished() ) );
|
|
||||||
timeLine->start();
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
onAnimationStep( MINIMUM_HEIGHT );
|
onAnimationStep( minHeight );
|
||||||
onAnimationFinished();
|
onAnimationFinished();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,9 +89,19 @@ void
|
|||||||
AnimatedSplitter::addWidget( QWidget* widget )
|
AnimatedSplitter::addWidget( QWidget* widget )
|
||||||
{
|
{
|
||||||
QSplitter::addWidget( widget );
|
QSplitter::addWidget( widget );
|
||||||
|
m_sizes << widget->minimumSize();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
AnimatedSplitter::addWidget( AnimatedWidget* widget )
|
||||||
|
{
|
||||||
|
QSplitter::addWidget( widget );
|
||||||
|
m_sizes << widget->hiddenSize();
|
||||||
|
|
||||||
connect( widget, SIGNAL( showWidget() ), SLOT( onShowRequest() ) );
|
connect( widget, SIGNAL( showWidget() ), SLOT( onShowRequest() ) );
|
||||||
connect( widget, SIGNAL( hideWidget() ), SLOT( onHideRequest() ) );
|
connect( widget, SIGNAL( hideWidget() ), SLOT( onHideRequest() ) );
|
||||||
|
connect( widget, SIGNAL( hiddenSizeChanged() ), SLOT( onHiddenSizeChanged() ) );
|
||||||
connect( this, SIGNAL( shown( QWidget* ) ), widget, SLOT( onShown( QWidget* ) ) );
|
connect( this, SIGNAL( shown( QWidget* ) ), widget, SLOT( onShown( QWidget* ) ) );
|
||||||
connect( this, SIGNAL( hidden( QWidget* ) ), widget, SLOT( onHidden( QWidget* ) ) );
|
connect( this, SIGNAL( hidden( QWidget* ) ), widget, SLOT( onHidden( QWidget* ) ) );
|
||||||
}
|
}
|
||||||
@@ -122,6 +124,8 @@ AnimatedSplitter::onShowRequest()
|
|||||||
|
|
||||||
if ( j > 0 )
|
if ( j > 0 )
|
||||||
show( j );
|
show( j );
|
||||||
|
else
|
||||||
|
qDebug() << "Could not find widget:" << sender();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -142,6 +146,8 @@ AnimatedSplitter::onHideRequest()
|
|||||||
|
|
||||||
if ( j > 0 )
|
if ( j > 0 )
|
||||||
hide( j );
|
hide( j );
|
||||||
|
else
|
||||||
|
qDebug() << "Could not find widget:" << sender();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -182,15 +188,28 @@ AnimatedSplitter::onAnimationFinished()
|
|||||||
QWidget* w = widget( m_animateIndex );
|
QWidget* w = widget( m_animateIndex );
|
||||||
if ( m_animateForward )
|
if ( m_animateForward )
|
||||||
{
|
{
|
||||||
w->setMinimumHeight( 100 );
|
w->setMinimumHeight( w->minimumHeight() );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
w->setMaximumHeight( MINIMUM_HEIGHT );
|
w->setMaximumHeight( m_sizes.at( m_animateIndex ).height() );
|
||||||
}
|
}
|
||||||
|
|
||||||
m_animateIndex = -1;
|
m_animateIndex = -1;
|
||||||
|
}
|
||||||
if ( sender() )
|
|
||||||
sender()->deleteLater();
|
|
||||||
|
void
|
||||||
|
AnimatedSplitter::onHiddenSizeChanged()
|
||||||
|
{
|
||||||
|
AnimatedWidget* w = (AnimatedWidget*)(sender());
|
||||||
|
int i = indexOf( w );
|
||||||
|
m_sizes.replace( i, w->hiddenSize() );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
AnimatedWidget::AnimatedWidget( AnimatedSplitter* parent )
|
||||||
|
: m_parent( parent )
|
||||||
|
{
|
||||||
|
m_parent->addWidget( this );
|
||||||
}
|
}
|
||||||
|
@@ -2,6 +2,9 @@
|
|||||||
#define ANIMATEDSPLITTER_H
|
#define ANIMATEDSPLITTER_H
|
||||||
|
|
||||||
#include <QSplitter>
|
#include <QSplitter>
|
||||||
|
#include <QTimeLine>
|
||||||
|
|
||||||
|
class AnimatedWidget;
|
||||||
|
|
||||||
class AnimatedSplitter : public QSplitter
|
class AnimatedSplitter : public QSplitter
|
||||||
{
|
{
|
||||||
@@ -16,6 +19,7 @@ public:
|
|||||||
void setGreedyWidget( int index ) { m_greedyIndex = index; }
|
void setGreedyWidget( int index ) { m_greedyIndex = index; }
|
||||||
|
|
||||||
void addWidget( QWidget* widget );
|
void addWidget( QWidget* widget );
|
||||||
|
void addWidget( AnimatedWidget* widget );
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void shown( QWidget* );
|
void shown( QWidget* );
|
||||||
@@ -28,12 +32,39 @@ private slots:
|
|||||||
void onAnimationStep( int frame );
|
void onAnimationStep( int frame );
|
||||||
void onAnimationFinished();
|
void onAnimationFinished();
|
||||||
|
|
||||||
|
void onHiddenSizeChanged();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int m_animateIndex;
|
int m_animateIndex;
|
||||||
bool m_animateForward;
|
bool m_animateForward;
|
||||||
|
|
||||||
int m_greedyIndex;
|
int m_greedyIndex;
|
||||||
int m_greedyHeight;
|
QList<QSize> m_sizes;
|
||||||
|
QTimeLine* m_timeLine;
|
||||||
|
};
|
||||||
|
|
||||||
|
class AnimatedWidget : public QWidget
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit AnimatedWidget( AnimatedSplitter* parent );
|
||||||
|
|
||||||
|
QSize hiddenSize() const { return m_hiddenSize; }
|
||||||
|
void setHiddenSize( const QSize& size ) { m_hiddenSize = size; emit hiddenSizeChanged(); }
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
virtual void onShown( QWidget* ) {}
|
||||||
|
virtual void onHidden( QWidget* ) {}
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void showWidget();
|
||||||
|
void hideWidget();
|
||||||
|
|
||||||
|
void hiddenSizeChanged();
|
||||||
|
|
||||||
|
private:
|
||||||
|
AnimatedSplitter* m_parent;
|
||||||
|
QSize m_hiddenSize;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //ANIMATEDSPLITTER_H
|
#endif //ANIMATEDSPLITTER_H
|
||||||
|
Reference in New Issue
Block a user