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
208 enum MovementUnit : std::uint8_t
209 { MoveItem, MoveColumn, MoveRow, MovePage, MoveMax,
210 MoveMid, MoveByAmount };
211 enum LayoutType : std::uint8_t
212 { LayoutVertical, LayoutHorizontal, LayoutGrid };
213
214#if 0
215 void SetDrawFromBottom(bool draw);
216#endif
217
218 void Reset() override; // MythUIType
219 void Update();
220
221 virtual void SetValue(int value) { MoveToNamedPosition(QString::number(value)); }
222 virtual void SetValue(const QString &value) { MoveToNamedPosition(value); }
223 void SetValueByData(const QVariant& data);
224 virtual int GetIntValue() const;
225 virtual QString GetValue() const;
226 QVariant GetDataValue() const;
227 MythRect GetButtonArea(void) const;
228
229 void SetItemCurrent(MythUIButtonListItem* item);
230 void SetItemCurrent(int current, int topPos = -1);
231 MythUIButtonListItem* GetItemCurrent() const;
232 MythUIButtonListItem* GetItemFirst() const;
233 MythUIButtonListItem* GetItemNext(MythUIButtonListItem *item) const;
234 MythUIButtonListItem* GetItemAt(int pos) const;
235 MythUIButtonListItem* GetItemByData(const QVariant& data);
236
237 uint ItemWidth(void);
238 uint ItemHeight(void);
239 LayoutType GetLayout() const { return m_layout; }
240
241 bool MoveItemUpDown(MythUIButtonListItem *item, bool up);
242
243 void SetAllChecked(MythUIButtonListItem::CheckState state);
244
245 int GetCurrentPos() const { return m_selPosition; }
246 int GetItemPos(MythUIButtonListItem* item) const;
247 int GetTopItemPos(void) const { return m_topPosition; }
248 int GetCount() const;
249 int GetVisibleCount();
250 bool IsEmpty() const;
251
252 virtual bool MoveDown(MovementUnit unit = MoveItem, uint amount = 0);
253 virtual bool MoveUp(MovementUnit unit = MoveItem, uint amount = 0);
254 bool MoveToNamedPosition(const QString &position_name);
255
256 void RemoveItem(MythUIButtonListItem *item);
257
258 bool IsShadowing(void) { return m_shadowListName == GetFocusedName(); }
259 void SetLCDTitles(const QString &title, const QString &columnList = "");
260 void updateLCD(void);
261
262 void SetSearchFields(const QString &fields) { m_searchFields = fields; }
263 void ShowSearchDialog(void);
264 bool Find(const QString &searchStr, bool startsWith = false);
265 bool FindNext(void);
266 bool FindPrev(void);
267
268 void LoadInBackground(int start = 0, int pageSize = 20);
269 int StopLoad(void);
270
271 public slots:
272 void Select();
273 void Deselect();
274 void ToggleEnabled();
275
276 signals:
281
282 protected:
283 void customEvent(QEvent *event) override; // MythUIType
284
285 enum ScrollStyle : std::uint8_t
286 { ScrollFree, ScrollCenter, ScrollGroupCenter };
287 enum ArrangeType : std::uint8_t
288 { ArrangeFixed, ArrangeFill, ArrangeSpread, ArrangeStack };
289 enum WrapStyle : std::int8_t
290 { WrapCaptive = -1, WrapNone = 0, WrapSelect = 1,
291 WrapItems = 2, WrapFlowing = 3 };
292
293 void DrawSelf(MythPainter *p, int xoffset, int yoffset,
294 int alphaMod, QRect clipRect) override; // MythUIType
295 void Const();
296 virtual void Init();
297
298 void InsertItem(MythUIButtonListItem *item, int listPosition = -1);
299
300 int minButtonWidth(const MythRect & area);
301 int minButtonHeight(const MythRect & area);
302 void InitButton(int itemIdx, MythUIStateType* & realButton,
303 MythUIButtonListItem* & buttonItem);
304 MythUIGroup *PrepareButton(int buttonIdx, int itemIdx,
305 int & selectedIdx, int & button_shift);
306 bool DistributeRow(int & first_button, int & last_button,
307 int & first_item, int & last_item,
308 int & selected_column, int & skip_cols,
309 bool grow_left, bool grow_right,
310 int ** col_widths, int & row_height,
311 int total_height, int split_height,
312 int & col_cnt, bool & wrapped);
313 bool DistributeCols(int & first_button, int & last_button,
314 int & first_item, int & last_item,
315 int & selected_column, int & selected_row,
316 int & skip_cols, int ** col_widths,
317 QList<int> & row_heights,
318 int & top_height, int & bottom_height,
319 bool & wrapped);
320 bool DistributeButtons(void);
321 void CalculateButtonPositions(void);
322 void CalculateArrowStates(void);
323 void SetScrollBarPosition(void);
324 void ItemVisible(MythUIButtonListItem *item);
325
326 void SetActive(bool active);
327
328 int PageUp(void);
329 int PageDown(void);
330
331 bool DoFind(bool doMove, bool searchForward);
332
333 void FindEnabledUp(MovementUnit unit);
334 void FindEnabledDown(MovementUnit unit);
335
336 /* methods for subclasses to override */
337 virtual void CalculateVisibleItems(void);
338 virtual QPoint GetButtonPosition(int column, int row) const;
339
340 void SetButtonArea(const MythRect &rect);
341 bool ParseElement(const QString &filename, QDomElement &element,
342 bool showWarnings) override; // MythUIType
343 void CopyFrom(MythUIType *base) override; // MythUIType
344 void CreateCopy(MythUIType *parent) override; // MythUIType
345 void Finalize(void) override; // MythUIType
346
347 void SanitizePosition(void);
348
349
350
351 LayoutType m_layout {LayoutVertical};
352 ArrangeType m_arrange {ArrangeFixed};
353 ScrollStyle m_scrollStyle {ScrollFree};
354 WrapStyle m_wrapStyle {WrapNone};
355 int m_defaultAlignment {Qt::AlignLeft | Qt::AlignTop};
356 std::optional<int> m_shadowAlignment {std::nullopt};
357 MythRect m_contentsRect {0, 0, 0, 0};
358
359 MythPoint m_searchPosition {-2,-2};
360 QString m_searchFields {"**ALL**"};
361 QString m_searchStr;
362 bool m_searchStartsWith {false};
363
364 int m_itemWidth {0};
365 int m_itemHeight {0};
366 int m_itemHorizSpacing {0};
367 int m_itemVertSpacing {0};
368 int m_itemsVisible {0};
369 int m_maxVisible {0};
370 int m_rows {0};
371 int m_columns {0};
372 int m_leftColumns {0};
373 int m_rightColumns {0};
374 int m_topRows {0};
375 int m_bottomRows {0};
376
378
379 bool m_active {false};
380 bool m_showArrow {true};
381 bool m_showScrollBar {true};
382
383 MythUIScrollBar *m_scrollBar {nullptr};
384 MythUIStateType *m_upArrow {nullptr};
385 MythUIStateType *m_downArrow {nullptr};
386
387 MythUIStateType *m_buttontemplate {nullptr};
388
389 QVector<MythUIStateType *> m_buttonList;
390 QMap<int, MythUIButtonListItem *> m_buttonToItem;
391 QHash<QString, QString> m_actionRemap;
392
393 bool m_initialized {false};
394 bool m_needsUpdate {false};
395 bool m_clearing {false};
396
397 int m_selPosition {0};
398 int m_topPosition {0};
399 int m_itemCount {0};
400 bool m_keepSelAtBottom {false};
401
402 QList<MythUIButtonListItem*> m_itemList;
403 int m_nextItemLoaded {0};
404
405 bool m_defaultDrawFromBottom {false};
406 std::optional<bool> m_shadowDrawFromBottom {std::nullopt};
407
408 QString m_lcdTitle;
409 QStringList m_lcdColumns;
410
412 friend class MythUIButtonTree;
413};
414
416{
417 Q_OBJECT
418 public:
419 SearchButtonListDialog(MythScreenStack *parent, const char *name,
420 MythUIButtonList *parentList, QString searchText)
421 : MythScreenType(parent, name, false),
422 m_parentList(parentList), m_searchText(std::move(searchText)) {}
423 ~SearchButtonListDialog(void) override = default;
424
425 bool Create(void) override; // MythScreenType
426 bool keyPressEvent(QKeyEvent *event) override; // MythScreenType
427
428 protected slots:
429 void searchChanged(void);
430 void prevClicked(void);
431 void nextClicked(void);
432
433 protected:
434 bool m_startsWith {false};
435
436 MythUIButtonList *m_parentList {nullptr};
438
439 MythUITextEdit *m_searchEdit {nullptr};
440 MythUIButton *m_prevButton {nullptr};
441 MythUIButton *m_nextButton {nullptr};
442 MythUIStateType *m_searchState {nullptr};
443};
444
446
447#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