Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Command line fixes and improvements #138

Merged
merged 8 commits into from
Jun 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
154 changes: 124 additions & 30 deletions src/commandline.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#include <QApplication>
#include "commandline.h"
#include "consts.h"
#include "preferences.h"

CommandLine::CommandLine()
CommandLine::CommandLine(QObject *parent) : QObject(parent),
m_terminated(false),
m_clearKeyTimer(new QTimer(this))
{
m_terminated = false;
m_clearKeyTimer->setSingleShot(true);
}

void CommandLine::processKey(Key value)
Expand Down Expand Up @@ -38,12 +41,20 @@ void CommandLine::processKey(Key value)
m_addresses.clear();
m_terminated = false;
}
else if (m_clearKeyTimer->isActive())
{
// Double tap, clear line
m_keyStack.clear();
m_errorText.clear();
}
else
{
// Backspace
m_keyStack.pop();
m_errorText.clear();
}

m_clearKeyTimer->start(QApplication::doubleClickInterval());
}
else
{
Expand All @@ -60,6 +71,29 @@ void CommandLine::processKey(Key value)
processStack();
}

void getSelection(QSet<int> *selection, int *numberEntry, int *startRange)
{
if(*startRange != 0 && *numberEntry != 0)
{
// Thru
if (*numberEntry > *startRange)
for(int i = *startRange; i <= *numberEntry; i++)
selection->insert(i);
else
for(int i = *numberEntry; i <= *startRange; i++)
selection->insert(i);
}
else
{
// Single
if(*numberEntry!=0)
selection->insert(*numberEntry);
}

*numberEntry = 0;
*startRange = 0;
}

void CommandLine::processStack()
{
enum {
Expand Down Expand Up @@ -106,7 +140,7 @@ void CommandLine::processStack()
{
// Not a valid entry, would be >512
state = stError;
m_errorText = "Error - number out of range";
m_errorText = E_RANGE;
return;
}

Expand All @@ -118,36 +152,43 @@ void CommandLine::processStack()
{
// Not a valid entry, would be >max
state = stError;
m_errorText = "Error - number out of range";
m_errorText = E_RANGE;
return;
}
}
break;

case THRU:
m_text.append(" THRU ");
m_text.append(QString(" %1 ").arg(K_THRU));
if(numberEntry==0 || state!=stChannel || startRange!=0)
{
m_errorText = "Error - syntax error";
m_errorText = E_SYNTAX;
return;
}
startRange=numberEntry;
numberEntry = 0;
break;

case AT:
m_text.append(" @ ");
if(startRange!=0 && numberEntry==0)
// [@] [@] = [@] [Full]
if (
m_keyStack.count() > 1 &&
m_keyStack.last() == m_keyStack[m_keyStack.count() - 2]
)
{
m_errorText = "Error - syntax error";
m_keyStack.pop();
processKey(FULL);
return;
}
if(startRange!=0 && numberEntry!=0)

m_text.append(QString(" %1 ").arg(K_AT));;
if(startRange!=0 && numberEntry==0)
{
for(int i=startRange; i<numberEntry; i++)
selection << i;
m_errorText = E_SYNTAX;
return;
}
if(numberEntry!=0) selection << numberEntry;

getSelection(&selection, &numberEntry, &startRange);

if(selection.isEmpty() && !m_previousKeyStack.isEmpty())
{
Expand All @@ -158,8 +199,7 @@ void CommandLine::processStack()
}

state = stLevels;
numberEntry = 0;
startRange = 0;

// Copy the entries up to the at to the last addresses
i=0;
m_previousKeyStack.clear();
Expand All @@ -171,14 +211,27 @@ void CommandLine::processStack()
break;

case AND:
m_text.append(" AND ");
m_text.append(QString(" %1 ").arg(K_AND));
if(numberEntry==0 || state != stChannel)
{
m_errorText = "Error - syntax error";
return;
if (m_keyStack.count() == 1 && !m_previousKeyStack.isEmpty())
{
// Empty command line and selection...use previous
m_keyStack = m_previousKeyStack;
processKey(AND);
return;
}
else
{
m_errorText = E_SYNTAX;
return;
}
}
selection << numberEntry;

getSelection(&selection, &numberEntry, &startRange);
numberEntry = 0;
startRange = 0;

break;

case ENTER:
Expand All @@ -199,26 +252,44 @@ void CommandLine::processStack()
return;

case FULL:
if(selection.isEmpty() && !m_previousKeyStack.isEmpty())
// Anything selected?
if(
selection.isEmpty()
&& m_keyStack.size()
&& !m_keyStack.contains(AT)
)
{
m_keyStack = m_previousKeyStack;
m_keyStack.push(AT);
m_keyStack.push(FULL);
processStack();
m_keyStack.pop();
processKey(AT);
processKey(FULL);
return;
}
else if (selection.isEmpty())
{
// ...Nope nothing
// Lets try the previous selection
if (!m_previousKeyStack.isEmpty())
{
m_keyStack = m_previousKeyStack;
processKey(AT);
processKey(FULL);
}
else
{
m_errorText = E_NO_SELECTION;
}
return;
}

if(state!=stLevels)
m_text.append(" @ ");
m_text.append("FULL*");
m_text.append(QString("%1*").arg(K_FULL));
if(startRange!=0 && numberEntry==0)
{
m_errorText = "Error : Syntax Error";
m_errorText = E_SYNTAX;
return;
}
if(state==stLevels && numberEntry!=0)
{
m_errorText = "Error : Syntax Error";
m_errorText = E_SYNTAX;
return;
}
m_level = MAX_SACN_LEVEL;
Expand All @@ -240,11 +311,34 @@ QString CommandLine::text()

/************************ CommandLineWidget ******************************/

CommandLineWidget::CommandLineWidget(QWidget *parent) : QTextEdit(parent)
CommandLineWidget::CommandLineWidget(QWidget *parent) : QTextEdit(parent),
m_cursorTimer(new QTimer(this)),
m_cursorState(true)
{
this->setReadOnly(true);
setStyleSheet("color: rgb(127, 255, 23);background: black;font: 75 12pt \"Courier\";");
clear();

// Cursor blinker
connect(m_cursorTimer, SIGNAL(timeout()), this, SLOT(flashCursor()));
m_cursorTimer->setInterval(300);
m_cursorTimer->setSingleShot(false);
m_cursorTimer->start();
}

void CommandLineWidget::flashCursor()
{
if (this->hasFocus())
{
auto cursor = (m_cursorState == true) ? "_" : "";
this->setText(QString("%1%2")
.arg(m_commandLine.text())
.arg(cursor));

m_cursorState = !m_cursorState;
} else {
this->setText(m_commandLine.text());
}
}

void CommandLineWidget::displayText()
Expand Down
24 changes: 22 additions & 2 deletions src/commandline.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,26 @@
#include <QPlainTextEdit>
#include <QStack>
#include <QLCDNumber>
#include <QTimer>
#include <QString>

class CommandLine
// Strings
static const QString K_THRU(QObject::tr("THRU"));
static const QString K_AT(QObject::tr("AT"));
static const QString K_FULL(QObject::tr("FULL"));
static const QString K_CLEAR(QObject::tr("CLEAR"));
static const QString K_AND(QObject::tr("AND"));

static const QString E_SYNTAX(QObject::tr("Error - syntax error"));
static const QString E_RANGE(QObject::tr("Error - number out of range"));
static const QString E_NO_SELECTION(QObject::tr("Error - no selection"));

class CommandLine : public QObject
{
Q_OBJECT
public:
explicit CommandLine(QObject *parent = nullptr);

enum Key {
K0,
K1,
Expand All @@ -30,7 +46,6 @@ class CommandLine
ALL_OFF
};

CommandLine();

QString text();
QString errorText() { return m_errorText; }
Expand All @@ -46,6 +61,7 @@ class CommandLine
bool m_terminated;
QStack<Key> m_previousKeyStack;
QStack<Key> m_keyStack;
QTimer *m_clearKeyTimer;
};

class CommandLineWidget : public QTextEdit
Expand Down Expand Up @@ -75,9 +91,13 @@ public slots:
void setLevels(QSet<int> addreses, int level);
protected:
virtual void keyPressEvent(QKeyEvent *e);
private slots:
void flashCursor();
private:
CommandLine m_commandLine;
void displayText();
QTimer *m_cursorTimer;
bool m_cursorState;
};

