1 /*
2  *  Copyright (c) 2017 Laurent Valentin Jospin <laurent.valentin@famillejospin.ch>
3  *
4  *  This program is free software; you can redistribute it and/or modify
5  *  it under the terms of the GNU General Public License as published by
6  *  the Free Software Foundation; either version 2 of the License, or
7  *  (at your option) any later version.
8  *
9  *  This program is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *  GNU General Public License for more details.
13  *
14  *  You should have received a copy of the GNU General Public License
15  *  along with this program; if not, write to the Free Software
16  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  */
18 
19 #ifndef KISDOCUMENTAWARESPINBOXUNITMANAGER_H
20 #define KISDOCUMENTAWARESPINBOXUNITMANAGER_H
21 
22 #include "kis_spin_box_unit_manager.h"
23 #include "kis_double_parse_unit_spin_box.h"
24 
25 #include "kritaui_export.h"
26 class KisDocumentAwareSpinBoxUnitManagerBuilder : public KisSpinBoxUnitManagerBuilder
27 {
28 
29 public:
30 
31     KisSpinBoxUnitManager* buildUnitManager(QObject* parent) override;
32 };
33 
34 /*!
35  * \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).
36  * \see KisSpinBoxUnitManager
37  */
38 class KRITAUI_EXPORT KisDocumentAwareSpinBoxUnitManager : public KisSpinBoxUnitManager
39 {
40     Q_OBJECT
41 
42 public:
43 
44     enum PixDir {
45         PIX_DIR_X,
46         PIX_DIR_Y
47     }; //in case the image has not the same x and y resolution, indicate on which direction get the resolution.
48 
49     //! \brief configure a KisDocumentAwareSpinBoxUnitManager for the given spinbox (make the manager a child of the spinbox and attach it to the spinbox).
50     static void setDocumentAwarnessToExistingUnitSpinBox(KisDoubleParseUnitSpinBox* spinBox, bool setUnitFromOutsideToggle = false);
51 
52     //! \brief create a unitSpinBox that is already document aware.
53     static KisDoubleParseUnitSpinBox* createUnitSpinBoxWithDocumentAwarness(QWidget* parent = 0);
54 
55     KisDocumentAwareSpinBoxUnitManager(QObject *parent = 0, int pPixDir = PIX_DIR_X);
56 
57     //! \see KisSpinBoxUnitManager
58     qreal getConversionFactor(int dim, QString psymbol) const override;
59     //! \see KisSpinBoxUnitManager
60     qreal getConversionConstant(int dim, QString symbol) const override;
61 
62 protected:
63 
64     //! \see KisSpinBoxUnitManager
65     virtual bool hasPercent(int unitDim) const override;
66 
67     PixDir pixDir;
68 };
69 
70 #endif // KISDOCUMENTAWARESPINBOXUNITMANAGER_H
71