#include "ColorOptsDialog.h" #include <QColorDialog> #include <QLabel> #include <QLayout> #include <QPainter> #include <QPushButton> #include <QSlider> ColorOptsDialog::ColorOptsDialog( QColor m, QColor c, QColor e, int t ) { setWindowTitle( "Color Options" ); setAttribute( Qt::WA_DeleteOnClose ); setModal( true ); QVBoxLayout* vl = new QVBoxLayout( this ); QGridLayout* gl = new QGridLayout; vl->addLayout( gl ); sample = new ColorSample; sample->setFixedSize( 200, 200 ); gl->addWidget( sample, 0, 0, 4, 1 ); sample->maskC = m; sample->conflictC = c; sample->eraserC = e; QPushButton* pickMask = new QPushButton( "Pick stencil color..." ); gl->addWidget( pickMask, 0, 1, 1, 1 ); connect( pickMask, SIGNAL( pressed() ), this, SLOT( chooseMaskColor() ) ); pickMask->setFixedWidth( pickMask->sizeHint().width() + 10 ); QPushButton* pickConf = new QPushButton( "Pick conflict color..." ); gl->addWidget( pickConf, 1, 1, 1, 1 ); connect( pickConf, SIGNAL( pressed() ), this, SLOT( chooseConflictColor() ) ); QPushButton* pickEras = new QPushButton( "Pick eraser color..." ); gl->addWidget( pickEras, 2, 1, 1, 1 ); connect( pickEras, SIGNAL( pressed() ), this, SLOT( chooseEraserColor() ) ); gl->setRowStretch( 3, 1 ); swatch = new ToleranceSwatch; swatch->setFixedHeight( 80 ); swatch->tolerance = t; vl->addWidget( swatch); QSlider* slider = new QSlider( Qt::Horizontal ); QHBoxLayout* shl = new QHBoxLayout; vl->addLayout( shl ); shl->addStretch( 1 ); shl->addWidget( slider, 10 ); shl->addStretch( 1 ); slider->setRange( 0, 5 ); slider->setTickInterval( 1 ); slider->setTickPosition( QSlider::TicksAbove ); slider->setValue( swatch->tolerance ); connect( slider, SIGNAL( valueChanged(int) ), swatch, SLOT( setTolerance(int) ) ); QHBoxLayout* hl = new QHBoxLayout; vl->addLayout( hl ); hl->addStretch( 1 ); QPushButton* ok = new QPushButton( "OK" ); hl->addWidget( ok ); connect( ok, SIGNAL( pressed() ), this, SLOT( okay() ) ); ok->setFocus( Qt::OtherFocusReason ); ok->setDefault( true ); QPushButton* cancel = new QPushButton( "Cancel" ); hl->addWidget( cancel ); connect( cancel, SIGNAL( pressed() ), this, SLOT( close() ) ); setFixedSize( sizeHint() ); } ColorOptsDialog::~ColorOptsDialog(void) { } void ColorOptsDialog::chooseMaskColor() { bool ok; QRgb m = QColorDialog::getRgba( sample->maskC.rgba(), &ok, this ); if ( !ok ) return; sample->maskC.setRgba( m ); sample->update(); } void ColorOptsDialog::chooseConflictColor() { QColor c = QColorDialog::getColor( sample->conflictC, this ); if ( !c.isValid() ) return; sample->conflictC = c; sample->update(); } void ColorOptsDialog::chooseEraserColor() { bool ok; QRgb e = QColorDialog::getRgba( sample->eraserC.rgba(), &ok, this ); if ( !ok ) return; sample->eraserC.setRgba( e ); sample->update(); } void ColorOptsDialog::okay() { emit setMaskColor( sample->maskC ); emit setConflictColor( sample->conflictC ); emit setEraserColor( sample->eraserC ); emit setTolerance( swatch->tolerance ); close(); } void ColorSample::paintEvent( QPaintEvent* ) { QPainter p( this ); QRect r( 0, 0, 15, 15 ); p.scale( width() / r.width(), height() / r.height() ); p.fillRect( r, QBrush( Qt::lightGray ) ); p.fillRect( r, QBrush( Qt::white, Qt::Dense4Pattern ) ); p.setPen( Qt::NoPen ); p.setBrush( palette().background() ); p.drawRect( QRect( 0, 6, 15, 1 ) ); p.setBrush( eraserC ); p.drawRect( QRect( 0, 6, 15, 1 ) ); r = QRect( 1, 1, 13, 13 ); p.fillRect( r, maskC ); p.setClipRect( QRect( 0, 0, 15, 6 ) ); p.setClipRect( QRect( 0, 7, 15, 8 ), Qt::UniteClip ); p.setPen( conflictC ); p.drawText( r, Qt::AlignCenter, "?" ); } void ToleranceSwatch::paintEvent( QPaintEvent* ) { //See DiffWidget::setTolerance() and imageDiff(). //tolerance / 10.0 * 255 * 3 = RGB variance. //Hence, each tick on the slider, and each square //in the swatch, should have an RGB variance of //roughly 76.5 in total. //There are 6 squares. float r = 0.0; float g = 255.0; float b = 0.0; QPainter p( this ); p.setPen( QColor( 150, 150, 150 ) ); for ( int i = 0 ; i < 6 ; i++ ) { p.setBrush( QColor( r, g, b ) ); p.drawRect( i * contentsRect().width() / 6, 20, contentsRect().width() / 6, contentsRect().height() - 21 ); r += 76.5 / 2; b += 76.5 / 2; } int end = contentsRect().width() * ( tolerance + 1 ) / 6; if ( end > contentsRect().width() - 1 ) end = contentsRect().width() - 1; p.setPen( QColor( 150, 0, 0 ) ); p.drawLine( 0, 19, 0, 15 ); p.drawLine( 0, 15, end, 15 ); p.drawLine( end, 15, end, 19 ); p.drawText( QRect( 0, 0, contentsRect().width(), 15 ), Qt::AlignLeft | Qt::AlignBottom, "These colors will be considered similar when diffing/merging." ); } void ToleranceSwatch::setTolerance( int t ) { tolerance = t; update(); }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#3 | 5534 | Sam Stafford |
A brand new help file, a bit of cosmetic sprucing, one critical bug fix, and a partridge in a pear tree. |
||
#2 | 5515 | Sam Stafford |
A little more groundwork for merging. Color options are now saved automatically, and may include alpha channels (semitransparent stencils are nifty). |
||
#1 | 5512 | Sam Stafford | UI reshuffling - pushed stencil-related options into a dialog. |