Loading...
Searching...
No Matches
PromptLineEdit.hpp
1#pragma once
2#include <QColor>
3#include <QLineEdit>
4#include <QString>
5#include <QStringList>
6
7#include <score_lib_base_export.h>
8
9#include <verdigris>
10
11class QKeyEvent;
12class QPaintEvent;
13class QCompleter;
14
15namespace score
16{
25class SCORE_LIB_BASE_EXPORT PromptLineEdit : public QLineEdit
26{
27 W_OBJECT(PromptLineEdit)
28
29public:
30 explicit PromptLineEdit(QWidget* parent = nullptr);
31 ~PromptLineEdit() override;
32
33 void historyAdd(const QString& line);
34 bool historySave(const QString& filename);
35 bool historyLoad(const QString& filename);
36 void historySetMaxLen(int len);
37 void historyClear();
38 QStringList historyGetAll() const { return m_history; }
39
40 void lineEntered(const QString& line)
41 E_SIGNAL(SCORE_LIB_BASE_EXPORT, lineEntered, line);
42
43 void setCompleter(QCompleter* completer);
44 QCompleter* completer() const;
45
46 void setHint(const QString& hint, const QColor& color = QColor(), bool bold = false);
47 void clearHint();
48 void hintRequested(const QString& currentText)
49 E_SIGNAL(SCORE_LIB_BASE_EXPORT, hintRequested, currentText);
50
51public:
52 void insertCompletion(const QString& s);
53 W_SLOT(insertCompletion);
54
55private:
56 void keyPressEvent(QKeyEvent* event) override;
57 void paintEvent(QPaintEvent* event) override;
58 void focusInEvent(QFocusEvent* e) override;
59
60 // Helper methods
61 void navigateHistory(bool up);
62 void updateHint();
63
64 // Completer processing
65 bool proceedCompleterBegin(QKeyEvent* e);
66 void proceedCompleterEnd(QKeyEvent* e);
67 QString wordUnderCursor() const;
68
69 // History management
70 QStringList m_history;
71 int m_historyMaxLen{};
72 int m_historyIndex{};
73 QString m_historyStash; // Stash current line when browsing history
74
75 // QCompleter-based completion
76 QCompleter* m_completer{};
77
78 // Hints
79 QString m_hint;
80 QColor m_hintColor{};
81 bool m_hintBold{};
82};
83}
PromptLineEdit - A QLineEdit with readline-like features.
Definition PromptLineEdit.hpp:26
Base toolkit upon which the software is built.
Definition Application.cpp:97