00001 #ifndef MYTHUIBUTTONLIST_H_
00002 #define MYTHUIBUTTONLIST_H_
00003
00004 #include <QList>
00005 #include <QHash>
00006 #include <QString>
00007 #include <QVariant>
00008
00009 #include "mythuitype.h"
00010 #include "mythuiimage.h"
00011 #include "mythuitext.h"
00012 #include "mythuigroup.h"
00013 #include "mythscreentype.h"
00014
00015 class MythUIButtonList;
00016 class MythUIScrollBar;
00017 class MythUIStateType;
00018
00019 struct TextProperties {
00020 QString text;
00021 QString state;
00022 };
00023
00024 class MUI_PUBLIC MythUIButtonListItem
00025 {
00026 public:
00027 enum CheckState {
00028 CantCheck = -1,
00029 NotChecked = 0,
00030 HalfChecked,
00031 FullChecked
00032 };
00033
00034 MythUIButtonListItem(MythUIButtonList *lbtype, const QString& text,
00035 const QString& image = "", bool checkable = false,
00036 CheckState state = CantCheck, bool showArrow = false,
00037 int listPosition = -1);
00038 MythUIButtonListItem(MythUIButtonList *lbtype, const QString& text,
00039 QVariant data, int listPosition = -1);
00040 virtual ~MythUIButtonListItem();
00041
00042 MythUIButtonList *parent() const;
00043
00044 void SetText(const QString &text, const QString &name="",
00045 const QString &state="");
00046 void SetTextFromMap(InfoMap &infoMap, const QString &state="");
00047 void SetTextFromMap(QMap<QString, TextProperties> &stringMap);
00048 QString GetText(const QString &name="") const;
00049
00050 bool FindText(const QString &searchStr, const QString &fieldList = "**ALL**",
00051 bool startsWith = false) const;
00052
00053 void SetFontState(const QString &state, const QString &name="");
00054
00058 void setImage(MythImage *image, const QString &name="");
00059
00064 MythImage *getImage(const QString &name="");
00065
00066 void SetImage(const QString &filename, const QString &name="",
00067 bool force_reload = false);
00068 void SetImageFromMap(const InfoMap &imageMap);
00069 QString GetImage(const QString &name="") const;
00070
00071 void DisplayState(const QString &state, const QString &name);
00072 void SetStatesFromMap(const InfoMap &stateMap);
00073
00074 bool checkable() const;
00075 void setCheckable(bool flag);
00076
00077 CheckState state() const;
00078 void setChecked(CheckState state);
00079
00080 void setDrawArrow(bool flag);
00081
00082 void SetData(QVariant data);
00083 QVariant GetData();
00084
00085 bool MoveUpDown(bool flag);
00086
00087 virtual void SetToRealButton(MythUIStateType *button, bool selected);
00088
00089 protected:
00090 MythUIButtonList *m_parent;
00091 QString m_text;
00092 QString m_fontState;
00093 MythImage *m_image;
00094 QString m_imageFilename;
00095 bool m_checkable;
00096 CheckState m_state;
00097 QVariant m_data;
00098 bool m_showArrow;
00099
00100 QMap<QString, TextProperties> m_strings;
00101 QMap<QString, MythImage*> m_images;
00102 InfoMap m_imageFilenames;
00103 InfoMap m_states;
00104
00105 friend class MythUIButtonList;
00106 friend class MythGenericTree;
00107 };
00108
00118 class MUI_PUBLIC MythUIButtonList : public MythUIType
00119 {
00120 Q_OBJECT
00121 public:
00122 MythUIButtonList(MythUIType *parent, const QString &name);
00123 MythUIButtonList(MythUIType *parent, const QString &name,
00124 const QRect &area, bool showArrow = true,
00125 bool showScrollArrows = false,
00126 bool showScrollBar = false);
00127 ~MythUIButtonList();
00128
00129 virtual bool keyPressEvent(QKeyEvent *);
00130 virtual bool gestureEvent(MythGestureEvent *event);
00131 virtual void customEvent(QEvent *);
00132
00133 enum MovementUnit { MoveItem, MoveColumn, MoveRow, MovePage, MoveMax,
00134 MoveMid, MoveByAmount };
00135 enum LayoutType { LayoutVertical, LayoutHorizontal, LayoutGrid };
00136
00137 void SetDrawFromBottom(bool draw);
00138
00139 void Reset();
00140 void Update();
00141
00142 virtual void SetValue(int value) { MoveToNamedPosition(QString::number(value)); }
00143 virtual void SetValue(QString value) { MoveToNamedPosition(value); }
00144 void SetValueByData(QVariant data);
00145 virtual int GetIntValue() const;
00146 virtual QString GetValue() const;
00147 QVariant GetDataValue() const;
00148 MythRect GetButtonArea(void) const;
00149
00150 void SetItemCurrent(MythUIButtonListItem* item);
00151 void SetItemCurrent(int pos, int topPos = -1);
00152 MythUIButtonListItem* GetItemCurrent() const;
00153 MythUIButtonListItem* GetItemFirst() const;
00154 MythUIButtonListItem* GetItemNext(MythUIButtonListItem *item) const;
00155 MythUIButtonListItem* GetItemAt(int pos) const;
00156 MythUIButtonListItem* GetItemByData(QVariant data);
00157
00158 uint ItemWidth(void);
00159 uint ItemHeight(void);
00160 LayoutType GetLayout() const { return m_layout; }
00161
00162 bool MoveItemUpDown(MythUIButtonListItem *item, bool up);
00163
00164 void SetAllChecked(MythUIButtonListItem::CheckState state);
00165
00166 int GetCurrentPos() const { return m_selPosition; }
00167 int GetItemPos(MythUIButtonListItem* item) const;
00168 int GetTopItemPos(void) const { return m_topPosition; }
00169 int GetCount() const;
00170 uint GetVisibleCount();
00171 bool IsEmpty() const;
00172
00173 virtual bool MoveDown(MovementUnit unit = MoveItem, uint amount = 0);
00174 virtual bool MoveUp(MovementUnit unit = MoveItem, uint amount = 0);
00175 bool MoveToNamedPosition(const QString &position_name);
00176
00177 void RemoveItem(MythUIButtonListItem *item);
00178
00179 void SetLCDTitles(const QString &title, const QString &columnList = "");
00180 void updateLCD(void);
00181
00182 void SetSearchFields(const QString &fields) { m_searchFields = fields; }
00183 void ShowSearchDialog(void);
00184 bool Find(const QString &searchStr, bool startsWith = false);
00185 bool FindNext(void);
00186 bool FindPrev(void);
00187
00188 void LoadInBackground(int start = 0, int pageSize = 20);
00189 int StopLoad(void);
00190
00191 public slots:
00192 void Select();
00193 void Deselect();
00194
00195 signals:
00196 void itemSelected(MythUIButtonListItem* item);
00197 void itemClicked(MythUIButtonListItem* item);
00198 void itemVisible(MythUIButtonListItem* item);
00199 void itemLoaded(MythUIButtonListItem* item);
00200
00201 protected:
00202 enum ScrollStyle { ScrollFree, ScrollCenter, ScrollGroupCenter };
00203 enum ArrangeType { ArrangeFixed, ArrangeFill, ArrangeSpread, ArrangeStack };
00204 enum WrapStyle { WrapCaptive = -1, WrapNone = 0, WrapSelect, WrapItems,
00205 WrapFlowing };
00206
00207 virtual void DrawSelf(MythPainter *p, int xoffset, int yoffset,
00208 int alphaMod, QRect clipRect);
00209 void Const();
00210 virtual void Init();
00211
00212 void InsertItem(MythUIButtonListItem *item, int listPosition = -1);
00213
00214 int minButtonWidth(const MythRect & area);
00215 int minButtonHeight(const MythRect & area);
00216 void InitButton(int itemIdx, MythUIStateType* & realButton,
00217 MythUIButtonListItem* & buttonItem);
00218 MythUIGroup *PrepareButton(int buttonIdx, int itemIdx,
00219 int & selectedIdx, int & button_shift);
00220 bool DistributeRow(int & first_button, int & last_button,
00221 int & first_item, int & last_item,
00222 int & selected_column, int & skip_cols,
00223 bool grow_left, bool grow_right,
00224 int ** col_widths, int & row_height,
00225 int total_height, int split_height,
00226 int & col_cnt, bool & wrapped);
00227 bool DistributeCols(int & first_button, int & last_button,
00228 int & first_item, int & last_item,
00229 int & selected_column, int & selected_row,
00230 int & skip_cols, int ** col_widths,
00231 QList<int> & row_heights,
00232 int & top_height, int & bottom_height,
00233 bool & wrapped);
00234 bool DistributeButtons(void);
00235 void SetPosition(void);
00236 void SetPositionArrowStates(void);
00237 void SetScrollBarPosition(void);
00238 void ItemVisible(MythUIButtonListItem *item);
00239
00240 void SetActive(bool active);
00241
00242 int PageUp(void);
00243 int PageDown(void);
00244
00245 bool DoFind(bool doMove, bool searchForward);
00246
00247
00248 virtual void CalculateVisibleItems(void);
00249 virtual QPoint GetButtonPosition(int column, int row) const;
00250
00251 void SetButtonArea(const MythRect &rect);
00252 virtual bool ParseElement(
00253 const QString &filename, QDomElement &element, bool showWarnings);
00254 virtual void CopyFrom(MythUIType *base);
00255 virtual void CreateCopy(MythUIType *parent);
00256 virtual void Finalize(void);
00257
00258 void SanitizePosition(void);
00259
00260
00261
00262 LayoutType m_layout;
00263 ArrangeType m_arrange;
00264 ScrollStyle m_scrollStyle;
00265 WrapStyle m_wrapStyle;
00266 int m_alignment;
00267
00268 MythRect m_contentsRect;
00269
00270 MythPoint m_searchPosition;
00271 QString m_searchFields;
00272 QString m_searchStr;
00273 bool m_searchStartsWith;
00274
00275 int m_itemWidth;
00276 int m_itemHeight;
00277 int m_itemHorizSpacing;
00278 int m_itemVertSpacing;
00279 uint m_itemsVisible;
00280 int m_maxVisible;
00281 int m_rows;
00282 int m_columns;
00283 int m_leftColumns, m_rightColumns;
00284 int m_topRows, m_bottomRows;
00285
00286 bool m_active;
00287 bool m_showArrow;
00288 bool m_showScrollBar;
00289
00290 MythUIScrollBar *m_scrollBar;
00291 MythUIStateType *m_upArrow;
00292 MythUIStateType *m_downArrow;
00293
00294 MythUIStateType *m_buttontemplate;
00295
00296 QVector<MythUIStateType *> m_ButtonList;
00297 QMap<int, MythUIButtonListItem *> m_ButtonToItem;
00298 QHash<QString, QString> m_actionRemap;
00299
00300 bool m_initialized;
00301 bool m_needsUpdate;
00302 bool m_clearing;
00303
00304 int m_selPosition;
00305 int m_topPosition;
00306 int m_itemCount;
00307 bool m_keepSelAtBottom;
00308
00309 QList<MythUIButtonListItem*> m_itemList;
00310 int m_nextItemLoaded;
00311
00312 bool m_drawFromBottom;
00313
00314 QString m_lcdTitle;
00315 QStringList m_lcdColumns;
00316
00317 friend class MythUIButtonListItem;
00318 friend class MythUIButtonTree;
00319 };
00320
00321 class MUI_PUBLIC SearchButtonListDialog : public MythScreenType
00322 {
00323 Q_OBJECT
00324 public:
00325 SearchButtonListDialog(MythScreenStack *parent, const char *name,
00326 MythUIButtonList *parentList, QString searchText);
00327 ~SearchButtonListDialog(void);
00328
00329 bool Create(void);
00330 bool keyPressEvent(QKeyEvent *event);
00331
00332 protected slots:
00333 void searchChanged(void);
00334 void prevClicked(void);
00335 void nextClicked(void);
00336
00337 protected:
00338 bool m_startsWith;
00339
00340 MythUIButtonList *m_parentList;
00341 QString m_searchText;
00342
00343 MythUITextEdit *m_searchEdit;
00344 MythUIButton *m_prevButton;
00345 MythUIButton *m_nextButton;
00346 MythUIStateType *m_searchState;
00347 };
00348
00349 Q_DECLARE_METATYPE(MythUIButtonListItem *)
00350
00351 #endif