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