Files
qad/libs/widgets/evalspinbox.h
Andrey 728c132f2b refactoring qad widgets part 1
c++ cast, nullptr, forward declaration, agregate ui, connect to member functions, order and clear includes
2022-12-11 16:27:04 +03:00

107 lines
3.1 KiB
C++

/*
QAD - Qt ADvanced
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef EVALSPINBOX_H
#define EVALSPINBOX_H
#include "qad_widgets_export.h"
#include <QAbstractSpinBox>
class QPIEvaluator;
class QLabel;
class QAD_WIDGETS_EXPORT EvalSpinBox: public QAbstractSpinBox
{
Q_OBJECT
Q_PROPERTY(double value READ value WRITE setValue NOTIFY valueChanged USER true)
Q_PROPERTY(QString expression READ expression WRITE setExpression USER true)
Q_PROPERTY(QString defaultText READ defaultText WRITE setDefaultText)
Q_PROPERTY(bool clearButtonVisible READ isClearButtonVisible WRITE setClearButtonVisible)
Q_PROPERTY(bool calculationVisible READ isCalculationVisible WRITE setCalculationVisible)
Q_PROPERTY(int precision READ precision WRITE setPrecision)
public:
explicit EvalSpinBox(QWidget * parent = nullptr);
~EvalSpinBox() override;
double value() const;
const QString & expression() const;
const QString & defaultText() const {return dt;}
bool isClearButtonVisible() const {return cw_visible;}
bool isCalculationVisible() const {return calc_visible;}
bool isCleared() const;
int precision() const {return precision_;}
void stepBy(int steps) override;
void clear() override;
QSize sizeHint() const override;
public slots:
void setExpression(const QString & expr);
void setValue(double val);
void setDefaultText(const QString & t);
void setClearButtonVisible(bool visible);
void setCalculationVisible(bool visible);
void setPrecision(int precision) {precision_ = precision;}
protected:
QString text() const {return QAbstractSpinBox::text();}
StepEnabled stepEnabled() const override;
void focusInEvent(QFocusEvent *event) override;
void focusOutEvent(QFocusEvent *event) override;
void wheelEvent(QWheelEvent *event) override;
void stepByDouble(double steps);
private slots:
void clearMouseRelease(QMouseEvent * e);
void textChanged_(const QString & text);
void setExpressionSlot();
void resizeIcons();
signals:
void valueChanged(double val);
void cleared();
private:
bool eventFilter(QObject * o, QEvent * e) override;
void resizeEvent(QResizeEvent * ) override;
void changeEvent(QEvent * e) override;
void statusPaintEvent();
void cwPaintEvent();
QWidget * status;
QWidget * cw;
QPIEvaluator * eval;
QLabel * label;
QImage icon_ok;
QImage icon_fail;
QImage icon_calc;
QImage icon;
QImage clear_im;
QString dt;
bool cw_visible, calc_visible;
int precision_;
};
#endif // EVALSPINBOX_H