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 
27 using muibCbFn = QString (*)(const QString &name, void *data);
28 struct muibCbInfo
29 {
30  muibCbFn fn {nullptr};
31  void* data {nullptr};
32 };
33 
35 {
36  public:
37  enum CheckState {
38  CantCheck = -1,
39  NotChecked = 0,
41  FullChecked
42  };
43 
44  MythUIButtonListItem(MythUIButtonList *lbtype, QString text,
45  QString image = "", bool checkable = false,
46  CheckState state = CantCheck, bool showArrow = false,
47  int listPosition = -1);
48  MythUIButtonListItem(MythUIButtonList *lbtype, const QString& text,
49  QVariant data, int listPosition = -1);
50  template <typename SLOT>
52  const QString& text, SLOT slot, int listPosition = -1)
53  : MythUIButtonListItem(lbtype, text, QVariant::fromValue(static_cast<MythUICallbackMF>(slot)), listPosition) { }
54  template <typename SLOT>
56  const QString& text, SLOT slot, int listPosition = -1)
57  : MythUIButtonListItem(lbtype, text, QVariant::fromValue(static_cast<MythUICallbackMFc>(slot)), listPosition) { }
58  virtual ~MythUIButtonListItem();
59 
60  MythUIButtonList *parent() const;
61 
62  void SetText(const QString &text, const QString &name="",
63  const QString &state="");
64  void SetTextFromMap(const InfoMap &infoMap, const QString &state="");
65  void SetTextFromMap(const QMap<QString, TextProperties> &stringMap);
66  void SetTextCb(muibCbFn fn, void *data);
67  QString GetText(const QString &name="") const;
68  TextProperties GetTextProp(const QString &name = "") const;
69 
70  bool FindText(const QString &searchStr, const QString &fieldList = "**ALL**",
71  bool startsWith = false) const;
72 
73  void SetFontState(const QString &state, const QString &name="");
74 
78  void SetImage(MythImage *image, const QString &name="");
79 
85  MythImage *GetImage(const QString &name="");
86 
88  bool HasImage(const QString &name="")
89  {
90  MythImage *img = GetImage(name);
91  if (img)
92  {
93  img->DecrRef();
94  return true;
95  }
96 
97  return false;
98  }
99 
100  void SetImage(const QString &filename, const QString &name="",
101  bool force_reload = false);
102  void SetImageFromMap(const InfoMap &imageMap);
103  void SetImageCb(muibCbFn fn, void *data);
104  QString GetImageFilename(const QString &name="") const;
105 
106  void DisplayState(const QString &state, const QString &name);
107  void SetStatesFromMap(const InfoMap &stateMap);
108  void SetStateCb(muibCbFn fn, void *data);
109  QString GetState(const QString &name);
110 
111  bool isVisible() const { return m_isVisible; }
112  void setVisible(bool flag) { m_isVisible = flag; }
113 
114  bool checkable() const;
115  void setCheckable(bool flag);
116 
117  bool isEnabled() const;
118  void setEnabled(bool flag);
119 
120  CheckState state() const;
121  void setChecked(CheckState state);
122 
123  void setDrawArrow(bool flag);
124 
125  void SetData(QVariant data);
126  QVariant GetData();
127 
128  bool MoveUpDown(bool flag);
129 
130  virtual void SetToRealButton(MythUIStateType *button, bool selected);
131 
132  private:
133  void DoButtonText(MythUIText *buttontext);
134  void DoButtonImage(MythUIImage *buttonimage);
135  void DoButtonArrow(MythUIImage *buttonarrow) const;
136  void DoButtonCheck(MythUIStateType *buttoncheck);
137  void DoButtonLookupText(MythUIText *text, const TextProperties& textprop);
138  static void DoButtonLookupFilename(MythUIImage *image, const QString& filename);
139  static void DoButtonLookupImage(MythUIImage *uiimage, MythImage *image);
140  static void DoButtonLookupState(MythUIStateType *statetype, const QString& name);
141 
142  protected:
143  MythUIButtonList *m_parent {nullptr};
144  QString m_text;
145  QString m_fontState;
146  MythImage *m_image {nullptr};
148  bool m_checkable {false};
149  CheckState m_state {CantCheck};
150  QVariant m_data {0};
151  bool m_showArrow {false};
152  bool m_isVisible {false};
153  bool m_enabled {true};
154  bool m_debugme {false};
155 
156  QMap<QString, TextProperties> m_strings;
157  QMap<QString, MythImage*> m_images;
163 
164  friend class MythUIButtonList;
165  friend class MythGenericTree;
166 };
167 
178 {
179  Q_OBJECT
180  public:
181  MythUIButtonList(MythUIType *parent, const QString &name);
182  MythUIButtonList(MythUIType *parent, const QString &name,
183  QRect area, bool showArrow = true,
184  bool showScrollBar = false);
185  ~MythUIButtonList() override;
186 
187  bool keyPressEvent(QKeyEvent *event) override; // MythUIType
188  bool gestureEvent(MythGestureEvent *event) override; // MythUIType
189  void customEvent(QEvent *event) override; // MythUIType
190 
191  enum MovementUnit { MoveItem, MoveColumn, MoveRow, MovePage, MoveMax,
192  MoveMid, MoveByAmount };
193  enum LayoutType { LayoutVertical, LayoutHorizontal, LayoutGrid };
194 
195  void SetDrawFromBottom(bool draw);
196 
197  void Reset() override; // MythUIType
198  void Update();
199 
200  virtual void SetValue(int value) { MoveToNamedPosition(QString::number(value)); }
201  virtual void SetValue(const QString &value) { MoveToNamedPosition(value); }
202  void SetValueByData(const QVariant& data);
203  virtual int GetIntValue() const;
204  virtual QString GetValue() const;
205  QVariant GetDataValue() const;
206  MythRect GetButtonArea(void) const;
207 
208  void SetItemCurrent(MythUIButtonListItem* item);
209  void SetItemCurrent(int current, int topPos = -1);
210  MythUIButtonListItem* GetItemCurrent() const;
211  MythUIButtonListItem* GetItemFirst() const;
212  MythUIButtonListItem* GetItemNext(MythUIButtonListItem *item) const;
213  MythUIButtonListItem* GetItemAt(int pos) const;
214  MythUIButtonListItem* GetItemByData(const QVariant& data);
215 
216  uint ItemWidth(void);
217  uint ItemHeight(void);
218  LayoutType GetLayout() const { return m_layout; }
219 
220  bool MoveItemUpDown(MythUIButtonListItem *item, bool up);
221 
222  void SetAllChecked(MythUIButtonListItem::CheckState state);
223 
224  int GetCurrentPos() const { return m_selPosition; }
225  int GetItemPos(MythUIButtonListItem* item) const;
226  int GetTopItemPos(void) const { return m_topPosition; }
227  int GetCount() const;
228  int GetVisibleCount();
229  bool IsEmpty() const;
230 
231  virtual bool MoveDown(MovementUnit unit = MoveItem, uint amount = 0);
232  virtual bool MoveUp(MovementUnit unit = MoveItem, uint amount = 0);
233  bool MoveToNamedPosition(const QString &position_name);
234 
235  void RemoveItem(MythUIButtonListItem *item);
236 
237  void SetLCDTitles(const QString &title, const QString &columnList = "");
238  void updateLCD(void);
239 
240  void SetSearchFields(const QString &fields) { m_searchFields = fields; }
241  void ShowSearchDialog(void);
242  bool Find(const QString &searchStr, bool startsWith = false);
243  bool FindNext(void);
244  bool FindPrev(void);
245 
246  void LoadInBackground(int start = 0, int pageSize = 20);
247  int StopLoad(void);
248 
249  public slots:
250  void Select();
251  void Deselect();
252  void ToggleEnabled();
253 
254  signals:
255  void itemSelected(MythUIButtonListItem* item);
256  void itemClicked(MythUIButtonListItem* item);
257  void itemVisible(MythUIButtonListItem* item);
258  void itemLoaded(MythUIButtonListItem* item);
259 
260  protected:
261  enum ScrollStyle { ScrollFree, ScrollCenter, ScrollGroupCenter };
262  enum ArrangeType { ArrangeFixed, ArrangeFill, ArrangeSpread, ArrangeStack };
263  enum WrapStyle { WrapCaptive = -1, WrapNone = 0, WrapSelect, WrapItems,
264  WrapFlowing };
265 
266  void DrawSelf(MythPainter *p, int xoffset, int yoffset,
267  int alphaMod, QRect clipRect) override; // MythUIType
268  void Const();
269  virtual void Init();
270 
271  void InsertItem(MythUIButtonListItem *item, int listPosition = -1);
272 
273  int minButtonWidth(const MythRect & area);
274  int minButtonHeight(const MythRect & area);
275  void InitButton(int itemIdx, MythUIStateType* & realButton,
276  MythUIButtonListItem* & buttonItem);
277  MythUIGroup *PrepareButton(int buttonIdx, int itemIdx,
278  int & selectedIdx, int & button_shift);
279  bool DistributeRow(int & first_button, int & last_button,
280  int & first_item, int & last_item,
281  int & selected_column, int & skip_cols,
282  bool grow_left, bool grow_right,
283  int ** col_widths, int & row_height,
284  int total_height, int split_height,
285  int & col_cnt, bool & wrapped);
286  bool DistributeCols(int & first_button, int & last_button,
287  int & first_item, int & last_item,
288  int & selected_column, int & selected_row,
289  int & skip_cols, int ** col_widths,
290  QList<int> & row_heights,
291  int & top_height, int & bottom_height,
292  bool & wrapped);
293  bool DistributeButtons(void);
294  void CalculateButtonPositions(void);
295  void CalculateArrowStates(void);
296  void SetScrollBarPosition(void);
297  void ItemVisible(MythUIButtonListItem *item);
298 
299  void SetActive(bool active);
300 
301  int PageUp(void);
302  int PageDown(void);
303 
304  bool DoFind(bool doMove, bool searchForward);
305 
306  void FindEnabledUp(MovementUnit unit);
307  void FindEnabledDown(MovementUnit unit);
308 
309  /* methods for subclasses to override */
310  virtual void CalculateVisibleItems(void);
311  virtual QPoint GetButtonPosition(int column, int row) const;
312 
313  void SetButtonArea(const MythRect &rect);
314  bool ParseElement(const QString &filename, QDomElement &element,
315  bool showWarnings) override; // MythUIType
316  void CopyFrom(MythUIType *base) override; // MythUIType
317  void CreateCopy(MythUIType *parent) override; // MythUIType
318  void Finalize(void) override; // MythUIType
319 
320  void SanitizePosition(void);
321 
322 
323 
324  LayoutType m_layout {LayoutVertical};
325  ArrangeType m_arrange {ArrangeFixed};
326  ScrollStyle m_scrollStyle {ScrollFree};
327  WrapStyle m_wrapStyle {WrapNone};
328  int m_alignment {Qt::AlignLeft | Qt::AlignTop};
329 
330  MythRect m_contentsRect {0, 0, 0, 0};
331 
332  MythPoint m_searchPosition {-2,-2};
333  QString m_searchFields {"**ALL**"};
334  QString m_searchStr;
335  bool m_searchStartsWith {false};
336 
337  int m_itemWidth {0};
338  int m_itemHeight {0};
339  int m_itemHorizSpacing {0};
340  int m_itemVertSpacing {0};
341  int m_itemsVisible {0};
342  int m_maxVisible {0};
343  int m_rows {0};
344  int m_columns {0};
345  int m_leftColumns {0};
346  int m_rightColumns {0};
347  int m_topRows {0};
348  int m_bottomRows {0};
349 
350  bool m_active {false};
351  bool m_showArrow {true};
352  bool m_showScrollBar {true};
353 
354  MythUIScrollBar *m_scrollBar {nullptr};
355  MythUIStateType *m_upArrow {nullptr};
356  MythUIStateType *m_downArrow {nullptr};
357 
358  MythUIStateType *m_buttontemplate {nullptr};
359 
360  QVector<MythUIStateType *> m_buttonList;
361  QMap<int, MythUIButtonListItem *> m_buttonToItem;
362  QHash<QString, QString> m_actionRemap;
363 
364  bool m_initialized {false};
365  bool m_needsUpdate {false};
366  bool m_clearing {false};
367 
368  int m_selPosition {0};
369  int m_topPosition {0};
370  int m_itemCount {0};
371  bool m_keepSelAtBottom {false};
372 
373  QList<MythUIButtonListItem*> m_itemList;
374  int m_nextItemLoaded {0};
375 
376  bool m_drawFromBottom {false};
377 
378  QString m_lcdTitle;
379  QStringList m_lcdColumns;
380 
381  friend class MythUIButtonListItem;
382  friend class MythUIButtonTree;
383 };
384 
386 {
387  Q_OBJECT
388  public:
389  SearchButtonListDialog(MythScreenStack *parent, const char *name,
390  MythUIButtonList *parentList, QString searchText)
391  : MythScreenType(parent, name, false),
392  m_parentList(parentList), m_searchText(std::move(searchText)) {}
393  ~SearchButtonListDialog(void) override = default;
394 
395  bool Create(void) override; // MythScreenType
396  bool keyPressEvent(QKeyEvent *event) override; // MythScreenType
397 
398  protected slots:
399  void searchChanged(void);
400  void prevClicked(void);
401  void nextClicked(void);
402 
403  protected:
404  bool m_startsWith {false};
405 
406  MythUIButtonList *m_parentList {nullptr};
407  QString m_searchText;
408 
409  MythUITextEdit *m_searchEdit {nullptr};
410  MythUIButton *m_prevButton {nullptr};
411  MythUIButton *m_nextButton {nullptr};
412  MythUIStateType *m_searchState {nullptr};
413 };
414 
416 
417 #endif
MythUIType::keyPressEvent
virtual bool keyPressEvent(QKeyEvent *event)
Key event handler.
Definition: mythuitype.cpp:993
MythUIButtonList::GetTopItemPos
int GetTopItemPos(void) const
Definition: mythuibuttonlist.h:226
Q_DECLARE_METATYPE
Q_DECLARE_METATYPE(GrabberScript *)
MythUIButtonList::m_itemList
QList< MythUIButtonListItem * > m_itemList
Definition: mythuibuttonlist.h:373
MythUIButtonListItem::isVisible
bool isVisible() const
Definition: mythuibuttonlist.h:111
MythUIButtonListItem::HalfChecked
@ HalfChecked
Definition: mythuibuttonlist.h:40
MythUIButtonList::GetLayout
LayoutType GetLayout() const
Definition: mythuibuttonlist.h:218
MythUIImage
Image widget, displays a single image or multiple images in sequence.
Definition: mythuiimage.h:97
MUI_PUBLIC
#define MUI_PUBLIC
Definition: mythuiexp.h:9
muibCbFn
QString(*)(const QString &name, void *data) muibCbFn
Definition: mythuibuttonlist.h:27
false
VERBOSE_PREAMBLE false
Definition: verbosedefs.h:85
MythUIButtonListItem::m_strings
QMap< QString, TextProperties > m_strings
Definition: mythuibuttonlist.h:156
MythUIButtonListItem::m_stateCb
muibCbInfo m_stateCb
Definition: mythuibuttonlist.h:162
MythUIButtonList::MoveRow
@ MoveRow
Definition: mythuibuttonlist.h:191
MythUIButtonListItem::m_imageFilenames
InfoMap m_imageFilenames
Definition: mythuibuttonlist.h:158
MythScreenStack
Definition: mythscreenstack.h:16
MythScreenType::Create
virtual bool Create(void)
Definition: mythscreentype.cpp:265
muibCbInfo
Definition: mythuibuttonlist.h:28
MythUIButtonListItem::m_fontState
QString m_fontState
Definition: mythuibuttonlist.h:145
MythUIType::customEvent
void customEvent(QEvent *event) override
Definition: mythuitype.cpp:999
MythUITextEdit
A text entry and edit widget.
Definition: mythuitextedit.h:32
SearchButtonListDialog::m_searchText
QString m_searchText
Definition: mythuibuttonlist.h:407
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:147
MythUIButtonListItem::m_textCb
muibCbInfo m_textCb
Definition: mythuibuttonlist.h:160
MythUIButtonList::SetSearchFields
void SetSearchFields(const QString &fields)
Definition: mythuibuttonlist.h:240
MythUIButtonListItem::MythUIButtonListItem
MythUIButtonListItem(typename std::enable_if< FunctionPointerTest< SLOT >::MemberFunction, MythUIButtonList * >::type lbtype, const QString &text, SLOT slot, int listPosition=-1)
Definition: mythuibuttonlist.h:51
MythUIButtonListItem::MythUIButtonListItem
MythUIButtonListItem(typename std::enable_if< FunctionPointerTest< SLOT >::MemberConstFunction, MythUIButtonList * >::type lbtype, const QString &text, SLOT slot, int listPosition=-1)
Definition: mythuibuttonlist.h:55
MythUIButtonListItem::setVisible
void setVisible(bool flag)
Definition: mythuibuttonlist.h:112
SearchButtonListDialog
Definition: mythuibuttonlist.h:385
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:1224
MythUIType::DrawSelf
virtual void DrawSelf(MythPainter *p, int xoffset, int yoffset, int alphaMod, QRect clipRect)
Definition: mythuitype.cpp:479
MythUIButtonList::m_buttonToItem
QMap< int, MythUIButtonListItem * > m_buttonToItem
Definition: mythuibuttonlist.h:361
MythDate::current
QDateTime current(bool stripped)
Returns current Date and Time in UTC.
Definition: mythdate.cpp:10
MythUIButtonListItem::m_imageCb
muibCbInfo m_imageCb
Definition: mythuibuttonlist.h:161
MythUIButtonListItem::CheckState
CheckState
Definition: mythuibuttonlist.h:37
MythUIButtonListItem::HasImage
bool HasImage(const QString &name="")
Returns true when the image exists.
Definition: mythuibuttonlist.h:88
InfoMap
QHash< QString, QString > InfoMap
Definition: mythtypes.h:15
MythUIButtonListItem
Definition: mythuibuttonlist.h:34
MythUICallbackMF
void(QObject::*)(void) MythUICallbackMF
Definition: mythuitype.h:43
MythUIButtonList::m_lcdColumns
QStringList m_lcdColumns
Definition: mythuibuttonlist.h:379
MythUIButtonList::GetCurrentPos
int GetCurrentPos() const
Definition: mythuibuttonlist.h:224
MythUIButtonList::ArrangeType
ArrangeType
Definition: mythuibuttonlist.h:262
MythUIButtonListItem::m_states
InfoMap m_states
Definition: mythuibuttonlist.h:159
hardwareprofile.config.p
p
Definition: config.py:33
MythUIButtonList::LayoutType
LayoutType
Definition: mythuibuttonlist.h:193
SearchButtonListDialog::SearchButtonListDialog
SearchButtonListDialog(MythScreenStack *parent, const char *name, MythUIButtonList *parentList, QString searchText)
Definition: mythuibuttonlist.h:389
MythUIButtonList::ScrollStyle
ScrollStyle
Definition: mythuibuttonlist.h:261
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
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:1167
GetState
#define GetState(a, b)
Definition: audiooutputopensles.cpp:48
MythUIButtonList::m_searchStr
QString m_searchStr
Definition: mythuibuttonlist.h:334
uint
unsigned int uint
Definition: compat.h:144
MythUIScrollBar
Scroll bar widget.
Definition: mythuiscrollbar.h:15
muibCbInfo::fn
muibCbFn fn
Definition: mythuibuttonlist.h:30
MythUIButtonList::MovementUnit
MovementUnit
Definition: mythuibuttonlist.h:191
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:157
MythUIButtonList::SetValue
virtual void SetValue(const QString &value)
Definition: mythuibuttonlist.h:201
mythimage.h
MythUIButtonList::m_actionRemap
QHash< QString, QString > m_actionRemap
Definition: mythuibuttonlist.h:362
MythUIText
All purpose text widget, displays a text string.
Definition: mythuitext.h:30
MythScreenType::keyPressEvent
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
Definition: mythscreentype.cpp:397
MythUIButtonListItem::m_text
QString m_text
Definition: mythuibuttonlist.h:144
MythUIButtonList::m_lcdTitle
QString m_lcdTitle
Definition: mythuibuttonlist.h:378
MythUIButtonList::LayoutVertical
@ LayoutVertical
Definition: mythuibuttonlist.h:193
MythUIButtonList::WrapStyle
WrapStyle
Definition: mythuibuttonlist.h:263
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:1009
std
Definition: mythchrono.h:23
MythGenericTree
Definition: mythgenerictree.h:27
MythUIButtonList::MoveMid
@ MoveMid
Definition: mythuibuttonlist.h:192
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:360
MythUIButtonList::SetValue
virtual void SetValue(int value)
Definition: mythuibuttonlist.h:200
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:1233
MythUIButtonList
List widget, displays list items in a variety of themeable arrangements and can trigger signals when ...
Definition: mythuibuttonlist.h:177
build_compdb.filename
filename
Definition: build_compdb.py:21
TextProperties::text
QString text
Definition: mythuibuttonlist.h:23
muibCbInfo::data
void * data
Definition: mythuibuttonlist.h:31
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:1309
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