inputbool.cpp
Go to the documentation of this file.
1 /******************************************************************************
2  *
3  *
4  *
5  * Copyright (C) 1997-2015 by Dimitri van Heesch.
6  *
7  * Permission to use, copy, modify, and distribute this software and its
8  * documentation under the terms of the GNU General Public License is hereby
9  * granted. No representations are made about the suitability of this software
10  * for any purpose. It is provided "as is" without express or implied warranty.
11  * See the GNU General Public License for more details.
12  *
13  */
14 
15 #include "inputbool.h"
16 #include "helplabel.h"
17 
18 #include <QCheckBox>
19 #include <QTextStream>
20 #include <QTextCodec>
21 #include <QGridLayout>
22 
23 InputBool::InputBool( QGridLayout *layout, int &row,
24  const QString &id, bool checked,
25  const QString &docs )
26  : m_default(checked), m_docs(docs), m_id(id)
27 {
28  m_lab = new HelpLabel(id);
29  m_cb = new QCheckBox;
30  layout->addWidget(m_lab,row, 0);
31  layout->addWidget(m_cb,row, 1);
32  m_enabled = true;
33  m_state=!checked; // force update
34  setValue(checked);
35  connect( m_cb, SIGNAL(toggled(bool)), SLOT(setValue(bool)) );
36  connect( m_lab, SIGNAL(enter()), SLOT(help()) );
37  connect( m_lab, SIGNAL(reset()), SLOT(reset()) );
38  row++;
39 }
40 
42 {
43  showHelp(this);
44 }
45 
47 {
48  m_enabled = b;
49  m_cb->setEnabled(b);
50  m_lab->setEnabled(b);
51  updateDefault();
53 }
54 
56 {
57  for (int i=0;i<m_dependencies.count();i++)
58  {
59  m_dependencies[i]->setEnabled(m_enabled && m_state);
60  }
61 }
62 
63 void InputBool::setValue( bool s )
64 {
65  if (m_state!=s)
66  {
67  m_state=s;
68  updateDefault();
70  m_cb->setChecked( s );
71  m_value = m_state;
72  emit changed();
73  }
74 }
75 
77 {
78  if (m_state==m_default || !m_lab->isEnabled())
79  {
80  m_lab->setText(QString::fromLatin1("<qt>")+m_id+QString::fromLatin1("</qt"));
81  }
82  else
83  {
84  m_lab->setText(QString::fromLatin1("<qt><font color='red'>")+m_id+QString::fromLatin1("</font></qt>"));
85  }
86 }
87 
88 QVariant &InputBool::value()
89 {
90  return m_value;
91 }
92 
94 {
95  QString v = m_value.toString().toLower();
96  m_state = (v==QString::fromLatin1("yes") ||
97  v==QString::fromLatin1("true") ||
98  v==QString::fromLatin1("1"));
99  m_cb->setChecked( m_state );
100  updateDefault();
102 }
103 
105 {
107 }
108 
110 {
111  if (m_state)
112  t << codec->fromUnicode(QString::fromLatin1("YES"));
113  else
114  t << codec->fromUnicode(QString::fromLatin1("NO"));
115 }
116 
void setEnabled(bool)
Definition: inputbool.cpp:46
void help()
Definition: inputbool.cpp:41
virtual QCString fromUnicode(const QString &uc, int &lenInOut) const
Definition: qtextcodec.cpp:783
The QString class provides an abstraction of Unicode text and the classic C null-terminated char arra...
Definition: qstring.h:350
QLabel * m_lab
Definition: inputbool.h:68
static QString fromLatin1(const char *, int len=-1)
Definition: qstring.cpp:14539
bool m_state
Definition: inputbool.h:60
def connect(nxgraph, k1, k2, p1=0, p2=0, kwds)
Definition: graph.py:30
QCheckBox * m_cb
Definition: inputbool.h:64
bool m_enabled
Definition: inputbool.h:62
void writeValue(QTextStream &t, QTextCodec *codec)
Definition: inputbool.cpp:109
QVariant & value()
Definition: inputbool.cpp:88
uint count() const
Definition: qlist.h:66
void setValue(bool)
Definition: inputbool.cpp:63
void updateDependencies()
Definition: inputbool.cpp:55
void changed()
void update()
Definition: inputbool.cpp:93
void showHelp(Input *)
The QTextStream class provides basic functions for reading and writing text using a QIODevice...
Definition: qtextstream.h:53
QList< Input * > m_dependencies
Definition: inputbool.h:66
bool m_default
Definition: inputbool.h:61
void reset()
Definition: inputbool.cpp:104
static bool * b
Definition: config.cpp:1043
QString m_id
Definition: inputbool.h:67
void updateDefault()
Definition: inputbool.cpp:76
Provides conversion between text encodings.
Definition: qtextcodec.h:62
static QCString * s
Definition: config.cpp:1042
QVariant m_value
Definition: inputbool.h:63
InputBool(QGridLayout *layout, int &row, const QString &id, bool enabled, const QString &docs)
Definition: inputbool.cpp:23