Chris@1196: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@1196: Chris@1196: /* Chris@1196: Sonic Visualiser Chris@1196: An audio file viewer and annotation editor. Chris@1196: Centre for Digital Music, Queen Mary, University of London. Chris@1196: This file copyright 2007-2016 QMUL. Chris@1196: Chris@1196: This program is free software; you can redistribute it and/or Chris@1196: modify it under the terms of the GNU General Public License as Chris@1196: published by the Free Software Foundation; either version 2 of the Chris@1196: License, or (at your option) any later version. See the file Chris@1196: COPYING included with this distribution for more information. Chris@1196: */ Chris@1196: Chris@1198: #include "ColourMapComboBox.h" Chris@1196: Chris@1198: #include "layer/ColourMapper.h" Chris@1196: Chris@1196: #include "base/Debug.h" Chris@1196: Chris@1196: #include Chris@1196: Chris@1196: #include Chris@1196: Chris@1196: using namespace std; Chris@1196: Chris@1199: ColourMapComboBox::ColourMapComboBox(bool includeSwatches, QWidget *parent) : Chris@1199: NotifyingComboBox(parent), Chris@1199: m_includeSwatches(includeSwatches) Chris@1196: { Chris@1196: setEditable(false); Chris@1196: rebuild(); Chris@1196: Chris@1196: connect(this, SIGNAL(activated(int)), this, SLOT(comboActivated(int))); Chris@1196: Chris@1196: if (count() < 20 && count() > maxVisibleItems()) { Chris@1266: setMaxVisibleItems(count()); Chris@1196: } Chris@1196: } Chris@1196: Chris@1196: void Chris@1198: ColourMapComboBox::comboActivated(int index) Chris@1196: { Chris@1198: emit colourMapChanged(index); Chris@1196: } Chris@1196: Chris@1196: void Chris@1198: ColourMapComboBox::rebuild() Chris@1196: { Chris@1196: blockSignals(true); Chris@1196: Chris@1196: int ix = currentIndex(); Chris@1196: Chris@1196: clear(); Chris@1196: Chris@1196: int size = (QFontMetrics(QFont()).height() * 2) / 3; Chris@1196: if (size < 12) size = 12; Chris@1196: Chris@1198: for (int i = 0; i < ColourMapper::getColourMapCount(); ++i) { Chris@1362: QString name = ColourMapper::getColourMapLabel(i); Chris@1199: if (m_includeSwatches) { Chris@1362: ColourMapper mapper(i, false, 0.0, 1.0); Chris@1199: addItem(mapper.getExamplePixmap(QSize(size * 2, size)), name); Chris@1199: } else { Chris@1199: addItem(name); Chris@1199: } Chris@1196: } Chris@1196: Chris@1196: setCurrentIndex(ix); Chris@1196: Chris@1196: blockSignals(false); Chris@1196: } Chris@1196: