summaryrefslogtreecommitdiffstats
path: root/src/gui/boolfieldwidget.cpp
blob: cb8eff166823dbb1e5139bfdd1d32d9affc61955 (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
/***************************************************************************
    copyright            : (C) 2005-2006 by Robby Stephenson
    email                : robby@periapsis.org
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of version 2 of the GNU General Public License as  *
 *   published by the Free Software Foundation;                            *
 *                                                                         *
 ***************************************************************************/

#include "boolfieldwidget.h"
#include "../field.h"
#include "../latin1literal.h"

#include <tqlabel.h>
#include <tqcheckbox.h>
#include <layout.h>

using Tellico::GUI::BoolFieldWidget;

BoolFieldWidget::BoolFieldWidget(Data::FieldPtr field_, TQWidget* parent_, const char* name_/*=0*/)
    : FieldWidget(field_, parent_, name_) {

  m_checkBox = new TQCheckBox(this);
  connect(m_checkBox, TQT_SIGNAL(clicked()), TQT_SIGNAL(modified()));
  registerWidget();
}

TQString BoolFieldWidget::text() const {
  if(m_checkBox->isChecked()) {
    return TQString::fromLatin1("true");
  }

  return TQString();
}

void BoolFieldWidget::setText(const TQString& text_) {
  blockSignals(true);

  m_checkBox->blockSignals(true);
  // be lax, don't have to check for "1" or "true"
  // just check for a non-empty string
  m_checkBox->setChecked(!text_.isEmpty());
  m_checkBox->blockSignals(false);

  blockSignals(false);
}

void BoolFieldWidget::clear() {
  m_checkBox->setChecked(false);
  editMultiple(false);
}

TQWidget* BoolFieldWidget::widget() {
  return m_checkBox;
}

#include "boolfieldwidget.moc"