MythTV  master
mythuibuttonlist.h
Go to the documentation of this file.
1 #ifndef MYTHUIBUTTONLIST_H_
2 #define MYTHUIBUTTONLIST_H_
3 
4 #include <QList>
5 #include <QHash>
6 #include <QString>
7 #include <QVariant>
8 
9 #include "mythuitype.h"
10 #include "mythscreentype.h"
11 #include "mythimage.h"
12 
13 class MythUIButtonList;
14 class MythUIScrollBar;
15 class MythUIStateType;
16 class MythUIGroup;
17 
19  QString text;
20  QString state;
21 };
22 
24 {
25  public:
26  enum CheckState {
27  CantCheck = -1,
28  NotChecked = 0,
30  FullChecked
31  };
32 
33  MythUIButtonListItem(MythUIButtonList *lbtype, const QString& text,
34  const QString& image = "", bool checkable = false,
35  CheckState state = CantCheck, bool showArrow = false,
36  int listPosition = -1);
37  MythUIButtonListItem(MythUIButtonList *lbtype, const QString& text,
38  QVariant data, int listPosition = -1);
39  virtual ~MythUIButtonListItem();
40 
41  MythUIButtonList *parent() const;
42 
43  void SetText(const QString &text, const QString &name="",
44  const QString &state="");
45  void SetTextFromMap(const InfoMap &infoMap, const QString &state="");
46  void SetTextFromMap(const QMap<QString, TextProperties> &stringMap);
47  QString GetText(const QString &name="") const;
48 
49  bool FindText(const QString &searchStr, const QString &fieldList = "**ALL**",
50  bool startsWith = false) const;
51 
52  void SetFontState(const QString &state, const QString &name="");
53 
57  void SetImage(MythImage *image, const QString &name="");
58 
64  MythImage *GetImage(const QString &name="");
65 
67  bool HasImage(const QString &name="")
68  {
69  MythImage *img = GetImage(name);
70  if (img)
71  {
72  img->DecrRef();
73  return true;
74  }
75 
76  return false;
77  }
78 
79  void SetImage(const QString &filename, const QString &name="",
80  bool force_reload = false);
81  void SetImageFromMap(const InfoMap &imageMap);
82  QString GetImageFilename(const QString &name="") const;
83 
84  void DisplayState(const QString &state, const QString &name);
85  void SetStatesFromMap(const InfoMap &stateMap);
86 
87  bool isVisible() const { return m_isVisible; }
88  void setVisible(bool flag) { m_isVisible = flag; }
89 
90  bool checkable() const;
91  void setCheckable(bool flag);
92 
93  bool isEnabled() const;
94  void setEnabled(bool flag);
95 
96  CheckState state() const;
97  void setChecked(CheckState state);
98 
99  void setDrawArrow(bool flag);
100 
101  void SetData(QVariant data);
102  QVariant GetData();
103 
104  bool MoveUpDown(bool flag);
105 
106  virtual void SetToRealButton(MythUIStateType *button, bool selected);
107 
108  protected:
109  MythUIButtonList *m_parent {nullptr};
110  QString m_text;
111  QString m_fontState;
112  MythImage *m_image {nullptr};
116  QVariant m_data {0};
117  bool m_showArrow {false};
118  bool m_isVisible {false};
119  bool m_enabled {true};
120 
121  QMap<QString, TextProperties> m_strings;
122  QMap<QString, MythImage*> m_images;
125 
126  friend class MythUIButtonList;
127  friend class MythGenericTree;
128 };
129 
140 {
141  Q_OBJECT
142  public:
143  MythUIButtonList(MythUIType *parent, const QString &name);
144  MythUIButtonList(MythUIType *parent, const QString &name,
145  const QRect &area, bool showArrow = true,
146  bool showScrollBar = false);
147  ~MythUIButtonList();
148 
149  bool keyPressEvent(QKeyEvent *event) override; // MythUIType
150  bool gestureEvent(MythGestureEvent *event) override; // MythUIType
151  void customEvent(QEvent *) override; // MythUIType
152 
153  enum MovementUnit { MoveItem, MoveColumn, MoveRow, MovePage, MoveMax,
154  MoveMid, MoveByAmount };
155  enum LayoutType { LayoutVertical, LayoutHorizontal, LayoutGrid };
156 
157  void SetDrawFromBottom(bool draw);
158 
159  void Reset() override; // MythUIType
160  void Update();
161 
162  virtual void SetValue(int value) { MoveToNamedPosition(QString::number(value)); }
163  virtual void SetValue(const QString &value) { MoveToNamedPosition(value); }
164  void SetValueByData(const QVariant& data);
165  virtual int GetIntValue() const;
166  virtual QString GetValue() const;
167  QVariant GetDataValue() const;
168  MythRect GetButtonArea(void) const;
169 
170  void SetItemCurrent(MythUIButtonListItem* item);
171  void SetItemCurrent(int current, int topPos = -1);
172  MythUIButtonListItem* GetItemCurrent() const;
173  MythUIButtonListItem* GetItemFirst() const;
174  MythUIButtonListItem* GetItemNext(MythUIButtonListItem *item) const;
175  MythUIButtonListItem* GetItemAt(int pos) const;
176  MythUIButtonListItem* GetItemByData(const QVariant& data);
177 
178  uint ItemWidth(void);
179  uint ItemHeight(void);
180  LayoutType GetLayout() const { return m_layout; }
181 
182  bool MoveItemUpDown(MythUIButtonListItem *item, bool up);
183 
184  void SetAllChecked(MythUIButtonListItem::CheckState state);
185 
186  int GetCurrentPos() const { return m_selPosition; }
187  int GetItemPos(MythUIButtonListItem* item) const;
188  int GetTopItemPos(void) const { return m_topPosition; }
189  int GetCount() const;
190  uint GetVisibleCount();
191  bool IsEmpty() const;
192 
193  virtual bool MoveDown(MovementUnit unit = MoveItem, uint amount = 0);
194  virtual bool MoveUp(MovementUnit unit = MoveItem, uint amount = 0);
195  bool MoveToNamedPosition(const QString &position_name);
196 
197  void RemoveItem(MythUIButtonListItem *item);
198 
199  void SetLCDTitles(const QString &title, const QString &columnList = "");
200  void updateLCD(void);
201 
202  void SetSearchFields(const QString &fields) { m_searchFields = fields; }
203  void ShowSearchDialog(void);
204  bool Find(const QString &searchStr, bool startsWith = false);
205  bool FindNext(void);
206  bool FindPrev(void);
207 
208  void LoadInBackground(int start = 0, int pageSize = 20);
209  int StopLoad(void);
210 
211  public slots:
212  void Select();
213  void Deselect();
214  void ToggleEnabled();
215 
216  signals:
217  void itemSelected(MythUIButtonListItem* item);
218  void itemClicked(MythUIButtonListItem* item);
219  void itemVisible(MythUIButtonListItem* item);
220  void itemLoaded(MythUIButtonListItem* item);
221 
222  protected:
223  enum ScrollStyle { ScrollFree, ScrollCenter, ScrollGroupCenter };
224  enum ArrangeType { ArrangeFixed, ArrangeFill, ArrangeSpread, ArrangeStack };
225  enum WrapStyle { WrapCaptive = -1, WrapNone = 0, WrapSelect, WrapItems,
226  WrapFlowing };
227 
228  void DrawSelf(MythPainter *p, int xoffset, int yoffset,
229  int alphaMod, QRect clipRect) override; // MythUIType
230  void Const();
231  virtual void Init();
232 
233  void InsertItem(MythUIButtonListItem *item, int listPosition = -1);
234 
235  int minButtonWidth(const MythRect & area);
236  int minButtonHeight(const MythRect & area);
237  void InitButton(int itemIdx, MythUIStateType* & realButton,
238  MythUIButtonListItem* & buttonItem);
239  MythUIGroup *PrepareButton(int buttonIdx, int itemIdx,
240  int & selectedIdx, int & button_shift);
241  bool DistributeRow(int & first_button, int & last_button,
242  int & first_item, int & last_item,
243  int & selected_column, int & skip_cols,
244  bool grow_left, bool grow_right,
245  int ** col_widths, int & row_height,
246  int total_height, int split_height,
247  int & col_cnt, bool & wrapped);
248  bool DistributeCols(int & first_button, int & last_button,
249  int & first_item, int & last_item,
250  int & selected_column, int & selected_row,
251  int & skip_cols, int ** col_widths,
252  QList<int> & row_heights,
253  int & top_height, int & bottom_height,
254  bool & wrapped);
255  bool DistributeButtons(void);
256  void CalculateButtonPositions(void);
257  void CalculateArrowStates(void);
258  void SetScrollBarPosition(void);
259  void ItemVisible(MythUIButtonListItem *item);
260 
261  void SetActive(bool active);
262 
263  int PageUp(void);
264  int PageDown(void);
265 
266  bool DoFind(bool doMove, bool searchForward);
267 
268  void FindEnabledUp(MovementUnit unit);
269  void FindEnabledDown(MovementUnit unit);
270 
271  /* methods for subclasses to override */
272  virtual void CalculateVisibleItems(void);
273  virtual QPoint GetButtonPosition(int column, int row) const;
274 
275  void SetButtonArea(const MythRect &rect);
276  bool ParseElement(const QString &filename, QDomElement &element,
277  bool showWarnings) override; // MythUIType
278  void CopyFrom(MythUIType *base) override; // MythUIType
279  void CreateCopy(MythUIType *parent) override; // MythUIType
280  void Finalize(void) override; // MythUIType
281 
282  void SanitizePosition(void);
283 
284 
285 
286  LayoutType m_layout {LayoutVertical};
287  ArrangeType m_arrange {ArrangeFixed};
288  ScrollStyle m_scrollStyle {ScrollFree};
289  WrapStyle m_wrapStyle {WrapNone};
290  int m_alignment {Qt::AlignLeft | Qt::AlignTop};
291 
292  MythRect m_contentsRect {0, 0, 0, 0};
293 
294  MythPoint m_searchPosition {-2,-2};
295  QString m_searchFields {"**ALL**"};
296  QString m_searchStr;
297  bool m_searchStartsWith {false};
298 
299  int m_itemWidth {0};
300  int m_itemHeight {0};
301  int m_itemHorizSpacing {0};
302  int m_itemVertSpacing {0};
303  uint m_itemsVisible {0};
304  int m_maxVisible {0};
305  int m_rows {0};
306  int m_columns {0};
307  int m_leftColumns {0};
308  int m_rightColumns {0};
309  int m_topRows {0};
310  int m_bottomRows {0};
311 
312  bool m_active {false};
313  bool m_showArrow {true};
314  bool m_showScrollBar {true};
315 
316  MythUIScrollBar *m_scrollBar {nullptr};
317  MythUIStateType *m_upArrow {nullptr};
318  MythUIStateType *m_downArrow {nullptr};
319 
320  MythUIStateType *m_buttontemplate {nullptr};
321 
322  QVector<MythUIStateType *> m_ButtonList;
323  QMap<int, MythUIButtonListItem *> m_ButtonToItem;
324  QHash<QString, QString> m_actionRemap;
325 
326  bool m_initialized {false};
327  bool m_needsUpdate {false};
328  bool m_clearing {false};
329 
330  int m_selPosition {0};
331  int m_topPosition {0};
332  int m_itemCount {0};
333  bool m_keepSelAtBottom {false};
334 
335  QList<MythUIButtonListItem*> m_itemList;
336  int m_nextItemLoaded {0};
337 
338  bool m_drawFromBottom {false};
339 
340  QString m_lcdTitle;
341  QStringList m_lcdColumns;
342 
343  friend class MythUIButtonListItem;
344  friend class MythUIButtonTree;
345 };
346 
348 {
349  Q_OBJECT
350  public:
352  MythUIButtonList *parentList, QString searchText)
353  : MythScreenType(parent, name, false),
354  m_parentList(parentList), m_searchText(searchText) {}
355  ~SearchButtonListDialog(void) = default;
356 
357  bool Create(void) override; // MythScreenType
358  bool keyPressEvent(QKeyEvent *event) override; // MythScreenType
359 
360  protected slots:
361  void searchChanged(void);
362  void prevClicked(void);
363  void nextClicked(void);
364 
365  protected:
366  bool m_startsWith {false};
367 
368  MythUIButtonList *m_parentList {nullptr};
369  QString m_searchText;
370 
371  MythUITextEdit *m_searchEdit {nullptr};
372  MythUIButton *m_prevButton {nullptr};
373  MythUIButton *m_nextButton {nullptr};
374  MythUIStateType *m_searchState {nullptr};
375 };
376 
378 
379 #endif
virtual void SetValue(const QString &value)
This widget is used for grouping other widgets for display when a particular named state is called.
bool HasImage(const QString &name="")
Returns true when the image exists.
unsigned int slots[4]
Definition: element.c:38
QVector< MythUIStateType * > m_ButtonList
virtual bool keyPressEvent(QKeyEvent *event)
Key event handler.
Definition: mythuitype.cpp:971
SearchButtonListDialog(MythScreenStack *parent, const char *name, MythUIButtonList *parentList, QString searchText)
QHash< QString, QString > m_actionRemap
void customEvent(QEvent *event) override
Definition: mythuitype.cpp:977
virtual void SetValue(int value)
int DecrRef(void) override
Decrements reference count and deletes on 0.
Definition: mythimage.cpp:55
virtual bool gestureEvent(MythGestureEvent *event)
Mouse click/movement handler, receives mouse gesture events from the QCoreApplication event loop.
Definition: mythuitype.cpp:986
int GetTopItemPos(void) const
virtual bool Create(void)
void setVisible(bool flag)
unsigned int uint
Definition: compat.h:140
QMap< QString, TextProperties > m_strings
Q_DECLARE_METATYPE(GrabberScript *)
QStringList m_lcdColumns
The base class on which all widgets and screens are based.
Definition: mythuitype.h:63
QMap< QString, MythImage * > m_images
virtual void CreateCopy(MythUIType *parent)
Copy the state of this widget to the one given, it must be of the same type.
VERBOSE_PREAMBLE false
Definition: verbosedefs.h:85
QHash< QString, QString > InfoMap
Definition: mythtypes.h:15
QDateTime current(bool stripped)
Returns current Date and Time in UTC.
Definition: mythdate.cpp:10
A text entry and edit widget.
Create a group of widgets.
Definition: mythuigroup.h:11
Wrapper around QRect allowing us to handle percentage and other relative values for areas in mythui.
Definition: mythrect.h:17
virtual void DrawSelf(MythPainter *p, int xoffset, int yoffset, int alphaMod, QRect clipRect)
Definition: mythuitype.cpp:465
A custom event that represents a mouse gesture.
Definition: mythgesture.h:39
const char * name
Definition: ParseText.cpp:328
List widget, displays list items in a variety of themeable arrangements and can trigger signals when ...
A single button widget.
Definition: mythuibutton.h:21
bool keyPressEvent(QKeyEvent *) override
Key event handler.
virtual void Reset(void)
Reset the widget to it's original state, should not reset changes made by the theme.
Definition: mythuitype.cpp:69
Scroll bar widget.
#define MUI_PUBLIC
Definition: mythuiexp.h:9
virtual void CopyFrom(MythUIType *base)
Copy this widgets state from another.
LayoutType GetLayout() const
Wrapper around QPoint allowing us to handle percentage and other relative values for positioning in m...
Definition: mythrect.h:86
Screen in which all other widgets are contained and rendered.
int GetCurrentPos() const
void SetSearchFields(const QString &fields)
QList< MythUIButtonListItem * > m_itemList
virtual bool ParseElement(const QString &filename, QDomElement &element, bool showWarnings)
Parse the xml definition of this widget setting the state of the object accordingly.
A tree widget for displaying and navigating a MythGenericTree()
QMap< int, MythUIButtonListItem * > m_ButtonToItem
virtual void Finalize(void)
Perform any post-xml parsing initialisation tasks.