terminalgui  0.1.0
Widgets for your terminal, powered by Qt! Create textual GUI (TUI) in your console easily.
tglineedit.h
1 #pragma once
2 
3 #include <widgets/tglabel.h>
4 
5 namespace Tg {
6 class LineEdit : public Label
7 {
8  Q_OBJECT
9 
10  Q_PROPERTY(QString placeholderText READ placeholderText WRITE setPlaceholderText NOTIFY placeholderTextChanged)
11  Q_PROPERTY(int cursorPosition READ cursorPosition WRITE setCursorPosition NOTIFY cursorPositionChanged)
12 
13  Q_PROPERTY(Tg::Color placeholderTextColor READ placeholderTextColor WRITE setPlaceholderTextColor NOTIFY placeholderTextColorChanged)
14  Q_PROPERTY(Tg::Color placeholderBackgroundColor READ placeholderBackgroundColor WRITE setPlaceholderBackgroundColor NOTIFY placeholderBackgroundColorChanged)
15 
16 public:
17  LineEdit(Widget *parent);
19  LineEdit(const QString &placeholderText = QString(), Widget *parent = nullptr);
20  LineEdit(const QString &placeholderText = QString(), Screen *screen = nullptr);
21 
22  QString placeholderText() const;
23  int cursorPosition() const;
24 
25  Tg::Color placeholderTextColor() const;
26  Tg::Color placeholderBackgroundColor() const;
27 
28 public slots:
29  void setPlaceholderText(const QString &placeholderText);
30  void setCursorPosition(const int cursorPosition);
31 
32  void setPlaceholderTextColor(const Tg::Color &placeholderTextColor);
33  void setPlaceholderBackgroundColor(const Tg::Color &placeholderBackgroundColor);
34 
35 signals:
36  void placeholderTextChanged(const QString &placeholderText) const;
37  void cursorPositionChanged(const int cursorPosition) const;
38  void placeholderTextColorChanged(const Tg::Color &placeholderTextColor) const;
39  void placeholderBackgroundColorChanged(const Tg::Color &placeholderBackgroundColor) const;
40 
41 protected:
42  void init() override;
43  void consumeKeyboardBuffer(const QString &keyboardBuffer) override;
44 
45  void displayPlaceholderText();
46 
47 private:
48  QString _placeholderText;
49  QString _realText;
50  int _cursorPosition = 0;
51  Tg::Color _placeholderTextColor;
52  Tg::Color _placeholderBackgroundColor;
53 };
54 }
Tg::Screen
Screen is the "canvas" on which widgets (subclasses of Widget) are drawn.
Definition: tgscreen.h:31
Tg::LineEdit::init
void init() override
Initializes Widget and it's connections.
Definition: tglineedit.cpp:98
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::LineEdit
Definition: tglineedit.h:7
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::LineEdit::consumeKeyboardBuffer
void consumeKeyboardBuffer(const QString &keyboardBuffer) override
Called when Widget accepts focus and keyboardBuffer is not empty.
Definition: tglineedit.cpp:117
Tg::Label
Definition: tglabel.h:7