| # kio Library API Documentation
Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Source Files

# statusbarprogress.cpp

    00001 /* This file is part of the KDE libraries
    00002    Copyright (C) 2000 Matej Koss <koss@miesto.sk>
    00003
    00004    This library is free software; you can redistribute it and/or
    00005    modify it under the terms of the GNU Library General Public
    00006    License version 2 as published by the Free Software Foundation.
    00007
    00008    This library is distributed in the hope that it will be useful,
    00009    but WITHOUT ANY WARRANTY; without even the implied warranty of
    00010    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00011    Library General Public License for more details.
    00012
    00013    You should have received a copy of the GNU Library General Public License
    00014    along with this library; see the file COPYING.LIB.  If not, write to
    00015    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    00016    Boston, MA 02111-1307, USA.
    00017 */
    00018
    00019 #include <qtooltip.h>
    00020 #include <qlayout.h>
    00021 #include <qwidgetstack.h>
    00022
    00023 #include <kapplication.h>
    00024 #include <klocale.h>
    00025 #include <kdebug.h>
    00026
    00027 #include "jobclasses.h"
    00028 #include "statusbarprogress.h"
    00029
    00030 namespace KIO {
    00031
    00032 StatusbarProgress::StatusbarProgress( QWidget* parent, bool button )
    00033   : ProgressBase( parent ) {
    00034
    00035   m_bShowButton = button;
    00036
    00037   // only clean this dialog
    00038   setOnlyClean(true);
    00039   // TODO : is this really needed ?
    00040   setStopOnClose(false);
    00041
    00042   int w = fontMetrics().width( " 999.9 kB/s 00:00:01 " ) + 8;
    00043   box = new QHBoxLayout( this, 0, 0 );
    00044
    00045   m_pButton = new QPushButton( "X", this );
    00046   box->addWidget( m_pButton  );
    00047   stack = new QWidgetStack( this );
    00048   box->addWidget( stack );
    00049   connect( m_pButton, SIGNAL( clicked() ), this, SLOT( slotStop() ) );
    00050
    00051   m_pProgressBar = new KProgress( this );
    00052   m_pProgressBar->setFrameStyle( QFrame::Box | QFrame::Raised );
    00053   m_pProgressBar->setLineWidth( 1 );
    00054   m_pProgressBar->setBackgroundMode( QWidget::PaletteBackground );
    00055   m_pProgressBar->installEventFilter( this );
    00056   m_pProgressBar->setMinimumWidth( w );
    00057   stack->addWidget( m_pProgressBar, 1 );
    00058
    00059   m_pLabel = new QLabel( "", this );
    00060   m_pLabel->setAlignment( AlignHCenter | AlignVCenter );
    00061   m_pLabel->installEventFilter( this );
    00062   m_pLabel->setMinimumWidth( w );
    00063   stack->addWidget( m_pLabel, 2 );
    00064   setMinimumSize( sizeHint() );
    00065
    00066   mode = None;
    00067   setMode();
    00068 }
    00069
    00070
    00071 void StatusbarProgress::setJob( KIO::Job *job )
    00072 {
    00073   ProgressBase::setJob( job );
    00074
    00075   mode = Progress;
    00076   setMode();
    00077 }
    00078
    00079
    00080 void StatusbarProgress::setMode() {
    00081   switch ( mode ) {
    00082   case None:
    00083     if ( m_bShowButton ) {
    00084       m_pButton->hide();
    00085     }
    00086     stack->hide();
    00087     break;
    00088
    00089   case Label:
    00090     if ( m_bShowButton ) {
    00091       m_pButton->show();
    00092     }
    00093     stack->show();
    00094     stack->raiseWidget( m_pLabel );
    00095     break;
    00096
    00097   case Progress:
    00098     if ( m_bShowButton ) {
    00099       m_pButton->show();
    00100     }
    00101     stack->show();
    00102     stack->raiseWidget( m_pProgressBar );
    00103     break;
    00104   }
    00105 }
    00106
    00107
    00108 void StatusbarProgress::slotClean() {
    00109   // we don't want to delete this widget, only clean
    00110   m_pProgressBar->setValue( 0 );
    00111   m_pLabel->clear();
    00112
    00113   mode = None;
    00114   setMode();
    00115 }
    00116
    00117
    00118 void StatusbarProgress::slotTotalSize( KIO::Job*, KIO::filesize_t size ) {
    00119   m_iTotalSize = size;
    00120 }
    00121
    00122 void StatusbarProgress::slotPercent( KIO::Job*, unsigned long percent ) {
    00123   m_pProgressBar->setValue( percent );
    00124 }
    00125
    00126
    00127 void StatusbarProgress::slotSpeed( KIO::Job*, unsigned long bytes_per_second ) {
    00128   if ( bytes_per_second == 0 ) {
    00129     m_pLabel->setText( i18n( " Stalled ") );
    00130   } else {
    00131     m_pLabel->setText( i18n( " %1/s ").arg( KIO::convertSize( bytes_per_second )) );
    00132   }
    00133 }
    00134
    00135
    00136 bool StatusbarProgress::eventFilter( QObject *, QEvent *ev ) {
    00137   if ( ! m_pJob ) { // don't react when there isn't any job doing IO
    00138     return true;
    00139   }
    00140
    00141   if ( ev->type() == QEvent::MouseButtonPress ) {
    00142     QMouseEvent *e = (QMouseEvent*)ev;
    00143
    00144     if ( e->button() == LeftButton ) {    // toggle view on left mouse button
    00145       if ( mode == Label ) {
    00146         mode = Progress;
    00147       } else if ( mode == Progress ) {
    00148         mode = Label;
    00149       }
    00150       setMode();
    00151       return true;
    00152
    00153     }
    00154   }
    00155
    00156   return false;
    00157 }
    00158
    00159 void StatusbarProgress::virtual_hook( int id, void* data )
    00160 { ProgressBase::virtual_hook( id, data ); }
    00161
    00162 } /* namespace */
    00163 #include "statusbarprogress.moc"

This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Jan 28 13:14:40 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001