diff options
author | Ken Moore <ken@ixsystems.com> | 2016-10-20 14:36:40 -0400 |
---|---|---|
committer | Ken Moore <ken@ixsystems.com> | 2016-10-20 14:36:40 -0400 |
commit | 021dad072d5db15f79cc11b44ee4708258503c05 (patch) | |
tree | b852af9845bf6f551f635b05ff0d1892d10065af /src-qt5/desktop-utils/lumina-calculator/EqValidator.h | |
parent | Add the ability to acknowledge the "power" symbol (^) within an equation (diff) | |
download | lumina-021dad072d5db15f79cc11b44ee4708258503c05.tar.gz lumina-021dad072d5db15f79cc11b44ee4708258503c05.tar.bz2 lumina-021dad072d5db15f79cc11b44ee4708258503c05.zip |
Finish cleaning up some of the calculator:
1) Add an input validator to the line edit to ensure only valid characters get added
2) Add the ability to click a history item to copy that equation into the line edit.
3) Turn off some debugging messages.
Diffstat (limited to 'src-qt5/desktop-utils/lumina-calculator/EqValidator.h')
-rw-r--r-- | src-qt5/desktop-utils/lumina-calculator/EqValidator.h | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src-qt5/desktop-utils/lumina-calculator/EqValidator.h b/src-qt5/desktop-utils/lumina-calculator/EqValidator.h new file mode 100644 index 00000000..462a330d --- /dev/null +++ b/src-qt5/desktop-utils/lumina-calculator/EqValidator.h @@ -0,0 +1,39 @@ +//=========================================== +// Lumina Desktop source code +// Copyright (c) 2016, Ken Moore +// Available under the 3-clause BSD license +// See the LICENSE file for full details +//=========================================== +#ifndef _LUMINA_CALCULATOR_VALIDATOR_H +#define _LUMINA_CALCULATOR_VALIDATOR_H + +#define VALIDCHARS QString("x*+-/^eE().0123456789") +#define NOSTARTCHARS QString("x*/^)eE.") +#define NOENDCHARS QString("x*/^(eE.") +#define NOCHANGE QString("().") + +#include <QValidator> +#include <QString> +#include <QDebug> + +class EqValidator : public QValidator{ + Q_OBJECT +public: + EqValidator(QObject *parent = 0) : QValidator(parent){} + ~EqValidator(){} + + virtual void fixup(QString &input) const{ + if(input.isEmpty()){ return; } + if( NOSTARTCHARS.contains(input.left(1)) && !NOCHANGE.contains(input.left(1)) ){ input.prepend("1"); } + if( NOENDCHARS.contains(input.right(1)) && !NOCHANGE.contains(input.right(1)) ){ input.append("1"); } + } + + virtual QValidator::State validate(QString &input, int&pos) const { + //qDebug() << "Got validate:" << input << pos; + if(pos>0 && !VALIDCHARS.contains(input[pos-1])){ return QValidator::Invalid; } + if(!input.isEmpty() && NOSTARTCHARS.contains(input.left(1))){ return QValidator::Intermediate; } + if(!input.isEmpty() && NOENDCHARS.contains(input.right(1))){ return QValidator::Intermediate; } + return QValidator::Acceptable; + } +}; +#endif |