gwenhywfar 4.0.3
|
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_ListBox: public Qt4_W_Widget { 00015 public: 00016 Qt4_W_ListBox(GWEN_WIDGET *w):Qt4_W_Widget(w) { 00017 } 00018 00019 00020 00021 ~Qt4_W_ListBox() { 00022 } 00023 00024 00025 00026 virtual int setup() { 00027 QTreeWidget *qw; 00028 uint32_t flags; 00029 GWEN_WIDGET *wParent; 00030 QSizePolicy::Policy hpolicy=QSizePolicy::Minimum; 00031 QSizePolicy::Policy vpolicy=QSizePolicy::Minimum; 00032 QT4_GuiDialog *qtDialog; 00033 00034 flags=GWEN_Widget_GetFlags(_widget); 00035 wParent=GWEN_Widget_Tree_GetParent(_widget); 00036 00037 qw=new QTreeWidget(); 00038 qw->setAllColumnsShowFocus(true); 00039 qw->setSortingEnabled(true); 00040 qw->setRootIsDecorated(false); 00041 qw->setItemsExpandable(false); 00042 qw->setSelectionBehavior(QAbstractItemView::SelectRows); 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(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)), 00057 qtDialog->getMainWindow(), 00058 SLOT(slotActivated())); 00059 00060 if (wParent) 00061 GWEN_Widget_AddChildGuiWidget(wParent, _widget); 00062 return 0; 00063 } 00064 00065 00066 00067 int setIntProperty(GWEN_DIALOG_PROPERTY prop, 00068 int index, 00069 int value, 00070 int doSignal) { 00071 QTreeWidget *qw; 00072 00073 qw=(QTreeWidget*) GWEN_Widget_GetImplData(_widget, QT4_DIALOG_WIDGET_REAL); 00074 assert(qw); 00075 00076 switch(prop) { 00077 case GWEN_DialogProperty_ClearValues: 00078 qw->clear(); 00079 return 0; 00080 00081 case GWEN_DialogProperty_Value: { 00082 QTreeWidgetItem *item; 00083 00084 item=qw->topLevelItem(index); 00085 00086 if (item==NULL) { 00087 DBG_ERROR(GWEN_LOGDOMAIN, "Value %d out of range", value); 00088 return GWEN_ERROR_INVALID; 00089 } 00090 00091 qw->setCurrentItem(item); 00092 return 0; 00093 } 00094 00095 case GWEN_DialogProperty_ColumnWidth: 00096 qw->setColumnWidth(index, value); 00097 return 0; 00098 00099 case GWEN_DialogProperty_SelectionMode: 00100 switch(value) { 00101 case GWEN_Dialog_SelectionMode_None: 00102 qw->setSelectionMode(QAbstractItemView::NoSelection); 00103 return 0; 00104 case GWEN_Dialog_SelectionMode_Single: 00105 qw->setSelectionMode(QAbstractItemView::SingleSelection); 00106 return 0; 00107 case GWEN_Dialog_SelectionMode_Multi: 00108 qw->setSelectionMode(QAbstractItemView::ExtendedSelection); 00109 return 0; 00110 ; 00111 } 00112 DBG_ERROR(GWEN_LOGDOMAIN, "Unknown SelectionMode %d", value); 00113 return GWEN_ERROR_INVALID; 00114 00115 case GWEN_DialogProperty_SortDirection: 00116 switch(value) { 00117 case GWEN_DialogSortDirection_None: 00118 qw->sortByColumn(-1, Qt::AscendingOrder); 00119 break; 00120 case GWEN_DialogSortDirection_Up: 00121 qw->sortByColumn(index, Qt::AscendingOrder); 00122 break; 00123 case GWEN_DialogSortDirection_Down: 00124 qw->sortByColumn(index, Qt::DescendingOrder); 00125 break; 00126 } 00127 return 0; 00128 00129 case GWEN_DialogProperty_Sort: { 00130 int c; 00131 00132 c=qw->sortColumn(); 00133 if (c!=-1) { 00134 QHeaderView *h; 00135 00136 h=qw->header(); 00137 qw->sortItems(c, h->sortIndicatorOrder()); 00138 } 00139 return 0; 00140 } 00141 00142 default: 00143 return Qt4_W_Widget::setIntProperty(prop, index, value, doSignal); 00144 } 00145 }; 00146 00147 00148 00149 int getIntProperty(GWEN_DIALOG_PROPERTY prop, 00150 int index, 00151 int defaultValue) { 00152 QTreeWidget *qw; 00153 00154 qw=(QTreeWidget*) GWEN_Widget_GetImplData(_widget, QT4_DIALOG_WIDGET_REAL); 00155 assert(qw); 00156 00157 switch(prop) { 00158 case GWEN_DialogProperty_Value: { 00159 QTreeWidgetItem *item; 00160 int i=-1; 00161 00162 item=qw->currentItem(); 00163 while(item) { 00164 item=qw->itemAbove(item); 00165 i++; 00166 } 00167 00168 return i; 00169 } 00170 00171 case GWEN_DialogProperty_ColumnWidth: 00172 return qw->columnWidth(index); 00173 00174 case GWEN_DialogProperty_SelectionMode: 00175 switch(qw->selectionMode()) { 00176 case QAbstractItemView::NoSelection: 00177 return GWEN_Dialog_SelectionMode_None; 00178 case QAbstractItemView::SingleSelection: 00179 return GWEN_Dialog_SelectionMode_Single; 00180 case QAbstractItemView::ExtendedSelection: 00181 return GWEN_Dialog_SelectionMode_Multi; 00182 default: 00183 break; 00184 } 00185 DBG_ERROR(GWEN_LOGDOMAIN, "Unknown SelectionMode %d", 00186 qw->selectionMode()); 00187 return GWEN_ERROR_INVALID; 00188 00189 case GWEN_DialogProperty_SortDirection: 00190 if (qw->sortColumn()!=index) 00191 return GWEN_DialogSortDirection_None; 00192 else { 00193 switch(qw->header()->sortIndicatorOrder()) { 00194 case Qt::AscendingOrder: 00195 return GWEN_DialogSortDirection_Up; 00196 case Qt::DescendingOrder: 00197 return GWEN_DialogSortDirection_Down; 00198 default: 00199 return GWEN_DialogSortDirection_None; 00200 } 00201 } 00202 break; 00203 00204 default: 00205 return Qt4_W_Widget::getIntProperty(prop, index, defaultValue); 00206 } 00207 }; 00208 00209 00210 00211 int setCharProperty(GWEN_DIALOG_PROPERTY prop, 00212 int index, 00213 const char *value, 00214 int doSignal) { 00215 QTreeWidget *qw; 00216 QString text; 00217 00218 qw=(QTreeWidget*) GWEN_Widget_GetImplData(_widget, QT4_DIALOG_WIDGET_REAL); 00219 assert(qw); 00220 00221 if (value) 00222 text=QT4_Gui::extractHtml(value); 00223 00224 switch(prop) { 00225 case GWEN_DialogProperty_Title: { 00226 QString str; 00227 QString t; 00228 QStringList sl; 00229 int n=0; 00230 00231 /* remove all columns */ 00232 qw->header()->reset(); 00233 00234 str=text; 00235 while(!(t=str.section('\t', n, n)).isEmpty()){ 00236 sl+=t; 00237 n++; 00238 } 00239 qw->setHeaderLabels(sl); 00240 return 0; 00241 } 00242 00243 case GWEN_DialogProperty_ClearValues: 00244 qw->clear(); 00245 return 0; 00246 00247 case GWEN_DialogProperty_AddValue: { 00248 QString str; 00249 QString t; 00250 int n=0; 00251 QStringList sl; 00252 QTreeWidgetItem *item; 00253 00254 str=text; 00255 while(!(t=str.section('\t', n, n)).isEmpty()){ 00256 sl+=t; 00257 n++; 00258 } 00259 item=new QTreeWidgetItem(qw, sl); 00260 return 0; 00261 } 00262 00263 default: 00264 return Qt4_W_Widget::setCharProperty(prop, index, value, doSignal); 00265 } 00266 }; 00267 00268 00269 00270 const char *getCharProperty(GWEN_DIALOG_PROPERTY prop, 00271 int index, 00272 const char *defaultValue) { 00273 QTreeWidget *qw; 00274 QString str; 00275 00276 qw=(QTreeWidget*) GWEN_Widget_GetImplData(_widget, QT4_DIALOG_WIDGET_REAL); 00277 assert(qw); 00278 00279 switch(prop) { 00280 case GWEN_DialogProperty_Title: { 00281 QTreeWidgetItem *item; 00282 00283 item=qw->headerItem(); 00284 if (item) { 00285 int i; 00286 00287 for (i=0; i<qw->columnCount(); i++) { 00288 if (i) 00289 str+='\t'; 00290 str+=item->text(i); 00291 } 00292 if (str.isEmpty()) 00293 return defaultValue; 00294 else { 00295 GWEN_Widget_SetText(_widget, QT4_DIALOG_STRING_TITLE, str.toUtf8()); 00296 return GWEN_Widget_GetText(_widget, QT4_DIALOG_STRING_TITLE); 00297 } 00298 } 00299 return defaultValue; 00300 } 00301 00302 case GWEN_DialogProperty_Value: { 00303 QTreeWidgetItem *item; 00304 int i; 00305 00306 item=qw->topLevelItem(index); 00307 00308 if (item==NULL) { 00309 DBG_ERROR(GWEN_LOGDOMAIN, "Value %d out of range", index); 00310 return defaultValue; 00311 } 00312 00313 for (i=0; i<qw->columnCount(); i++) { 00314 if (i) 00315 str+='\t'; 00316 str+=item->text(i); 00317 } 00318 if (str.isEmpty()) 00319 return defaultValue; 00320 else { 00321 GWEN_Widget_SetText(_widget, QT4_DIALOG_STRING_VALUE, str.toUtf8()); 00322 return GWEN_Widget_GetText(_widget, QT4_DIALOG_STRING_VALUE); 00323 } 00324 } 00325 00326 default: 00327 return Qt4_W_Widget::getCharProperty(prop, index, defaultValue); 00328 } 00329 }; 00330 00331 }; 00332 00333 00334 00335 00336 00337 00338