File indexing completed on 2024-06-09 04:24:27

0001 /*
0002  *
0003  *  SPDX-FileCopyrightText: 2009 Edward Apap <schumifer@hotmail.com>
0004  *  SPDX-FileCopyrightText: 2013 Juan Palacios <jpalaciosdev@gmail.com>
0005  *
0006  *  SPDX-License-Identifier: GPL-2.0-or-later
0007  */
0008 
0009 #ifndef DLG_CANVASSIZE
0010 #define DLG_CANVASSIZE
0011 
0012 #include <KoDialog.h>
0013 #include <QIcon>
0014 
0015 
0016 #include "ui_wdg_canvassize.h"
0017 
0018 class KisDocumentAwareSpinBoxUnitManager;
0019 
0020 class WdgCanvasSize : public QWidget, public Ui::WdgCanvasSize
0021 {
0022     Q_OBJECT
0023 
0024 public:
0025     WdgCanvasSize(QWidget *parent) : QWidget(parent) {
0026         setupUi(this);
0027     }
0028 };
0029 
0030 
0031 
0032 class DlgCanvasSize: public KoDialog
0033 {
0034 
0035     Q_OBJECT
0036 
0037 public:
0038     enum anchor { NORTH_WEST = 0, NORTH, NORTH_EAST, WEST, CENTER, EAST, SOUTH_WEST, SOUTH, SOUTH_EAST, NONE};
0039 
0040     static const QString PARAM_PREFIX;
0041     static const QString PARAM_WIDTH_UNIT;
0042     static const QString PARAM_HEIGHT_UNIT;
0043     static const QString PARAM_XOFFSET_UNIT;
0044     static const QString PARAM_YOFFSET_UNIT;
0045 
0046     DlgCanvasSize(QWidget * parent, int width, int height, double resolution);
0047     ~DlgCanvasSize() override;
0048 
0049     qint32 width();
0050     qint32 height();
0051     qint32 xOffset();
0052     qint32 yOffset();
0053     WdgCanvasSize * m_page;
0054 
0055 private Q_SLOTS:
0056     void slotAspectChanged(bool keep);
0057     void slotAnchorButtonClicked(int id);
0058 
0059     void slotWidthChanged(double v);
0060     void slotHeightChanged(double v);
0061 
0062     void slotXOffsetChanged(double v);
0063     void slotYOffsetChanged(double v);
0064 
0065     void slotCanvasPreviewXOffsetChanged(int v);
0066     void slotCanvasPreviewYOffsetChanged(int v);
0067 
0068     void updatexOffsetIcon(bool v);
0069     void updateyOffsetIcon(bool v);
0070 
0071 private:
0072 
0073     void loadAnchorIcons();
0074     void updateAnchorIcons(int id);
0075     void updateButtons(int forceId);
0076     void updateOffset(int id);
0077     void expectedOffset(int id, double &xOffset, double &yOffset);
0078 
0079     bool m_keepAspect;
0080     const double m_aspectRatio;
0081     const double m_resolution;
0082     const int m_originalWidth, m_originalHeight;
0083     int m_newWidth, m_newHeight;
0084     int m_xOffset, m_yOffset;
0085 
0086     QIcon m_anchorIcons[9];
0087     QButtonGroup *m_group;
0088 
0089     KisDocumentAwareSpinBoxUnitManager* _widthUnitManager;
0090     KisDocumentAwareSpinBoxUnitManager* _heightUnitManager;
0091 
0092     KisDocumentAwareSpinBoxUnitManager* _xOffsetUnitManager;
0093     KisDocumentAwareSpinBoxUnitManager* _yOffsetUnitManager;
0094 };
0095 
0096 
0097 #endif // DLG_CANVASSIZE