1 /***************************************************************************
2 kquestion.cpp - description
4 begin : Tue May 22 2001
5 copyright : (C) 2001 by Javier Campos Morales
6 email : javi@asyris.org
7 ***************************************************************************/
9 /***************************************************************************
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. *
16 ***************************************************************************/
19 #include "kquestion.h"
20 #include "kquestion.moc"
27 #include <kprogress.h>
30 KQuestion::KQuestion( QWidget
*parent
, const char *name
)
31 : QHBox( parent
, name
), _countdownTimer( 0 )
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 ) );
67 void KQuestion::setText( const QString
&text
)
69 _view
->setText( text
);
73 void KQuestion::setPixmap( const QPixmap pixmap
)
75 _picture
->setPixmap( pixmap
);
78 void KQuestion::countdown(int starttime
)
80 _totalCount
= starttime
;
81 _currentCount
= starttime
;
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
);
96 _countdownTimer
->stop();
97 _countdownWidget
->reset();
101 void KQuestion::countDownOne()
104 //_countdownWidget->setProgress(_totalCount - _currentCount);
105 _countdownWidget
->advance(-1);
107 if (_currentCount
== 0)
108 _countdownTimer
->stop();
111 void KQuestion::countdownVisible(bool visible
)
114 _countdownWidget
->show();
116 _countdownWidget
->hide();
119 /** Get current time */
120 int KQuestion::getCurrentTime()
122 return _totalCount
- _currentCount
;