File indexing completed on 2024-05-12 17:21:07
0001 /* 0002 * SPDX-FileCopyrightText: 2020-2021 Han Young <hanyoung@protonmail.com> 0003 * SPDX-FileCopyrightText: 2021-2022 Rohan Asokan <rohan.asokan@Students.iiit.ac.in> 0004 * 0005 * SPDX-License-Identifier: GPL-3.0-or-later 0006 */ 0007 0008 #pragma once 0009 0010 #include <QObject> 0011 0012 class InputManager : public QObject 0013 { 0014 Q_OBJECT 0015 Q_PROPERTY(QString expression READ expression WRITE setExpression NOTIFY expressionChanged) 0016 Q_PROPERTY(QString result READ result NOTIFY resultChanged) 0017 Q_PROPERTY(QString binaryResult READ binaryResult NOTIFY binaryResultChanged) 0018 Q_PROPERTY(QString hexResult READ hexResult NOTIFY hexResultChanged) 0019 Q_PROPERTY(bool moveFromResult READ moveFromResult NOTIFY resultChanged) 0020 Q_PROPERTY(int cursorPosition READ getCursorPosition WRITE setCursorPosition NOTIFY cursorPositionChanged) 0021 Q_PROPERTY(bool binaryMode READ binaryMode WRITE setBinaryMode) 0022 0023 public: 0024 static InputManager *inst(); 0025 const QString &expression() const; 0026 void setExpression(const QString &expression); 0027 const QString &result() const; 0028 const QString &binaryResult() const; 0029 const QString &hexResult() const; 0030 bool moveFromResult() const; 0031 int getCursorPosition() const; 0032 void setCursorPosition(int position); 0033 Q_INVOKABLE int idealCursorPosition(int position) const; 0034 Q_INVOKABLE void append(const QString &subexpression); 0035 Q_INVOKABLE void backspace(); 0036 Q_INVOKABLE void equal(); 0037 Q_INVOKABLE void clear(); 0038 Q_INVOKABLE void fromHistory(const QString &result); 0039 void setBinaryMode(bool active); 0040 bool binaryMode(); 0041 QString formatNumbers(const QString &text); 0042 void addNumberSeparators(QString &number); 0043 0044 Q_SIGNALS: 0045 void expressionChanged(); 0046 void resultChanged(); 0047 void binaryResultChanged(); 0048 void hexResultChanged(); 0049 void cursorPositionChanged(); 0050 0051 private: 0052 InputManager(); 0053 bool m_moveFromResult = false; // clear expression on none operator input 0054 int m_inputPosition; 0055 QString m_input; 0056 QString m_output; 0057 QString m_expression; 0058 QString m_result; 0059 QString m_binaryResult; 0060 QString m_hexResult; 0061 bool m_isBinaryMode = false; // Changes the parser based on this variable 0062 QString m_groupSeparator; 0063 QString m_decimalPoint; 0064 };