keduca
kquestion.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "kquestion.h"
00020 #include "kquestion.moc"
00021
00022 #include <qlayout.h>
00023 #include <qpixmap.h>
00024 #include <qvbox.h>
00025 #include <qtimer.h>
00026
00027 #include <kprogress.h>
00028 #include <klocale.h>
00029
00030 KQuestion::KQuestion( QWidget *parent, const char *name )
00031 : QHBox( parent, name ), _countdownTimer( 0 )
00032 {
00033 initGUI();
00034 }
00035
00036 KQuestion::~KQuestion()
00037 {
00038 }
00039
00041 void KQuestion::initGUI()
00042 {
00043 setFrameShape( QFrame::Box );
00044 setFrameShadow( QFrame::Plain );
00045 setPalette( QPalette( Qt::white ) );
00046
00047 QVBox *picBox = new QVBox( this );
00048
00049 _picture = new QLabel( picBox, "PixmapLabel1" );
00050 _picture->setScaledContents( FALSE );
00051 _picture->setPalette( QPalette( Qt::white ) );
00052
00053 _countdownWidget = new KProgress( picBox );
00054 _countdownWidget->setSizePolicy( QSizePolicy( QSizePolicy::Preferred,
00055 QSizePolicy::Preferred ) );
00056 _countdownWidget->setFormat( i18n( "%v seconds left" ) );
00057
00058 _view = new QTextEdit( this, "TextView1" );
00059 _view->setReadOnly( true );
00060 _view->setFrameShape( QTextEdit::NoFrame );
00061 _view->setHScrollBarMode( QTextEdit::AlwaysOff );
00062 _view->setTextFormat( QTextEdit::RichText );
00063 _view->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)7, (QSizePolicy::SizeType)7, true ) );
00064 }
00065
00067 void KQuestion::setText( const QString &text)
00068 {
00069 _view->setText( text );
00070 }
00071
00073 void KQuestion::setPixmap( const QPixmap pixmap)
00074 {
00075 _picture->setPixmap( pixmap );
00076 }
00077
00078 void KQuestion::countdown(int starttime)
00079 {
00080 _totalCount = starttime;
00081 _currentCount = starttime;
00082 if (starttime > 0)
00083 {
00084 if (!_countdownTimer)
00085 {
00086 _countdownTimer = new QTimer(this);
00087 connect(_countdownTimer, SIGNAL(timeout()),
00088 this, SLOT(countDownOne()));
00089 }
00090 _countdownTimer->start(1000);
00091
00092
00093 _countdownWidget->setTotalSteps(starttime);
00094 _countdownWidget->setProgress(starttime);
00095 }else{
00096 _countdownTimer->stop();
00097 _countdownWidget->reset();
00098 }
00099 }
00100
00101 void KQuestion::countDownOne()
00102 {
00103 _currentCount--;
00104
00105 _countdownWidget->advance(-1);
00106
00107 if (_currentCount == 0)
00108 _countdownTimer->stop();
00109 }
00110
00111 void KQuestion::countdownVisible(bool visible)
00112 {
00113 if (visible)
00114 _countdownWidget->show();
00115 else
00116 _countdownWidget->hide();
00117 }
00118
00120 int KQuestion::getCurrentTime()
00121 {
00122 return _totalCount - _currentCount;
00123 }