annotate widgets/PropertyBox.cpp @ 1179:7c31eb5bc77d levelpanwidget

Switch to level-pan tool button in property box
author Chris Cannam
date Tue, 06 Dec 2016 09:20:10 +0000
parents ed99d432dc57
children 6a6a63506e3f
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@376 23 #include "layer/ColourDatabase.h"
Chris@100 24 #include "base/UnitDatabase.h"
Chris@167 25 #include "base/RangeMapper.h"
Chris@0 26
Chris@0 27 #include "AudioDial.h"
Chris@33 28 #include "LEDButton.h"
Chris@335 29 #include "IconLoader.h"
Chris@1178 30 #include "LevelPanWidget.h"
Chris@1179 31 #include "LevelPanToolButton.h"
Chris@1174 32 #include "WidgetScale.h"
Chris@0 33
Chris@189 34 #include "NotifyingCheckBox.h"
Chris@189 35 #include "NotifyingComboBox.h"
Chris@335 36 #include "NotifyingPushButton.h"
Chris@285 37 #include "ColourNameDialog.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@0 43 #include <QLabel>
Chris@33 44 #include <QFrame>
Chris@218 45 #include <QApplication>
Chris@285 46 #include <QColorDialog>
Chris@285 47 #include <QInputDialog>
Chris@769 48 #include <QDir>
Chris@0 49
Chris@0 50 #include <cassert>
Chris@0 51 #include <iostream>
Martin@46 52 #include <cmath>
Chris@0 53
Chris@456 54 //#define DEBUG_PROPERTY_BOX 1
Chris@0 55
Chris@0 56 PropertyBox::PropertyBox(PropertyContainer *container) :
Chris@185 57 m_container(container),
Chris@189 58 m_showButton(0),
Chris@189 59 m_playButton(0)
Chris@0 60 {
Chris@0 61 #ifdef DEBUG_PROPERTY_BOX
Chris@682 62 cerr << "PropertyBox[" << this << "(\"" <<
Chris@682 63 container->getPropertyContainerName() << "\" at " << container << ")]::PropertyBox" << endl;
Chris@0 64 #endif
Chris@0 65
Chris@34 66 m_mainBox = new QVBoxLayout;
Chris@34 67 setLayout(m_mainBox);
Chris@33 68
Chris@980 69 #ifdef Q_OS_MAC
Chris@980 70 QMargins mm = m_mainBox->contentsMargins();
Chris@980 71 QMargins mmhalf(mm.left()/2, mm.top()/3, mm.right()/2, mm.bottom()/3);
Chris@980 72 m_mainBox->setContentsMargins(mmhalf);
Chris@980 73 #endif
Chris@980 74
Chris@107 75 // m_nameWidget = new QLabel;
Chris@107 76 // m_mainBox->addWidget(m_nameWidget);
Chris@107 77 // m_nameWidget->setText(container->objectName());
Chris@107 78
Chris@34 79 m_mainWidget = new QWidget;
Chris@34 80 m_mainBox->addWidget(m_mainWidget);
Chris@107 81 m_mainBox->insertStretch(2, 10);
Chris@33 82
Chris@34 83 m_viewPlayFrame = 0;
Chris@34 84 populateViewPlayFrame();
Chris@33 85
Chris@0 86 m_layout = new QGridLayout;
Chris@34 87 m_layout->setMargin(0);
Chris@833 88 m_layout->setHorizontalSpacing(2);
Chris@833 89 m_layout->setVerticalSpacing(1);
Chris@33 90 m_mainWidget->setLayout(m_layout);
Chris@0 91
Chris@34 92 PropertyContainer::PropertyList properties = m_container->getProperties();
Chris@0 93
Chris@0 94 blockSignals(true);
Chris@0 95
Chris@0 96 size_t i;
Chris@0 97
Chris@0 98 for (i = 0; i < properties.size(); ++i) {
Chris@0 99 updatePropertyEditor(properties[i]);
Chris@0 100 }
Chris@0 101
Chris@0 102 blockSignals(false);
Chris@0 103
Chris@0 104 m_layout->setRowStretch(m_layout->rowCount(), 10);
Chris@0 105
Chris@100 106 connect(UnitDatabase::getInstance(), SIGNAL(unitDatabaseChanged()),
Chris@100 107 this, SLOT(unitDatabaseChanged()));
Chris@100 108
Chris@285 109 connect(ColourDatabase::getInstance(), SIGNAL(colourDatabaseChanged()),
Chris@285 110 this, SLOT(colourDatabaseChanged()));
Chris@285 111
Chris@0 112 #ifdef DEBUG_PROPERTY_BOX
Chris@682 113 cerr << "PropertyBox[" << this << "]::PropertyBox returning" << endl;
Chris@0 114 #endif
Chris@0 115 }
Chris@0 116
Chris@0 117 PropertyBox::~PropertyBox()
Chris@0 118 {
Chris@0 119 #ifdef DEBUG_PROPERTY_BOX
Chris@682 120 cerr << "PropertyBox[" << this << "]::~PropertyBox" << endl;
Chris@0 121 #endif
Chris@0 122 }
Chris@0 123
Chris@0 124 void
Chris@34 125 PropertyBox::populateViewPlayFrame()
Chris@33 126 {
Chris@36 127 #ifdef DEBUG_PROPERTY_BOX
Chris@729 128 cerr << "PropertyBox[" << this << ":" << m_container << "]::populateViewPlayFrame" << endl;
Chris@36 129 #endif
Chris@34 130
Chris@34 131 if (m_viewPlayFrame) {
Chris@34 132 delete m_viewPlayFrame;
Chris@34 133 m_viewPlayFrame = 0;
Chris@34 134 }
Chris@34 135
Chris@34 136 if (!m_container) return;
Chris@34 137
Chris@34 138 Layer *layer = dynamic_cast<Layer *>(m_container);
Chris@34 139 if (layer) {
Chris@193 140 disconnect(layer, SIGNAL(modelReplaced()),
Chris@193 141 this, SLOT(populateViewPlayFrame()));
Chris@34 142 connect(layer, SIGNAL(modelReplaced()),
Chris@34 143 this, SLOT(populateViewPlayFrame()));
Chris@34 144 }
Chris@34 145
Chris@34 146 PlayParameters *params = m_container->getPlayParameters();
Chris@33 147 if (!params && !layer) return;
Chris@33 148
Chris@34 149 m_viewPlayFrame = new QFrame;
Chris@34 150 m_viewPlayFrame->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
Chris@34 151 m_mainBox->addWidget(m_viewPlayFrame);
Chris@34 152
Chris@34 153 QHBoxLayout *layout = new QHBoxLayout;
Chris@34 154 m_viewPlayFrame->setLayout(layout);
Chris@34 155
Chris@34 156 layout->setMargin(layout->margin() / 2);
Chris@34 157
Chris@36 158 #ifdef DEBUG_PROPERTY_BOX
Chris@587 159 SVDEBUG << "PropertyBox::populateViewPlayFrame: container " << m_container << " (name " << m_container->getPropertyContainerName() << ") params " << params << endl;
Chris@36 160 #endif
Chris@36 161
Chris@33 162 if (layer) {
Chris@34 163 QLabel *showLabel = new QLabel(tr("Show"));
Chris@34 164 layout->addWidget(showLabel);
Chris@34 165 layout->setAlignment(showLabel, Qt::AlignVCenter);
Chris@34 166
Chris@185 167 m_showButton = new LEDButton(Qt::blue);
Chris@185 168 layout->addWidget(m_showButton);
Chris@185 169 connect(m_showButton, SIGNAL(stateChanged(bool)),
Chris@47 170 this, SIGNAL(showLayer(bool)));
Chris@189 171 connect(m_showButton, SIGNAL(mouseEntered()),
Chris@189 172 this, SLOT(mouseEnteredWidget()));
Chris@189 173 connect(m_showButton, SIGNAL(mouseLeft()),
Chris@189 174 this, SLOT(mouseLeftWidget()));
Chris@185 175 layout->setAlignment(m_showButton, Qt::AlignVCenter);
Chris@33 176 }
Chris@33 177
Chris@33 178 if (params) {
Chris@34 179
Chris@34 180 QLabel *playLabel = new QLabel(tr("Play"));
Chris@34 181 layout->addWidget(playLabel);
Chris@34 182 layout->setAlignment(playLabel, Qt::AlignVCenter);
Chris@34 183
Chris@189 184 m_playButton = new LEDButton(Qt::darkGreen);
Chris@189 185 m_playButton->setState(!params->isPlayMuted());
Chris@189 186 layout->addWidget(m_playButton);
Chris@189 187 connect(m_playButton, SIGNAL(stateChanged(bool)),
Chris@377 188 this, SLOT(playAudibleButtonChanged(bool)));
Chris@189 189 connect(m_playButton, SIGNAL(mouseEntered()),
Chris@189 190 this, SLOT(mouseEnteredWidget()));
Chris@189 191 connect(m_playButton, SIGNAL(mouseLeft()),
Chris@189 192 this, SLOT(mouseLeftWidget()));
Chris@34 193 connect(params, SIGNAL(playAudibleChanged(bool)),
Chris@377 194 this, SLOT(playAudibleChanged(bool)));
Chris@189 195 layout->setAlignment(m_playButton, Qt::AlignVCenter);
Chris@34 196
Chris@34 197 layout->insertStretch(-1, 10);
Chris@34 198
Chris@769 199 if (params->getPlayClipId() != "") {
Chris@769 200 QPushButton *playParamButton =
Chris@769 201 new QPushButton(QIcon(":icons/faders.png"), "");
Chris@1174 202 playParamButton->setFixedWidth(WidgetScale::scalePixelSize(24));
Chris@1174 203 playParamButton->setFixedHeight(WidgetScale::scalePixelSize(24));
Chris@769 204 layout->addWidget(playParamButton);
Chris@769 205 connect(playParamButton, SIGNAL(clicked()),
Chris@769 206 this, SLOT(editPlayParameters()));
Chris@63 207 }
Chris@63 208
Chris@1179 209 LevelPanToolButton *levelPan = new LevelPanToolButton;
Chris@1178 210 layout->addWidget(levelPan);
Chris@1178 211 connect(levelPan, SIGNAL(levelChanged(float)),
Chris@1178 212 this, SLOT(playGainControlChanged(float)));
Chris@1178 213 connect(levelPan, SIGNAL(panChanged(float)),
Chris@1178 214 this, SLOT(playPanControlChanged(float)));
Chris@1178 215 connect(params, SIGNAL(playGainChanged(float)),
Chris@1178 216 levelPan, SLOT(setLevel(float)));
Chris@1178 217 connect(params, SIGNAL(playPanChanged(float)),
Chris@1178 218 levelPan, SLOT(setPan(float)));
Chris@34 219
Chris@34 220 } else {
Chris@34 221
Chris@34 222 layout->insertStretch(-1, 10);
Chris@33 223 }
Chris@33 224 }
Chris@33 225
Chris@33 226 void
Chris@197 227 PropertyBox::updatePropertyEditor(PropertyContainer::PropertyName name,
Chris@197 228 bool rangeChanged)
Chris@0 229 {
Chris@0 230 PropertyContainer::PropertyType type = m_container->getPropertyType(name);
Chris@0 231 int row = m_layout->rowCount();
Chris@0 232
Chris@216 233 int min = 0, max = 0, value = 0, deflt = 0;
Chris@216 234 value = m_container->getPropertyRangeAndValue(name, &min, &max, &deflt);
Chris@0 235
Chris@0 236 bool have = (m_propertyControllers.find(name) !=
Chris@0 237 m_propertyControllers.end());
Chris@0 238
Chris@0 239 QString groupName = m_container->getPropertyGroupName(name);
Chris@87 240 QString propertyLabel = m_container->getPropertyLabel(name);
Chris@335 241 QString iconName = m_container->getPropertyIconName(name);
Chris@0 242
Chris@0 243 #ifdef DEBUG_PROPERTY_BOX
Chris@682 244 cerr << "PropertyBox[" << this
Chris@683 245 << "(\"" << m_container->getPropertyContainerName()
Chris@0 246 << "\")]";
Chris@682 247 cerr << "::updatePropertyEditor(\"" << name << "\"):";
Chris@682 248 cerr << " value " << value << ", have " << have << ", group \""
Chris@682 249 << groupName << "\"" << endl;
Chris@0 250 #endif
Chris@0 251
Chris@0 252 bool inGroup = (groupName != QString());
Chris@0 253
Chris@0 254 if (!have) {
Chris@0 255 if (inGroup) {
Chris@0 256 if (m_groupLayouts.find(groupName) == m_groupLayouts.end()) {
Chris@0 257 #ifdef DEBUG_PROPERTY_BOX
Chris@682 258 cerr << "PropertyBox: adding label \"" << groupName << "\" and frame for group for \"" << name << "\"" << endl;
Chris@0 259 #endif
Chris@33 260 m_layout->addWidget(new QLabel(groupName, m_mainWidget), row, 0);
Chris@33 261 QFrame *frame = new QFrame(m_mainWidget);
Chris@0 262 m_layout->addWidget(frame, row, 1, 1, 2);
Chris@493 263 m_groupLayouts[groupName] = new QGridLayout;
Chris@0 264 m_groupLayouts[groupName]->setMargin(0);
Chris@0 265 frame->setLayout(m_groupLayouts[groupName]);
Chris@0 266 }
Chris@0 267 } else {
Chris@0 268 #ifdef DEBUG_PROPERTY_BOX
Chris@682 269 cerr << "PropertyBox: adding label \"" << propertyLabel << "\"" << endl;
Chris@0 270 #endif
Chris@87 271 m_layout->addWidget(new QLabel(propertyLabel, m_mainWidget), row, 0);
Chris@0 272 }
Chris@0 273 }
Chris@0 274
Chris@0 275 switch (type) {
Chris@0 276
Chris@0 277 case PropertyContainer::ToggleProperty:
Chris@0 278 {
Chris@335 279 QAbstractButton *button = 0;
Chris@0 280
Chris@0 281 if (have) {
Chris@335 282 button = dynamic_cast<QAbstractButton *>(m_propertyControllers[name]);
Chris@335 283 assert(button);
Chris@0 284 } else {
Chris@0 285 #ifdef DEBUG_PROPERTY_BOX
Chris@682 286 cerr << "PropertyBox: creating new checkbox" << endl;
Chris@0 287 #endif
Chris@335 288 if (iconName != "") {
Chris@335 289 button = new NotifyingPushButton();
Chris@335 290 button->setCheckable(true);
Chris@335 291 QIcon icon(IconLoader().load(iconName));
Chris@335 292 button->setIcon(icon);
Chris@335 293 button->setObjectName(name);
Chris@1174 294 button->setFixedSize(WidgetScale::scaleQSize(QSize(18, 18)));
Chris@335 295 } else {
Chris@335 296 button = new NotifyingCheckBox();
Chris@335 297 button->setObjectName(name);
Chris@335 298 }
Chris@335 299 connect(button, SIGNAL(toggled(bool)),
Chris@335 300 this, SLOT(propertyControllerChanged(bool)));
Chris@335 301 connect(button, SIGNAL(mouseEntered()),
Chris@189 302 this, SLOT(mouseEnteredWidget()));
Chris@335 303 connect(button, SIGNAL(mouseLeft()),
Chris@189 304 this, SLOT(mouseLeftWidget()));
Chris@0 305 if (inGroup) {
Chris@335 306 button->setToolTip(propertyLabel);
Chris@493 307 m_groupLayouts[groupName]->addWidget
Chris@493 308 (button, 0, m_groupLayouts[groupName]->columnCount());
Chris@0 309 } else {
Chris@335 310 m_layout->addWidget(button, row, 1, 1, 2);
Chris@0 311 }
Chris@335 312 m_propertyControllers[name] = button;
Chris@0 313 }
Chris@0 314
Chris@335 315 if (button->isChecked() != (value > 0)) {
Chris@335 316 button->blockSignals(true);
Chris@335 317 button->setChecked(value > 0);
Chris@335 318 button->blockSignals(false);
Chris@55 319 }
Chris@0 320 break;
Chris@0 321 }
Chris@0 322
Chris@0 323 case PropertyContainer::RangeProperty:
Chris@0 324 {
Chris@0 325 AudioDial *dial;
Chris@0 326
Chris@0 327 if (have) {
Chris@0 328 dial = dynamic_cast<AudioDial *>(m_propertyControllers[name]);
Chris@0 329 assert(dial);
Chris@197 330 if (rangeChanged) {
Chris@197 331 dial->blockSignals(true);
Chris@197 332 dial->setMinimum(min);
Chris@197 333 dial->setMaximum(max);
Chris@197 334 dial->setRangeMapper(m_container->getNewPropertyRangeMapper(name));
Chris@197 335 dial->blockSignals(false);
Chris@197 336 }
Chris@197 337
Chris@0 338 } else {
Chris@0 339 #ifdef DEBUG_PROPERTY_BOX
Chris@682 340 cerr << "PropertyBox: creating new dial" << endl;
Chris@0 341 #endif
Chris@0 342 dial = new AudioDial();
Chris@0 343 dial->setObjectName(name);
Chris@0 344 dial->setMinimum(min);
Chris@0 345 dial->setMaximum(max);
Chris@0 346 dial->setPageStep(1);
Chris@34 347 dial->setNotchesVisible((max - min) <= 12);
Chris@1126 348 // important to set the range mapper before the default,
Chris@1126 349 // because the range mapper is used to map the default
Chris@1126 350 dial->setRangeMapper(m_container->getNewPropertyRangeMapper(name));
Chris@216 351 dial->setDefaultValue(deflt);
Chris@168 352 dial->setShowToolTip(true);
Chris@0 353 connect(dial, SIGNAL(valueChanged(int)),
Chris@0 354 this, SLOT(propertyControllerChanged(int)));
Chris@189 355 connect(dial, SIGNAL(mouseEntered()),
Chris@189 356 this, SLOT(mouseEnteredWidget()));
Chris@189 357 connect(dial, SIGNAL(mouseLeft()),
Chris@189 358 this, SLOT(mouseLeftWidget()));
Chris@0 359
Chris@0 360 if (inGroup) {
Chris@1174 361 dial->setFixedWidth(WidgetScale::scalePixelSize(24));
Chris@1174 362 dial->setFixedHeight(WidgetScale::scalePixelSize(24));
Chris@493 363 m_groupLayouts[groupName]->addWidget
Chris@493 364 (dial, 0, m_groupLayouts[groupName]->columnCount());
Chris@0 365 } else {
Chris@1174 366 dial->setFixedWidth(WidgetScale::scalePixelSize(32));
Chris@1174 367 dial->setFixedHeight(WidgetScale::scalePixelSize(32));
Chris@0 368 m_layout->addWidget(dial, row, 1);
Chris@33 369 QLabel *label = new QLabel(m_mainWidget);
Chris@0 370 connect(dial, SIGNAL(valueChanged(int)),
Chris@0 371 label, SLOT(setNum(int)));
Chris@0 372 label->setNum(value);
Chris@0 373 m_layout->addWidget(label, row, 2);
Chris@0 374 }
Chris@0 375
Chris@0 376 m_propertyControllers[name] = dial;
Chris@0 377 }
Chris@0 378
Chris@55 379 if (dial->value() != value) {
Chris@55 380 dial->blockSignals(true);
Chris@55 381 dial->setValue(value);
Chris@55 382 dial->blockSignals(false);
Chris@55 383 }
Chris@0 384 break;
Chris@0 385 }
Chris@0 386
Chris@0 387 case PropertyContainer::ValueProperty:
Chris@100 388 case PropertyContainer::UnitsProperty:
Chris@285 389 case PropertyContainer::ColourProperty:
Chris@0 390 {
Chris@189 391 NotifyingComboBox *cb;
Chris@0 392
Chris@0 393 if (have) {
Chris@189 394 cb = dynamic_cast<NotifyingComboBox *>(m_propertyControllers[name]);
Chris@0 395 assert(cb);
Chris@0 396 } else {
Chris@0 397 #ifdef DEBUG_PROPERTY_BOX
Chris@682 398 cerr << "PropertyBox: creating new combobox" << endl;
Chris@0 399 #endif
Chris@0 400
Chris@189 401 cb = new NotifyingComboBox();
Chris@0 402 cb->setObjectName(name);
Chris@100 403 cb->setDuplicatesEnabled(false);
Chris@197 404 }
Chris@100 405
Chris@197 406 if (!have || rangeChanged) {
Chris@285 407
Chris@197 408 cb->blockSignals(true);
Chris@197 409 cb->clear();
Chris@285 410 cb->setEditable(false);
Chris@285 411
Chris@100 412 if (type == PropertyContainer::ValueProperty) {
Chris@285 413
Chris@100 414 for (int i = min; i <= max; ++i) {
Chris@862 415
Chris@862 416 QString label = m_container->getPropertyValueLabel(name, i);
Chris@862 417 QString iname = m_container->getPropertyValueIconName(name, i);
Chris@862 418
Chris@862 419 if (iname != "") {
Chris@862 420 QIcon icon(IconLoader().load(iname));
Chris@862 421 cb->addItem(icon, label);
Chris@862 422 } else {
Chris@862 423 cb->addItem(label);
Chris@862 424 }
Chris@100 425 }
Chris@285 426
Chris@285 427 } else if (type == PropertyContainer::UnitsProperty) {
Chris@285 428
Chris@100 429 QStringList units = UnitDatabase::getInstance()->getKnownUnits();
Chris@100 430 for (int i = 0; i < units.size(); ++i) {
Chris@100 431 cb->addItem(units[i]);
Chris@100 432 }
Chris@285 433
Chris@100 434 cb->setEditable(true);
Chris@285 435
Chris@285 436 } else { // ColourProperty
Chris@290 437
Chris@290 438 //!!! should be a proper colour combobox class that
Chris@290 439 // manages its own Add New Colour entry...
Chris@1173 440
Chris@1173 441 int size = (QFontMetrics(QFont()).height() * 2) / 3;
Chris@1173 442 if (size < 12) size = 12;
Chris@285 443
Chris@285 444 ColourDatabase *db = ColourDatabase::getInstance();
Chris@769 445 for (int i = 0; i < db->getColourCount(); ++i) {
Chris@285 446 QString name = db->getColourName(i);
Chris@1173 447 cb->addItem(db->getExamplePixmap(i, QSize(size, size)), name);
Chris@285 448 }
Chris@285 449 cb->addItem(tr("Add New Colour..."));
Chris@285 450 }
Chris@285 451
Chris@197 452 cb->blockSignals(false);
Chris@280 453 if (cb->count() < 20 && cb->count() > cb->maxVisibleItems()) {
Chris@280 454 cb->setMaxVisibleItems(cb->count());
Chris@280 455 }
Chris@197 456 }
Chris@100 457
Chris@197 458 if (!have) {
Chris@0 459 connect(cb, SIGNAL(activated(int)),
Chris@0 460 this, SLOT(propertyControllerChanged(int)));
Chris@189 461 connect(cb, SIGNAL(mouseEntered()),
Chris@189 462 this, SLOT(mouseEnteredWidget()));
Chris@189 463 connect(cb, SIGNAL(mouseLeft()),
Chris@189 464 this, SLOT(mouseLeftWidget()));
Chris@100 465
Chris@0 466 if (inGroup) {
Chris@108 467 cb->setToolTip(propertyLabel);
Chris@493 468 m_groupLayouts[groupName]->addWidget
Chris@493 469 (cb, 0, m_groupLayouts[groupName]->columnCount());
Chris@0 470 } else {
Chris@0 471 m_layout->addWidget(cb, row, 1, 1, 2);
Chris@0 472 }
Chris@0 473 m_propertyControllers[name] = cb;
Chris@0 474 }
Chris@0 475
Chris@100 476 cb->blockSignals(true);
Chris@285 477 if (type == PropertyContainer::ValueProperty ||
Chris@285 478 type == PropertyContainer::ColourProperty) {
Chris@100 479 if (cb->currentIndex() != value) {
Chris@100 480 cb->setCurrentIndex(value);
Chris@100 481 }
Chris@100 482 } else {
Chris@100 483 QString unit = UnitDatabase::getInstance()->getUnitById(value);
Chris@100 484 if (cb->currentText() != unit) {
Chris@100 485 for (int i = 0; i < cb->count(); ++i) {
Chris@100 486 if (cb->itemText(i) == unit) {
Chris@100 487 cb->setCurrentIndex(i);
Chris@100 488 break;
Chris@100 489 }
Chris@100 490 }
Chris@100 491 }
Chris@100 492 }
Chris@100 493 cb->blockSignals(false);
Chris@0 494
Chris@681 495 #ifdef Q_OS_MAC
Chris@982 496 // Crashes on startup without this, for some reason; also
Chris@982 497 // prevents combo boxes from getting weirdly squished
Chris@982 498 // vertically
Chris@982 499 cb->setMinimumSize(QSize(10, cb->font().pixelSize() * 2));
Chris@0 500 #endif
Chris@0 501
Chris@0 502 break;
Chris@0 503 }
Chris@0 504
Chris@807 505 case PropertyContainer::InvalidProperty:
Chris@0 506 default:
Chris@0 507 break;
Chris@0 508 }
Chris@0 509 }
Chris@0 510
Chris@0 511 void
Chris@0 512 PropertyBox::propertyContainerPropertyChanged(PropertyContainer *pc)
Chris@0 513 {
Chris@0 514 if (pc != m_container) return;
Chris@0 515
Chris@55 516 #ifdef DEBUG_PROPERTY_BOX
Chris@587 517 SVDEBUG << "PropertyBox::propertyContainerPropertyChanged" << endl;
Chris@55 518 #endif
Chris@55 519
Chris@0 520 PropertyContainer::PropertyList properties = m_container->getProperties();
Chris@0 521 size_t i;
Chris@0 522
Chris@0 523 blockSignals(true);
Chris@0 524
Chris@0 525 for (i = 0; i < properties.size(); ++i) {
Chris@0 526 updatePropertyEditor(properties[i]);
Chris@0 527 }
Chris@0 528
Chris@0 529 blockSignals(false);
Chris@0 530 }
Chris@0 531
Chris@0 532 void
Chris@249 533 PropertyBox::propertyContainerPropertyRangeChanged(PropertyContainer *)
Chris@197 534 {
Chris@197 535 blockSignals(true);
Chris@197 536
Chris@197 537 PropertyContainer::PropertyList properties = m_container->getProperties();
Chris@197 538 for (size_t i = 0; i < properties.size(); ++i) {
Chris@197 539 updatePropertyEditor(properties[i], true);
Chris@197 540 }
Chris@197 541
Chris@197 542 blockSignals(false);
Chris@197 543 }
Chris@197 544
Chris@197 545 void
Chris@100 546 PropertyBox::unitDatabaseChanged()
Chris@100 547 {
Chris@729 548 #ifdef DEBUG_PROPERTY_BOX
Chris@682 549 cerr << "PropertyBox[" << this << "]: unitDatabaseChanged" << endl;
Chris@729 550 #endif
Chris@100 551 blockSignals(true);
Chris@100 552
Chris@682 553 // cerr << "my container is " << m_container << endl;
Chris@682 554 // cerr << "my container's name is... " << endl;
Chris@682 555 // cerr << m_container->objectName() << endl;
Chris@456 556
Chris@100 557 PropertyContainer::PropertyList properties = m_container->getProperties();
Chris@100 558 for (size_t i = 0; i < properties.size(); ++i) {
Chris@285 559 if (m_container->getPropertyType(properties[i]) ==
Chris@285 560 PropertyContainer::UnitsProperty) {
Chris@285 561 updatePropertyEditor(properties[i]);
Chris@285 562 }
Chris@285 563 }
Chris@285 564
Chris@285 565 blockSignals(false);
Chris@285 566 }
Chris@285 567
Chris@285 568 void
Chris@285 569 PropertyBox::colourDatabaseChanged()
Chris@285 570 {
Chris@285 571 blockSignals(true);
Chris@285 572
Chris@285 573 PropertyContainer::PropertyList properties = m_container->getProperties();
Chris@285 574 for (size_t i = 0; i < properties.size(); ++i) {
Chris@285 575 if (m_container->getPropertyType(properties[i]) ==
Chris@285 576 PropertyContainer::ColourProperty) {
Chris@285 577 updatePropertyEditor(properties[i], true);
Chris@285 578 }
Chris@100 579 }
Chris@100 580
Chris@100 581 blockSignals(false);
Chris@100 582 }
Chris@100 583
Chris@100 584 void
Chris@335 585 PropertyBox::propertyControllerChanged(bool on)
Chris@335 586 {
Chris@335 587 propertyControllerChanged(on ? 1 : 0);
Chris@335 588 }
Chris@335 589
Chris@335 590 void
Chris@0 591 PropertyBox::propertyControllerChanged(int value)
Chris@0 592 {
Chris@0 593 QObject *obj = sender();
Chris@0 594 QString name = obj->objectName();
Chris@0 595
Chris@34 596 #ifdef DEBUG_PROPERTY_BOX
Chris@587 597 SVDEBUG << "PropertyBox::propertyControllerChanged(" << name << ", " << value << ")" << endl;
Chris@34 598 #endif
Chris@0 599
Chris@0 600 PropertyContainer::PropertyType type = m_container->getPropertyType(name);
Chris@100 601
Chris@376 602 Command *c = 0;
Chris@376 603
Chris@100 604 if (type == PropertyContainer::UnitsProperty) {
Chris@285 605
Chris@189 606 NotifyingComboBox *cb = dynamic_cast<NotifyingComboBox *>(obj);
Chris@100 607 if (cb) {
Chris@100 608 QString unit = cb->currentText();
Chris@376 609 c = m_container->getSetPropertyCommand
Chris@100 610 (name, UnitDatabase::getInstance()->getUnitId(unit));
Chris@100 611 }
Chris@285 612
Chris@285 613 } else if (type == PropertyContainer::ColourProperty) {
Chris@285 614
Chris@285 615 if (value == int(ColourDatabase::getInstance()->getColourCount())) {
Chris@285 616 addNewColour();
Chris@285 617 if (value == int(ColourDatabase::getInstance()->getColourCount())) {
Chris@285 618 propertyContainerPropertyChanged(m_container);
Chris@285 619 return;
Chris@285 620 }
Chris@285 621 }
Chris@376 622 c = m_container->getSetPropertyCommand(name, value);
Chris@285 623
Chris@100 624 } else if (type != PropertyContainer::InvalidProperty) {
Chris@285 625
Chris@376 626 c = m_container->getSetPropertyCommand(name, value);
Chris@0 627 }
Chris@376 628
Chris@376 629 if (c) CommandHistory::getInstance()->addCommand(c, true, true);
Chris@218 630
Chris@218 631 updateContextHelp(obj);
Chris@0 632 }
Chris@285 633
Chris@285 634 void
Chris@285 635 PropertyBox::addNewColour()
Chris@285 636 {
Chris@285 637 QColor newColour = QColorDialog::getColor();
Chris@285 638 if (!newColour.isValid()) return;
Chris@285 639
Chris@285 640 ColourNameDialog dialog(tr("Name New Colour"),
Chris@361 641 tr("Enter a name for the new colour:"),
Chris@361 642 newColour, newColour.name(), this);
Chris@285 643 dialog.showDarkBackgroundCheckbox(tr("Prefer black background for this colour"));
Chris@285 644 if (dialog.exec() == QDialog::Accepted) {
Chris@285 645 //!!! command
Chris@285 646 ColourDatabase *db = ColourDatabase::getInstance();
Chris@285 647 int index = db->addColour(newColour, dialog.getColourName());
Chris@285 648 db->setUseDarkBackground(index, dialog.isDarkBackgroundChecked());
Chris@285 649 }
Chris@285 650 }
Chris@377 651
Chris@377 652 void
Chris@377 653 PropertyBox::playAudibleChanged(bool audible)
Chris@377 654 {
Chris@377 655 m_playButton->setState(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@218 782 QWidget *w = dynamic_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@189 789 QString wname = w->objectName();
Chris@189 790
Chris@218 791 QString extraText;
Chris@218 792 AudioDial *dial = dynamic_cast<AudioDial *>(w);
Chris@218 793 if (dial) {
Chris@908 794 double mv = dial->mappedValue();
Chris@218 795 QString unit = "";
Chris@218 796 if (dial->rangeMapper()) unit = dial->rangeMapper()->getUnit();
Chris@218 797 if (unit != "") {
Chris@218 798 extraText = tr(" (current value: %1%2)").arg(mv).arg(unit);
Chris@218 799 } else {
Chris@218 800 extraText = tr(" (current value: %1)").arg(mv);
Chris@218 801 }
Chris@218 802 }
Chris@218 803
Chris@189 804 if (w == m_showButton) {
Chris@190 805 emit contextHelpChanged(tr("Toggle Visibility of %1").arg(cname));
Chris@189 806 } else if (w == m_playButton) {
Chris@190 807 emit contextHelpChanged(tr("Toggle Playback of %1").arg(cname));
Chris@189 808 } else if (wname == "") {
Chris@189 809 return;
Chris@335 810 } else if (dynamic_cast<QAbstractButton *>(w)) {
Chris@190 811 emit contextHelpChanged(tr("Toggle %1 property of %2")
Chris@189 812 .arg(wname).arg(cname));
Chris@189 813 } else {
Chris@218 814 emit contextHelpChanged(tr("Adjust %1 property of %2%3")
Chris@218 815 .arg(wname).arg(cname).arg(extraText));
Chris@189 816 }
Chris@189 817 }
Chris@189 818
Chris@189 819 void
Chris@189 820 PropertyBox::mouseLeftWidget()
Chris@189 821 {
Chris@218 822 if (!(QApplication::mouseButtons() & Qt::LeftButton)) {
Chris@218 823 emit contextHelpChanged("");
Chris@218 824 }
Chris@189 825 }
Chris@189 826
Chris@64 827