summaryrefslogtreecommitdiffstats
path: root/kscd/ledlamp.cpp
blob: bfaa5c4e8ee93bbf3d58581a0487811aa3d0a7ec (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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*  This file is part of the KDE libraries
    Copyright (C) 1997 Richard Moore (moorer@cs.man.ac.uk)

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
    Boston, MA 02110-1301, USA.
*/


#include <stdio.h>
#include <qpainter.h>
#include <qbrush.h>
#include <qpen.h>
#include <qcolor.h>
#include "ledlamp.h"
#include "ledlamp.moc"

LedLamp::LedLamp(QWidget *parent, Type t) : QFrame(parent), 
  w( 10 ), h( 7 ), dx( 4 )
{
  // Make sure we're in a sane state
  s = Off;

  // Set the frame style
  //  setFrameStyle(Sunken | Box);
  setGeometry(0,0,h+1,w+1);
  ledtype = t;
} // LedLamp

void 
LedLamp::drawContents(QPainter *painter)
{

  
  QBrush lightBrush(this->foregroundColor());
  QBrush darkBrush(this->backgroundColor());

  QPen darkPen(this->backgroundColor(),1);
  QPen lightPen(this->foregroundColor(), 1);

  switch(s) 
    {
    case On:
      painter->setBrush(lightBrush);
      switch (ledtype)
	{
	case Rect:
	  painter->drawRect(1,1,w-3, h-2);
	  break;
	case Loop:
	  painter->setBrush(lightBrush);
	  painter->setPen(lightPen);
	  
	  painter->drawLine(0, 2, 0, h-2); //  |
	  painter->drawLine(1, 1, w-4, 1); // ~
	  painter->drawLine(w-3, 2, w-3, h-2); // |
	  painter->drawLine(2, h-2, w-3, h-2); //_
	  painter->drawLine(w-6,0,w-6,2); // ---+
	  painter->drawLine(3,h-2,3,h); // +---
	  break;
	}
      break;
      
    case Off:
      painter->setBrush(darkBrush);
      switch (ledtype)
	{
	case Rect:
	  painter->drawRect(1,1,w-3, h-2);
	  break;
	case Loop:
	  painter->setBrush(darkBrush);
	  painter->setPen(darkPen);

	  painter->fillRect(0,0,w,h, darkBrush);
	  /*
	    painter->drawLine(0, 2, 0, h-2); //  |
	    painter->drawLine(1, 1, w-4, 1); // ~
	    painter->drawLine(w-3, 2, w-3, h-2); // |
	    painter->drawLine(2, h-2, w-3, h-2); //_
	    painter->drawLine(w-6,0,w-6,2); // ---+
	    painter->drawLine(3,h-2,3,h); // +---
	    */
	  break;
	}
      break;
      
    default:
      fprintf(stderr, "LedLamp: INVALID State (%d)\n", s);
    }
} // drawContents