Changeset View
Changeset View
Standalone View
Standalone View
libs/ui/widgets/KisGamutMaskToolbar.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 <QWidget> | ||||
19 | #include "KisGamutMaskToolbar.h" | ||||
20 | #include <kis_icon_utils.h> | ||||
21 | #include <kis_canvas_resource_provider.h> | ||||
22 | | ||||
23 | KisGamutMaskToolbar::KisGamutMaskToolbar(QWidget* parent) : QWidget(parent) | ||||
24 | , m_selectedMask(nullptr) | ||||
25 | { | ||||
26 | m_ui = new Ui_wdgGamutMaskToolbar(); | ||||
27 | m_ui->setupUi(this); | ||||
28 | | ||||
29 | m_iconMaskOff = KisIconUtils::loadIcon("gamut-mask-off"); | ||||
30 | m_iconMaskOn = KisIconUtils::loadIcon("gamut-mask-on"); | ||||
31 | | ||||
32 | m_textNoMask = i18n("Select a mask in \"Gamut Masks\" docker"); | ||||
33 | m_textMaskDisabled = i18n("Mask is disabled"); | ||||
34 | | ||||
35 | m_ui->bnToggleMask->setChecked(false); | ||||
36 | m_ui->bnToggleMask->setIcon(m_iconMaskOff); | ||||
37 | | ||||
38 | m_ui->rotationSlider->setRange(0, 360); | ||||
39 | m_ui->rotationSlider->setPrefix(i18n("Rotation: ")); | ||||
40 | m_ui->rotationSlider->setSuffix("°"); | ||||
41 | m_ui->rotationSlider->setFastSliderStep(30); // TODO: test for usability | ||||
42 | m_ui->rotationSlider->hide(); | ||||
43 | | ||||
44 | // gamut mask connections | ||||
45 | connect(m_ui->bnToggleMask, SIGNAL(toggled(bool)), SLOT(slotGamutMaskToggle(bool))); | ||||
46 | connect(m_ui->rotationSlider, SIGNAL(valueChanged(int)), SLOT(slotGamutMaskRotate(int))); | ||||
47 | } | ||||
48 | | ||||
49 | void KisGamutMaskToolbar::connectMaskSignals(KisCanvasResourceProvider* resourceProvider) | ||||
50 | { | ||||
51 | connect(resourceProvider, SIGNAL(sigGamutMaskChanged(KoGamutMask*)), | ||||
52 | this, SLOT(slotGamutMaskSet(KoGamutMask*))); | ||||
53 | | ||||
54 | connect(resourceProvider, SIGNAL(sigGamutMaskUnset()), | ||||
55 | this, SLOT(slotGamutMaskUnset())); | ||||
56 | | ||||
57 | connect(this, SIGNAL(sigGamutMaskChanged(KoGamutMask*)), | ||||
58 | resourceProvider, SLOT(slotGamutMaskActivated(KoGamutMask*))); | ||||
59 | } | ||||
60 | | ||||
61 | void KisGamutMaskToolbar::slotGamutMaskSet(KoGamutMask *mask) | ||||
62 | { | ||||
63 | if (!mask) { | ||||
64 | return; | ||||
65 | } | ||||
66 | | ||||
67 | m_selectedMask = mask; | ||||
68 | | ||||
69 | if (m_selectedMask) { | ||||
70 | slotGamutMaskToggle(true); | ||||
71 | } else { | ||||
72 | slotGamutMaskToggle(false); | ||||
73 | } | ||||
74 | } | ||||
75 | | ||||
76 | void KisGamutMaskToolbar::slotGamutMaskUnset() | ||||
77 | { | ||||
78 | m_ui->rotationSlider->hide(); | ||||
79 | m_ui->labelMaskName->show(); | ||||
80 | m_ui->labelMaskName->setText(m_textNoMask); | ||||
81 | } | ||||
82 | | ||||
83 | void KisGamutMaskToolbar::slotGamutMaskToggle(bool state) | ||||
84 | { | ||||
85 | bool b = (!m_selectedMask) ? false : state; | ||||
86 | | ||||
87 | m_ui->bnToggleMask->setChecked(b); | ||||
88 | | ||||
89 | if (b == true) { | ||||
90 | m_ui->bnToggleMask->setIcon(m_iconMaskOn); | ||||
91 | m_ui->labelMaskName->hide(); | ||||
92 | m_ui->rotationSlider->show(); | ||||
93 | | ||||
94 | m_ui->rotationSlider->blockSignals(true); | ||||
95 | m_ui->rotationSlider->setValue(m_selectedMask->rotation()); | ||||
96 | m_ui->rotationSlider->blockSignals(false); | ||||
97 | } else { | ||||
98 | m_ui->bnToggleMask->setIcon(m_iconMaskOff); | ||||
99 | m_ui->rotationSlider->hide(); | ||||
100 | m_ui->labelMaskName->show(); | ||||
101 | m_ui->labelMaskName->setText(m_textMaskDisabled); | ||||
102 | } | ||||
103 | | ||||
104 | emit sigGamutMaskToggle(state); | ||||
105 | } | ||||
106 | | ||||
107 | void KisGamutMaskToolbar::slotGamutMaskRotate(int angle) | ||||
108 | { | ||||
109 | if (!m_selectedMask) { | ||||
110 | return; | ||||
111 | } | ||||
112 | | ||||
113 | m_selectedMask->setRotation(angle); | ||||
114 | emit sigGamutMaskChanged(m_selectedMask); | ||||
115 | } |