annotate widgets/WindowTypeSelector.cpp @ 607:5b72899d692b

Give a dedicated key to toggling the centre line, and move it out of the overlay level setting -- reducing number of overlay levels to 3. Introduce two distinct vertical scale types (so that we can hide the spectrogram colour scale part easily)
author Chris Cannam
date Mon, 30 Jan 2012 16:01:59 +0000
parents 34bbbcb3c01f
children 4a578a360011
rev   line source
Chris@139 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@139 2
Chris@139 3 /*
Chris@139 4 Sonic Visualiser
Chris@139 5 An audio file viewer and annotation editor.
Chris@139 6 Centre for Digital Music, Queen Mary, University of London.
Chris@139 7 This file copyright 2006 Chris Cannam.
Chris@139 8
Chris@139 9 This program is free software; you can redistribute it and/or
Chris@139 10 modify it under the terms of the GNU General Public License as
Chris@139 11 published by the Free Software Foundation; either version 2 of the
Chris@139 12 License, or (at your option) any later version. See the file
Chris@139 13 COPYING included with this distribution for more information.
Chris@139 14 */
Chris@139 15
Chris@139 16 #include "WindowTypeSelector.h"
Chris@139 17
Chris@139 18 #include "WindowShapePreview.h"
Chris@139 19
Chris@139 20 #include <QVBoxLayout>
Chris@139 21 #include <QComboBox>
Chris@139 22
Chris@139 23 #include "base/Preferences.h"
Chris@139 24
Chris@139 25 WindowTypeSelector::WindowTypeSelector(WindowType defaultType, QWidget *parent) :
Chris@139 26 QFrame(parent),
Chris@139 27 m_windowType(WindowType(999))
Chris@139 28 {
Chris@139 29 QVBoxLayout *layout = new QVBoxLayout;
Chris@139 30 layout->setMargin(0);
Chris@139 31 setLayout(layout);
Chris@139 32
Chris@139 33 // The WindowType enum is in rather a ragbag order -- reorder it here
Chris@139 34 // in a more sensible order
Chris@139 35 m_windows = new WindowType[9];
Chris@139 36 m_windows[0] = HanningWindow;
Chris@139 37 m_windows[1] = HammingWindow;
Chris@139 38 m_windows[2] = BlackmanWindow;
Chris@139 39 m_windows[3] = BlackmanHarrisWindow;
Chris@139 40 m_windows[4] = NuttallWindow;
Chris@139 41 m_windows[5] = GaussianWindow;
Chris@139 42 m_windows[6] = ParzenWindow;
Chris@139 43 m_windows[7] = BartlettWindow;
Chris@139 44 m_windows[8] = RectangularWindow;
Chris@139 45
Chris@139 46 Preferences *prefs = Preferences::getInstance();
Chris@139 47
Chris@139 48 m_windowShape = new WindowShapePreview;
Chris@139 49
Chris@139 50 m_windowCombo = new QComboBox;
Chris@216 51 int min = 0, max = 0, deflt = 0, i = 0;
Chris@139 52 int window = int(defaultType);
Chris@139 53 if (window == 999) {
Chris@216 54 window = prefs->getPropertyRangeAndValue("Window Type", &min, &max,
Chris@216 55 &deflt);
Chris@139 56 }
Chris@139 57 int index = 0;
Chris@139 58
Chris@139 59 for (i = 0; i <= 8; ++i) {
Chris@139 60 m_windowCombo->addItem(prefs->getPropertyValueLabel("Window Type",
Chris@139 61 m_windows[i]));
Chris@139 62 if (m_windows[i] == window) index = i;
Chris@139 63 }
Chris@139 64
Chris@139 65 m_windowCombo->setCurrentIndex(index);
Chris@139 66
Chris@139 67 layout->addWidget(m_windowShape);
Chris@139 68 layout->addWidget(m_windowCombo);
Chris@139 69
Chris@139 70 connect(m_windowCombo, SIGNAL(currentIndexChanged(int)),
Chris@139 71 this, SLOT(windowIndexChanged(int)));
Chris@139 72 windowIndexChanged(index);
Chris@139 73 }
Chris@139 74
Chris@139 75 WindowTypeSelector::~WindowTypeSelector()
Chris@139 76 {
Chris@139 77 delete[] m_windows;
Chris@139 78 }
Chris@139 79
Chris@139 80 WindowType
Chris@139 81 WindowTypeSelector::getWindowType() const
Chris@139 82 {
Chris@139 83 return m_windowType;
Chris@139 84 }
Chris@139 85
Chris@139 86 void
Chris@139 87 WindowTypeSelector::setWindowType(WindowType type)
Chris@139 88 {
Chris@139 89 if (type == m_windowType) return;
Chris@139 90 int index;
Chris@139 91 for (index = 0; index <= 8; ++index) {
Chris@139 92 if (m_windows[index] == type) break;
Chris@139 93 }
Chris@139 94 if (index <= 8) m_windowCombo->setCurrentIndex(index);
Chris@139 95 m_windowType = type;
Chris@139 96 m_windowShape->setWindowType(m_windowType);
Chris@139 97 }
Chris@139 98
Chris@139 99 void
Chris@139 100 WindowTypeSelector::windowIndexChanged(int index)
Chris@139 101 {
Chris@139 102 WindowType type = m_windows[index];
Chris@139 103 if (type == m_windowType) return;
Chris@139 104 m_windowType = type;
Chris@139 105 m_windowShape->setWindowType(m_windowType);
Chris@139 106 emit windowTypeChanged(type);
Chris@139 107 }
Chris@139 108