00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "qt4_gui_dialog.hpp"
00011 #include "qt4dialogbox.hpp"
00012
00013 #include <gwenhywfar/dialog_be.h>
00014 #include <gwenhywfar/widget_be.h>
00015 #include <gwenhywfar/debug.h>
00016
00017 #include <QApplication>
00018 #include <QLabel>
00019 #include <QPushButton>
00020 #include <QLineEdit>
00021 #include <QTextEdit>
00022 #include <QTextBrowser>
00023 #include <QComboBox>
00024 #include <QGroupBox>
00025 #include <QProgressBar>
00026 #include <QHBoxLayout>
00027 #include <QVBoxLayout>
00028 #include <QGridLayout>
00029 #include <QFrame>
00030 #include <QTreeWidget>
00031 #include <QTabWidget>
00032 #include <QCheckBox>
00033 #include <QStackedWidget>
00034 #include <QScrollArea>
00035 #include <QSpinBox>
00036 #include <QRadioButton>
00037 #include <QHeaderView>
00038
00039 #include <QDebug>
00040
00041 #include <list>
00042 #include <string>
00043
00044
00045
00046
00047 #define QT4_DIALOG_WIDGET_REAL 0
00048 #define QT4_DIALOG_WIDGET_CONTENT 1
00049 #define QT4_DIALOG_WIDGET_LAYOUT 2
00050
00051 #define QT4_DIALOG_STRING_TITLE 0
00052 #define QT4_DIALOG_STRING_VALUE 1
00053
00054
00055
00056 #include "w_widget.cpp"
00057 #include "w_dialog.cpp"
00058 #include "w_vlayout.cpp"
00059 #include "w_hlayout.cpp"
00060 #include "w_gridlayout.cpp"
00061 #include "w_label.cpp"
00062 #include "w_lineedit.cpp"
00063 #include "w_pushbutton.cpp"
00064 #include "w_hline.cpp"
00065 #include "w_vline.cpp"
00066 #include "w_textedit.cpp"
00067 #include "w_combobox.cpp"
00068 #include "w_tabbook.cpp"
00069 #include "w_checkbox.cpp"
00070 #include "w_groupbox.cpp"
00071 #include "w_widgetstack.cpp"
00072 #include "w_textbrowser.cpp"
00073 #include "w_scrollarea.cpp"
00074 #include "w_progressbar.cpp"
00075 #include "w_listbox.cpp"
00076 #include "w_radiobutton.cpp"
00077 #include "w_spinbox.cpp"
00078
00079
00080
00081
00082 QT4_GuiDialog::QT4_GuiDialog(QT4_Gui *gui, GWEN_DIALOG *dlg)
00083 :CppDialog(dlg)
00084 ,_gui(gui)
00085 ,_mainWidget(NULL)
00086 {
00087
00088 }
00089
00090
00091
00092 QT4_GuiDialog::~QT4_GuiDialog() {
00093 if (_mainWidget)
00094 _mainWidget->unlinkFromDialog();
00095
00096 }
00097
00098
00099
00100 QT4_GuiDialog *QT4_GuiDialog::getDialog(GWEN_DIALOG *dlg) {
00101 CppDialog *cppDlg;
00102
00103 cppDlg=CppDialog::getDialog(dlg);
00104 if (cppDlg)
00105 return dynamic_cast<QT4_GuiDialog*>(cppDlg);
00106 return NULL;
00107 }
00108
00109
00110
00111 int QT4_GuiDialog::execute() {
00112 QT4_DialogBox *dialogBox;
00113 int rv;
00114
00115 dialogBox=dynamic_cast<QT4_DialogBox*>(getMainWindow());
00116 if (dialogBox==NULL) {
00117 DBG_INFO(0, "Dialog's main widget is not derived from class FXDialogBox");
00118 return GWEN_ERROR_GENERIC;
00119 }
00120
00121
00122 rv=dialogBox->exec();
00123 GWEN_Dialog_EmitSignalToAll(_dialog, GWEN_DialogEvent_TypeFini, "");
00124
00125 if (rv==QT4_DialogBox::Accepted) {
00126
00127 return 1;
00128 }
00129 else
00130 return 0;
00131 }
00132
00133
00134
00135 int QT4_GuiDialog::openDialog() {
00136 QT4_DialogBox *dialogBox;
00137
00138 dialogBox=dynamic_cast<QT4_DialogBox*>(getMainWindow());
00139 if (dialogBox==NULL) {
00140 DBG_INFO(0, "Dialog's main widget is not derived from class FXDialogBox");
00141 return GWEN_ERROR_GENERIC;
00142 }
00143
00144
00145 dialogBox->show();
00146
00147 qApp->processEvents();
00148
00149 return 0;
00150 }
00151
00152
00153
00154 int QT4_GuiDialog::closeDialog() {
00155 QT4_DialogBox *dialogBox;
00156
00157 dialogBox=dynamic_cast<QT4_DialogBox*>(getMainWindow());
00158 if (dialogBox==NULL) {
00159 DBG_INFO(0, "Dialog's main widget is not derived from class FXDialogBox");
00160 return GWEN_ERROR_GENERIC;
00161 }
00162
00163
00164 GWEN_Dialog_EmitSignalToAll(_dialog, GWEN_DialogEvent_TypeFini, "");
00165
00166
00167 dialogBox->hide();
00168
00169 qApp->processEvents();
00170
00171 delete _mainWidget;
00172 _mainWidget=NULL;
00173
00174 return 0;
00175 }
00176
00177
00178
00179 int QT4_GuiDialog::runDialog(bool untilEnd) {
00180 QT4_DialogBox *dialogBox;
00181
00182 dialogBox=dynamic_cast<QT4_DialogBox*>(getMainWindow());
00183 if (dialogBox==NULL) {
00184 DBG_INFO(0, "Dialog's main widget is not derived from class FXDialogBox");
00185 return GWEN_ERROR_GENERIC;
00186 }
00187
00188 if (untilEnd) {
00189 dialogBox->cont();
00190 }
00191 else { {
00192
00193 qApp->processEvents();
00194 }
00195 }
00196
00197 return 0;
00198 }
00199
00200
00201
00202 int QT4_GuiDialog::setIntProperty(GWEN_WIDGET *w,
00203 GWEN_DIALOG_PROPERTY prop,
00204 int index,
00205 int value,
00206 int doSignal) {
00207 return GWEN_Widget_SetIntProperty(w, prop, index, value, doSignal);
00208 }
00209
00210
00211
00212 int QT4_GuiDialog::getIntProperty(GWEN_WIDGET *w,
00213 GWEN_DIALOG_PROPERTY prop,
00214 int index,
00215 int defaultValue) {
00216 return GWEN_Widget_GetIntProperty(w, prop, index, defaultValue);
00217 }
00218
00219
00220
00221 int QT4_GuiDialog::setCharProperty(GWEN_WIDGET *w,
00222 GWEN_DIALOG_PROPERTY prop,
00223 int index,
00224 const char *value,
00225 int doSignal) {
00226 return GWEN_Widget_SetCharProperty(w, prop, index, value, doSignal);
00227 }
00228
00229
00230
00231 const char *QT4_GuiDialog::getCharProperty(GWEN_WIDGET *w,
00232 GWEN_DIALOG_PROPERTY prop,
00233 int index,
00234 const char *defaultValue) {
00235 return GWEN_Widget_GetCharProperty(w, prop, index, defaultValue);
00236 }
00237
00238
00239
00240 int QT4_GuiDialog::setupTree(GWEN_WIDGET *w) {
00241 int rv;
00242 Qt4_W_Widget *xw=NULL;
00243
00244 switch(GWEN_Widget_GetType(w)) {
00245 case GWEN_Widget_TypeDialog:
00246 xw=new Qt4_W_Dialog(w);
00247 break;
00248 case GWEN_Widget_TypeVLayout:
00249 xw=new Qt4_W_VLayout(w);
00250 break;
00251 case GWEN_Widget_TypeHLayout:
00252 xw=new Qt4_W_HLayout(w);
00253 break;
00254 case GWEN_Widget_TypeGridLayout:
00255 xw=new Qt4_W_GridLayout(w);
00256 break;
00257 case GWEN_Widget_TypeLabel:
00258 xw=new Qt4_W_Label(w);
00259 break;
00260 case GWEN_Widget_TypeLineEdit:
00261 xw=new Qt4_W_LineEdit(w);
00262 break;
00263 case GWEN_Widget_TypeVSpacer:
00264 case GWEN_Widget_TypeHSpacer:
00265
00266 xw=new Qt4_W_Widget(w);
00267 break;
00268 case GWEN_Widget_TypePushButton:
00269 xw=new Qt4_W_PushButton(w);
00270 break;
00271 case GWEN_Widget_TypeHLine:
00272 xw=new Qt4_W_HLine(w);
00273 break;
00274 case GWEN_Widget_TypeVLine:
00275 xw=new Qt4_W_VLine(w);
00276 break;
00277 case GWEN_Widget_TypeTextEdit:
00278 xw=new Qt4_W_TextEdit(w);
00279 break;
00280 case GWEN_Widget_TypeComboBox:
00281 xw=new Qt4_W_ComboBox(w);
00282 break;
00283 case GWEN_Widget_TypeTabBook:
00284 xw=new Qt4_W_TabBook(w);
00285 break;
00286 case GWEN_Widget_TypeTabPage:
00287 xw=new Qt4_W_VLayout(w);
00288 break;
00289 case GWEN_Widget_TypeCheckBox:
00290 xw=new Qt4_W_CheckBox(w);
00291 break;
00292 case GWEN_Widget_TypeGroupBox:
00293 xw=new Qt4_W_GroupBox(w);
00294 break;
00295 case GWEN_Widget_TypeWidgetStack:
00296 xw=new Qt4_W_WidgetStack(w);
00297 break;
00298 case GWEN_Widget_TypeTextBrowser:
00299 xw=new Qt4_W_TextBrowser(w);
00300 break;
00301 case GWEN_Widget_TypeScrollArea:
00302 xw=new Qt4_W_ScrollArea(w);
00303 break;
00304 case GWEN_Widget_TypeProgressBar:
00305 xw=new Qt4_W_ProgressBar(w);
00306 break;
00307 case GWEN_Widget_TypeListBox:
00308 xw=new Qt4_W_ListBox(w);
00309 break;
00310 case GWEN_Widget_TypeRadioButton:
00311 xw=new Qt4_W_RadioButton(w);
00312 break;
00313 case GWEN_Widget_TypeSpinBox:
00314 xw=new Qt4_W_SpinBox(w);
00315 break;
00316 default:
00317 DBG_ERROR(GWEN_LOGDOMAIN, "Unhandled widget type %d (%s)",
00318 GWEN_Widget_GetType(w), GWEN_Widget_Type_toString(GWEN_Widget_GetType(w)));
00319 break;
00320 }
00321
00322 if (xw==NULL) {
00323 DBG_ERROR(GWEN_LOGDOMAIN, "No widget created.");
00324 return GWEN_ERROR_INTERNAL;
00325 }
00326
00327 rv=xw->setup();
00328 if (rv<0) {
00329 DBG_INFO(GWEN_LOGDOMAIN, "here (%d)", rv);
00330 return rv;
00331 }
00332 else {
00333 GWEN_WIDGET *wChild;
00334
00335 if (GWEN_Widget_GetType(w)==GWEN_Widget_TypeDialog)
00336 _mainWidget=(QT4_DialogBox*) GWEN_Widget_GetImplData(xw->getCInterface(), QT4_DIALOG_WIDGET_REAL);
00337
00338
00339 wChild=GWEN_Widget_Tree_GetFirstChild(w);
00340 while(wChild) {
00341
00342 rv=setupTree(wChild);
00343 if (rv<0) {
00344 DBG_INFO(GWEN_LOGDOMAIN, "here (%d)", rv);
00345 return rv;
00346 }
00347 wChild=GWEN_Widget_Tree_GetNext(wChild);
00348 }
00349 }
00350
00351 return 0;
00352 }
00353
00354
00355 bool QT4_GuiDialog::setup(QWidget *parentWindow) {
00356 GWEN_WIDGET_TREE *wtree;
00357 GWEN_WIDGET *w;
00358 int rv;
00359
00360 wtree=GWEN_Dialog_GetWidgets(_dialog);
00361 if (wtree==NULL) {
00362 DBG_ERROR(GWEN_LOGDOMAIN, "No widget tree in dialog");
00363 return false;
00364 }
00365 w=GWEN_Widget_Tree_GetFirst(wtree);
00366 if (w==NULL) {
00367 DBG_ERROR(GWEN_LOGDOMAIN, "No widgets in dialog");
00368 return false;
00369 }
00370
00371 rv=setupTree(w);
00372 if (rv<0) {
00373 DBG_ERROR(GWEN_LOGDOMAIN, "here (%d)", rv);
00374 return false;
00375 }
00376
00377 _mainWidget=(QT4_DialogBox*) GWEN_Widget_GetImplData(w, QT4_DIALOG_WIDGET_REAL);
00378
00379 rv=GWEN_Dialog_EmitSignalToAll(_dialog, GWEN_DialogEvent_TypeInit, "");
00380 if (rv<0) {
00381 DBG_INFO(0, "Error initializing dialog: %d", rv);
00382 return false;
00383 }
00384
00385
00386 return true;
00387 }
00388
00389
00390
00391
00392