gwenhywfar  5.10.1
qt4_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 "qt4_gui_dialog.hpp"
11 #include "qt4dialogbox.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 
46 
47 #define QT4_DIALOG_WIDGET_REAL 0
48 #define QT4_DIALOG_WIDGET_CONTENT 1
49 #define QT4_DIALOG_WIDGET_LAYOUT 2
50 
51 #define QT4_DIALOG_STRING_TITLE 0
52 #define QT4_DIALOG_STRING_VALUE 1
53 
54 
55 
56 #include "w_widget.cpp"
57 #include "w_dialog.cpp"
58 #include "w_vlayout.cpp"
59 #include "w_hlayout.cpp"
60 #include "w_gridlayout.cpp"
61 #include "w_label.cpp"
62 #include "w_lineedit.cpp"
63 #include "w_pushbutton.cpp"
64 #include "w_hline.cpp"
65 #include "w_vline.cpp"
66 #include "w_textedit.cpp"
67 #include "w_combobox.cpp"
68 #include "w_tabbook.cpp"
69 #include "w_checkbox.cpp"
70 #include "w_groupbox.cpp"
71 #include "w_widgetstack.cpp"
72 #include "w_textbrowser.cpp"
73 #include "w_scrollarea.cpp"
74 #include "w_progressbar.cpp"
75 #include "w_listbox.cpp"
76 #include "w_radiobutton.cpp"
77 #include "w_spinbox.cpp"
78 
79 
80 
81 
83  :CppDialog(dlg)
84  ,_gui(gui)
85  ,_mainWidget(NULL) {
86 
87 }
88 
89 
90 
92  if (_mainWidget)
94 
95 }
96 
97 
98 
100  CppDialog *cppDlg;
101 
102  cppDlg=CppDialog::getDialog(dlg);
103  if (cppDlg)
104  return dynamic_cast<QT4_GuiDialog*>(cppDlg);
105  return NULL;
106 }
107 
108 
109 
111  QT4_DialogBox *dialogBox;
112  int rv;
113 
114  dialogBox=dynamic_cast<QT4_DialogBox*>(getMainWindow());
115  if (dialogBox==NULL) {
116  DBG_INFO(0, "Dialog's main widget is not derived from class FXDialogBox");
117  return GWEN_ERROR_GENERIC;
118  }
119 
120  /* execute dialog */
121  rv=dialogBox->exec();
123 
124  if (rv==QT4_DialogBox::Accepted) {
125  /* accepted */
126  return 1;
127  }
128  else
129  return 0;
130 }
131 
132 
133 
135  QT4_DialogBox *dialogBox;
136 
137  dialogBox=dynamic_cast<QT4_DialogBox*>(getMainWindow());
138  if (dialogBox==NULL) {
139  DBG_INFO(0, "Dialog's main widget is not derived from class FXDialogBox");
140  return GWEN_ERROR_GENERIC;
141  }
142 
143  /* show dialog */
144  dialogBox->show();
145  /* gui update */
146  qApp->processEvents();
147 
148  return 0;
149 }
150 
151 
152 
154  QT4_DialogBox *dialogBox;
155 
156  dialogBox=dynamic_cast<QT4_DialogBox*>(getMainWindow());
157  if (dialogBox==NULL) {
158  DBG_INFO(0, "Dialog's main widget is not derived from class FXDialogBox");
159  return GWEN_ERROR_GENERIC;
160  }
161 
162  /* let dialog write its settings */
164 
165  /* hide dialog */
166  dialogBox->hide();
167  /* gui update */
168  qApp->processEvents();
169 
170  delete _mainWidget;
172 
173  return 0;
174 }
175 
176 
177 
178 int QT4_GuiDialog::runDialog(bool untilEnd) {
179  QT4_DialogBox *dialogBox;
180 
181  dialogBox=dynamic_cast<QT4_DialogBox*>(getMainWindow());
182  if (dialogBox==NULL) {
183  DBG_INFO(0, "Dialog's main widget is not derived from class FXDialogBox");
184  return GWEN_ERROR_GENERIC;
185  }
186 
187  if (untilEnd) {
188  dialogBox->cont();
189  }
190  else {
191  {
192  /* gui update */
193  qApp->processEvents();
194  }
195  }
196 
197  return 0;
198 }
199 
200 
201 
204  int index,
205  int value,
206  int doSignal) {
207  return GWEN_Widget_SetIntProperty(w, prop, index, value, doSignal);
208 }
209 
210 
211 
214  int index,
215  int defaultValue) {
216  return GWEN_Widget_GetIntProperty(w, prop, index, defaultValue);
217 }
218 
219 
220 
223  int index,
224  const char *value,
225  int doSignal) {
226  return GWEN_Widget_SetCharProperty(w, prop, index, value, doSignal);
227 }
228 
229 
230 
233  int index,
234  const char *defaultValue) {
235  return GWEN_Widget_GetCharProperty(w, prop, index, defaultValue);
236 }
237 
238 
239 
241  int rv;
242  Qt4_W_Widget *xw=NULL;
243 
244  switch(GWEN_Widget_GetType(w)) {
246  xw=new Qt4_W_Dialog(w);
247  break;
249  xw=new Qt4_W_VLayout(w);
250  break;
252  xw=new Qt4_W_HLayout(w);
253  break;
255  xw=new Qt4_W_GridLayout(w);
256  break;
258  xw=new Qt4_W_Label(w);
259  break;
261  xw=new Qt4_W_LineEdit(w);
262  break;
265  /* abuse widget */
266  xw=new Qt4_W_Widget(w);
267  break;
269  xw=new Qt4_W_PushButton(w);
270  break;
272  xw=new Qt4_W_HLine(w);
273  break;
275  xw=new Qt4_W_VLine(w);
276  break;
278  xw=new Qt4_W_TextEdit(w);
279  break;
281  xw=new Qt4_W_ComboBox(w);
282  break;
284  xw=new Qt4_W_TabBook(w);
285  break;
287  xw=new Qt4_W_VLayout(w);
288  break;
290  xw=new Qt4_W_CheckBox(w);
291  break;
293  xw=new Qt4_W_GroupBox(w);
294  break;
296  xw=new Qt4_W_WidgetStack(w);
297  break;
299  xw=new Qt4_W_TextBrowser(w);
300  break;
302  xw=new Qt4_W_ScrollArea(w);
303  break;
305  xw=new Qt4_W_ProgressBar(w);
306  break;
308  xw=new Qt4_W_ListBox(w);
309  break;
311  xw=new Qt4_W_RadioButton(w);
312  break;
314  xw=new Qt4_W_SpinBox(w);
315  break;
316  default:
317  DBG_ERROR(GWEN_LOGDOMAIN, "Unhandled widget type %d (%s)",
319  break;
320  }
321 
322  if (xw==NULL) {
323  DBG_ERROR(GWEN_LOGDOMAIN, "No widget created.");
324  return GWEN_ERROR_INTERNAL;
325  }
326 
327  rv=xw->setup();
328  if (rv<0) {
329  DBG_INFO(GWEN_LOGDOMAIN, "here (%d)", rv);
330  return rv;
331  }
332  else {
333  GWEN_WIDGET *wChild;
334 
337 
338  /* handle children */
339  wChild=GWEN_Widget_Tree_GetFirstChild(w);
340  while(wChild) {
341  /* recursion */
342  rv=setupTree(wChild);
343  if (rv<0) {
344  DBG_INFO(GWEN_LOGDOMAIN, "here (%d)", rv);
345  return rv;
346  }
347  wChild=GWEN_Widget_Tree_GetNext(wChild);
348  }
349  }
350 
351  return 0;
352 }
353 
354 
355 bool QT4_GuiDialog::setup(QWidget *parentWindow) {
356  GWEN_WIDGET_TREE *wtree;
357  GWEN_WIDGET *w;
358  int rv;
359 
361  if (wtree==NULL) {
362  DBG_ERROR(GWEN_LOGDOMAIN, "No widget tree in dialog");
363  return false;
364  }
365  w=GWEN_Widget_Tree_GetFirst(wtree);
366  if (w==NULL) {
367  DBG_ERROR(GWEN_LOGDOMAIN, "No widgets in dialog");
368  return false;
369  }
370 
371  rv=setupTree(w);
372  if (rv<0) {
373  DBG_ERROR(GWEN_LOGDOMAIN, "here (%d)", rv);
374  return false;
375  }
376 
378 
380  if (rv<0) {
381  DBG_INFO(0, "Error initializing dialog: %d", rv);
382  return false;
383  }
384 
385 
386  return true;
387 }
388 
389 
390 
391 
392 
virtual int setup()
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
int GWEN_Widget_SetCharProperty(GWEN_WIDGET *w, GWEN_DIALOG_PROPERTY prop, int index, const char *value, int doSignal)
Definition: widget.c:795
GWEN_WIDGET_TREE * GWEN_Dialog_GetWidgets(const GWEN_DIALOG *dlg)
Definition: dialog.c:629
int setupTree(GWEN_WIDGET *w)
void unlinkFromDialog()
static QT4_GuiDialog * getDialog(GWEN_DIALOG *dlg)
GWEN_DIALOG_PROPERTY
Definition: dialog.h:260
#define NULL
Definition: binreloc.c:300
#define GWEN_LOGDOMAIN
Definition: logger.h:35
int runDialog(bool untilEnd)
A C++ binding for the C module GWEN_DIALOG.
Definition: cppdialog.hpp:32
struct GWEN_DIALOG GWEN_DIALOG
Definition: dialog.h:54
void * GWEN_Widget_GetImplData(const GWEN_WIDGET *w, int index)
Definition: widget.c:122
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
virtual int setCharProperty(GWEN_WIDGET *w, GWEN_DIALOG_PROPERTY prop, int index, const char *value, int doSignal)
#define GWEN_ERROR_GENERIC
Definition: error.h:62
QT4_GuiDialog(QT4_Gui *gui, GWEN_DIALOG *dlg)
bool setup(QWidget *parentWindow)
struct GWEN_WIDGET GWEN_WIDGET
Definition: widget_be.h:34
QT4_DialogBox * _mainWidget
#define DBG_ERROR(dbg_logger, format, args...)
Definition: debug.h:97
#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
#define QT4_DIALOG_WIDGET_REAL
virtual int getIntProperty(GWEN_WIDGET *w, GWEN_DIALOG_PROPERTY prop, int index, int defaultValue)
virtual ~QT4_GuiDialog()
#define GWEN_ERROR_INTERNAL
Definition: error.h:125
virtual int setIntProperty(GWEN_WIDGET *w, GWEN_DIALOG_PROPERTY prop, int index, int value, int doSignal)
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
virtual const char * getCharProperty(GWEN_WIDGET *w, GWEN_DIALOG_PROPERTY prop, int index, const char *defaultValue)
GWEN_WIDGET * getCInterface()
Definition: cppwidget.cpp:156
QT4_DialogBox * getMainWindow()