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