terminalgui  0.1.0
Widgets for your terminal, powered by Qt! Create textual GUI (TUI) in your console easily.
tglistview.h
1 #pragma once
2 
3 #include <widgets/tgscrollarea.h>
4 
5 #include <QPointer>
6 #include <QModelIndex>
7 #include <QAbstractItemModel>
8 
9 namespace Tg {
10 class ListView : public ScrollArea
11 {
12  Q_OBJECT
13 
14  Q_PROPERTY(bool wrapRows READ wrapRows WRITE setWrapRows NOTIFY wrapRowsChanged)
15  Q_PROPERTY(bool alternatingRowColors READ alternatingRowColors WRITE setAlternatingRowColors NOTIFY alternatingRowColorsChanged)
16  Q_PROPERTY(Tg::Color alternativeBackgroundColor READ alternativeBackgroundColor WRITE setAlternativeBackgroundColor NOTIFY alternativeBackgroundColorChanged)
17  Q_PROPERTY(qsizetype currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged)
18  Q_PROPERTY(Tg::Color currentIndexColor READ currentIndexColor WRITE setCurrentIndexColor NOTIFY currentIndexColorChanged)
19  Q_PROPERTY(QAbstractItemModel* model READ model WRITE setModel NOTIFY modelChanged)
20 
21 public:
22  ListView(Widget *parent);
24 
25  QAbstractItemModel *model() const;
26  void setModel(QAbstractItemModel *model);
27 
28  bool wrapRows() const;
29  bool alternatingRowColors() const;
30  Tg::Color alternativeBackgroundColor() const;
31 
32  qsizetype currentIndex() const;
33  Tg::Color currentIndexColor() const;
34 
35 public slots:
36  void setWrapRows(const bool wrapRows);
37  void setAlternatingRowColors(const bool alternatingRowColors);
38  void setAlternativeBackgroundColor(const Tg::Color &alternativeBackgroundColor);
39  void setCurrentIndex(const qsizetype currentIndex);
40  void setCurrentIndexColor(const Tg::Color &currentIndexColor);
41 
42 signals:
43  void wrapRowsChanged(const bool wrapRows) const;
44  void alternatingRowColorsChanged(const bool alternatingRowColors) const;
45  void modelChanged(QAbstractItemModel* model) const;
46  void alternativeBackgroundColorChanged(const Tg::Color &alternativeBackgroundColor) const;
47  void currentIndexChanged(const qsizetype currentIndex) const;
48  void currentIndexColorChanged(const Tg::Color &currentIndexColor) const;
49 
50 protected:
51  void init() override;
52  void consumeKeyboardBuffer(const QString &keyboardBuffer) override;
53  QString drawAreaContents(const QPoint &pixel) const override;
54 
55  QString getLine(const int row) const;
56  QString getLine(const QModelIndex index) const;
57 
58 protected slots:
59  void updateChildrenDimensions() override;
60 
61 private:
62  QPointer<QAbstractItemModel> _model;
63  bool _wrapRows = false;
64  bool _alternatingRowColors = false;
65  Tg::Color _alternativeBackgroundColor;
66  Tg::Color _currentIndexColor;
67  qsizetype _currentIndex = 0;
68 };
69 }
Tg::Screen
Screen is the "canvas" on which widgets (subclasses of Widget) are drawn.
Definition: tgscreen.h:31
Tg::ListView::init
void init() override
Initializes Widget and it's connections.
Definition: tglistview.cpp:164
Tg::ListView
Definition: tglistview.h:11
Tg
All Terminal GUI classes (both core and widgets) are defined within the Tg namespace.
Definition: tgcolor.h:6
Tg::Widget
Base class for all widgets in a Terminal Gui application.
Definition: tgwidget.h:64
Tg::Color
Represents colors in a terminal.
Definition: tgcolor.h:20
Tg::Widget::screen
Screen * screen() const
Returns the Screen on which this Widget is being drawn.
Definition: tgwidget.cpp:174
Tg::ScrollArea
Definition: tgscrollarea.h:11
Tg::ListView::consumeKeyboardBuffer
void consumeKeyboardBuffer(const QString &keyboardBuffer) override
Called when Widget accepts focus and keyboardBuffer is not empty.
Definition: tglistview.cpp:182