From fe2be78491ab016a9ffb6f5d61d447c4bb88583e Mon Sep 17 00:00:00 2001 From: Robert Knight Date: Tue, 19 Jun 2007 19:48:58 +0000 Subject: [PATCH] Animated entry of color schemes in the list. svn path=/trunk/KDE/kdebase/apps/konsole/; revision=677729 --- src/EditProfileDialog.cpp | 43 ++++++++++++++++++++++++++++++++++++++- src/EditProfileDialog.h | 19 +++++++++++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) diff --git a/src/EditProfileDialog.cpp b/src/EditProfileDialog.cpp index 2b29956b4..1b49aacb4 100644 --- a/src/EditProfileDialog.cpp +++ b/src/EditProfileDialog.cpp @@ -31,6 +31,8 @@ #include #include +#include + // KDE #include #include @@ -314,7 +316,15 @@ void EditProfileDialog::setupAppearancePage(const Profile* info) // setup color list updateColorSchemeList(); - _ui->colorSchemeList->setItemDelegate(new ColorSchemeViewDelegate(this)); + ColorSchemeViewDelegate* delegate = new ColorSchemeViewDelegate(this); + + QTimeLine* timeLine = new QTimeLine( 1000 , this ); + delegate->setEntryTimeLine(timeLine); + + connect( timeLine , SIGNAL(valueChanged(qreal)) , this , + SLOT(colorSchemeAnimationUpdate()) ); + + _ui->colorSchemeList->setItemDelegate(delegate); _ui->colorSchemeList->setMouseTracking(true); _ui->colorSchemeList->installEventFilter(this); @@ -341,6 +351,16 @@ void EditProfileDialog::setupAppearancePage(const Profile* info) SLOT(setFontSize(int)) ); connect( _ui->editFontButton , SIGNAL(clicked()) , this , SLOT(showFontDialog()) ); + + // start entry animation + timeLine->start(); +} +void EditProfileDialog::colorSchemeAnimationUpdate() +{ + QAbstractItemModel* model = _ui->colorSchemeList->model(); + + for ( int i = model->rowCount() ; i >= 0 ; i-- ) + _ui->colorSchemeList->update( model->index(i,0) ); } void EditProfileDialog::updateFontPreviewLabel(const QFont& font) { @@ -926,9 +946,30 @@ QWidget* ColorSchemeViewDelegate::createEditor(QWidget* parent, const QStyleOpti } #endif +void ColorSchemeViewDelegate::setEntryTimeLine(QTimeLine* timeLine) +{ + _entryTimeLine = timeLine; +} + void ColorSchemeViewDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const { + // entry animation + // + // note that the translation occurs for each item drawn, but the + // painter is not reset between painting items. this means that when + // the items are painted in order ( as occurs when the list is first + // shown ), there is a visually pleasing staggering of items as they + // enter. + if ( _entryTimeLine != 0 ) + { + qreal value = 1.0-_entryTimeLine->currentValue(); + painter->translate( value * + option.rect.width() , 0 ); + + painter->setOpacity( _entryTimeLine->currentValue() ); + } + const ColorScheme* scheme = index.data(Qt::UserRole + 1).value(); Q_ASSERT(scheme); diff --git a/src/EditProfileDialog.h b/src/EditProfileDialog.h index dc937700d..133e30752 100644 --- a/src/EditProfileDialog.h +++ b/src/EditProfileDialog.h @@ -25,12 +25,14 @@ #include #include #include +#include // KDE #include class QAbstractButton; class QTextCodec; +class QTimeLine; namespace Ui { @@ -121,6 +123,8 @@ private slots: void fontSelected(const QFont&); //void previewFont(const QFont&); + void colorSchemeAnimationUpdate(); + // scrolling page void noScrollBack(); void fixedScrollBack(); @@ -204,6 +208,8 @@ private: */ class ColorSchemeViewDelegate : public QAbstractItemDelegate { +Q_OBJECT + public: ColorSchemeViewDelegate(QObject* parent = 0); @@ -213,6 +219,19 @@ public: virtual QSize sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index) const; + /** + * Sets the timeline used to control the entry animation + * for this delegate. + * + * During a call to paint(), the value of the timeLine is used to + * determine how to render the item ( with 0 being the beginning + * of the animation and 1.0 being the end ) + */ + void setEntryTimeLine( QTimeLine* timeLine ); + +private: + QPointer _entryTimeLine; + // virtual QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& option, // const QModelIndex& index) const; // virtual bool editorEvent(QEvent* event,QAbstractItemModel* model,