summaryrefslogtreecommitdiffstats
path: root/keduca/keduca/kquestion.cpp
blob: 7b549168a6be3c8921e69161219802722b4a72cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/***************************************************************************
                          kquestion.cpp  -  description
                             -------------------
    begin                : Tue May 22 2001
    copyright            : (C) 2001 by Javier Campos Morales
    email                : javi@asyris.org
***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/


#include "kquestion.h"
#include "kquestion.moc"

#include <tqlayout.h>
#include <tqpixmap.h>
#include <tqvbox.h>
#include <tqtimer.h>

#include <kprogress.h>
#include <klocale.h>

KQuestion::KQuestion( TQWidget *parent, const char *name )
  : TQHBox( parent, name ), _countdownTimer( 0 )
{
  initGUI();
}

KQuestion::~KQuestion()
{
}

/** Init graphical interface */
void KQuestion::initGUI()
{
  setFrameShape( TQFrame::Box );
  setFrameShadow( TQFrame::Plain );
  setPalette( TQPalette( TQt::white ) );

  TQVBox *picBox = new TQVBox( this );

  _picture = new TQLabel( picBox, "PixmapLabel1" );
  _picture->setScaledContents( FALSE );
  _picture->setPalette( TQPalette( TQt::white ) );

  _countdownWidget = new KProgress( picBox );
  _countdownWidget->setSizePolicy( TQSizePolicy( TQSizePolicy::Preferred,
                                                TQSizePolicy::Preferred ) );
  _countdownWidget->setFormat( i18n( "%v seconds left" ) );

    _view = new TQTextEdit( this, "TextView1" );
    _view->setReadOnly( true );
    _view->setFrameShape( TQTextEdit::NoFrame );
    _view->setHScrollBarMode( TQTextEdit::AlwaysOff );
    _view->setTextFormat( TQTextEdit::RichText );
    _view->setSizePolicy( TQSizePolicy( (TQSizePolicy::SizeType)7, (TQSizePolicy::SizeType)7, true ) );
}

/** Set text */
void KQuestion::setText( const TQString &text)
{
    _view->setText( text );
}

/** Set pixmap */
void KQuestion::setPixmap( const TQPixmap pixmap)
{
    _picture->setPixmap( pixmap );
}

void KQuestion::countdown(int starttime)
{
  _totalCount = starttime;
  _currentCount = starttime;
  if (starttime > 0)
  {
    if (!_countdownTimer)
    {
      _countdownTimer = new TQTimer(this);
      connect(_countdownTimer, TQT_SIGNAL(timeout()),
              this, TQT_SLOT(countDownOne()));
    }
    _countdownTimer->start(1000);
    // make one step less than time passes by in seconds
    // so that the user will see when time is up
    _countdownWidget->setTotalSteps(starttime);
    _countdownWidget->setProgress(starttime);
  }else{
    _countdownTimer->stop();
    _countdownWidget->reset();
  }
}

void KQuestion::countDownOne()
{
  _currentCount--;
  //_countdownWidget->setProgress(_totalCount - _currentCount);
  _countdownWidget->advance(-1);

  if (_currentCount == 0)
    _countdownTimer->stop();
}

void KQuestion::countdownVisible(bool visible)
{
  if (visible)
    _countdownWidget->show();
  else
    _countdownWidget->hide();
}

/** Get current time */
int KQuestion::getCurrentTime()
{
  return _totalCount - _currentCount;
}