Mercurial > hg > easaier-soundaccess
comparison widgets/WindowTypeSelector.cpp @ 0:fc9323a41f5a
start base : Sonic Visualiser sv1-1.0rc1
author | lbajardsilogic |
---|---|
date | Fri, 11 May 2007 09:08:14 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:fc9323a41f5a |
---|---|
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 | |
48 m_windowShape = new WindowShapePreview; | |
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 | |
75 WindowTypeSelector::~WindowTypeSelector() | |
76 { | |
77 delete[] m_windows; | |
78 } | |
79 | |
80 WindowType | |
81 WindowTypeSelector::getWindowType() const | |
82 { | |
83 return m_windowType; | |
84 } | |
85 | |
86 void | |
87 WindowTypeSelector::setWindowType(WindowType type) | |
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; | |
96 m_windowShape->setWindowType(m_windowType); | |
97 } | |
98 | |
99 void | |
100 WindowTypeSelector::windowIndexChanged(int index) | |
101 { | |
102 WindowType type = m_windows[index]; | |
103 if (type == m_windowType) return; | |
104 m_windowType = type; | |
105 m_windowShape->setWindowType(m_windowType); | |
106 emit windowTypeChanged(type); | |
107 } | |
108 |