Krita Source Code Documentation
Loading...
Searching...
No Matches
dlg_border_selection.cc
Go to the documentation of this file.
1/*
2 * dlg_border_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
18
20 : KisOperationUIWidget(i18n("Border Selection"), parent)
21 , m_width(config->getInt("x-radius", 1))
22 , m_antialiasing(config->getBool("antialiasing", false))
23{
24 Q_ASSERT(view);
25 KisImageWSP image = view->image();
26 Q_ASSERT(image);
27 m_resolution = image->yRes();
28
29 setupUi(this);
30
31 spbWidth->setValue(m_width);
32 spbWidth->setFocus();
33 spbWidth->setVisible(true);
34 spbWidthDouble->setVisible(false);
35
36 cmbUnit->addItems(KoUnit::listOfUnitNameForUi());
37 cmbUnit->setCurrentIndex(KoUnit(KoUnit::Pixel).indexInListForUi());
38
39 // ensure that both spinboxes request the same horizontal size
40 KisSizeGroup *spbGroup = new KisSizeGroup(this);
41 spbGroup->addWidget(spbWidth);
42 spbGroup->addWidget(spbWidthDouble);
43
44 connect(spbWidth, SIGNAL(valueChanged(int)), this, SLOT(slotWidthChanged(int)));
45 connect(spbWidthDouble, SIGNAL(valueChanged(double)), this, SLOT(slotWidthChanged(double)));
46 connect(cmbUnit, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUnitChanged(int)));
47 connect(chkAntialiasing, SIGNAL(toggled(bool)), this, SLOT(slotAntialiasingChanged(bool)));
49}
50
52{
53 slotWidthChanged((double) width);
54}
55
57{
58 const KoUnit selectedUnit = KoUnit::fromListForUi(cmbUnit->currentIndex());
59 const double resWidth = (selectedUnit == KoUnit(KoUnit::Pixel)) ? width : (width * m_resolution);
60 m_width = qRound(selectedUnit.fromUserValue(resWidth));
62}
63
65{
67
68 const KoUnit selectedUnit = KoUnit::fromListForUi(index);
69 if (selectedUnit != KoUnit(KoUnit::Pixel)) {
70 spbWidth->setVisible(false);
71 spbWidthDouble->setVisible(true);
72 } else {
73 spbWidth->setVisible(true);
74 spbWidthDouble->setVisible(false);
75 }
76}
77
82
84{
85 const bool antialiasingEnabled = m_width > 1;
86
87 if (antialiasingEnabled) {
88 chkAntialiasing->setChecked(m_antialiasing);
89 } else {
90 bool tmp_antialiasing = m_antialiasing;
91 chkAntialiasing->setChecked(false);
92 m_antialiasing = tmp_antialiasing;
93 }
94
95 chkAntialiasing->setEnabled(antialiasingEnabled);
96}
97
99{
100 const KoUnit selectedUnit = KoUnit::fromListForUi(cmbUnit->currentIndex());
101 if (selectedUnit != KoUnit(KoUnit::Pixel)) {
102 spbWidthDouble->blockSignals(true);
103 spbWidthDouble->setValue(selectedUnit.toUserValue(value / m_resolution));
104 spbWidthDouble->blockSignals(false);
105 } else {
106 const int finalValue = (selectedUnit == KoUnit(KoUnit::Point)) ? qRound(value / m_resolution) : value;
107 spbWidth->blockSignals(true);
108 spbWidth->setValue(selectedUnit.toUserValue(finalValue));
109 spbWidth->blockSignals(false);
110 }
111}
112
114{
115 config->setProperty("x-radius", m_width);
116 config->setProperty("y-radius", m_width);
117 config->setProperty("antialiasing", m_antialiasing);
118}
119
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 updateWidthUIValue(double value)
void slotWidthChanged(int width)
void slotAntialiasingChanged(bool value)
void slotUnitChanged(int index)
void getConfiguration(KisOperationConfigurationSP config) override
WdgBorderSelection(QWidget *parent, KisViewManager *view, KisOperationConfigurationSP config)