From e273cfe15f98f3845ccacf04d638396d3b43e66e Mon Sep 17 00:00:00 2001 From: Pino Toscano Date: Fri, 19 Mar 2010 15:24:07 +0000 Subject: [PATCH] port SearchLineWidget to KPixmapSequence* and remove own AnimatedWidget svn path=/trunk/KDE/kdegraphics/okular/; revision=1105224 --- CMakeLists.txt | 1 - ui/animatedwidget.cpp | 103 ------------------------------------------ ui/animatedwidget.h | 45 ------------------ ui/searchlineedit.cpp | 26 +++++++++-- ui/searchlineedit.h | 7 +-- 5 files changed, 25 insertions(+), 157 deletions(-) delete mode 100644 ui/animatedwidget.cpp delete mode 100644 ui/animatedwidget.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 0503245e9..653732480 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -123,7 +123,6 @@ set(okularpart_SRCS conf/dlgperformance.cpp conf/dlgpresentation.cpp ui/embeddedfilesdialog.cpp - ui/animatedwidget.cpp ui/annotwindow.cpp ui/annotationmodel.cpp ui/annotationpopup.cpp diff --git a/ui/animatedwidget.cpp b/ui/animatedwidget.cpp deleted file mode 100644 index d014adea7..000000000 --- a/ui/animatedwidget.cpp +++ /dev/null @@ -1,103 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Pino Toscano * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - ***************************************************************************/ - -#include "animatedwidget.h" - -#include -#include - -#include - -AnimatedWidget::AnimatedWidget( const QString& iconName, QWidget *parent ) - : QWidget( parent ), m_icon( iconName ), m_frames( 0 ), m_currentFrame( 0 ), - m_size( 0 ) -{ - setAutoFillBackground( false ); - - hide(); -} - -AnimatedWidget::~AnimatedWidget() -{ -} - -void AnimatedWidget::start() -{ - if ( m_timer.isActive() ) - return; - - if ( !m_frames ) - { - load(); - if ( !m_frames ) - return; - } - - m_timer.start( 1000 / m_frames, this ); - show(); -} - -void AnimatedWidget::stop() -{ - m_timer.stop(); - m_currentFrame = 0; - hide(); -} - -void AnimatedWidget::paintEvent( QPaintEvent *event ) -{ - Q_UNUSED( event ); - - const int row_size = m_pixmap.width() / m_size; - const int row = m_currentFrame / row_size; - const int column = m_currentFrame % row_size; - - QPainter p( this ); - p.fillRect( rect(), Qt::transparent ); - p.drawPixmap( 0, 0, m_pixmap, column * m_size, row * m_size, m_size, m_size ); -} - -void AnimatedWidget::resizeEvent( QResizeEvent *event ) -{ - Q_UNUSED( event ); - - m_timer.stop(); - load(); -} - -void AnimatedWidget::timerEvent( QTimerEvent *event ) -{ - if ( event->timerId() == m_timer.timerId() ) - { - m_currentFrame++; - if ( m_currentFrame == m_frames ) - m_currentFrame = 0; - update(); - } - QWidget::timerEvent( event ); -} - -void AnimatedWidget::load() -{ - // FIXME implement a better logic for the animation size - m_size = 22; - const QString path = KIconLoader::global()->iconPath( m_icon, -m_size ); - QPixmap pix( path ); - if ( pix.isNull() ) - return; - - if ( ( pix.width() % m_size != 0 ) || ( pix.height() % m_size != 0 ) ) - return; - - m_frames = ( pix.height() / m_size ) * ( pix.width() / m_size ); - m_pixmap = pix; - m_currentFrame = 0; -} - -#include "animatedwidget.moc" diff --git a/ui/animatedwidget.h b/ui/animatedwidget.h deleted file mode 100644 index c8cca236c..000000000 --- a/ui/animatedwidget.h +++ /dev/null @@ -1,45 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Pino Toscano * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - ***************************************************************************/ - -#ifndef ANIMATEDWIDGET_H -#define ANIMATEDWIDGET_H - -#include -#include -#include - -class AnimatedWidget : public QWidget -{ - Q_OBJECT - - public: - AnimatedWidget( const QString& iconName, QWidget *parent = 0 ); - virtual ~AnimatedWidget(); - - public slots: - void start(); - void stop(); - - protected: - void paintEvent( QPaintEvent *event ); - void resizeEvent( QResizeEvent *event ); - void timerEvent( QTimerEvent *event ); - - private: - void load(); - - QString m_icon; - QPixmap m_pixmap; - int m_frames; - int m_currentFrame; - int m_size; - QBasicTimer m_timer; -}; - -#endif diff --git a/ui/searchlineedit.cpp b/ui/searchlineedit.cpp index 6d344b28e..4ad0acee7 100644 --- a/ui/searchlineedit.cpp +++ b/ui/searchlineedit.cpp @@ -1,6 +1,6 @@ /*************************************************************************** * Copyright (C) 2004 by Enrico Ros * - * Copyright (C) 2007 by Pino Toscano * + * Copyright (C) 2007, 2009-2010 by Pino Toscano * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * @@ -11,7 +11,6 @@ #include "searchlineedit.h" // local includes -#include "animatedwidget.h" #include "core/document.h" // qt/kde includes @@ -19,6 +18,8 @@ #include #include #include +#include +#include SearchLineEdit::SearchLineEdit( QWidget * parent, Okular::Document * document ) : KLineEdit( parent ), m_document( document ), m_minLength( 0 ), @@ -236,13 +237,14 @@ SearchLineWidget::SearchLineWidget( QWidget * parent, Okular::Document * documen m_edit = new SearchLineEdit( this, document ); layout->addWidget( m_edit ); - m_anim = new AnimatedWidget( "process-working", this ); + m_anim = new KPixmapSequenceWidget( this ); m_anim->setFixedSize( 22, 22 ); layout->addWidget( m_anim ); + m_anim->hide(); m_timer = new QTimer( this ); m_timer->setSingleShot( true ); - connect( m_timer, SIGNAL( timeout() ), m_anim, SLOT( start() ) ); + connect( m_timer, SIGNAL( timeout() ), this, SLOT( slotTimedout() ) ); connect( m_edit, SIGNAL( searchStarted() ), this, SLOT( slotSearchStarted() ) ); connect( m_edit, SIGNAL( searchStopped() ), this, SLOT( slotSearchStopped() ) ); @@ -261,7 +263,21 @@ void SearchLineWidget::slotSearchStarted() void SearchLineWidget::slotSearchStopped() { m_timer->stop(); - m_anim->stop(); + m_anim->hide(); +} + +void SearchLineWidget::slotTimedout() +{ + if ( m_anim->sequence().isEmpty() ) + { + const KPixmapSequence seq( "process-working", 22 ); + if ( seq.frameCount() > 0 ) + { + m_anim->setInterval( 1000 / seq.frameCount() ); + m_anim->setSequence( seq ); + } + } + m_anim->show(); } #include "searchlineedit.moc" diff --git a/ui/searchlineedit.h b/ui/searchlineedit.h index b23fe71e2..5108f5a65 100644 --- a/ui/searchlineedit.h +++ b/ui/searchlineedit.h @@ -1,6 +1,6 @@ /*************************************************************************** * Copyright (C) 2004 by Enrico Ros * - * Copyright (C) 2007 by Pino Toscano * + * Copyright (C) 2007, 2009-2010 by Pino Toscano * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * @@ -16,7 +16,7 @@ #include class QTimer; -class AnimatedWidget; +class KPixmapSequenceWidget; /** * @short A line edit for find-as-you-type search. Outputs to the Document. @@ -82,10 +82,11 @@ class SearchLineWidget : public QWidget private slots: void slotSearchStarted(); void slotSearchStopped(); + void slotTimedout(); private: SearchLineEdit *m_edit; - AnimatedWidget* m_anim; + KPixmapSequenceWidget* m_anim; QTimer *m_timer; };