gwenhywfar 4.0.3

w_label.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002     begin       : Mon Feb 15 2010
00003     copyright   : (C) 2010 by Martin Preuss
00004     email       : martin@libchipcard.de
00005 
00006  ***************************************************************************
00007  *          Please see toplevel file COPYING for license details           *
00008  ***************************************************************************/
00009 
00010 
00011 #include <gwen-gui-cpp/cppwidget.hpp>
00012 
00013 
00014 class Qt4_W_Label: public Qt4_W_Widget {
00015 public:
00016   Qt4_W_Label(GWEN_WIDGET *w):Qt4_W_Widget(w) {
00017   }
00018 
00019 
00020 
00021   ~Qt4_W_Label() {
00022   }
00023 
00024 
00025 
00026   virtual int setup() {
00027     QWidget *qw;
00028     uint32_t flags;
00029     GWEN_WIDGET *wParent;
00030     QSizePolicy::Policy hpolicy=QSizePolicy::Minimum;
00031     QSizePolicy::Policy vpolicy=QSizePolicy::Minimum;
00032     const char *s;
00033     QString text;
00034 
00035     flags=GWEN_Widget_GetFlags(_widget);
00036     wParent=GWEN_Widget_Tree_GetParent(_widget);
00037     s=GWEN_Widget_GetText(_widget, 0);
00038     if (s)
00039       text=QT4_Gui::extractHtml(s);
00040 
00041     qw=new QLabel(text);
00042 
00043     /* handle flags */
00044     if (flags & GWEN_WIDGET_FLAGS_FILLX)
00045       hpolicy=QSizePolicy::Expanding;
00046     if (flags & GWEN_WIDGET_FLAGS_FILLY)
00047       vpolicy=QSizePolicy::Expanding;
00048     qw->setSizePolicy(hpolicy, vpolicy);
00049 
00050     GWEN_Widget_SetImplData(_widget, QT4_DIALOG_WIDGET_REAL, (void*) qw);
00051 
00052     if (wParent)
00053       GWEN_Widget_AddChildGuiWidget(wParent, _widget);
00054     return 0;
00055   }
00056 
00057 
00058 
00059   int setCharProperty(GWEN_DIALOG_PROPERTY prop,
00060                       int index,
00061                       const char *value,
00062                       int doSignal) {
00063     QLabel *qw;
00064     QString text;
00065 
00066     qw=(QLabel*) GWEN_Widget_GetImplData(_widget, QT4_DIALOG_WIDGET_REAL);
00067     assert(qw);
00068 
00069     if (value)
00070       text=QT4_Gui::extractHtml(value);
00071 
00072     switch(prop) {
00073     case GWEN_DialogProperty_Title:
00074       qw->setText(text);
00075       return 0;
00076     default:
00077       break;
00078     }
00079 
00080     DBG_WARN(GWEN_LOGDOMAIN,
00081              "Function is not appropriate for this type of widget (%s)",
00082              GWEN_Widget_Type_toString(GWEN_Widget_GetType(_widget)));
00083     return GWEN_ERROR_INVALID;
00084   };
00085 
00086 
00087 
00088   const char *getCharProperty(GWEN_DIALOG_PROPERTY prop,
00089                               int index,
00090                               const char *defaultValue) {
00091     QLabel *qw;
00092     QString str;
00093 
00094     qw=(QLabel*) GWEN_Widget_GetImplData(_widget, QT4_DIALOG_WIDGET_REAL);
00095     assert(qw);
00096 
00097     switch(prop) {
00098     case GWEN_DialogProperty_Title:
00099       str=qw->text();
00100       if (str.isEmpty())
00101         return defaultValue;
00102       else {
00103         GWEN_Widget_SetText(_widget, QT4_DIALOG_STRING_TITLE, str.toUtf8());
00104         return GWEN_Widget_GetText(_widget, QT4_DIALOG_STRING_TITLE);
00105       }
00106       break;
00107 
00108     default:
00109       break;
00110     }
00111 
00112     DBG_WARN(GWEN_LOGDOMAIN,
00113              "Function is not appropriate for this type of widget (%s)",
00114              GWEN_Widget_Type_toString(GWEN_Widget_GetType(_widget)));
00115     return defaultValue;
00116   };
00117 
00118 };
00119 
00120 
00121 
00122 
00123 
00124 
00125