3
Copyright (C) 1998 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 "portposdlg.h"
24
#include "structureport.h"
25
#include "portablekde.h"
29
#include <kbuttonbox.h>
33
#include <kiconloader.h>
34
#include <kseparator.h>
37
#include <arts/debug.h>
41
PortPosDlg::PortPosDlg(QWidget *parent, Structure *structure) :QDialog(parent,"Props", TRUE)
43
this->structure = structure;
45
setCaption(i18n("Arts: Structureport view"));
47
QVBoxLayout *mainlayout = new QVBoxLayout(this);
48
//QHBoxLayout *contentslayout = new QHBoxLayout;
52
mainlayout->addSpacing(5);
53
QLabel *objectlabel = new QLabel(this);
54
QFont labelfont(objectlabel->font());
55
labelfont.setPointSize(labelfont.pointSize()*3/2);
56
objectlabel->setFont(labelfont);
57
objectlabel->setText(QString(" ")+i18n("Object Type: ")+QString(port->owner->name())+QString(" "));
58
objectlabel->setAlignment(AlignCenter);
59
min_size(objectlabel);
60
mainlayout->addWidget(objectlabel);
66
mainlayout->addSpacing(5);
67
QLabel *portlabel = new QLabel(this);
68
labelfont.setPointSize(labelfont.pointSize()*4/5);
69
portlabel->setFont(labelfont);
70
portlabel->setText(i18n("Port Description: ")+ port->description);
72
portlabel->setAlignment(AlignCenter);
73
mainlayout->addWidget(portlabel);
75
int labelwidth = imax(portlabel->sizeHint().width(),objectlabel->sizeHint().width());
77
portlabel->setMinimumWidth(labelwidth);
78
objectlabel->setMinimumWidth(labelwidth);
82
mainlayout->addSpacing(5);
83
KSeparator *ruler = new KSeparator( KSeparator::HLine, this);
84
mainlayout->addWidget(ruler);
85
mainlayout->addSpacing(5);
86
mainlayout->addLayout(contentslayout);
90
listbox = new QListBox(this);
94
listbox->setMinimumSize(100,200);
95
mainlayout->addWidget(listbox);
98
mainlayout->addSpacing(5);
99
KSeparator *ruler2 = new KSeparator( KSeparator::HLine, this);
100
mainlayout->addWidget(ruler2);
104
QHBoxLayout *buttonlayout = new QHBoxLayout;
105
mainlayout->addSpacing(5);
106
mainlayout->addLayout(buttonlayout);
107
mainlayout->addSpacing(5);
109
buttonlayout->addSpacing(5);
110
KButtonBox *bbox = new KButtonBox(this);
112
bbox->addButton(i18n("Help"));
115
KIconLoader iconloader;
116
QButton *raise = bbox->addButton(i18n("Raise"));
117
raise->setPixmap(iconloader.loadIcon("up", KIcon::Small));
118
connect( raise, SIGNAL( clicked() ), SLOT( raise() ));
120
QButton *lower = bbox->addButton(i18n("Lower"));
121
lower->setPixmap(iconloader.loadIcon("down", KIcon::Small));
122
connect( lower, SIGNAL( clicked() ), SLOT( lower() ));
124
QButton *rename = bbox->addButton(i18n("Rename"));
125
connect( rename, SIGNAL( clicked() ), SLOT( rename() ));
127
QButton *okbutton = bbox->addButton(i18n("Okay"));
128
connect( okbutton, SIGNAL( clicked() ), SLOT(accept() ) );
131
QButton *cancelbutton = bbox->addButton(i18n("Cancel"));
132
connect( cancelbutton, SIGNAL( clicked() ), SLOT(reject() ) );
137
buttonlayout->addWidget(bbox);
138
buttonlayout->addSpacing(5);
140
//mainlayout->activate();
141
mainlayout->freeze();
144
void PortPosDlg::raise()
146
int i = listbox->currentItem();
147
arts_debug("selected %d",i);
150
StructurePort *port = listports[i];
153
// hmm ok this is ugly that the raise function calls lowerPosition
154
port->lowerPosition();
158
for(l=0;l<listports.size();l++)
159
if(listports[l]->id() == port->id())
160
listbox->setCurrentItem(l);
163
void PortPosDlg::lower()
165
int i = listbox->currentItem();
166
arts_debug("selected %d",i);
168
StructurePort *port = listports[i];
171
port->raisePosition();
175
for(l=0;l<listports.size();l++)
176
if(listports[l]->id() == port->id())
177
listbox->setCurrentItem(l);
180
void PortPosDlg::rename()
182
int i = listbox->currentItem();
183
arts_debug("selected %d",i);
185
StructurePort *port = listports[i];
188
NameDlg *nd = new NameDlg(0,port->name(),i18n("Rename Port"));
193
arts_debug("rename OK...");
194
port->rename(nd->name());
200
for(l=0;l<listports.size();l++)
201
if(listports[l]->id() == port->id())
202
listbox->setCurrentItem(l);
204
void PortPosDlg::update()
206
list<StructureComponent *> &cl = *structure->getComponentList();
207
list<StructureComponent *>::iterator ci;
209
listports.erase(listports.begin(), listports.end());
212
// first incoming ports, then outgoing (which are represented by
213
// the opposite directions inside the structure)
214
for(int direction = 0; direction < 2; direction++)
216
map<long, StructurePort *> pmap;
217
int finddirection = ModulePort::in;
220
if(direction == 0) finddirection = ModulePort::out;
222
for(ci = cl.begin(); ci != cl.end(); ci++)
224
StructureComponent *component = *ci;
225
if(component->type() == StructureComponent::ctPort)
227
StructurePort *port = (StructurePort *)component;
228
if(port->port()->direction == finddirection)
230
arts_debug("port %s position %ld",port->name(),port->position());
231
pmap[port->position()] = port;
236
for(int i=0;i<pcount;i++)
238
StructurePort *port = pmap[i];
242
listbox->insertItem(port->name(),listports.size());
243
listports.push_back(port);
244
arts_debug("listports.size() is now %d",listports.size());
250
#include "portposdlg.moc"