1 /***************************************************************************
2     begin       : Tue Feb 16 2010
3     copyright   : (C) 2010 by Martin Preuss
4                   (C) 2016 by Christian David
5     email       : martin@libchipcard.de
6                   christian-david@web.de
7 
8  ***************************************************************************
9  *          Please see toplevel file COPYING for license details           *
10  ***************************************************************************/
11 
12 #ifdef HAVE_CONFIG_H
13 # include <config.h>
14 #endif
15 
16 
17 
18 #include "qt5dialogbox.hpp"
19 #include "qt5_gui_dialog.hpp"
20 
21 #include <QCloseEvent>
22 
23 #include <gwenhywfar/debug.h>
24 
25 
QT5_DialogBox(QT5_GuiDialog * dialog,QWidget * parent,bool modal,Qt::WindowFlags f)26 QT5_DialogBox::QT5_DialogBox(QT5_GuiDialog *dialog,
27                              QWidget *parent,
28                              bool modal,
29                              Qt::WindowFlags f)
30   :QDialog(parent, f)
31   ,_dialog(dialog) {
32   setModal(modal);
33 }
34 
35 
36 
~QT5_DialogBox()37 QT5_DialogBox::~QT5_DialogBox() {
38 }
39 
40 
41 
accept()42 void QT5_DialogBox::accept() {
43   QDialog::accept();
44 }
45 
46 
47 
reject()48 void QT5_DialogBox::reject() {
49   QDialog::reject();
50 }
51 
52 
53 
cont()54 int QT5_DialogBox::cont() {
55   return exec();
56 }
57 
58 
59 
closeEvent(QCloseEvent * e)60 void QT5_DialogBox::closeEvent(QCloseEvent *e) {
61   if (_dialog) {
62     int rv;
63 
64     rv=GWEN_Dialog_EmitSignal(_dialog->getCInterface(), GWEN_DialogEvent_TypeClose, "");
65     if (rv!=GWEN_DialogEvent_ResultReject) {
66       e->accept();
67     }
68   }
69   else {
70     e->accept();
71   }
72 }
73 
74 
75 
unlinkFromDialog()76 void QT5_DialogBox::unlinkFromDialog() {
77   _dialog=NULL;
78 }
79 
80 
81 
slotActivated()82 void QT5_DialogBox::slotActivated() {
83   const QObject *snd;
84 
85   snd=sender();
86   if (snd) {
87     GWEN_WIDGET *w;
88     const char *wname;
89     int rv=GWEN_DialogEvent_ResultNotHandled;
90 
91     w=GWEN_Dialog_FindWidgetByImplData(_dialog->getCInterface(), QT5_DIALOG_WIDGET_REAL, snd);
92     if (w==NULL) {
93       DBG_INFO(0, "Widget not found");
94       return;
95     }
96     wname=GWEN_Widget_GetName(w);
97 
98     DBG_INFO(GWEN_LOGDOMAIN, "Command for [%s] (type: %s)",
99              wname?wname:"(unnamed)",
100              GWEN_Widget_Type_toString(GWEN_Widget_GetType(w)));
101 
102     switch(GWEN_Widget_GetType(w)) {
103     case GWEN_Widget_TypeUnknown:
104     case GWEN_Widget_TypeNone:
105       break;
106 
107     case GWEN_Widget_TypePushButton:
108     case GWEN_Widget_TypeLineEdit:
109     case GWEN_Widget_TypeComboBox:
110     case GWEN_Widget_TypeListBox:
111     case GWEN_Widget_TypeCheckBox:
112     case GWEN_Widget_TypeLabel:
113     case GWEN_Widget_TypeTextEdit:
114     case GWEN_Widget_TypeSpinBox:
115       rv=GWEN_Dialog_EmitSignal(GWEN_Widget_GetDialog(w),
116                                 GWEN_DialogEvent_TypeActivated,
117                                 GWEN_Widget_GetName(w));
118       break;
119     case GWEN_Widget_TypeRadioButton:
120     case GWEN_Widget_TypeProgressBar:
121     case GWEN_Widget_TypeGroupBox:
122     case GWEN_Widget_TypeHSpacer:
123     case GWEN_Widget_TypeVSpacer:
124     case GWEN_Widget_TypeHLayout:
125     case GWEN_Widget_TypeVLayout:
126     case GWEN_Widget_TypeGridLayout:
127     case GWEN_Widget_TypeDialog:
128     case GWEN_Widget_TypeTabBook:
129     case GWEN_Widget_TypeTabPage:
130     case GWEN_Widget_TypeScrollArea:
131     case GWEN_Widget_TypeWidgetStack:
132     case GWEN_Widget_TypeHLine:
133     case GWEN_Widget_TypeVLine:
134     case GWEN_Widget_TypeTextBrowser:
135       /* nothing to do for these types */
136       ;
137     }
138 
139     if (rv==GWEN_DialogEvent_ResultAccept) {
140       accept();
141     }
142     else if (rv==GWEN_DialogEvent_ResultReject) {
143       reject();
144     }
145   }
146 }
147 
148 
149 
slotValueChanged()150 void QT5_DialogBox::slotValueChanged() {
151   const QObject *snd;
152 
153   snd=sender();
154   if (snd) {
155     GWEN_WIDGET *w;
156     const char *wname;
157     int rv=GWEN_DialogEvent_ResultNotHandled;
158 
159     w=GWEN_Dialog_FindWidgetByImplData(_dialog->getCInterface(), QT5_DIALOG_WIDGET_REAL, snd);
160     if (w==NULL) {
161       DBG_INFO(0, "Widget not found");
162       return;
163     }
164     wname=GWEN_Widget_GetName(w);
165 
166     DBG_INFO(GWEN_LOGDOMAIN, "ValueChanged for [%s] (type: %s)",
167              wname?wname:"(unnamed)",
168              GWEN_Widget_Type_toString(GWEN_Widget_GetType(w)));
169 
170     switch(GWEN_Widget_GetType(w)) {
171     case GWEN_Widget_TypeUnknown:
172     case GWEN_Widget_TypeNone:
173       break;
174 
175     case GWEN_Widget_TypePushButton:
176     case GWEN_Widget_TypeLineEdit:
177     case GWEN_Widget_TypeComboBox:
178     case GWEN_Widget_TypeListBox:
179     case GWEN_Widget_TypeCheckBox:
180     case GWEN_Widget_TypeLabel:
181     case GWEN_Widget_TypeTextEdit:
182     case GWEN_Widget_TypeSpinBox:
183       rv=GWEN_Dialog_EmitSignal(GWEN_Widget_GetDialog(w),
184                                 GWEN_DialogEvent_TypeValueChanged,
185                                 GWEN_Widget_GetName(w));
186       break;
187 
188     case GWEN_Widget_TypeRadioButton:
189     case GWEN_Widget_TypeProgressBar:
190     case GWEN_Widget_TypeGroupBox:
191     case GWEN_Widget_TypeHSpacer:
192     case GWEN_Widget_TypeVSpacer:
193     case GWEN_Widget_TypeHLayout:
194     case GWEN_Widget_TypeVLayout:
195     case GWEN_Widget_TypeGridLayout:
196     case GWEN_Widget_TypeDialog:
197     case GWEN_Widget_TypeTabBook:
198     case GWEN_Widget_TypeTabPage:
199     case GWEN_Widget_TypeScrollArea:
200     case GWEN_Widget_TypeWidgetStack:
201     case GWEN_Widget_TypeHLine:
202     case GWEN_Widget_TypeVLine:
203     case GWEN_Widget_TypeTextBrowser:
204       /* nothing to do for these types */
205       ;
206     }
207 
208     if (rv==GWEN_DialogEvent_ResultAccept) {
209       accept();
210     }
211     else if (rv==GWEN_DialogEvent_ResultReject) {
212       reject();
213     }
214   }
215 }
216 
217 #include "qt5dialogbox.moc"
218