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