3
Copyright (C) 1998-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 "portpropdlg.h"
23
#include "portablekde.h"
27
#include <kbuttonbox.h>
28
#include <kseparator.h>
39
static void min_size(QWidget *w) {
40
w->setMinimumSize(w->sizeHint());
43
PortPropDlg::PortPropDlg(QWidget *parent, ModulePort *port) :QDialog(parent,"Props", TRUE)
49
if(port->PortDesc.isConnected())
50
newconntype = ctConnection;
52
if(port->PortDesc.hasValue())
53
newconntype = ctValue;
57
setCaption(i18n("Arts port properties"));
59
QVBoxLayout *mainlayout = new QVBoxLayout(this);
60
QHBoxLayout *contentslayout = new QHBoxLayout;
64
mainlayout->addSpacing(5);
65
QLabel *objectlabel = new QLabel(this);
66
QFont labelfont(objectlabel->font());
67
labelfont.setPointSize(labelfont.pointSize()*3/2);
68
objectlabel->setFont(labelfont);
69
objectlabel->setText(QString(" ")+i18n("Object Type: ")+QString(port->owner->name())+QString(" "));
70
objectlabel->setAlignment(AlignCenter);
71
min_size(objectlabel);
72
mainlayout->addWidget(objectlabel);
76
mainlayout->addSpacing(5);
77
QLabel *portlabel = new QLabel(this);
78
labelfont.setPointSize(labelfont.pointSize()*4/5);
79
portlabel->setFont(labelfont);
80
portlabel->setText(i18n("Port Description: ")+ port->description);
82
portlabel->setAlignment(AlignCenter);
83
mainlayout->addWidget(portlabel);
85
int labelwidth = max(portlabel->sizeHint().width(),objectlabel->sizeHint().width());
87
portlabel->setMinimumWidth(labelwidth);
88
objectlabel->setMinimumWidth(labelwidth);
92
mainlayout->addSpacing(5);
93
KSeparator *ruler = new KSeparator( KSeparator::HLine, this);
94
mainlayout->addWidget(ruler);
96
mainlayout->addSpacing(5);
97
mainlayout->addLayout(contentslayout);
101
contentslayout->addSpacing(5);
102
if(port->owner->pixmap())
104
QLabel *iconlabel = new QLabel(this);
106
iconlabel->setPixmap(*port->owner->pixmap());
108
contentslayout->addWidget(iconlabel);
110
QVBoxLayout *connlayout = new QVBoxLayout;
111
contentslayout->addSpacing(5);
112
contentslayout->addLayout(connlayout);
113
contentslayout->addSpacing(5);
117
QButtonGroup *rb_group = new QButtonGroup(this);
120
rb_noconn = new QRadioButton(i18n("not connected"), this);
121
rb_group->insert(rb_noconn);
123
connlayout->addWidget(rb_noconn);
124
connect( rb_noconn, SIGNAL( clicked() ), SLOT(conn_none() ) );
126
rb_connto = new QRadioButton(i18n("connection"), this);
127
rb_group->insert(rb_connto);
129
connlayout->addWidget(rb_connto);
130
connect( rb_connto, SIGNAL( clicked() ), SLOT(conn_to() ) );
132
rb_const = new QRadioButton(i18n("constant value"), this);
133
rb_group->insert(rb_const);
135
connlayout->addWidget(rb_const);
136
connect( rb_const, SIGNAL( clicked() ), SLOT(conn_value() ) );
138
QHBoxLayout *valuelayout = new QHBoxLayout;
139
connlayout->addLayout(valuelayout);
141
valuelabel = new QLabel("value:", this);
142
valuelayout->addSpacing(20);
143
min_size(valuelabel);
144
valuelayout->addWidget(valuelabel);
146
valuelayout->addSpacing(5);
148
valueedit = new QLineEdit(this);
150
if(port->PortDesc.hasValue())
152
Arts::Any value = port->PortDesc.value();
154
b.write(value.value);
156
if(value.type == "float")
157
newvalue.sprintf("%2.4f", b.readFloat());
158
else if(value.type == "long")
159
newvalue.sprintf("%ld", b.readLong());
160
else if(value.type == "string")
164
newvalue = s.c_str();
166
else if(value.type == "boolean")
173
else newvalue = ("*unknown type* " + value.type).c_str();
175
valueedit->setText(newvalue);
178
connect(valueedit, SIGNAL( textChanged(const QString&) ),
179
SLOT( connvalue_changed(const QString&) ));
180
valuelayout->addWidget(valueedit);
185
rb_conf = new QRadioButton(i18n("configurable"), this);
186
rb_group->insert(rb_conf);
188
connlayout->addWidget(rb_conf);
189
connect( rb_conf, SIGNAL( clicked() ), SLOT(conn_conf() ) );
193
valuelayout->addStretch(1);
194
valuelayout->addSpacing(5);
196
mainlayout->addSpacing(5);
197
KSeparator *ruler2 = new KSeparator( KSeparator::HLine, this);
198
mainlayout->addWidget(ruler2);
202
QHBoxLayout *buttonlayout = new QHBoxLayout;
203
mainlayout->addSpacing(5);
204
mainlayout->addLayout(buttonlayout);
205
mainlayout->addSpacing(5);
207
buttonlayout->addSpacing(5);
208
KButtonBox *bbox = new KButtonBox(this);
210
QButton *helpbutton = bbox->addButton(i18n("Help"));
211
connect( helpbutton, SIGNAL( clicked() ), SLOT(showHelp()));
214
QButton *okbutton = bbox->addButton(i18n("Okay"));
215
connect( okbutton, SIGNAL( clicked() ), SLOT(apply_changes() ) );
216
connect( okbutton, SIGNAL( clicked() ), SLOT(accept() ) );
218
QButton *cancelbutton = bbox->addButton(i18n("Cancel"));
219
connect( cancelbutton, SIGNAL( clicked() ), SLOT(reject() ) );
223
buttonlayout->addWidget(bbox);
224
buttonlayout->addSpacing(5);
226
//mainlayout->activate();
227
mainlayout->freeze();
232
void PortPropDlg::updatestatus()
234
rb_noconn->setChecked(newconntype == ctNone);
236
valuelabel->setEnabled(newconntype == ctValue);
237
valueedit->setEnabled(newconntype == ctValue);
238
rb_const->setChecked(newconntype == ctValue);
240
rb_connto->setChecked(newconntype == ctConnection);
243
void PortPropDlg::conn_value()
245
newconntype = ctValue;
246
if(port->PortDesc.type().direction == Arts::output)
247
newconntype = ctNone; // yes, confusing, should be done better
251
void PortPropDlg::conn_to()
253
if(!port->PortDesc.isConnected()) // no connection there?
254
newconntype = ctNone;
256
newconntype = ctConnection;
260
void PortPropDlg::conn_conf()
262
newconntype = ctNone; // no conf supported
266
void PortPropDlg::conn_none()
268
newconntype = ctNone;
272
void PortPropDlg::connvalue_changed(const QString& _newvalue)
274
newvalue = _newvalue;
277
void PortPropDlg::showHelp()
279
// transforms port->owner->name() to an anchor for the right documentation
280
// example: "Arts::Synth_MULTI_ADD" => "MREF-SYNTH-MULTI-ADD"
281
string s = port->owner->name();
282
string anchor = "MREF-";
284
string::iterator si = s.begin();
285
if(strncmp(s.c_str(),"Arts::",6) == 0) si += 6;
289
if(*si == '_') anchor += '-'; else anchor += toupper(*si);
292
kapp->invokeHelp(anchor.c_str());
295
void PortPropDlg::apply_changes()
297
if(newconntype != ctConnection)
299
if(port->PortDesc.isConnected())
300
port->PortDesc.disconnectAll();
303
if(newconntype == ctValue)
305
string type = port->PortDesc.type().dataType;
311
b.writeFloat(newvalue.toFloat());
312
else if(type == "long")
313
b.writeLong(newvalue.toLong());
314
else if(type == "string")
315
b.writeString(newvalue.ascii());
316
else if(type == "boolean")
318
b.writeBool(newvalue.upper() == "TRUE" || newvalue.upper() == "T"
324
b.read(a.value, b.size());
325
port->PortDesc.value(a);
329
if(newconntype == ctNone)
330
port->PortDesc.hasValue(false);
332
#include "portpropdlg.moc"