annotate widgets/PropertyBox.cpp @ 1180:6a6a63506e3f levelpanwidget

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