All Classes Namespaces Functions Variables Enumerations Properties Pages
colormanager.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 "colormanager.h"
19 
20 #include "object.h"
21 #include "editor.h"
22 
23 
24 ColorManager::ColorManager(Editor* editor) : BaseManager(editor)
25 {
26 }
27 
28 ColorManager::~ColorManager()
29 {
30 }
31 
32 bool ColorManager::init()
33 {
34  return true;
35 }
36 
37 Status ColorManager::load(Object* o)
38 {
39  mCurrentColorIndex = 0;
40  mCurrentFrontColor = o->data()->getCurrentColor();
41 
42  return Status::OK;
43 }
44 
45 Status ColorManager::save(Object* o)
46 {
47  o->data()->setCurrentColor(mCurrentFrontColor);
48  return Status::OK;
49 }
50 
51 void ColorManager::workingLayerChanged(Layer* layer)
52 {
53  mIsWorkingOnVectorLayer = (layer->type() == Layer::VECTOR);
54  if (mIsWorkingOnVectorLayer)
55  {
56  mCurrentFrontColor = object()->getColor(mCurrentColorIndex).color;
57  emit colorChanged(mCurrentFrontColor, mCurrentColorIndex);
58  }
59 }
60 
61 QColor ColorManager::frontColor()
62 {
63 
64  if (mIsWorkingOnVectorLayer)
65  return object()->getColor(mCurrentColorIndex).color;
66  else
67  return mCurrentFrontColor;
68 }
69 
70 void ColorManager::setColorNumber(int n)
71 {
72  Q_ASSERT(n >= 0);
73 
74  mCurrentColorIndex = n;
75 
76  QColor currentColor = object()->getColor(mCurrentColorIndex).color;
77 
78  emit colorNumberChanged(mCurrentColorIndex);
79  emit colorChanged(currentColor, mCurrentColorIndex);
80 }
81 
82 void ColorManager::setColor(const QColor& newColor)
83 {
84  if (mCurrentFrontColor != newColor)
85  {
86  mCurrentFrontColor = newColor;
87 
88  emit colorChanged(mCurrentFrontColor, mCurrentColorIndex);
89 
90  if (mIsWorkingOnVectorLayer)
91  {
92  object()->setColor(mCurrentColorIndex, newColor);
93  }
94  }
95 }
96 
97 int ColorManager::frontColorNumber()
98 {
99  return mCurrentColorIndex;
100 }
Definition: layer.h:39
Definition: object.h:54
Definition: editor.h:51