annotate widgets/PropertyBox.cpp @ 1187:306c24eeab10 levelpanwidget

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