ArmarXWidgetController.cpp
Go to the documentation of this file.
1 /*
2 * This file is part of ArmarX.
3 *
4 * ArmarX is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * ArmarX is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * @package ArmarX::
17 * @author Mirko Waechter ( mirko.waechter at kit dot edu)
18 * @date 2012
19 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22 
23 #include "ArmarXWidgetController.h"
24 
25 #include <QDialog>
26 #include <QMainWindow>
27 #include <QMessageBox>
28 #include <QThread>
29 #include <QToolBar>
30 
32 
33 #include "QtUtil.h"
34 #include <Inventor/nodes/SoNode.h>
35 
36 namespace armarx
37 {
39  {
40  __appMainWindow = nullptr;
41  }
42 
44  {
45  if (__widget && !__widget->parent())
46  {
47  delete __widget;
48  }
49 
50  // ARMARX_VERBOSE << "Deleting WidgetController " ;
51  }
52 
53  QPointer<QWidget>
55  {
56  if (!__widget)
57  {
58  __widget = new QWidget();
59  }
60 
61  return __widget;
62  }
63 
64  QPointer<QDialog>
66  {
67  return nullptr;
68  }
69 
70  QPointer<QWidget>
72  {
73  return nullptr;
74  }
75 
76  QIcon
78  {
79  return QIcon();
80  }
81 
82  QIcon
84  {
85  return QIcon();
86  }
87 
88  QIcon
90  {
91  return QIcon();
92  }
93 
94  QIcon
96  {
97  return QIcon();
98  }
99 
100  QPointer<QDialog>
102  {
103  return nullptr;
104  }
105 
106  bool
108  {
109  if (instanceName.length() == 0)
110  {
111  throw LocalException("The instance name of the widget must not be empty");
112  }
113 
114  if (__instanceName.length() > 0)
115  {
116  return false;
117  }
118 
119  __instanceName = instanceName;
120  return true;
121  }
122 
123  QString
125  {
126  return __instanceName;
127  }
128 
129  void
130  ArmarXWidgetController::setMainWindow(QMainWindow* mainWindow)
131  {
132  __appMainWindow = mainWindow;
133  }
134 
135  QMainWindow*
137  {
138  return __appMainWindow;
139  }
140 
141  QPointer<TipDialog>
143  {
144  return tipDialog;
145  }
146 
147  void
148  armarx::ArmarXWidgetController::setTipDialog(QPointer<TipDialog> tipDialog)
149  {
150  this->tipDialog = tipDialog;
151  }
152 
153  void
155  {
156  this->mutex3D = mutex3D;
157  }
158 
159  void
161  {
162  configured();
163  emit configAccepted(this);
164  }
165 
166  void
168  {
169  emit configRejected(this);
170  }
171 
172  void
174  {
176  ARMARX_DEBUG << (enable ? "enabling" : "disabling") << " the main widget";
177 
178  getWidget()->setEnabled(enable);
179  }
180 
181  int
183  {
184  QMessageBox msgBox;
185  ARMARX_WARNING_S << "MessageBox says: " << msg.toStdString() << flush;
186  msgBox.setText(msg);
187  return msgBox.exec();
188  }
189 
190  void
192  {
193  ARMARX_DEBUG << "Requesting to " << (enable ? "enable" : "disable") << " the main widget";
194  if (!QMetaObject::invokeMethod(this, "enableMainWidget", Q_ARG(bool, enable)))
195  {
196  ARMARX_WARNING << "Failed to invoke enable";
197  }
198  }
199 
200  void
202  {
203  }
204 
205  void
207  {
208  }
209 } // namespace armarx
210 
211 std::ostream&
212 std::operator<<(std::ostream& stream, const QString& string)
213 {
214  stream << string.toStdString();
215  return stream;
216 }
217 
218 std::ostream&
219 std::operator<<(std::ostream& stream, const QPointF& point)
220 {
221  stream << point.x() << ", " << point.y();
222  return stream;
223 }
224 
225 std::ostream&
226 std::operator<<(std::ostream& stream, const QRectF& rect)
227 {
228  stream << "topleft: " << rect.topLeft() << ", bottomright:" << rect.bottomRight();
229  return stream;
230 }
231 
232 std::ostream&
233 std::operator<<(std::ostream& stream, const QSizeF& rect)
234 {
235  stream << "SizeF: " << rect.width() << "x" << rect.height();
236  return stream;
237 }
armarx::ArmarXWidgetController::mutex3D
std::shared_ptr< std::recursive_mutex > mutex3D
Definition: ArmarXWidgetController.h:309
armarx::ArmarXWidgetController::configRejected
void configRejected()
Definition: ArmarXWidgetController.cpp:167
armarx::ArmarXWidgetController::getCustomTitlebarWidget
virtual QPointer< QWidget > getCustomTitlebarWidget(QWidget *parent=0)
getTitleToolbar returns a pointer to the a toolbar widget of this controller.
Definition: ArmarXWidgetController.cpp:71
armarx::ArmarXWidgetController::onUnlockWidget
virtual void onUnlockWidget()
Definition: ArmarXWidgetController.cpp:206
armarx::ArmarXWidgetController::configured
virtual void configured()
This function must be implemented by the user, if he supplies a config dialog.
Definition: ArmarXWidgetController.h:103
armarx::ArmarXWidgetController::getConfigDialog
virtual QPointer< QDialog > getConfigDialog(QWidget *parent=0)
getConfigDialog returns a pointer to the a configuration widget of this controller.
Definition: ArmarXWidgetController.cpp:65
armarx::ArmarXWidgetController::getInstanceName
QString getInstanceName()
Definition: ArmarXWidgetController.cpp:124
armarx::ArmarXWidgetController::enableMainWidget
void enableMainWidget(bool enable)
Definition: ArmarXWidgetController.cpp:173
armarx::ArmarXWidgetController::getMainWindow
virtual QMainWindow * getMainWindow()
Returns the ArmarX MainWindow.
Definition: ArmarXWidgetController.cpp:136
armarx::ArmarXWidgetController::setTipDialog
void setTipDialog(QPointer< TipDialog > tipDialog)
Definition: ArmarXWidgetController.cpp:148
armarx::ArmarXWidgetController::configAccepted
void configAccepted()
Definition: ArmarXWidgetController.cpp:160
armarx::ArmarXWidgetController::getSceneConfigDialog
virtual QPointer< QDialog > getSceneConfigDialog(QWidget *parent=nullptr)
Reimplementing this function and returning a QDialog* will enable a configuration button which opens ...
Definition: ArmarXWidgetController.cpp:101
armarx::ArmarXWidgetController::getTipDialog
QPointer< TipDialog > getTipDialog() const
Returns the default instance for the TipDialog used by all widgets (if not set otherwise).
Definition: ArmarXWidgetController.cpp:142
armarx::ArmarXWidgetController::setMutex3D
virtual void setMutex3D(RecursiveMutexPtr const &mutex3D)
This mutex is used to protect 3d scene updates. Usually called by the ArmarXGui main window on creati...
Definition: ArmarXWidgetController.cpp:154
armarx::ArmarXWidgetController::GetWidgetIcon
static QIcon GetWidgetIcon()
Implement this function to supply an icon for the menu (if you implemented static QString GetWidgetNa...
Definition: ArmarXWidgetController.cpp:83
armarx::ArmarXWidgetController::RecursiveMutexPtr
std::shared_ptr< RecursiveMutex > RecursiveMutexPtr
Definition: ArmarXWidgetController.h:262
armarx::ArmarXWidgetController::GetWidgetCategoryIcon
static QIcon GetWidgetCategoryIcon()
Implement this function to supply an icon for the menu (if you implemented static QString GetWidgetNa...
Definition: ArmarXWidgetController.cpp:95
armarx::flush
const LogSender::manipulator flush
Definition: LogSender.h:251
ARMARX_DEBUG
#define ARMARX_DEBUG
Definition: Logging.h:184
ARMARX_WARNING_S
#define ARMARX_WARNING_S
Definition: Logging.h:213
Component.h
std::operator<<
ARMARXCORE_IMPORT_EXPORT ostream & operator<<(ostream &stream, const armarx::RunningTaskIceBase &task)
armarx::ArmarXWidgetController::setInstanceName
bool setInstanceName(QString instanceName)
sets the name of this instance.
Definition: ArmarXWidgetController.cpp:107
armarx::ArmarXWidgetController::showMessageBox
static int showMessageBox(const QString &msg)
Definition: ArmarXWidgetController.cpp:182
CHECK_QT_THREAD
#define CHECK_QT_THREAD(qtObject)
Macro to check whether the current function is executed in the thread of the given Qt object.
Definition: QtUtil.h:30
ArmarXWidgetController.h
armarx::ArmarXWidgetController::enableMainWidgetAsync
void enableMainWidgetAsync(bool enable)
This function enables/disables the main widget asynchronously (if called from a non qt thread).
Definition: ArmarXWidgetController.cpp:191
QtUtil.h
armarx::ArmarXWidgetController::onLockWidget
virtual void onLockWidget()
Definition: ArmarXWidgetController.cpp:201
armarx::ArmarXWidgetController::getWidget
virtual QPointer< QWidget > getWidget()
getWidget returns a pointer to the a widget of this controller.
Definition: ArmarXWidgetController.cpp:54
armarx::ArmarXWidgetController::getWidgetCategoryIcon
virtual QIcon getWidgetCategoryIcon() const
Implement this function to supply an icon for the category.
Definition: ArmarXWidgetController.cpp:89
armarx::ArmarXWidgetController::getWidgetIcon
virtual QIcon getWidgetIcon() const
Implement this function to supply an icon for the menu.
Definition: ArmarXWidgetController.cpp:77
ARMARX_WARNING
#define ARMARX_WARNING
Definition: Logging.h:193
armarx::ArmarXWidgetController::setMainWindow
virtual void setMainWindow(QMainWindow *mainWindow)
Definition: ArmarXWidgetController.cpp:130
armarx::ArmarXWidgetController::ArmarXWidgetController
ArmarXWidgetController()
Definition: ArmarXWidgetController.cpp:38
armarx::ArmarXWidgetController::~ArmarXWidgetController
~ArmarXWidgetController() override
Definition: ArmarXWidgetController.cpp:43
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27