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"
16 #include "commandprocessor.h"
17 #include "promptlineedit.h"
20 ConsoleWidget::ConsoleWidget(QWidget * parent/*= NULL*/): QWidget(parent), cmdLine(new PromptLineEdit(this)), screen(new QTextEdit), cmdProc(new CommandProcessor)
22 // cmdLine = new PromptLineEdit(this);
23 cmdLine->setFrame(false);
25 // screen = new QTextEdit;
26 screen->setAlignment(Qt::AlignBottom | Qt::AlignLeft);
27 screen->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
28 screen->setReadOnly(true);
30 QVBoxLayout * mainLayout = new QVBoxLayout;
31 mainLayout->addWidget(screen);
32 mainLayout->addWidget(cmdLine);
34 setLayout(mainLayout);
36 connect(cmdLine, SIGNAL(returnPressed()), this, SLOT(Execute()));
38 QScrollBar * scrollbar = screen->verticalScrollBar();
39 connect(scrollbar, SIGNAL(rangeChanged(int, int)), this, SLOT(MoveScrollBarToBottom(int, int)));
42 ConsoleWidget::~ConsoleWidget()
46 void ConsoleWidget::Execute(void)
48 QString response = cmdProc->Process(cmdLine->text());
50 if (Global::tool == TTNone)
51 screen->append(cmdLine->text());
53 if (response.length() > 0)
54 screen->append(response);
59 void ConsoleWidget::SetToolPrompt(void)
61 if (Global::tool == TTParallel)
62 cmdLine->SetPrompt(QString("Parallel: set distance, number of repeats [%1 [%3]][, %2]").arg(Global::parallelDist / buInInches[Global::parallelBU]).arg(Global::parallelNum).arg(buShortName[Global::parallelBU]));
64 cmdLine->SetPrompt("ATNS");
67 void ConsoleWidget::MoveScrollBarToBottom(int min, int max)
70 screen->verticalScrollBar()->setValue(max);