Krita Source Code Documentation
Loading...
Searching...
No Matches
dlg_offsetimage.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2013 Lukáš Tvrdý <lukast.dev@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
7#include "dlg_offsetimage.h"
8
9#include <klocalizedstring.h>
10#include <kis_debug.h>
11#include <kis_config.h>
12
14
15const QString DlgOffsetImage::PARAM_PREFIX = "imageoffsetdlg";
18
19DlgOffsetImage::DlgOffsetImage(QWidget * parent, const char * name, QSize imageSize)
20 : KoDialog(parent),
21 m_offsetSize(imageSize)
22{
23 setCaption("BUG: No sane caption is set");
26 setObjectName(name);
27
28
29 m_lock = false;
30
31 m_page = new WdgOffsetImage(this);
32 Q_CHECK_PTR(m_page);
33 m_page->setObjectName("offset_image");
34
36 resize(m_page->sizeHint());
37
40
43
44 m_page->offsetXdoubleSpinBox->setUnitManager(_widthUnitManager);
45 m_page->offsetYdoubleSpinBox->setUnitManager(_heightUnitManager);
46 m_page->offsetXdoubleSpinBox->setDisplayUnit(false);
47 m_page->offsetYdoubleSpinBox->setDisplayUnit(false);
48
49 m_page->offsetXdoubleSpinBox->setReturnUnit("px");
50 m_page->offsetYdoubleSpinBox->setReturnUnit("px");
51
52 m_page->unitXComboBox->setModel(_widthUnitManager);
53 m_page->unitYComboBox->setModel(_heightUnitManager);
54
55 KisConfig cfg(true);
56
57 QString unitx = cfg.readEntry<QString>(PARAM_XOFFSET_UNIT, "px");
58 QString unity = cfg.readEntry<QString>(PARAM_YOFFSET_UNIT, "px");
59
62
63 const int xUnitIndex = _widthUnitManager->getsUnitSymbolList().indexOf(unitx);
64 const int yUnitIndex = _heightUnitManager->getsUnitSymbolList().indexOf(unity);
65
66 m_page->unitXComboBox->setCurrentIndex(xUnitIndex);
67 m_page->unitYComboBox->setCurrentIndex(yUnitIndex);
68
69 connect(this, SIGNAL(okClicked()),this, SLOT(okClicked()));
70 connect(m_page->middleOffsetBtn, SIGNAL(clicked()), this, SLOT(slotMiddleOffset()));
71 connect(m_page->offsetXdoubleSpinBox, SIGNAL(valueChangedPt(double)), this, SLOT(slotOffsetXChanged(double)));
72 connect(m_page->offsetYdoubleSpinBox, SIGNAL(valueChangedPt(double)), this, SLOT(slotOffsetYChanged(double)));
73
74 connect(m_page->unitXComboBox, SIGNAL(currentIndexChanged(int)), _widthUnitManager, SLOT(selectApparentUnitFromIndex(int)));
75 connect(m_page->unitYComboBox, SIGNAL(currentIndexChanged(int)), _heightUnitManager, SLOT(selectApparentUnitFromIndex(int)));
76 connect(_widthUnitManager, SIGNAL(unitChanged(int)), m_page->unitXComboBox, SLOT(setCurrentIndex(int)));
77 connect(_heightUnitManager, SIGNAL(unitChanged(int)), m_page->unitYComboBox, SLOT(setCurrentIndex(int)));
78
80}
81
91
93{
94 m_offsetX = qRound(newOffsetX);
95}
96
98{
99 m_offsetY = qRound(newOffsetY);
100}
101
103{
104 int offsetX = m_offsetSize.width() / 2;
105 int offsetY = m_offsetSize.height() / 2;
106 m_page->offsetXdoubleSpinBox->changeValue(offsetX);
107 m_page->offsetYdoubleSpinBox->changeValue(offsetY);
108}
109
111{
112 accept();
113}
114
115
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
KisDocumentAwareSpinBoxUnitManager * _widthUnitManager
void slotOffsetYChanged(double)
static const QString PARAM_YOFFSET_UNIT
static const QString PARAM_XOFFSET_UNIT
int offsetX() const
static const QString PARAM_PREFIX
int offsetY() const
WdgOffsetImage * m_page
KisDocumentAwareSpinBoxUnitManager * _heightUnitManager
void slotOffsetXChanged(double)
~DlgOffsetImage() override
DlgOffsetImage(QWidget *parent=0, const char *name=0, QSize imageSize=QSize())
void writeEntry(const QString &name, const T &value)
Definition kis_config.h:779
T readEntry(const QString &name, const T &defaultValue=T())
Definition kis_config.h:789
The KisDocumentAwareSpinBoxUnitManager class is a KisSpinBoxUnitManager that is able to connect to th...
void setApparentUnitFromSymbol(QString pSymbol)
virtual QStringList getsUnitSymbolList(bool withName=false) const
A dialog base class with standard buttons and predefined layouts.
Definition KoDialog.h:116
void setMainWidget(QWidget *widget)
Definition KoDialog.cpp:354
virtual void setCaption(const QString &caption)
Definition KoDialog.cpp:498
void setButtons(ButtonCodes buttonMask)
Definition KoDialog.cpp:195
void setDefaultButton(ButtonCode id)
Definition KoDialog.cpp:302
@ Ok
Show Ok button. (this button accept()s the dialog; result set to QDialog::Accepted)
Definition KoDialog.h:127
@ Cancel
Show Cancel-button. (this button reject()s the dialog; result set to QDialog::Rejected)
Definition KoDialog.h:130