All Classes Namespaces Functions Variables Enumerations Properties Pages
timelinepage.cpp
1 /*
2 
3 Pencil2D - Traditional Animation Software
4 Copyright (C) 2005-2007 Patrick Corrieri & Pascal Naidon
5 Copyright (C) 2012-2020 Matthew Chiawen Chang
6 
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; version 2 of the License.
10 
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15 
16 */
17 
18 #include "timelinepage.h"
19 
20 #include "pencildef.h"
21 #include "preferencemanager.h"
22 
23 #include "ui_timelinepage.h"
24 
25 TimelinePage::TimelinePage()
26  : ui(new Ui::TimelinePage)
27 {
28  ui->setupUi(this);
29 
30  ui->timelineLength->setMaximum(MaxFramesBound);
31 
32  auto spinBoxValueChange = static_cast<void(QSpinBox::*)(int)>(&QSpinBox::valueChanged);
33  auto sliderChanged = static_cast<void(QSlider::*)(int)>(&QSlider::valueChanged);
34  auto comboChanged = static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged);
35  connect(ui->timelineLength, spinBoxValueChange, this, &TimelinePage::timelineLengthChanged);
36  connect(ui->scrubBox, &QCheckBox::stateChanged, this, &TimelinePage::scrubChanged);
37  connect(ui->radioButtonAddNewKey, &QRadioButton::toggled, this, &TimelinePage::drawEmptyKeyRadioButtonToggled);
38  connect(ui->radioButtonDuplicate, &QRadioButton::toggled, this, &TimelinePage::drawEmptyKeyRadioButtonToggled);
39  connect(ui->radioButtonDrawOnPrev, &QRadioButton::toggled, this, &TimelinePage::drawEmptyKeyRadioButtonToggled);
40  connect(ui->flipRollMsecsSlider, sliderChanged, this, &TimelinePage::flipRollMsecSliderChanged);
41  connect(ui->flipRollMsecsSpinBox, spinBoxValueChange, this, &TimelinePage::flipRollMsecSpinboxChanged);
42  connect(ui->flipRollNumDrawingsSlider, sliderChanged, this, &TimelinePage::flipRollNumDrawingsSliderChanged);
43  connect(ui->flipRollNumDrawingsSpinBox, spinBoxValueChange, this, &TimelinePage::flipRollNumDrawingsSpinboxChanged);
44  connect(ui->flipInBtwnMsecSlider, sliderChanged, this, &TimelinePage::flipInbetweenMsecSliderChanged);
45  connect(ui->flipInBtwnMsecSpinBox, spinBoxValueChange, this, &TimelinePage::flipInbetweenMsecSpinboxChanged);
46  connect(ui->soundScrubSlider, sliderChanged, this, &TimelinePage::soundScrubMsecSliderChanged);
47  connect(ui->soundScrubSpinBox, spinBoxValueChange, this, &TimelinePage::soundScrubMsecSpinboxChanged);
48  connect(ui->layerVisibilityComboBox, comboChanged, this, &TimelinePage::layerVisibilityChanged);
49  connect(ui->visibilitySlider, &QSlider::valueChanged, this, &TimelinePage::layerVisibilityThresholdChanged);
50  connect(ui->visibilitySpinbox, spinBoxValueChange, this, &TimelinePage::layerVisibilityThresholdChanged);
51  ui->visibilitySpinbox->setSuffix("%");
52 }
53 
54 TimelinePage::~TimelinePage()
55 {
56  delete ui;
57 }
58 
59 void TimelinePage::updateValues()
60 {
61  QSignalBlocker b1(ui->scrubBox);
62  ui->scrubBox->setChecked(mManager->isOn(SETTING::SHORT_SCRUB));
63 
64  QSignalBlocker b3(ui->timelineLength);
65  ui->timelineLength->setValue(mManager->getInt(SETTING::TIMELINE_SIZE));
66  if (mManager->getString(SETTING::TIMELINE_SIZE).toInt() <= 0)
67  ui->timelineLength->setValue(240);
68 
69  QSignalBlocker b4(ui->radioButtonAddNewKey);
70  QSignalBlocker b5(ui->radioButtonDuplicate);
71  QSignalBlocker b6(ui->radioButtonDrawOnPrev);
72  int action = mManager->getInt(SETTING::DRAW_ON_EMPTY_FRAME_ACTION);
73  switch (action)
74  {
75  case CREATE_NEW_KEY:
76  ui->radioButtonAddNewKey->setChecked(true);
77  break;
78  case DUPLICATE_PREVIOUS_KEY:
79  ui->radioButtonDuplicate->setChecked(true);
80  break;
81  case KEEP_DRAWING_ON_PREVIOUS_KEY:
82  ui->radioButtonDrawOnPrev->setChecked(true);
83  break;
84  default:
85  break;
86  }
87 
88  // to secure that you have a relevant minimum setting for sound scrub
89  int fps = mManager->getInt(SETTING::FPS);
90  int minMsec = 1000 / fps;
91  if (minMsec > 100) { minMsec = 100; }
92  ui->soundScrubSpinBox->setMinimum(minMsec);
93  ui->soundScrubSlider->setMinimum(minMsec);
94 
95  ui->flipRollMsecsSlider->setValue(mManager->getInt(SETTING::FLIP_ROLL_MSEC));
96  ui->flipRollNumDrawingsSlider->setValue(mManager->getInt(SETTING::FLIP_ROLL_DRAWINGS));
97  ui->flipInBtwnMsecSlider->setValue(mManager->getInt(SETTING::FLIP_INBETWEEN_MSEC));
98  ui->flipRollMsecsSpinBox->setValue(mManager->getInt(SETTING::FLIP_ROLL_MSEC));
99  ui->flipRollNumDrawingsSpinBox->setValue(mManager->getInt(SETTING::FLIP_ROLL_DRAWINGS));
100  ui->flipInBtwnMsecSpinBox->setValue(mManager->getInt(SETTING::FLIP_INBETWEEN_MSEC));
101  ui->soundScrubSpinBox->setValue(mManager->getInt(SETTING::SOUND_SCRUB_MSEC));
102  ui->soundScrubSlider->setValue(mManager->getInt(SETTING::SOUND_SCRUB_MSEC));
103 
104  int convertedVisibilityThreshold = static_cast<int>(mManager->getFloat(SETTING::LAYER_VISIBILITY_THRESHOLD)*100);
105 
106  ui->visibilitySlider->setValue(convertedVisibilityThreshold);
107  ui->visibilitySpinbox->setValue(convertedVisibilityThreshold);
108 
109  int visibilityType = mManager->getInt(SETTING::LAYER_VISIBILITY);
110  ui->layerVisibilityComboBox->setCurrentIndex(visibilityType);
111  layerVisibilityChanged(visibilityType);
112 }
113 
114 void TimelinePage::timelineLengthChanged(int value)
115 {
116  mManager->set(SETTING::TIMELINE_SIZE, value);
117 }
118 
119 void TimelinePage::fontSizeChanged(int value)
120 {
121  mManager->set(SETTING::LABEL_FONT_SIZE, value);
122 }
123 
124 void TimelinePage::scrubChanged(int value)
125 {
126  mManager->set(SETTING::SHORT_SCRUB, value != Qt::Unchecked);
127 }
128 
129 void TimelinePage::layerVisibilityChanged(int value)
130 {
131  mManager->set(SETTING::LAYER_VISIBILITY, value);
132  ui->visibilitySlider->setEnabled(value == 1);
133  ui->visibilitySpinbox->setEnabled(value == 1);
134 }
135 
136 void TimelinePage::layerVisibilityThresholdChanged(int value)
137 {
138  float percentage = static_cast<float>(value/100.0f);
139  mManager->set(SETTING::LAYER_VISIBILITY_THRESHOLD, percentage);
140 
141  QSignalBlocker b8(ui->visibilitySlider);
142  ui->visibilitySlider->setValue(value);
143 
144  QSignalBlocker b9(ui->visibilitySpinbox);
145  ui->visibilitySpinbox->setValue(value);
146 }
147 
148 void TimelinePage::drawEmptyKeyRadioButtonToggled(bool)
149 {
150  if (ui->radioButtonAddNewKey->isChecked())
151  {
152  mManager->set(SETTING::DRAW_ON_EMPTY_FRAME_ACTION, CREATE_NEW_KEY);
153  }
154  else if (ui->radioButtonDuplicate->isChecked())
155  {
156  mManager->set(SETTING::DRAW_ON_EMPTY_FRAME_ACTION, DUPLICATE_PREVIOUS_KEY);
157  }
158  else if (ui->radioButtonDrawOnPrev->isChecked())
159  {
160  mManager->set(SETTING::DRAW_ON_EMPTY_FRAME_ACTION, KEEP_DRAWING_ON_PREVIOUS_KEY);
161  }
162 }
163 
164 void TimelinePage::flipRollMsecSliderChanged(int value)
165 {
166  ui->flipRollMsecsSpinBox->setValue(value);
167  mManager->set(SETTING::FLIP_ROLL_MSEC, value);
168 }
169 
170 void TimelinePage::flipRollMsecSpinboxChanged(int value)
171 {
172  ui->flipRollMsecsSlider->setValue(value);
173  mManager->set(SETTING::FLIP_ROLL_MSEC, value);
174 }
175 
176 void TimelinePage::flipRollNumDrawingsSliderChanged(int value)
177 {
178  ui->flipRollNumDrawingsSpinBox->setValue(value);
179  mManager->set(SETTING::FLIP_ROLL_DRAWINGS, value);
180 }
181 
182 void TimelinePage::flipRollNumDrawingsSpinboxChanged(int value)
183 {
184  ui->flipRollNumDrawingsSlider->setValue(value);
185  mManager->set(SETTING::FLIP_ROLL_DRAWINGS, value);
186 }
187 
188 void TimelinePage::flipInbetweenMsecSliderChanged(int value)
189 {
190  ui->flipInBtwnMsecSpinBox->setValue(value);
191  mManager->set(SETTING::FLIP_INBETWEEN_MSEC, value);
192 }
193 
194 void TimelinePage::flipInbetweenMsecSpinboxChanged(int value)
195 {
196  ui->flipInBtwnMsecSlider->setValue(value);
197  mManager->set(SETTING::FLIP_INBETWEEN_MSEC, value);
198 }
199 
200 void TimelinePage::soundScrubActiveChanged(int i)
201 {
202  bool b = true;
203  if (i == 0)
204  b = false;
205  mManager->set(SETTING::SOUND_SCRUB_ACTIVE, b);
206  emit soundScrubChanged(b);
207 }
208 
209 void TimelinePage::soundScrubMsecSliderChanged(int value)
210 {
211  ui->soundScrubSpinBox->setValue(value);
212  mManager->set(SETTING::SOUND_SCRUB_MSEC, value);
213  emit soundScrubMsecChanged(value);
214 }
215 
216 void TimelinePage::soundScrubMsecSpinboxChanged(int value)
217 {
218  ui->soundScrubSlider->setValue(value);
219  mManager->set(SETTING::SOUND_SCRUB_MSEC, value);
220  emit soundScrubMsecChanged(value);
221 }
void valueChanged(int i)
int toInt(bool *ok, int base) const const
void stateChanged(int state)
void toggled(bool checked)
void valueChanged(int value)
Unchecked
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void currentIndexChanged(int index)