Esempio n. 1
0
void ColorPicker::keyPressEvent(QKeyEvent *event)
{
    int key = event->key();
    int dx = 0;
    int dy = 0;
    if (key == Qt::Key_Left) {
        dx = -1;
    } else if (key == Qt::Key_Right) {
        dx = 1;
    } else if (key == Qt::Key_Up) {
        dy = -1;
    } else if (key == Qt::Key_Down) {
        dy = 1;
    } else if (key == Qt::Key_Return) {
        emitColorChanged();
        close();
        return;
    } else if (key == Qt::Key_Escape) {
        close();
        return;
    } else {
        return;
    }

    QPoint pos = QCursor::pos();
    QCursor::setPos(pos.x() + dx, pos.y() + dy);
}
Esempio n. 2
0
void ColorPicker::mousePressEvent(QMouseEvent *event)
{
    if (event->button() == Qt::LeftButton) {
        emitColorChanged();
        close();
    }
}
Esempio n. 3
0
KoColorPopupAction::KoColorPopupAction(QObject *parent)
    : QAction(parent),
    d(new KoColorPopupActionPrivate())
{
    d->menu = new QMenu();
    QWidget *widget = new QWidget(d->menu);
    QWidgetAction *wdgAction = new QWidgetAction(d->menu);
    d->colorSetWidget = new KoColorSetWidget(widget);

    d->colorChooser = new KoTriangleColorSelector( widget );
    // prevent mouse release on color selector from closing popup
    d->colorChooser->setAttribute( Qt::WA_NoMousePropagation );
    d->opacitySlider = new KoColorSlider( Qt::Vertical, widget );
    d->opacitySlider->setFixedWidth(25);
    d->opacitySlider->setRange(0, 255);
    d->opacitySlider->setValue(255);
    d->opacitySlider->setToolTip( i18n( "Opacity" ) );

    QGridLayout * layout = new QGridLayout( widget );
    layout->addWidget( d->colorSetWidget, 0, 0, 1, -1 );
    layout->addWidget( d->colorChooser, 1, 0 );
    layout->addWidget( d->opacitySlider, 1, 1 );
    layout->setMargin(4);

    wdgAction->setDefaultWidget(widget);
    d->menu->addAction(wdgAction);
    setMenu(d->menu);
    new QHBoxLayout(d->menu);
    d->menu->layout()->addWidget(widget);
    d->menu->layout()->setMargin(0);

    connect(this, SIGNAL(triggered()), this, SLOT(emitColorChanged()));

    connect(d->colorSetWidget, SIGNAL(colorChanged(const KoColor &, bool)), this, SLOT(colorWasSelected(const KoColor &, bool)));

    connect( d->colorChooser, SIGNAL( colorChanged( const QColor &) ),
             this, SLOT( colorWasEdited( const QColor &) ) );
    connect( d->opacitySlider, SIGNAL(valueChanged(int)),
             this, SLOT(opacityWasChanged(int)));
}