summaryrefslogtreecommitdiffstats
path: root/kvoctrain/kvoctrain/query-dialogs/QueryDlgBase.h
blob: 6f62ddf0c4cf957eda7511bd0bd088861f02e33e (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
/***************************************************************************

                   base class for query dialogs

    -----------------------------------------------------------------------

    begin          : Thu Nov 25 20:50:53 MET 1999

    copyright      : (C) 1999-2001 Ewald Arnold <kvoctrain@ewald-arnold.de>
                     (C) 2001 The KDE-EDU team
                     (C) 2005 Peter Hedlund <peter.hedlund@kdemail.net>

    -----------------------------------------------------------------------

 ***************************************************************************

 ***************************************************************************
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 ***************************************************************************/


#ifndef Query_Dlg_Base_H
#define Query_Dlg_Base_H

#include <time.h>
#include <stdlib.h>

#include <kdialogbase.h>

#include <QueryManager.h>
#include <grammarmanager.h>

class kvoctrainExpr;
class kvoctrainDoc;

class QLineEdit;
class QMultiLineEdit;
class QLabel;
class QRadioButton;

class QueryDlgBase : public KDialogBase
{

  Q_OBJECT

public:
  enum Result { Unknown, Known, Timeout, StopIt };

  QueryDlgBase(const QString & caption, QWidget *parent = 0, const char *name = 0, bool modal = false);

  virtual ~QueryDlgBase ();

  bool smartCompare (const QString&, const QString&, int level) const;

  bool verifyField(QLineEdit *field, const QString &really);
  void resetField (QLineEdit *field);

  bool verifyField(QMultiLineEdit *field, const QString &really,
                    bool mixed);
  void resetField (QMultiLineEdit *field);

  void verifyButton(QRadioButton *radio, bool is_ok, QWidget *widget2 = 0);
  void resetButton (QRadioButton *radio, QWidget *widget2 = 0);

  // Show string after selceting known/unknown
  // depending on progress and randomness
  QString  getOKComment(int percent);
  QString  getNOKComment(int percent);
  QString  getTimeoutComment(int percent);

  int getRandom(int range)
    {
//        srand((unsigned int)time((time_t *)NULL));
        return (int) (range * ((1.0*rand())/RAND_MAX));
    }

  virtual void initFocus() const;

signals:
  void sigQueryChoice(QueryDlgBase::Result);
  void sigEditEntry(int row, int col);

protected:
  virtual void closeEvent(QCloseEvent*e);
  virtual void slotUser1();

  struct RB_Label {
    RB_Label (QRadioButton* _rb, QLabel *_label)
      : rb(_rb), label(_label) {}

    QRadioButton  *rb;
    QLabel        *label;
  };

  int            q_row,
                 q_ocol,
                 q_tcol;
  kvoctrainDoc  *kv_doc;
  kvoctrainExpr *kv_exp;
  QString        translation;
  QTimer        *qtimer;
  int            timercount;
};


#endif // Query_Dlg_Base_H