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 
11 #include <gwen-gui-cpp/cppwidget.hpp>
12 
13 
14 class Qt5_W_Widget: public CppWidget {
15 public:
Qt5_W_Widget(GWEN_WIDGET * w)16   Qt5_W_Widget(GWEN_WIDGET *w):CppWidget(w) {
17   }
18 
19 
20 
~Qt5_W_Widget()21   ~Qt5_W_Widget() {
22   }
23 
24 
25 
setup()26   virtual int setup() {
27     QWidget *qw;
28     uint32_t flags;
29     GWEN_WIDGET *wParent;
30     QSizePolicy::Policy hpolicy=QSizePolicy::Minimum;
31     QSizePolicy::Policy vpolicy=QSizePolicy::Minimum;
32 
33     flags=GWEN_Widget_GetFlags(_widget);
34     wParent=GWEN_Widget_Tree_GetParent(_widget);
35 
36     qw=new QWidget();
37 
38     /* handle flags */
39     if (flags & GWEN_WIDGET_FLAGS_FILLX)
40       hpolicy=QSizePolicy::Expanding;
41     if (flags & GWEN_WIDGET_FLAGS_FILLY)
42       vpolicy=QSizePolicy::Expanding;
43     qw->setSizePolicy(hpolicy, vpolicy);
44 
45     GWEN_Widget_SetImplData(_widget, QT5_DIALOG_WIDGET_REAL, (void*) qw);
46     GWEN_Widget_SetImplData(_widget, QT5_DIALOG_WIDGET_CONTENT, (void*) qw);
47 
48     if (wParent)
49       GWEN_Widget_AddChildGuiWidget(wParent, _widget);
50     return 0;
51   }
52 
53 
54 
getQWidget(GWEN_WIDGET * w)55   static QWidget *getQWidget(GWEN_WIDGET *w) {
56     QWidget *qw;
57 
58     qw=(QWidget*) GWEN_Widget_GetImplData(w, QT5_DIALOG_WIDGET_REAL);
59     assert(qw);
60 
61     return qw;
62   }
63 
64 
setIntProperty(GWEN_DIALOG_PROPERTY prop,GWEN_UNUSED int index,int value,GWEN_UNUSED int doSignal)65   int setIntProperty(GWEN_DIALOG_PROPERTY prop,
66                      GWEN_UNUSED int index,
67                      int value,
68                      GWEN_UNUSED int doSignal) {
69     QWidget *qw;
70 
71     qw=(QWidget*) GWEN_Widget_GetImplData(_widget, QT5_DIALOG_WIDGET_REAL);
72     assert(qw);
73 
74     switch(prop) {
75     case GWEN_DialogProperty_Width:
76       qw->resize(value, qw->height());
77       return 0;
78 
79     case GWEN_DialogProperty_Height:
80       qw->resize(qw->width(), value);
81       return 0;
82 
83     case GWEN_DialogProperty_Enabled:
84       qw->setEnabled((value==0)?false:true);
85       return 0;
86 
87     case GWEN_DialogProperty_Focus:
88       qw->setFocus();
89       return 0;
90 
91     case GWEN_DialogProperty_Visibility:
92       if (value==0)
93         qw->hide();
94       else
95         qw->show();
96       return 0;
97 
98     default:
99       break;
100     }
101 
102     DBG_WARN(GWEN_LOGDOMAIN,
103              "Function is not appropriate for this type of widget (%s)",
104              GWEN_Widget_Type_toString(GWEN_Widget_GetType(_widget)));
105     return GWEN_ERROR_INVALID;
106   };
107 
108 
109 
getIntProperty(GWEN_DIALOG_PROPERTY prop,GWEN_UNUSED int index,int defaultValue)110   int getIntProperty(GWEN_DIALOG_PROPERTY prop,
111                      GWEN_UNUSED int index,
112                      int defaultValue) {
113     QWidget *qw;
114 
115     qw=(QWidget*) GWEN_Widget_GetImplData(_widget, QT5_DIALOG_WIDGET_REAL);
116     assert(qw);
117 
118     switch(prop) {
119     case GWEN_DialogProperty_Width:
120       return qw->width();
121 
122     case GWEN_DialogProperty_Height:
123       return qw->height();
124 
125     case GWEN_DialogProperty_Enabled:
126       return (qw->isEnabled())?1:0;
127 
128     case GWEN_DialogProperty_Focus:
129       return (qw->hasFocus())?1:0;
130 
131     default:
132       break;
133     }
134 
135     DBG_WARN(GWEN_LOGDOMAIN,
136              "Function is not appropriate for this type of widget (%s)",
137              GWEN_Widget_Type_toString(GWEN_Widget_GetType(_widget)));
138     return defaultValue;
139   };
140 
141 
142 
setCharProperty(GWEN_UNUSED GWEN_DIALOG_PROPERTY prop,GWEN_UNUSED int index,GWEN_UNUSED const char * value,GWEN_UNUSED int doSignal)143   int setCharProperty(GWEN_UNUSED GWEN_DIALOG_PROPERTY prop,
144                       GWEN_UNUSED int index,
145                       GWEN_UNUSED const char *value,
146                       GWEN_UNUSED int doSignal) {
147     DBG_WARN(GWEN_LOGDOMAIN,
148              "Function is not appropriate for this type of widget (%s)",
149              GWEN_Widget_Type_toString(GWEN_Widget_GetType(_widget)));
150     return GWEN_ERROR_INVALID;
151   };
152 
153 
154 
getCharProperty(GWEN_UNUSED GWEN_DIALOG_PROPERTY prop,GWEN_UNUSED int index,const char * defaultValue)155   const char *getCharProperty(GWEN_UNUSED GWEN_DIALOG_PROPERTY prop,
156                               GWEN_UNUSED int index,
157                               const char *defaultValue) {
158     DBG_WARN(GWEN_LOGDOMAIN,
159              "Function is not appropriate for this type of widget (%s)",
160              GWEN_Widget_Type_toString(GWEN_Widget_GetType(_widget)));
161     return defaultValue;
162   };
163 
164 };
165 
166 
167 
168 
169 
170 
171 
172