]> Shamusworld >> Repos - architektonas/blobdiff - src/consolewidget.cpp
Miscellaneous fixes/updates:
[architektonas] / src / consolewidget.cpp
diff --git a/src/consolewidget.cpp b/src/consolewidget.cpp
new file mode 100644 (file)
index 0000000..ce55cc4
--- /dev/null
@@ -0,0 +1,58 @@
+//
+// consolewidget.cpp: Command line widget
+//
+// Part of the Architektonas Project
+// (C) 2021 Underground Software
+// See the README and GPLv3 files for licensing and warranty information
+//
+// JLH = James Hammons <jlhamm@acm.org>
+//
+// WHO  WHEN        WHAT
+// ---  ----------  ------------------------------------------------------------
+// JLH  11/20/2021  Created this file
+//
+
+#include "consolewidget.h"
+
+ConsoleWidget::ConsoleWidget(QWidget * parent/*= NULL*/): QWidget(parent)
+{
+       cmdline = new PromptLineEdit(this);
+       cmdline->setFrame(false);
+
+       screen = new QTextEdit;
+       screen->setAlignment(Qt::AlignBottom | Qt::AlignLeft);
+       screen->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
+       screen->setReadOnly(true);
+
+       QVBoxLayout * mainLayout = new QVBoxLayout;
+       mainLayout->addWidget(screen);
+       mainLayout->addWidget(cmdline);
+
+       setLayout(mainLayout);
+
+       connect(cmdline, SIGNAL(returnPressed()), this, SLOT(Execute()));
+
+       QScrollBar * scrollbar = screen->verticalScrollBar();
+       connect(scrollbar, SIGNAL(rangeChanged(int, int)), this, SLOT(MoveScrollBarToBottom(int, int)));
+}
+
+ConsoleWidget::~ConsoleWidget()
+{
+}
+
+void ConsoleWidget::Execute(void)
+{
+       screen->append(cmdline->text());
+       screen->append("<font color=red>Error: don't know how to '" + cmdline->text() + "'</font>");
+       cmdline->clear();
+}
+
+void ConsoleWidget::MoveScrollBarToBottom(int min, int max)
+{
+       Q_UNUSED(min);
+       screen->verticalScrollBar()->setValue(max);
+}
+
+void ConsoleWidget::paintEvent(QPaintEvent * /*event*/)
+{
+}