annotate widgets/PropertyBox.cpp @ 1198:69ff93e0c624 levelpanwidget

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