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

« back to all changes in this revision

Viewing changes to arts/builder/portpropdlg.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) 1998-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 "portpropdlg.h"
 
23
#include "portablekde.h"
 
24
 
 
25
#include <qlayout.h>
 
26
#include <qlabel.h>
 
27
#include <kbuttonbox.h>
 
28
#include <kseparator.h>
 
29
#include <qbttngrp.h>
 
30
#include <qradiobt.h>
 
31
#include <kapp.h>
 
32
#include <qlined.h>
 
33
#include <stdio.h>
 
34
#include <algorithm>
 
35
#include <ctype.h> 
 
36
 
 
37
using namespace std;
 
38
 
 
39
static void min_size(QWidget *w) {
 
40
  w->setMinimumSize(w->sizeHint());
 
41
 
42
 
 
43
PortPropDlg::PortPropDlg(QWidget *parent, ModulePort *port) :QDialog(parent,"Props", TRUE)
 
44
{
 
45
        this->port = port;
 
46
 
 
47
        newconntype = ctNone;
 
48
 
 
49
        if(port->PortDesc.isConnected())
 
50
                newconntype = ctConnection;
 
51
 
 
52
        if(port->PortDesc.hasValue())
 
53
                newconntype = ctValue;
 
54
        
 
55
        newvalue = "";
 
56
 
 
57
        setCaption(i18n("Arts port properties"));
 
58
 
 
59
        QVBoxLayout *mainlayout = new QVBoxLayout(this);
 
60
        QHBoxLayout *contentslayout = new QHBoxLayout;
 
61
 
 
62
// object type
 
63
 
 
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);
 
73
 
 
74
// port description
 
75
 
 
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);
 
81
        min_size(portlabel);
 
82
        portlabel->setAlignment(AlignCenter);
 
83
        mainlayout->addWidget(portlabel);
 
84
 
 
85
        int labelwidth = max(portlabel->sizeHint().width(),objectlabel->sizeHint().width());
 
86
 
 
87
        portlabel->setMinimumWidth(labelwidth);
 
88
        objectlabel->setMinimumWidth(labelwidth);
 
89
 
 
90
// hruler
 
91
 
 
92
        mainlayout->addSpacing(5);
 
93
        KSeparator *ruler = new KSeparator( KSeparator::HLine, this);
 
94
        mainlayout->addWidget(ruler);
 
95
 
 
96
        mainlayout->addSpacing(5);
 
97
        mainlayout->addLayout(contentslayout);
 
98
 
 
99
// icon
 
100
 
 
101
        contentslayout->addSpacing(5);
 
102
        if(port->owner->pixmap())
 
103
        {
 
104
                QLabel *iconlabel = new QLabel(this);
 
105
 
 
106
                iconlabel->setPixmap(*port->owner->pixmap());
 
107
                min_size(iconlabel);
 
108
                contentslayout->addWidget(iconlabel);
 
109
        }
 
110
        QVBoxLayout *connlayout = new QVBoxLayout;
 
111
        contentslayout->addSpacing(5);
 
112
        contentslayout->addLayout(connlayout);
 
113
        contentslayout->addSpacing(5);
 
114
 
 
115
// radio group
 
116
 
 
117
        QButtonGroup *rb_group = new QButtonGroup(this);
 
118
        rb_group->hide();
 
119
 
 
120
        rb_noconn = new QRadioButton(i18n("not connected"), this);
 
121
        rb_group->insert(rb_noconn);
 
122
        min_size(rb_noconn);
 
123
        connlayout->addWidget(rb_noconn);
 
124
        connect( rb_noconn, SIGNAL( clicked() ), SLOT(conn_none() ) );
 
125
 
 
126
        rb_connto = new QRadioButton(i18n("connection"), this);
 
127
        rb_group->insert(rb_connto);
 
128
        min_size(rb_connto);
 
129
        connlayout->addWidget(rb_connto);
 
130
        connect( rb_connto, SIGNAL( clicked() ), SLOT(conn_to() ) );
 
131
 
 
132
        rb_const = new QRadioButton(i18n("constant value"), this);
 
133
        rb_group->insert(rb_const);
 
134
        min_size(rb_const);
 
135
        connlayout->addWidget(rb_const);
 
136
        connect( rb_const, SIGNAL( clicked() ), SLOT(conn_value() ) );
 
137
 
 
138
        QHBoxLayout *valuelayout = new QHBoxLayout;
 
139
        connlayout->addLayout(valuelayout);
 
140
        
 
141
        valuelabel = new QLabel("value:", this);
 
142
        valuelayout->addSpacing(20);
 
143
        min_size(valuelabel);
 
144
        valuelayout->addWidget(valuelabel);     
 
145
 
 
146
        valuelayout->addSpacing(5);
 
147
 
 
148
        valueedit = new QLineEdit(this);
 
149
 
 
150
        if(port->PortDesc.hasValue())
 
151
        {
 
152
                Arts::Any value = port->PortDesc.value();
 
153
                Arts::Buffer b;
 
154
                b.write(value.value);
 
155
 
 
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")
 
161
                {
 
162
                        string s;
 
163
                        b.readString(s);
 
164
                        newvalue = s.c_str();
 
165
                }
 
166
                else if(value.type == "boolean")
 
167
                {
 
168
                        if(b.readBool())
 
169
                                newvalue = "true";
 
170
                        else
 
171
                                newvalue = "false";
 
172
                }
 
173
                else newvalue = ("*unknown type* " + value.type).c_str();
 
174
        }
 
175
        valueedit->setText(newvalue);
 
176
 
 
177
        min_size(valueedit);
 
