All Classes Namespaces Functions Variables Enumerations Properties Pages
pencilsettings.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 #include "pencilsettings.h"
18 
19 #include <QStringList>
20 #include <QDebug>
21 
22 
23 // ==== Singleton ====
24 
25 QSettings& pencilSettings()
26 {
27  static QSettings settings(PENCIL2D, PENCIL2D);
28 
29  if ( !settings.contains("InitPencilSetting") )
30  {
31  restoreToDefaultSetting();
32  settings.setValue("InitPencilSetting", true);
33  }
34  return settings;
35 }
36 
37 void restoreToDefaultSetting() // TODO: finish reset list
38 {
39  QSettings s(PENCIL2D, PENCIL2D);
40 
41  s.setValue("penWidth", 2.0);
42  s.setValue("pencilWidth", 4.0);
43  s.setValue("polyLineWidth", 1.5);
44  s.setValue("eraserWidth", 10.0);
45  s.setValue("brushWidth", 15.0);
46  s.setValue("brushFeather", 15.0);
47  s.setValue("brushUseFeather", true);
48 
49  s.setValue(SETTING_AUTO_SAVE_NUMBER, 15);
50  s.setValue(SETTING_TOOL_CURSOR, true);
51 
52  s.sync();
53  qDebug("restored default tools");
54 }
55 
56 void checkExistingShortcuts()
57 {
58  QSettings defaultKey(":resources/kb.ini", QSettings::IniFormat);
59 
60  QSettings curSetting( PENCIL2D, PENCIL2D );
61  foreach (QString pShortcutsKey, defaultKey.allKeys())
62  {
63  if ( ! curSetting.contains( pShortcutsKey ) )
64  {
65  curSetting.setValue(pShortcutsKey, defaultKey.value(pShortcutsKey));
66  }
67  }
68 
69  curSetting.beginGroup(SHORTCUTS_GROUP);
70  defaultKey.beginGroup(SHORTCUTS_GROUP);
71  foreach (QString pKey, curSetting.allKeys())
72  {
73  if ( !defaultKey.contains(pKey) )
74  {
75  curSetting.remove(pKey);
76  }
77  }
78  defaultKey.endGroup();
79  curSetting.endGroup();
80  curSetting.sync();
81 }
82 
83 void restoreShortcutsToDefault()
84 {
85  QSettings defaultKey(":resources/kb.ini", QSettings::IniFormat);
86 
87  QSettings curSetting( PENCIL2D, PENCIL2D );
88  curSetting.remove("shortcuts");
89 
90  foreach (QString pShortcutsKey, defaultKey.allKeys())
91  {
92  curSetting.setValue(pShortcutsKey, defaultKey.value(pShortcutsKey));
93  }
94 }