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

« back to all changes in this revision

Viewing changes to arts/builder/portposdlg.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 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 "portposdlg.h"
 
23
#include "namedlg.h"
 
24
#include "structureport.h"
 
25
#include "portablekde.h"
 
26
#include <qlayout.h>
 
27
#include <qlabel.h>
 
28
#include <qlistbox.h>
 
29
#include <kbuttonbox.h>
 
30
#include <qbttngrp.h>
 
31
#include <qradiobt.h>
 
32
#include <kapp.h>
 
33
#include <kiconloader.h>
 
34
#include <kseparator.h>
 
35
#include <qlined.h>
 
36
#include <stdio.h>
 
37
#include <arts/debug.h>
 
38
 
 
39
using namespace std;
 
40
 
 
41
PortPosDlg::PortPosDlg(QWidget *parent, Structure *structure) :QDialog(parent,"Props", TRUE)
 
42
{
 
43
        this->structure = structure;
 
44
 
 
45
        setCaption(i18n("Arts: Structureport view"));
 
46
 
 
47
        QVBoxLayout *mainlayout = new QVBoxLayout(this);
 
48
        //QHBoxLayout *contentslayout = new QHBoxLayout;
 
49
 
 
50
// object type
 
51
/*
 
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);
 
61
*/
 
62
 
 
63
// port description
 
64
 
 
65
/*
 
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);
 
71
        min_size(portlabel);
 
72
        portlabel->setAlignment(AlignCenter);
 
73
        mainlayout->addWidget(portlabel);
 
74
 
 
75
        int labelwidth = imax(portlabel->sizeHint().width(),objectlabel->sizeHint().width());
 
76
 
 
77
        portlabel->setMinimumWidth(labelwidth);
 
78
        objectlabel->setMinimumWidth(labelwidth);
 
79
 
 
80
// hruler
 
81
 
 
82
        mainlayout->addSpacing(5);
 
83
        KSeparator *ruler = new KSeparator( KSeparator::HLine, this);
 
84
        mainlayout->addWidget(ruler);
 
85
        mainlayout->addSpacing(5);
 
86
        mainlayout->addLayout(contentslayout);
 
87
*/
 
88
// list
 
89
 
 
90
        listbox = new QListBox(this);
 
91
 
 
92
        update();
 
93
 
 
94
        listbox->setMinimumSize(100,200);
 
95
        mainlayout->addWidget(listbox);
 
96
// hruler
 
97
 
 
98
        mainlayout->addSpacing(5);
 
99
        KSeparator *ruler2 = new KSeparator( KSeparator::HLine, this);
 
100
        mainlayout->addWidget(ruler2);
 
101
 
 
102
// buttons
 
103
 
 
104
        QHBoxLayout *buttonlayout = new QHBoxLayout;
 
105
        mainlayout->addSpacing(5);
 
106
        mainlayout->addLayout(buttonlayout);
 
107
        mainlayout->addSpacing(5);
 
108
 
 
109
        buttonlayout->addSpacing(5);
 
110
        KButtonBox *bbox = new KButtonBox(this);
 
111
 
 
112
        bbox->addButton(i18n("Help"));
 
113
        bbox->addStretch(1);
 
114
 
 
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() ));
 
119
 
 
120
        QButton *lower = bbox->addButton(i18n("Lower"));
 
121
        lower->setPixmap(iconloader.loadIcon("down", KIcon::Small));
 
122
        connect( lower, SIGNAL( clicked() ), SLOT( lower() ));
 
123
 
 
124
        QButton *rename = bbox->addButton(i18n("Rename"));
 
125
        connect( rename, SIGNAL( clicked() ), SLOT( rename() ));
 
126
 
 
127
        QButton *okbutton = bbox->addButton(i18n("Okay"));
 
128
        connect( okbutton, SIGNAL( clicked() ), SLOT(accept() ) );
 
129
 
 
130
/*
 
131
        QButton *cancelbutton = bbox->addButton(i18n("Cancel"));
 
132
        connect( cancelbutton, SIGNAL( clicked() ), SLOT(reject() ) );
 
133
*/
 
