All Classes Namespaces Functions Variables Enumerations Properties Pages
colorbox.cpp
1 /*
2 
3 Pencil2D - Traditional Animation Software
4 Copyright (C) 2012-2020 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 "colorbox.h"
20 #include "editor.h"
21 #include "colormanager.h"
22 
23 
24 ColorBox::ColorBox(QWidget* parent) : BaseDockWidget( parent )
25 {
26  setWindowTitle(tr("Color Box", "Color Box window title"));
27 }
28 
29 ColorBox::~ColorBox()
30 {
31 }
32 
33 void ColorBox::initUI()
34 {
35  mColorWheel = new ColorWheel(this);
36 
38  layout->setContentsMargins(5, 5, 5, 5);
39  layout->addWidget(mColorWheel);
40  layout->setStretch(0, 1);
41  layout->setStretch(1, 0);
42  QWidget* mainWidget = new QWidget;
43  mainWidget->setLayout(layout);
44  setWidget(mainWidget);
45 
46  connect(mColorWheel, &ColorWheel::colorChanged, this, &ColorBox::onWheelMove);
47  connect(mColorWheel, &ColorWheel::colorSelected, this, &ColorBox::onWheelRelease);
48 
49  connect(editor(), &Editor::objectLoaded, this, &ColorBox::updateUI);
50 }
51 
52 void ColorBox::updateUI()
53 {
54  QColor newColor = editor()->color()->frontColor();
55  setColor(newColor);
56 }
57 
58 QColor ColorBox::color()
59 {
60  return mColorWheel->color();
61 }
62 
63 void ColorBox::setColor(QColor newColor)
64 {
65  newColor = newColor.toHsv();
66 
67  if ( newColor != mColorWheel->color() )
68  {
69  mColorWheel->setColor(newColor);
70  }
71 }
72 
73 void ColorBox::onWheelMove(const QColor& color)
74 {
75  emit colorChanged(color);
76 }
77 
78 void ColorBox::onWheelRelease(const QColor& color)
79 {
80  emit colorChanged(color);
81 }
QLayout * layout() const const
void setContentsMargins(int left, int top, int right, int bottom)
void setStretch(int index, int stretch)
QString tr(const char *sourceText, const char *disambiguation, int n)
QColor toHsv() const const
void addWidget(QWidget *widget, int stretch, Qt::Alignment alignment)
void setLayout(QLayout *layout)
QColor frontColor(bool useIndexedColor=true)
frontColor
void setWidget(QWidget *widget)
void setWindowTitle(const QString &)
QWidget(QWidget *parent, Qt::WindowFlags f)
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)