File indexing completed on 2024-05-26 04:30:39

0001 /*
0002  *  SPDX-FileCopyrightText: 2017 Laurent Valentin Jospin <laurent.valentin@famillejospin.ch>
0003  *
0004  *  SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 
0007 #ifndef KISDOCUMENTAWARESPINBOXUNITMANAGER_H
0008 #define KISDOCUMENTAWARESPINBOXUNITMANAGER_H
0009 
0010 #include "kis_spin_box_unit_manager.h"
0011 #include "kis_double_parse_unit_spin_box.h"
0012 
0013 #include "kritaui_export.h"
0014 class KisDocumentAwareSpinBoxUnitManagerBuilder : public KisSpinBoxUnitManagerBuilder
0015 {
0016 
0017 public:
0018 
0019     KisSpinBoxUnitManager* buildUnitManager(QObject* parent) override;
0020 };
0021 
0022 /*!
0023  * \brief The KisDocumentAwareSpinBoxUnitManager class is a KisSpinBoxUnitManager that is able to connect to the current document to compute transformation for document relative units (the ones that depend of the resolution, or the size in pixels of the image).
0024  * \see KisSpinBoxUnitManager
0025  */
0026 class KRITAUI_EXPORT KisDocumentAwareSpinBoxUnitManager : public KisSpinBoxUnitManager
0027 {
0028     Q_OBJECT
0029 
0030 public:
0031 
0032     enum PixDir {
0033         PIX_DIR_X,
0034         PIX_DIR_Y
0035     }; //in case the image has not the same x and y resolution, indicate on which direction get the resolution.
0036 
0037     //! \brief configure a KisDocumentAwareSpinBoxUnitManager for the given spinbox (make the manager a child of the spinbox and attach it to the spinbox).
0038     static void setDocumentAwarenessToExistingUnitSpinBox(KisDoubleParseUnitSpinBox* spinBox, bool setUnitFromOutsideToggle = false);
0039 
0040     //! \brief create a unitSpinBox that is already document aware.
0041     static KisDoubleParseUnitSpinBox* createUnitSpinBoxWithDocumentAwareness(QWidget* parent = 0);
0042 
0043     KisDocumentAwareSpinBoxUnitManager(QObject *parent = 0, int pPixDir = PIX_DIR_X);
0044 
0045     //! \see KisSpinBoxUnitManager
0046     qreal getConversionFactor(int dim, QString psymbol) const override;
0047     //! \see KisSpinBoxUnitManager
0048     qreal getConversionConstant(int dim, QString symbol) const override;
0049 
0050 protected:
0051 
0052     //! \see KisSpinBoxUnitManager
0053     virtual bool hasPercent(int unitDim) const override;
0054 
0055     PixDir pixDir;
0056 };
0057 
0058 #endif // KISDOCUMENTAWARESPINBOXUNITMANAGER_H