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

« back to all changes in this revision

Viewing changes to arts/builder/structureport.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
    /*
 
2
 
 
3
    Copyright (C) 1999 Stefan Westerfeld
 
4
                       stefan@space.twc.de
 
5
 
 
6
    This program is free software; you can redistribute it and/or modify
 
7
    it under the terms of the GNU General Public License as published by
 
8
    the Free Software Foundation; either version 2 of the License, or
 
9
    (at your option) any later version.
 
10
 
 
11
    This program is distributed in the hope that it will be useful,
 
12
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
    GNU General Public License for more details.
 
15
 
 
16
    You should have received a copy of the GNU General Public License
 
17
    along with this program; if not, write to the Free Software
 
18
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
19
 
 
20
    */
 
21
 
 
22
#include "structureport.h"
 
23
#include "drawutils.h"
 
24
#include "portablekde.h"
 
25
#include <qbitmap.h>
 
26
#include <assert.h>
 
27
#include <stdio.h>
 
28
#include <arts/debug.h>
 
29
 
 
30
using namespace std;
 
31
 
 
32
StructurePort::StructurePort(Arts::StructurePortDesc SPortDesc,
 
33
     Arts::StructureDesc StructureDesc, StructureCanvas *canvas)
 
34
                                        : StructureComponent(canvas)
 
35
{
 
36
        string portname = SPortDesc.name();
 
37
        this->SPortDesc = SPortDesc;
 
38
        this->StructureDesc = StructureDesc;
 
39
        _x = SPortDesc.x();
 
40
        _y = SPortDesc.y();
 
41
        _selected = false;
 
42
        _visible = false;
 
43
 
 
44
        ModulePort::Direction dir;
 
45
        if(SPortDesc.type().direction == Arts::input)
 
46
                dir = ModulePort::in;
 
47
        else
 
48
                dir = ModulePort::out;
 
49
 
 
50
        if(SPortDesc.type().connType == Arts::conn_property)
 
51
                arts_debug("got property here....");
 
52
                        //       owner, description, portnr
 
53
        arts_debug(">>creating structureport: %s",portname.c_str());
 
54
        _port = new ModulePort(this, portname.c_str(), 0, dir,this->SPortDesc);
 
55
        arts_debug("<<");
 
56
}
 
57
 
 
58
StructurePort::~StructurePort()
 
59
{
 
60
        hide();
 
61
        StructureDesc.freeStructurePortDesc(SPortDesc);
 
62
}
 
63
 
 
64
StructureComponent::ComponentType StructurePort::type()
 
65
{
 
66
        return ctPort;
 
67
}
 
68
 
 
69
bool StructurePort::drawNeedsBackground(int segment)
 
70
{
 
71
        assert(segment==0);
 
72
        return true;
 
73
}
 
74
 
 
75
void StructurePort::drawSegment(QPainter *dest, int cellsize, int segment)
 
