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, __FUNCTION__)
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(bool useIndexedColor)
62 {
63  if (mIsWorkingOnVectorLayer && useIndexedColor)
64  return object()->getColor(mCurrentColorIndex).color;
65  else
66  return mCurrentFrontColor;
67 }
68 
69 void ColorManager::setColorNumber(int n)
70 {
71  Q_ASSERT(n >= 0);
72 
73  mCurrentColorIndex = n;
74 
75  QColor currentColor = object()->getColor(mCurrentColorIndex).color;
76 
77  emit colorNumberChanged(mCurrentColorIndex);
78  setFrontColor(currentColor);
79 }
80 
81 void ColorManager::setFrontColor(const QColor& newFrontColor)
82 {
83  mCurrentFrontColor = newFrontColor;
84  emit colorChanged(newFrontColor, mCurrentColorIndex);
85 }
86 
88 {
89  object()->setColor(mCurrentColorIndex, newColor);
90  emit colorChanged(newColor, mCurrentColorIndex);
91 }
92 
93 int ColorManager::frontColorNumber() const
94 {
95  return mCurrentColorIndex;
96 }
Definition: layer.h:38
void setIndexedColor(const QColor &newColor)
Set color for current index.
QColor frontColor(bool useIndexedColor=true)
frontColor
Definition: object.h:41
Definition: editor.h:55