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@139
|
51 int min = 0, max = 0, i = 0;
|
Chris@139
|
52 int window = int(defaultType);
|
Chris@139
|
53 if (window == 999) {
|
Chris@139
|
54 window = prefs->getPropertyRangeAndValue("Window Type", &min, &max);
|
Chris@139
|
55 }
|
Chris@139
|
56 int index = 0;
|
Chris@139
|
57
|
Chris@139
|
58 for (i = 0; i <= 8; ++i) {
|
Chris@139
|
59 m_windowCombo->addItem(prefs->getPropertyValueLabel("Window Type",
|
Chris@139
|
60 m_windows[i]));
|
Chris@139
|
61 if (m_windows[i] == window) index = i;
|
Chris@139
|
62 }
|
Chris@139
|
63
|
Chris@139
|
64 m_windowCombo->setCurrentIndex(index);
|
Chris@139
|
65
|
Chris@139
|
66 layout->addWidget(m_windowShape);
|
Chris@139
|
67 layout->addWidget(m_windowCombo);
|
Chris@139
|
68
|
Chris@139
|
69 connect(m_windowCombo, SIGNAL(currentIndexChanged(int)),
|
Chris@139
|
70 this, SLOT(windowIndexChanged(int)));
|
Chris@139
|
71 windowIndexChanged(index);
|
Chris@139
|
72 }
|
Chris@139
|
73
|
Chris@139
|
74 WindowTypeSelector::~WindowTypeSelector()
|
Chris@139
|
75 {
|
Chris@139
|
76 delete[] m_windows;
|
Chris@139
|
77 }
|
Chris@139
|
78
|
Chris@139
|
79 WindowType
|
Chris@139
|
80 WindowTypeSelector::getWindowType() const
|
Chris@139
|
81 {
|
Chris@139
|
82 return m_windowType;
|
Chris@139
|
83 }
|
Chris@139
|
84
|
Chris@139
|
85 void
|
Chris@139
|
86 WindowTypeSelector::setWindowType(WindowType type)
|
Chris@139
|
87 {
|
Chris@139
|
88 if (type == m_windowType) return;
|
Chris@139
|
89 int index;
|
Chris@139
|
90 for (index = 0; index <= 8; ++index) {
|
Chris@139
|
91 if (m_windows[index] == type) break;
|
Chris@139
|
92 }
|
Chris@139
|
93 if (index <= 8) m_windowCombo->setCurrentIndex(index);
|
Chris@139
|
94 m_windowType = type;
|
Chris@139
|
95 m_windowShape->setWindowType(m_windowType);
|
Chris@139
|
96 }
|
Chris@139
|
97
|
Chris@139
|
98 void
|
Chris@139
|
99 WindowTypeSelector::windowIndexChanged(int index)
|
Chris@139
|
100 {
|
Chris@139
|
101 WindowType type = m_windows[index];
|
Chris@139
|
102 if (type == m_windowType) return;
|
Chris@139
|
103 m_windowType = type;
|
Chris@139
|
104 m_windowShape->setWindowType(m_windowType);
|
Chris@139
|
105 emit windowTypeChanged(type);
|
Chris@139
|
106 }
|
Chris@139
|
107
|