File: VariableEditor.h

package info (click to toggle)
structure-synth 1.0.0-1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 2,072 kB
  • ctags: 1,176
  • sloc: cpp: 7,070; python: 167; makefile: 66; lisp: 25
file content (79 lines) | stat: -rw-r--r-- 2,185 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#pragma once

#include <QString>
#include <QVector>
#include <QWidget>
#include <QSlider>
#include <QDoubleSpinBox>
#include <QHBoxLayout>

#include "../Parser/Preprocessor.h"

/// Classes for the GUI Editor for the preprocessor constant variables.
/// E.g. the line: #define angle 45 (float:0.0-360.0)
///	will make a simple editor widget appear.
namespace StructureSynth {
	namespace GUI {
	
		class VariableWidget; // Forward decl...

		/// The Variable Editor window.
		class VariableEditor : public QWidget {
		public:
			VariableEditor(QWidget* parent);

			QString updateFromPreprocessor(Parser::Preprocessor* pp, QString in, bool* showGUI);

		private:
			
			QSpacerItem* spacer;
			QVector<VariableWidget*> variables;
			QVBoxLayout* layout;
		};

		// A helper class (combined float slider+spinner)
		class ComboSlider : public QWidget {
		Q_OBJECT
		public:
			ComboSlider(QWidget* parent, double defaultValue, double minimum, double maximum) 
				: QWidget(parent), defaultValue(defaultValue), minimum(minimum), maximum(maximum){
				setLayout(new QHBoxLayout());
				slider = new QSlider(Qt::Horizontal,this);
				slider->setRange(0,1000);
				double val = (defaultValue-minimum)/(maximum-minimum);
				slider->setValue(val*1000);
				spinner = new QDoubleSpinBox(this);
				spinner->setMaximum(maximum);
				spinner->setMinimum(minimum);
				spinner->setValue(defaultValue);
				layout()->addWidget(slider);
				layout()->addWidget(spinner);
				connect(spinner, SIGNAL(valueChanged(double)), this, SLOT(spinnerChanged(double)));
				connect(slider, SIGNAL(valueChanged(int)), this, SLOT(sliderChanged(int)));
			}

			double getValue() { return spinner->value(); }
		
		protected slots:
			void spinnerChanged(double) {
				double val = (spinner->value()-minimum)/(maximum-minimum);
				slider->setValue(val*1000);
			}

			void sliderChanged(int) {
				double val = (slider->value()/1000.0)*(maximum-minimum)+minimum;
				spinner->setValue(val);
			}

		private:
			
			QSlider* slider;
			QDoubleSpinBox* spinner;
			double defaultValue;
			double minimum;
			double maximum;
		};

	}
}