moved kdeaccessibility kdeaddons kdeadmin kdeartwork kdebindings kdeedu kdegames...
[kdeedu.git] / keduca / keduca / kquestion.cpp
blob262f89b31ef301ed711c60149d18686c782e67fc
1 /***************************************************************************
2 kquestion.cpp - description
3 -------------------
4 begin : Tue May 22 2001
5 copyright : (C) 2001 by Javier Campos Morales
6 email : javi@asyris.org
7 ***************************************************************************/
9 /***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
19 #include "kquestion.h"
20 #include "kquestion.moc"
22 #include <qlayout.h>
23 #include <qpixmap.h>
24 #include <qvbox.h>
25 #include <qtimer.h>
27 #include <kprogress.h>
28 #include <klocale.h>
30 KQuestion::KQuestion( QWidget *parent, const char *name )
31 : QHBox( parent, name ), _countdownTimer( 0 )
33 initGUI();
36 KQuestion::~KQuestion()
40 /** Init graphical interface */
41 void KQuestion::initGUI()
43 setFrameShape( QFrame::Box );
44 setFrameShadow( QFrame::Plain );
45 setPalette( QPalette( Qt::white ) );
47 QVBox *picBox = new QVBox( this );
49 _picture = new QLabel( picBox, "PixmapLabel1" );
50 _picture->setScaledContents( FALSE );
51 _picture->setPalette( QPalette( Qt::white ) );
53 _countdownWidget = new KProgress( picBox );
54 _countdownWidget->setSizePolicy( QSizePolicy( QSizePolicy::Preferred,
55 QSizePolicy::Preferred ) );
56 _countdownWidget->setFormat( i18n( "%v seconds left" ) );
58 _view = new QTextEdit( this, "TextView1" );
59 _view->setReadOnly( true );
60 _view->setFrameShape( QTextEdit::NoFrame );
61 _view->setHScrollBarMode( QTextEdit::AlwaysOff );
62 _view->setTextFormat( QTextEdit::RichText );
63 _view->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)7, (QSizePolicy::SizeType)7, true ) );
66 /** Set text */
67 void KQuestion::setText( const QString &text)
69 _view->setText( text );
72 /** Set pixmap */
73 void KQuestion::setPixmap( const QPixmap pixmap)
75 _picture->setPixmap( pixmap );
78 void KQuestion::countdown(int starttime)
80 _totalCount = starttime;
81 _currentCount = starttime;
82 if (starttime > 0)
84 if (!_countdownTimer)
86 _countdownTimer = new QTimer(this);
87 connect(_countdownTimer, SIGNAL(timeout()),
88 this, SLOT(countDownOne()));
90 _countdownTimer->start(1000);
91 // make one step less than time passes by in seconds
92 // so that the user will see when time is up
93 _countdownWidget->setTotalSteps(starttime);
94 _countdownWidget->setProgress(starttime);
95 }else{
96 _countdownTimer->stop();
97 _countdownWidget->reset();
101 void KQuestion::countDownOne()
103 _currentCount--;
104 //_countdownWidget->setProgress(_totalCount - _currentCount);
105 _countdownWidget->advance(-1);
107 if (_currentCount == 0)
108 _countdownTimer->stop();
111 void KQuestion::countdownVisible(bool visible)
113 if (visible)
114 _countdownWidget->show();
115 else
116 _countdownWidget->hide();
119 /** Get current time */
120 int KQuestion::getCurrentTime()
122 return _totalCount - _currentCount;