2 // promptlineedit.cpp: QLineEdit widget with uneditable (by user) prompt
4 // Part of the Architektonas Project
5 // (C) 2021 Underground Software
6 // See the README and GPLv3 files for licensing and warranty information
8 // JLH = James Hammons <jlhamm@acm.org>
11 // --- ---------- ------------------------------------------------------------
12 // JLH 11/27/2021 Created this file
15 #include "promptlineedit.h"
17 PromptLineEdit::PromptLineEdit(QWidget * parent/*= NULL*/): QLineEdit(parent)
19 connect(this, SIGNAL(cursorPositionChanged(int, int)), this, SLOT(HandleCursorMoved(int, int)));
20 connect(this, SIGNAL(textChanged(const QString &)), this, SLOT(HandleTextChanged(const QString &)));
21 connect(this, SIGNAL(selectionChanged(void)), this, SLOT(HandleSelectionChanged(void)));
26 PromptLineEdit::~PromptLineEdit()
30 void PromptLineEdit::HandleCursorMoved(int /*old*/, int neu)
32 if (neu < prompt.length())
33 setCursorPosition(prompt.length());
36 void PromptLineEdit::HandleTextChanged(const QString & s)
42 void PromptLineEdit::HandleSelectionChanged(void)
44 int selStart = selectionStart();
45 int selEnd = selectionEnd();
46 int promptLen = prompt.length();
51 if (selStart < promptLen)
52 setSelection(selEnd, -(selEnd - promptLen));
55 void PromptLineEdit::keyPressEvent(QKeyEvent * event)
57 if (event->key() == Qt::Key_Backspace)
59 if (cursorPosition() <= prompt.length())
66 QLineEdit::keyPressEvent(event);
69 QString PromptLineEdit::text(void) const
71 QString s = QLineEdit::text();
73 return s.right(s.length() - prompt.length());
76 void PromptLineEdit::SetPrompt(QString s)