annotate widgets/PropertyBox.cpp @ 1196:b1e3ee5f1be6 levelpanwidget

Introduce colour combobox class, to replace ad-hoc code in property box
author Chris Cannam
date Fri, 16 Dec 2016 13:08:33 +0000
parents 51bb2582c2cc
children ff77b7707c95
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 bool inGroup = (groupName != QString());
Chris@0 259
Chris@0 260 if (!have) {
Chris@1190 261
Chris@1190 262 QLabel *labelWidget = 0;
Chris@1190 263
Chris@0 264 if (inGroup) {
Chris@0 265 if (m_groupLayouts.find(groupName) == m_groupLayouts.end()) {
Chris@1190 266 labelWidget = new QLabel(groupName, m_mainWidget);
Chris@1190 267 }
Chris@1190 268 } else {
Chris@1190 269 inGroup = true;
Chris@1190 270 groupName = "ungrouped: " + propertyLabel;
Chris@1190 271 if (m_groupLayouts.find(groupName) == m_groupLayouts.end()) {
Chris@1190 272 labelWidget = new QLabel(propertyLabel, m_mainWidget);
Chris@1190 273 }
Chris@1190 274 }
Chris@1190 275
Chris@1190 276 if (labelWidget) {
Chris@1190 277 m_layout->addWidget(labelWidget, row, 0);
Chris@1190 278 QWidget *frame = new QWidget(m_mainWidget);
Chris@1190 279 frame->setMinimumSize(WidgetScale::scaleQSize(QSize(1, 24)));
Chris@1190 280 m_groupLayouts[groupName] = new QGridLayout;
Chris@1195 281 #ifdef Q_OS_MAC
Chris@1195 282 // Seems to be plenty of whitespace already
Chris@1195 283 m_groupLayouts[groupName]->setContentsMargins(0, 0, 0, 0);
Chris@1195 284 #else
Chris@1195 285 // Need a bit of padding on the left
Chris@1195 286 m_groupLayouts[groupName]->setContentsMargins
Chris@1195 287 (WidgetScale::scalePixelSize(10), 0, 0, 0);
Chris@1195 288 #endif
Chris@1190 289 frame->setLayout(m_groupLayouts[groupName]);
Chris@1190 290 m_layout->addWidget(frame, row, 1, 1, 2);
Chris@1190 291 m_layout->setColumnStretch(1, 10);
Chris@1190 292 }
Chris@0 293 }
Chris@0 294
Chris@0 295 switch (type) {
Chris@0 296
Chris@0 297 case PropertyContainer::ToggleProperty:
Chris@0 298 {
Chris@335 299 QAbstractButton *button = 0;
Chris@0 300
Chris@0 301 if (have) {
Chris@1196 302 button = qobject_cast<QAbstractButton *>(m_propertyControllers[name]);
Chris@335 303 assert(button);
Chris@0 304 } else {
Chris@0 305 #ifdef DEBUG_PROPERTY_BOX
Chris@682 306 cerr << "PropertyBox: creating new checkbox" << endl;
Chris@0 307 #endif
Chris@335 308 if (iconName != "") {
Chris@335 309 button = new NotifyingPushButton();
Chris@335 310 button->setCheckable(true);
Chris@335 311 QIcon icon(IconLoader().load(iconName));
Chris@335 312 button->setIcon(icon);
Chris@335 313 button->setObjectName(name);
Chris@1174 314 button->setFixedSize(WidgetScale::scaleQSize(QSize(18, 18)));
Chris@335 315 } else {
Chris@335 316 button = new NotifyingCheckBox();
Chris@335 317 button->setObjectName(name);
Chris@335 318 }
Chris@335 319 connect(button, SIGNAL(toggled(bool)),
Chris@335 320 this, SLOT(propertyControllerChanged(bool)));
Chris@335 321 connect(button, SIGNAL(mouseEntered()),
Chris@189 322 this, SLOT(mouseEnteredWidget()));
Chris@335 323 connect(button, SIGNAL(mouseLeft()),
Chris@189 324 this, SLOT(mouseLeftWidget()));
Chris@0 325 if (inGroup) {
Chris@335 326 button->setToolTip(propertyLabel);
Chris@493 327 m_groupLayouts[groupName]->addWidget
Chris@493 328 (button, 0, m_groupLayouts[groupName]->columnCount());
Chris@0 329 } else {
Chris@335 330 m_layout->addWidget(button, row, 1, 1, 2);
Chris@0 331 }
Chris@335 332 m_propertyControllers[name] = button;
Chris@0 333 }
Chris@0 334
Chris@335 335 if (button->isChecked() != (value > 0)) {
Chris@335 336 button->blockSignals(true);
Chris@335 337 button->setChecked(value > 0);
Chris@335 338 button->blockSignals(false);
Chris@55 339 }
Chris@0 340 break;
Chris@0 341 }
Chris@0 342
Chris@0 343 case PropertyContainer::RangeProperty:
Chris@0 344 {
Chris@0 345 AudioDial *dial;
Chris@0 346
Chris@0 347 if (have) {
Chris@1196 348 dial = qobject_cast<AudioDial *>(m_propertyControllers[name]);
Chris@0 349 assert(dial);
Chris@197 350 if (rangeChanged) {
Chris@197 351 dial->blockSignals(true);
Chris@197 352 dial->setMinimum(min);
Chris@197 353 dial->setMaximum(max);
Chris@197 354 dial->setRangeMapper(m_container->getNewPropertyRangeMapper(name));
Chris@197 355 dial->blockSignals(false);
Chris@197 356 }
Chris@197 357
Chris@0 358 } else {
Chris@0 359 #ifdef DEBUG_PROPERTY_BOX
Chris@682 360 cerr << "PropertyBox: creating new dial" << endl;
Chris@0 361 #endif
Chris@0 362 dial = new AudioDial();
Chris@0 363 dial->setObjectName(name);
Chris@0 364 dial->setMinimum(min);
Chris@0 365 dial->setMaximum(max);
Chris@0 366 dial->setPageStep(1);
Chris@34 367 dial->setNotchesVisible((max - min) <= 12);
Chris@1126 368 // important to set the range mapper before the default,
Chris@1126 369 // because the range mapper is used to map the default
Chris@1126 370 dial->setRangeMapper(m_container->getNewPropertyRangeMapper(name));
Chris@216 371 dial->setDefaultValue(deflt);
Chris@168 372 dial->setShowToolTip(true);
Chris@0 373 connect(dial, SIGNAL(valueChanged(int)),
Chris@0 374 this, SLOT(propertyControllerChanged(int)));
Chris@189 375 connect(dial, SIGNAL(mouseEntered()),
Chris@189 376 this, SLOT(mouseEnteredWidget()));
Chris@189 377 connect(dial, SIGNAL(mouseLeft()),
Chris@189 378 this, SLOT(mouseLeftWidget()));
Chris@0 379
Chris@0 380 if (inGroup) {
Chris@1174 381 dial->setFixedWidth(WidgetScale::scalePixelSize(24));
Chris@1174 382 dial->setFixedHeight(WidgetScale::scalePixelSize(24));
Chris@493 383 m_groupLayouts[groupName]->addWidget
Chris@493 384 (dial, 0, m_groupLayouts[groupName]->columnCount());
Chris@0 385 } else {
Chris@1174 386 dial->setFixedWidth(WidgetScale::scalePixelSize(32));
Chris@1174 387 dial->setFixedHeight(WidgetScale::scalePixelSize(32));
Chris@0 388 m_layout->addWidget(dial, row, 1);
Chris@33 389 QLabel *label = new QLabel(m_mainWidget);
Chris@0 390 connect(dial, SIGNAL(valueChanged(int)),
Chris@0 391 label, SLOT(setNum(int)));
Chris@0 392 label->setNum(value);
Chris@0 393 m_layout->addWidget(label, row, 2);
Chris@0 394 }
Chris@0 395
Chris@0 396 m_propertyControllers[name] = dial;
Chris@0 397 }
Chris@0 398
Chris@55 399 if (dial->value() != value) {
Chris@55 400 dial->blockSignals(true);
Chris@55 401 dial->setValue(value);
Chris@55 402 dial->blockSignals(false);
Chris@55 403 }
Chris@0 404 break;
Chris@0 405 }
Chris@0 406
Chris@1196 407 case PropertyContainer::ColourProperty:
Chris@1196 408 {
Chris@1196 409 ColourComboBox *cb;
Chris@1196 410
Chris@1196 411 if (have) {
Chris@1196 412 cb = qobject_cast<ColourComboBox *>(m_propertyControllers[name]);
Chris@1196 413 assert(cb);
Chris@1196 414 } else {
Chris@1196 415 #ifdef DEBUG_PROPERTY_BOX
Chris@1196 416 cerr << "PropertyBox: creating new colour combobox" << endl;
Chris@1196 417 #endif
Chris@1196 418 cb = new ColourComboBox(true);
Chris@1196 419 cb->setObjectName(name);
Chris@1196 420
Chris@1196 421 connect(cb, SIGNAL(colourChanged(int)),
Chris@1196 422 this, SLOT(propertyControllerChanged(int)));
Chris@1196 423 connect(cb, SIGNAL(mouseEntered()),
Chris@1196 424 this, SLOT(mouseEnteredWidget()));
Chris@1196 425 connect(cb, SIGNAL(mouseLeft()),
Chris@1196 426 this, SLOT(mouseLeftWidget()));
Chris@1196 427
Chris@1196 428 if (inGroup) {
Chris@1196 429 cb->setToolTip(propertyLabel);
Chris@1196 430 m_groupLayouts[groupName]->addWidget
Chris@1196 431 (cb, 0, m_groupLayouts[groupName]->columnCount());
Chris@1196 432 } else {
Chris@1196 433 m_layout->addWidget(cb, row, 1, 1, 2);
Chris@1196 434 }
Chris@1196 435 m_propertyControllers[name] = cb;
Chris@1196 436 }
Chris@1196 437
Chris@1196 438 if (cb->currentIndex() != value) {
Chris@1196 439 cb->blockSignals(true);
Chris@1196 440 cb->setCurrentIndex(value);
Chris@1196 441 cb->blockSignals(false);
Chris@1196 442 }
Chris@1196 443
Chris@1196 444 #ifdef Q_OS_MAC
Chris@1196 445 // Crashes on startup without this, for some reason; also
Chris@1196 446 // prevents combo boxes from getting weirdly squished
Chris@1196 447 // vertically
Chris@1196 448 cb->setMinimumSize(QSize(10, cb->font().pixelSize() * 2));
Chris@1196 449 #endif
Chris@1196 450
Chris@1196 451 break;
Chris@1196 452 }
Chris@1196 453
Chris@0 454 case PropertyContainer::ValueProperty:
Chris@100 455 case PropertyContainer::UnitsProperty:
Chris@0 456 {
Chris@189 457 NotifyingComboBox *cb;
Chris@0 458
Chris@0 459 if (have) {
Chris@1196 460 cb = qobject_cast<NotifyingComboBox *>(m_propertyControllers[name]);
Chris@0 461 assert(cb);
Chris@0 462 } else {
Chris@0 463 #ifdef DEBUG_PROPERTY_BOX
Chris@682 464 cerr << "PropertyBox: creating new combobox" << endl;
Chris@0 465 #endif
Chris@0 466
Chris@189 467 cb = new NotifyingComboBox();
Chris@0 468 cb->setObjectName(name);
Chris@100 469 cb->setDuplicatesEnabled(false);
Chris@197 470 }
Chris@100 471
Chris@197 472 if (!have || rangeChanged) {
Chris@285 473
Chris@197 474 cb->blockSignals(true);
Chris@197 475 cb->clear();
Chris@285 476 cb->setEditable(false);
Chris@285 477
Chris@100 478 if (type == PropertyContainer::ValueProperty) {
Chris@285 479
Chris@100 480 for (int i = min; i <= max; ++i) {
Chris@862 481
Chris@862 482 QString label = m_container->getPropertyValueLabel(name, i);
Chris@862 483 QString iname = m_container->getPropertyValueIconName(name, i);
Chris@862 484
Chris@862 485 if (iname != "") {
Chris@862 486 QIcon icon(IconLoader().load(iname));
Chris@862 487 cb->addItem(icon, label);
Chris@862 488 } else {
Chris@862 489 cb->addItem(label);
Chris@862 490 }
Chris@100 491 }
Chris@285 492
Chris@1196 493 } else { // PropertyContainer::UnitsProperty
Chris@285 494
Chris@100 495 QStringList units = UnitDatabase::getInstance()->getKnownUnits();
Chris@100 496 for (int i = 0; i < units.size(); ++i) {
Chris@100 497 cb->addItem(units[i]);
Chris@100 498 }
Chris@285 499
Chris@100 500 cb->setEditable(true);
Chris@280 501 }
Chris@197 502 }
Chris@100 503
Chris@197 504 if (!have) {
Chris@0 505 connect(cb, SIGNAL(activated(int)),
Chris@0 506 this, SLOT(propertyControllerChanged(int)));
Chris@189 507 connect(cb, SIGNAL(mouseEntered()),
Chris@189 508 this, SLOT(mouseEnteredWidget()));
Chris@189 509 connect(cb, SIGNAL(mouseLeft()),
Chris@189 510 this, SLOT(mouseLeftWidget()));
Chris@100 511
Chris@0 512 if (inGroup) {
Chris@108 513 cb->setToolTip(propertyLabel);
Chris@493 514 m_groupLayouts[groupName]->addWidget
Chris@493 515 (cb, 0, m_groupLayouts[groupName]->columnCount());
Chris@0 516 } else {
Chris@0 517 m_layout->addWidget(cb, row, 1, 1, 2);
Chris@0 518 }
Chris@0 519 m_propertyControllers[name] = cb;
Chris@0 520 }
Chris@0 521
Chris@100 522 cb->blockSignals(true);
Chris@1196 523 if (type == PropertyContainer::ValueProperty) {
Chris@100 524 if (cb->currentIndex() != value) {
Chris@100 525 cb->setCurrentIndex(value);
Chris@100 526 }
Chris@100 527 } else {
Chris@100 528 QString unit = UnitDatabase::getInstance()->getUnitById(value);
Chris@100 529 if (cb->currentText() != unit) {
Chris@100 530 for (int i = 0; i < cb->count(); ++i) {
Chris@100 531 if (cb->itemText(i) == unit) {
Chris@100 532 cb->setCurrentIndex(i);
Chris@100 533 break;
Chris@100 534 }
Chris@100 535 }
Chris@100 536 }
Chris@100 537 }
Chris@100 538 cb->blockSignals(false);
Chris@0 539
Chris@681 540 #ifdef Q_OS_MAC
Chris@982 541 // Crashes on startup without this, for some reason; also
Chris@982 542 // prevents combo boxes from getting weirdly squished
Chris@982 543 // vertically
Chris@982 544 cb->setMinimumSize(QSize(10, cb->font().pixelSize() * 2));
Chris@0 545 #endif
Chris@0 546
Chris@0 547 break;
Chris@0 548 }
Chris@0 549
Chris@807 550 case PropertyContainer::InvalidProperty:
Chris@0 551 default:
Chris@0 552 break;
Chris@0 553 }
Chris@0 554 }
Chris@0 555
Chris@0 556 void
Chris@0 557 PropertyBox::propertyContainerPropertyChanged(PropertyContainer *pc)
Chris@0 558 {
Chris@0 559 if (pc != m_container) return;
Chris@0 560
Chris@55 561 #ifdef DEBUG_PROPERTY_BOX
Chris@587 562 SVDEBUG << "PropertyBox::propertyContainerPropertyChanged" << endl;
Chris@55 563 #endif
Chris@55 564
Chris@0 565 PropertyContainer::PropertyList properties = m_container->getProperties();
Chris@0 566 size_t i;
Chris@0 567
Chris@0 568 blockSignals(true);
Chris@0 569
Chris@0 570 for (i = 0; i < properties.size(); ++i) {
Chris@0 571 updatePropertyEditor(properties[i]);
Chris@0 572 }
Chris@0 573
Chris@0 574 blockSignals(false);
Chris@0 575 }
Chris@0 576
Chris@0 577 void
Chris@249 578 PropertyBox::propertyContainerPropertyRangeChanged(PropertyContainer *)
Chris@197 579 {
Chris@197 580 blockSignals(true);
Chris@197 581
Chris@197 582 PropertyContainer::PropertyList properties = m_container->getProperties();
Chris@197 583 for (size_t i = 0; i < properties.size(); ++i) {
Chris@197 584 updatePropertyEditor(properties[i], true);
Chris@197 585 }
Chris@197 586
Chris@197 587 blockSignals(false);
Chris@197 588 }
Chris@197 589
Chris@197 590 void
Chris@100 591 PropertyBox::unitDatabaseChanged()
Chris@100 592 {
Chris@729 593 #ifdef DEBUG_PROPERTY_BOX
Chris@682 594 cerr << "PropertyBox[" << this << "]: unitDatabaseChanged" << endl;
Chris@729 595 #endif
Chris@100 596 blockSignals(true);
Chris@100 597
Chris@682 598 // cerr << "my container is " << m_container << endl;
Chris@682 599 // cerr << "my container's name is... " << endl;
Chris@682 600 // cerr << m_container->objectName() << endl;
Chris@456 601
Chris@100 602 PropertyContainer::PropertyList properties = m_container->getProperties();
Chris@100 603 for (size_t i = 0; i < properties.size(); ++i) {
Chris@285 604 if (m_container->getPropertyType(properties[i]) ==
Chris@285 605 PropertyContainer::UnitsProperty) {
Chris@285 606 updatePropertyEditor(properties[i]);
Chris@285 607 }
Chris@285 608 }
Chris@285 609
Chris@285 610 blockSignals(false);
Chris@285 611 }
Chris@285 612
Chris@285 613 void
Chris@335 614 PropertyBox::propertyControllerChanged(bool on)
Chris@335 615 {
Chris@335 616 propertyControllerChanged(on ? 1 : 0);
Chris@335 617 }
Chris@335 618
Chris@335 619 void
Chris@0 620 PropertyBox::propertyControllerChanged(int value)
Chris@0 621 {
Chris@0 622 QObject *obj = sender();
Chris@0 623 QString name = obj->objectName();
Chris@0 624
Chris@34 625 #ifdef DEBUG_PROPERTY_BOX
Chris@587 626 SVDEBUG << "PropertyBox::propertyControllerChanged(" << name << ", " << value << ")" << endl;
Chris@34 627 #endif
Chris@0 628
Chris@0 629 PropertyContainer::PropertyType type = m_container->getPropertyType(name);
Chris@100 630
Chris@376 631 Command *c = 0;
Chris@376 632
Chris@100 633 if (type == PropertyContainer::UnitsProperty) {
Chris@285 634
Chris@1196 635 NotifyingComboBox *cb = qobject_cast<NotifyingComboBox *>(obj);
Chris@100 636 if (cb) {
Chris@100 637 QString unit = cb->currentText();
Chris@376 638 c = m_container->getSetPropertyCommand
Chris@100 639 (name, UnitDatabase::getInstance()->getUnitId(unit));
Chris@100 640 }
Chris@285 641
Chris@100 642 } else if (type != PropertyContainer::InvalidProperty) {
Chris@285 643
Chris@376 644 c = m_container->getSetPropertyCommand(name, value);
Chris@0 645 }
Chris@376 646
Chris@376 647 if (c) CommandHistory::getInstance()->addCommand(c, true, true);
Chris@218 648
Chris@218 649 updateContextHelp(obj);
Chris@0 650 }
Chris@285 651
Chris@285 652 void
Chris@377 653 PropertyBox::playAudibleChanged(bool audible)
Chris@377 654 {
Chris@1180 655 m_playButton->setChecked(audible);
Chris@377 656 }
Chris@377 657
Chris@377 658 void
Chris@377 659 PropertyBox::playAudibleButtonChanged(bool audible)
Chris@377 660 {
Chris@377 661 PlayParameters *params = m_container->getPlayParameters();
Chris@377 662 if (!params) return;
Chris@377 663
Chris@377 664 if (params->isPlayAudible() != audible) {
Chris@377 665 PlayParameterRepository::EditCommand *command =
Chris@377 666 new PlayParameterRepository::EditCommand(params);
Chris@377 667 command->setPlayAudible(audible);
Chris@377 668 CommandHistory::getInstance()->addCommand(command, true, true);
Chris@377 669 }
Chris@377 670 }
Chris@34 671
Chris@34 672 void
Chris@1178 673 PropertyBox::playGainControlChanged(float gain)
Chris@34 674 {
Chris@218 675 QObject *obj = sender();
Chris@377 676
Chris@377 677 PlayParameters *params = m_container->getPlayParameters();
Chris@377 678 if (!params) return;
Chris@377 679
Chris@377 680 if (params->getPlayGain() != gain) {
Chris@377 681 PlayParameterRepository::EditCommand *command =
Chris@377 682 new PlayParameterRepository::EditCommand(params);
Chris@377 683 command->setPlayGain(gain);
Chris@377 684 CommandHistory::getInstance()->addCommand(command, true, true);
Chris@377 685 }
Chris@377 686
Chris@218 687 updateContextHelp(obj);
Chris@34 688 }
Chris@34 689
Chris@34 690 void
Chris@1178 691 PropertyBox::playPanControlChanged(float pan)
Chris@34 692 {
Chris@218 693 QObject *obj = sender();
Chris@377 694
Chris@377 695 PlayParameters *params = m_container->getPlayParameters();
Chris@377 696 if (!params) return;
Chris@377 697
Chris@377 698 if (params->getPlayPan() != pan) {
Chris@377 699 PlayParameterRepository::EditCommand *command =
Chris@377 700 new PlayParameterRepository::EditCommand(params);
Chris@377 701 command->setPlayPan(pan);
Chris@377 702 CommandHistory::getInstance()->addCommand(command, true, true);
Chris@377 703 }
Chris@377 704
Chris@218 705 updateContextHelp(obj);
Chris@34 706 }
Chris@769 707
Chris@63 708 void
Chris@769 709 PropertyBox::editPlayParameters()
Chris@63 710 {
Chris@63 711 PlayParameters *params = m_container->getPlayParameters();
Chris@63 712 if (!params) return;
Chris@63 713
Chris@769 714 QString clip = params->getPlayClipId();
Chris@377 715
Chris@377 716 PlayParameterRepository::EditCommand *command =
Chris@377 717 new PlayParameterRepository::EditCommand(params);
Chris@63 718
Chris@769 719 QInputDialog *dialog = new QInputDialog(this);
Chris@63 720
Chris@769 721 QDir dir(":/samples");
Chris@769 722 QStringList clipFiles = dir.entryList(QStringList() << "*.wav", QDir::Files);
Chris@63 723
Chris@769 724 QStringList clips;
Chris@769 725 foreach (QString str, clipFiles) {
Chris@769 726 clips.push_back(str.replace(".wav", ""));
Chris@769 727 }
Chris@769 728 dialog->setComboBoxItems(clips);
Chris@63 729
Chris@769 730 dialog->setLabelText(tr("Set playback clip:"));
Chris@769 731
Chris@769 732 QComboBox *cb = dialog->findChild<QComboBox *>();
Chris@779 733 if (cb) {
Chris@779 734 for (int i = 0; i < cb->count(); ++i) {
Chris@779 735 if (cb->itemText(i) == clip) {
Chris@779 736 cb->setCurrentIndex(i);
Chris@779 737 }
Chris@779 738 }
Chris@779 739 }
Chris@769 740
Chris@769 741 connect(dialog, SIGNAL(textValueChanged(QString)),
Chris@769 742 this, SLOT(playClipChanged(QString)));
Chris@64 743
Chris@63 744 if (dialog->exec() == QDialog::Accepted) {
Chris@769 745 QString newClip = dialog->textValue();
Chris@769 746 command->setPlayClipId(newClip);
Chris@377 747 CommandHistory::getInstance()->addCommand(command, true);
Chris@64 748 } else {
Chris@377 749 delete command;
Chris@64 750 // restore in case we mucked about with the configuration
Chris@64 751 // as a consequence of signals from the dialog
Chris@769 752 params->setPlayClipId(clip);
Chris@63 753 }
Chris@63 754
Chris@63 755 delete dialog;
Chris@63 756 }
Chris@63 757
Chris@64 758 void
Chris@769 759 PropertyBox::playClipChanged(QString id)
Chris@64 760 {
Chris@64 761 PlayParameters *params = m_container->getPlayParameters();
Chris@64 762 if (!params) return;
Chris@64 763
Chris@769 764 params->setPlayClipId(id);
Chris@64 765 }
Chris@769 766
Chris@185 767 void
Chris@185 768 PropertyBox::layerVisibilityChanged(bool visible)
Chris@185 769 {
Chris@185 770 if (m_showButton) m_showButton->setState(visible);
Chris@185 771 }
Chris@189 772
Chris@189 773 void
Chris@189 774 PropertyBox::mouseEnteredWidget()
Chris@189 775 {
Chris@218 776 updateContextHelp(sender());
Chris@218 777 }
Chris@218 778
Chris@218 779 void
Chris@218 780 PropertyBox::updateContextHelp(QObject *o)
Chris@218 781 {
Chris@1196 782 QWidget *w = qobject_cast<QWidget *>(o);
Chris@189 783 if (!w) return;
Chris@218 784
Chris@189 785 if (!m_container) return;
Chris@190 786 QString cname = m_container->getPropertyContainerName();
Chris@189 787 if (cname == "") return;
Chris@189 788
Chris@1180 789 LevelPanToolButton *lp = qobject_cast<LevelPanToolButton *>(w);
Chris@1180 790 if (lp) {
Chris@1180 791 emit contextHelpChanged(tr("Adjust playback level and pan of %1").arg(cname));
Chris@1180 792 return;
Chris@1180 793 }
Chris@1180 794
Chris@189 795 QString wname = w->objectName();
Chris@189 796
Chris@1180 797 if (wname == "playParamButton") {
Chris@1180 798 PlayParameters *params = m_container->getPlayParameters();
Chris@1180 799 if (params) {
Chris@1180 800 emit contextHelpChanged
Chris@1180 801 (tr("Change sound used for playback (currently \"%1\")")
Chris@1180 802 .arg(params->getPlayClipId()));
Chris@1180 803 return;
Chris@1180 804 }
Chris@1180 805 }
Chris@1180 806
Chris@218 807 QString extraText;
Chris@1180 808
Chris@1180 809 AudioDial *dial = qobject_cast<AudioDial *>(w);
Chris@218 810 if (dial) {
Chris@908 811 double mv = dial->mappedValue();
Chris@218 812 QString unit = "";
Chris@218 813 if (dial->rangeMapper()) unit = dial->rangeMapper()->getUnit();
Chris@218 814 if (unit != "") {
Chris@218 815 extraText = tr(" (current value: %1%2)").arg(mv).arg(unit);
Chris@218 816 } else {
Chris@218 817 extraText = tr(" (current value: %1)").arg(mv);
Chris@218 818 }
Chris@218 819 }
Chris@218 820
Chris@189 821 if (w == m_showButton) {
Chris@190 822 emit contextHelpChanged(tr("Toggle Visibility of %1").arg(cname));
Chris@189 823 } else if (w == m_playButton) {
Chris@190 824 emit contextHelpChanged(tr("Toggle Playback of %1").arg(cname));
Chris@189 825 } else if (wname == "") {
Chris@189 826 return;
Chris@1196 827 } else if (qobject_cast<QAbstractButton *>(w)) {
Chris@190 828 emit contextHelpChanged(tr("Toggle %1 property of %2")
Chris@189 829 .arg(wname).arg(cname));
Chris@189 830 } else {
Chris@218 831 emit contextHelpChanged(tr("Adjust %1 property of %2%3")
Chris@218 832 .arg(wname).arg(cname).arg(extraText));
Chris@189 833 }
Chris@189 834 }
Chris@189 835
Chris@189 836 void
Chris@189 837 PropertyBox::mouseLeftWidget()
Chris@189 838 {
Chris@218 839 if (!(QApplication::mouseButtons() & Qt::LeftButton)) {
Chris@218 840 emit contextHelpChanged("");
Chris@218 841 }
Chris@189 842 }
Chris@189 843
Chris@64 844