All Classes Namespaces Functions Variables Enumerations Properties Pages
onionskinwidget.cpp
1 /*
2 
3 Pencil2D - Traditional Animation Software
4 Copyright (C) 2012-2020 Matthew Chiawen Chang
5 
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License
8 as published by the Free Software Foundation; version 2 of the License.
9 
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14 
15 */
16 
17 #include "onionskinwidget.h"
18 #include "ui_onionskin.h"
19 
20 #include "preferencemanager.h"
21 #include "editor.h"
22 #include "util.h"
23 
24 OnionSkinWidget::OnionSkinWidget(QWidget *parent) :
25  BaseDockWidget(parent),
26  ui(new Ui::OnionSkin)
27 {
28  ui->setupUi(this);
29  clearFocusOnFinished(ui->onionPrevFramesNumBox);
30  clearFocusOnFinished(ui->onionNextFramesNumBox);
31  clearFocusOnFinished(ui->onionMinOpacityBox);
32  clearFocusOnFinished(ui->onionMaxOpacityBox);
33 }
34 
35 OnionSkinWidget::~OnionSkinWidget()
36 {
37  delete ui;
38 }
39 
40 void OnionSkinWidget::initUI()
41 {
42  updateUI();
43  makeConnections();
44 
45 #ifdef __APPLE__
46  // Mac only style. ToolButtons are naturally borderless on Win/Linux.
47  QString stylesheet =
48  "QToolButton { border: 0px; } "
49  "QToolButton:pressed{ border: 1px solid #FFADAD; border-radius: 2px; background-color: #D5D5D5; }"
50  "QToolButton:checked{ border: 1px solid #ADADAD; border-radius: 2px; background-color: #D5D5D5; }";
51  setStyleSheet(this->styleSheet().append(stylesheet));
52 #endif
53 }
54 
55 void OnionSkinWidget::makeConnections()
56 {
57  auto spinBoxChanged = static_cast<void(QSpinBox::*)(int)>(&QSpinBox::valueChanged);
58  connect(ui->onionMaxOpacityBox, spinBoxChanged, this, &OnionSkinWidget::onionMaxOpacityChange);
59  connect(ui->onionMinOpacityBox, spinBoxChanged, this, &OnionSkinWidget::onionMinOpacityChange);
60  connect(ui->onionPrevFramesNumBox, spinBoxChanged, this, &OnionSkinWidget::onionPrevFramesNumChange);
61  connect(ui->onionNextFramesNumBox, spinBoxChanged, this, &OnionSkinWidget::onionNextFramesNumChange);
62 
63  connect(ui->onionPrevButton, &QToolButton::clicked, this, &OnionSkinWidget::onionPrevButtonClicked);
64  connect(ui->onionNextButton, &QToolButton::clicked, this, &OnionSkinWidget::onionNextButtonClicked);
65  connect(ui->onionBlueButton, &QToolButton::clicked, this, &OnionSkinWidget::onionBlueButtonClicked);
66  connect(ui->onionRedButton, &QToolButton::clicked, this, &OnionSkinWidget::onionRedButtonClicked);
67 
68  connect(ui->onionSkinMode, &QCheckBox::stateChanged, this, &OnionSkinWidget::onionSkinModeChange);
69  connect(ui->onionWhilePlayback, &QCheckBox::stateChanged, this, &OnionSkinWidget::playbackStateChanged);
70 
71  PreferenceManager* prefs = editor()->preference();
72  connect(prefs, &PreferenceManager::optionChanged, this, &OnionSkinWidget::updateUI);
73 
74 }
75 
76 void OnionSkinWidget::updateUI()
77 {
78  PreferenceManager* prefs = editor()->preference();
79 
80  QSignalBlocker b1(ui->onionPrevButton);
81  ui->onionPrevButton->setChecked(prefs->isOn(SETTING::PREV_ONION));
82 
83  QSignalBlocker b2(ui->onionNextButton);
84  ui->onionNextButton->setChecked(prefs->isOn(SETTING::NEXT_ONION));
85 
86  QSignalBlocker b3(ui->onionBlueButton);
87  ui->onionBlueButton->setChecked(prefs->isOn(SETTING::ONION_BLUE));
88 
89  ui->onionRedButton->setEnabled(ui->onionPrevButton->isChecked());
90  ui->onionBlueButton->setEnabled(ui->onionNextButton->isChecked());
91 
92  QSignalBlocker b4(ui->onionRedButton);
93  ui->onionRedButton->setChecked(prefs->isOn(SETTING::ONION_RED));
94 
95  ui->onionMaxOpacityBox->setValue(prefs->getInt(SETTING::ONION_MAX_OPACITY));
96  ui->onionMinOpacityBox->setValue(prefs->getInt(SETTING::ONION_MIN_OPACITY));
97  ui->onionPrevFramesNumBox->setValue(prefs->getInt(SETTING::ONION_PREV_FRAMES_NUM));
98  ui->onionNextFramesNumBox->setValue(prefs->getInt(SETTING::ONION_NEXT_FRAMES_NUM));
99 
100  QSignalBlocker b5(ui->onionSkinMode);
101  ui->onionSkinMode->setChecked(prefs->getString(SETTING::ONION_TYPE) == "absolute");
102 
103  QSignalBlocker b6(ui->onionWhilePlayback);
104  ui->onionWhilePlayback->setChecked(prefs->getInt(SETTING::ONION_WHILE_PLAYBACK));
105 
106 }
107 
108 void OnionSkinWidget::onionPrevButtonClicked(bool isOn)
109 {
110  PreferenceManager* prefs = editor()->preference();
111  prefs->set(SETTING::PREV_ONION, isOn);
112 }
113 
114 void OnionSkinWidget::onionNextButtonClicked(bool isOn)
115 {
116  PreferenceManager* prefs = editor()->preference();
117  prefs->set(SETTING::NEXT_ONION, isOn);
118 }
119 
120 void OnionSkinWidget::onionRedButtonClicked(bool isOn)
121 {
122  PreferenceManager* prefs = editor()->preference();
123  prefs->set(SETTING::ONION_RED, isOn);
124 }
125 
126 void OnionSkinWidget::onionBlueButtonClicked(bool isOn)
127 {
128  PreferenceManager* prefs = editor()->preference();
129  prefs->set(SETTING::ONION_BLUE, isOn);
130 }
131 
132 void OnionSkinWidget::onionMaxOpacityChange(int value)
133 {
134  PreferenceManager* prefs = editor()->preference();
135  prefs->set(SETTING::ONION_MAX_OPACITY, value);
136 }
137 
138 void OnionSkinWidget::onionMinOpacityChange(int value)
139 {
140  PreferenceManager* prefs = editor()->preference();
141  prefs->set(SETTING::ONION_MIN_OPACITY, value);
142 }
143 
144 void OnionSkinWidget::onionPrevFramesNumChange(int value)
145 {
146  PreferenceManager* prefs = editor()->preference();
147  prefs->set(SETTING::ONION_PREV_FRAMES_NUM, value);
148 }
149 
150 void OnionSkinWidget::onionNextFramesNumChange(int value)
151 {
152  PreferenceManager* prefs = editor()->preference();
153  prefs->set(SETTING::ONION_NEXT_FRAMES_NUM, value);
154 }
155 
156 void OnionSkinWidget::onionSkinModeChange(int value)
157 {
158  PreferenceManager* prefs = editor()->preference();
159  if (value == Qt::Checked)
160  {
161  prefs->set(SETTING::ONION_TYPE, QString("absolute"));
162  }
163  else
164  {
165  prefs->set(SETTING::ONION_TYPE, QString("relative"));
166  }
167 }
168 
169 void OnionSkinWidget::playbackStateChanged(int value)
170 {
171  PreferenceManager* prefs = editor()->preference();
172  prefs->set(SETTING::ONION_WHILE_PLAYBACK, value);
173 }
void setStyleSheet(const QString &styleSheet)
void valueChanged(int i)
void clicked(bool checked)
void stateChanged(int state)
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)