gwenhywfar  4.6.0beta
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 
91 
93  if (_mainWidget)
95 
96 }
97 
98 
99 
101  CppDialog *cppDlg;
102 
103  cppDlg=CppDialog::getDialog(dlg);
104  if (cppDlg)
105  return dynamic_cast<QT4_GuiDialog*>(cppDlg);
106  return NULL;
107 }
108 
109 
110 
112  QT4_DialogBox *dialogBox;
113  int rv;
114 
115  dialogBox=dynamic_cast<QT4_DialogBox*>(getMainWindow());
116  if (dialogBox==NULL) {
117  DBG_INFO(0, "Dialog's main widget is not derived from class FXDialogBox");
118  return GWEN_ERROR_GENERIC;
119  }
120 
121  /* execute dialog */
122  rv=dialogBox->exec();
124 
125  if (rv==QT4_DialogBox::Accepted) {
126  /* accepted */
127  return 1;
128  }
129  else
130  return 0;
131 }
132 
133 
134 
136  QT4_DialogBox *dialogBox;
137 
138  dialogBox=dynamic_cast<QT4_DialogBox*>(getMainWindow());
139  if (dialogBox==NULL) {
140  DBG_INFO(0, "Dialog's main widget is not derived from class FXDialogBox");
141  return GWEN_ERROR_GENERIC;
142  }
143 
144  /* show dialog */
145  dialogBox->show();
146  /* gui update */
147  qApp->processEvents();
148 
149  return 0;
150 }
151 
152 
153 
155  QT4_DialogBox *dialogBox;
156 
157  dialogBox=dynamic_cast<QT4_DialogBox*>(getMainWindow());
158  if (dialogBox==NULL) {
159  DBG_INFO(0, "Dialog's main widget is not derived from class FXDialogBox");
160  return GWEN_ERROR_GENERIC;
161  }
162 
163  /* let dialog write its settings */
165 
166  /* hide dialog */
167  dialogBox->hide();
168  /* gui update */
169  qApp->processEvents();
170 
171  delete _mainWidget;
173 
174  return 0;
175 }
176 
177 
178 
179 int QT4_GuiDialog::runDialog(bool untilEnd) {
180  QT4_DialogBox *dialogBox;
181 
182  dialogBox=dynamic_cast<QT4_DialogBox*>(getMainWindow());
183  if (dialogBox==NULL) {
184  DBG_INFO(0, "Dialog's main widget is not derived from class FXDialogBox");
185  return GWEN_ERROR_GENERIC;
186  }
187 
188  if (untilEnd) {
189  dialogBox->cont();
190  }
191  else { {
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