batchprogressdialog.cpp

Go to the documentation of this file.
00001 
00002 //
00003 //    BATCHPROGRESSDIALOG.CPP
00004 //
00005 //    Copyright (C) 2004 Gilles Caulier <caulier dot gilles at free.fr>
00006 //
00007 //    This program is free software; you can redistribute it and/or modify
00008 //    it under the terms of the GNU Library General Public License as published by
00009 //    the Free Software Foundation; either version 2 of the License, or
00010 //    (at your option) any later version.
00011 //
00012 //    This program is distributed in the hope that it will be useful,
00013 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 //    GNU Library General Public License for more details.
00016 //
00017 //    You should have received a copy of the GNU Library General Public License
00018 //    along with this program; if not, write to the Free Software
00019 //    Foundation, Inc., 51 Franklin Steet, Fifth Floor, Boston, MA 02110-1301, USA.
00020 //
00022 
00023 
00024 // Include files for Qt
00025 
00026 #include <qvbox.h>
00027 #include <qlayout.h>
00028 #include <qdir.h>
00029 #include <qwidget.h>
00030 #include <qgroupbox.h>
00031 #include <qwhatsthis.h>
00032 #include <qcolor.h>
00033 #include <qhgroupbox.h>
00034 #include <qvgroupbox.h>
00035 #include <qheader.h>
00036 #include <qlistview.h>
00037 #include <qframe.h>
00038 #include <qlabel.h>
00039 #include <qcolor.h>
00040 #include <qpixmap.h>
00041 #include <qpushbutton.h>
00042 
00043 // Include files for KDE
00044 
00045 #include <klocale.h>
00046 #include <kprogress.h>
00047 #include <kinstance.h>
00048 #include <kconfig.h>
00049 #include <kapplication.h>
00050 #include <kdebug.h>
00051 #include <kdialogbase.h>
00052 #include <kiconloader.h>
00053 #include <klistview.h>
00054 #include <kstandarddirs.h>
00055 #include <kapplication.h>
00056 #include <kaboutdata.h>
00057 #include <khelpmenu.h>
00058 #include <kiconloader.h>
00059 #include <kpopupmenu.h>
00060 
00061 // Include files for libKipi.
00062 
00063 #include "libkipi/version.h"
00064 
00065 // Local includes
00066 
00067 #include "batchprogressdialog.h"
00068 
00069 namespace KIPI
00070 {
00071 
00072 class BatchProgressItem : public KListViewItem
00073 {
00074 public:
00075    BatchProgressItem(KListView * parent, QListViewItem *after, const QString &message, int messageType)
00076                    : KListViewItem( parent, after), m_messagetype(messageType)
00077    {
00078    // Set the icon.
00079 
00080    switch( m_messagetype )
00081      {
00082      case KIPI::StartingMessage:
00083         setPixmap( 0, SmallIcon( "run" ) );
00084         break;
00085      case KIPI::SuccessMessage:
00086         setPixmap( 0, SmallIcon( "ok" ) );
00087         break;
00088      case KIPI::WarningMessage:
00089         setPixmap( 0, SmallIcon( "flag" ) );
00090         break;
00091      case KIPI::ErrorMessage:
00092         setPixmap( 0, SmallIcon( "stop" ) );
00093         break;
00094      case KIPI::ProgressMessage:
00095         setPixmap( 0, SmallIcon( "info" ) );
00096         break;
00097      default:
00098         setPixmap( 0, SmallIcon( "info" ) );
00099      }
00100 
00101    // Set the message text.
00102 
00103    setText(1, message);
00104    }
00105 
00106 private:
00107    int m_messagetype;
00108 
00109    void paintCell (QPainter *p, const QColorGroup &cg, int column, int width, int alignment)
00110       {
00111       QColorGroup _cg( cg );
00112 
00113       if ( m_messagetype == KIPI::ErrorMessage )
00114           {
00115           _cg.setColor( QColorGroup::Text, Qt::red );
00116           KListViewItem::paintCell( p, _cg, column, width, alignment );
00117           return;
00118           }
00119 
00120       if ( m_messagetype == KIPI::WarningMessage )
00121           {
00122           _cg.setColor( QColorGroup::Text, Qt::darkYellow );
00123           KListViewItem::paintCell( p, _cg, column, width, alignment );
00124           return;
00125           }
00126 
00127       KListViewItem::paintCell( p, cg, column, width, alignment );
00128       }
00129 };
00130 
00131 
00132 struct BatchProgressDialog::Private {
00133 };
00134 
00135 
00137 
00138 BatchProgressDialog::BatchProgressDialog( QWidget *parent, const QString &caption )
00139                    : KDialogBase( parent, "KIPIBatchProgressDialog", true /* modal */,
00140                                   caption, Cancel)
00141 {
00142     d = new Private;
00143     QWidget* box = makeVBoxMainWidget();
00144 
00145     //---------------------------------------------
00146 
00147     QFrame *headerFrame = new QFrame( box );
00148     headerFrame->setFrameStyle(QFrame::Panel|QFrame::Sunken);
00149     QHBoxLayout* layout = new QHBoxLayout( headerFrame );
00150     layout->setMargin( 2 ); // to make sure the frame gets displayed
00151     layout->setSpacing( 0 );
00152     QLabel *pixmapLabelLeft = new QLabel( headerFrame, "pixmapLabelLeft" );
00153     pixmapLabelLeft->setScaledContents( false );
00154     layout->addWidget( pixmapLabelLeft );
00155     QLabel *labelTitle = new QLabel( caption, headerFrame, "labelTitle" );
00156     layout->addWidget( labelTitle );
00157     layout->setStretchFactor( labelTitle, 1 );
00158 
00159     QString dir;
00160     KGlobal::dirs()->addResourceType("kipi_banner_left", KGlobal::dirs()->kde_default("data") + "kipi/data");
00161     dir = KGlobal::dirs()->findResourceDir("kipi_banner_left", "banner_left.png");
00162 
00163     pixmapLabelLeft->setPaletteBackgroundColor( QColor(201, 208, 255) );
00164     pixmapLabelLeft->setPixmap( QPixmap( dir + "banner_left.png" ) );
00165     labelTitle->setPaletteBackgroundColor( QColor(201, 208, 255) );
00166 
00167     //---------------------------------------------
00168 
00169 
00170     m_actionsList = new KListView( box );
00171     m_actionsList->addColumn(i18n( "Status" ));
00172     m_actionsList->addColumn(i18n( "Current Actions" ));
00173     m_actionsList->setSorting(-1);
00174     m_actionsList->setItemMargin(1);
00175     m_actionsList->header()->hide();
00176     m_actionsList->setResizeMode(QListView::LastColumn);
00177     QWhatsThis::add( m_actionsList, i18n("<p>This is the current tasks list released.") );
00178 
00179     //---------------------------------------------
00180 
00181     m_progress = new KProgress( box, "Progress" );
00182     m_progress->setTotalSteps(100);
00183     m_progress->setValue(0);
00184     QWhatsThis::add( m_progress, i18n("<p>This is the list current percent task released.") );
00185     resize( 600, 400 );
00186 }
00187 
00188 
00190 
00191 BatchProgressDialog::~BatchProgressDialog()
00192 {
00193     delete d;
00194 }
00195 
00196 
00198 
00199 void BatchProgressDialog::addedAction(const QString &text, int type)
00200 {
00201     m_item = new KIPI::BatchProgressItem(m_actionsList,
00202                                          m_actionsList->lastItem(),
00203                                          text, type);
00204 
00205     m_actionsList->ensureItemVisible(m_item);
00206 }
00207 
00208 
00209 void BatchProgressDialog::reset()
00210 {
00211     m_actionsList->clear();
00212     m_progress->setValue(0);
00213 }
00214 
00215 
00216 void BatchProgressDialog::setProgress(int current, int total)
00217 {
00218     m_progress->setTotalSteps(total);
00219     m_progress->setValue(current);
00220 }
00221 
00222 }  // NameSpace KIPI
00223 
00224 #include "batchprogressdialog.moc"

Generated on Tue Sep 25 22:34:22 2007 for libKipi by  doxygen 1.5.3