1 /* VSlider.hpp
2  * Copyright (C) 2018, 2019  Sven Jähnichen
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef BWIDGETS_VSLIDER_HPP_
19 #define BWIDGETS_VSLIDER_HPP_
20 
21 #define BWIDGETS_DEFAULT_VSLIDER_WIDTH (BWIDGETS_DEFAULT_VSCALE_WIDTH * 2)
22 #define BWIDGETS_DEFAULT_VSLIDER_HEIGHT BWIDGETS_DEFAULT_VSCALE_HEIGHT
23 #define BWIDGETS_DEFAULT_VSLIDER_DEPTH 1.0
24 
25 #include "Knob.hpp"
26 #include "VScale.hpp"
27 #include "Label.hpp"
28 #include "Focusable.hpp"
29 
30 namespace BWidgets
31 {
32 /**
33  * Class BWidgets::VSlider
34  *
35  * RangeWidget class for a vertical slider.
36  * The Widget is clickable by default.
37  */
38 class VSlider : public VScale, public Focusable
39 {
40 public:
41 	VSlider ();
42 	VSlider (const double  x, const double y, const double width, const double height, const std::string& name,
43 			 const double value, const double min, const double max, const double step);
44 
45 	/**
46 	 * Creates a new (orphan) slider and copies the slider properties from a
47 	 * source slider.
48 	 * @param that Source slider
49 	 */
50 	VSlider (const VSlider& that);
51 
52 	/**
53 	 * Assignment. Copies the slider properties from a source slider and keeps
54 	 * its name and its position within the widget tree. Emits an expose event
55 	 * if the widget is visible and a value changed event.
56 	 * @param that Source slider
57 	 */
58 	VSlider& operator= (const VSlider& that);
59 
60 	/**
61 	 * Pattern cloning. Creates a new instance of the widget and copies all
62 	 * its properties.
63 	 */
64 	virtual Widget* clone () const override;
65 
66 	/**
67 	 * Changes the value of the widget and keeps it within the defined range.
68 	 * Passes the value to its predefined child widgets.
69 	 * Emits a value changed event and (if visible) an expose event.
70 	 * @param val Value
71 	 */
72 	virtual void setValue (const double val) override;
73 
74 	/**
75 	 * Calls a redraw of the widget and calls postRedisplay () if the the
76 	 * Widget is visible.
77 	 * This method should be called if the widgets properties are indirectly
78 	 * changed.
79 	 */
80 	virtual void update () override;
81 
82 	/**
83 	 * Scans theme for widget properties and applies these properties.
84 	 * @param theme Theme to be scanned.
85 	 * 				styles used are:
86 	 * 				BWIDGETS_KEYWORD_BORDER
87 	 * 				BWIDGETS_KEYWORD_BACKGROUND
88 	 * 				BWIDGETS_KEYWORD_FGCOLORS
89 	 * 				BWIDGETS_KEYWORD_BGCOLORS
90 	 * @param name Name of the BStyles::StyleSet within the theme to be
91 	 * 		  	   applied.
92 	 */
93 	virtual void applyTheme (BStyles::Theme& theme) override;
94 	virtual void applyTheme (BStyles::Theme& theme, const std::string& name) override;
95 
96 	/**
97 	 * Predefined empty method to handle a
98 	 * BEvents::EventType::FOCUS_IN_EVENT.
99 	 * @param event Focus event
100 	 */
101 	virtual void onFocusIn (BEvents::FocusEvent* event) override;
102 
103 	/**
104 	 * Predefined empty method to handle a
105 	 * BEvents::EventType::FOCUS_OUT_EVENT.
106 	 * @param event Focus event
107 	 */
108 	virtual void onFocusOut (BEvents::FocusEvent* event) override;
109 
110 protected:
111 	virtual void updateCoords () override;
112 
113 	Knob knob;
114 	Label focusLabel;
115 	double knobRadius;
116 	BUtilities::Point knobPosition;
117 };
118 
119 }
120 
121 #endif /* BWIDGETS_VSLIDER_HPP_ */
122