annotate widgets/PropertyBox.cpp @ 1197:ff77b7707c95 levelpanwidget

Take advantage of the fact that a group layout is now always used, to simplify code
author Chris Cannam
date Fri, 16 Dec 2016 13:10:21 +0000
parents b1e3ee5f1be6
children 69ff93e0c624
rev   line source
Chris@58 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@0 2
Chris@0 3 /*
Chris@59 4 Sonic Visualiser
Chris@59 5 An audio file viewer and annotation editor.
Chris@59 6 Centre for Digital Music, Queen Mary, University of London.
Chris@182 7 This file copyright 2006 Chris Cannam and QMUL.
Chris@0 8
Chris@59 9 This program is free software; you can redistribute it and/or
Chris@59 10 modify it under the terms of the GNU General Public License as
Chris@59 11 published by the Free Software Foundation; either version 2 of the
Chris@59 12 License, or (at your option) any later version. See the file
Chris@59 13 COPYING included with this distribution for more information.
Chris@0 14 */
Chris@0 15
Chris@0 16 #include "PropertyBox.h"
Chris@63 17 #include "PluginParameterDialog.h"
Chris@0 18
Chris@0 19 #include "base/PropertyContainer.h"
Chris@33 20 #include "base/PlayParameters.h"
Chris@377 21 #include "base/PlayParameterRepository.h"
Chris@128 22 #include "layer/Layer.h"
Chris@100 23 #include "base/UnitDatabase.h"
Chris@167 24 #include "base/RangeMapper.h"
Chris@0 25
Chris@0 26 #include "AudioDial.h"
Chris@33 27 #include "LEDButton.h"
Chris@335 28 #include "IconLoader.h"
Chris@1178 29 #include "LevelPanWidget.h"
Chris@1179 30 #include "LevelPanToolButton.h"
Chris@1174 31 #include "WidgetScale.h"
Chris@0 32
Chris@189 33 #include "NotifyingCheckBox.h"
Chris@189 34 #include "NotifyingComboBox.h"
Chris@335 35 #include "NotifyingPushButton.h"
Chris@1189 36 #include "NotifyingToolButton.h"
Chris@1196 37 #include "ColourComboBox.h"
Chris@189 38
Chris@0 39 #include <QGridLayout>
Chris@0 40 #include <QHBoxLayout>
Chris@33 41 #include <QVBoxLayout>
Chris@63 42 #include <QPushButton>
Chris@1189 43 #include <QToolButton>
Chris@0 44 #include <QLabel>
Chris@33 45 #include <QFrame>
Chris@218 46 #include <QApplication>
Chris@285 47 #include <QColorDialog>
Chris@285 48 #include <QInputDialog>
Chris@769 49 #include <QDir>
Chris@0 50
Chris@0 51 #include <cassert>
Chris@0 52 #include <iostream>
Martin@46 53 #include <cmath>
Chris@0 54
Chris@456 55 //#define DEBUG_PROPERTY_BOX 1
Chris@0 56
Chris@0 57 PropertyBox::PropertyBox(PropertyContainer *container) :
Chris@185 58 m_container(container),
Chris@189 59 m_showButton(0),
Chris@189 60 m_playButton(0)
Chris@0 61 {
Chris@0 62 #ifdef DEBUG_PROPERTY_BOX
Chris@682 63 cerr << "PropertyBox[" << this << "(\"" <<
Chris@682 64 container->getPropertyContainerName() << "\" at " << container << ")]::PropertyBox" << endl;
Chris@0 65 #endif
Chris@0 66
Chris@34 67 m_mainBox = new QVBoxLayout;
Chris@34 68 setLayout(m_mainBox);
Chris@33 69
Chris@980 70 #ifdef Q_OS_MAC
Chris@980 71 QMargins mm = m_mainBox->contentsMargins();
Chris@980 72 QMargins mmhalf(mm.left()/2, mm.top()/3, mm.right()/2, mm.bottom()/3);
Chris@980 73 m_mainBox->setContentsMargins(mmhalf);
Chris@980 74 #endif
Chris@980 75
Chris@107 76 // m_nameWidget = new QLabel;
Chris@107 77 // m_mainBox->addWidget(m_nameWidget);
Chris@107 78 // m_nameWidget->setText(container->objectName());
Chris@107 79
Chris@34 80 m_mainWidget = new QWidget;
Chris@34 81 m_mainBox->addWidget(m_mainWidget);
Chris@107 82 m_mainBox->insertStretch(2, 10);
Chris@33 83
Chris@34 84 m_viewPlayFrame = 0;
Chris@34 85 populateViewPlayFrame();
Chris@33 86
Chris@0 87 m_layout = new QGridLayout;
Chris@34 88 m_layout->setMargin(0);
Chris@833 89 m_layout->setHorizontalSpacing(2);
Chris@833 90 m_layout->setVerticalSpacing(1);
Chris@33 91 m_mainWidget->setLayout(m_layout);
Chris@0 92
Chris@34 93 PropertyContainer::PropertyList properties = m_container->getProperties();
Chris@0 94
Chris@0 95 blockSignals(true);
Chris@0 96
Chris@0 97 size_t i;
Chris@0 98
Chris@0 99 for (i = 0; i < properties.size(); ++i) {
Chris@0 100 updatePropertyEditor(properties[i]);
Chris@0 101 }
Chris@0 102
Chris@0 103 blockSignals(false);
Chris@0 104
Chris@0 105 m_layout->setRowStretch(m_layout->rowCount(), 10);
Chris@0 106
Chris@100 107 connect(UnitDatabase::getInstance(), SIGNAL(unitDatabaseChanged()),
Chris@100 108 this, SLOT(unitDatabaseChanged()));
Chris@100 109
Chris@0 110 #ifdef DEBUG_PROPERTY_BOX
Chris@682 111 cerr << "PropertyBox[" << this << "]::PropertyBox returning" << endl;
Chris@0 112 #endif
Chris@0 113 }
Chris@0 114
Chris@0 115 PropertyBox::~PropertyBox()
Chris@0 116 {
Chris@0 117 #ifdef DEBUG_PROPERTY_BOX
Chris@682 118 cerr << "PropertyBox[" << this << "]::~PropertyBox" << endl;
Chris@0 119 #endif
Chris@0 120 }
Chris@0 121
Chris@0 122 void
Chris@34 123 PropertyBox::populateViewPlayFrame()
Chris@33 124 {
Chris@36 125 #ifdef DEBUG_PROPERTY_BOX
Chris@729 126 cerr << "PropertyBox[" << this << ":" << m_container << "]::populateViewPlayFrame" << endl;
Chris@36 127 #endif
Chris@34 128
Chris@34 129 if (m_viewPlayFrame) {
Chris@34 130 delete m_viewPlayFrame;
Chris@34 131 m_viewPlayFrame = 0;
Chris@34 132 }
Chris@34 133
Chris@34 134 if (!m_container) return;
Chris@34 135
Chris@34 136 Layer *layer = dynamic_cast<Layer *>(m_container);
Chris@34 137 if (layer) {
Chris@193 138 disconnect(layer, SIGNAL(modelReplaced()),
Chris@193 139 this, SLOT(populateViewPlayFrame()));
Chris@34 140 connect(layer, SIGNAL(modelReplaced()),
Chris@34 141 this, SLOT(populateViewPlayFrame()));
Chris@34 142 }
Chris@34 143
Chris@34 144 PlayParameters *params = m_container->getPlayParameters();
Chris@33 145 if (!params && !layer) return;
Chris@33 146
Chris@34 147 m_viewPlayFrame = new QFrame;
Chris@34 148 m_viewPlayFrame->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
Chris@34 149 m_mainBox->addWidget(m_viewPlayFrame);
Chris@34 150
Chris@1189 151 QGridLayout *layout = new QGridLayout;
Chris@34 152 m_viewPlayFrame->setLayout(layout);
Chris@34 153
Chris@34 154 layout->setMargin(layout->margin() / 2);
Chris@34 155
Chris@36 156 #ifdef DEBUG_PROPERTY_BOX
Chris@587 157 SVDEBUG << "PropertyBox::populateViewPlayFrame: container " << m_container << " (name " << m_container->getPropertyContainerName() << ") params " << params << endl;
Chris@36 158 #endif
Chris@1189 159
Chris@1189 160 QSize buttonSize = WidgetScale::scaleQSize(QSize(26, 26));
Chris@1189 161 int col = 0;
Chris@1189 162
Chris@33 163 if (params) {
Chris@1189 164
Chris@1189 165 m_playButton = new NotifyingToolButton;
Chris@1187 166 m_playButton->setCheckable(true);
Chris@1187 167 m_playButton->setIcon(IconLoader().load("speaker"));
Chris@1190 168 m_playButton->setToolTip(tr("Click to toggle playback"));
Chris@1187 169 m_playButton->setChecked(!params->isPlayMuted());
Chris@1189 170 m_playButton->setFixedSize(buttonSize);
Chris@1187 171 connect(m_playButton, SIGNAL(toggled(bool)),
Chris@1187 172 this, SLOT(playAudibleButtonChanged(bool)));
Chris@1187 173 connect(m_playButton, SIGNAL(mouseEntered()),
Chris@1187 174 this, SLOT(mouseEnteredWidget()));
Chris@1187 175 connect(m_playButton, SIGNAL(mouseLeft()),
Chris@1187 176 this, SLOT(mouseLeftWidget()));
Chris@1187 177 connect(params, SIGNAL(playAudibleChanged(bool)),
Chris@1187 178 this, SLOT(playAudibleChanged(bool)));
Chris@63 179
Chris@1179 180 LevelPanToolButton *levelPan = new LevelPanToolButton;
Chris@1189 181 levelPan->setFixedSize(buttonSize);
Chris@1189 182 levelPan->setImageSize((buttonSize.height() * 3) / 4);
Chris@1189 183 layout->addWidget(levelPan, 0, col++, Qt::AlignCenter);
Chris@1178 184 connect(levelPan, SIGNAL(levelChanged(float)),
Chris@1178 185 this, SLOT(playGainControlChanged(float)));
Chris@1178 186 connect(levelPan, SIGNAL(panChanged(float)),
Chris@1178 187 this, SLOT(playPanControlChanged(float)));
Chris@1178 188 connect(params, SIGNAL(playGainChanged(float)),
Chris@1178 189 levelPan, SLOT(setLevel(float)));
Chris@1178 190 connect(params, SIGNAL(playPanChanged(float)),
Chris@1178 191 levelPan, SLOT(setPan(float)));
Chris@1180 192 connect(levelPan, SIGNAL(mouseEntered()),
Chris@1180 193 this, SLOT(mouseEnteredWidget()));
Chris@1180 194 connect(levelPan, SIGNAL(mouseLeft()),
Chris@1180 195 this, SLOT(mouseLeftWidget()));
Chris@1180 196
Chris@1189 197 layout->addWidget(m_playButton, 0, col++, Qt::AlignCenter);
Chris@1189 198
Chris@1187 199 if (params->getPlayClipId() != "") {
Chris@1189 200 QToolButton *playParamButton = new QToolButton;
Chris@1187 201 playParamButton->setObjectName("playParamButton");
Chris@1187 202 playParamButton->setIcon(IconLoader().load("faders"));
Chris@1189 203 playParamButton->setFixedSize(buttonSize);
Chris@1189 204 layout->addWidget(playParamButton, 0, col++, Qt::AlignCenter);
Chris@1187 205 connect(playParamButton, SIGNAL(clicked()),
Chris@1187 206 this, SLOT(editPlayParameters()));
Chris@1187 207 connect(playParamButton, SIGNAL(mouseEntered()),
Chris@1187 208 this, SLOT(mouseEnteredWidget()));
Chris@1187 209 connect(playParamButton, SIGNAL(mouseLeft()),
Chris@1187 210 this, SLOT(mouseLeftWidget()));
Chris@1187 211 }
Chris@1187 212 }
Chris@1187 213
Chris@1189 214 layout->setColumnStretch(col++, 10);
Chris@1187 215
Chris@1187 216 if (layer) {
Chris@1187 217
Chris@1187 218 QLabel *showLabel = new QLabel(tr("Show"));
Chris@1189 219 layout->addWidget(showLabel, 0, col++, Qt::AlignVCenter | Qt::AlignRight);
Chris@1187 220
Chris@1187 221 m_showButton = new LEDButton(Qt::blue);
Chris@1189 222 layout->addWidget(m_showButton, 0, col++, Qt::AlignVCenter | Qt::AlignLeft);
Chris@1187 223 connect(m_showButton, SIGNAL(stateChanged(bool)),
Chris@1187 224 this, SIGNAL(showLayer(bool)));
Chris@1187 225 connect(m_showButton, SIGNAL(mouseEntered()),
Chris@1180 226 this, SLOT(mouseEnteredWidget()));
Chris@1187 227 connect(m_showButton, SIGNAL(mouseLeft()),
Chris@1180 228 this, SLOT(mouseLeftWidget()));
Chris@33 229 }
Chris@33 230 }
Chris@33 231
Chris@33 232 void
Chris@197 233 PropertyBox::updatePropertyEditor(PropertyContainer::PropertyName name,
Chris@197 234 bool rangeChanged)
Chris@0 235 {
Chris@0 236 PropertyContainer::PropertyType type = m_container->getPropertyType(name);
Chris@0 237 int row = m_layout->rowCount();
Chris@0 238
Chris@216 239 int min = 0, max = 0, value = 0, deflt = 0;
Chris@216 240 value = m_container->getPropertyRangeAndValue(name, &min, &max, &deflt);
Chris@0 241
Chris@0 242 bool have = (m_propertyControllers.find(name) !=
Chris@0 243 m_propertyControllers.end());
Chris@0 244
Chris@0 245 QString groupName = m_container->getPropertyGroupName(name);
Chris@87 246 QString propertyLabel = m_container->getPropertyLabel(name);
Chris@335 247 QString iconName = m_container->getPropertyIconName(name);
Chris@0 248
Chris@0 249 #ifdef DEBUG_PROPERTY_BOX
Chris@682 250 cerr << "PropertyBox[" << this
Chris@683 251 << "(\"" << m_container->getPropertyContainerName()
Chris@0 252 << "\")]";
Chris@682 253 cerr << "::updatePropertyEditor(\"" << name << "\"):";
Chris@682 254 cerr << " value " << value << ", have " << have << ", group \""
Chris@682 255 << groupName << "\"" << endl;
Chris@0 256 #endif
Chris@0 257
Chris@0 258 if (!have) {
Chris@1190 259
Chris@1190 260 QLabel *labelWidget = 0;
Chris@1190 261
Chris@1197 262 if (groupName != QString()) {
Chris@0 263 if (m_groupLayouts.find(groupName) == m_groupLayouts.end()) {
Chris@1190 264 labelWidget = new QLabel(groupName, m_mainWidget);
Chris@1190 265 }
Chris@1190 266 } else {
Chris@1190 267 groupName = "ungrouped: " + propertyLabel;
Chris@1190 268 if (m_groupLayouts.find(groupName) == m_groupLayouts.end()) {
Chris@1190 269 labelWidget = new QLabel(propertyLabel, m_mainWidget);
Chris@1190 270 }
Chris@1190 271 }
Chris@1190 272
Chris@1190 273 if (labelWidget) {
Chris@1190 274 m_layout->addWidget(labelWidget, row, 0);
Chris@1190 275 QWidget *frame = new QWidget(m_mainWidget);
Chris@1190 276 frame->setMinimumSize(WidgetScale::scaleQSize(QSize(1, 24)));
Chris@1190 277 m_groupLayouts[groupName] = new QGridLayout;
Chris@1195 278 #ifdef Q_OS_MAC
Chris@1195 279 // Seems to be plenty of whitespace already
Chris@1195 280 m_groupLayouts[groupName]->setContentsMargins(0, 0, 0, 0);
Chris@1195 281 #else
Chris@1195 282 // Need a bit of padding on the left
Chris@1195 283 m_groupLayouts[groupName]->setContentsMargins
Chris@1195 284 (WidgetScale::scalePixelSize(10), 0, 0, 0);
Chris@1195 285 #endif
Chris@1190 286 frame->setLayout(m_groupLayouts[groupName]);
Chris@1190 287 m_layout->addWidget(frame, row, 1, 1, 2);
Chris@1190 288 m_layout->setColumnStretch(1, 10);
Chris@1190 289 }
Chris@0 290 }
Chris@0 291
Chris@0 292 switch (type) {
Chris@0 293
Chris@0 294 case PropertyContainer::ToggleProperty:
Chris@0 295 {
Chris@335 296 QAbstractButton *button = 0;
Chris@0 297
Chris@0 298 if (have) {
Chris@1196 299 button = qobject_cast<QAbstractButton *>(m_propertyControllers[name]);
Chris@335 300 assert(button);
Chris@0 301 } else {
Chris@0 302 #ifdef DEBUG_PROPERTY_BOX
Chris@682 303 cerr << "PropertyBox: creating new checkbox" << endl;
Chris@0 304 #endif
Chris@335 305 if (iconName != "") {
Chris@335 306 button = new NotifyingPushButton();
Chris@335 307 button->setCheckable(true);
Chris@335 308 QIcon icon(IconLoader().load(iconName));
Chris@335 309 button->setIcon(icon);
Chris@335 310 button->setObjectName(name);
Chris@1174 311 button->setFixedSize(WidgetScale::scaleQSize(QSize(18, 18)));
Chris@335 312 } else {
Chris@335 313 button = new NotifyingCheckBox();
Chris@335 314 button->setObjectName(name);
Chris@335 315 }
Chris@335 316 connect(button, SIGNAL(toggled(bool)),
Chris@335 317 this, SLOT(propertyControllerChanged(bool)));
Chris@335 318 connect(button, SIGNAL(mouseEntered()),
Chris@189 319 this, SLOT(mouseEnteredWidget()));
Chris@335 320 connect(button, SIGNAL(mouseLeft()),
Chris@189 321 this, SLOT(mouseLeftWidget()));
Chris@1197 322 button->setToolTip(propertyLabel);
Chris@1197 323 m_groupLayouts[groupName]->addWidget
Chris@1197 324 (button, 0, m_groupLayouts[groupName]->columnCount());
Chris@335 325 m_propertyControllers[name] = button;
Chris@0 326 }
Chris@0 327
Chris@335 328 if (button->isChecked() != (value > 0)) {
Chris@335 329 button->blockSignals(true);
Chris@335 330 button->setChecked(value > 0);
Chris@335 331 button->blockSignals(false);
Chris@55 332 }
Chris@0 333 break;
Chris@0 334 }
Chris@0 335
Chris@0 336 case PropertyContainer::RangeProperty:
Chris@0 337 {
Chris@0 338 AudioDial *dial;
Chris@0 339
Chris@0 340 if (have) {
Chris@1196 341 dial = qobject_cast<AudioDial *>(m_propertyControllers[name]);
Chris@0 342 assert(dial);
Chris@197 343 if (rangeChanged) {
Chris@197 344 dial->blockSignals(true);
Chris@197 345 dial->setMinimum(min);
Chris@197 346 dial->setMaximum(max);
Chris@197 347 dial->setRangeMapper(m_container->getNewPropertyRangeMapper(name));
Chris@197 348 dial->blockSignals(false);
Chris@197 349 }
Chris@197 350
Chris@0 351 } else {
Chris@0 352 #ifdef DEBUG_PROPERTY_BOX
Chris@682 353 cerr << "PropertyBox: creating new dial" << endl;
Chris@0 354 #endif
Chris@0 355 dial = new AudioDial();
Chris@0 356 dial->setObjectName(name);
Chris@0 357 dial->setMinimum(min);
Chris@0 358 dial->setMaximum(max);
Chris@0 359 dial->setPageStep(1);
Chris@34 360 dial->setNotchesVisible((max - min) <= 12);
Chris@1126 361 // important to set the range mapper before the default,
Chris@1126 362 // because the range mapper is used to map the default
Chris@1126 363 dial->setRangeMapper(m_container->getNewPropertyRangeMapper(name));
Chris@216 364 dial->setDefaultValue(deflt);
Chris@168 365 dial->setShowToolTip(true);
Chris@0 366 connect(dial, SIGNAL(valueChanged(int)),
Chris@0 367 this, SLOT(propertyControllerChanged(int)));
Chris@189 368 connect(dial, SIGNAL(mouseEntered()),
Chris@189 369 this, SLOT(mouseEnteredWidget()));
Chris@189 370 connect(dial, SIGNAL(mouseLeft()),
Chris@189 371 this, SLOT(mouseLeftWidget()));
Chris@0 372
Chris@1197 373 dial->setFixedWidth(WidgetScale::scalePixelSize(24));
Chris@1197 374 dial->setFixedHeight(WidgetScale::scalePixelSize(24));
Chris@1197 375 m_groupLayouts[groupName]->addWidget
Chris@1197 376 (dial, 0, m_groupLayouts[groupName]->columnCount());
Chris@0 377
Chris@0 378 m_propertyControllers[name] = dial;
Chris@0 379 }
Chris@0 380
Chris@55 381 if (dial->value() != value) {
Chris@55 382 dial->blockSignals(true);
Chris@55 383 dial->setValue(value);
Chris@55 384 dial->blockSignals(false);
Chris@55 385 }
Chris@0 386 break;
Chris@0 387 }
Chris@0 388
Chris@1196 389 case PropertyContainer::ColourProperty:
Chris@1196 390 {
Chris@1196 391 ColourComboBox *cb;
Chris@1196 392
Chris@1196 393 if (have) {
Chris@1196 394 cb = qobject_cast<ColourComboBox *>(m_propertyControllers[name]);
Chris@1196 395 assert(cb);
Chris@1196 396 } else {
Chris@1196 397 #ifdef DEBUG_PROPERTY_BOX
Chris@1196 398 cerr << "PropertyBox: creating new colour combobox" << endl;
Chris@1196 399 #endif
Chris@1196 400 cb = new ColourComboBox(true);
Chris@1196 401 cb->setObjectName(name);
Chris@1196 402
Chris@1196 403 connect(cb, SIGNAL(colourChanged(int)),
Chris@1196 404 this, SLOT(propertyControllerChanged(int)));
Chris@1196 405 connect(cb, SIGNAL(mouseEntered()),
Chris@1196 406 this, SLOT(mouseEnteredWidget()));
Chris@1196 407 connect(cb, SIGNAL(mouseLeft()),
Chris@1196 408 this, SLOT(mouseLeftWidget()));
Chris@1196 409
Chris@1197 410 cb->setToolTip(propertyLabel);
Chris@1197 411 m_groupLayouts[groupName]->addWidget
Chris@1197 412 (cb, 0, m_groupLayouts[groupName]->columnCount());
Chris@1196 413 m_propertyControllers[name] = cb;
Chris@1196 414 }
Chris@1196 415
Chris@1196 416 if (cb->currentIndex() != value) {
Chris@1196 417 cb->blockSignals(true);
Chris@1196 418 cb->setCurrentIndex(value);
Chris@1196 419 cb->blockSignals(false);
Chris@1196 420 }
Chris@1196 421
Chris@1196 422 #ifdef Q_OS_MAC
Chris@1196 423 // Crashes on startup without this, for some reason; also
Chris@1196 424 // prevents combo boxes from getting weirdly squished
Chris@1196 425 // vertically
Chris@1196 426 cb->setMinimumSize(QSize(10, cb->font().pixelSize() * 2));
Chris@1196 427 #endif
Chris@1196 428
Chris@1196 429 break;
Chris@1196 430 }
Chris@1196 431
Chris@0 432 case PropertyContainer::ValueProperty:
Chris@100 433 case PropertyContainer::UnitsProperty:
Chris@0 434 {
Chris@189 435 NotifyingComboBox *cb;
Chris@0 436
Chris@0 437 if (have) {
Chris@1196 438 cb = qobject_cast<NotifyingComboBox *>(m_propertyControllers[name]);
Chris@0 439 assert(cb);
Chris@0 440 } else {
Chris@0 441 #ifdef DEBUG_PROPERTY_BOX
Chris@682 442 cerr << "PropertyBox: creating new combobox" << endl;
Chris@0 443 #endif
Chris@0 444
Chris@189 445 cb = new NotifyingComboBox();
Chris@0 446 cb->setObjectName(name);
Chris@100 447 cb->setDuplicatesEnabled(false);
Chris@197 448 }
Chris@100 449
Chris@197 450 if (!have || rangeChanged) {
Chris@285 451
Chris@197 452 cb->blockSignals(true);
Chris@197 453 cb->clear();
Chris@285 454 cb->setEditable(false);
Chris@285 455
Chris@100 456 if (type == PropertyContainer::ValueProperty) {
Chris@285 457
Chris@100 458 for (int i = min; i <= max; ++i) {
Chris@862 459
Chris@862 460 QString label = m_container->getPropertyValueLabel(name, i);
Chris@862 461 QString iname = m_container->getPropertyValueIconName(name, i);
Chris@862 462
Chris@862 463 if (iname != "") {
Chris@862 464 QIcon icon(IconLoader().load(iname));
Chris@862 465 cb->addItem(icon, label);
Chris@862 466 } else {
Chris@862 467 cb->addItem(label);
Chris@862 468 }
Chris@100 469 }
Chris@285 470
Chris@1196 471 } else { // PropertyContainer::UnitsProperty
Chris@285 472
Chris@100 473 QStringList units = UnitDatabase::getInstance()->getKnownUnits();
Chris@100 474 for (int i = 0; i < units.size(); ++i) {
Chris@100 475 cb->addItem(units[i]);
Chris@100 476 }
Chris@285 477
Chris@100 478 cb->setEditable(true);
Chris@280 479 }
Chris@197 480 }
Chris@100 481
Chris@197 482 if (!have) {
Chris@0 483 connect(cb, SIGNAL(activated(int)),
Chris@0 484 this, SLOT(propertyControllerChanged(int)));
Chris@189 485 connect(cb, SIGNAL(mouseEntered()),
Chris@189 486 this, SLOT(mouseEnteredWidget()));
Chris@189 487 connect(cb, SIGNAL(mouseLeft()),
Chris@189 488 this, SLOT(mouseLeftWidget()));
Chris@100 489
Chris@1197 490 cb->setToolTip(propertyLabel);
Chris@1197 491 m_groupLayouts[groupName]->addWidget
Chris@1197 492 (cb, 0, m_groupLayouts[groupName]->columnCount());
Chris@0 493 m_propertyControllers[name] = cb;
Chris@0 494 }
Chris@0 495
Chris@100 496 cb->blockSignals(true);
Chris@1196 497 if (type == PropertyContainer::ValueProperty) {
Chris@100 498 if (cb->currentIndex() != value) {
Chris@100 499 cb->setCurrentIndex(value);
Chris@100 500 }
Chris@100 501 } else {
Chris@100 502 QString unit = UnitDatabase::getInstance()->getUnitById(value);
Chris@100 503 if (cb->currentText() != unit) {
Chris@100 504 for (int i = 0; i < cb->count(); ++i) {
Chris@100 505 if (cb->itemText(i) == unit) {
Chris@100 506 cb->setCurrentIndex(i);
Chris@100 507 break;
Chris@100 508 }
Chris@100 509 }
Chris@100 510 }
Chris@100 511 }
Chris@100 512 cb->blockSignals(false);
Chris@0 513
Chris@681 514 #ifdef Q_OS_MAC
Chris@982 515 // Crashes on startup without this, for some reason; also
Chris@982 516 // prevents combo boxes from getting weirdly squished
Chris@982 517 // vertically
Chris@982 518 cb->setMinimumSize(QSize(10, cb->font().pixelSize() * 2));
Chris@0 519 #endif
Chris@0 520
Chris@0 521 break;
Chris@0 522 }
Chris@0 523
Chris@807 524 case PropertyContainer::InvalidProperty:
Chris@0 525 default:
Chris@0 526 break;
Chris@0 527 }
Chris@0 528 }
Chris@0 529
Chris@0 530 void
Chris@0 531 PropertyBox::propertyContainerPropertyChanged(PropertyContainer *pc)
Chris@0 532 {
Chris@0 533 if (pc != m_container) return;
Chris@0 534
Chris@55 535 #ifdef DEBUG_PROPERTY_BOX
Chris@587 536 SVDEBUG << "PropertyBox::propertyContainerPropertyChanged" << endl;
Chris@55 537 #endif
Chris@55 538
Chris@0 539 PropertyContainer::PropertyList properties = m_container->getProperties();
Chris@0 540 size_t i;
Chris@0 541
Chris@0 542 blockSignals(true);
Chris@0 543
Chris@0 544 for (i = 0; i < properties.size(); ++i) {
Chris@0 545 updatePropertyEditor(properties[i]);
Chris@0 546 }
Chris@0 547
Chris@0 548 blockSignals(false);
Chris@0 549 }
Chris@0 550
Chris@0 551 void
Chris@249 552 PropertyBox::propertyContainerPropertyRangeChanged(PropertyContainer *)
Chris@197 553 {
Chris@197 554 blockSignals(true);
Chris@197 555
Chris@197 556 PropertyContainer::PropertyList properties = m_container->getProperties();
Chris@197 557 for (size_t i = 0; i < properties.size(); ++i) {
Chris@197 558 updatePropertyEditor(properties[i], true);
Chris@197 559 }
Chris@197 560
Chris@197 561 blockSignals(false);
Chris@197 562 }
Chris@197 563
Chris@197 564 void
Chris@100 565 PropertyBox::unitDatabaseChanged()
Chris@100 566 {
Chris@729 567 #ifdef DEBUG_PROPERTY_BOX
Chris@682 568 cerr << "PropertyBox[" << this << "]: unitDatabaseChanged" << endl;
Chris@729 569 #endif
Chris@100 570 blockSignals(true);
Chris@100 571
Chris@682 572 // cerr << "my container is " << m_container << endl;
Chris@682 573 // cerr << "my container's name is... " << endl;
Chris@682 574 // cerr << m_container->objectName() << endl;
Chris@456 575
Chris@100 576 PropertyContainer::PropertyList properties = m_container->getProperties();
Chris@100 577 for (size_t i = 0; i < properties.size(); ++i) {
Chris@285 578 if (m_container->getPropertyType(properties[i]) ==
Chris@285 579 PropertyContainer::UnitsProperty) {
Chris@285 580 updatePropertyEditor(properties[i]);
Chris@285 581 }
Chris@285 582 }
Chris@285 583
Chris@285 584 blockSignals(false);
Chris@285 585 }
Chris@285 586
Chris@285 587 void
Chris@335 588 PropertyBox::propertyControllerChanged(bool on)
Chris@335 589 {
Chris@335 590 propertyControllerChanged(on ? 1 : 0);
Chris@335 591 }
Chris@335 592
Chris@335 593 void
Chris@0 594 PropertyBox::propertyControllerChanged(int value)
Chris@0 595 {
Chris@0 596 QObject *obj = sender();
Chris@0 597 QString name = obj->objectName();
Chris@0 598
Chris@34 599 #ifdef DEBUG_PROPERTY_BOX
Chris@587 600 SVDEBUG << "PropertyBox::propertyControllerChanged(" << name << ", " << value << ")" << endl;
Chris@34 601 #endif
Chris@0 602
Chris@0 603 PropertyContainer::PropertyType type = m_container->getPropertyType(name);
Chris@100 604
Chris@376 605 Command *c = 0;
Chris@376 606
Chris@100 607 if (type == PropertyContainer::UnitsProperty) {
Chris@285 608
Chris@1196 609 NotifyingComboBox *cb = qobject_cast<NotifyingComboBox *>(obj);
Chris@100 610 if (cb) {
Chris@100 611 QString unit = cb->currentText();
Chris@376 612 c = m_container->getSetPropertyCommand
Chris@100 613 (name, UnitDatabase::getInstance()->getUnitId(unit));
Chris@100 614 }
Chris@285 615
Chris@100 616 } else if (type != PropertyContainer::InvalidProperty) {
Chris@285 617
Chris@376 618 c = m_container->getSetPropertyCommand(name, value);
Chris@0 619 }
Chris@376 620
Chris@376 621 if (c) CommandHistory::getInstance()->addCommand(c, true, true);
Chris@218 622
Chris@218 623 updateContextHelp(obj);
Chris@0 624 }
Chris@285 625
Chris@285 626 void
Chris@377 627 PropertyBox::playAudibleChanged(bool audible)
Chris@377 628 {
Chris@1180 629 m_playButton->setChecked(audible);
Chris@377 630 }
Chris@377 631
Chris@377 632 void
Chris@377 633 PropertyBox::playAudibleButtonChanged(bool audible)
Chris@377 634 {
Chris@377 635 PlayParameters *params = m_container->getPlayParameters();
Chris@377 636 if (!params) return;
Chris@377 637
Chris@377 638 if (params->isPlayAudible() != audible) {
Chris@377 639 PlayParameterRepository::EditCommand *command =
Chris@377 640 new PlayParameterRepository::EditCommand(params);
Chris@377 641 command->setPlayAudible(audible);
Chris@377 642 CommandHistory::getInstance()->addCommand(command, true, true);
Chris@377 643 }
Chris@377 644 }
Chris@34 645
Chris@34 646 void
Chris@1178 647 PropertyBox::playGainControlChanged(float gain)
Chris@34 648 {
Chris@218 649 QObject *obj = sender();
Chris@377 650
Chris@377 651 PlayParameters *params = m_container->getPlayParameters();
Chris@377 652 if (!params) return;
Chris@377 653
Chris@377 654 if (params->getPlayGain() != gain) {
Chris@377 655 PlayParameterRepository::EditCommand *command =
Chris@377 656 new PlayParameterRepository::EditCommand(params);
Chris@377 657 command->setPlayGain(gain);
Chris@377 658 CommandHistory::getInstance()->addCommand(command, true, true);
Chris@377 659 }
Chris@377 660
Chris@218 661 updateContextHelp(obj);
Chris@34 662 }
Chris@34 663
Chris@34 664 void
Chris@1178 665 PropertyBox::playPanControlChanged(float pan)
Chris@34 666 {
Chris@218 667 QObject *obj = sender();
Chris@377 668
Chris@377 669 PlayParameters *params = m_container->getPlayParameters();
Chris@377 670 if (!params) return;
Chris@377 671
Chris@377 672 if (params->getPlayPan() != pan) {
Chris@377 673 PlayParameterRepository::EditCommand *command =
Chris@377 674 new PlayParameterRepository::EditCommand(params);
Chris@377 675 command->setPlayPan(pan);
Chris@377 676 CommandHistory::getInstance()->addCommand(command, true, true);
Chris@377 677 }
Chris@377 678
Chris@218 679 updateContextHelp(obj);
Chris@34 680 }
Chris@769 681
Chris@63 682 void
Chris@769 683 PropertyBox::editPlayParameters()
Chris@63 684 {
Chris@63 685 PlayParameters *params = m_container->getPlayParameters();
Chris@63 686 if (!params) return;
Chris@63 687
Chris@769 688 QString clip = params->getPlayClipId();
Chris@377 689
Chris@377 690 PlayParameterRepository::EditCommand *command =
Chris@377 691 new PlayParameterRepository::EditCommand(params);
Chris@63 692
Chris@769 693 QInputDialog *dialog = new QInputDialog(this);
Chris@63 694
Chris@769 695 QDir dir(":/samples");
Chris@769 696 QStringList clipFiles = dir.entryList(QStringList() << "*.wav", QDir::Files);
Chris@63 697
Chris@769 698 QStringList clips;
Chris@769 699 foreach (QString str, clipFiles) {
Chris@769 700 clips.push_back(str.replace(".wav", ""));
Chris@769 701 }
Chris@769 702 dialog->setComboBoxItems(clips);
Chris@63 703
Chris@769 704 dialog->setLabelText(tr("Set playback clip:"));
Chris@769 705
Chris@769 706 QComboBox *cb = dialog->findChild<QComboBox *>();
Chris@779 707 if (cb) {
Chris@779 708 for (int i = 0; i < cb->count(); ++i) {
Chris@779 709 if (cb->itemText(i) == clip) {
Chris@779 710 cb->setCurrentIndex(i);
Chris@779 711 }
Chris@779 712 }
Chris@779 713 }
Chris@769 714
Chris@769 715 connect(dialog, SIGNAL(textValueChanged(QString)),
Chris@769 716 this, SLOT(playClipChanged(QString)));
Chris@64 717
Chris@63 718 if (dialog->exec() == QDialog::Accepted) {
Chris@769 719 QString newClip = dialog->textValue();
Chris@769 720 command->setPlayClipId(newClip);
Chris@377 721 CommandHistory::getInstance()->addCommand(command, true);
Chris@64 722 } else {
Chris@377 723 delete command;
Chris@64 724 // restore in case we mucked about with the configuration
Chris@64 725 // as a consequence of signals from the dialog
Chris@769 726 params->setPlayClipId(clip);
Chris@63 727 }
Chris@63 728
Chris@63 729 delete dialog;
Chris@63 730 }
Chris@63 731
Chris@64 732 void
Chris@769 733 PropertyBox::playClipChanged(QString id)
Chris@64 734 {
Chris@64 735 PlayParameters *params = m_container->getPlayParameters();
Chris@64 736 if (!params) return;
Chris@64 737
Chris@769 738 params->setPlayClipId(id);
Chris@64 739 }
Chris@769 740
Chris@185 741 void
Chris@185 742 PropertyBox::layerVisibilityChanged(bool visible)
Chris@185 743 {
Chris@185 744 if (m_showButton) m_showButton->setState(visible);
Chris@185 745 }
Chris@189 746
Chris@189 747 void
Chris@189 748 PropertyBox::mouseEnteredWidget()
Chris@189 749 {
Chris@218 750 updateContextHelp(sender());
Chris@218 751 }
Chris@218 752
Chris@218 753 void
Chris@218 754 PropertyBox::updateContextHelp(QObject *o)
Chris@218 755 {
Chris@1196 756 QWidget *w = qobject_cast<QWidget *>(o);
Chris@189 757 if (!w) return;
Chris@218 758
Chris@189 759 if (!m_container) return;
Chris@190 760 QString cname = m_container->getPropertyContainerName();
Chris@189 761 if (cname == "") return;
Chris@189 762
Chris@1180 763 LevelPanToolButton *lp = qobject_cast<LevelPanToolButton *>(w);
Chris@1180 764 if (lp) {
Chris@1180 765 emit contextHelpChanged(tr("Adjust playback level and pan of %1").arg(cname));
Chris@1180 766 return;
Chris@1180 767 }
Chris@1180 768
Chris@189 769 QString wname = w->objectName();
Chris@189 770
Chris@1180 771 if (wname == "playParamButton") {
Chris@1180 772 PlayParameters *params = m_container->getPlayParameters();
Chris@1180 773 if (params) {
Chris@1180 774 emit contextHelpChanged
Chris@1180 775 (tr("Change sound used for playback (currently \"%1\")")
Chris@1180 776 .arg(params->getPlayClipId()));
Chris@1180 777 return;
Chris@1180 778 }
Chris@1180 779 }
Chris@1180 780
Chris@218 781 QString extraText;
Chris@1180 782
Chris@1180 783 AudioDial *dial = qobject_cast<AudioDial *>(w);
Chris@218 784 if (dial) {
Chris@908 785 double mv = dial->mappedValue();
Chris@218 786 QString unit = "";
Chris@218 787 if (dial->rangeMapper()) unit = dial->rangeMapper()->getUnit();
Chris@218 788 if (unit != "") {
Chris@218 789 extraText = tr(" (current value: %1%2)").arg(mv).arg(unit);
Chris@218 790 } else {
Chris@218 791 extraText = tr(" (current value: %1)").arg(mv);
Chris@218 792 }
Chris@218 793 }
Chris@218 794
Chris@189 795 if (w == m_showButton) {
Chris@190 796 emit contextHelpChanged(tr("Toggle Visibility of %1").arg(cname));
Chris@189 797 } else if (w == m_playButton) {
Chris@190 798 emit contextHelpChanged(tr("Toggle Playback of %1").arg(cname));
Chris@189 799 } else if (wname == "") {
Chris@189 800 return;
Chris@1196 801 } else if (qobject_cast<QAbstractButton *>(w)) {
Chris@190 802 emit contextHelpChanged(tr("Toggle %1 property of %2")
Chris@189 803 .arg(wname).arg(cname));
Chris@189 804 } else {
Chris@218 805 emit contextHelpChanged(tr("Adjust %1 property of %2%3")
Chris@218 806 .arg(wname).arg(cname).arg(extraText));
Chris@189 807 }
Chris@189 808 }
Chris@189 809
Chris@189 810 void
Chris@189 811 PropertyBox::mouseLeftWidget()
Chris@189 812 {
Chris@218 813 if (!(QApplication::mouseButtons() & Qt::LeftButton)) {
Chris@218 814 emit contextHelpChanged("");
Chris@218 815 }
Chris@189 816 }
Chris@189 817
Chris@64 818