1 /* ItemBox.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_ITEMBOX_HPP_ 19 #define BWIDGETS_ITEMBOX_HPP_ 20 21 #include "BItems.hpp" 22 #include "Label.hpp" 23 #include "ValueWidget.hpp" 24 #include <cmath> 25 26 #define BWIDGETS_DEFAULT_ITEMBOX_WIDTH 100.0 27 #define BWIDGETS_DEFAULT_ITEMBOX_HEIGHT 20.0 28 29 #define BWIDGETS_DEFAULT_ITEMBOX_ITEM_NAME "/item" 30 31 #ifndef UNSELECTED 32 #define UNSELECTED -HUGE_VAL 33 #endif 34 35 namespace BWidgets 36 { 37 38 /** 39 * Class BWidgets::ItemBox 40 * 41 * Single line box widget displaying an item widget. An item is a value 42 * associated with a widget. If no widget has been selected (nullptr), an 43 * internal label widget will be used. 44 * 45 * TODO: Flexible padding 46 */ 47 class ItemBox : public ValueWidget 48 { 49 public: 50 ItemBox (); 51 ItemBox (const double x, const double y, const double width, const double height, 52 const std::string& name, const BItems::Item item); 53 54 /** 55 * Creates a new (orphan) item box and copies the properties from a 56 * source item box widget. 57 * @param that Source choice box 58 */ 59 ItemBox (const ItemBox& that); 60 61 ~ItemBox (); 62 63 /** 64 * Assignment. Copies the properties from a source item box widget 65 * and keeps its name and its position within the widget tree. Emits a 66 * BEvents::ExposeEvent if the text widget is visible. 67 * @param that Source text widget 68 */ 69 ItemBox& operator= (const ItemBox& that); 70 71 /** 72 * Pattern cloning. Creates a new instance of the widget and copies all 73 * its properties. 74 */ 75 virtual Widget* clone () const override; 76 77 /** 78 * Sets the item stored in this widget. 79 * @param item Item. 80 */ 81 void setItem (const BItems::Item item); 82 83 /** 84 * Gets (a pointer to) the item stored in this widget. 85 * @return Item. 86 */ 87 BItems::Item* getItem (); 88 89 /** 90 * Scans theme for widget properties and applies these properties. 91 * @param theme Theme to be scanned. 92 * @param name Name of the BStyles::StyleSet within the theme to be 93 * applied. 94 */ 95 virtual void applyTheme (BStyles::Theme& theme) override; 96 virtual void applyTheme (BStyles::Theme& theme, const std::string& name) override; 97 98 /** 99 * Calls a redraw of the widget and calls postRedisplay () if the the 100 * Widget is visible. 101 * This method should be called if the widgets properties are indirectly 102 * changed. 103 */ 104 virtual void update () override; 105 106 protected: 107 BItems::Item item; 108 }; 109 110 } 111 112 #endif /* BWIDGETS_ITEMBOX_HPP_ */ 113