libyui-qt  2.46.13
YQCheckBox.cc
1 /*
2  Copyright (C) 2000-2012 Novell, Inc
3  This library is free software; you can redistribute it and/or modify
4  it under the terms of the GNU Lesser General Public License as
5  published by the Free Software Foundation; either version 2.1 of the
6  License, or (at your option) version 3.0 of the License. This library
7  is distributed in the hope that it will be useful, but WITHOUT ANY
8  WARRANTY; without even the implied warranty of MERCHANTABILITY or
9  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
10  License for more details. You should have received a copy of the GNU
11  Lesser General Public License along with this library; if not, write
12  to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
13  Floor, Boston, MA 02110-1301 USA
14 */
15 
16 
17 /*-/
18 
19  File: YQCheckBox.cc
20 
21  Author: Stefan Hundhammer <sh@suse.de>
22 
23 /-*/
24 
25 
26 #include <qcheckbox.h>
27 #include <QBoxLayout>
28 #define YUILogComponent "qt-ui"
29 #include <yui/YUILog.h>
30 
31 #include "utf8.h"
32 #include "YQApplication.h"
33 #include "YQUI.h"
34 #include <yui/YEvent.h>
35 #include "YQCheckBox.h"
36 
37 
38 #define SPACING 8
39 
40 
41 YQCheckBox::YQCheckBox( YWidget * parent,
42  const std::string & label,
43  bool checked )
44  : QCheckBox( fromUTF8( label ), (QWidget *) parent->widgetRep() )
45  , YCheckBox( parent, label )
46 {
47  setWidgetRep( this );
48 
49  QCheckBox::setChecked( checked );
50 
51  connect( this, &QCheckBox::stateChanged,
52  this, &YQCheckBox::stateChanged );
53 }
54 
55 
57 {
58  // NOP
59 }
60 
61 
62 YCheckBoxState
64 {
65  switch ( checkState() )
66  {
67  case Qt::Checked: return YCheckBox_on;
68  case Qt::Unchecked: return YCheckBox_off;
69  case Qt::PartiallyChecked: return YCheckBox_dont_care;
70  }
71 
72  return YCheckBox_off;
73 }
74 
75 
76 void
77 YQCheckBox::setValue( YCheckBoxState newValue )
78 {
79  switch ( newValue )
80  {
81  case YCheckBox_on:
82  QCheckBox::setChecked( true );
83  setTristate( false );
84  break;
85 
86  case YCheckBox_off:
87  QCheckBox::setChecked( false );
88  setTristate( false );
89  break;
90 
91  case YCheckBox_dont_care:
92  QCheckBox::setTristate( true );
93  setCheckState(Qt::PartiallyChecked);
94  break;
95  }
96 }
97 
98 
99 void YQCheckBox::setLabel( const std::string & label )
100 {
101  setText( fromUTF8( label ) );
102  YCheckBox::setLabel( label );
103 }
104 
105 
106 void YQCheckBox::setUseBoldFont( bool useBold )
107 {
108  setFont( useBold ?
109  YQUI::yqApp()->boldFont() :
110  YQUI::yqApp()->currentFont() );
111 
112  YCheckBox::setUseBoldFont( useBold );
113 }
114 
115 
116 void YQCheckBox::setEnabled( bool enabled )
117 {
118  QCheckBox::setEnabled( enabled );
119  YWidget::setEnabled( enabled );
120 }
121 
122 
124 {
125  return 2*SPACING + sizeHint().width();
126 }
127 
128 
130 {
131  return sizeHint().height();
132 }
133 
134 
135 void YQCheckBox::setSize( int newWidth, int newHeight )
136 {
137  resize( newWidth, newHeight );
138 }
139 
140 
142 {
143  setFocus();
144 
145  return true;
146 }
147 
148 
149 void YQCheckBox::stateChanged( int newState )
150 {
151  // yuiMilestone() << "new state: " << newState << std::endl;
152 
153  if ( notify() )
154  YQUI::ui()->sendEvent( new YWidgetEvent( this, YEvent::ValueChanged ) );
155 }
156 
157 
158 #include "YQCheckBox.moc"
YQCheckBox(YWidget *parent, const std::string &label, bool checked)
Constructor.
Definition: YQCheckBox.cc:41
static YQApplication * yqApp()
Return the global YApplication object as YQApplication.
Definition: YQUI.cc:284
virtual void setValue(YCheckBoxState state)
Set the CheckBox value (on/off/don't care).
Definition: YQCheckBox.cc:77
virtual bool setKeyboardFocus()
Accept the keyboard focus.
Definition: YQCheckBox.cc:141
virtual ~YQCheckBox()
Destructor.
Definition: YQCheckBox.cc:56
virtual YCheckBoxState value()
Get the current value:
Definition: YQCheckBox.cc:63
virtual int preferredWidth()
Preferred width of the widget.
Definition: YQCheckBox.cc:123
virtual void setUseBoldFont(bool bold=true)
Use a bold font.
Definition: YQCheckBox.cc:106
virtual void setSize(int newWidth, int newHeight)
Set the new size of the widget.
Definition: YQCheckBox.cc:135
virtual void setLabel(const std::string &label)
Change the label (the text) on the RadioButton.
Definition: YQCheckBox.cc:99
void sendEvent(YEvent *event)
Widget event handlers (slots) call this when an event occured that should be the answer to a UserInpu...
Definition: YQUI.cc:486
virtual int preferredHeight()
Preferred height of the widget.
Definition: YQCheckBox.cc:129
virtual void setEnabled(bool enabled)
Set enabled / disabled state.
Definition: YQCheckBox.cc:116
static YQUI * ui()
Access the global Qt-UI.
Definition: YQUI.h:81