kmail Library API Documentation

imapprogressdialog.cpp

00001 00020 #ifdef HAVE_CONFIG_H 00021 #include <config.h> 00022 #endif 00023 00024 #include "imapprogressdialog.h" 00025 00026 #include <kpushbutton.h> 00027 #include <klocale.h> 00028 #include <kdialog.h> 00029 #include <kstdguiitem.h> 00030 00031 #include <qlayout.h> 00032 #include <qstyle.h> 00033 #include <qpainter.h> 00034 #include <qprogressbar.h> 00035 00036 00037 namespace KMail { 00038 00039 00040 ProgressListViewItem::ProgressListViewItem(int col, int pro, QListView* parent, 00041 const QString& label1, 00042 const QString& label2, 00043 const QString& label3, 00044 const QString& label4, 00045 const QString& label5, 00046 const QString& label6, 00047 const QString& label7, 00048 const QString& label8 ) 00049 : QListViewItem( parent, label1, label2, label3, label4, label5, label6, 00050 label7, label8 ) 00051 { 00052 pbcol = col; 00053 prog = pro; 00054 mProgress = new QProgressBar( 100, 0 ); 00055 mProgress->setProgress( prog ); 00056 } 00057 00058 ProgressListViewItem::ProgressListViewItem(int col, int pro, QListView* parent, 00059 ProgressListViewItem* after, 00060 const QString& label1, 00061 const QString& label2, 00062 const QString& label3, 00063 const QString& label4, 00064 const QString& label5, 00065 const QString& label6, 00066 const QString& label7, 00067 const QString& label8 ) 00068 : QListViewItem( parent, after, label1, label2, label3, label4, label5, 00069 label6, label7, label8 ) 00070 { 00071 pbcol = col; 00072 prog = pro; 00073 mProgress = new QProgressBar( 100, 0 ); 00074 mProgress->setProgress( prog ); 00075 } 00076 00077 ProgressListViewItem::~ProgressListViewItem() 00078 { 00079 delete mProgress; 00080 } 00081 00082 void ProgressListViewItem::setProgress( int progress ) 00083 { 00084 mProgress->setProgress( progress ); 00085 } 00086 00087 void ProgressListViewItem::paintCell( QPainter *p, const QColorGroup &cg, 00088 int column, int width, int alignment ) 00089 { 00090 QColorGroup _cg( cg ); 00091 QColor c = _cg.text(); 00092 00093 00094 if ( column == pbcol ){ 00095 const QRect bar = QRect( 0, 0, width, height() ); 00096 mProgress->resize( width, height() ); 00097 00098 QPixmap pm( bar.size() ); 00099 QPainter paint( &pm ); 00100 00101 paint.fillRect( bar, listView()->paletteBackgroundColor() ); 00102 paint.setFont( p->font() ); 00103 00104 QStyle::SFlags flags = QStyle::Style_Default; 00105 if (isEnabled()) 00106 flags |= QStyle::Style_Enabled; 00107 00108 listView()->style().drawControl(QStyle::CE_ProgressBarGroove, &paint, mProgress, 00109 QStyle::visualRect(listView()->style().subRect(QStyle::SR_ProgressBarGroove, mProgress), mProgress ), 00110 listView()->colorGroup(), flags); 00111 00112 listView()->style().drawControl(QStyle::CE_ProgressBarContents, &paint, mProgress, 00113 QStyle::visualRect(listView()->style().subRect(QStyle::SR_ProgressBarContents, mProgress), mProgress ), 00114 listView()->colorGroup(), flags); 00115 00116 if (mProgress->percentageVisible()) 00117 listView()->style().drawControl(QStyle::CE_ProgressBarLabel, &paint, mProgress, 00118 QStyle::visualRect(listView()->style().subRect(QStyle::SR_ProgressBarLabel, mProgress), mProgress ), 00119 listView()->colorGroup(), flags); 00120 paint.end(); 00121 00122 p->drawPixmap( bar.x(), bar.y(), pm ); 00123 00124 } 00125 else { 00126 _cg.setColor( QColorGroup::Text, c ); 00127 QListViewItem::paintCell( p, _cg, column, width, alignment ); 00128 } 00129 } 00130 00131 IMAPProgressDialog::IMAPProgressDialog( QWidget* parent, const char* name, bool modal, WFlags fl ) 00132 : QDialog( parent, name, modal, fl ), 00133 mPreviousItem( 0 ) 00134 { 00135 00136 setCaption( i18n("IMAP Progress") ); 00137 resize( 360, 328 ); 00138 00139 QBoxLayout* topLayout = new QVBoxLayout( this, KDialog::marginHint(), KDialog::spacingHint(), 00140 "topLayout"); 00141 00142 mSyncEditorListView = new QListView( this, "SyncEditorListView" ); 00143 mSyncEditorListView->addColumn( i18n( "Folder" ) ); 00144 mSyncEditorListView->addColumn( i18n( "Progress" ) ); 00145 mSyncEditorListView->addColumn( i18n( "Status" ) ); 00146 mSyncEditorListView->setSorting( -1, false ); 00147 mSyncEditorListView->setColumnWidth( 0, 100 ); 00148 mSyncEditorListView->setColumnWidth( 1, 100 ); 00149 mSyncEditorListView->setColumnWidth( 2, 200 ); 00150 00151 mSyncEditorListView->setColumnWidthMode(0, QListView::Maximum); 00152 mSyncEditorListView->setColumnWidthMode(2, QListView::Maximum); 00153 00154 topLayout->addWidget( mSyncEditorListView ); 00155 00156 QBoxLayout* bottomLayout = new QHBoxLayout( topLayout, KDialog::spacingHint(), "bottomLayout"); 00157 bottomLayout->addStretch(); 00158 00159 KPushButton* pbClose = new KPushButton( KStdGuiItem::close(), this ); 00160 bottomLayout->addWidget( pbClose ); 00161 00162 connect(pbClose, SIGNAL(clicked()), this, SLOT(close()) ); 00163 } 00164 00165 void IMAPProgressDialog::clear() 00166 { 00167 QListViewItem* item; 00168 while( ( item = mSyncEditorListView->firstChild() ) != 0 ) delete item; 00169 mPreviousItem = 0; 00170 } 00171 00172 /* retrieves the info needed to update the list view items and it's progress bar */ 00173 00174 void IMAPProgressDialog::syncState( const QString& folderName, 00175 int progress, const QString& syncStatus ) 00176 { 00177 ProgressListViewItem* item = 0; 00178 for( QListViewItem* it = mSyncEditorListView->firstChild(); it != 0; it = it->nextSibling() ) { 00179 if( folderName == it->text(0) ) { 00180 item = static_cast<ProgressListViewItem*>(it); 00181 break; 00182 } 00183 } 00184 00185 if ( progress > 100 ) 00186 progress = 100; 00187 00188 if( item ) { 00189 item->setProgress( progress ); 00190 item->setText( 2, syncStatus ); 00191 } else { 00192 mPreviousItem = new ProgressListViewItem( 1, progress, 00193 mSyncEditorListView, 00194 mPreviousItem, folderName, 00195 QString::null, syncStatus ); 00196 } 00197 } 00198 00199 void IMAPProgressDialog::closeEvent( QCloseEvent* e ) 00200 { 00201 e->accept(); 00202 hide(); 00203 } 00204 00205 00206 /* 00207 * Destructor 00208 */ 00209 IMAPProgressDialog::~IMAPProgressDialog() 00210 { 00211 // no need to delete child widgets. 00212 } 00213 00214 00215 } 00216 00217 #include "imapprogressdialog.moc"
KDE Logo
This file is part of the documentation for kmail Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Jul 28 23:57:58 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003