76
{
 
77
        string pname = SPortDesc.name();
 
78
        assert(segment==0);
 
79
 
 
80
        QPainter &p = *dest;
 
81
 
 
82
        int direction = (_port->direction == ModulePort::out)?1:0;
 
83
 
 
84
// FIXME: make these color defs available at one central place, they
 
85
// are currently copied from main.cpp
 
86
 
 
87
        QColor mcolor(43,43,168);
 
88
        QColor mcolorlight(164,176,242);
 
89
    QColorGroup g( Qt::white, Qt::blue, mcolorlight, mcolor.dark(), mcolor,
 
90
                                                                                                                Qt::black, Qt::black );
 
91
        QBrush fill( mcolor );
 
92
        QPen textpen(QColor(255,255,180),1);
 
93
        int border = cellsize/10;
 
94
        int boxtop = (cellsize/2)*(1-direction);
 
95
 
 
96
        qDrawShadePanel(&p,0,boxtop,cellsize,cellsize/2, g, false, 1, &fill);
 
97
        p.setPen(textpen);
 
98
 
 
99
        // Selection box
 
100
        if(_selected)
 
101
        {
 
102
                QPen pen(Qt::white,1,Qt::DotLine);
 
103
 
 
104
                p.setPen(pen);
 
105
                p.drawRect(0,boxtop,cellsize,cellsize/2);
 
106
        }
 
107
                                                // ... doesn't look centered without the 2*border ?!?
 
108
        int textwidth;
 
109
        char *label = DrawUtils::cropText(&p, pname.c_str(), cellsize-border*2,
 
110
                                          textwidth);
 
111
        p.drawText(border,border+boxtop,cellsize-border-1,(cellsize/2-1)-2*border,
 
112
      Qt::AlignCenter,label);
 
113
 
 
114
        int arrowwidth = cellsize/4;
 
115
 
 
116
        int i;
 
117
        for(i=0;i<3;i++)
 
118
        {
 
119
                QBrush fbrush;
 
120
                int delta = 0;
 
121
                switch(i)
 
122
                {
 
123
                        case 0: delta = 0;
 
124
                                        fbrush = QBrush(g.light());
 
125
                                break;
 
126
                        case 1: delta = 2;
 
127
                                        fbrush = QBrush(g.dark());
 
128
                                break;
 
129
                        case 2: delta = 1;
 
130
                                        fbrush = fill;
 
131
                                break;
 
132
                }
 
133
 
 
134
/**********************
 
135
-   |   |
 
136
c   |   |
 
137
-  -+   +-
 
138
d |       |
 
139
-  \     /
 
140
    \   /
 
141
     \_/
 
142
  |b| w |b|
 
143
*********************/
 
144
   
 
145
        int t = (cellsize/2-1)*direction;  // top
 
146
        int l = delta;       // left
 
147
                int w = arrowwidth-2;  // arrow body width
 
148
        int h = cellsize/2;  // total arrow height
 
149
 
 
150
                int b = (cellsize/2-arrowwidth)/2;  // x border width
 
151
/*
 
152
        int c = cellsize/10;
 
153
        int d = cellsize/6;
 
154
*/
 
155
        int c = cellsize/12;
 
156
                int d = cellsize/5;
 
157
 
 
158
        QPointArray a(9);
 
159
        a.setPoint(0,b+l,t);
 
160
        a.setPoint(1,b+l,t+c);
 
161
        a.setPoint(2,l,t+c);
 
162
        a.setPoint(3,l,t+c+d);
 
163
        a.setPoint(4,b+w/2+l,t+h);
 
164
        a.setPoint(5,b*2+w+l,t+c+d);
 
165
        a.setPoint(6,b*2+w+l,t+c);
 
166
        a.setPoint(7,b+w+l,t+c);
 
167
        a.setPoint(8,b+w+l,t);
 
168
        //a.setPoint(9,b+l,t);
 
169
/*
 
170
        a.setPoint(0,t,b+l);
 
171
        a.setPoint(1,t+c,b+l);
 
172
        a.setPoint(2,t+c,l);
 
173
        a.setPoint(3,t+c+d,l);
 
174
        a.setPoint(4,t+h,b+w/2+l);
 
175
        a.setPoint(5,t+c+d,b*2+w+l);
 
176
        a.setPoint(6,t+c,b*2+w+l);
 
177
        a.setPoint(7,t+c,b+w+l);
 
178
        a.setPoint(8,t,b+w+l);
 
179
        a.setPoint(9,t,b+l);
 
180
*/
 
181
                p.setPen(Qt::NoPen);
 
182
                p.setBrush(fbrush);
 
183
                p.drawPolygon(a);
 
184
        if(delta==1 && direction==0)
 
185
                {
 
186
                        p.setPen(g.light());
 
187
                        p.drawLine(b+l,t,b+w+l,t);
 
188
                }
 
189
/*
 
190
                p.fillRect((cellsize/2-arrowwidth)/2+delta,cellsize/2-1,
 
191
                                                                        arrowwidth,cellsize/2,fbrush);
 
192
*/
 
193
        }
 
194
        {
 
195
                int border = cellsize/7;
 
196
 
 
197
                QBrush pbrush(_port->color(false));
 
198
 
 
199
                _port->clickrect = QRect(border,direction * cellsize/2 + border,
 
200
                                        cellsize/2-2*border, cellsize/2-2*border);
 
201
                qDrawShadePanel(&p, _port->clickrect, g, _port->down(), 2, &pbrush);
 
202
        }
 
203
}
 
