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