annotate widgets/ColourMapComboBox.cpp @ 1264:5f68f5c74904

This was new in GCC 7
author Chris Cannam
date Tue, 12 Dec 2017 11:19:15 +0000
parents 73d43e410a6b
children a34a2a25907c
rev   line source
Chris@1196 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@1196 2
Chris@1196 3 /*
Chris@1196 4 Sonic Visualiser
Chris@1196 5 An audio file viewer and annotation editor.
Chris@1196 6 Centre for Digital Music, Queen Mary, University of London.
Chris@1196 7 This file copyright 2007-2016 QMUL.
Chris@1196 8
Chris@1196 9 This program is free software; you can redistribute it and/or
Chris@1196 10 modify it under the terms of the GNU General Public License as
Chris@1196 11 published by the Free Software Foundation; either version 2 of the
Chris@1196 12 License, or (at your option) any later version. See the file
Chris@1196 13 COPYING included with this distribution for more information.
Chris@1196 14 */
Chris@1196 15
Chris@1198 16 #include "ColourMapComboBox.h"
Chris@1196 17
Chris@1198 18 #include "layer/ColourMapper.h"
Chris@1196 19
Chris@1196 20 #include "base/Debug.h"
Chris@1196 21
Chris@1196 22 #include <QFontMetrics>
Chris@1196 23
Chris@1196 24 #include <iostream>
Chris@1196 25
Chris@1196 26 using namespace std;
Chris@1196 27
Chris@1199 28 ColourMapComboBox::ColourMapComboBox(bool includeSwatches, QWidget *parent) :
Chris@1199 29 NotifyingComboBox(parent),
Chris@1199 30 m_includeSwatches(includeSwatches)
Chris@1196 31 {
Chris@1196 32 setEditable(false);
Chris@1196 33 rebuild();
Chris@1196 34
Chris@1196 35 connect(this, SIGNAL(activated(int)), this, SLOT(comboActivated(int)));
Chris@1196 36
Chris@1196 37 if (count() < 20 && count() > maxVisibleItems()) {
Chris@1196 38 setMaxVisibleItems(count());
Chris@1196 39 }
Chris@1196 40 }
Chris@1196 41
Chris@1196 42 void
Chris@1198 43 ColourMapComboBox::comboActivated(int index)
Chris@1196 44 {
Chris@1198 45 emit colourMapChanged(index);
Chris@1196 46 }
Chris@1196 47
Chris@1196 48 void
Chris@1198 49 ColourMapComboBox::rebuild()
Chris@1196 50 {
Chris@1196 51 blockSignals(true);
Chris@1196 52
Chris@1196 53 int ix = currentIndex();
Chris@1196 54
Chris@1196 55 clear();
Chris@1196 56
Chris@1196 57 int size = (QFontMetrics(QFont()).height() * 2) / 3;
Chris@1196 58 if (size < 12) size = 12;
Chris@1196 59
Chris@1198 60 for (int i = 0; i < ColourMapper::getColourMapCount(); ++i) {
Chris@1199 61 QString name = ColourMapper::getColourMapName(i);
Chris@1199 62 if (m_includeSwatches) {
Chris@1199 63 ColourMapper mapper(i, 0.0, 1.0);
Chris@1199 64 addItem(mapper.getExamplePixmap(QSize(size * 2, size)), name);
Chris@1199 65 } else {
Chris@1199 66 addItem(name);
Chris@1199 67 }
Chris@1196 68 }
Chris@1196 69
Chris@1196 70 setCurrentIndex(ix);
Chris@1196 71
Chris@1196 72 blockSignals(false);
Chris@1196 73 }
Chris@1196 74