Pencil2D Animation
Download Community News Docs Contribute
  • Overview
  • Articles
  • Code
  •  
  • Class List
  • Class Index
  • Class Hierarchy
  • Class Members
  • File List
Loading...
Searching...
No Matches
  • app
  • src
popupcolorpalettewidget.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#include "popupcolorpalettewidget.h"
18
19#include <QBoxLayout>
20#include <QGraphicsDropShadowEffect>
21#include <QPushButton>
22#include <QKeyEvent>
23#include <QDebug>
24#include "colorbox.h"
25#include "editor.h"
26#include "scribblearea.h"
27
28
29PopupColorPaletteWidget::PopupColorPaletteWidget( ScribbleArea *parent ) :
30 QWidget ( parent, Qt::Window ),
31 mContainer ( parent )
32{
33 QVBoxLayout* mainLayout = new QVBoxLayout( this );
34
35 setVisible( false );
36 setFixedWidth(200);
37
38 mColorBox = new ColorBox();
39 mainLayout->addWidget(mColorBox);
40 mColorBox->adjustSize();
41
42 QGraphicsDropShadowEffect* effect = new QGraphicsDropShadowEffect();
43 effect->setXOffset(2);
44 effect->setYOffset(2);
45 effect->setBlurRadius(5);
46 setGraphicsEffect(effect);
47
48 setAutoFillBackground(true);
49 setWindowTitle(tr("Color palette"));
50 setWindowFlags( ( (windowFlags()
51 | Qt::CustomizeWindowHint)
52 & ~Qt::WindowMaximizeButtonHint
53 & ~Qt::WindowMinimizeButtonHint) );
54
55 // --- bottom buttons layout ---
56 QHBoxLayout *buttonsLayout = new QHBoxLayout();
57 mainLayout->addLayout(buttonsLayout);
58 closeButton = new QPushButton(this);
59 closeButton->setText(tr("close/toggle"));
60 buttonsLayout->addWidget(closeButton);
61
62 // --- connections ---
63 connect( closeButton , &QPushButton::clicked , mContainer , &ScribbleArea::togglePopupPalette );
64 connect( mColorBox, &ColorBox::colorChanged, this, &PopupColorPaletteWidget::onColorChanged );
65}
66
67void PopupColorPaletteWidget::popup()
68{
69 if ( this->isVisible() )
70 {
71 //color = m_colorBox->color();
72 hide();
73 return;
74 }
75 // opening palette
76 mColorBox->setColor( mContainer->editor()->color()->frontColor() );
77 mColorBox->setFocus();
78
79 QPoint cPos = QCursor::pos();
80 int radius = width() / 2;
81
82 cPos.setX(cPos.x()-radius); // adjust cPos to center widget
83 cPos.setY(cPos.y()-radius);
84
85 move( cPos );
86 show();
87 return;
88}
89
90void PopupColorPaletteWidget::keyPressEvent(QKeyEvent *event)
91{
92 if (event->key() == Qt::Key_Enter)
93 {
94 mColorBox->setFocus();
95 qDebug() << "sent key_enter";
96 return;
97 }
98 else if (event->key() == Qt::Key_Escape)
99 {
100 close();
101 }
102 else
103 {
104 event->ignore();
105 qDebug() << "sent event.ignore()";
106 QCoreApplication::sendEvent(mContainer, event);
107 }
108}
109
110// --------------- slots ---------------
111
112void PopupColorPaletteWidget::onColorChanged(const QColor& color)
113{
114 mContainer->editor()->color()->setColor( color );
115}
ColorBox
Definition: colorbox.h:24
ColorManager::frontColor
QColor frontColor(bool useIndexedColor=true)
frontColor
Definition: colormanager.cpp:61
ScribbleArea
Definition: scribblearea.h:51
QAbstractButton::clicked
void clicked(bool checked)
QBoxLayout::addLayout
void addLayout(QLayout *layout, int stretch)
QBoxLayout::addWidget
void addWidget(QWidget *widget, int stretch, Qt::Alignment alignment)
QColor
QCoreApplication::sendEvent
bool sendEvent(QObject *receiver, QEvent *event)
QCursor::pos
QPoint pos()
QGraphicsDropShadowEffect
QGraphicsDropShadowEffect::setBlurRadius
void setBlurRadius(qreal blurRadius)
QGraphicsDropShadowEffect::setXOffset
void setXOffset(qreal dx)
QGraphicsDropShadowEffect::setYOffset
void setYOffset(qreal dy)
QHBoxLayout
QKeyEvent
QPoint
QPoint::setX
void setX(int x)
QPoint::setY
void setY(int y)
QPoint::x
int x() const const
QPoint::y
int y() const const
QPushButton
Qt
Qt::Key_Enter
Key_Enter
Qt::Window
Window
QVBoxLayout
QWidget
QWidget::close
bool close()
QWidget::event
virtual bool event(QEvent *event) override
QWidget::hide
void hide()
QWidget::move
void move(int x, int y)
QWidget::setFocus
void setFocus()
QWidget::show
void show()
QWidget::isVisible
bool isVisible() const const
QWidget::width
width
Generated on Thu May 8 2025 04:47:53 for Pencil2D by doxygen 1.9.6 based on revision 4513250b1d5b1a3676ec0e67b06b7a885ceaae39