00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
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
00034
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