00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "toggleswitch.h"
00012
00013 #include "canvasitemparts.h"
00014 #include "ecnode.h"
00015 #include "libraryitem.h"
00016 #include "switch.h"
00017
00018 #include <klocale.h>
00019 #include <qpainter.h>
00020
00021
00022 Item* ECDPDT::construct( ItemDocument *itemDocument, bool newItem, const char *id )
00023 {
00024 return new ECDPDT( (ICNDocument*)itemDocument, newItem, id );
00025 }
00026
00027 LibraryItem* ECDPDT::libraryItem()
00028 {
00029 return new LibraryItem(
00030 QString("ec/dpdt_toggle"),
00031 i18n("DPDT"),
00032 i18n("Switches"),
00033 "dpdt.png",
00034 LibraryItem::lit_component,
00035 ECDPDT::construct );
00036 }
00037
00038
00039 ECDPDT::ECDPDT( ICNDocument *icnDocument, bool newItem, const char *id )
00040 : Component( icnDocument, newItem, id ? id : "dpdt_toggle" )
00041 {
00042 m_name = i18n("DPDT Toggle");
00043 m_desc = i18n("Double-Pole Double-Throw switch.");
00044 setSize( -16, -32, 32, 64 );
00045
00046 addButton( "button", QRect( -16, 32, 32, 20 ), "", true );
00047
00048 createProperty( "button_text", Variant::Type::String );
00049 property("button_text")->setCaption( i18n("Button Text") );
00050
00051 Variant * v = createProperty( "bounce", Variant::Type::Bool );
00052 v->setCaption("Bounce");
00053 v->setAdvanced(true);
00054 v->setValue(false);
00055
00056 v = createProperty( "bounce_period", Variant::Type::Double );
00057 v->setCaption("Bounce Period");
00058 v->setAdvanced(true);
00059 v->setUnit("s");
00060 v->setValue(5e-3);
00061
00062 init4PinRight( -24, -8, 8, 24 );
00063
00064 init2PinLeft( -16, 16 );
00065
00066 m_switch1 = createSwitch( m_pNNode[0], m_pPNode[0], false );
00067 m_switch2 = createSwitch( m_pNNode[0], m_pPNode[1], true );
00068 m_switch3 = createSwitch( m_pNNode[1], m_pPNode[2], false );
00069 m_switch4 = createSwitch( m_pNNode[1], m_pPNode[3], true );
00070 pressed = false;
00071 }
00072
00073
00074 ECDPDT::~ECDPDT()
00075 {
00076 }
00077
00078
00079 void ECDPDT::dataChanged()
00080 {
00081 button("button")->setText( dataString("button_text") );
00082
00083 bool bounce = dataBool("bounce");
00084 int bouncePeriod_ms = int(dataDouble("bounce_period")*1e3);
00085
00086 m_switch1->setBounce( bounce, bouncePeriod_ms );
00087 m_switch2->setBounce( bounce, bouncePeriod_ms );
00088 m_switch3->setBounce( bounce, bouncePeriod_ms );
00089 m_switch4->setBounce( bounce, bouncePeriod_ms );
00090 }
00091
00092
00093 void ECDPDT::drawShape( QPainter &p )
00094 {
00095 initPainter(p);
00096
00097 int _x = (int)x()-16;
00098 int _y = (int)y()-32;
00099 const int radius = 2;
00100
00101 p.drawEllipse( _x, _y+15, 2*radius, 2*radius );
00102 p.drawEllipse( _x, _y+47, 2*radius, 2*radius );
00103 p.drawEllipse( _x+width()-2*radius+1, _y+7, 2*radius, 2*radius );
00104 p.drawEllipse( _x+width()-2*radius+1, _y+23, 2*radius, 2*radius );
00105 p.drawEllipse( _x+width()-2*radius+1, _y+39, 2*radius, 2*radius );
00106 p.drawEllipse( _x+width()-2*radius+1, _y+55, 2*radius, 2*radius );
00107
00108 const int dy = pressed ? 6 : -6;
00109
00110 p.drawLine( _x+2*radius, _y+16, _x+width()-2*radius+2, _y+16+dy );
00111 p.drawLine( _x+2*radius, _y+48, _x+width()-2*radius+2, _y+48+dy );
00112
00113 deinitPainter(p);
00114 }
00115
00116 void ECDPDT::buttonStateChanged( const QString &, bool state )
00117 {
00118 pressed = state;
00119 m_switch1->setState( state ? Switch::Open : Switch::Closed );
00120 m_switch2->setState( state ? Switch::Closed : Switch::Open );
00121 m_switch3->setState( state ? Switch::Open : Switch::Closed );
00122 m_switch4->setState( state ? Switch::Closed : Switch::Open );
00123 }
00124
00125
00126
00127
00128 Item* ECDPST::construct( ItemDocument *itemDocument, bool newItem, const char *id )
00129 {
00130 return new ECDPST( (ICNDocument*)itemDocument, newItem, id );
00131 }
00132
00133 LibraryItem* ECDPST::libraryItem()
00134 {
00135 return new LibraryItem(
00136 QString("ec/dpst_toggle"),
00137 i18n("DPST"),
00138 i18n("Switches"),
00139 "dpst.png",
00140 LibraryItem::lit_component,
00141 ECDPST::construct );
00142 }
00143
00144 ECDPST::ECDPST( ICNDocument *icnDocument, bool newItem, const char *id )
00145 : Component( icnDocument, newItem, (id) ? id : "dpst_toggle" )
00146 {
00147 m_name = i18n("DPST Toggle");
00148 m_desc = i18n("Double-Pole Single-Throw switch.");
00149 setSize( -16, -16, 32, 32 );
00150
00151 addButton( "button", QRect( -16, 16, 32, 20 ), "", true );
00152
00153 createProperty( "button_text", Variant::Type::String );
00154 property("button_text")->setCaption( i18n("Button Text") );
00155
00156 Variant * v = createProperty( "bounce", Variant::Type::Bool );
00157 v->setCaption("Bounce");
00158 v->setAdvanced(true);
00159 v->setValue(false);
00160
00161 v = createProperty( "bounce_period", Variant::Type::Double );
00162 v->setCaption("Bounce Period");
00163 v->setAdvanced(true);
00164 v->setUnit("s");
00165 v->setValue(5e-3);
00166
00167 init2PinLeft( -8, 8 );
00168 init2PinRight( -8, 8 );
00169
00170 m_switch1 = createSwitch( m_pPNode[0], m_pNNode[0], true );
00171 m_switch2 = createSwitch( m_pPNode[1], m_pNNode[1], true );
00172 pressed = false;
00173 }
00174
00175
00176 ECDPST::~ECDPST()
00177 {
00178 }
00179
00180
00181 void ECDPST::dataChanged()
00182 {
00183 button("button")->setText( dataString("button_text") );
00184
00185 bool bounce = dataBool("bounce");
00186 int bouncePeriod_ms = int(dataDouble("bounce_period")*1e3);
00187
00188 m_switch1->setBounce( bounce, bouncePeriod_ms );
00189 m_switch2->setBounce( bounce, bouncePeriod_ms );
00190 }
00191
00192
00193 void ECDPST::drawShape( QPainter &p )
00194 {
00195 initPainter(p);
00196
00197 int _x = (int)x()-16;
00198 int _y = (int)y()-16;
00199 const int radius = 2;
00200
00201 p.drawEllipse( _x, _y+6, 2*radius, 2*radius );
00202 p.drawEllipse( _x, _y+22, 2*radius, 2*radius );
00203 p.drawEllipse( _x+width()-2*radius+1, _y+6, 2*radius, 2*radius );
00204 p.drawEllipse( _x+width()-2*radius+1, _y+22, 2*radius, 2*radius );
00205
00206 const int dy = pressed ? 6 : 0;
00207
00208 p.drawLine( _x+2*radius,_y+7,_x+width()-2*radius,_y+1+dy );
00209 p.drawLine( _x+2*radius,_y+24,_x+width()-2*radius,_y+18+dy );
00210
00211 deinitPainter(p);
00212 }
00213
00214 void ECDPST::buttonStateChanged( const QString &, bool state )
00215 {
00216 m_switch1->setState( state ? Switch::Closed : Switch::Open );
00217 m_switch2->setState( state ? Switch::Closed : Switch::Open );
00218 pressed = state;
00219 }
00220
00221
00222
00223
00224 Item* ECSPDT::construct( ItemDocument *itemDocument, bool newItem, const char *id )
00225 {
00226 return new ECSPDT( (ICNDocument*)itemDocument, newItem, id );
00227 }
00228
00229 LibraryItem* ECSPDT::libraryItem()
00230 {
00231 return new LibraryItem(
00232 QString("ec/spdt_toggle"),
00233 i18n("SPDT"),
00234 i18n("Switches"),
00235 "spdt.png",
00236 LibraryItem::lit_component,
00237 ECSPDT::construct );
00238 }
00239
00240
00241 ECSPDT::ECSPDT( ICNDocument *icnDocument, bool newItem, const char *id )
00242 : Component( icnDocument, newItem, (id) ? id : "spdt_toggle" )
00243 {
00244 m_name = i18n("SPDT Toggle");
00245 m_desc = i18n("Single-Pole Double-Throw switch.");
00246 setSize( -16, -16, 32, 32 );
00247
00248 addButton( "button", QRect( -16, 16, width(), 20 ), "", true );
00249
00250 createProperty( "button_text", Variant::Type::String );
00251 property("button_text")->setCaption( i18n("Button Text") );
00252
00253 Variant * v = createProperty( "bounce", Variant::Type::Bool );
00254 v->setCaption("Bounce");
00255 v->setAdvanced(true);
00256 v->setValue(false);
00257
00258 v = createProperty( "bounce_period", Variant::Type::Double );
00259 v->setCaption("Bounce Period");
00260 v->setAdvanced(true);
00261 v->setUnit("s");
00262 v->setValue(5e-3);
00263
00264 init1PinLeft( 0 );
00265 init2PinRight( -8, 8 );
00266
00267 m_switch1 = createSwitch( m_pNNode[0], m_pPNode[0], false );
00268 m_switch2 = createSwitch( m_pNNode[0], m_pPNode[1], true );
00269
00270 pressed = false;
00271 }
00272
00273
00274 ECSPDT::~ECSPDT()
00275 {
00276 }
00277
00278
00279 void ECSPDT::dataChanged()
00280 {
00281 button("button")->setText( dataString("button_text") );
00282
00283 bool bounce = dataBool("bounce");
00284 int bouncePeriod_ms = int(dataDouble("bounce_period")*1e3);
00285
00286 m_switch1->setBounce( bounce, bouncePeriod_ms );
00287 m_switch2->setBounce( bounce, bouncePeriod_ms );
00288 }
00289
00290
00291 void ECSPDT::drawShape( QPainter &p )
00292 {
00293 initPainter(p);
00294
00295 int _x = (int)x()-16;
00296 int _y = (int)y()-16;
00297 const int radius = 2;
00298
00299 p.drawEllipse( _x, _y+15, 2*radius, 2*radius );
00300 p.drawEllipse( _x+width()-2*radius+1, _y+6, 2*radius, 2*radius );
00301 p.drawEllipse( _x+width()-2*radius+1, _y+22, 2*radius, 2*radius );
00302
00303 const int dy = pressed ? 21 : 10;
00304 p.drawLine( _x+2*radius, _y+16, _x+width()-2*radius+2, _y+dy );
00305
00306 deinitPainter(p);
00307 }
00308
00309 void ECSPDT::buttonStateChanged( const QString &, bool state )
00310 {
00311 pressed = state;
00312 m_switch1->setState( state ? Switch::Open : Switch::Closed );
00313 m_switch2->setState( state ? Switch::Closed : Switch::Open );
00314 }
00315
00316
00317
00318
00319 Item* ECSPST::construct( ItemDocument *itemDocument, bool newItem, const char *id )
00320 {
00321 return new ECSPST( (ICNDocument*)itemDocument, newItem, id );
00322 }
00323
00324 LibraryItem* ECSPST::libraryItem()
00325 {
00326 return new LibraryItem(
00327 QString("ec/spst_toggle"),
00328 i18n("SPST"),
00329 i18n("Switches"),
00330 "spst.png",
00331 LibraryItem::lit_component,
00332 ECSPST::construct
00333 );
00334 }
00335
00336
00337 ECSPST::ECSPST( ICNDocument *icnDocument, bool newItem, const char *id )
00338 : Component( icnDocument, newItem, (id) ? id : "spst_toggle" )
00339 {
00340 m_name = i18n("SPST Toggle");
00341 m_desc = i18n("Single-Pole Single-Throw switch.");
00342 setSize( -16, -8, 32, 16 );
00343 pressed = false;
00344
00345 addButton( "button", QRect( -16, 8, width(), 20 ), "", true );
00346
00347 createProperty( "button_text", Variant::Type::String );
00348 property("button_text")->setCaption( i18n("Button Text") );
00349
00350 Variant * v = createProperty( "bounce", Variant::Type::Bool );
00351 v->setCaption("Bounce");
00352 v->setAdvanced(true);
00353 v->setValue(false);
00354
00355 v = createProperty( "bounce_period", Variant::Type::Double );
00356 v->setCaption("Bounce Period");
00357 v->setAdvanced(true);
00358 v->setUnit("s");
00359 v->setValue(5e-3);
00360
00361 button("button")->setState(pressed);
00362
00363 init1PinLeft();
00364 init1PinRight();
00365
00366 m_switch = createSwitch( m_pNNode[0], m_pPNode[0], !pressed );
00367 }
00368
00369
00370 ECSPST::~ECSPST()
00371 {
00372 }
00373
00374
00375 void ECSPST::dataChanged()
00376 {
00377 button("button")->setText( dataString("button_text") );
00378
00379 bool bounce = dataBool("bounce");
00380 int bouncePeriod_ms = int(dataDouble("bounce_period")*1e3);
00381 m_switch->setBounce( bounce, bouncePeriod_ms );
00382 }
00383
00384
00385 void ECSPST::drawShape( QPainter &p )
00386 {
00387 initPainter(p);
00388
00389 int _x = (int)x()-16;
00390 int _y = (int)y()-8;
00391 const int radius = 2;
00392
00393 p.drawEllipse( _x, _y+7, 2*radius, 2*radius );
00394 p.drawEllipse( _x+width()-2*radius+1, _y+7, 2*radius, 2*radius );
00395 const int dy = pressed ? 0 : -6;
00396 p.drawLine( _x+2*radius, _y+8, _x+width()-2*radius, _y+8+dy );
00397
00398 deinitPainter(p);
00399 }
00400
00401 void ECSPST::buttonStateChanged( const QString &, bool state )
00402 {
00403 pressed = state;
00404 m_switch->setState( state ? Switch::Closed : Switch::Open );
00405 }
00406
00407