Ejemplo n.º 1
0
void ColorDisplay::mouseReleaseEvent(QMouseEvent *event)
{
	if(isReadOnly())	return;
	int colorIndex = colorId(event->pos());
	QColor color = QColorDialog::getColor(colors.at(colorIndex), this, tr("Choisir une nouvelle couleur"));
	if(color.isValid()) {
		colors.replace(colorIndex, color.rgb());
		emit colorEdited(colorIndex, color.rgb());
	}
	update();
}
Ejemplo n.º 2
0
ColorLineEdit::ColorLineEdit(QWidget* parent)
    : QLineEdit(parent), p(new Private)
{
    p->background.setTexture(QPixmap(QStringLiteral(":/color_widgets/alphaback.png")));
    setColor(Qt::white);
    /// \todo determine if having this connection might be useful
    /*connect(this, &QLineEdit::textChanged, [this](const QString& text){
        QColor color = p->colorFromString(text);
        if ( color.isValid() )
            Q_EMIT colorChanged(color);
    });*/
    connect(this, &QLineEdit::textEdited, [this](const QString& text){
        QColor color = color_widgets::colorFromString(text, p->show_alpha);
        if ( color.isValid() )
        {
            p->color = color;
            p->setPalette(color, this);
            Q_EMIT colorEdited(color);
            Q_EMIT colorChanged(color);
        }
    });
    connect(this, &QLineEdit::editingFinished, [this](){
        QColor color = color_widgets::colorFromString(text(), p->show_alpha);
        if ( color.isValid() )
        {
            p->color = color;
            Q_EMIT colorEditingFinished(color);
            Q_EMIT colorChanged(color);
        }
        else
        {
            setText(color_widgets::stringFromColor(p->color, p->show_alpha));
            Q_EMIT colorEditingFinished(p->color);
            Q_EMIT colorChanged(color);
        }
        p->setPalette(p->color, this);
    });
}