]> Shamusworld >> Repos - architektonas/blob - src/consolewidget.cpp
Miscellaneous fixes/updates:
[architektonas] / src / consolewidget.cpp
1 //
2 // consolewidget.cpp: Command line widget
3 //
4 // Part of the Architektonas Project
5 // (C) 2021 Underground Software
6 // See the README and GPLv3 files for licensing and warranty information
7 //
8 // JLH = James Hammons <jlhamm@acm.org>
9 //
10 // WHO  WHEN        WHAT
11 // ---  ----------  ------------------------------------------------------------
12 // JLH  11/20/2021  Created this file
13 //
14
15 #include "consolewidget.h"
16
17 ConsoleWidget::ConsoleWidget(QWidget * parent/*= NULL*/): QWidget(parent)
18 {
19         cmdline = new PromptLineEdit(this);
20         cmdline->setFrame(false);
21
22         screen = new QTextEdit;
23         screen->setAlignment(Qt::AlignBottom | Qt::AlignLeft);
24         screen->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
25         screen->setReadOnly(true);
26
27         QVBoxLayout * mainLayout = new QVBoxLayout;
28         mainLayout->addWidget(screen);
29         mainLayout->addWidget(cmdline);
30
31         setLayout(mainLayout);
32
33         connect(cmdline, SIGNAL(returnPressed()), this, SLOT(Execute()));
34
35         QScrollBar * scrollbar = screen->verticalScrollBar();
36         connect(scrollbar, SIGNAL(rangeChanged(int, int)), this, SLOT(MoveScrollBarToBottom(int, int)));
37 }
38
39 ConsoleWidget::~ConsoleWidget()
40 {
41 }
42
43 void ConsoleWidget::Execute(void)
44 {
45         screen->append(cmdline->text());
46         screen->append("<font color=red>Error: don't know how to '" + cmdline->text() + "'</font>");
47         cmdline->clear();
48 }
49
50 void ConsoleWidget::MoveScrollBarToBottom(int min, int max)
51 {
52         Q_UNUSED(min);
53         screen->verticalScrollBar()->setValue(max);
54 }
55
56 void ConsoleWidget::paintEvent(QPaintEvent * /*event*/)
57 {
58 }