Krita Source Code Documentation
Loading...
Searching...
No Matches
dlg_grow_selection.cc
Go to the documentation of this file.
1/*
2 * dlg_grow_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
10#include "dlg_grow_selection.h"
11
12#include <KoUnit.h>
13#include <kis_size_group.h>
14#include <KisViewManager.h>
15#include <kis_image.h>
17
18
20 : KisOperationUIWidget(i18n("Grow Selection"), parent)
21 , m_growValue(config->getInt("x-radius", 1))
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 spbGrowValue->setValue(m_growValue);
31 spbGrowValue->setFocus();
32 spbGrowValue->setVisible(true);
33 spbGrowValueDouble->setVisible(false);
34
35 cmbUnit->addItems(KoUnit::listOfUnitNameForUi());
36 cmbUnit->setCurrentIndex(KoUnit(KoUnit::Pixel).indexInListForUi());
37
38 // ensure that both spinboxes request the same horizontal size
39 KisSizeGroup *spbGroup = new KisSizeGroup(this);
40 spbGroup->addWidget(spbGrowValue);
41 spbGroup->addWidget(spbGrowValueDouble);
42
43 connect(spbGrowValue, SIGNAL(valueChanged(int)), this, SLOT(slotGrowValueChanged(int)));
44 connect(spbGrowValueDouble, SIGNAL(valueChanged(double)), this, SLOT(slotGrowValueChanged(double)));
45 connect(cmbUnit, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUnitChanged(int)));
46}
47
52
54{
55 const KoUnit selectedUnit = KoUnit::fromListForUi(cmbUnit->currentIndex());
56 const double resValue = (selectedUnit == KoUnit(KoUnit::Pixel)) ? value : (value * m_resolution);
57 m_growValue = qRound(selectedUnit.fromUserValue(resValue));
58}
59
61{
63
64 const KoUnit selectedUnit = KoUnit::fromListForUi(index);
65 if (selectedUnit != KoUnit(KoUnit::Pixel)) {
66 spbGrowValue->setVisible(false);
67 spbGrowValueDouble->setVisible(true);
68 } else {
69 spbGrowValue->setVisible(true);
70 spbGrowValueDouble->setVisible(false);
71 }
72}
73
75{
76 const KoUnit selectedUnit = KoUnit::fromListForUi(cmbUnit->currentIndex());
77 if (selectedUnit != KoUnit(KoUnit::Pixel)) {
78 spbGrowValueDouble->blockSignals(true);
79 spbGrowValueDouble->setValue(selectedUnit.toUserValue(value / m_resolution));
80 spbGrowValueDouble->blockSignals(false);
81 } else {
82 const int finalValue = (selectedUnit == KoUnit(KoUnit::Point)) ? qRound(value / m_resolution) : value;
83 spbGrowValue->blockSignals(true);
84 spbGrowValue->setValue(selectedUnit.toUserValue(finalValue));
85 spbGrowValue->blockSignals(false);
86 }
87}
88
90{
91 config->setProperty("x-radius", m_growValue);
92 config->setProperty("y-radius", m_growValue);
93}
94
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 updateGrowUIValue(double value)
void slotGrowValueChanged(int value)
WdgGrowSelection(QWidget *parent, KisViewManager *view, KisOperationConfigurationSP config)
void slotUnitChanged(int index)
void getConfiguration(KisOperationConfigurationSP config) override