178
        connect(valueedit, SIGNAL( textChanged(const QString&) ),
 
179
                           SLOT( connvalue_changed(const QString&) ));
 
180
        valuelayout->addWidget(valueedit);
 
181
 
 
182
 
 
183
//---- configurable
 
184
/*
 
185
        rb_conf = new QRadioButton(i18n("configurable"), this);
 
186
        rb_group->insert(rb_conf);
 
187
        min_size(rb_conf);
 
188
        connlayout->addWidget(rb_conf);
 
189
        connect( rb_conf, SIGNAL( clicked() ), SLOT(conn_conf() ) );
 
190
*/
 
191
// hruler
 
192
 
 
193
        valuelayout->addStretch(1);
 
194
        valuelayout->addSpacing(5);
 
195
 
 
196
        mainlayout->addSpacing(5);
 
197
        KSeparator *ruler2 = new KSeparator( KSeparator::HLine, this);
 
198
        mainlayout->addWidget(ruler2);
 
199
 
 
200
// buttons
 
201
 
 
202
        QHBoxLayout *buttonlayout = new QHBoxLayout;
 
203
        mainlayout->addSpacing(5);
 
204
        mainlayout->addLayout(buttonlayout);
 
205
        mainlayout->addSpacing(5);
 
206
 
 
207
        buttonlayout->addSpacing(5);
 
208
        KButtonBox *bbox = new KButtonBox(this);
 
209
 
 
210
        QButton *helpbutton = bbox->addButton(i18n("Help"));
 
211
        connect( helpbutton, SIGNAL( clicked() ), SLOT(showHelp()));
 
212
        bbox->addStretch(1);
 
213
 
 
214
        QButton *okbutton = bbox->addButton(i18n("Okay"));
 
215
        connect( okbutton, SIGNAL( clicked() ), SLOT(apply_changes() ) );
 
216
        connect( okbutton, SIGNAL( clicked() ), SLOT(accept() ) );
 
217
 
 
218
        QButton *cancelbutton = bbox->addButton(i18n("Cancel"));
 
219
        connect( cancelbutton, SIGNAL( clicked() ), SLOT(reject() ) );
 
220
        bbox->layout();
 
221
        //min_size(bbox);
 
222
 
 
223
        buttonlayout->addWidget(bbox);
 
224
        buttonlayout->addSpacing(5);
 
225
 
 
226
        //mainlayout->activate();
 
227
        mainlayout->freeze();
 
228
 
 
229
        updatestatus();
 
230
};
 
231
 
 
232
void PortPropDlg::updatestatus()
 
233
{
 
234
        rb_noconn->setChecked(newconntype == ctNone);
 
235
 
 
236
        valuelabel->setEnabled(newconntype == ctValue);
 
237
        valueedit->setEnabled(newconntype == ctValue);
 
238
        rb_const->setChecked(newconntype == ctValue);
 
239
 
 
240
        rb_connto->setChecked(newconntype == ctConnection);
 
241
}
 
242
 
 
243
void PortPropDlg::conn_value()
 
244
{
 
245
        newconntype = ctValue;
 
246
        if(port->PortDesc.type().direction == Arts::output)
 
247
                newconntype = ctNone;   // yes, confusing, should be done better
 
248
        updatestatus();
 
249
}
 
250
 
 
251
void PortPropDlg::conn_to()
 
252
{
 
253
        if(!port->PortDesc.isConnected())               // no connection there?
 
254
                newconntype = ctNone;
 
255
        else
 
256
                newconntype = ctConnection;
 
257
        updatestatus();
 
258
}
 
259
 
 
260
void PortPropDlg::conn_conf()
 
261
{
 
262
        newconntype = ctNone;   // no conf supported
 
263
        updatestatus();
 
264
}
 
265
 
 
266
void PortPropDlg::conn_none()
 
267
{
 
268
        newconntype = ctNone;
 
269
        updatestatus();
 
270
}
 
271
 
 
272
void PortPropDlg::connvalue_changed(const QString& _newvalue)
 
273
{
 
274
        newvalue = _newvalue;
 
275
}
 
276
 
 
277
void PortPropDlg::showHelp()
 
278
{
 
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-";
 
283
 
 
284
        string::iterator si = s.begin();
 
285
        if(strncmp(s.c_str(),"Arts::",6) == 0) si += 6;
 
286
 
 
287
        while(si != s.end())
 
288
        {
 
289
                if(*si == '_') anchor += '-'; else anchor += toupper(*si);
 
290
                si++;
 
291
        }
 
292
        kapp->invokeHelp(anchor.c_str());
 
293
}
 
294
 
 
295
void PortPropDlg::apply_changes()
 
296
{
 
297
        if(newconntype != ctConnection)
 
298
        {
 
299
                if(port->PortDesc.isConnected())
 
300
                        port->PortDesc.disconnectAll();
 
301
        }
 
302
 
 
303
        if(newconntype == ctValue)
 
304
        {
 
305
                string type = port->PortDesc.type().dataType;
 
306
 
 
307
                Arts::Any a;
 
308
                a.type = type;
 
309
                Arts::Buffer b;
 
310
                if(type == "float")
 
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")
 
317
                {
 
318
                        b.writeBool(newvalue.upper() == "TRUE" || newvalue.upper() == "T"
 
319
                                          || newvalue == "1");
 
320
                }
 
321
 
 
322
                if(b.size() > 0)
 
323
                {
 
324
                        b.read(a.value, b.size());
 
325
                        port->PortDesc.value(a);
 
326
                }
 
327
        }
 
328
 
 
329
        if(newconntype == ctNone)
 
330
                port->PortDesc.hasValue(false);
 
331
}
 
332
#include "portpropdlg.moc"