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 requires is_nonconst_member_func_v<SLOT>
62 : MythUIButtonListItem(lbtype, text, QVariant::fromValue(static_cast<MythUICallbackMF>(slot)), listPosition) { }
63 template <typename SLOT>
65 const QString& text, SLOT slot, int listPosition = -1)
66 requires is_const_member_func_v<SLOT>
67 : MythUIButtonListItem(lbtype, text, QVariant::fromValue(static_cast<MythUICallbackMFc>(slot)), listPosition) { }
68 virtual ~MythUIButtonListItem();
69
70 MythUIButtonList *parent() const;
71
72 void SetText(const QString &text, const QString &name="",
73 const QString &state="");
74 void SetTextFromMap(const InfoMap &infoMap, const QString &state="");
75 void SetTextFromMap(const QMap<QString, TextProperties> &stringMap);
76 void SetTextCb(muibCbFn fn, void *data);
77 QString GetText(const QString &name="") const;
78 TextProperties GetTextProp(const QString &name = "") const;
79
80 bool FindText(const QString &searchStr, const QString &fieldList = "**ALL**",
81 bool startsWith = false) const;
82
83 void SetFontState(const QString &state, const QString &name="");
84
88 void SetImage(MythImage *image, const QString &name="");
89
95 MythImage *GetImage(const QString &name="");
96
98 bool HasImage(const QString &name="")
99 {
100 MythImage *img = GetImage(name);
101 if (img)
102 {
103 img->DecrRef();
104 return true;
105 }
106
107 return false;
108 }
109
110 void SetImage(const QString &filename, const QString &name="",
111 bool force_reload = false);
112 void SetImageFromMap(const InfoMap &imageMap);
113 void SetImageCb(muibCbFn fn, void *data);
114 QString GetImageFilename(const QString &name="") const;
115
116 void SetProgress1(int start, int total, int used);
117 void SetProgress2(int start, int total, int used);
118
119 void DisplayState(const QString &state, const QString &name);
120 void SetStatesFromMap(const InfoMap &stateMap);
121 void SetStateCb(muibCbFn fn, void *data);
122 QString GetState(const QString &name);
123
124 bool isVisible() const { return m_isVisible; }
125 void setVisible(bool flag) { m_isVisible = flag; }
126
127 bool checkable() const;
128 void setCheckable(bool flag);
129
130 bool isEnabled() const;
131 void setEnabled(bool flag);
132
133 CheckState state() const;
134 void setChecked(CheckState state);
135
136 void setDrawArrow(bool flag);
137
138 void SetData(QVariant data);
139 QVariant GetData();
140
141 bool MoveUpDown(bool flag);
142
143 virtual void SetToRealButton(MythUIStateType *button, bool selected);
144
145 private:
146 void DoButtonText(MythUIText *buttontext);
147 void DoButtonImage(MythUIImage *buttonimage);
148 void DoButtonArrow(MythUIImage *buttonarrow) const;
149 void DoButtonCheck(MythUIStateType *buttoncheck);
150 void DoButtonProgress1(MythUIProgressBar *buttonprogress) const;
151 void DoButtonProgress2(MythUIProgressBar *buttonprogress) const;
152 void DoButtonLookupText(MythUIText *text, const TextProperties& textprop);
153 static void DoButtonLookupFilename(MythUIImage *image, const QString& filename);
154 static void DoButtonLookupImage(MythUIImage *uiimage, MythImage *image);
155 static void DoButtonLookupState(MythUIStateType *statetype, const QString& name);
156
157 protected:
158 MythUIButtonList *m_parent {nullptr};
159 QString m_text;
160 QString m_fontState;
161 MythImage *m_image {nullptr};
163 bool m_checkable {false};
164 CheckState m_state {CantCheck};
165 QVariant m_data {0};
166 bool m_showArrow {false};
167 bool m_isVisible {false};
168 bool m_enabled {true};
169 bool m_debugme {false};
172
173 QMap<QString, TextProperties> m_strings;
174 QMap<QString, MythImage*> m_images;
180
181 friend class MythUIButtonList;
182 friend class MythGenericTree;
183};
184
195{
196 Q_OBJECT
197 public:
198 MythUIButtonList(MythUIType *parent, const QString &name,
199 QString shadow = "");
200 MythUIButtonList(MythUIType *parent, const QString &name,
201 QRect area, bool showArrow = true,
202 bool showScrollBar = false);
203 ~MythUIButtonList() override;
204
205 bool keyPressEvent(QKeyEvent *event) override; // MythUIType
206 bool gestureEvent(MythGestureEvent *event) override; // MythUIType
207 void customEvent(QEvent *event) override; // MythUIType
208
209 enum MovementUnit : std::uint8_t
210 { MoveItem, MoveColumn, MoveRow, MovePage, MoveMax,
211 MoveMid, MoveByAmount };
212 enum LayoutType : std::uint8_t
213 { LayoutVertical, LayoutHorizontal, LayoutGrid };
214
215#if 0
216 void SetDrawFromBottom(bool draw);
217#endif
218
219 void Reset() override; // MythUIType
220 void Update();
221
222 virtual void SetValue(int value) { MoveToNamedPosition(QString::number(value)); }
223 virtual void SetValue(const QString &value) { MoveToNamedPosition(value); }
224 void SetValueByData(const QVariant& data);
225 virtual int GetIntValue() const;
226 virtual QString GetValue() const;
227 QVariant GetDataValue() const;
228 MythRect GetButtonArea(void) const;
229
230 void SetItemCurrent(MythUIButtonListItem* item);
231 void SetItemCurrent(int current, int topPos = -1);
232 MythUIButtonListItem* GetItemCurrent() const;
233 MythUIButtonListItem* GetItemFirst() const;
234 MythUIButtonListItem* GetItemNext(MythUIButtonListItem *item) const;
235 MythUIButtonListItem* GetItemAt(int pos) const;
236 MythUIButtonListItem* GetItemByData(const QVariant& data);
237
238 uint ItemWidth(void);
239 uint ItemHeight(void);
240 LayoutType GetLayout() const { return m_layout; }
241
242 bool MoveItemUpDown(MythUIButtonListItem *item, bool up);
243
244 void SetAllChecked(MythUIButtonListItem::CheckState state);
245
246 int GetCurrentPos() const { return m_selPosition; }
247 int GetItemPos(MythUIButtonListItem* item) const;
248 int GetTopItemPos(void) const { return m_topPosition; }
249 int GetCount() const;
250 int GetVisibleCount();
251 bool IsEmpty() const;
252
253 virtual bool MoveDown(MovementUnit unit = MoveItem, uint amount = 0);
254 virtual bool MoveUp(MovementUnit unit = MoveItem, uint amount = 0);
255 bool MoveToNamedPosition(const QString &position_name);
256
257 void RemoveItem(MythUIButtonListItem *item);
258
259 bool IsShadowing(void) { return m_shadowListName == GetFocusedName(); }
260 void SetLCDTitles(const QString &title, const QString &columnList = "");
261 void updateLCD(void);
262
263 void SetSearchFields(const QString &fields) { m_searchFields = fields; }
264 void ShowSearchDialog(void);
265 bool Find(const QString &searchStr, bool startsWith = false);
266 bool FindNext(void);
267 bool FindPrev(void);
268
269 void LoadInBackground(int start = 0, int pageSize = 20);
270 int StopLoad(void);
271
272 public slots:
273 void Select();
274 void Deselect();
275 void ToggleEnabled();
276
277 signals:
282
283 protected:
284 enum ScrollStyle : std::uint8_t
285 { ScrollFree, ScrollCenter, ScrollGroupCenter };
286 enum ArrangeType : std::uint8_t
287 { ArrangeFixed, ArrangeFill, ArrangeSpread, ArrangeStack };
288 enum WrapStyle : std::int8_t
289 { WrapCaptive = -1, WrapNone = 0, WrapSelect = 1,
290 WrapItems = 2, WrapFlowing = 3 };
291
292 void DrawSelf(MythPainter *p, int xoffset, int yoffset,
293 int alphaMod, QRect clipRect) override; // MythUIType
294 void Const();
295 virtual void Init();
296
297 void InsertItem(MythUIButtonListItem *item, int listPosition = -1);
298
299 int minButtonWidth(const MythRect & area);
300 int minButtonHeight(const MythRect & area);
301 void InitButton(int itemIdx, MythUIStateType* & realButton,
302 MythUIButtonListItem* & buttonItem);
303 MythUIGroup *PrepareButton(int buttonIdx, int itemIdx,
304 int & selectedIdx, int & button_shift);
305 bool DistributeRow(int & first_button, int & last_button,
306 int & first_item, int & last_item,
307 int & selected_column, int & skip_cols,
308 bool grow_left, bool grow_right,
309 int ** col_widths, int & row_height,
310 int total_height, int split_height,
311 int & col_cnt, bool & wrapped);
312 bool DistributeCols(int & first_button, int & last_button,
313 int & first_item, int & last_item,
314 int & selected_column, int & selected_row,
315 int & skip_cols, int ** col_widths,
316 QList<int> & row_heights,
317 int & top_height, int & bottom_height,
318 bool & wrapped);
319 bool DistributeButtons(void);
320 void CalculateButtonPositions(void);
321 void CalculateArrowStates(void);
322 void SetScrollBarPosition(void);
323 void ItemVisible(MythUIButtonListItem *item);
324
325 void SetActive(bool active);
326
327 int PageUp(void);
328 int PageDown(void);
329
330 bool DoFind(bool doMove, bool searchForward);
331
332 void FindEnabledUp(MovementUnit unit);
333 void FindEnabledDown(MovementUnit unit);
334
335 /* methods for subclasses to override */
336 virtual void CalculateVisibleItems(void);
337 virtual QPoint GetButtonPosition(int column, int row) const;
338
339 void SetButtonArea(const MythRect &rect);
340 bool ParseElement(const QString &filename, QDomElement &element,
341 bool showWarnings) override; // MythUIType
342 void CopyFrom(MythUIType *base) override; // MythUIType
343 void CreateCopy(MythUIType *parent) override; // MythUIType
344 void Finalize(void) override; // MythUIType
345
346 void SanitizePosition(void);
347
348
349
350 LayoutType m_layout {LayoutVertical};
351 ArrangeType m_arrange {ArrangeFixed};
352 ScrollStyle m_scrollStyle {ScrollFree};
353 WrapStyle m_wrapStyle {WrapNone};
354 int m_defaultAlignment {Qt::AlignLeft | Qt::AlignTop};
355 std::optional<int> m_shadowAlignment {std::nullopt};
356 MythRect m_contentsRect {0, 0, 0, 0};
357
358 MythPoint m_searchPosition {-2,-2};
359 QString m_searchFields {"**ALL**"};
360 QString m_searchStr;
361 bool m_searchStartsWith {false};
362
363 int m_itemWidth {0};
364 int m_itemHeight {0};
365 int m_itemHorizSpacing {0};
366 int m_itemVertSpacing {0};
367 int m_itemsVisible {0};
368 int m_maxVisible {0};
369 int m_rows {0};
370 int m_columns {0};
371 int m_leftColumns {0};
372 int m_rightColumns {0};
373 int m_topRows {0};
374 int m_bottomRows {0};
375
377
378 bool m_active {false};
379 bool m_showArrow {true};
380 bool m_showScrollBar {true};
381
382 MythUIScrollBar *m_scrollBar {nullptr};
383 MythUIStateType *m_upArrow {nullptr};
384 MythUIStateType *m_downArrow {nullptr};
385
386 MythUIStateType *m_buttontemplate {nullptr};
387
388 QVector<MythUIStateType *> m_buttonList;
389 QMap<int, MythUIButtonListItem *> m_buttonToItem;
390 QHash<QString, QString> m_actionRemap;
391
392 bool m_initialized {false};
393 bool m_needsUpdate {false};
394 bool m_clearing {false};
395
396 int m_selPosition {0};
397 int m_topPosition {0};
398 int m_itemCount {0};
399 bool m_keepSelAtBottom {false};
400
401 QList<MythUIButtonListItem*> m_itemList;
402 int m_nextItemLoaded {0};
403
404 bool m_defaultDrawFromBottom {false};
405 std::optional<bool> m_shadowDrawFromBottom {std::nullopt};
406
407 QString m_lcdTitle;
408 QStringList m_lcdColumns;
409
411 friend class MythUIButtonTree;
412};
413
415{
416 Q_OBJECT
417 public:
418 SearchButtonListDialog(MythScreenStack *parent, const char *name,
419 MythUIButtonList *parentList, QString searchText)
420 : MythScreenType(parent, name, false),
421 m_parentList(parentList), m_searchText(std::move(searchText)) {}
422 ~SearchButtonListDialog(void) override = default;
423
424 bool Create(void) override; // MythScreenType
425 bool keyPressEvent(QKeyEvent *event) override; // MythScreenType
426
427 protected slots:
428 void searchChanged(void);
429 void prevClicked(void);
430 void nextClicked(void);
431
432 protected:
433 bool m_startsWith {false};
434
435 MythUIButtonList *m_parentList {nullptr};
437
438 MythUITextEdit *m_searchEdit {nullptr};
439 MythUIButton *m_prevButton {nullptr};
440 MythUIButton *m_nextButton {nullptr};
441 MythUIStateType *m_searchState {nullptr};
442};
443
445
446#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.
QMap< QString, MythImage * > m_images
MythUIButtonListItem(MythUIButtonList *lbtype, const QString &text, SLOT slot, int listPosition=-1)
MythUIButtonListItem(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:97
SearchButtonListDialog(MythScreenStack *parent, const char *name, MythUIButtonList *parentList, QString searchText)
~SearchButtonListDialog(void) override=default
unsigned int uint
Definition: compat.h:60
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
constexpr bool is_nonconst_member_func_v
Definition: mythuitype.h:67
constexpr bool is_const_member_func_v
Definition: mythuitype.h:64
QDateTime current(bool stripped)
Returns current Date and Time in UTC.
Definition: mythdate.cpp:15
VERBOSE_PREAMBLE false
Definition: verbosedefs.h:80