Files
pay/BitcoinValue.h
T

85 lines
2.7 KiB
C++
Raw Permalink Normal View History

2020-06-12 20:53:01 +02:00
/*
* This file is part of the Flowee project
2021-11-03 18:29:31 +01:00
* Copyright (C) 2020-2021 Tom Zander <tom@flowee.org>
2020-06-12 20:53:01 +02:00
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef BITCOINVALUE_H
#define BITCOINVALUE_H
#include <QObject>
#include <QString>
class BitcoinValue : public QObject
{
Q_OBJECT
Q_PROPERTY(double value READ realValue WRITE setRealValue NOTIFY valueChanged)
Q_PROPERTY(QString enteredString READ enteredString WRITE setEnteredString NOTIFY enteredStringChanged)
2021-11-03 18:29:31 +01:00
Q_PROPERTY(int maxFractionalDigits READ maxFractionalDigits WRITE setMaxFractionalDigits RESET resetMaxFractionalDigits NOTIFY maxFractionalDigitsChanged)
Q_PROPERTY(int cursorPos READ cursorPos WRITE setCursorPos NOTIFY cursorPosChanged)
2020-06-12 20:53:01 +02:00
public:
explicit BitcoinValue(QObject *parent = nullptr);
qint64 value() const;
void setValue(qint64 value);
inline double realValue() {
return m_value;
}
inline void setRealValue(double val) {
setValue(val);
}
2021-11-03 18:29:31 +01:00
Q_INVOKABLE void moveLeft();
Q_INVOKABLE void moveRight();
Q_INVOKABLE void insertNumber(QChar number);
2020-06-12 20:53:01 +02:00
Q_INVOKABLE void addSeparator();
2020-06-22 12:14:13 +02:00
Q_INVOKABLE void paste();
2020-06-12 20:53:01 +02:00
Q_INVOKABLE void backspacePressed();
2021-11-09 20:41:37 +01:00
Q_INVOKABLE void reset();
2020-06-12 20:53:01 +02:00
QString enteredString() const;
2020-06-12 20:53:01 +02:00
void setEnteredString(const QString &s);
2021-11-03 18:29:31 +01:00
/*
* For fiat prices we want to limit the number of digits after
* the unit separator. This allows us to do so.
* Notice that reset unsets this making the number of digits follow the
* Bitcoin Cash unit selected application-wide.
*/
int maxFractionalDigits() const;
void setMaxFractionalDigits(int newMaxFractionalDigits);
void resetMaxFractionalDigits();
int cursorPos() const;
void setCursorPos(int newCursorPos);
2020-06-12 20:53:01 +02:00
signals:
void valueChanged();
void enteredStringChanged();
2021-11-03 18:29:31 +01:00
void maxFractionalDigitsChanged();
void cursorPosChanged();
2020-06-12 20:53:01 +02:00
private:
2021-11-03 18:29:31 +01:00
// sets integer form of m_value from the \a value
void setStringValue(const QString &value);
2020-06-12 20:53:01 +02:00
qint64 m_value;
QString m_typedNumber;
2021-11-03 18:29:31 +01:00
int m_cursorPos = 0;
int m_maxFractionalDigits = -1;
2020-06-12 20:53:01 +02:00
};
#endif