annotate widgets/PropertyBox.cpp @ 1195:51bb2582c2cc levelpanwidget

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