gwenhywfar 4.0.3

w_textedit.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_TextEdit: public Qt4_W_Widget {
00015 public:
00016   Qt4_W_TextEdit(GWEN_WIDGET *w):Qt4_W_Widget(w) {
00017   }
00018 
00019 
00020 
00021   ~Qt4_W_TextEdit() {
00022   }
00023 
00024 
00025 
00026   virtual int setup() {
00027     QTextEdit *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     QT4_GuiDialog *qtDialog;
00035 
00036     flags=GWEN_Widget_GetFlags(_widget);
00037     wParent=GWEN_Widget_Tree_GetParent(_widget);
00038     s=GWEN_Widget_GetText(_widget, 0);
00039     if (s)
00040       text=QString::fromUtf8(s);
00041 
00042     qw=new QTextEdit(text);
00043 
00044     /* handle flags */
00045     if (flags & GWEN_WIDGET_FLAGS_FILLX)
00046       hpolicy=QSizePolicy::Expanding;
00047     if (flags & GWEN_WIDGET_FLAGS_FILLY)
00048       vpolicy=QSizePolicy::Expanding;
00049     qw->setSizePolicy(hpolicy, vpolicy);
00050 
00051     GWEN_Widget_SetImplData(_widget, QT4_DIALOG_WIDGET_REAL, (void*) qw);
00052 
00053     qtDialog=dynamic_cast<QT4_GuiDialog*>(getDialog());
00054     assert(qtDialog);
00055 
00056     qw->connect(qw, SIGNAL(returnPressed()),
00057                 qtDialog->getMainWindow(),
00058                 SLOT(slotActivated()));
00059 
00060 
00061     if (wParent)
00062       GWEN_Widget_AddChildGuiWidget(wParent, _widget);
00063     return 0;
00064   }
00065 
00066 
00067 
00068   int setCharProperty(GWEN_DIALOG_PROPERTY prop,
00069                       int index,
00070                       const char *value,
00071                       int doSignal) {
00072     QTextEdit *qw;
00073     QString text;
00074 
00075     qw=(QTextEdit*) GWEN_Widget_GetImplData(_widget, QT4_DIALOG_WIDGET_REAL);
00076     assert(qw);
00077 
00078     if (value)
00079       text=QString::fromUtf8(value);
00080 
00081     switch(prop) {
00082     case GWEN_DialogProperty_Value:
00083       qw->setText(text);
00084       return 0;
00085     default:
00086       break;
00087     }
00088 
00089     DBG_WARN(GWEN_LOGDOMAIN,
00090              "Function is not appropriate for this type of widget (%s)",
00091              GWEN_Widget_Type_toString(GWEN_Widget_GetType(_widget)));
00092     return GWEN_ERROR_INVALID;
00093   };
00094 
00095 
00096 
00097   const char *getCharProperty(GWEN_DIALOG_PROPERTY prop,
00098                               int index,
00099                               const char *defaultValue) {
00100     QLabel *qw;
00101     QString str;
00102 
00103     qw=(QLabel*) GWEN_Widget_GetImplData(_widget, QT4_DIALOG_WIDGET_REAL);
00104     assert(qw);
00105 
00106     switch(prop) {
00107     case GWEN_DialogProperty_Value:
00108       str=qw->text();
00109       if (str.isEmpty())
00110         return defaultValue;
00111       else {
00112         GWEN_Widget_SetText(_widget, QT4_DIALOG_STRING_TITLE, str.toUtf8());
00113         return GWEN_Widget_GetText(_widget, QT4_DIALOG_STRING_TITLE);
00114       }
00115       break;
00116 
00117     default:
00118       break;
00119     }
00120 
00121     DBG_WARN(GWEN_LOGDOMAIN,
00122              "Function is not appropriate for this type of widget (%s)",
00123              GWEN_Widget_Type_toString(GWEN_Widget_GetType(_widget)));
00124     return defaultValue;
00125   };
00126 
00127 };
00128 
00129 
00130 
00131 
00132 
00133 
00134