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 
26 {
27  init(defaultType);
28 }
29 
31 {
32  Preferences *prefs = Preferences::getInstance();
33  int min = 0, max = 0, deflt = 0;
34  WindowType type =
35  WindowType(prefs->getPropertyRangeAndValue("Window Type", &min, &max,
36  &deflt));
37  init(type);
38 }
39 
40 void
41 WindowTypeSelector::init(WindowType defaultType)
42 {
43  QVBoxLayout *layout = new QVBoxLayout;
44  layout->setMargin(0);
45  setLayout(layout);
46 
47  // The WindowType enum is in rather a ragbag order -- reorder it here
48  // in a more sensible order
49  m_windows = new WindowType[9];
50  m_windows[0] = HanningWindow;
51  m_windows[1] = HammingWindow;
52  m_windows[2] = BlackmanWindow;
53  m_windows[3] = BlackmanHarrisWindow;
54  m_windows[4] = NuttallWindow;
55  m_windows[5] = GaussianWindow;
56  m_windows[6] = ParzenWindow;
57  m_windows[7] = BartlettWindow;
58  m_windows[8] = RectangularWindow;
59 
60  Preferences *prefs = Preferences::getInstance();
61 
63 
64  m_windowCombo = new QComboBox;
65  int window = int(defaultType);
66  int index = 0;
67 
68  for (int i = 0; i <= 8; ++i) {
69  m_windowCombo->addItem(prefs->getPropertyValueLabel("Window Type",
70  m_windows[i]));
71  if (m_windows[i] == window) index = i;
72  }
73 
74  m_windowCombo->setCurrentIndex(index);
75 
76  layout->addWidget(m_windowShape);
77  layout->addWidget(m_windowCombo);
78 
79  connect(m_windowCombo, SIGNAL(currentIndexChanged(int)),
80  this, SLOT(windowIndexChanged(int)));
81 
82  m_windowType = defaultType;
84 }
85 
87 {
88  delete[] m_windows;
89 }
90 
91 WindowType
93 {
94  return m_windowType;
95 }
96 
97 void
99 {
100  if (type == m_windowType) return;
101  int index;
102  for (index = 0; index <= 8; ++index) {
103  if (m_windows[index] == type) break;
104  }
105  if (index <= 8) m_windowCombo->setCurrentIndex(index);
106  m_windowType = type;
108 }
109 
110 void
112 {
113  WindowType type = m_windows[index];
114  if (type == m_windowType) return;
115  m_windowType = type;
117  emit windowTypeChanged(type);
118 }
119 
void windowTypeChanged(WindowType type)
WindowShapePreview * m_windowShape
void windowIndexChanged(int index)
void setWindowType(WindowType type)
void init(WindowType type)
void setWindowType(WindowType type)
WindowType getWindowType() const