204
 
 
205
// in cells
 
206
bool StructurePort::move(int x, int y)
 
207
{
 
208
        int oldx = _x, oldy = _y;
 
209
        _x = x;
 
210
        _y = y;
 
211
 
 
212
        SPortDesc.moveTo(x,y);
 
213
 
 
214
        canvas->redrawRect(oldx,oldy,1,1);
 
215
        canvas->redrawRect(_x,_y,1,1);
 
216
 
 
217
        return true;
 
218
}
 
219
 
 
220
int StructurePort::width()
 
221
{
 
222
        return 1;
 
223
}
 
224
 
 
225
int StructurePort::height()
 
226
{
 
227
        return 1;
 
228
}
 
229
 
 
230
int StructurePort::x()
 
231
{
 
232
        return _x;
 
233
}
 
234
 
 
235
int StructurePort::y()
 
236
{
 
237
        return _y;
 
238
}
 
239
 
 
240
bool StructurePort::selected()
 
241
{
 
242
        return _selected;
 
243
}
 
244
 
 
245
void StructurePort::hide()
 
246
{
 
247
        if(_visible)
 
248
        {
 
249
                _visible = false;
 
250
                canvas->redrawRect(_x,_y,1,1);
 
251
        }
 
252
}
 
253
 
 
254
void StructurePort::show()
 
255
{
 
256
        if(!_visible)
 
257
        {
 
258
                _visible = true;
 
259
                canvas->redrawRect(_x,_y,1,1);
 
260
        }
 
261
}
 
262
 
 
263
bool StructurePort::visible()
 
264
{
 
265
        return(_visible);
 
266
}
 
267
 
 
268
void StructurePort::setSelected(bool newselection)
 
269
{
 
270
        if(newselection != _selected)
 
271
        {
 
272
                _selected = newselection;
 
273
                canvas->redrawRect(_x,_y,1,1);
 
274
        }
 
275
}
 
276
 
 
277
ModulePort *StructurePort::portAt(int segment, int x, int y)
 
278
{
 
279
        assert(segment == 0);
 
280
 
 
281
        QPoint clickpoint(x,y);
 
282
        if(_port->clickrect.contains(clickpoint)) return _port;
 
283
        return 0;
 
284
}
 
285
 
 
286
void StructurePort::dumpPorts(list<ModulePort *>& ports)
 
287
{
 
288
        ports.push_back(_port);
 
289
}
 
290
 
 
291
QPixmap *StructurePort::pixmap()
 
292
{
 
293
        return 0;
 
294
}
 
295
 
 
296
const char *StructurePort::name()
 
297
{
 
298
        static char xname[1000];
 
299
        strcpy(xname,SPortDesc.name().c_str());
 
300
        return xname;
 
301
}
 
302
 
 
303
void StructurePort::raisePosition()
 
304
{
 
305
        SPortDesc.raisePosition();
 
306
}
 
307
 
 
308
void StructurePort::lowerPosition()
 
309
{
 
310
        SPortDesc.lowerPosition();
 
311
}
 
312
 
 
313
void StructurePort::rename(const char *newname)
 
314
{
 
315
        SPortDesc.rename(newname);
 
316
        canvas->redrawRect(_x,_y,1,1);
 
317
}
 
318
 
 
319
long StructurePort::id()
 
320
{
 
321
        return SPortDesc.ID();
 
322
}
 
323
 
 
324
long StructurePort::position()
 
325
{
 
326
        return SPortDesc.position();
 
327
}
 
328
 
 
329
ModulePort *StructurePort::port()
 
330
{
 
331
        return _port;
 
332
}