2 #include "popupcolorpalettewidget.h"
5 #include <QGraphicsDropShadowEffect>
10 #include "scribblearea.h"
13 PopupColorPaletteWidget::PopupColorPaletteWidget(
ScribbleArea *parent ) :
14 QWidget ( parent, Qt::Window ),
17 QVBoxLayout* mainLayout =
new QVBoxLayout(
this );
23 mainLayout->addWidget(mColorBox);
24 mColorBox->adjustSize();
26 QGraphicsDropShadowEffect* effect =
new QGraphicsDropShadowEffect();
27 effect->setXOffset(2);
28 effect->setYOffset(2);
29 effect->setBlurRadius(5);
30 setGraphicsEffect(effect);
32 setAutoFillBackground(
true);
33 setWindowTitle(
"Color palette");
34 setWindowFlags( ( (windowFlags()
35 | Qt::CustomizeWindowHint)
36 & ~Qt::WindowMaximizeButtonHint
37 & ~Qt::WindowMinimizeButtonHint) );
40 QHBoxLayout *buttonsLayout =
new QHBoxLayout();
41 mainLayout->addLayout(buttonsLayout);
42 closeButton =
new QPushButton(
this);
43 closeButton->setText(
"close/toggle");
44 buttonsLayout->addWidget(closeButton);
47 connect( closeButton , SIGNAL( clicked() ) , mContainer , SLOT( togglePopupPalette() ) );
48 connect( mColorBox, SIGNAL( colorChanged(QColor) ),
this, SLOT( onColorChanged(QColor) ) );
51 void PopupColorPaletteWidget::popup()
53 if ( this->isVisible() )
60 mColorBox->setColor( mContainer->editor()->color()->frontColor() );
61 mColorBox->setFocus();
63 QPoint cPos = QCursor::pos();
64 int radius = width() / 2;
66 cPos.setX(cPos.x()-radius);
67 cPos.setY(cPos.y()-radius);
74 void PopupColorPaletteWidget::keyPressEvent(QKeyEvent *event)
76 if (event->key() == Qt::Key_Enter)
78 mColorBox->setFocus();
79 qDebug() <<
"sent key_enter";
82 else if (event->key() == Qt::Key_Escape)
89 qDebug() <<
"sent event.ignore()";
90 QCoreApplication::sendEvent(mContainer, event);
96 void PopupColorPaletteWidget::onColorChanged(
const QColor& color)
98 mContainer->editor()->color()->setColor( color );