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