1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
|
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
/*
Rosegarden
A MIDI and audio sequencer and musical notation editor.
This program is Copyright 2000-2008
Guillaume Laurent <[email protected]>,
Chris Cannam <[email protected]>,
Richard Bown <[email protected]>
The moral rights of Guillaume Laurent, Chris Cannam, and Richard
Bown to claim authorship of this work have been asserted.
This file Copyright 2006 Martin Shepherd <[email protected]>.
Other copyrights also apply to some parts of this work. Please
see the AUTHORS file and individual file headers for details.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version. See the file
COPYING included with this distribution for more information.
*/
#include "RosegardenParameterArea.h"
#include "RosegardenParameterBox.h"
#include <ktabwidget.h>
#include <tqfont.h>
#include <tqframe.h>
#include <tqpoint.h>
#include <tqscrollview.h>
#include <tqstring.h>
#include <tqvbox.h>
#include <tqlayout.h>
#include <tqvgroupbox.h>
#include <tqwidget.h>
#include <tqwidgetstack.h>
#include <iostream>
#include <set>
namespace Rosegarden
{
RosegardenParameterArea::RosegardenParameterArea(TQWidget *parent,
const char *name, WFlags f)
: TQWidgetStack(parent, name, f),
m_style(RosegardenParameterArea::CLASSIC_STYLE),
m_scrollView(new TQScrollView(this, 0, TQt::WStaticContents)),
m_classic(new TQVBox(m_scrollView->viewport())),
m_tabBox(new KTabWidget(this)),
m_active(0),
m_spacing(0)
{
m_scrollView->addChild(m_classic);
m_scrollView->setHScrollBarMode(TQScrollView::AlwaysOff);
m_scrollView->setVScrollBarMode(TQScrollView::Auto);
m_scrollView->setResizePolicy(TQScrollView::AutoOneFit);
// Install the classic-style VBox widget in the widget-stack.
addWidget(m_scrollView, CLASSIC_STYLE);
// Install the widget that implements the tab-style to the widget-stack.
addWidget(m_tabBox, TAB_BOX_STYLE);
}
void RosegardenParameterArea::addRosegardenParameterBox(
RosegardenParameterBox *b)
{
// Check that the box hasn't been added before.
for (unsigned int i = 0; i < m_parameterBoxes.size(); i++) {
if (m_parameterBoxes[i] == b)
return ;
}
// Append the parameter box to the list to be displayed.
m_parameterBoxes.push_back(b);
m_scrollView->setMinimumWidth(std::max(m_scrollView->minimumWidth(),
b->sizeHint().width()) + 8);
// Create a titled group box for the parameter box, parented by the
// classic layout widget, so that it can be used to provide a title
// and outline, in classic mode. Add this container to an array that
// parallels the above array of parameter boxes.
TQVGroupBox *box = new TQVGroupBox(b->getLongLabel(), m_classic);
box->layout()->setMargin( 4 ); // about half the default value
TQFont f;
f.setBold( true );
box->setFont( f );
m_groupBoxes.push_back(box);
if (m_spacing)
delete m_spacing;
m_spacing = new TQFrame(m_classic);
m_classic->setStretchFactor(m_spacing, 100);
// Add the parameter box to the current container of the displayed
// widgets, unless the current container has been set up yet.
if (m_active)
moveWidget(0, m_active, b);
// Queue a redisplay of the parameter area, to incorporate the new box.
update();
}
void RosegardenParameterArea::setArrangement(Arrangement style)
{
// Lookup the container of the specified style.
TQWidget *container;
switch (style) {
case CLASSIC_STYLE:
container = m_classic;
break;
case TAB_BOX_STYLE:
container = m_tabBox;
break;
default:
std::cerr << "setArrangement() was passed an unknown arrangement style."
<< std::endl;
return ;
}
// Does the current container of the parameter-box widgets differ
// from the one that is associated with the currently configured
// style?
if (container != m_active) {
// Move the parameter boxes from the old container to the new one.
std::vector<RosegardenParameterBox *> sorted;
std::set<RosegardenParameterBox *> unsorted;
for (unsigned int i = 0; i < m_parameterBoxes.size(); i++) {
unsorted.insert(m_parameterBoxes[i]);
}
TQString previous = "";
while (!unsorted.empty()) {
std::set<RosegardenParameterBox *>::iterator i = unsorted.begin();
bool have = false;
while (i != unsorted.end()) {
if ((*i)->getPreviousBox(style) == previous) {
sorted.push_back(*i);
previous = (*i)->getShortLabel();
unsorted.erase(i);
have = true;
break;
}
++i;
}
if (!have) {
while (!unsorted.empty()) {
sorted.push_back(*unsorted.begin());
unsorted.erase(unsorted.begin());
}
break;
}
}
for (std::vector<RosegardenParameterBox *>::iterator i = sorted.begin();
i != sorted.end(); ++i) {
moveWidget(m_active, container, *i);
(*i)->showAdditionalControls(style == TAB_BOX_STYLE);
}
// Switch the widget stack to displaying the new container.
raiseWidget(style);
}
// Record the identity of the active container, and the associated
// arrangement style.
m_active = container;
m_style = style;
}
void RosegardenParameterArea::moveWidget(TQWidget *old_container,
TQWidget *new_container,
RosegardenParameterBox *box)
{
// Remove any state that is associated with the parameter boxes,
// from the active container.
if (old_container == m_classic) {
;
} else if (old_container == m_tabBox) {
m_tabBox->removePage(box);
}
// Reparent the parameter box, and perform any container-specific
// configuration.
if (new_container == m_classic) {
int index = 0;
while (index < m_parameterBoxes.size()) {
if (box == m_parameterBoxes[index])
break;
++index;
}
if (index < m_parameterBoxes.size()) {
box->reparent(m_groupBoxes[index], 0, TQPoint(0, 0), FALSE);
}
} else if (new_container == m_tabBox) {
box->reparent(new_container, 0, TQPoint(0, 0), FALSE);
m_tabBox->insertTab(box, box->getShortLabel());
}
}
}
#include "RosegardenParameterArea.moc"
|