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 "QtUtil.h"
26 
28 
29 #include <Inventor/nodes/SoNode.h>
30 
31 #include <QMainWindow>
32 #include <QMessageBox>
33 #include <QDialog>
34 #include <QToolBar>
35 #include <QThread>
36 
37 namespace armarx
38 {
40  {
41  __appMainWindow = nullptr;
42  }
43 
45  {
46  if (__widget && !__widget->parent())
47  {
48  delete __widget;
49  }
50 
51  // ARMARX_VERBOSE << "Deleting WidgetController " ;
52  }
53 
55  {
56  if (!__widget)
57  {
58  __widget = new QWidget();
59  }
60 
61  return __widget;
62  }
63 
64  QPointer<QDialog> ArmarXWidgetController::getConfigDialog(QWidget* parent)
65  {
66  return nullptr;
67  }
68 
69  QPointer<QWidget> ArmarXWidgetController::getCustomTitlebarWidget(QWidget* parent)
70  {
71  return nullptr;
72  }
73 
75  {
76  return QIcon();
77  }
78 
80  {
81  return QIcon();
82  }
83 
85  {
86  return QIcon();
87  }
88 
90  {
91  return QIcon();
92  }
93 
94  QPointer<QDialog> ArmarXWidgetController::getSceneConfigDialog(QWidget* parent)
95  {
96  return nullptr;
97  }
98 
99  bool ArmarXWidgetController::setInstanceName(QString instanceName)
100  {
101  if (instanceName.length() == 0)
102  {
103  throw LocalException("The instance name of the widget must not be empty");
104  }
105 
106  if (__instanceName.length() > 0)
107  {
108  return false;
109  }
110 
111  __instanceName = instanceName;
112  return true;
113  }
114 
116  {
117  return __instanceName;
118  }
119 
120  void ArmarXWidgetController::setMainWindow(QMainWindow* mainWindow)
121  {
122  __appMainWindow = mainWindow;
123  }
124 
126  {
127  return __appMainWindow;
128  }
129 
130  QPointer<TipDialog> ArmarXWidgetController::getTipDialog() const
131  {
132  return tipDialog;
133  }
134 
135  void armarx::ArmarXWidgetController::setTipDialog(QPointer<TipDialog> tipDialog)
136  {
137  this->tipDialog = tipDialog;
138  }
139 
140 
142  {
143  this->mutex3D = mutex3D;
144  }
145 
147  {
148  configured();
149  emit configAccepted(this);
150  }
151 
153  {
154  emit configRejected(this);
155  }
156 
158  {
160  ARMARX_DEBUG << (enable ? "enabling" : "disabling") << " the main widget";
161 
162  getWidget()->setEnabled(enable);
163  }
164 
165 
167  {
168  QMessageBox msgBox;
169  ARMARX_WARNING_S << "MessageBox says: " << msg.toStdString() << flush;
170  msgBox.setText(msg);
171  return msgBox.exec();
172  }
173 
175  {
176  ARMARX_DEBUG << "Requesting to " << (enable ? "enable" : "disable") << " the main widget";
177  if (!QMetaObject::invokeMethod(this, "enableMainWidget", Q_ARG(bool, enable)))
178  {
179  ARMARX_WARNING << "Failed to invoke enable";
180  }
181  }
182 
184 
186 }
187 
188 std::ostream& std::operator<< (std::ostream& stream, const QString& string)
189 {
190  stream << string.toStdString();
191  return stream;
192 }
193 
194 std::ostream& std::operator<< (std::ostream& stream, const QPointF& point)
195 {
196  stream << point.x() << ", " << point.y();
197  return stream;
198 }
199 
200 std::ostream& std::operator<<(std::ostream& stream, const QRectF& rect)
201 {
202  stream << "topleft: " << rect.topLeft() << ", bottomright:" << rect.bottomRight();
203  return stream;
204 }
205 
206 std::ostream& std::operator<<(std::ostream& stream, const QSizeF& rect)
207 {
208  stream << "SizeF: " << rect.width() << "x" << rect.height();
209  return stream;
210 }
armarx::ArmarXWidgetController::mutex3D
std::shared_ptr< std::recursive_mutex > mutex3D
Definition: ArmarXWidgetController.h:301
armarx::ArmarXWidgetController::configRejected
void configRejected()
Definition: ArmarXWidgetController.cpp:152
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:69
armarx::ArmarXWidgetController::onUnlockWidget
virtual void onUnlockWidget()
Definition: ArmarXWidgetController.cpp:185
armarx::ArmarXWidgetController::configured
virtual void configured()
This function must be implemented by the user, if he supplies a config dialog.
Definition: ArmarXWidgetController.h:101
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:64
armarx::ArmarXWidgetController::getInstanceName
QString getInstanceName()
Definition: ArmarXWidgetController.cpp:115
armarx::ArmarXWidgetController::enableMainWidget
void enableMainWidget(bool enable)
Definition: ArmarXWidgetController.cpp:157
armarx::ArmarXWidgetController::getMainWindow
virtual QMainWindow * getMainWindow()
Returns the ArmarX MainWindow.
Definition: ArmarXWidgetController.cpp:125
armarx::ArmarXWidgetController::setTipDialog
void setTipDialog(QPointer< TipDialog > tipDialog)
Definition: ArmarXWidgetController.cpp:135
armarx::ArmarXWidgetController::configAccepted
void configAccepted()
Definition: ArmarXWidgetController.cpp:146
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:94
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:130
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:141
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:79
armarx::ArmarXWidgetController::RecursiveMutexPtr
std::shared_ptr< RecursiveMutex > RecursiveMutexPtr
Definition: ArmarXWidgetController.h:256
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:89
armarx::flush
const LogSender::manipulator flush
Definition: LogSender.h:251
ARMARX_DEBUG
#define ARMARX_DEBUG
Definition: Logging.h:177
ARMARX_WARNING_S
#define ARMARX_WARNING_S
Definition: Logging.h:206
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:99
armarx::ArmarXWidgetController::showMessageBox
static int showMessageBox(const QString &msg)
Definition: ArmarXWidgetController.cpp:166
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:174
QtUtil.h
armarx::ArmarXWidgetController::onLockWidget
virtual void onLockWidget()
Definition: ArmarXWidgetController.cpp:183
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:84
armarx::ArmarXWidgetController::getWidgetIcon
virtual QIcon getWidgetIcon() const
Implement this function to supply an icon for the menu.
Definition: ArmarXWidgetController.cpp:74
ARMARX_WARNING
#define ARMARX_WARNING
Definition: Logging.h:186
armarx::ArmarXWidgetController::setMainWindow
virtual void setMainWindow(QMainWindow *mainWindow)
Definition: ArmarXWidgetController.cpp:120
armarx::ArmarXWidgetController::ArmarXWidgetController
ArmarXWidgetController()
Definition: ArmarXWidgetController.cpp:39
armarx::ArmarXWidgetController::~ArmarXWidgetController
~ArmarXWidgetController() override
Definition: ArmarXWidgetController.cpp:44
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28