class EditableLCDNumber : public QLCDNumber
Expand Down
6 changes: 5 additions & 1 deletion src/transmitwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ transmitwindow::transmitwindow(int universe, QWidget *parent) :
QToolButton *button = new QToolButton(this);
button->setText(QString::number(i+1));
button->setMinimumSize(16, 16);
button->setFocusPolicy(Qt::FocusPolicy::NoFocus);
layout->addWidget(button);
m_presetButtons << button;
connect(button, SIGNAL(pressed()), this, SLOT(presetButtonPressed()));
Expand All @@ -85,6 +86,7 @@ transmitwindow::transmitwindow(int universe, QWidget *parent) :
m_presetButtons << recordButton;
recordButton->setCheckable(true);
recordButton->setIcon(QIcon(":/icons/record.png"));
recordButton->setFocusPolicy(Qt::FocusPolicy::NoFocus);
layout->addWidget(recordButton);
ui->gbPresets->setLayout(layout);
connect(recordButton, SIGNAL(toggled(bool)), this, SLOT(recordButtonPressed(bool)));
Expand Down Expand Up @@ -271,7 +273,7 @@ void transmitwindow::setUniverseOptsEnabled(bool enabled)
ui->gbProtocolVersion->setEnabled(enabled);
ui->cbBlind->setEnabled(enabled ? ui->rbRatified->isChecked() : false);
ui->tabWidget->setEnabled(!enabled);

on_tabWidget_currentChanged(ui->tabWidget->currentIndex());

if(enabled)
{
Expand Down Expand Up @@ -528,6 +530,8 @@ void transmitwindow::on_tabWidget_currentChanged(int index)
m_sender->setLevelRange(0, MAX_DMX_ADDRESS-1, 0);
QMetaObject::invokeMethod(
m_fxEngine,"pause");

ui->teCommandline->setFocus();
}

if(index==tabEffects)
Expand Down
Loading