Changeset View
Changeset View
Standalone View
Standalone View
libs/ui/widgets/KisLayerStyleAngleSelector.cpp
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * Copyright (c) 2018 Anna Medonosova <anna.medonosova@gmail.com> | ||||
3 | * | ||||
4 | * This library is free software; you can redistribute it and/or modify | ||||
5 | * it under the terms of the GNU Lesser General Public License as published by | ||||
6 | * the Free Software Foundation; version 2.1 of the License. | ||||
7 | * | ||||
8 | * This library is distributed in the hope that it will be useful, | ||||
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
11 | * GNU Lesser General Public License for more details. | ||||
12 | * | ||||
13 | * You should have received a copy of the GNU Lesser General Public License | ||||
14 | * along with this program; if not, write to the Free Software | ||||
15 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||||
16 | */ | ||||
17 | | ||||
18 | #include "KisLayerStyleAngleSelector.h" | ||||
19 | | ||||
20 | #include <QWidget> | ||||
21 | #include <QDial> | ||||
22 | | ||||
23 | #include <kis_signals_blocker.h> | ||||
24 | | ||||
25 | KisLayerStyleAngleSelector::KisLayerStyleAngleSelector(QWidget *parent) | ||||
26 | : QWidget(parent) | ||||
27 | , m_enableGlobalLight(false) | ||||
28 | { | ||||
29 | ui = new Ui_WdgKisLayerStyleAngleSelector(); | ||||
30 | ui->setupUi(this); | ||||
31 | | ||||
32 | ui->chkUseGlobalLight->hide(); | ||||
33 | | ||||
34 | connect(ui->dialAngle, SIGNAL(valueChanged(int)), SLOT(slotDialAngleChanged(int))); | ||||
35 | connect(ui->intAngle, SIGNAL(valueChanged(int)), SLOT(slotIntAngleChanged(int))); | ||||
36 | } | ||||
37 | | ||||
38 | int KisLayerStyleAngleSelector::value() | ||||
39 | { | ||||
40 | return ui->intAngle->value(); | ||||
41 | } | ||||
42 | | ||||
43 | void KisLayerStyleAngleSelector::setValue(int value) | ||||
44 | { | ||||
45 | KisSignalsBlocker intB(ui->intAngle); | ||||
46 | KisSignalsBlocker dialB(ui->dialAngle); | ||||
47 | | ||||
48 | ui->intAngle->setValue(value); | ||||
49 | ui->dialAngle->setValue(value + m_dialValueShift); | ||||
50 | } | ||||
51 | | ||||
52 | void KisLayerStyleAngleSelector::enableGlobalLight(bool enable) | ||||
53 | { | ||||
54 | m_enableGlobalLight = enable; | ||||
55 | | ||||
56 | if (enable) { | ||||
57 | ui->chkUseGlobalLight->show(); | ||||
58 | connect(ui->chkUseGlobalLight, SIGNAL(toggled(bool)), SLOT(slotGlobalLightToggled())); | ||||
59 | } else { | ||||
60 | ui->chkUseGlobalLight->hide(); | ||||
61 | disconnect(ui->chkUseGlobalLight, SIGNAL(toggled(bool)), this, SLOT(slotGlobalLightToggled())); | ||||
62 | } | ||||
63 | } | ||||
64 | | ||||
65 | bool KisLayerStyleAngleSelector::useGlobalLight() | ||||
66 | { | ||||
67 | return m_enableGlobalLight && ui->chkUseGlobalLight->isChecked(); | ||||
68 | } | ||||
69 | | ||||
70 | void KisLayerStyleAngleSelector::setUseGlobalLight(bool state) | ||||
71 | { | ||||
72 | ui->chkUseGlobalLight->setChecked(state); | ||||
73 | } | ||||
74 | | ||||
75 | void KisLayerStyleAngleSelector::slotDialAngleChanged(int value) | ||||
76 | { | ||||
77 | KisSignalsBlocker b(ui->intAngle); | ||||
78 | | ||||
79 | int normalizedValue = 0; | ||||
80 | if (value >= 270 && value <= 360) { | ||||
81 | // Due to the mismatch between the domain of the dial (0°,360°) | ||||
82 | // and the spinbox (-179°,180°), the shift in the third quadrant | ||||
83 | // of the dial is different | ||||
84 | normalizedValue = value - 360 - m_dialValueShift; | ||||
85 | } else { | ||||
86 | normalizedValue = value - m_dialValueShift; | ||||
87 | } | ||||
88 | | ||||
89 | ui->intAngle->setValue(normalizedValue); | ||||
90 | emit valueChanged(normalizedValue); | ||||
91 | emitChangeSignals(); | ||||
92 | } | ||||
93 | | ||||
94 | void KisLayerStyleAngleSelector::slotIntAngleChanged(int value) | ||||
95 | { | ||||
96 | KisSignalsBlocker b(ui->dialAngle); | ||||
97 | | ||||
98 | int angleDialValue = value + m_dialValueShift; | ||||
99 | ui->dialAngle->setValue(angleDialValue); | ||||
100 | | ||||
101 | emit valueChanged(value); | ||||
102 | emitChangeSignals(); | ||||
103 | } | ||||
104 | | ||||
105 | void KisLayerStyleAngleSelector::slotGlobalLightToggled() | ||||
106 | { | ||||
107 | emitChangeSignals(); | ||||
108 | } | ||||
109 | | ||||
110 | void KisLayerStyleAngleSelector::emitChangeSignals() | ||||
111 | { | ||||
112 | if (useGlobalLight()) { | ||||
113 | emit globalAngleChanged(value()); | ||||
114 | } | ||||
115 | | ||||
116 | emit configChanged(); | ||||
117 | } |