libyui-qt  2.52.2
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 #define SPACING 8
38 
39 using std::string;
40 
41 
42 YQCheckBox::YQCheckBox( YWidget * parent,
43  const string & label,
44  bool checked )
45  : QCheckBox( fromUTF8( label ), (QWidget *) parent->widgetRep() )
46  , YCheckBox( parent, label )
47 {
48  setWidgetRep( this );
49 
50  QCheckBox::setChecked( checked );
51 
52  connect( this, &QCheckBox::stateChanged,
53  this, &YQCheckBox::stateChanged );
54 }
55 
56 
58 {
59  // NOP
60 }
61 
62 
63 YCheckBoxState
65 {
66  switch ( checkState() )
67  {
68  case Qt::Checked: return YCheckBox_on;
69  case Qt::Unchecked: return YCheckBox_off;
70  case Qt::PartiallyChecked: return YCheckBox_dont_care;
71  }
72 
73  return YCheckBox_off;
74 }
75 
76 
77 void
78 YQCheckBox::setValue( YCheckBoxState newValue )
79 {
80  switch ( newValue )
81  {
82  case YCheckBox_on:
83  QCheckBox::setChecked( true );
84  setTristate( false );
85  break;
86 
87  case YCheckBox_off:
88  QCheckBox::setChecked( false );
89  setTristate( false );
90  break;
91 
92  case YCheckBox_dont_care:
93  QCheckBox::setTristate( true );
94  setCheckState(Qt::PartiallyChecked);
95  break;
96  }
97 }
98 
99 
100 void YQCheckBox::setLabel( const string & label )
101 {
102  setText( fromUTF8( label ) );
103  YCheckBox::setLabel( label );
104 }
105 
106 
107 void YQCheckBox::setUseBoldFont( bool useBold )
108 {
109  setFont( useBold ?
110  YQUI::yqApp()->boldFont() :
111  YQUI::yqApp()->currentFont() );
112 
113  YCheckBox::setUseBoldFont( useBold );
114 }
115 
116 
117 void YQCheckBox::setEnabled( bool enabled )
118 {
119  QCheckBox::setEnabled( enabled );
120  YWidget::setEnabled( enabled );
121 }
122 
123 
125 {
126  return 2*SPACING + sizeHint().width();
127 }
128 
129 
131 {
132  return sizeHint().height();
133 }
134 
135 
136 void YQCheckBox::setSize( int newWidth, int newHeight )
137 {
138  resize( newWidth, newHeight );
139 }
140 
141 
143 {
144  setFocus();
145 
146  return true;
147 }
148 
149 
150 void YQCheckBox::stateChanged( int newState )
151 {
152  // yuiMilestone() << "new state: " << newState << endl;
153 
154  if ( notify() )
155  YQUI::ui()->sendEvent( new YWidgetEvent( this, YEvent::ValueChanged ) );
156 }
157 
158 
159 
YQCheckBox(YWidget *parent, const std::string &label, bool checked)
Constructor.
Definition: YQCheckBox.cc:42
static YQApplication * yqApp()
Return the global YApplication object as YQApplication.
Definition: YQUI.cc:268
virtual void setValue(YCheckBoxState state)
Set the CheckBox value (on/off/don&#39;t care).
Definition: YQCheckBox.cc:78
virtual bool setKeyboardFocus()
Accept the keyboard focus.
Definition: YQCheckBox.cc:142
virtual ~YQCheckBox()
Destructor.
Definition: YQCheckBox.cc:57
virtual YCheckBoxState value()
Get the current value:
Definition: YQCheckBox.cc:64
virtual int preferredWidth()
Preferred width of the widget.
Definition: YQCheckBox.cc:124
virtual void setUseBoldFont(bool bold=true)
Use a bold font.
Definition: YQCheckBox.cc:107
virtual void setSize(int newWidth, int newHeight)
Set the new size of the widget.
Definition: YQCheckBox.cc:136
virtual void setLabel(const std::string &label)
Change the label (the text) on the RadioButton.
Definition: YQCheckBox.cc:100
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:480
virtual int preferredHeight()
Preferred height of the widget.
Definition: YQCheckBox.cc:130
virtual void setEnabled(bool enabled)
Set enabled / disabled state.
Definition: YQCheckBox.cc:117
static YQUI * ui()
Access the global Qt-UI.
Definition: YQUI.h:83