Pencil2D  ff90c0872e88be3bf81c548cd60f01983012ec49
Pencil2D is an animation software for both bitmap and vector graphics. It is free, multi-platform, and open source.
 All Classes Functions
colorbox.cpp
1 /*
2 
3 Pencil - Traditional Animation Software
4 Copyright (C) 2012-2017 Matthew Chiawen Chang
5 
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License
8 as published by the Free Software Foundation; version 2 of the License.
9 
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14 
15 */
16 
17 #include <QVBoxLayout>
18 #include "colorwheel.h"
19 #include "colorinspector.h"
20 #include "colorbox.h"
21 
22 ColorBox::ColorBox( QWidget* parent ) : BaseDockWidget( parent )
23 {
24  setWindowTitle( tr( "Color Wheel", "Color Wheel's window title" ) );
25 
26  QVBoxLayout* layout = new QVBoxLayout();
27 
28  mColorWheel = new ColorWheel(this);
29  mColorInspector = new ColorInspector(this);
30 
31  layout->setContentsMargins(5,5,5,5);
32  layout->addWidget(mColorWheel);
33  layout->addWidget(mColorInspector);
34 
35  QWidget* mainWidget = new QWidget;
36  mainWidget->setLayout(layout);
37 
38  setWidget( mainWidget );
39 
40  connect( mColorWheel, &ColorWheel::colorChanged, this, &ColorBox::onWheelMove );
41  connect( mColorInspector, &ColorInspector::colorChanged, this, &ColorBox::onSpinboxChange );
42  connect( mColorWheel, &ColorWheel::colorSelected, this, &ColorBox::onWheelRelease );
43 
44  mColorWheel->setColor(Qt::black);
45  mColorInspector->setColor(Qt::black);
46  mColorWheel->setMinimumSize(100,100);
47 
48 
49 }
50 
51 ColorBox::~ColorBox()
52 {
53 }
54 
55 void ColorBox::initUI()
56 {
57 
58 }
59 
60 void ColorBox::updateUI()
61 {
62 
63 }
64 
65 QColor ColorBox::color()
66 {
67  return mColorWheel->color();
68 }
69 
70 void ColorBox::setColor(const QColor& newColor)
71 {
72  if ( newColor != mColorWheel->color() )
73  {
74  mColorWheel->setColor(newColor);
75  mColorInspector->setColor(newColor);
76 
77  emit colorChanged(newColor);
78  }
79 }
80 
81 void ColorBox::onSpinboxChange(const QColor& color)
82 {
83  if ( mColorWheel->color() != color )
84  {
85  mColorWheel->setColor(color);
86  emit colorChanged(color);
87  }
88 }
89 
90 void ColorBox::onWheelMove(const QColor& color)
91 {
92  if ( mColorInspector->color() != color )
93  {
94  mColorInspector->setColor(color);
95  }
96 }
97 
98 void ColorBox::onWheelRelease(const QColor& color)
99 {
100  mColorInspector->setColor(color);
101  emit colorChanged(color);
102 }