Omnidome
Fulldome Mapping Software Toolkit
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ParameterWidget.h
Go to the documentation of this file.
1 /* Copyright (c) 2014-2016 "Omnidome" by cr8tr
2  * Dome Mapping Projection Software (http://omnido.me).
3  * Omnidome was created by Michael Winkelmann aka Wilston Oreo (@WilstonOreo)
4  *
5  * This file is part of Omnidome.
6  *
7  * Omnidome is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as
9  * published by the Free Software Foundation, either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU Affero General Public License for more details.
16  * You should have received a copy of the GNU Affero General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 #ifndef OMNI_UI_MIXIN_PARAMETERWIDGET_H_
20 #define OMNI_UI_MIXIN_PARAMETERWIDGET_H_
21 
22 #include <QWidget>
23 #include <QLayout>
24 
25 namespace omni {
26  namespace ui {
27  namespace mixin {
28  /**@brief Setup and remove a parameter widget for a certain plugin
29  interface
30  @tparam Base class of parameter widget
31  @detail Interface can be a mapping, canvas or input interface
32  **/
33  template<typename WIDGET = QWidget>
35  public:
36  typedef WIDGET widget_type;
37 
38  /// Remove parameter widget from given widget
39  template<typename PARENT_WIDGET>
40  inline void removeParameterWidget(PARENT_WIDGET *_widget) {
41  if (parameterWidget_) {
42  _widget->layout()->removeWidget(parameterWidget_);
43  parameterWidget_->hide();
44  parameterWidget_->deleteLater();
45  parameterWidget_ = nullptr;
46  }
47  }
48 
49  /// Setup widget for interface and place it onto widget
50  template<typename PARENT_WIDGET, typename INTERFACE>
51  bool setupParameterWidget(PARENT_WIDGET *_widget, INTERFACE *_interface) {
52  if (!_widget) return false;
53  if (!_widget->layout()) return false;
54 
55  removeParameterWidget(_widget);
56 
57  if (!_interface) return false;
58 
59  /// Make a new parameter widget
60  parameterWidget_ = _interface->widget();
61 
62  if (parameterWidget_) {
64 
65  _widget->layout()->addWidget(parameterWidget_);
66  parameterWidget_->show();
67  return true;
68  }
69  return false;
70  }
71 
72  /// Return pointer to parameterWidget
74  return parameterWidget_;
75  }
76 
77  private:
78  /// Additional options. Is called during setup process
79  inline virtual void parameterWidgetSetupOptions(widget_type *_paramWidget)
80  const {}
81 
83  };
84  }
85  }
86 }
87 
88 #endif /* OMNI_UI_MIXIN_PARAMETERWIDGET_H_ */
virtual void parameterWidgetSetupOptions(widget_type *_paramWidget) const
Additional options. Is called during setup process.
Definition: ParameterWidget.h:79
WIDGET widget_type
Definition: ParameterWidget.h:36
Setup and remove a parameter widget for a certain plugin interface.
Definition: ParameterWidget.h:34
bool setupParameterWidget(PARENT_WIDGET *_widget, INTERFACE *_interface)
Setup widget for interface and place it onto widget.
Definition: ParameterWidget.h:51
widget_type * parameterWidget_
Definition: ParameterWidget.h:82
void removeParameterWidget(PARENT_WIDGET *_widget)
Remove parameter widget from given widget.
Definition: ParameterWidget.h:40
widget_type * parameterWidget()
Return pointer to parameterWidget.
Definition: ParameterWidget.h:73