]> Shamusworld >> Repos - architektonas/blob - src/consolewidget.cpp
Added Parallel tool + command processing.
[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 #include "commandprocessor.h"
17 #include "promptlineedit.h"
18 #include "structs.h"
19
20 ConsoleWidget::ConsoleWidget(QWidget * parent/*= NULL*/): QWidget(parent), cmdLine(new PromptLineEdit(this)), screen(new QTextEdit), cmdProc(new CommandProcessor)
21 {
22 //      cmdLine = new PromptLineEdit(this);
23         cmdLine->setFrame(false);
24
25 //      screen = new QTextEdit;
26         screen->setAlignment(Qt::AlignBottom | Qt::AlignLeft);
27         screen->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
28         screen->setReadOnly(true);
29
30         QVBoxLayout * mainLayout = new QVBoxLayout;
31         mainLayout->addWidget(screen);
32         mainLayout->addWidget(cmdLine);
33
34         setLayout(mainLayout);
35
36         connect(cmdLine, SIGNAL(returnPressed()), this, SLOT(Execute()));
37
38         QScrollBar * scrollbar = screen->verticalScrollBar();
39         connect(scrollbar, SIGNAL(rangeChanged(int, int)), this, SLOT(MoveScrollBarToBottom(int, int)));
40 }
41
42 ConsoleWidget::~ConsoleWidget()
43 {
44 }
45
46 void ConsoleWidget::Execute(void)
47 {
48         QString response = cmdProc->Process(cmdLine->text());
49
50         if (Global::tool == TTNone)
51                 screen->append(cmdLine->text());
52
53         if (response.length() > 0)
54                 screen->append(response);
55
56         cmdLine->clear();
57 }
58
59 void ConsoleWidget::SetToolPrompt(void)
60 {
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]));
63         else
64                 cmdLine->SetPrompt("ATNS");
65 }
66
67 void ConsoleWidget::MoveScrollBarToBottom(int min, int max)
68 {
69         Q_UNUSED(min);
70         screen->verticalScrollBar()->setValue(max);
71 }