Pencil2D Animation
Download Community News Docs Contribute
  • Overview
  • Articles
  • Code
  •  
  • Class List
  • Class Index
  • Class Hierarchy
  • Class Members
  • File List
Loading...
Searching...
No Matches
  • core_lib
  • src
  • managers
colormanager.cpp
1/*
2
3Pencil2D - Traditional Animation Software
4Copyright (C) 2005-2007 Patrick Corrieri & Pascal Naidon
5Copyright (C) 2012-2020 Matthew Chiawen Chang
6
7This program is free software; you can redistribute it and/or
8modify it under the terms of the GNU General Public License
9as published by the Free Software Foundation; version 2 of the License.
10
11This program is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16*/
17
18#include "colormanager.h"
19
20#include "object.h"
21#include "editor.h"
22
23
24ColorManager::ColorManager(Editor* editor) : BaseManager(editor, __FUNCTION__)
25{
26}
27
28ColorManager::~ColorManager()
29{
30}
31
32bool ColorManager::init()
33{
34 return true;
35}
36
37Status ColorManager::load(Object* o)
38{
39 mCurrentColorIndex = 0;
40 mCurrentFrontColor = o->data()->getCurrentColor();
41
42 return Status::OK;
43}
44
45Status ColorManager::save(Object* o)
46{
47 o->data()->setCurrentColor(mCurrentFrontColor);
48 return Status::OK;
49}
50
51void 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
61QColor ColorManager::frontColor(bool useIndexedColor)
62{
63 if (mIsWorkingOnVectorLayer && useIndexedColor)
64 return object()->getColor(mCurrentColorIndex).color;
65 else
66 return mCurrentFrontColor;
67}
68
69void 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
81void ColorManager::setFrontColor(const QColor& newFrontColor)
82{
83 mCurrentFrontColor = newFrontColor;
84 emit colorChanged(newFrontColor, mCurrentColorIndex);
85}
86
87void ColorManager::setIndexedColor(const QColor& newColor)
88{
89 object()->setColor(mCurrentColorIndex, newColor);
90 emit colorChanged(newColor, mCurrentColorIndex);
91}
92
93int ColorManager::frontColorNumber() const
94{
95 return mCurrentColorIndex;
96}
BaseManager
Definition: basemanager.h:29
ColorManager::setIndexedColor
void setIndexedColor(const QColor &newColor)
Set color for current index.
Definition: colormanager.cpp:87
ColorManager::frontColor
QColor frontColor(bool useIndexedColor=true)
frontColor
Definition: colormanager.cpp:61
Editor
Definition: editor.h:71
Layer
Definition: layer.h:33
Object
Definition: object.h:42
Status
Definition: pencilerror.h:40
QColor
Generated on Thu May 8 2025 04:47:53 for Pencil2D by doxygen 1.9.6 based on revision 4513250b1d5b1a3676ec0e67b06b7a885ceaae39