00001 #ifndef MANAGED_LIST_H
00002 #define MANAGED_LIST_H
00003
00004 #include <vector>
00005 #include <qguardedptr.h>
00006
00007 using namespace std;
00008
00009 #include "uitypes.h"
00010 #include "mythwidgets.h"
00011 #include "settings.h"
00012
00013
00014
00015 enum ManagedListItemStates{MLS_NORMAL, MLS_BOLD, MLS_USER};
00016
00017 class ManagedList;
00018 class ManagedListGroup;
00019
00021
00022
00023
00024
00025
00026 class MPUBLIC ManagedListItem : public QObject
00027 {
00028 Q_OBJECT
00029
00030 public:
00031 ManagedListItem(const QString& startingText = "", ManagedList* _parentList=NULL,
00032 QObject* _parent=NULL, const char* _name=0);
00033
00034 virtual bool hasLeft(){ return false; }
00035 virtual bool hasRight(){ return false; }
00036
00037 const int getState() const { return curState; }
00038 void setState(int val) { curState = val; emit changed(this); }
00039
00040 const bool getEnabled() const { return enabled; }
00041 virtual void setEnabled(bool val) { enabled = val; }
00042
00043 ManagedList* getParentList() { return parentList; }
00044 virtual void setParentList(ManagedList* _parent);
00045
00046
00047
00048 virtual void setValue(const QString& val) { valueText = val; syncTextToValue(); }
00049
00050 virtual const QString& getValue() const { return valueText; }
00051
00052 virtual const QString& getText() const { return text; }
00053 void setText(const QString& newText) { text = newText; emit changed(this); }
00054
00055 public slots:
00056 virtual void cursorLeft(bool) { canceled(); }
00057 virtual void cursorRight(bool) { selected(); }
00058 virtual void select() { selected(); }
00059 virtual void gotFocus() {}
00060 virtual void slotGuiActivate(ManagedListGroup*) {};
00061
00062 signals:
00063 void selected(ManagedListItem*);
00064 void changed(ManagedListItem*);
00065 void canceled(ManagedListItem*);
00066
00067 protected:
00068 virtual void syncTextToValue() { changed(); }
00069 virtual void selected() { if (enabled) emit selected(this); }
00070 virtual void canceled() { if (enabled) emit canceled(this); }
00071 virtual void changed() { emit(changed(this)); }
00072 int curState;
00073 int listIndex;
00074 bool enabled;
00075 QGuardedPtr<ManagedList> parentList;
00076
00077 QString text;
00078 QString valueText;
00079 };
00080
00081
00082 class MPUBLIC DialogDoneListItem : public ManagedListItem
00083 {
00084 Q_OBJECT
00085 public:
00086 DialogDoneListItem(const QString& startingText, int _result, MythDialog* _dialog = NULL, ManagedList* _parentList=NULL,
00087 QObject* _parent=NULL, const char* _name=0)
00088 : ManagedListItem(startingText, _parentList, _parent, _name)
00089 {
00090 dialog = _dialog;
00091 resultValue = _result;
00092 }
00093
00094 virtual bool hasLeft(){ return false; }
00095 virtual bool hasRight(){ return false; }
00096
00097 virtual void selected() { if (enabled && dialog) dialog->done(resultValue); }
00098
00099 void setDialog(MythDialog* dlg) { dialog = dlg;}
00100
00101 MythDialog* getDialog() { return dialog;}
00102
00103 protected:
00104 QGuardedPtr<MythDialog> dialog;
00105 int resultValue;
00106 };
00107
00108
00109
00111
00112
00113
00114
00115
00116 class IntegerManagedListItem : public ManagedListItem
00117 {
00118 Q_OBJECT
00119
00120 public:
00121 IntegerManagedListItem(int bigStepAmt = 10, int stepAmt=1, ManagedList* parentList=NULL,
00122 QObject* _parent=NULL, const char* _name=0);
00123 void setTemplates(const QString& negStr, const QString& negOneStr, const QString& zeroStr,
00124 const QString& oneStr, const QString& posStr);
00125 void setShortTemplates(const QString& negStr, const QString& negOneStr,
00126 const QString& zeroStr, const QString& oneStr,
00127 const QString& posStr);
00128
00129 int intValue() const { return valueText.toInt();}
00130
00131 virtual void setValue(int newVal) { ManagedListItem::setValue(QString::number(newVal));}
00132
00133 virtual void changeValue(int amount) { setValue(intValue() + amount); }
00134
00135 const QString& getShortText() const { return shortText; }
00136 virtual bool hasLeft(){ return true; }
00137 virtual bool hasRight(){ return true; }
00138 public slots:
00139 virtual void cursorLeft(bool page = false) { if (enabled) changeValue(page ? (0 - bigStep) : (0 - step)); }
00140 virtual void cursorRight(bool page = false) { if (enabled) changeValue(page ? bigStep : step); }
00141
00142 protected:
00143 virtual void syncTextToValue();
00144 void setText(const QString& newText) { text = newText; }
00145 int step;
00146 int bigStep;
00147 QString negTemplate;
00148 QString negOneTemplate;
00149 QString posTemplate;
00150 QString posOneTemplate;
00151 QString zeroTemplate;
00152 QString shortNegTemplate;
00153 QString shortNegOneTemplate;
00154 QString shortPosOneTemplate;
00155 QString shortPosTemplate;
00156 QString shortZeroTemplate;
00157
00158 QString shortText;
00159 };
00160
00161
00162
00163
00164
00165
00166
00167
00169
00170
00171
00172 class MPUBLIC ManagedListGroup : public ManagedListItem
00173 {
00174 Q_OBJECT
00175
00176 public:
00177 ManagedListGroup(const QString& txt, ManagedListGroup* pGroup, ManagedList* parentList=NULL,
00178 QObject* _parent=NULL, const char* _name=0);
00179
00180 const QPtrList<ManagedListItem>* getItems() const { return &itemList;}
00181 bool addItem(ManagedListItem* item, int where = -1);
00182
00183 const int getItemCount() const { return itemCount;}
00184
00185 virtual bool hasLeft(){ return false; }
00186 virtual bool hasRight(){ return (itemCount > 0); }
00187
00188 ManagedListGroup* getParentGroup() { return parentGroup; }
00189 void setParentGroup(ManagedListGroup* pGroup) { parentGroup = pGroup; }
00190
00191
00192 virtual void cursorRight(bool page = false);
00193 virtual void select();
00194
00195 int getCurIndex() const { return curItem; }
00196 void setCurIndex(int newVal);
00197
00198 ManagedListItem* getItem(int index) { return itemList.at(index); }
00199 ManagedListItem* getCurItem() { return itemList.at(curItem); }
00200
00201 const QString getCurItemValue() { return getItemValue(curItem); }
00202 const QString getItemValue(int which) { ManagedListItem *itm = getItem(which);
00203 return itm ? itm->getValue() : 0; }
00204
00205 const QString getCurItemText() { return getItemText(curItem); }
00206 const QString getItemText(int which) { ManagedListItem *itm = getItem(which);
00207 return itm ? itm->getText() : ""; }
00208
00209 virtual void setParentList(ManagedList* _parent);
00210
00211 virtual void clear();
00212
00213 public slots:
00214 virtual void doGoBack();
00215 virtual void slotGuiActivate(ManagedListGroup*);
00216 signals:
00217 void goingBack();
00218 void wentBack();
00219
00220 protected:
00221 QPtrList<ManagedListItem> itemList;
00222 int curItem;
00223 int itemCount;
00224 QGuardedPtr<ManagedListGroup> parentGroup;
00225 QGuardedPtr<ManagedListItem> goBack;
00226 };
00227
00228
00230
00231
00232
00233
00234 class MPUBLIC SelectManagedListItem : public ManagedListGroup
00235 {
00236 Q_OBJECT
00237
00238 public:
00239 SelectManagedListItem(const QString& baseText, ManagedListGroup* pGroup, ManagedList* parentList,
00240 QObject* _parent=NULL, const char* _name=0);
00241 virtual ManagedListItem* addSelection(const QString& label, QString value=QString::null, bool selectit=false);
00242 virtual ManagedListItem* addButton(const QString& label, QString value=QString::null, bool selectit=false);
00243
00244 virtual void clearSelections(void);
00245
00246 virtual void cursorRight(bool page = false);
00247 virtual void cursorLeft(bool page = false);
00248 virtual void select();
00249
00250 virtual void selectValue(const QString& newValue) { select(newValue, true);}
00251 virtual void setValue(const QString& newValue);
00252 virtual void selectText(const QString& newValue) { select(newValue, false);}
00253 virtual void selectItem(int index) { curItem = index; changed(); }
00254 virtual void select(const QString& newValue, bool bValue);
00255
00256 virtual bool hasLeft(){ return true; }
00257 virtual bool hasRight(){ return true; }
00258
00259
00260 virtual int getValueIndex(QString value) {
00261 int i = -1;
00262 for(ManagedListItem* tempItem = itemList.first(); tempItem; tempItem = itemList.next() )
00263 {
00264 i++;
00265 if (tempItem->getValue() == value)
00266 return i;
00267 }
00268 return -1;
00269 };
00270
00271 virtual int getTextIndex(QString txt) {
00272 int i = -1;
00273 for(ManagedListItem* tempItem = itemList.first(); tempItem; tempItem = itemList.next() )
00274 {
00275 i++;
00276 if (tempItem->getText() == txt)
00277 return i;
00278 }
00279
00280 return -1;
00281 };
00282
00283 signals:
00284 void selectionAdded(const QString& label, QString value, bool select = false);
00285 void selectionsCleared(void);
00286 void buttonPressed(ManagedListItem* itm, ManagedListItem* button);
00287
00288 public slots:
00289 virtual void buttonSelected(ManagedListItem* itm);
00290 virtual void itemSelected(ManagedListItem* itm);
00291 virtual void doGoBack();
00292
00293 protected:
00294 bool isSet;
00295 QString baseText;
00296 int lastItem;
00297 };
00298
00299
00300 class MPUBLIC BoolManagedListItem : public SelectManagedListItem
00301 {
00302 Q_OBJECT
00303 public:
00304 BoolManagedListItem(bool initialValue, ManagedListGroup* pGroup=NULL, ManagedList* parentList=NULL,
00305 QObject* _parent=NULL, const char* _name=0);
00306 void setLabels(const QString& trueLbl, const QString& falseLbl);
00307 virtual bool hasLeft(){ return true; }
00308 virtual bool hasRight(){ return true; }
00309
00310
00311 virtual void setValue(bool val)
00312 {
00313
00314 if (val)
00315 SelectManagedListItem::setValue("1");
00316 else
00317 SelectManagedListItem::setValue("0");
00318 }
00319
00320
00321 bool boolValue() const {return (bool)valueText.toInt();}
00322
00323
00324
00325 public slots:
00326 virtual void cursorLeft(bool) { if (enabled) setValue(!boolValue()); }
00327 virtual void cursorRight(bool) { if (enabled) setValue(!boolValue()); }
00328 virtual void slotGuiActivate(ManagedListGroup*) { generateList(); }
00329
00330 protected:
00331 void generateList();
00332 void setText(const QString& newText) { text = newText; emit(changed(this)); }
00333 QString trueLabel;
00334 QString falseLabel;
00335 bool initialValue;
00336 bool listBuilt;
00337 };
00338
00339
00340
00342
00343
00344
00345 class MPUBLIC BoundedIntegerManagedListItem : public SelectManagedListItem
00346 {
00347 Q_OBJECT
00348
00349 public:
00350 BoundedIntegerManagedListItem(int minValIn, int maxValIn, int _bigStep, int _step = 1,
00351 ManagedListGroup* _group=NULL, ManagedList* parentList=NULL,
00352 QObject* _parent=NULL, const char* _name=0, bool _invert = false);
00353
00354
00355 virtual bool hasLeft()
00356 {
00357 if (inverted)
00358 return intValue() < maxVal;
00359 else
00360 return intValue() > minVal;
00361 }
00362
00363 virtual bool hasRight()
00364 {
00365 if (inverted)
00366 return intValue() > minVal;
00367 else
00368 return intValue() < maxVal;
00369 }
00370
00371 void setTemplates(const QString& negStr, const QString& negOneStr, const QString& zeroStr,
00372 const QString& oneStr, const QString& posStr);
00373
00374 int intValue() const { return valueText.toInt();}
00375
00376 virtual void setValue(int newVal);
00377
00378 virtual void changeValue(int amount) { setValue(intValue() + amount); }
00379
00380
00381 QString numericToString(int v);
00382
00383
00384 public slots:
00385 virtual void cursorLeft(bool page = false)
00386 {
00387 if (enabled)
00388 {
00389 if (inverted)
00390 changeValue(page ? bigStep : step);
00391 else
00392 changeValue(page ? (0 - bigStep) : (0 - step));
00393 }
00394 }
00395
00396 virtual void cursorRight(bool page = false)
00397 {
00398 if (enabled)
00399 {
00400 if (inverted)
00401 changeValue(page ? (0 - bigStep) : (0 - step));
00402 else
00403 changeValue(page ? bigStep : step);
00404 }
00405 }
00406
00407
00408 virtual void slotGuiActivate(ManagedListGroup*) { generateList(); }
00409
00410 protected:
00411 void generateList();
00412 int step;
00413 int bigStep;
00414 QString negTemplate;
00415 QString negOneTemplate;
00416 QString posTemplate;
00417 QString posOneTemplate;
00418 QString zeroTemplate;
00419
00420 protected:
00421 int maxVal;
00422 int minVal;
00423 bool listBuilt;
00424 bool inverted;
00425 };
00426
00427
00428 class MPUBLIC ManagedListSetting : public Setting, public SimpleDBStorage
00429 {
00430 Q_OBJECT
00431
00432 protected:
00433 ManagedListSetting(QString _table, QString _column,
00434 ManagedList *_parentList = NULL) :
00435 Setting(this), SimpleDBStorage(this, _table, _column),
00436 parentList(_parentList), listItem(NULL) { }
00437
00438 QGuardedPtr<ManagedList> parentList;
00439 QGuardedPtr<ManagedListItem> listItem;
00440
00441 public slots:
00442 void itemChanged(ManagedListItem*) { syncDBFromItem(); }
00443
00444
00445
00446 public:
00447
00448 virtual void load() {
00449 SimpleDBStorage::load();
00450 syncItemFromDB();
00451 }
00452
00453 virtual void setValue(int val) {setValue(QString::number(val));}
00454
00455 virtual void setValue(const QString& val) {
00456 if (listItem)
00457 {
00458 listItem->setValue(val);
00459 syncDBFromItem();
00460 }
00461 else
00462 {
00463 Setting::setValue(val);
00464 }
00465 }
00466
00467 virtual const QString getValue() {
00468 if (listItem)
00469 {
00470 syncDBFromItem();
00471 return listItem->getValue();
00472 }
00473 else
00474 {
00475 return Setting::getValue();
00476 }
00477
00478 }
00479
00480 virtual void syncDBFromItem()
00481 {
00482 if (listItem)
00483 Setting::setValue(listItem->getValue());
00484 }
00485
00486 virtual void syncItemFromDB()
00487 {
00488 if (listItem)
00489 listItem->setValue(settingValue);
00490 }
00491
00492 ManagedListItem* getItem() { return listItem; }
00493 operator ManagedListItem*() { return listItem; }
00494 };
00495
00496
00497 class MPUBLIC SelectManagedListSetting : public ManagedListSetting
00498 {
00499 protected:
00500 SelectManagedListSetting(const QString& listName, const QString& listText, ManagedListGroup* _group,
00501 QString _table, QString _column, ManagedList* _parentList=NULL)
00502 : ManagedListSetting(_table, _column, _parentList)
00503 {
00504 constructListItem(listText, _group, _parentList, listName);
00505 listItem = selectItem;
00506
00507 connect(listItem, SIGNAL(changed(ManagedListItem*)), this, SLOT(itemChanged(ManagedListItem*)));
00508 }
00509
00510 QGuardedPtr<SelectManagedListItem> selectItem;
00511
00512 virtual void constructListItem(const QString& listText, ManagedListGroup* _group,
00513 ManagedList* _parentList, const QString& listName)
00514 {
00515 selectItem = new SelectManagedListItem(listText, _group, _parentList, this, listName);
00516 }
00517
00518 public:
00519 ManagedListItem* addSelection(const QString& label, const QString& value)
00520 {
00521 if (selectItem)
00522 return selectItem->addSelection(label, value);
00523
00524 return NULL;
00525 }
00526
00527 ManagedListItem* addButton(const QString& label, const QString& value)
00528 {
00529 if (selectItem)
00530 return selectItem->addButton(label, value);
00531
00532 return NULL;
00533 }
00534
00535 ManagedListItem* addSelection(const QString& label, int value)
00536 {
00537 if (selectItem)
00538 return selectItem->addSelection(label, QString::number(value));
00539
00540 return NULL;
00541 }
00542
00543 void clearSelections() {
00544 if (selectItem)
00545 selectItem->clearSelections();
00546 }
00547
00548 operator SelectManagedListItem* () { return selectItem; }
00549 };
00550
00551
00552 class MPUBLIC BoolManagedListSetting : public ManagedListSetting
00553 {
00554 public:
00555 BoolManagedListSetting(const QString& trueText, const QString& falseText, const QString& ItemName,
00556 QString _table, QString _column, ManagedListGroup* _group,
00557 ManagedList* _parentList=NULL)
00558 : ManagedListSetting(_table, _column, _parentList)
00559 {
00560 boolListItem = new BoolManagedListItem(false, _group, _parentList, this, ItemName);
00561 listItem = boolListItem;
00562 boolListItem->setLabels(trueText, falseText);
00563 connect(listItem, SIGNAL(changed(ManagedListItem*)), this, SLOT(itemChanged(ManagedListItem*)));
00564 }
00565
00566 operator BoolManagedListItem* () { return boolListItem; }
00567
00568 protected:
00569 BoolManagedListItem* boolListItem;
00570 };
00571
00572
00573 class MPUBLIC IntegerManagedListSetting : public ManagedListSetting
00574 {
00575 public:
00576 IntegerManagedListSetting(int _bigStep, int _step, const QString& ItemName, QString _table,
00577 QString _column, ManagedList* _parentList=NULL)
00578 : ManagedListSetting(_table, _column, _parentList)
00579 {
00580 IntegerListItem = new IntegerManagedListItem(_bigStep, _step, _parentList, this, ItemName);
00581 listItem = IntegerListItem;
00582 connect(listItem, SIGNAL(changed(ManagedListItem*)), this, SLOT(itemChanged(ManagedListItem*)));
00583 }
00584
00585 operator IntegerManagedListItem* () { return IntegerListItem; }
00586
00587 void setTemplates(const QString& negStr, const QString& negOneStr, const QString& zeroStr,
00588 const QString& oneStr, const QString& posStr)
00589 {
00590 IntegerListItem->setTemplates(negStr, negOneStr, zeroStr, oneStr, posStr);
00591 }
00592
00593 void setShortTemplates(const QString& negStr, const QString& negOneStr, const QString& zeroStr,
00594 const QString& oneStr, const QString& posStr)
00595 {
00596 IntegerListItem->setShortTemplates(negStr, negOneStr, zeroStr, oneStr, posStr);
00597 }
00598 protected:
00599 IntegerManagedListItem* IntegerListItem;
00600 };
00601
00602 class MPUBLIC BoundedIntegerManagedListSetting : public ManagedListSetting
00603 {
00604 public:
00605 BoundedIntegerManagedListSetting(int _min, int _max, int _bigStep, int _step, const QString& ItemName,
00606 QString _table, QString _column, ManagedListGroup* _group,
00607 ManagedList* _parentList=NULL, bool _invert = false)
00608 : ManagedListSetting(_table, _column, _parentList)
00609 {
00610 BoundedIntegerListItem = new BoundedIntegerManagedListItem(_min, _max, _bigStep, _step,
00611 _group, _parentList, this, ItemName,
00612 _invert);
00613 listItem = BoundedIntegerListItem;
00614 connect(listItem, SIGNAL(changed(ManagedListItem*)), this, SLOT(itemChanged(ManagedListItem*)));
00615 }
00616
00617 operator BoundedIntegerManagedListItem* () { return BoundedIntegerListItem; }
00618
00619 void setTemplates(const QString& negStr, const QString& negOneStr, const QString& zeroStr,
00620 const QString& oneStr, const QString& posStr)
00621 {
00622 BoundedIntegerListItem->setTemplates(negStr, negOneStr, zeroStr, oneStr, posStr);
00623 }
00624
00625 protected:
00626 BoundedIntegerManagedListItem* BoundedIntegerListItem;
00627 };
00628
00629
00630
00632
00633
00634
00635 class MPUBLIC ManagedList : public QObject
00636 {
00637 Q_OBJECT
00638
00639 public:
00640 ManagedList(MythDialog* parent, const char* name=0);
00641
00642 void paintEvent(const QRect& r, QPainter *p, bool force=NULL);
00643 void update(QPainter *p);
00644
00645 const XMLParse* getTheme() const { return theme; }
00646 void setTheme(XMLParse* newTheme) { theme = newTheme; }
00647
00648 const QString& getContainerName() const { return containerName; }
00649 void setContainerName(const QString& newStr) { containerName = newStr; }
00650
00651
00652 ManagedListItem* getItem(const QString& itemName) { return (ManagedListItem*)child(itemName);}
00653 MythDialog* getParent() { return (MythDialog*)parent();}
00654
00655 bool init(XMLParse *theme, const QString& containerNameIn, const QString& listNameIn, const QRect& r);
00656
00657 ManagedListGroup* getCurGroup() { return curGroup; }
00658 void setCurGroup(ManagedListGroup* newGroup);
00659
00660 bool goBack();
00661 bool getLocked() const { return locked; }
00662 void setLocked(bool val = true) { locked = val; }
00663
00664
00665
00666 public slots:
00667 void cursorDown(bool page = false);
00668 void cursorUp(bool page = false);
00669 void cursorLeft(bool page = false);
00670 void cursorRight(bool page = false);
00671 void select();
00672 void itemChanged(ManagedListItem* itm);
00673
00674
00675
00676
00677 protected:
00678 QGuardedPtr<ManagedListGroup> curGroup;
00679 XMLParse* theme;
00680 int listSize;
00681 QString containerName;
00682 QString listName;
00683 QRect listRect;
00684 bool locked;
00685 };
00686
00687
00688
00689 #endif