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 Qt4_W_ComboBox: public Qt4_W_Widget {
15 public:
Qt4_W_ComboBox(GWEN_WIDGET * w)16   Qt4_W_ComboBox(GWEN_WIDGET *w):Qt4_W_Widget(w) {
17   }
18 
19 
20 
~Qt4_W_ComboBox()21   ~Qt4_W_ComboBox() {
22   }
23 
24 
25 
setup()26   virtual int setup() {
27     QComboBox *qw;
28     uint32_t flags;
29     GWEN_WIDGET *wParent;
30     QSizePolicy::Policy hpolicy=QSizePolicy::Minimum;
31     QSizePolicy::Policy vpolicy=QSizePolicy::Minimum;
32     QT4_GuiDialog *qtDialog;
33 
34     flags=GWEN_Widget_GetFlags(_widget);
35     wParent=GWEN_Widget_Tree_GetParent(_widget);
36 
37     qw=new QComboBox();
38 
39     /* handle flags */
40     if (flags & GWEN_WIDGET_FLAGS_FILLX)
41       hpolicy=QSizePolicy::Expanding;
42     if (flags & GWEN_WIDGET_FLAGS_FILLY)
43       vpolicy=QSizePolicy::Expanding;
44     qw->setSizePolicy(hpolicy, vpolicy);
45     qw->setEditable((flags & GWEN_WIDGET_FLAGS_READONLY)?false:true);
46 
47     GWEN_Widget_SetImplData(_widget, QT4_DIALOG_WIDGET_REAL, (void*) qw);
48 
49     qtDialog=dynamic_cast<QT4_GuiDialog*>(getDialog());
50     assert(qtDialog);
51 
52     qw->connect(qw, SIGNAL(activated(int)),
53                 qtDialog->getMainWindow(),
54                 SLOT(slotActivated()));
55 
56 
57     if (wParent)
58       GWEN_Widget_AddChildGuiWidget(wParent, _widget);
59     return 0;
60   }
61 
62 
63 
setIntProperty(GWEN_DIALOG_PROPERTY prop,int index,int value,int doSignal)64   int setIntProperty(GWEN_DIALOG_PROPERTY prop,
65                      int index,
66                      int value,
67                      int doSignal) {
68     QComboBox *qw;
69 
70     qw=(QComboBox*) GWEN_Widget_GetImplData(_widget, QT4_DIALOG_WIDGET_REAL);
71     assert(qw);
72 
73     switch(prop) {
74     case GWEN_DialogProperty_Value:
75       qw->setCurrentIndex(value);
76       return 0;
77 
78     case GWEN_DialogProperty_ClearValues:
79       qw->clear();
80       return 0;
81 
82     default:
83       return Qt4_W_Widget::setIntProperty(prop, index, value, doSignal);
84     }
85   };
86 
87 
88 
getIntProperty(GWEN_DIALOG_PROPERTY prop,int index,int defaultValue)89   int getIntProperty(GWEN_DIALOG_PROPERTY prop,
90                      int index,
91                      int defaultValue) {
92     QComboBox *qw;
93 
94     qw=(QComboBox*) GWEN_Widget_GetImplData(_widget, QT4_DIALOG_WIDGET_REAL);
95     assert(qw);
96 
97     switch(prop) {
98     case GWEN_DialogProperty_Value:
99       return qw->currentIndex();
100 
101     case GWEN_DialogProperty_ValueCount:
102       return qw->count();
103 
104     default:
105       return Qt4_W_Widget::getIntProperty(prop, index, defaultValue);
106     }
107   };
108 
109 
110 
setCharProperty(GWEN_DIALOG_PROPERTY prop,int index,const char * value,int doSignal)111   int setCharProperty(GWEN_DIALOG_PROPERTY prop,
112                       int index,
113                       const char *value,
114                       int doSignal) {
115     QComboBox *qw;
116     QString text;
117 
118     qw=(QComboBox*) GWEN_Widget_GetImplData(_widget, QT4_DIALOG_WIDGET_REAL);
119     assert(qw);
120 
121     if (value)
122       text=QString::fromUtf8(value);
123 
124     switch(prop) {
125     case GWEN_DialogProperty_Value:
126       // undefined
127       break;
128 
129     case GWEN_DialogProperty_AddValue:
130       qw->addItem(text);
131       return 0;
132 
133     case GWEN_DialogProperty_ClearValues:
134       qw->clear();
135       return 0;
136     default:
137       break;
138     }
139 
140     DBG_WARN(GWEN_LOGDOMAIN,
141              "Function is not appropriate for this type of widget (%s)",
142              GWEN_Widget_Type_toString(GWEN_Widget_GetType(_widget)));
143     return GWEN_ERROR_INVALID;
144   };
145 
146 
147 
getCharProperty(GWEN_DIALOG_PROPERTY prop,int index,const char * defaultValue)148   const char *getCharProperty(GWEN_DIALOG_PROPERTY prop,
149                               int index,
150                               const char *defaultValue) {
151     QComboBox *qw;
152     QString str;
153 
154     qw=(QComboBox*) GWEN_Widget_GetImplData(_widget, QT4_DIALOG_WIDGET_REAL);
155     assert(qw);
156 
157     switch(prop) {
158     case GWEN_DialogProperty_Value:
159       str=qw->itemText(index);
160       if (str.isEmpty())
161         return defaultValue;
162       else {
163         GWEN_Widget_SetText(_widget, QT4_DIALOG_STRING_TITLE, str.toUtf8());
164         return GWEN_Widget_GetText(_widget, QT4_DIALOG_STRING_TITLE);
165       }
166       break;
167 
168     default:
169       break;
170     }
171 
172     DBG_WARN(GWEN_LOGDOMAIN,
173              "Function is not appropriate for this type of widget (%s)",
174              GWEN_Widget_Type_toString(GWEN_Widget_GetType(_widget)));
175     return defaultValue;
176   };
177 
178 };
179 
180 
181 
182 
183 
184 
185 
186