gwenhywfar  5.10.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 <QApplication>
18 #include <QLabel>
19 #include <QPushButton>
20 #include <QLineEdit>
21 #include <QTextEdit>
22 #include <QTextBrowser>
23 #include <QComboBox>
24 #include <QGroupBox>
25 #include <QProgressBar>
26 #include <QHBoxLayout>
27 #include <QVBoxLayout>
28 #include <QGridLayout>
29 #include <QFrame>
30 #include <QTreeWidget>
31 #include <QTabWidget>
32 #include <QCheckBox>
33 #include <QStackedWidget>
34 #include <QScrollArea>
35 #include <QSpinBox>
36 #include <QRadioButton>
37 #include <QHeaderView>
38 
39 #include <QDebug>
40 
41 #include <list>
42 #include <string>
43 
44 
45 #define QT5_DIALOG_STRING_TITLE 0
46 #define QT5_DIALOG_STRING_VALUE 1
47 
48 
49 #include "w_widget.cpp"
50 #include "w_dialog.cpp"
51 #include "w_vlayout.cpp"
52 #include "w_hlayout.cpp"
53 #include "w_gridlayout.cpp"
54 #include "w_label.cpp"
55 #include "w_lineedit.cpp"
56 #include "w_pushbutton.cpp"
57 #include "w_hline.cpp"
58 #include "w_vline.cpp"
59 #include "w_textedit.cpp"
60 #include "w_combobox.cpp"
61 #include "w_tabbook.cpp"
62 #include "w_checkbox.cpp"
63 #include "w_groupbox.cpp"
64 #include "w_widgetstack.cpp"
65 #include "w_textbrowser.cpp"
66 #include "w_scrollarea.cpp"
67 #include "w_progressbar.cpp"
68 #include "w_listbox.cpp"
69 #include "w_radiobutton.cpp"
70 #include "w_spinbox.cpp"
71 
72 
73 
75  :CppDialog(dlg)
76  ,_gui(gui)
77  ,_mainWidget(NULL) {
78 
79 }
80 
81 
82 
84  if (_mainWidget)
86 
87 }
88 
89 
90 
92  CppDialog *cppDlg;
93 
94  cppDlg=CppDialog::getDialog(dlg);
95  if (cppDlg)
96  return dynamic_cast<QT5_GuiDialog*>(cppDlg);
97  return NULL;
98 }
99 
100 
101 
103  QT5_DialogBox *dialogBox;
104  int rv;
105 
106  dialogBox=dynamic_cast<QT5_DialogBox*>(getMainWindow());
107  if (dialogBox==NULL) {
108  DBG_INFO(0, "Dialog's main widget is not derived from class FXDialogBox");
109  return GWEN_ERROR_GENERIC;
110  }
111 
112  /* execute dialog */
113  rv=dialogBox->exec();
115 
116  if (rv==QT5_DialogBox::Accepted) {
117  /* accepted */
118  return 1;
119  }
120  else
121  return 0;
122 }
123 
124 
125 
127  QT5_DialogBox *dialogBox;
128 
129  dialogBox=dynamic_cast<QT5_DialogBox*>(getMainWindow());
130  if (dialogBox==NULL) {
131  DBG_INFO(0, "Dialog's main widget is not derived from class FXDialogBox");
132  return GWEN_ERROR_GENERIC;
133  }
134 
135  /* show dialog */
136  dialogBox->show();
137  /* gui update */
138  qApp->processEvents();
139 
140  return 0;
141 }
142 
143 
144 
146  QT5_DialogBox *dialogBox;
147 
148  dialogBox=dynamic_cast<QT5_DialogBox*>(getMainWindow());
149  if (dialogBox==NULL) {
150  DBG_INFO(0, "Dialog's main widget is not derived from class FXDialogBox");
151  return GWEN_ERROR_GENERIC;
152  }
153 
154  /* let dialog write its settings */
156 
157  /* hide dialog */
158  dialogBox->hide();
159  /* gui update */
160  qApp->processEvents();
161 
162  delete _mainWidget;
164 
165  return 0;
166 }
167 
168 
169 
170 int QT5_GuiDialog::runDialog(bool untilEnd) {
171  QT5_DialogBox *dialogBox;
172 
173  dialogBox=dynamic_cast<QT5_DialogBox*>(getMainWindow());
174  if (dialogBox==NULL) {
175  DBG_INFO(0, "Dialog's main widget is not derived from class FXDialogBox");
176  return GWEN_ERROR_GENERIC;
177  }
178 
179  if (untilEnd) {
180  dialogBox->cont();
181  }
182  else {
183  {
184  /* gui update */
185  qApp->processEvents();
186  }
187  }
188 
189  return 0;
190 }
191 
192 
193 
196  int index,
197  int value,
198  int doSignal) {
199  return GWEN_Widget_SetIntProperty(w, prop, index, value, doSignal);
200 }
201 
202 
203 
206  int index,
207  int defaultValue) {
208  return GWEN_Widget_GetIntProperty(w, prop, index, defaultValue);
209 }
210 
211 
212 
215  int index,
216  const char *value,
217  int doSignal) {
218  return GWEN_Widget_SetCharProperty(w, prop, index, value, doSignal);
219 }
220 
221 
222 
225  int index,
226  const char *defaultValue) {
227  return GWEN_Widget_GetCharProperty(w, prop, index, defaultValue);
228 }
229 
230 
231 
233  int rv;
234  Qt5_W_Widget *xw=NULL;
235 
236  switch(GWEN_Widget_GetType(w)) {
238  xw=new Qt5_W_Dialog(w);
239  break;
241  xw=new Qt5_W_VLayout(w);
242  break;
244  xw=new Qt5_W_HLayout(w);
245  break;
247  xw=new Qt5_W_GridLayout(w);
248  break;
250  xw=new Qt5_W_Label(w);
251  break;
253  xw=new Qt5_W_LineEdit(w);
254  break;
257  /* abuse widget */
258  xw=new Qt5_W_Widget(w);
259  break;
261  xw=new Qt5_W_PushButton(w);
262  break;
264  xw=new Qt5_W_HLine(w);
265  break;
267  xw=new Qt5_W_VLine(w);
268  break;
270  xw=new Qt5_W_TextEdit(w);
271  break;
273  xw=new Qt5_W_ComboBox(w);
274  break;
276  xw=new Qt5_W_TabBook(w);
277  break;
279  xw=new Qt5_W_VLayout(w);
280  break;
282  xw=new Qt5_W_CheckBox(w);
283  break;
285  xw=new Qt5_W_GroupBox(w);
286  break;
288  xw=new Qt5_W_WidgetStack(w);
289  break;
291  xw=new Qt5_W_TextBrowser(w);
292  break;
294  xw=new Qt5_W_ScrollArea(w);
295  break;
297  xw=new Qt5_W_ProgressBar(w);
298  break;
300  xw=new Qt5_W_ListBox(w);
301  break;
303  xw=new Qt5_W_RadioButton(w);
304  break;
306  xw=new Qt5_W_SpinBox(w);
307  break;
308  default:
309  DBG_ERROR(GWEN_LOGDOMAIN, "Unhandled widget type %d (%s)",
311  break;
312  }
313 
314  if (xw==NULL) {
315  DBG_ERROR(GWEN_LOGDOMAIN, "No widget created.");
316  return GWEN_ERROR_INTERNAL;
317  }
318 
319  rv=xw->setup();
320  if (rv<0) {
321  DBG_INFO(GWEN_LOGDOMAIN, "here (%d)", rv);
322  return rv;
323  }
324  else {
325  GWEN_WIDGET *wChild;
326 
329 
330  /* handle children */
331  wChild=GWEN_Widget_Tree_GetFirstChild(w);
332  while(wChild) {
333  /* recursion */
334  rv=setupTree(wChild);
335  if (rv<0) {
336  DBG_INFO(GWEN_LOGDOMAIN, "here (%d)", rv);
337  return rv;
338  }
339  wChild=GWEN_Widget_Tree_GetNext(wChild);
340  }
341  }
342 
343  return 0;
344 }
345 
346 
347 bool QT5_GuiDialog::setup(GWEN_UNUSED QWidget *parentWindow) {
348  GWEN_WIDGET_TREE *wtree;
349  GWEN_WIDGET *w;
350  int rv;
351 
353  if (wtree==NULL) {
354  DBG_ERROR(GWEN_LOGDOMAIN, "No widget tree in dialog");
355  return false;
356  }
357  w=GWEN_Widget_Tree_GetFirst(wtree);
358  if (w==NULL) {
359  DBG_ERROR(GWEN_LOGDOMAIN, "No widgets in dialog");
360  return false;
361  }
362 
363  rv=setupTree(w);
364  if (rv<0) {
365  DBG_ERROR(GWEN_LOGDOMAIN, "here (%d)", rv);
366  return false;
367  }
368 
370 
372  if (rv<0) {
373  DBG_INFO(0, "Error initializing dialog: %d", rv);
374  return false;
375  }
376 
377 
378  return true;
379 }
380 
381 
382 
383 
384 
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
const char * GWEN_Widget_GetCharProperty(GWEN_WIDGET *w, GWEN_DIALOG_PROPERTY prop, int index, const char *defaultValue)
Definition: widget.c:812
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:795
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:35
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()
#define DBG_ERROR(dbg_logger, format, args...)
Definition: debug.h:97
virtual int getIntProperty(GWEN_WIDGET *w, GWEN_DIALOG_PROPERTY prop, int index, int defaultValue)
#define DBG_INFO(dbg_logger, format, args...)
Definition: debug.h:181
int GWEN_Widget_SetIntProperty(GWEN_WIDGET *w, GWEN_DIALOG_PROPERTY prop, int index, int value, int doSignal)
Definition: widget.c:762
int GWEN_Widget_GetIntProperty(GWEN_WIDGET *w, GWEN_DIALOG_PROPERTY prop, int index, int defaultValue)
Definition: widget.c:779
virtual const char * getCharProperty(GWEN_WIDGET *w, GWEN_DIALOG_PROPERTY prop, int index, const char *defaultValue)
#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:452
GWEN_WIDGET * getCInterface()
Definition: cppwidget.cpp:156
#define QT5_DIALOG_WIDGET_REAL
#define GWEN_UNUSED