Krita Source Code Documentation
Loading...
Searching...
No Matches
dlg_shrink_selection.cc
Go to the documentation of this file.
1/*
2 * dlg_shrink_selection.cc - part of Krita
3 *
4 * SPDX-FileCopyrightText: 2006 Michael Thaler <michael.thaler@physik.tu-muenchen.de>
5 * SPDX-FileCopyrightText: 2013 Juan Palacios <jpalaciosdev@gmail.com>
6 *
7 * SPDX-License-Identifier: GPL-2.0-or-later
8 */
9
11
12#include <KoUnit.h>
13#include <kis_size_group.h>
14#include <KisViewManager.h>
15#include <kis_image.h>
17
19 : KisOperationUIWidget(i18n("Shrink Selection"), parent)
20 , m_shrinkValue(config->getInt("x-radius", 1))
21 , m_shrinkFromImageBorder(!config->getBool("edgeLock", false))
22{
23 Q_ASSERT(view);
24 KisImageWSP image = view->image();
25 Q_ASSERT(image);
26 m_resolution = image->yRes();
27
28 setupUi(this);
29
30 spbShrinkValue->setValue(m_shrinkValue);
31 spbShrinkValue->setFocus();
32 spbShrinkValue->setVisible(true);
33 spbShrinkValueDouble->setVisible(false);
34
35 cmbUnit->addItems(KoUnit::listOfUnitNameForUi());
36 cmbUnit->setCurrentIndex(KoUnit(KoUnit::Pixel).indexInListForUi());
37 ckbShrinkFromImageBorder->setChecked(m_shrinkFromImageBorder);
38
39 // ensure that both spinboxes request the same horizontal size
40 KisSizeGroup *spbGroup = new KisSizeGroup(this);
41 spbGroup->addWidget(spbShrinkValue);
42 spbGroup->addWidget(spbShrinkValueDouble);
43
44 connect(spbShrinkValue, SIGNAL(valueChanged(int)), this, SLOT(slotShrinkValueChanged(int)));
45 connect(spbShrinkValueDouble, SIGNAL(valueChanged(double)), this, SLOT(slotShrinkValueChanged(double)));
46 connect(cmbUnit, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUnitChanged(int)));
47 connect(ckbShrinkFromImageBorder, SIGNAL(toggled(bool)), this, SLOT(slotShrinkFromImageBorderChanged(bool)));
48}
49
54
56{
57 const KoUnit selectedUnit = KoUnit::fromListForUi(cmbUnit->currentIndex());
58 const double resValue = (selectedUnit == KoUnit(KoUnit::Pixel)) ? value : (value * m_resolution);
59 m_shrinkValue = qRound(selectedUnit.fromUserValue(resValue));
60}
61
63{
65
66 const KoUnit selectedUnit = KoUnit::fromListForUi(index);
67 if (selectedUnit != KoUnit(KoUnit::Pixel)) {
68 spbShrinkValue->setVisible(false);
69 spbShrinkValueDouble->setVisible(true);
70 } else {
71 spbShrinkValue->setVisible(true);
72 spbShrinkValueDouble->setVisible(false);
73 }
74}
75
77{
78 const KoUnit selectedUnit = KoUnit::fromListForUi(cmbUnit->currentIndex());
79 if (selectedUnit != KoUnit(KoUnit::Pixel)) {
80 spbShrinkValueDouble->blockSignals(true);
81 spbShrinkValueDouble->setValue(selectedUnit.toUserValue(value / m_resolution));
82 spbShrinkValueDouble->blockSignals(false);
83 } else {
84 const int finalValue = (selectedUnit == KoUnit(KoUnit::Point)) ? qRound(value / m_resolution) : value;
85 spbShrinkValue->blockSignals(true);
86 spbShrinkValue->setValue(selectedUnit.toUserValue(finalValue));
87 spbShrinkValue->blockSignals(false);
88 }
89}
94
96{
97 config->setProperty("x-radius", m_shrinkValue);
98 config->setProperty("y-radius", m_shrinkValue);
99 config->setProperty("edgeLock", !m_shrinkFromImageBorder);
100}
101
float value(const T *src, size_t ch)
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
double yRes() const
void addWidget(QWidget *widget)
KisImageWSP image() const
Return the image this view is displaying.
qreal fromUserValue(qreal value) const
Definition KoUnit.cpp:201
static KoUnit fromListForUi(int index, ListOptions listOptions=ListAll, qreal factor=1.0)
Definition KoUnit.cpp:80
@ Point
Postscript point, 1/72th of an Inco.
Definition KoUnit.h:76
@ Pixel
Definition KoUnit.h:82
static QStringList listOfUnitNameForUi(ListOptions listOptions=ListAll)
Returns the list of unit types for the UI, controlled with the given listOptions.
Definition KoUnit.cpp:69
qreal toUserValue(qreal ptValue, bool rounding=true) const
Definition KoUnit.cpp:186
void slotUnitChanged(int index)
void slotShrinkFromImageBorderChanged(bool value)
void getConfiguration(KisOperationConfigurationSP config) override
void updateShrinkUIValue(double value)
WdgShrinkSelection(QWidget *parent, KisViewManager *view, KisOperationConfigurationSP config)
void slotShrinkValueChanged(int value)