gwenhywfar  5.14.1
qt5_gui_dialog.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  begin : Mon Feb 15 2010
3  copyright : (C) 2010 by Martin Preuss
4  email : martin@libchipcard.de
5 
6  ***************************************************************************
7  * Please see toplevel file COPYING for license details *
8  ***************************************************************************/
9 
10 #include "qt5_gui_dialog.hpp"
11 #include "qt5dialogbox.hpp"
12 
13 #include <gwenhywfar/dialog_be.h>
14 #include <gwenhywfar/widget_be.h>
15 #include <gwenhywfar/debug.h>
16 
17 #include <gwen-gui-cpp/cppwidget.hpp>
18 
19 #include <QApplication>
20 #include <QLabel>
21 #include <QPushButton>
22 #include <QLineEdit>
23 #include <QTextEdit>
24 #include <QTextBrowser>
25 #include <QComboBox>
26 #include <QGroupBox>
27 #include <QProgressBar>
28 #include <QHBoxLayout>
29 #include <QVBoxLayout>
30 #include <QGridLayout>
31 #include <QFrame>
32 #include <QTreeWidget>
33 #include <QTabWidget>
34 #include <QCheckBox>
35 #include <QStackedWidget>
36 #include <QScrollArea>
37 #include <QSpinBox>
38 #include <QRadioButton>
39 #include <QHeaderView>
40 #include <QSplitter>
41 #include <QList>
42 
43 #include <QDebug>
44 
45 #include <list>
46 #include <string>
47 
48 
49 #define QT5_DIALOG_STRING_TITLE 0
50 #define QT5_DIALOG_STRING_VALUE 1
51 
52 
53 #include "w_widget.cpp"
54 #include "w_dialog.cpp"
55 #include "w_vlayout.cpp"
56 #include "w_hlayout.cpp"
57 #include "w_gridlayout.cpp"
58 #include "w_label.cpp"
59 #include "w_lineedit.cpp"
60 #include "w_pushbutton.cpp"
61 #include "w_hline.cpp"
62 #include "w_vline.cpp"
63 #include "w_textedit.cpp"
64 #include "w_combobox.cpp"
65 #include "w_tabbook.cpp"
66 #include "w_checkbox.cpp"
67 #include "w_groupbox.cpp"
68 #include "w_widgetstack.cpp"
69 #include "w_textbrowser.cpp"
70 #include "w_scrollarea.cpp"
71 #include "w_progressbar.cpp"
72 #include "w_listbox.cpp"
73 #include "w_radiobutton.cpp"
74 #include "w_spinbox.cpp"
75 #include "w_splitter.cpp"
76 
77 
78 
80  :CppDialog(dlg)
81  ,_gui(gui)
82  ,_mainWidget(NULL) {
83 
84 }
85 
86 
87 
89  if (_mainWidget)
91 
92 }
93 
94 
95 
97  CppDialog *cppDlg;
98 
99  cppDlg=CppDialog::getDialog(dlg);
100  if (cppDlg)
101  return dynamic_cast<QT5_GuiDialog*>(cppDlg);
102  return NULL;
103 }
104 
105 
106 
108  QT5_DialogBox *dialogBox;
109  int rv;
110 
111  dialogBox=dynamic_cast<QT5_DialogBox*>(getMainWindow());
112  if (dialogBox==NULL) {
113  DBG_INFO(0, "Dialog's main widget is not derived from class FXDialogBox");
114  return GWEN_ERROR_GENERIC;
115  }
116 
117  /* execute dialog */
118  rv=dialogBox->exec();
120 
121  if (rv==QT5_DialogBox::Accepted) {
122  /* accepted */
123  return 1;
124  }
125  else
126  return 0;
127 }
128 
129 
130 
132  QT5_DialogBox *dialogBox;
133 
134  dialogBox=dynamic_cast<QT5_DialogBox*>(getMainWindow());
135  if (dialogBox==NULL) {
136  DBG_INFO(0, "Dialog's main widget is not derived from class FXDialogBox");
137  return GWEN_ERROR_GENERIC;
138  }
139 
140  /* show dialog */
141  dialogBox->show();
142  /* gui update */
143  qApp->processEvents();
144 
145  return 0;
146 }
147 
148 
149 
151  QT5_DialogBox *dialogBox;
152 
153  dialogBox=dynamic_cast<QT5_DialogBox*>(getMainWindow());
154  if (dialogBox==NULL) {
155  DBG_INFO(0, "Dialog's main widget is not derived from class FXDialogBox");
156  return GWEN_ERROR_GENERIC;
157  }
158 
159  /* let dialog write its settings */
161 
162  /* hide dialog */
163  dialogBox->hide();
164  /* gui update */
165  qApp->processEvents();
166 
167  delete _mainWidget;
169 
170  return 0;
171 }
172 
173 
174 
175 int QT5_GuiDialog::runDialog(bool untilEnd) {
176  QT5_DialogBox *dialogBox;
177 
178  dialogBox=dynamic_cast<QT5_DialogBox*>(getMainWindow());
179  if (dialogBox==NULL) {
180  DBG_INFO(0, "Dialog's main widget is not derived from class FXDialogBox");
181  return GWEN_ERROR_GENERIC;
182  }
183 
184  if (untilEnd) {
185  dialogBox->cont();
186  }
187  else {
188  {
189  /* gui update */
190  qApp->processEvents();
191  }
192  }
193 
194  return 0;
195 }
196 
197 
198 
201  int index,
202  int value,
203  int doSignal) {
204  return GWEN_Widget_SetIntProperty(w, prop, index, value, doSignal);
205 }
206 
207 
208 
211  int index,
212  int defaultValue) {
213  return GWEN_Widget_GetIntProperty(w, prop, index, defaultValue);
214 }
215 
216 
217 
220  int index,
221  const char *value,
222  int doSignal) {
223  return GWEN_Widget_SetCharProperty(w, prop, index, value, doSignal);
224 }
225 
226 
227 
230  int index,
231  const char *defaultValue) {
232  return GWEN_Widget_GetCharProperty(w, prop, index, defaultValue);
233 }
234 
235 
236 
238  int rv;
239  Qt5_W_Widget *xw=NULL;
240 
241  switch(GWEN_Widget_GetType(w)) {
243  xw=new Qt5_W_Dialog(w);
244  break;
246  xw=new Qt5_W_VLayout(w);
247  break;
249  xw=new Qt5_W_HLayout(w);
250  break;
252  xw=new Qt5_W_GridLayout(w);
253  break;
255  xw=new Qt5_W_Label(w);
256  break;
258  xw=new Qt5_W_LineEdit(w);
259  break;
262  /* abuse widget */
263  xw=new Qt5_W_Widget(w);
264  break;
266  xw=new Qt5_W_PushButton(w);
267  break;
269  xw=new Qt5_W_HLine(w);
270  break;
272  xw=new Qt5_W_VLine(w);
273  break;
275  xw=new Qt5_W_TextEdit(w);
276  break;
278  xw=new Qt5_W_ComboBox(w);
279  break;
281  xw=new Qt5_W_TabBook(w);
282  break;
284  xw=new Qt5_W_VLayout(w);
285  break;
287  xw=new Qt5_W_CheckBox(w);
288  break;
290  xw=new Qt5_W_GroupBox(w);
291  break;
293  xw=new Qt5_W_WidgetStack(w);
294  break;
296  xw=new Qt5_W_TextBrowser(w);
297  break;
299  xw=new Qt5_W_ScrollArea(w);
300  break;
302  xw=new Qt5_W_ProgressBar(w);
303  break;
305  xw=new Qt5_W_ListBox(w);
306  break;
308  xw=new Qt5_W_RadioButton(w);
309  break;
311  xw=new Qt5_W_SpinBox(w);
312  break;
314  xw=new Qt5_W_HSplitter(w);
315  break;
317  xw=new Qt5_W_VSplitter(w);
318  break;
319  default:
320  DBG_ERROR(GWEN_LOGDOMAIN, "Unhandled widget type %d (%s)",
322  break;
323  }
324 
325  if (xw==NULL) {
326  DBG_ERROR(GWEN_LOGDOMAIN, "No widget created.");
327  return GWEN_ERROR_INTERNAL;
328  }
329 
330  rv=xw->setup();
331  if (rv<0) {
332  DBG_INFO(GWEN_LOGDOMAIN, "here (%d)", rv);
333  return rv;
334  }
335  else {
336  GWEN_WIDGET *wChild;
337 
340 
341  /* handle children */
342  wChild=GWEN_Widget_Tree_GetFirstChild(w);
343  while(wChild) {
344  /* recursion */
345  rv=setupTree(wChild);
346  if (rv<0) {
347  DBG_INFO(GWEN_LOGDOMAIN, "here (%d)", rv);
348  return rv;
349  }
350  wChild=GWEN_Widget_Tree_GetNext(wChild);
351  }
352  }
353 
354  return 0;
355 }
356 
357 
358 bool QT5_GuiDialog::setup(GWEN_UNUSED QWidget *parentWindow) {
359  GWEN_WIDGET_TREE *wtree;
360  GWEN_WIDGET *w;
361  int rv;
362 
364  if (wtree==NULL) {
365  DBG_ERROR(GWEN_LOGDOMAIN, "No widget tree in dialog");
366  return false;
367  }
368  w=GWEN_Widget_Tree_GetFirst(wtree);
369  if (w==NULL) {
370  DBG_ERROR(GWEN_LOGDOMAIN, "No widgets in dialog");
371  return false;
372  }
373 
374  rv=setupTree(w);
375  if (rv<0) {
376  DBG_ERROR(GWEN_LOGDOMAIN, "here (%d)", rv);
377  return false;
378  }
379 
381 
383  if (rv<0) {
384  DBG_INFO(0, "Error initializing dialog: %d", rv);
385  return false;
386  }
387 
388 
389  return true;
390 }
391 
392 
393 
394 
395 
virtual int setIntProperty(GWEN_WIDGET *w, GWEN_DIALOG_PROPERTY prop, int index, int value, int doSignal)
GWEN_WIDGET_TYPE GWEN_Widget_GetType(const GWEN_WIDGET *w)
Definition: widget.c:185
#define DBG_ERROR(dbg_logger, format,...)
Definition: debug.h:97
const char * GWEN_Widget_GetCharProperty(GWEN_WIDGET *w, GWEN_DIALOG_PROPERTY prop, int index, const char *defaultValue)
Definition: widget.c:820
static QT5_GuiDialog * getDialog(GWEN_DIALOG *dlg)
int GWEN_Widget_SetCharProperty(GWEN_WIDGET *w, GWEN_DIALOG_PROPERTY prop, int index, const char *value, int doSignal)
Definition: widget.c:803
virtual int setup()
QT5_GuiDialog(QT5_Gui *gui, GWEN_DIALOG *dlg)
int runDialog(bool untilEnd)
GWEN_WIDGET_TREE * GWEN_Dialog_GetWidgets(const GWEN_DIALOG *dlg)
Definition: dialog.c:629
GWEN_DIALOG_PROPERTY
Definition: dialog.h:260
#define NULL
Definition: binreloc.c:300
int setupTree(GWEN_WIDGET *w)
void unlinkFromDialog()
#define GWEN_LOGDOMAIN
Definition: logger.h:32
A C++ binding for the C module GWEN_DIALOG.
Definition: cppdialog.hpp:32
struct GWEN_DIALOG GWEN_DIALOG
Definition: dialog.h:54
QT5_DialogBox * _mainWidget
void * GWEN_Widget_GetImplData(const GWEN_WIDGET *w, int index)
Definition: widget.c:122
bool setup(QWidget *parentWindow)
virtual int setCharProperty(GWEN_WIDGET *w, GWEN_DIALOG_PROPERTY prop, int index, const char *value, int doSignal)
int GWEN_Dialog_EmitSignalToAll(GWEN_DIALOG *dlg, GWEN_DIALOG_EVENTTYPE t, const char *sender)
Definition: dialog.c:330
GWEN_DIALOG * _dialog
Definition: cppdialog.hpp:50
#define GWEN_ERROR_GENERIC
Definition: error.h:62
struct GWEN_WIDGET GWEN_WIDGET
Definition: widget_be.h:34
QT5_DialogBox * getMainWindow()
virtual ~QT5_GuiDialog()
virtual int getIntProperty(GWEN_WIDGET *w, GWEN_DIALOG_PROPERTY prop, int index, int defaultValue)
int GWEN_Widget_SetIntProperty(GWEN_WIDGET *w, GWEN_DIALOG_PROPERTY prop, int index, int value, int doSignal)
Definition: widget.c:770
int GWEN_Widget_GetIntProperty(GWEN_WIDGET *w, GWEN_DIALOG_PROPERTY prop, int index, int defaultValue)
Definition: widget.c:787
virtual const char * getCharProperty(GWEN_WIDGET *w, GWEN_DIALOG_PROPERTY prop, int index, const char *defaultValue)
#define DBG_INFO(dbg_logger, format,...)
Definition: debug.h:181
#define GWEN_ERROR_INTERNAL
Definition: error.h:125
static CPPGUI_API CppDialog * getDialog(GWEN_DIALOG *dlg)
Definition: cppdialog.cpp:146
const char * GWEN_Widget_Type_toString(GWEN_WIDGET_TYPE t)
Definition: widget.c:456
GWEN_WIDGET * getCInterface()
Definition: cppwidget.cpp:156
#define QT5_DIALOG_WIDGET_REAL
#define GWEN_UNUSED