svgui  1.9
WindowTypeSelector.cpp
Go to the documentation of this file.
00001 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
00002 
00003 /*
00004     Sonic Visualiser
00005     An audio file viewer and annotation editor.
00006     Centre for Digital Music, Queen Mary, University of London.
00007     This file copyright 2006 Chris Cannam.
00008     
00009     This program is free software; you can redistribute it and/or
00010     modify it under the terms of the GNU General Public License as
00011     published by the Free Software Foundation; either version 2 of the
00012     License, or (at your option) any later version.  See the file
00013     COPYING included with this distribution for more information.
00014 */
00015 
00016 #include "WindowTypeSelector.h"
00017 
00018 #include "WindowShapePreview.h"
00019 
00020 #include <QVBoxLayout>
00021 #include <QComboBox>
00022 
00023 #include "base/Preferences.h"
00024 
00025 WindowTypeSelector::WindowTypeSelector(WindowType defaultType, QWidget *parent) :
00026     QFrame(parent),
00027     m_windowType(WindowType(999))
00028 {
00029     QVBoxLayout *layout = new QVBoxLayout;
00030     layout->setMargin(0);
00031     setLayout(layout);
00032 
00033     // The WindowType enum is in rather a ragbag order -- reorder it here
00034     // in a more sensible order
00035     m_windows = new WindowType[9];
00036     m_windows[0] = HanningWindow;
00037     m_windows[1] = HammingWindow;
00038     m_windows[2] = BlackmanWindow;
00039     m_windows[3] = BlackmanHarrisWindow;
00040     m_windows[4] = NuttallWindow;
00041     m_windows[5] = GaussianWindow;
00042     m_windows[6] = ParzenWindow;
00043     m_windows[7] = BartlettWindow;
00044     m_windows[8] = RectangularWindow;
00045 
00046     Preferences *prefs = Preferences::getInstance();
00047 
00048     m_windowShape = new WindowShapePreview;
00049 
00050     m_windowCombo = new QComboBox;
00051     int min = 0, max = 0, deflt = 0, i = 0;
00052     int window = int(defaultType);
00053     if (window == 999) {
00054         window = prefs->getPropertyRangeAndValue("Window Type", &min, &max,
00055                                                  &deflt);
00056     }
00057     int index = 0;
00058     
00059     for (i = 0; i <= 8; ++i) {
00060         m_windowCombo->addItem(prefs->getPropertyValueLabel("Window Type",
00061                                                             m_windows[i]));
00062         if (m_windows[i] == window) index = i;
00063     }
00064 
00065     m_windowCombo->setCurrentIndex(index);
00066 
00067     layout->addWidget(m_windowShape);
00068     layout->addWidget(m_windowCombo);
00069 
00070     connect(m_windowCombo, SIGNAL(currentIndexChanged(int)),
00071             this, SLOT(windowIndexChanged(int)));
00072     windowIndexChanged(index);
00073 }
00074 
00075 WindowTypeSelector::~WindowTypeSelector()
00076 {
00077     delete[] m_windows;
00078 }
00079 
00080 WindowType
00081 WindowTypeSelector::getWindowType() const
00082 {
00083     return m_windowType;
00084 }
00085 
00086 void
00087 WindowTypeSelector::setWindowType(WindowType type)
00088 {
00089     if (type == m_windowType) return;
00090     int index;
00091     for (index = 0; index <= 8; ++index) {
00092         if (m_windows[index] == type) break;
00093     }
00094     if (index <= 8) m_windowCombo->setCurrentIndex(index);
00095     m_windowType = type;
00096     m_windowShape->setWindowType(m_windowType);
00097 }
00098 
00099 void
00100 WindowTypeSelector::windowIndexChanged(int index)
00101 {
00102     WindowType type = m_windows[index];
00103     if (type == m_windowType) return;
00104     m_windowType = type;
00105     m_windowShape->setWindowType(m_windowType);
00106     emit windowTypeChanged(type);
00107 }
00108