Krita Source Code Documentation
Loading...
Searching...
No Matches
kis_rectangle_constraint_widget.cpp
Go to the documentation of this file.
1/*
2 * SPDX-License-Identifier: GPL-2.0-or-later
3 */
4
7
8#include <kis_icon.h>
10#include "kis_signals_blocker.h"
11#include <KConfigGroup>
12#include <KSharedConfig>
13
15 : QWidget(parent)
16{
17 m_tool = tool;
18
19 setupUi(this);
20
21 connect(lockWidthButton, SIGNAL(toggled(bool)), this, SLOT(inputsChanged()));
22 connect(lockHeightButton, SIGNAL(toggled(bool)), this, SLOT(inputsChanged()));
23 connect(lockRatioButton, SIGNAL(toggled(bool)), this, SLOT(inputsChanged()));
24
25 QIcon lockedIcon = KisIconUtils::loadIcon("locked");
26 QIcon unlockedIcon = KisIconUtils::loadIcon("unlocked");
27 lockWidthButton->setIcon(lockWidthButton->isChecked() ? lockedIcon : unlockedIcon);
28 lockHeightButton->setIcon(lockHeightButton->isChecked() ? lockedIcon : unlockedIcon);
29 lockRatioButton->setIcon(lockRatioButton->isChecked() ? lockedIcon : unlockedIcon);
30
31 connect(intWidth, SIGNAL(valueChanged(int)), this, SLOT(inputWidthChanged()));
32 connect(intHeight, SIGNAL(valueChanged(int)), this, SLOT(inputHeightChanged()));
33 connect(doubleRatio, SIGNAL(valueChanged(double)), this, SLOT(inputRatioChanged()));
34
35 connect(this, SIGNAL(constraintsChanged(bool,bool,bool,float,float,float)), m_tool, SLOT(constraintsChanged(bool,bool,bool,float,float,float)));
36 connect(m_tool, SIGNAL(rectangleChanged(QRectF)), this, SLOT(rectangleChanged(QRectF)));
37
39 m_cornersAspectLocker->connectSpinBoxes(intRoundCornersX, intRoundCornersY, cornersAspectButton);
40
41 connect(m_cornersAspectLocker, SIGNAL(sliderValueChanged()), SLOT(slotRoundCornersChanged()));
42 connect(m_cornersAspectLocker, SIGNAL(aspectButtonChanged()), SLOT(slotRoundCornersAspectLockChanged()));
43
44 connect(m_tool, SIGNAL(sigRequestReloadConfig()), SLOT(slotReloadConfig()));
46
47 if (!showRoundCornersGUI) {
48 intRoundCornersX->setVisible(false);
49 intRoundCornersY->setVisible(false);
50 cornersAspectButton->setVisible(false);
51 }
52}
53
55{
56 lockWidthButton->setChecked(true);
58}
59
61{
62 lockHeightButton->setChecked(true);
64}
65
67{
68 lockRatioButton->setChecked(true);
70}
71
73{
74 Q_EMIT constraintsChanged(
75 lockRatioButton->isChecked(),
76 lockWidthButton->isChecked(),
77 lockHeightButton->isChecked(),
78 doubleRatio->value(),
79 intWidth->value(),
80 intHeight->value()
81 );
82 QIcon lockedIcon = KisIconUtils::loadIcon("locked");
83 QIcon unlockedIcon = KisIconUtils::loadIcon("unlocked");
84 lockWidthButton->setIcon(lockWidthButton->isChecked() ? lockedIcon : unlockedIcon);
85 lockHeightButton->setIcon(lockHeightButton->isChecked() ? lockedIcon : unlockedIcon);
86 lockRatioButton->setIcon(lockRatioButton->isChecked() ? lockedIcon : unlockedIcon);
87}
88
90{
91 m_tool->roundCornersChanged(intRoundCornersX->value(), intRoundCornersY->value());
92
93 KConfigGroup cfg = KSharedConfig::openConfig()->group(m_tool->toolId());
94 cfg.writeEntry("roundCornersX", intRoundCornersX->value());
95 cfg.writeEntry("roundCornersY", intRoundCornersY->value());
96}
97
99{
100 KConfigGroup cfg = KSharedConfig::openConfig()->group(m_tool->toolId());
101 cfg.writeEntry("roundCornersAspectLocked", cornersAspectButton->keepAspectRatio());
102}
103
105{
106 KConfigGroup cfg = KSharedConfig::openConfig()->group(m_tool->toolId());
107
108 {
109 KisSignalsBlocker b(intRoundCornersX, intRoundCornersY, cornersAspectButton);
110 intRoundCornersX->setValue(cfg.readEntry("roundCornersX", 0));
111 intRoundCornersY->setValue(cfg.readEntry("roundCornersY", 0));
112 cornersAspectButton->setKeepAspectRatio(cfg.readEntry("roundCornersAspectLocked", true));
114 }
115
117}
118
120{
121 intWidth->blockSignals(true);
122 intHeight->blockSignals(true);
123 doubleRatio->blockSignals(true);
124
125 if (!lockWidthButton->isChecked()) intWidth->setValue(rect.width());
126 if (!lockHeightButton->isChecked()) intHeight->setValue(rect.height());
127
128 if (!lockRatioButton->isChecked() && !(rect.width() == 0 && rect.height() == 0)) {
129 doubleRatio->setValue(fabs(rect.width()) / fabs(rect.height()));
130 }
131
132 intWidth->blockSignals(false);
133 intHeight->blockSignals(false);
134 doubleRatio->blockSignals(false);
135}
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
void connectSpinBoxes(SpinBoxType *spinOne, SpinBoxType *spinTwo, KoAspectButton *aspectButton)
KisRectangleConstraintWidget(QWidget *parentWidget, KisToolRectangleBase *tool, bool showRoundCornersGUI)
void constraintsChanged(bool forceRatio, bool forceWidth, bool forceHeight, float ratio, float width, float height)
void roundCornersChanged(int rx, int ry)
Q_INVOKABLE QString toolId() const
QIcon loadIcon(const QString &name)