Chris@139: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@139: Chris@139: /* Chris@139: Sonic Visualiser Chris@139: An audio file viewer and annotation editor. Chris@139: Centre for Digital Music, Queen Mary, University of London. Chris@139: This file copyright 2006 Chris Cannam. Chris@139: Chris@139: This program is free software; you can redistribute it and/or Chris@139: modify it under the terms of the GNU General Public License as Chris@139: published by the Free Software Foundation; either version 2 of the Chris@139: License, or (at your option) any later version. See the file Chris@139: COPYING included with this distribution for more information. Chris@139: */ Chris@139: Chris@139: #include "WindowTypeSelector.h" Chris@139: Chris@139: #include "WindowShapePreview.h" Chris@139: Chris@139: #include Chris@139: #include Chris@139: Chris@139: #include "base/Preferences.h" Chris@139: Chris@139: WindowTypeSelector::WindowTypeSelector(WindowType defaultType, QWidget *parent) : Chris@139: QFrame(parent), Chris@139: m_windowType(WindowType(999)) Chris@139: { Chris@139: QVBoxLayout *layout = new QVBoxLayout; Chris@139: layout->setMargin(0); Chris@139: setLayout(layout); Chris@139: Chris@139: // The WindowType enum is in rather a ragbag order -- reorder it here Chris@139: // in a more sensible order Chris@139: m_windows = new WindowType[9]; Chris@139: m_windows[0] = HanningWindow; Chris@139: m_windows[1] = HammingWindow; Chris@139: m_windows[2] = BlackmanWindow; Chris@139: m_windows[3] = BlackmanHarrisWindow; Chris@139: m_windows[4] = NuttallWindow; Chris@139: m_windows[5] = GaussianWindow; Chris@139: m_windows[6] = ParzenWindow; Chris@139: m_windows[7] = BartlettWindow; Chris@139: m_windows[8] = RectangularWindow; Chris@139: Chris@139: Preferences *prefs = Preferences::getInstance(); Chris@139: Chris@139: m_windowShape = new WindowShapePreview; Chris@139: Chris@139: m_windowCombo = new QComboBox; Chris@139: int min = 0, max = 0, i = 0; Chris@139: int window = int(defaultType); Chris@139: if (window == 999) { Chris@139: window = prefs->getPropertyRangeAndValue("Window Type", &min, &max); Chris@139: } Chris@139: int index = 0; Chris@139: Chris@139: for (i = 0; i <= 8; ++i) { Chris@139: m_windowCombo->addItem(prefs->getPropertyValueLabel("Window Type", Chris@139: m_windows[i])); Chris@139: if (m_windows[i] == window) index = i; Chris@139: } Chris@139: Chris@139: m_windowCombo->setCurrentIndex(index); Chris@139: Chris@139: layout->addWidget(m_windowShape); Chris@139: layout->addWidget(m_windowCombo); Chris@139: Chris@139: connect(m_windowCombo, SIGNAL(currentIndexChanged(int)), Chris@139: this, SLOT(windowIndexChanged(int))); Chris@139: windowIndexChanged(index); Chris@139: } Chris@139: Chris@139: WindowTypeSelector::~WindowTypeSelector() Chris@139: { Chris@139: delete[] m_windows; Chris@139: } Chris@139: Chris@139: WindowType Chris@139: WindowTypeSelector::getWindowType() const Chris@139: { Chris@139: return m_windowType; Chris@139: } Chris@139: Chris@139: void Chris@139: WindowTypeSelector::setWindowType(WindowType type) Chris@139: { Chris@139: if (type == m_windowType) return; Chris@139: int index; Chris@139: for (index = 0; index <= 8; ++index) { Chris@139: if (m_windows[index] == type) break; Chris@139: } Chris@139: if (index <= 8) m_windowCombo->setCurrentIndex(index); Chris@139: m_windowType = type; Chris@139: m_windowShape->setWindowType(m_windowType); Chris@139: } Chris@139: Chris@139: void Chris@139: WindowTypeSelector::windowIndexChanged(int index) Chris@139: { Chris@139: WindowType type = m_windows[index]; Chris@139: if (type == m_windowType) return; Chris@139: m_windowType = type; Chris@139: m_windowShape->setWindowType(m_windowType); Chris@139: emit windowTypeChanged(type); Chris@139: } Chris@139: