File indexing completed on 2024-05-19 04:26:56

0001 /*
0002  * SPDX-FileCopyrightText: 2016 Laurent Valentin Jospin <laurent.valentin@famillejospin.ch>
0003  * SPDX-FileCopyrightText: 2021 Deif Lou <ginoba@gmail.com>
0004  *
0005  * SPDX-License-Identifier: GPL-2.0-or-later
0006  */
0007 #ifndef LIBKIS_INTPARSESPINBOX_H
0008 #define LIBKIS_INTPARSESPINBOX_H
0009 
0010 #include "kis_int_parse_spin_box.h"
0011 
0012 #include "kritalibkis_export.h"
0013 #include "libkis.h"
0014 
0015 /**
0016  * @brief A wrapper around KisIntParseSpinBox, which is a cleverer SpinBox,
0017  * able to parse arithmetic expressions. The widget itself is accessed with
0018  * the widget() function.
0019  *
0020  * Use this spinbox instead of the basic one from Qt if you want it to be able
0021  * to parse arithmetic expressions.
0022  */
0023 class KRITALIBKIS_EXPORT IntParseSpinBox : public QObject
0024 {
0025     Q_OBJECT
0026     Q_DISABLE_COPY(IntParseSpinBox)
0027 
0028 public:
0029     explicit IntParseSpinBox();
0030     ~IntParseSpinBox() override;
0031 
0032 public Q_SLOTS:
0033 
0034     /**
0035      * @brief Get the internal KisIntParseSpinBox as a QWidget, so it may be
0036      * added to a UI
0037      * 
0038      * @return the internal KisIntParseSpinBox as a QWidget
0039      */
0040     QSpinBox* widget() const;
0041 
0042     /**
0043      * @brief This is a reimplementation of @ref QSpinBox::stepBy that
0044      * uses @ref setValue
0045      * @param steps Number of steps that the value should change
0046      */
0047     void stepBy(int steps);
0048     /**
0049      * @brief Set the value of the spinbox
0050      * 
0051      * This reimplementation also tries to clear the current expression and
0052      * warning message whenever possible. This will happen when the new value
0053      * is different from the current one and the line edit has not the focus
0054      * or it is read-only. One can force the reset also by passing true to the
0055      * @p overwriteExpression parameter.
0056      * 
0057      * @param value The new value
0058      * @param overwriteExpression Get if the expression in the edit field
0059      * (and the warning message) should be reset to reflect the new value.
0060      * The default is false so that if the user is editing the expression
0061      * it won't be disrupted by any default call to this function
0062      */
0063     void setValue(int value, bool overwriteExpression = false);
0064     /**
0065      * @brief Get if the last expression entered is a valid one
0066      * @retval true if the last expression entered is valid
0067      * @retval false otherwise
0068      */
0069     bool isLastValid() const;
0070     /**
0071      * @brief This virtual function is similar to cleanText(). But child classes
0072      * may reimplement it to further process ("clean up") the expression.
0073      * @return The processed expression
0074      */
0075     virtual QString veryCleanText() const;
0076 
0077 Q_SIGNALS:
0078     /**
0079      * @brief signal emitted when the last parsed expression is not valid.
0080      */
0081     void errorWhileParsing(const QString &expr) const;
0082     /**
0083      * @brief signal emitted when the last parsed expression is valid and
0084      * the expression before was not valid.
0085      */
0086     void noMoreParsingError() const;
0087 
0088 private:
0089     struct Private;
0090     Private *const d;
0091 
0092 };
0093 
0094 #endif // LIBKIS_INTPARSESPINBOX_H