3
Copyright (C) 1999 Stefan Westerfeld
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.
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.
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.
22
#include "structureport.h"
23
#include "drawutils.h"
24
#include "portablekde.h"
28
#include <arts/debug.h>
32
StructurePort::StructurePort(Arts::StructurePortDesc SPortDesc,
33
Arts::StructureDesc StructureDesc, StructureCanvas *canvas)
34
: StructureComponent(canvas)
36
string portname = SPortDesc.name();
37
this->SPortDesc = SPortDesc;
38
this->StructureDesc = StructureDesc;
44
ModulePort::Direction dir;
45
if(SPortDesc.type().direction == Arts::input)
48
dir = ModulePort::out;
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);
58
StructurePort::~StructurePort()
61
StructureDesc.freeStructurePortDesc(SPortDesc);
64
StructureComponent::ComponentType StructurePort::type()
69
bool StructurePort::drawNeedsBackground(int segment)
75
void StructurePort::drawSegment(QPainter *dest, int cellsize, int segment)
77
string pname = SPortDesc.name();
82
int direction = (_port->direction == ModulePort::out)?1:0;
84
// FIXME: make these color defs available at one central place, they
85
// are currently copied from main.cpp
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);
96
qDrawShadePanel(&p,0,boxtop,cellsize,cellsize/2, g, false, 1, &fill);
102
QPen pen(Qt::white,1,Qt::DotLine);
105
p.drawRect(0,boxtop,cellsize,cellsize/2);
107
// ... doesn't look centered without the 2*border ?!?
109
char *label = DrawUtils::cropText(&p, pname.c_str(), cellsize-border*2,
111
p.drawText(border,border+boxtop,cellsize-border-1,(cellsize/2-1)-2*border,
112
Qt::AlignCenter,label);
114
int arrowwidth = cellsize/4;
124
fbrush = QBrush(g.light());
127
fbrush = QBrush(g.dark());
134
/**********************
143
*********************/
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
150
int b = (cellsize/2-arrowwidth)/2; // x border width
160
a.setPoint(1,b+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);
171
a.setPoint(1,t+c,b+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);
184
if(delta==1 && direction==0)
187
p.drawLine(b+l,t,b+w+l,t);
190
p.fillRect((cellsize/2-arrowwidth)/2+delta,cellsize/2-1,
191
arrowwidth,cellsize/2,fbrush);
195
int border = cellsize/7;
197
QBrush pbrush(_port->color(false));
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);
206
bool StructurePort::move(int x, int y)
208
int oldx = _x, oldy = _y;
212
SPortDesc.moveTo(x,y);
214
canvas->redrawRect(oldx,oldy,1,1);
215
canvas->redrawRect(_x,_y,1,1);
220
int StructurePort::width()
225
int StructurePort::height()
230
int StructurePort::x()
235
int StructurePort::y()
240
bool StructurePort::selected()
245
void StructurePort::hide()
250
canvas->redrawRect(_x,_y,1,1);
254
void StructurePort::show()
259
canvas->redrawRect(_x,_y,1,1);
263
bool StructurePort::visible()
268
void StructurePort::setSelected(bool newselection)
270
if(newselection != _selected)
272
_selected = newselection;
273
canvas->redrawRect(_x,_y,1,1);
277
ModulePort *StructurePort::portAt(int segment, int x, int y)
279
assert(segment == 0);
281
QPoint clickpoint(x,y);
282
if(_port->clickrect.contains(clickpoint)) return _port;
286
void StructurePort::dumpPorts(list<ModulePort *>& ports)
288
ports.push_back(_port);
291
QPixmap *StructurePort::pixmap()
296
const char *StructurePort::name()
298
static char xname[1000];
299
strcpy(xname,SPortDesc.name().c_str());
303
void StructurePort::raisePosition()
305
SPortDesc.raisePosition();
308
void StructurePort::lowerPosition()
310
SPortDesc.lowerPosition();
313
void StructurePort::rename(const char *newname)
315
SPortDesc.rename(newname);
316
canvas->redrawRect(_x,_y,1,1);
319
long StructurePort::id()
321
return SPortDesc.ID();
324
long StructurePort::position()
326
return SPortDesc.position();
329
ModulePort *StructurePort::port()