134
        bbox->layout();
 
135
        //min_size(bbox);
 
136
 
 
137
        buttonlayout->addWidget(bbox);
 
138
        buttonlayout->addSpacing(5);
 
139
 
 
140
        //mainlayout->activate();
 
141
        mainlayout->freeze();
 
142
};
 
143
 
 
144
void PortPosDlg::raise()
 
145
{
 
146
        int i = listbox->currentItem();
 
147
        arts_debug("selected %d",i);
 
148
        if(i < 0) return;
 
149
 
 
150
        StructurePort *port = listports[i];
 
151
        assert(port);
 
152
 
 
153
        // hmm ok this is ugly that the raise function calls lowerPosition
 
154
        port->lowerPosition();
 
155
        update();
 
156
 
 
157
        unsigned long l;
 
158
        for(l=0;l<listports.size();l++)
 
159
                if(listports[l]->id() == port->id())
 
160
                        listbox->setCurrentItem(l);
 
161
}
 
162
 
 
163
void PortPosDlg::lower()
 
164
{
 
165
        int i = listbox->currentItem();
 
166
        arts_debug("selected %d",i);
 
167
        if(i < 0) return;
 
168
        StructurePort *port = listports[i];
 
169
        assert(port);
 
170
 
 
171
        port->raisePosition();
 
172
        update();
 
173
 
 
174
        unsigned long l;
 
175
        for(l=0;l<listports.size();l++)
 
176
                if(listports[l]->id() == port->id())
 
177
                        listbox->setCurrentItem(l);
 
178
}
 
179
 
 
180
void PortPosDlg::rename()
 
181
{
 
182
        int i = listbox->currentItem();
 
183
        arts_debug("selected %d",i);
 
184
        if(i < 0) return;
 
185
        StructurePort *port = listports[i];
 
186
        assert(port);
 
187
 
 
188
        NameDlg *nd = new NameDlg(0,port->name(),i18n("Rename Port"));
 
189
        assert(nd);
 
190
 
 
191
        if(nd->exec())
 
192
        {
 
193
                arts_debug("rename OK...");
 
194
                port->rename(nd->name());
 
195
        }
 
196
        delete nd;
 
197
        update();
 
198
 
 
199
        unsigned long l;
 
200
        for(l=0;l<listports.size();l++)
 
201
                if(listports[l]->id() == port->id())
 
202
                        listbox->setCurrentItem(l);
 
203
}
 
204
void PortPosDlg::update()
 
205
{
 
206
        list<StructureComponent *> &cl = *structure->getComponentList();
 
207
        list<StructureComponent *>::iterator ci;
 
208
 
 
209
        listports.erase(listports.begin(), listports.end());
 
210
        listbox->clear();
 
211
 
 
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++)
 
215
        {
 
216
                map<long, StructurePort *> pmap;
 
217
                int finddirection = ModulePort::in;
 
218
                int pcount = 0;
 
219
 
 
220
                if(direction == 0) finddirection = ModulePort::out;
 
221
 
 
222
                for(ci = cl.begin(); ci != cl.end(); ci++)
 
223
                {
 
224
                        StructureComponent *component = *ci;
 
225
                        if(component->type() == StructureComponent::ctPort)
 
226
                        {
 
227
                                StructurePort *port = (StructurePort *)component;
 
228
                                if(port->port()->direction == finddirection)
 
229
                                {
 
230
                                        arts_debug("port %s position %ld",port->name(),port->position());
 
231
                                        pmap[port->position()] = port;
 
232
                                        pcount++;
 
233
                                }
 
234
                        }
 
235
                }
 
236
                for(int i=0;i<pcount;i++)
 
237
                {
 
238
                        StructurePort *port = pmap[i];
 
239
                        if (port)
 
240
                        {
 
241
                                assert(port);
 
242
                                listbox->insertItem(port->name(),listports.size());
 
243
                                listports.push_back(port);
 
244
                                arts_debug("listports.size() is now %d",listports.size());
 
245
                        }
 
246
                }
 
247
        }
 
248
        listbox->repaint();
 
249
}
 
250
#include "portposdlg.moc"