Pencil2D  ff90c0872e88be3bf81c548cd60f01983012ec49
Pencil2D is an animation software for both bitmap and vector graphics. It is free, multi-platform, and open source.
 All Classes Functions
preferencesdialog.cpp
1 /*
2 
3 Pencil - Traditional Animation Software
4 Copyright (C) 2005-2007 Patrick Corrieri & Pascal Naidon
5 Copyright (C) 2013-2017 Matt 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 #include "preferencesdialog.h"
18 #include <QComboBox>
19 #include <QMessageBox>
20 
21 PreferencesDialog::PreferencesDialog( QWidget* parent ) : QDialog(parent)
22 {
23  setWindowTitle(tr("Preferences"));
24  setMaximumWidth(600);
25  setMaximumHeight(680);
26 }
27 
28 PreferencesDialog::~PreferencesDialog()
29 {
30 }
31 
32 void PreferencesDialog::init( PreferenceManager* m )
33 {
34  Q_ASSERT( m != nullptr );
35  mPrefManager = m;
36 
37  contentsWidget = new QListWidget;
38  contentsWidget->setViewMode( QListView::IconMode );
39  contentsWidget->setIconSize( QSize( 96, 84 ) );
40  contentsWidget->setMovement( QListView::Static );
41  contentsWidget->setMaximumWidth( 128 );
42  contentsWidget->setSpacing( 5 );
43 
44  GeneralPage* general = new GeneralPage( this );
45  general->setManager( mPrefManager );
46  general->updateValues();
47  //connect(mPrefManager, &PreferenceManager::effectChanged, general, &GeneralPage::updateValues);
48 
49  mFilesPage = new FilesPage( this );
50  mFilesPage->setManager( mPrefManager );
51  mFilesPage->updateValues();
52 
53  connect(mFilesPage, &FilesPage::clearRecentList, this, &PreferencesDialog::clearRecentList);
54  connect(this, &PreferencesDialog::updateRecentFileListBtn, mFilesPage, &FilesPage::updateClearRecentListButton);
55 
56  TimelinePage* timeline = new TimelinePage( this );
57  timeline->setManager( mPrefManager );
58  timeline->updateValues();
59 
60  ToolsPage* tools = new ToolsPage( this );
61  tools->setManager( mPrefManager );
62  tools->updateValues();
63 
64  ShortcutsPage* shortcuts = new ShortcutsPage( this );
65  shortcuts->setManager( mPrefManager );
66 
67  pagesWidget = new QStackedWidget;
68  pagesWidget->setMinimumHeight(40);
69 
70  pagesWidget->addWidget( general );
71  pagesWidget->addWidget( mFilesPage );
72  pagesWidget->addWidget( timeline );
73  pagesWidget->addWidget( tools );
74  pagesWidget->addWidget( shortcuts );
75 
76  QPushButton* closeButton = new QPushButton( tr( "Close", "Close button of preference dialog." ) );
77  connect( closeButton, &QPushButton::clicked, this, &PreferencesDialog::close );
78 
79  createIcons();
80  contentsWidget->setCurrentRow( 0 );
81 
82  QHBoxLayout* horizontalLayout = new QHBoxLayout;
83  horizontalLayout->addWidget( contentsWidget );
84  horizontalLayout->addWidget( pagesWidget, 1 );
85 
86  QHBoxLayout* buttonsLayout = new QHBoxLayout;
87  buttonsLayout->addStretch( 1 );
88  buttonsLayout->addWidget( closeButton );
89 
90  QVBoxLayout* mainLayout = new QVBoxLayout;
91  mainLayout->addLayout( horizontalLayout );
92  mainLayout->addStretch( 1 );
93  mainLayout->addSpacing( 5 );
94  mainLayout->addLayout( buttonsLayout );
95  setLayout( mainLayout );
96 }
97 
98 void PreferencesDialog::createIcons()
99 {
100  QListWidgetItem* generalButton = new QListWidgetItem(contentsWidget);
101  generalButton->setIcon(QIcon(":icons/prefspencil.png"));
102  generalButton->setText(tr("General"));
103  generalButton->setTextAlignment(Qt::AlignHCenter);
104  generalButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
105 
106  QListWidgetItem* filesButton = new QListWidgetItem(contentsWidget);
107  filesButton->setIcon(QIcon(":icons/prefs-files.png"));
108  filesButton->setText(tr("Files"));
109  filesButton->setTextAlignment(Qt::AlignHCenter);
110  filesButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
111 
112  QListWidgetItem* timelineButton = new QListWidgetItem(contentsWidget);
113  timelineButton->setIcon(QIcon(":icons/prefstimeline.png"));
114  timelineButton->setText(tr("Timeline"));
115  timelineButton->setTextAlignment(Qt::AlignHCenter);
116  timelineButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
117 
118  QListWidgetItem* toolsButton = new QListWidgetItem(contentsWidget);
119  toolsButton->setIcon(QIcon(":/icons/prefs-files.png"));
120  toolsButton->setText(tr("Tools"));
121  toolsButton->setTextAlignment(Qt::AlignHCenter);
122  toolsButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
123 
124  QListWidgetItem* shortcutsButton = new QListWidgetItem(contentsWidget);
125  shortcutsButton->setIcon(QIcon(":/icons/prefs-shortcuts.png"));
126  shortcutsButton->setText(tr("Shortcuts"));
127  shortcutsButton->setTextAlignment(Qt::AlignHCenter);
128  shortcutsButton->setFlags((Qt::ItemIsSelectable | Qt::ItemIsEnabled));
129 
130  auto onCurrentItemChanged = static_cast< void ( QListWidget::* )( QListWidgetItem*, QListWidgetItem* ) >( &QListWidget::currentItemChanged );
131  connect(contentsWidget,
132  onCurrentItemChanged,
133  this,
134  &PreferencesDialog::changePage);
135 }
136 
137 void PreferencesDialog::closeEvent(QCloseEvent *)
138 {
139  done( QDialog::Accepted );
140 }
141 
142 void PreferencesDialog::changePage(QListWidgetItem* current, QListWidgetItem* previous)
143 {
144  if (!current)
145  current = previous;
146 
147  pagesWidget->setCurrentIndex(contentsWidget->row(current));
148 }
149 
150 void PreferencesDialog::updateRecentListBtn(bool isEmpty)
151 {
152  if (isEmpty == true)
153  {
154  emit updateRecentFileListBtn();
155  }
156 }
157 
158 GeneralPage::GeneralPage(QWidget* parent) : QWidget(parent)
159 {
160  QSettings settings( PENCIL2D, PENCIL2D );
161  contents = new QWidget();
162  QVBoxLayout* outerLay = new QVBoxLayout(this);
163  QVBoxLayout* lay = new QVBoxLayout(contents);
164  scrollArea = new QScrollArea;
165 
166  QGroupBox* languageBox = new QGroupBox( tr("Language", "GroupBox title in Preference") );
167  QGroupBox* windowOpacityBox = new QGroupBox( tr( "Window opacity", "GroupBox title in Preference" ) );
168  QGroupBox* backgroundBox = new QGroupBox( tr( "Background", "GroupBox title in Preference" ) );
169  QGroupBox* appearanceBox = new QGroupBox( tr( "Appearance", "GroupBox title in Preference" ) );
170  QGroupBox* displayBox = new QGroupBox( tr( "Canvas", "GroupBox title in Preference" ) );
171  QGroupBox* editingBox = new QGroupBox( tr( "Editing", "GroupBox title in Preference" ) );
172  QGroupBox* gridBox = new QGroupBox(tr("Grid", "groupBox title in Preference") );
173 
174  mLanguageCombo = new QComboBox;
175  mLanguageCombo->addItem( tr( "<System-Language>" ), "" );
176  mLanguageCombo->addItem( tr( "Czech" ), "cs" );
177  mLanguageCombo->addItem( tr( "Danish" ), "da" );
178  mLanguageCombo->addItem( tr( "English" ), "en" );
179  mLanguageCombo->addItem( tr( "German" ), "de" );
180  mLanguageCombo->addItem( tr( "Spanish" ), "es" );
181  mLanguageCombo->addItem( tr( "French" ), "fr" );
182  mLanguageCombo->addItem( tr( "Hungarian" ), "hu-HU" );
183  mLanguageCombo->addItem( tr( "Italian" ), "it" );
184  mLanguageCombo->addItem( tr( "Japanese" ), "ja" );
185  mLanguageCombo->addItem( tr( "Portuguese - Brazil" ), "pt-BR" );
186  mLanguageCombo->addItem( tr( "Russian" ), "ja" );
187  mLanguageCombo->addItem( tr( "Chinese - Taiwan" ), "zh-TW" );
188 
189  QLabel* windowOpacityLabel = new QLabel(tr("Opacity"));
190  mWindowOpacityLevel = new QSlider(Qt::Horizontal);
191  mWindowOpacityLevel->setMinimum(30);
192  mWindowOpacityLevel->setMaximum(100);
193  int value = settings.value("windowOpacity").toInt();
194  mWindowOpacityLevel->setValue( 100 - value );
195 
196  mBackgroundButtons = new QButtonGroup();
197  QRadioButton* checkerBackgroundButton = new QRadioButton();
198  QRadioButton* whiteBackgroundButton = new QRadioButton();
199  QRadioButton* greyBackgroundButton = new QRadioButton();
200  QRadioButton* dotsBackgroundButton = new QRadioButton();
201  QRadioButton* weaveBackgroundButton = new QRadioButton();
202 
203  QPixmap previewCheckerboard( ":background/checkerboard.png" );
204  QPixmap previewWhite(32,32);
205  QPixmap previewGrey(32,32);
206  QPixmap previewDots( ":background/dots.png" );
207  QPixmap previewWeave( ":background/weave.jpg" );
208 
209  previewWhite.fill( Qt::white );
210 
211  previewGrey.fill( Qt:: lightGray );
212 
213  checkerBackgroundButton->setIcon( previewCheckerboard.scaled(32, 32) );
214  whiteBackgroundButton->setIcon( previewWhite );
215  greyBackgroundButton->setIcon( previewGrey );
216  dotsBackgroundButton->setIcon( previewDots.scaled(32, 32) );
217  weaveBackgroundButton->setIcon( previewWeave.scaled(32, 32) );
218  mBackgroundButtons->addButton(checkerBackgroundButton);
219  mBackgroundButtons->addButton(whiteBackgroundButton);
220  mBackgroundButtons->addButton(greyBackgroundButton);
221  mBackgroundButtons->addButton(dotsBackgroundButton);
222  mBackgroundButtons->addButton(weaveBackgroundButton);
223  mBackgroundButtons->setId(checkerBackgroundButton, 1);
224  mBackgroundButtons->setId(whiteBackgroundButton, 2);
225  mBackgroundButtons->setId(greyBackgroundButton, 3);
226  mBackgroundButtons->setId(dotsBackgroundButton, 4);
227  mBackgroundButtons->setId(weaveBackgroundButton, 5);
228 
229  QHBoxLayout* backgroundLayout = new QHBoxLayout();
230  backgroundBox->setLayout(backgroundLayout);
231  backgroundLayout->addWidget(checkerBackgroundButton);
232  backgroundLayout->addWidget(whiteBackgroundButton);
233  backgroundLayout->addWidget(greyBackgroundButton);
234  backgroundLayout->addWidget(dotsBackgroundButton);
235  backgroundLayout->addWidget(weaveBackgroundButton);
236 
237  mShadowsBox = new QCheckBox(tr("Shadows"));
238  mToolCursorsBox = new QCheckBox(tr("Tool Cursors"));
239  mAntialiasingBox = new QCheckBox(tr("Antialiasing"));
240  mDottedCursorBox = new QCheckBox(tr("Dotted Cursor"));
241 
242  QGridLayout* langLayout = new QGridLayout;
243  languageBox->setLayout( langLayout );
244  langLayout->addWidget( mLanguageCombo );
245 
246 
247  mGridCheckBox = new QCheckBox(tr("Enable Grid"));
248 
249  mGridSizeInput = new QSpinBox();
250  mGridSizeInput->setMinimum(1);
251  mGridSizeInput->setMaximum(512);
252  mGridSizeInput->setFixedWidth(80);
253  gridSize = settings.value("gridSize").toInt();
254  mGridSizeInput->setValue( gridSize );
255 
256  connect( mGridSizeInput, SIGNAL(valueChanged(int)), this, SLOT(gridSizeChange(int)));
257 
258  QGridLayout* windowOpacityLayout = new QGridLayout();
259  windowOpacityBox->setLayout(windowOpacityLayout);
260  windowOpacityLayout->addWidget(windowOpacityLabel, 0, 0);
261  windowOpacityLayout->addWidget(mWindowOpacityLevel, 0, 1);
262 
263  QVBoxLayout* appearanceLayout = new QVBoxLayout();
264  appearanceBox->setLayout(appearanceLayout);
265  appearanceLayout->addWidget(mShadowsBox);
266  appearanceLayout->addWidget(mToolCursorsBox);
267  appearanceLayout->addWidget(mDottedCursorBox);
268 
269  QGridLayout* displayLayout = new QGridLayout();
270  displayBox->setLayout(displayLayout);
271  displayLayout->addWidget(mAntialiasingBox, 0, 0);
272 
273  QGridLayout* gridLayout = new QGridLayout();
274  gridBox->setLayout(gridLayout);
275  gridLayout->addWidget(mGridSizeInput, 0, 0);
276  gridLayout->addWidget(mGridCheckBox, 0, 10);
277 
278  QLabel* curveSmoothingLabel = new QLabel(tr("Vector curve smoothing"));
279  mCurveSmoothingLevel = new QSlider(Qt::Horizontal);
280  mCurveSmoothingLevel->setMinimum(1);
281  mCurveSmoothingLevel->setMaximum(100);
282  value = settings.value("curveSmoothing").toInt();
283  mCurveSmoothingLevel->setValue( value );
284 
285  mHighResBox = new QCheckBox(tr("Tablet high-resolution position"));
286 
287 
288  QGridLayout* editingLayout = new QGridLayout();
289  editingBox->setLayout(editingLayout);
290  editingLayout->addWidget(curveSmoothingLabel, 0, 0);
291  editingLayout->addWidget(mCurveSmoothingLevel, 1, 0);
292  editingLayout->addWidget(mHighResBox, 2, 0);
293 
294  outerLay->addWidget(scrollArea);
295  outerLay->addStretch(1);
296 
297  lay->addWidget( languageBox );
298  lay->addWidget( windowOpacityBox );
299  lay->addWidget( appearanceBox );
300  lay->addWidget( backgroundBox );
301  lay->addWidget( displayBox );
302  lay->addWidget( editingBox );
303  lay->addWidget( gridBox );
304 
305  scrollArea->setHorizontalScrollBarPolicy (Qt::ScrollBarAlwaysOff);
306  scrollArea->setVerticalScrollBarPolicy (Qt::ScrollBarAlwaysOn);
307  scrollArea->setMaximumWidth(400);
308  scrollArea->setMinimumWidth(128);
309  scrollArea->setWidgetResizable (true);
310  scrollArea->setWidget(contents);
311 
312  PreferencesDialog* preference = qobject_cast< PreferencesDialog* >( parent );
313 
314  auto kButtonClicked = static_cast< void (QButtonGroup::* )( int ) >( &QButtonGroup::buttonClicked );
315  auto kCurIndexChagned = static_cast< void( QComboBox::* )( int ) >( &QComboBox::currentIndexChanged );
316  connect( mLanguageCombo, kCurIndexChagned, this, &GeneralPage::languageChanged );
317  connect( mWindowOpacityLevel, &QSlider::valueChanged, preference, &PreferencesDialog::windowOpacityChange );
318  connect( mBackgroundButtons, kButtonClicked, this, &GeneralPage::backgroundChange );
319  connect( mShadowsBox, &QCheckBox::stateChanged, this, &GeneralPage::shadowsCheckboxStateChanged );
320  connect( mToolCursorsBox, &QCheckBox::stateChanged, this, &GeneralPage::toolCursorsCheckboxStateChanged );
321  connect( mAntialiasingBox, &QCheckBox::stateChanged, this, &GeneralPage::antiAliasCheckboxStateChanged );
322  connect( mCurveSmoothingLevel, &QSlider::valueChanged, this, &GeneralPage::curveSmoothingChange );
323  connect( mHighResBox, &QCheckBox::stateChanged, this, &GeneralPage::highResCheckboxStateChanged );
324  connect( mDottedCursorBox, &QCheckBox::stateChanged, this, &GeneralPage::dottedCursorCheckboxStateChanged );
325  connect( mGridSizeInput, SIGNAL(valueChanged(int)), this, SLOT(gridSizeChange(int)));
326  connect( mGridCheckBox, &QCheckBox::stateChanged, this, &GeneralPage::gridCheckBoxStateChanged );
327 
328  setLayout(lay);
329 }
330 
331 void GeneralPage::resizeEvent(QResizeEvent *event)
332 {
333  int size = 0;
334  if (this->height() < 560 ) {
335  size = this->height();
336  } else if (this->height() >= 560) {
337  size = 560;
338  }
339  scrollArea->setMinimumHeight(size);
340  QWidget::resizeEvent(event);
341 }
342 
343 
344 void GeneralPage::updateValues()
345 {
346  int index = mLanguageCombo->findData( mManager->getString( SETTING::LANGUAGE ) );
347 
348  if ( index >= 0 )
349  {
350  mLanguageCombo->blockSignals( true );
351  mLanguageCombo->setCurrentIndex( index );
352  mLanguageCombo->blockSignals( false );
353  }
354 
355  mCurveSmoothingLevel->setValue(mManager->getInt(SETTING::CURVE_SMOOTHING));
356  mWindowOpacityLevel->setValue(100 - mManager->getInt(SETTING::WINDOW_OPACITY));
357  mShadowsBox->setChecked(mManager->isOn(SETTING::SHADOW));
358  mToolCursorsBox->setChecked(mManager->isOn(SETTING::TOOL_CURSOR));
359  mAntialiasingBox->setChecked(mManager->isOn(SETTING::ANTIALIAS));
360  mDottedCursorBox->setChecked(mManager->isOn(SETTING::DOTTED_CURSOR));
361  mGridSizeInput->setValue(mManager->getInt(SETTING::GRID_SIZE));
362  mGridCheckBox->setChecked(mManager->isOn(SETTING::GRID));
363 
364  mHighResBox->setChecked(mManager->isOn(SETTING::HIGH_RESOLUTION));
365 
366  QString bgName = mManager->getString(SETTING::BACKGROUND_STYLE);
367  if (bgName == "checkerboard") {
368  mBackgroundButtons->button(1)->setChecked(true);
369  }
370  if (bgName == "white") {
371  mBackgroundButtons->button(2)->setChecked(true);
372  }
373  if (bgName == "grey") {
374  mBackgroundButtons->button(3)->setChecked(true);
375  }
376  if (bgName == "dots") {
377  mBackgroundButtons->button(4)->setChecked(true);
378  }
379  if (bgName == "weave") {
380  mBackgroundButtons->button(5)->setChecked(true);
381  }
382 }
383 
384 void GeneralPage::languageChanged( int i )
385 {
386  QString strLocale = mLanguageCombo->itemData( i ).toString();
387  mManager->set( SETTING::LANGUAGE, strLocale );
388 
389  QMessageBox::warning( this,
390  tr( "Restart Required" ),
391  tr( "The language change will take effect after a restart of Pencil2D" ) );
392 }
393 
394 void GeneralPage::backgroundChange(int value)
395 {
396  QString brushName = "white";
397  switch (value) {
398  case 1:
399  brushName = "checkerboard";
400  break;
401  case 2:
402  brushName = "white";
403  break;
404  case 3:
405  brushName = "grey";
406  break;
407  case 4:
408  brushName = "dots";
409  break;
410  case 5:
411  brushName = "weave";
412  break;
413  default:
414  break;
415  }
416  mManager->set(SETTING::BACKGROUND_STYLE, brushName);
417 }
418 
419 void GeneralPage::curveSmoothingChange(int value)
420 {
421  mManager->set(SETTING::CURVE_SMOOTHING, value);
422 }
423 
424 void GeneralPage::highResCheckboxStateChanged( bool b )
425 {
426  mManager->set( SETTING::HIGH_RESOLUTION, b );
427 }
428 
429 void GeneralPage::shadowsCheckboxStateChanged( bool b )
430 {
431  mManager->set( SETTING::SHADOW, b );
432 }
433 
434 void GeneralPage::antiAliasCheckboxStateChanged( bool b )
435 {
436  mManager->set( SETTING::ANTIALIAS, b );
437 }
438 
439 void GeneralPage::toolCursorsCheckboxStateChanged(bool b)
440 {
441  mManager->set( SETTING::TOOL_CURSOR, b );
442 }
443 
444 void GeneralPage::dottedCursorCheckboxStateChanged(bool b)
445 {
446  mManager->set( SETTING::DOTTED_CURSOR, b );
447 }
448 
449 void GeneralPage::gridSizeChange(int value)
450 {
451  mManager->set(SETTING::GRID_SIZE, value);
452 }
453 
454 void GeneralPage::gridCheckBoxStateChanged(bool b)
455 {
456  mManager->set(SETTING::GRID, b);
457 }
458 
459 TimelinePage::TimelinePage(QWidget* parent) : QWidget(parent)
460 {
461  QSettings settings( PENCIL2D, PENCIL2D );
462 
463  QVBoxLayout* lay = new QVBoxLayout();
464 
465  QGroupBox* timeLineBox = new QGroupBox(tr("Timeline"));
466  mDrawLabel = new QCheckBox(tr("Draw timeline labels"));
467  mFontSize = new QSpinBox();
468  QLabel* frameSizeLabel = new QLabel(tr("Frame size"));
469  mFrameSize = new QSlider(Qt::Horizontal, this);
470  QLabel* lengthSizeLabel = new QLabel(tr("Timeline size in Frames"));
471  mLengthSize = new QLineEdit(this);
472  QIntValidator* lengthSizeValidator = new QIntValidator(this);
473  lengthSizeValidator->setBottom(2);
474  mLengthSize->setValidator( lengthSizeValidator );
475 
476  mScrubBox = new QCheckBox(tr("Short scrub"));
477 
478  mFontSize->setRange(4, 20);
479  mFrameSize->setRange(4, 20);
480 
481  mFontSize->setFixedWidth(50);
482  mLengthSize->setFixedWidth(50);
483 
484 
485  mFrameSize->setValue(settings.value("frameSize").toInt());
486  if (settings.value("labelFontSize").toInt()==0) mFontSize->setValue(12);
487  if (settings.value("frameSize").toInt()==0) mFrameSize->setValue(6);
488  mLengthSize->setText(settings.value("length").toString());
489  if (settings.value("length").toInt()==0) mLengthSize->setText("240");
490 
491  connect(mFontSize, SIGNAL(valueChanged(int)), this, SLOT(fontSizeChange(int)));
492  connect(mFrameSize, SIGNAL(valueChanged(int)), this, SLOT(frameSizeChange(int)));
493  connect(mLengthSize, SIGNAL(textChanged(QString)), this, SLOT(lengthSizeChange(QString)));
494  connect( mDrawLabel, &QCheckBox::stateChanged, this, &TimelinePage::labelChange );
495  connect( mScrubBox, &QCheckBox::stateChanged, this, &TimelinePage::scrubChange );
496 
497  lay->addWidget(frameSizeLabel);
498  lay->addWidget(mFrameSize);
499  lay->addWidget(lengthSizeLabel);
500  lay->addWidget(mLengthSize);
501  lay->addWidget(mScrubBox);
502  timeLineBox->setLayout(lay);
503 
504  QVBoxLayout* lay2 = new QVBoxLayout();
505  lay2->addWidget(timeLineBox);
506  lay2->addStretch(1);
507  setLayout(lay2);
508 }
509 
510 void TimelinePage::updateValues()
511 {
512  mScrubBox->setChecked(mManager->isOn(SETTING::SHORT_SCRUB));
513  mDrawLabel->setChecked(mManager->isOn(SETTING::DRAW_LABEL));
514  mFontSize->setValue(mManager->getInt(SETTING::LABEL_FONT_SIZE));
515  mFrameSize->setValue(mManager->getInt(SETTING::FRAME_SIZE));
516  mLengthSize->setText(mManager->getString(SETTING::TIMELINE_SIZE));
517 }
518 
519 void TimelinePage::lengthSizeChange(QString value)
520 {
521  int length = value.toInt();
522  mManager->set(SETTING::TIMELINE_SIZE, length);
523 }
524 
525 void TimelinePage::fontSizeChange(int value)
526 {
527  mManager->set(SETTING::LABEL_FONT_SIZE, value);
528 }
529 
530 void TimelinePage::frameSizeChange(int value)
531 {
532  mManager->set(SETTING::FRAME_SIZE, value);
533 }
534 
535 void TimelinePage::labelChange(bool value)
536 {
537  mManager->set(SETTING::DRAW_LABEL, value);
538 }
539 
540 void TimelinePage::scrubChange(bool value)
541 {
542  mManager->set(SETTING::SHORT_SCRUB, value);
543 }
544 
545 FilesPage::FilesPage(QWidget* parent) : QWidget(parent)
546 {
547  QVBoxLayout *lay = new QVBoxLayout();
548 
549  QVBoxLayout *clearRecentChangesLay = new QVBoxLayout();
550 
551  QGroupBox *autosaveBox = new QGroupBox( tr( "Autosave documents", "Preference" ) );
552  mAutosaveCheckBox = new QCheckBox(tr("Enable autosave", "Preference" ));
553  QLabel *autosaveNumberLabel = new QLabel( tr( "Number of modifications before autosaving:", "Preference" ) );
554  mAutosaveNumberBox = new QSpinBox();
555 
556  QGroupBox *clearRecentFilesBox = new QGroupBox(tr("Clear recent files list", "Clear Recent Files (Preference)" ));
557  QLabel *clearRecentFilesLbl = new QLabel(tr("This will clear your list of recently opened files", "Clear Recent Files (Preference)" ));
558  mClearRecentFilesBtn = new QPushButton( tr( "Clear", "Clear Recent Files (Preference)" ) );
559 
560  mAutosaveNumberBox = new QSpinBox();
561 
562  mAutosaveNumberBox->setMinimum(5);
563  mAutosaveNumberBox->setMaximum(200);
564  mAutosaveNumberBox->setFixedWidth(50);
565 
566  connect(mAutosaveCheckBox, &QCheckBox::stateChanged, this, &FilesPage::autosaveChange);
567  connect(mAutosaveNumberBox, SIGNAL(valueChanged(int)), this, SLOT(autosaveNumberChange(int)));
568  connect(mClearRecentFilesBtn, SIGNAL(clicked(bool)), this, SLOT(clearRecentFilesList()));
569 
570  lay->addWidget(mAutosaveCheckBox);
571  lay->addWidget(autosaveNumberLabel);
572  lay->addWidget(mAutosaveNumberBox);
573  autosaveBox->setLayout(lay);
574 
575  clearRecentChangesLay->addWidget(clearRecentFilesLbl);
576  clearRecentChangesLay->addWidget(mClearRecentFilesBtn);
577  clearRecentFilesBox->setLayout(clearRecentChangesLay);
578 
579  QVBoxLayout* mainLayout = new QVBoxLayout();
580  mainLayout->addWidget(autosaveBox);
581  mainLayout->addWidget(clearRecentFilesBox);
582  mainLayout->addStretch(1);
583  setLayout(mainLayout);
584 }
585 
586 void FilesPage::updateValues()
587 {
588  mAutosaveCheckBox->setChecked(mManager->isOn(SETTING::AUTO_SAVE));
589  mAutosaveNumberBox->setValue(mManager->getInt(SETTING::AUTO_SAVE_NUMBER));
590 }
591 
592 void FilesPage::updateClearRecentListButton()
593 {
594  mClearRecentFilesBtn->setEnabled(false);
595  mClearRecentFilesBtn->setText("List is empty");
596 }
597 
598 void FilesPage::autosaveChange(bool b)
599 {
600  mManager->set(SETTING::AUTO_SAVE, b);
601 }
602 
603 void FilesPage::autosaveNumberChange(int number)
604 {
605  mManager->set(SETTING::AUTO_SAVE_NUMBER, number);
606 }
607 
608 void FilesPage::clearRecentFilesList()
609 {
610  emit clearRecentList();
611 }
612 
613 ToolsPage::ToolsPage(QWidget* parent) : QWidget(parent)
614 {
615  QSettings settings( PENCIL2D, PENCIL2D );
616 
617  QVBoxLayout* lay = new QVBoxLayout();
618 
619  QGroupBox* onionSkinBox = new QGroupBox(tr("Onion skin"));
620 
621  QLabel* onionMaxOpacityLabel = new QLabel(tr("Maximum onion opacity %"));
622  mOnionMaxOpacityBox = new QSpinBox();
623  QLabel* onionMinOpacityLabel = new QLabel(tr("Minimum onion opacity %"));
624  mOnionMinOpacityBox = new QSpinBox();
625  QLabel* onionPrevFramesNumLabel = new QLabel(tr("Number of previous onion frames shown"));
626  mOnionPrevFramesNumBox = new QSpinBox();
627  QLabel* onionNextFramesNumLabel = new QLabel(tr("Number of next onion frames shown"));
628  mOnionNextFramesNumBox = new QSpinBox();
629 
630  mOnionMaxOpacityBox->setMinimum(0);
631  mOnionMaxOpacityBox->setMaximum(100);
632  mOnionMaxOpacityBox->setFixedWidth(50);
633  mOnionMinOpacityBox->setMinimum(0);
634  mOnionMinOpacityBox->setMaximum(100);
635  mOnionMinOpacityBox->setFixedWidth(50);
636  mOnionPrevFramesNumBox->setMinimum(1);
637  mOnionPrevFramesNumBox->setMaximum(60);
638  mOnionPrevFramesNumBox->setFixedWidth(50);
639  mOnionNextFramesNumBox->setMinimum(1);
640  mOnionNextFramesNumBox->setMaximum(60);
641  mOnionNextFramesNumBox->setFixedWidth(50);
642 
643  mOnionMaxOpacityBox->setValue(settings.value( SETTING_ONION_MAX_OPACITY ).toInt());
644  mOnionMinOpacityBox->setValue(settings.value( SETTING_ONION_MIN_OPACITY ).toInt());
645  mOnionPrevFramesNumBox->setValue(settings.value( SETTING_ONION_PREV_FRAMES_NUM).toInt());
646  mOnionNextFramesNumBox->setValue(settings.value( SETTING_ONION_NEXT_FRAMES_NUM ).toInt());
647 
648  connect(mOnionMaxOpacityBox, SIGNAL(valueChanged(int)), this, SLOT(onionMaxOpacityChange(int)));
649  connect(mOnionMinOpacityBox, SIGNAL(valueChanged(int)), this, SLOT(onionMinOpacityChange(int)));
650  connect(mOnionPrevFramesNumBox, SIGNAL(valueChanged(int)), this, SLOT(onionPrevFramesNumChange(int)));
651  connect(mOnionNextFramesNumBox, SIGNAL(valueChanged(int)), this, SLOT(onionNextFramesNumChange(int)));
652 
653  lay->addWidget(onionMaxOpacityLabel);
654  lay->addWidget(mOnionMaxOpacityBox);
655  lay->addWidget(onionMinOpacityLabel);
656  lay->addWidget(mOnionMinOpacityBox);
657  lay->addWidget(onionPrevFramesNumLabel);
658  lay->addWidget(mOnionPrevFramesNumBox);
659  lay->addWidget(onionNextFramesNumLabel);
660  lay->addWidget(mOnionNextFramesNumBox);
661  onionSkinBox->setLayout(lay);
662 
663  QGroupBox* brushBox = new QGroupBox(tr("Brush Tools"));
664  mUseQuickSizingBox = new QCheckBox(tr("Use Quick Sizing"));
665  QVBoxLayout* brushBoxLayout = new QVBoxLayout();
666  brushBoxLayout->addWidget(mUseQuickSizingBox);
667 
668  connect( mUseQuickSizingBox, &QCheckBox::stateChanged, this, &ToolsPage::quickSizingChange );
669 
670  brushBox->setLayout(brushBoxLayout);
671 
672 
673  QVBoxLayout* lay2 = new QVBoxLayout();
674  lay2->addWidget(onionSkinBox);
675  lay2->addWidget(brushBox);
676  lay2->addStretch(1);
677  setLayout(lay2);
678 }
679 
680 void ToolsPage::updateValues()
681 {
682  mOnionMaxOpacityBox->setValue(mManager->getInt(SETTING::ONION_MAX_OPACITY));
683  mOnionMinOpacityBox->setValue(mManager->getInt(SETTING::ONION_MIN_OPACITY));
684  mOnionPrevFramesNumBox->setValue(mManager->getInt(SETTING::ONION_PREV_FRAMES_NUM));
685  mOnionNextFramesNumBox->setValue(mManager->getInt(SETTING::ONION_NEXT_FRAMES_NUM));
686  mUseQuickSizingBox->setChecked(mManager->isOn(SETTING::QUICK_SIZING));
687 }
688 
689 void ToolsPage::onionMaxOpacityChange(int value)
690 {
691  mManager->set(SETTING::ONION_MAX_OPACITY, value);
692 }
693 
694 void ToolsPage::quickSizingChange( bool b )
695 {
696  mManager->set(SETTING::QUICK_SIZING, b);
697 }
698 
699 void ToolsPage::onionMinOpacityChange(int value)
700 {
701  mManager->set(SETTING::ONION_MIN_OPACITY, value);
702 }
703 
704 void ToolsPage::onionPrevFramesNumChange(int value)
705 {
706  mManager->set(SETTING::ONION_PREV_FRAMES_NUM, value);
707 }
708 
709 void ToolsPage::onionNextFramesNumChange(int value)
710 {
711  mManager->set(SETTING::ONION_NEXT_FRAMES_NUM, value);
712 }