~ubuntu-branches/ubuntu/hoary/kdemultimedia/hoary

« back to all changes in this revision

Viewing changes to kscd/ledlamp.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Martin Schulze
  • Date: 2003-01-22 15:00:51 UTC
  • Revision ID: james.westby@ubuntu.com-20030122150051-uihwkdoxf15mi1tn
Tags: upstream-2.2.2
ImportĀ upstreamĀ versionĀ 2.2.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*  This file is part of the KDE libraries
 
2
    Copyright (C) 1997 Richard Moore (moorer@cs.man.ac.uk)
 
3
 
 
4
    This library is free software; you can redistribute it and/or
 
5
    modify it under the terms of the GNU Library General Public
 
6
    License as published by the Free Software Foundation; either
 
7
    version 2 of the License, or (at your option) any later version.
 
8
 
 
9
    This library is distributed in the hope that it will be useful,
 
10
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
12
    Library General Public License for more details.
 
13
 
 
14
    You should have received a copy of the GNU Library General Public License
 
15
    along with this library; see the file COPYING.LIB.  If not, write to
 
16
    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 
17
    Boston, MA 02111-1307, USA.
 
18
*/
 
19
 
 
20
 
 
21
#include <stdio.h>
 
22
#include <qpainter.h>
 
23
#include <qbrush.h>
 
24
#include <qpen.h>
 
25
#include <qcolor.h>
 
26
#include "ledlamp.h"
 
27
#include "ledlamp.moc"
 
28
 
 
29
LedLamp::LedLamp(QWidget *parent, Type t) : QFrame(parent), 
 
30
  w( 10 ), h( 7 ), dx( 4 )
 
31
{
 
32
  // Make sure we're in a sane state
 
33
  s = Off;
 
34
 
 
35
  // Set the frame style
 
36
  //  setFrameStyle(Sunken | Box);
 
37
  setGeometry(0,0,h+1,w+1);
 
38
  ledtype = t;
 
39
} // LedLamp
 
40
 
 
41
void 
 
42
LedLamp::drawContents(QPainter *painter)
 
43
{
 
44
 
 
45
  
 
46
  QBrush lightBrush(this->foregroundColor());
 
47
  QBrush darkBrush(this->backgroundColor());
 
48
 
 
49
  QPen darkPen(this->backgroundColor(),1);
 
50
  QPen lightPen(this->foregroundColor(), 1);
 
51
 
 
52
  switch(s) 
 
53
    {
 
54
    case On:
 
55
      painter->setBrush(lightBrush);
 
56
      switch (ledtype)
 
57
        {
 
58
        case Rect:
 
59
          painter->drawRect(1,1,w-3, h-2);
 
60
          break;
 
61
        case Loop:
 
62
          painter->setBrush(lightBrush);
 
63
          painter->setPen(lightPen);
 
64
          
 
65
          painter->drawLine(0, 2, 0, h-2); //  |
 
66
          painter->drawLine(1, 1, w-4, 1); // ~
 
67
          painter->drawLine(w-3, 2, w-3, h-2); // |
 
68
          painter->drawLine(2, h-2, w-3, h-2); //_
 
69
          painter->drawLine(w-6,0,w-6,2); // ---+
 
70
          painter->drawLine(3,h-2,3,h); // +---
 
71
          break;
 
72
        }
 
73
      break;
 
74
      
 
75
    case Off:
 
76
      painter->setBrush(darkBrush);
 
77
      switch (ledtype)
 
78
        {
 
79
        case Rect:
 
80
          painter->drawRect(1,1,w-3, h-2);
 
81
          break;
 
82
        case Loop:
 
83
          painter->setBrush(darkBrush);
 
84
          painter->setPen(darkPen);
 
85
 
 
86
          painter->fillRect(0,0,w,h, darkBrush);
 
87
          /*
 
88
            painter->drawLine(0, 2, 0, h-2); //  |
 
89
            painter->drawLine(1, 1, w-4, 1); // ~
 
90
            painter->drawLine(w-3, 2, w-3, h-2); // |
 
91
            painter->drawLine(2, h-2, w-3, h-2); //_
 
92
            painter->drawLine(w-6,0,w-6,2); // ---+
 
93
            painter->drawLine(3,h-2,3,h); // +---
 
94
            */
 
95
          break;
 
96
        }
 
97
      break;
 
98
      
 
99
    default:
 
100
      fprintf(stderr, "LedLamp: INVALID State (%d)\n", s);
 
101
    }
 
102
} // drawContents
 
103