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 <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
80
81
82
84 if (_mainWidget)
85 _mainWidget->unlinkFromDialog();
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
170int 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;
309#warning "Creating HLayout instead of HSplitter until implemented"
310 DBG_ERROR(GWEN_LOGDOMAIN, "HSplitter not implemented, using HLayout instead");
311 xw=new Qt5_W_HLayout(w);
312 break;
314#warning "Creating VLayout instead of VSplitter until implemented"
315 DBG_ERROR(GWEN_LOGDOMAIN, "VSplitter not implemented, using VLayout instead");
316 xw=new Qt5_W_VLayout(w);
317 break;
318 default:
319 DBG_ERROR(GWEN_LOGDOMAIN, "Unhandled widget type %d (%s)",
321 break;
322 }
323
324 if (xw==NULL) {
325 DBG_ERROR(GWEN_LOGDOMAIN, "No widget created.");
326 return GWEN_ERROR_INTERNAL;
327 }
328
329 rv=xw->setup();
330 if (rv<0) {
331 DBG_INFO(GWEN_LOGDOMAIN, "here (%d)", rv);
332 return rv;
333 }
334 else {
335 GWEN_WIDGET *wChild;
336
339
340 /* handle children */
341 wChild=GWEN_Widget_Tree_GetFirstChild(w);
342 while(wChild) {
343 /* recursion */
344 rv=setupTree(wChild);
345 if (rv<0) {
346 DBG_INFO(GWEN_LOGDOMAIN, "here (%d)", rv);
347 return rv;
348 }
349 wChild=GWEN_Widget_Tree_GetNext(wChild);
350 }
351 }
352
353 return 0;
354}
355
356
357bool QT5_GuiDialog::setup(GWEN_UNUSED QWidget *parentWindow) {
358 GWEN_WIDGET_TREE *wtree;
359 GWEN_WIDGET *w;
360 int rv;
361
363 if (wtree==NULL) {
364 DBG_ERROR(GWEN_LOGDOMAIN, "No widget tree in dialog");
365 return false;
366 }
367 w=GWEN_Widget_Tree_GetFirst(wtree);
368 if (w==NULL) {
369 DBG_ERROR(GWEN_LOGDOMAIN, "No widgets in dialog");
370 return false;
371 }
372
373 rv=setupTree(w);
374 if (rv<0) {
375 DBG_ERROR(GWEN_LOGDOMAIN, "here (%d)", rv);
376 return false;
377 }
378
380
382 if (rv<0) {
383 DBG_INFO(0, "Error initializing dialog: %d", rv);
384 return false;
385 }
386
387
388 return true;
389}
390
391
392
393
394
#define NULL
Definition binreloc.c:300
CppDialog(GWEN_DIALOG *dlg)
GWEN_DIALOG * _dialog
Definition cppdialog.hpp:50
static CPPGUI_API CppDialog * getDialog(GWEN_DIALOG *dlg)
GWEN_WIDGET * getCInterface()
virtual int setIntProperty(GWEN_WIDGET *w, GWEN_DIALOG_PROPERTY prop, int index, int value, int doSignal)
bool setup(QWidget *parentWindow)
int runDialog(bool untilEnd)
QT5_DialogBox * getMainWindow()
virtual const char * getCharProperty(GWEN_WIDGET *w, GWEN_DIALOG_PROPERTY prop, int index, const char *defaultValue)
virtual int setCharProperty(GWEN_WIDGET *w, GWEN_DIALOG_PROPERTY prop, int index, const char *value, int doSignal)
int setupTree(GWEN_WIDGET *w)
QT5_DialogBox * _mainWidget
QT5_GuiDialog(QT5_Gui *gui, GWEN_DIALOG *dlg)
static QT5_GuiDialog * getDialog(GWEN_DIALOG *dlg)
virtual ~QT5_GuiDialog()
virtual int getIntProperty(GWEN_WIDGET *w, GWEN_DIALOG_PROPERTY prop, int index, int defaultValue)
virtual int setup()
#define DBG_INFO(dbg_logger, format,...)
Definition debug.h:181
#define DBG_ERROR(dbg_logger, format,...)
Definition debug.h:97
GWEN_WIDGET_TREE * GWEN_Dialog_GetWidgets(const GWEN_DIALOG *dlg)
Definition dialog.c:629
int GWEN_Dialog_EmitSignalToAll(GWEN_DIALOG *dlg, GWEN_DIALOG_EVENTTYPE t, const char *sender)
Definition dialog.c:330
struct GWEN_DIALOG GWEN_DIALOG
Definition dialog.h:54
GWEN_DIALOG_PROPERTY
Definition dialog.h:260
@ GWEN_DialogEvent_TypeInit
Definition dialog.h:99
@ GWEN_DialogEvent_TypeFini
Definition dialog.h:100
#define GWEN_ERROR_INTERNAL
Definition error.h:125
#define GWEN_ERROR_GENERIC
Definition error.h:62
#define GWEN_UNUSED
#define GWEN_LOGDOMAIN
Definition logger.h:32
#define QT5_DIALOG_WIDGET_REAL
int GWEN_Widget_SetIntProperty(GWEN_WIDGET *w, GWEN_DIALOG_PROPERTY prop, int index, int value, int doSignal)
Definition widget.c:770
int GWEN_Widget_SetCharProperty(GWEN_WIDGET *w, GWEN_DIALOG_PROPERTY prop, int index, const char *value, int doSignal)
Definition widget.c:803
void * GWEN_Widget_GetImplData(const GWEN_WIDGET *w, int index)
Definition widget.c:122
int GWEN_Widget_GetIntProperty(GWEN_WIDGET *w, GWEN_DIALOG_PROPERTY prop, int index, int defaultValue)
Definition widget.c:787
const char * GWEN_Widget_GetCharProperty(GWEN_WIDGET *w, GWEN_DIALOG_PROPERTY prop, int index, const char *defaultValue)
Definition widget.c:820
const char * GWEN_Widget_Type_toString(GWEN_WIDGET_TYPE t)
Definition widget.c:456
GWEN_WIDGET_TYPE GWEN_Widget_GetType(const GWEN_WIDGET *w)
Definition widget.c:185
struct GWEN_WIDGET GWEN_WIDGET
Definition widget_be.h:34
@ GWEN_Widget_TypeTabBook
Definition widget_be.h:67
@ GWEN_Widget_TypeHSplitter
Definition widget_be.h:76
@ GWEN_Widget_TypeComboBox
Definition widget_be.h:56
@ GWEN_Widget_TypeTabPage
Definition widget_be.h:68
@ GWEN_Widget_TypeRadioButton
Definition widget_be.h:57
@ GWEN_Widget_TypeHLayout
Definition widget_be.h:62
@ GWEN_Widget_TypeLineEdit
Definition widget_be.h:54
@ GWEN_Widget_TypeWidgetStack
Definition widget_be.h:70
@ GWEN_Widget_TypeScrollArea
Definition widget_be.h:71
@ GWEN_Widget_TypeLabel
Definition widget_be.h:52
@ GWEN_Widget_TypeGroupBox
Definition widget_be.h:59
@ GWEN_Widget_TypeDialog
Definition widget_be.h:66
@ GWEN_Widget_TypePushButton
Definition widget_be.h:53
@ GWEN_Widget_TypeCheckBox
Definition widget_be.h:69
@ GWEN_Widget_TypeTextBrowser
Definition widget_be.h:74
@ GWEN_Widget_TypeHSpacer
Definition widget_be.h:60
@ GWEN_Widget_TypeHLine
Definition widget_be.h:72
@ GWEN_Widget_TypeVSplitter
Definition widget_be.h:77
@ GWEN_Widget_TypeTextEdit
Definition widget_be.h:55
@ GWEN_Widget_TypeGridLayout
Definition widget_be.h:64
@ GWEN_Widget_TypeVLayout
Definition widget_be.h:63
@ GWEN_Widget_TypeProgressBar
Definition widget_be.h:58
@ GWEN_Widget_TypeSpinBox
Definition widget_be.h:75
@ GWEN_Widget_TypeVSpacer
Definition widget_be.h:61
@ GWEN_Widget_TypeVLine
Definition widget_be.h:73
@ GWEN_Widget_TypeListBox
Definition widget_be.h:65