annotate widgets/PropertyBox.cpp @ 1190:2513f660c183 levelpanwidget

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