2 // consolewidget.cpp: Command line widget
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/20/2021 Created this file
15 #include "consolewidget.h"
17 ConsoleWidget::ConsoleWidget(QWidget * parent/*= NULL*/): QWidget(parent)
19 cmdline = new PromptLineEdit(this);
20 cmdline->setFrame(false);
22 screen = new QTextEdit;
23 screen->setAlignment(Qt::AlignBottom | Qt::AlignLeft);
24 screen->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
25 screen->setReadOnly(true);
27 QVBoxLayout * mainLayout = new QVBoxLayout;
28 mainLayout->addWidget(screen);
29 mainLayout->addWidget(cmdline);
31 setLayout(mainLayout);
33 connect(cmdline, SIGNAL(returnPressed()), this, SLOT(Execute()));
35 QScrollBar * scrollbar = screen->verticalScrollBar();
36 connect(scrollbar, SIGNAL(rangeChanged(int, int)), this, SLOT(MoveScrollBarToBottom(int, int)));
39 ConsoleWidget::~ConsoleWidget()
43 void ConsoleWidget::Execute(void)
45 screen->append(cmdline->text());
46 screen->append("<font color=red>Error: don't know how to '" + cmdline->text() + "'</font>");
50 void ConsoleWidget::MoveScrollBarToBottom(int min, int max)
53 screen->verticalScrollBar()->setValue(max);
56 void ConsoleWidget::paintEvent(QPaintEvent * /*event*/)