comparison widgets/PropertyBox.cpp @ 34:c43f2c4f66f2

* As previous commit
author Chris Cannam
date Fri, 17 Feb 2006 18:11:08 +0000
parents 651e4e868bcc
children 10ba9276a315
comparison
equal deleted inserted replaced
33:651e4e868bcc 34:c43f2c4f66f2
35 #ifdef DEBUG_PROPERTY_BOX 35 #ifdef DEBUG_PROPERTY_BOX
36 std::cerr << "PropertyBox[" << this << "(\"" << 36 std::cerr << "PropertyBox[" << this << "(\"" <<
37 container->getPropertyContainerName().toStdString() << "\")]::PropertyBox" << std::endl; 37 container->getPropertyContainerName().toStdString() << "\")]::PropertyBox" << std::endl;
38 #endif 38 #endif
39 39
40 QVBoxLayout *vbox = new QVBoxLayout; 40 m_mainBox = new QVBoxLayout;
41 setLayout(vbox); 41 setLayout(m_mainBox);
42 42
43 bool needViewPlayBox = false; 43 bool needViewPlayBox = false;
44 44
45 if (container->getPlayParameters() || dynamic_cast<Layer *>(container)) {
46 needViewPlayBox = true;
47 }
48
49 if (needViewPlayBox) {
50 #ifdef DEBUG_PROPERTY_BOX
51 std::cerr << "Adding view play box" << std::endl;
52 #endif
53 QFrame *frame = new QFrame;
54 frame->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
55 QHBoxLayout *hbox = new QHBoxLayout;
56 frame->setLayout(hbox);
57 vbox->addWidget(frame);
58 populateViewPlayBox(container, hbox);
59 hbox->insertStretch(-1, 10);
60 }
61
62 m_mainWidget = new QWidget; 45 m_mainWidget = new QWidget;
63 vbox->addWidget(m_mainWidget); 46 m_mainBox->addWidget(m_mainWidget);
64 47 m_mainBox->insertStretch(1, 10);
65 vbox->insertStretch(-1, 10); 48
49 m_viewPlayFrame = 0;
50 populateViewPlayFrame();
66 51
67 m_layout = new QGridLayout; 52 m_layout = new QGridLayout;
53 m_layout->setMargin(0);
68 m_mainWidget->setLayout(m_layout); 54 m_mainWidget->setLayout(m_layout);
69 55
70 PropertyContainer::PropertyList properties = container->getProperties(); 56 PropertyContainer::PropertyList properties = m_container->getProperties();
71 57
72 blockSignals(true); 58 blockSignals(true);
73 59
74 size_t i; 60 size_t i;
75 61
92 std::cerr << "PropertyBox[" << this << "]::~PropertyBox" << std::endl; 78 std::cerr << "PropertyBox[" << this << "]::~PropertyBox" << std::endl;
93 #endif 79 #endif
94 } 80 }
95 81
96 void 82 void
97 PropertyBox::populateViewPlayBox(PropertyContainer *container, QLayout *layout) 83 PropertyBox::populateViewPlayFrame()
98 { 84 {
99 Layer *layer = dynamic_cast<Layer *>(container); 85 std::cerr << "PropertyBox(" << m_container << ")::populateViewPlayFrame" << std::endl;
100 PlayParameters *params = container->getPlayParameters(); 86
87 if (m_viewPlayFrame) {
88 delete m_viewPlayFrame;
89 m_viewPlayFrame = 0;
90 }
91
92 if (!m_container) return;
93
94 Layer *layer = dynamic_cast<Layer *>(m_container);
95 if (layer) {
96 connect(layer, SIGNAL(modelReplaced()),
97 this, SLOT(populateViewPlayFrame()));
98 }
99
100 PlayParameters *params = m_container->getPlayParameters();
101 if (!params && !layer) return; 101 if (!params && !layer) return;
102 102
103 std::cerr << "PropertyBox::populateViewPlayBox: container " << container << " (name " << container->getPropertyContainerName().toStdString() << ") params " << params << std::endl; 103 m_viewPlayFrame = new QFrame;
104 m_viewPlayFrame->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
105 m_mainBox->addWidget(m_viewPlayFrame);
106
107 QHBoxLayout *layout = new QHBoxLayout;
108 m_viewPlayFrame->setLayout(layout);
109
110 layout->setMargin(layout->margin() / 2);
111
112 std::cerr << "PropertyBox::populateViewPlayFrame: container " << m_container << " (name " << m_container->getPropertyContainerName().toStdString() << ") params " << params << std::endl;
104 113
105 if (layer) { 114 if (layer) {
115 QLabel *showLabel = new QLabel(tr("Show"));
116 layout->addWidget(showLabel);
117 layout->setAlignment(showLabel, Qt::AlignVCenter);
118
106 LEDButton *showButton = new LEDButton(Qt::blue); 119 LEDButton *showButton = new LEDButton(Qt::blue);
107 layout->addWidget(showButton); 120 layout->addWidget(showButton);
108 connect(showButton, SIGNAL(stateChanged(bool)), 121 connect(showButton, SIGNAL(stateChanged(bool)),
109 layer, SLOT(showLayer(bool))); 122 layer, SLOT(showLayer(bool)));
123 layout->setAlignment(showButton, Qt::AlignVCenter);
110 } 124 }
111 125
112 if (params) { 126 if (params) {
127
128 QLabel *playLabel = new QLabel(tr("Play"));
129 layout->addWidget(playLabel);
130 layout->setAlignment(playLabel, Qt::AlignVCenter);
131
113 LEDButton *playButton = new LEDButton(Qt::darkGreen); 132 LEDButton *playButton = new LEDButton(Qt::darkGreen);
114 layout->addWidget(playButton); 133 layout->addWidget(playButton);
115 connect(playButton, SIGNAL(stateChanged(bool)), 134 connect(playButton, SIGNAL(stateChanged(bool)),
116 params, SLOT(setPlayAudible(bool))); 135 params, SLOT(setPlayAudible(bool)));
136 connect(params, SIGNAL(playAudibleChanged(bool)),
137 playButton, SLOT(setState(bool)));
138 layout->setAlignment(playButton, Qt::AlignVCenter);
139
140 layout->insertStretch(-1, 10);
141
142 AudioDial *gainDial = new AudioDial;
143 layout->addWidget(gainDial);
144 gainDial->setMeterColor(Qt::darkRed);
145 gainDial->setMinimum(-50);
146 gainDial->setMaximum(50);
147 gainDial->setPageStep(1);
148 gainDial->setFixedWidth(24);
149 gainDial->setFixedHeight(24);
150 gainDial->setNotchesVisible(false);
151 gainDial->setToolTip(tr("Layer playback level"));
152 gainDial->setDefaultValue(0);
153 connect(gainDial, SIGNAL(valueChanged(int)),
154 this, SLOT(playGainDialChanged(int)));
155 connect(params, SIGNAL(playGainChanged(float)),
156 this, SLOT(playGainChanged(float)));
157 connect(this, SIGNAL(changePlayGain(float)),
158 params, SLOT(setPlayGain(float)));
159 connect(this, SIGNAL(changePlayGainDial(int)),
160 gainDial, SLOT(setValue(int)));
161 layout->setAlignment(gainDial, Qt::AlignVCenter);
162
163 AudioDial *panDial = new AudioDial;
164 layout->addWidget(panDial);
165 panDial->setMeterColor(Qt::darkGreen);
166 panDial->setMinimum(-50);
167 panDial->setMaximum(50);
168 panDial->setPageStep(1);
169 panDial->setFixedWidth(24);
170 panDial->setFixedHeight(24);
171 panDial->setNotchesVisible(false);
172 panDial->setToolTip(tr("Layer playback pan"));
173 panDial->setDefaultValue(0);
174 connect(panDial, SIGNAL(valueChanged(int)),
175 this, SLOT(playPanDialChanged(int)));
176 connect(params, SIGNAL(playPanChanged(float)),
177 this, SLOT(playPanChanged(float)));
178 connect(this, SIGNAL(changePlayPan(float)),
179 params, SLOT(setPlayPan(float)));
180 connect(this, SIGNAL(changePlayPanDial(int)),
181 panDial, SLOT(setValue(int)));
182 layout->setAlignment(panDial, Qt::AlignVCenter);
183
184 } else {
185
186 layout->insertStretch(-1, 10);
117 } 187 }
118 } 188 }
119 189
120 void 190 void
121 PropertyBox::updatePropertyEditor(PropertyContainer::PropertyName name) 191 PropertyBox::updatePropertyEditor(PropertyContainer::PropertyName name)
207 dial = new AudioDial(); 277 dial = new AudioDial();
208 dial->setObjectName(name); 278 dial->setObjectName(name);
209 dial->setMinimum(min); 279 dial->setMinimum(min);
210 dial->setMaximum(max); 280 dial->setMaximum(max);
211 dial->setPageStep(1); 281 dial->setPageStep(1);
212 dial->setNotchesVisible(true); 282 dial->setNotchesVisible((max - min) <= 12);
283 dial->setDefaultValue(value);
213 connect(dial, SIGNAL(valueChanged(int)), 284 connect(dial, SIGNAL(valueChanged(int)),
214 this, SLOT(propertyControllerChanged(int))); 285 this, SLOT(propertyControllerChanged(int)));
215 286
216 if (inGroup) { 287 if (inGroup) {
217 dial->setFixedWidth(24); 288 dial->setFixedWidth(24);
300 PropertyBox::propertyControllerChanged(int value) 371 PropertyBox::propertyControllerChanged(int value)
301 { 372 {
302 QObject *obj = sender(); 373 QObject *obj = sender();
303 QString name = obj->objectName(); 374 QString name = obj->objectName();
304 375
376 #ifdef DEBUG_PROPERTY_BOX
305 std::cerr << "PropertyBox::propertyControllerChanged(" << name.toStdString() 377 std::cerr << "PropertyBox::propertyControllerChanged(" << name.toStdString()
306 << ", " << value << ")" << std::endl; 378 << ", " << value << ")" << std::endl;
379 #endif
307 380
308 PropertyContainer::PropertyType type = m_container->getPropertyType(name); 381 PropertyContainer::PropertyType type = m_container->getPropertyType(name);
309 382
310 if (type != PropertyContainer::InvalidProperty) { 383 if (type != PropertyContainer::InvalidProperty) {
311 m_container->setProperty(name, value); 384 m_container->setProperty(name, value);
318 //!!! unfortunately this doesn't update an already-visible tooltip 391 //!!! unfortunately this doesn't update an already-visible tooltip
319 } 392 }
320 } 393 }
321 } 394 }
322 395
323 396 void
397 PropertyBox::playGainChanged(float gain)
398 {
399 int dialValue = lrint(log10(gain) * 20.0);
400 if (dialValue < -50) dialValue = -50;
401 if (dialValue > 50) dialValue = 50;
402 emit changePlayGainDial(dialValue);
403 }
404
405 void
406 PropertyBox::playGainDialChanged(int dialValue)
407 {
408 float gain = pow(10, float(dialValue) / 20.0);
409 emit changePlayGain(gain);
410 }
411
412 void
413 PropertyBox::playPanChanged(float pan)
414 {
415 int dialValue = lrint(pan * 50.0);
416 if (dialValue < -50) dialValue = -50;
417 if (dialValue > 50) dialValue = 50;
418 emit changePlayPanDial(dialValue);
419 }
420
421 void
422 PropertyBox::playPanDialChanged(int dialValue)
423 {
424 float pan = float(dialValue) / 50.0;
425 if (pan < -1.0) pan = -1.0;
426 if (pan > 1.0) pan = 1.0;
427 emit changePlayPan(pan);
428 }
324 429
325 #ifdef INCLUDE_MOCFILES 430 #ifdef INCLUDE_MOCFILES
326 #include "PropertyBox.moc.cpp" 431 #include "PropertyBox.moc.cpp"
327 #endif 432 #endif
328 433