From ce4a32fe52ef09d8f5ff1dd22c001110902b60a2 Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdelibs@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- kdeui/tests/kledtest.cpp | 160 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 160 insertions(+) create mode 100644 kdeui/tests/kledtest.cpp (limited to 'kdeui/tests/kledtest.cpp') diff --git a/kdeui/tests/kledtest.cpp b/kdeui/tests/kledtest.cpp new file mode 100644 index 000000000..8fc082420 --- /dev/null +++ b/kdeui/tests/kledtest.cpp @@ -0,0 +1,160 @@ +#include +#include +#include +#include +#include "kled.h" +#include "kledtest.h" + + + +KLedTest::KLedTest(QWidget* parent) + : QWidget(parent, 0), + LedWidth(16), + LedHeight(10), + Grid(3), + ledcolor(0), + red(QColor("red")), + blue(QColor("blue")), + green(QColor("green")), + yellow(QColor("yellow")), + kled_round(true) // Switch HERE between rectangle and circular leds +{ + if (kled_round) { + //KLed l(KLed::red, &qw); // create lamp + //KLed l(KLed::blue, &qw); // create lamp + l = new KLed(Qt::green, this); // create lamp + //KLed l(KLed::yellow, &qw); // create lamp + //KLed l(KLed::orange, &qw); // create lamp + + + l->resize(16,30); + //l.setLook(KLed::flat); + l->setShape(KLed::Circular); + //l->setShape(KLed::Rectangular); + + //l->setLook(KLed::Flat); + //l->setLook(KLed::Flat); + //l->setLook(KLed::Flat); + + l->move(5,5); + // ktmp tmpobj(l); + + t_toggle.start(1000, false); + t_color.start(3500, false); + t_look.start(3500, false); + QObject::connect(&t_toggle, SIGNAL(timeout()), l, SLOT(toggle())); + QObject::connect(&t_color, SIGNAL(timeout()), this, SLOT(nextColor())); + QObject::connect(&t_look, SIGNAL(timeout()), this, SLOT(nextLook())); + l->show(); + resize(240,140); + } + else { + y=Grid; index=0; + for( int shape=0; (int)shape<2; shape=(KLed::Shape)(shape+1)) { + x=Grid; + for( int look=0; (int)look<3; look=(KLed::Look)(look+1)) { + for(state=KLed::Off; (int)state<2; state=(KLed::State)(state+1)) + { + leds[index]=new KLed(Qt::yellow, state, + (KLed::Look)(look+1), + (KLed::Shape)(shape+1), this); + leds[index]->setGeometry(x, y, LedWidth, LedHeight); + ++index; + x+=Grid+LedWidth; + } + } + y+=Grid+LedHeight; + } + setFixedSize(x+Grid, y+Grid); + connect(&timer, SIGNAL(timeout()), SLOT(timeout())); + timer.start(500); + } +} + + +KLedTest::~KLedTest() +{ + if (kled_round) { + delete l; + } +} + + +void +KLedTest::nextColor() { + + ledcolor++; + ledcolor%=4; + + switch(ledcolor) { + default: + case 0: l->setColor(green); break; + case 1: l->setColor(blue); break; + case 2: l->setColor(red); break; + case 3: l->setColor(yellow); break; + } +} + + +void +KLedTest::nextLook() { + register int tmp; + if (kled_round) { + tmp = (static_cast(ledlook) +1 ) % 3 ; + } + else { + tmp = (static_cast(ledlook) + 1) % 3; + } + ledlook = static_cast(tmp); + l->setLook(ledlook); + //qDebug("painting look %i", ledlook); + //l->repaint(); +} + + +void +KLedTest::timeout() +{ + const int NoOfLeds=sizeof(leds)/sizeof(leds[0]); + int count; + // ----- + for(count=0; countstate()==KLed::Off) + { + leds[count]->setState(KLed::On); + } else { + leds[count]->setState(KLed::Off); + } + } +} + + +/*#include */ + +int main( int argc, char **argv ) +{ + KApplication a( argc, argv, "KLedTest" ); + KLedTest widget; + // ----- + /* + if (argc>1) { // look out for round or circular led command + if (strncmp(argv[1],"-c",2)) { + // paint circular + printf("painting circular led\n"); + widget.kled_round = true; + } + else if (strncmp(argv[1],"-r",2)) { + // paint rectangle + printf("painting rectangular led\n"); + widget.kled_round = false; + } + } + */ + a.setMainWidget(&widget); + widget.show(); + return a.exec(); // go +} + +#include "kledtest.moc" + -- cgit v1.2.1