Chameleon

Chameleon Svn Source Tree

Root/branches/xZenu/src/util/doxygen/addon/doxywizard/inputbool.cpp

Source at commit 1322 created 12 years 8 months ago.
By meklort, Add doxygen to utils folder
1/******************************************************************************
2 *
3 *
4 *
5 * Copyright (C) 1997-2011 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#include <QtGui>
18
19InputBool::InputBool( QGridLayout *layout, int &row,
20 const QString &id, bool checked,
21 const QString &docs )
22 : m_default(checked), m_docs(docs), m_id(id)
23{
24 m_lab = new HelpLabel(id);
25 m_cb = new QCheckBox;
26 layout->addWidget(m_lab,row, 0);
27 layout->addWidget(m_cb,row, 1);
28 m_enabled = true;
29 m_state=!checked; // force update
30 setValue(checked);
31 connect( m_cb, SIGNAL(toggled(bool)), SLOT(setValue(bool)) );
32 connect( m_lab, SIGNAL(enter()), SLOT(help()) );
33 connect( m_lab, SIGNAL(reset()), SLOT(reset()) );
34 row++;
35}
36
37void InputBool::help()
38{
39 showHelp(this);
40}
41
42void InputBool::setEnabled(bool b)
43{
44 m_enabled = b;
45 m_cb->setEnabled(b);
46 updateDependencies();
47}
48
49void InputBool::updateDependencies()
50{
51 for (int i=0;i<m_dependencies.count();i++)
52 {
53 m_dependencies[i]->setEnabled(m_enabled && m_state);
54 }
55}
56
57void InputBool::setValue( bool s )
58{
59 if (m_state!=s)
60 {
61 m_state=s;
62 updateDefault();
63 updateDependencies();
64 m_cb->setChecked( s );
65 m_value = m_state;
66 emit changed();
67 }
68}
69
70void InputBool::updateDefault()
71{
72 if (m_state==m_default)
73 {
74 m_lab->setText(QString::fromAscii("<qt>")+m_id+QString::fromAscii("</qt"));
75 }
76 else
77 {
78 m_lab->setText(QString::fromAscii("<qt><font color='red'>")+m_id+QString::fromAscii("</font></qt>"));
79 }
80}
81
82QVariant &InputBool::value()
83{
84 return m_value;
85}
86
87void InputBool::update()
88{
89 QString v = m_value.toString().toLower();
90 m_state = (v==QString::fromAscii("yes") ||
91 v==QString::fromAscii("true") ||
92 v==QString::fromAscii("1"));
93 m_cb->setChecked( m_state );
94 updateDefault();
95 updateDependencies();
96}
97
98void InputBool::reset()
99{
100 setValue(m_default);
101}
102
103void InputBool::writeValue(QTextStream &t,QTextCodec *codec)
104{
105 if (m_state)
106 t << codec->fromUnicode(QString::fromAscii("YES"));
107 else
108 t << codec->fromUnicode(QString::fromAscii("NO"));
109}
110
111

Archive Download this file

Revision: 1322