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_PushButton: public Qt5_W_Widget {
15 public:
Qt5_W_PushButton(GWEN_WIDGET * w)16   Qt5_W_PushButton(GWEN_WIDGET *w):Qt5_W_Widget(w) {
17   }
18 
19 
20 
~Qt5_W_PushButton()21   ~Qt5_W_PushButton() {
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     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 QPushButton(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(clicked(bool)),
57                 qtDialog->getMainWindow(),
58                 SLOT(slotActivated()));
59 
60     if (wParent)
61       GWEN_Widget_AddChildGuiWidget(wParent, _widget);
62     return 0;
63   }
64 
65 
66 
setCharProperty(GWEN_DIALOG_PROPERTY prop,GWEN_UNUSED int index,const char * value,GWEN_UNUSED int doSignal)67   int setCharProperty(GWEN_DIALOG_PROPERTY prop,
68                       GWEN_UNUSED int index,
69                       const char *value,
70                       GWEN_UNUSED int doSignal) {
71     QPushButton *qw;
72     QString text;
73 
74     qw=(QPushButton*) GWEN_Widget_GetImplData(_widget, QT5_DIALOG_WIDGET_REAL);
75     assert(qw);
76 
77     if (value)
78       text=QString::fromUtf8(value);
79 
80     switch(prop) {
81     case GWEN_DialogProperty_Title:
82       qw->setText(text);
83       return 0;
84     default:
85       break;
86     }
87 
88     DBG_WARN(GWEN_LOGDOMAIN,
89              "Function is not appropriate for this type of widget (%s)",
90              GWEN_Widget_Type_toString(GWEN_Widget_GetType(_widget)));
91     return GWEN_ERROR_INVALID;
92   };
93 
94 
95 
getCharProperty(GWEN_DIALOG_PROPERTY prop,GWEN_UNUSED int index,const char * defaultValue)96   const char *getCharProperty(GWEN_DIALOG_PROPERTY prop,
97                               GWEN_UNUSED int index,
98                               const char *defaultValue) {
99     QPushButton *qw;
100     QString str;
101 
102     qw=(QPushButton*) GWEN_Widget_GetImplData(_widget, QT5_DIALOG_WIDGET_REAL);
103     assert(qw);
104 
105     switch(prop) {
106     case GWEN_DialogProperty_Title:
107       str=qw->text();
108       if (str.isEmpty())
109         return defaultValue;
110       else {
111         GWEN_Widget_SetText(_widget, QT5_DIALOG_STRING_TITLE, str.toUtf8());
112         return GWEN_Widget_GetText(_widget, QT5_DIALOG_STRING_TITLE);
113       }
114       break;
115 
116     default:
117       break;
118     }
119 
120     DBG_WARN(GWEN_LOGDOMAIN,
121              "Function is not appropriate for this type of widget (%s)",
122              GWEN_Widget_Type_toString(GWEN_Widget_GetType(_widget)));
123     return defaultValue;
124   };
125 
126 };
127 
128 
129 
130 
131 
132 
133 
134