Source Code (Use browser search to find items of interest.)

Class Index

qt'QColorShowLabel (./qt-2.1.0/src/dialogs/qcolordialog.cpp:562)

class QColorShowLabel : public QFrame
{
    Q_OBJECT

public:
    QColorShowLabel( QWidget *parent ) :QFrame( parent ) {
	setFrameStyle( QFrame::Panel|QFrame::Sunken );
	setBackgroundMode( PaletteBackground );
	setAcceptDrops( TRUE );
	mousePressed = FALSE;
    }
    void setColor( QColor c ) { col = c; }

signals:
    void colorDropped( QRgb );

protected:
    void drawContents( QPainter *p );
    void mousePressEvent( QMouseEvent *e );
    void mouseMoveEvent( QMouseEvent *e );
    void mouseReleaseEvent( QMouseEvent *e );
    void dragEnterEvent( QDragEnterEvent *e );
    void dragLeaveEvent( QDragLeaveEvent *e );
    void dropEvent( QDropEvent *e );

private:
    QColor col;
    bool mousePressed;
    QPoint pressPos;

};

void QColorShowLabel::drawContents( QPainter *p )
{
    p->fillRect( contentsRect(), col );
}


qt'QColorShowLabel::drawContents() (./qt-2.1.0/src/dialogs/qcolordialog.cpp:594)

void QColorShowLabel::drawContents( QPainter *p )
{
    p->fillRect( contentsRect(), col );
}


qt'QColorShowLabel::mousePressEvent() (./qt-2.1.0/src/dialogs/qcolordialog.cpp:610)

void QColorShowLabel::mousePressEvent( QMouseEvent *e )
{
    mousePressed = TRUE;
    pressPos = e->pos();
}


qt'QColorShowLabel::mouseMoveEvent() (./qt-2.1.0/src/dialogs/qcolordialog.cpp:616)

void QColorShowLabel::mouseMoveEvent( QMouseEvent *e )
{
    if ( !mousePressed )
	return;
    if ( ( pressPos - e->pos() ).manhattanLength() > QApplication::startDragDistance() ) {
	QColorDrag *drg = new QColorDrag( col, this );
	QPixmap pix( 30, 20 );
	pix.fill( col );
	QPainter p( &pix );
	p.drawRect( 0, 0, pix.width(), pix.height() );
	p.end();
	drg->setPixmap( pix );
	mousePressed = FALSE;
	drg->dragCopy();
    }
}


qt'QColorShowLabel::dragEnterEvent() (./qt-2.1.0/src/dialogs/qcolordialog.cpp:633)

void QColorShowLabel::dragEnterEvent( QDragEnterEvent *e )
{
    if ( QColorDrag::canDecode( e ) )
	e->accept();
    else
	e->ignore();
}


qt'QColorShowLabel::dragLeaveEvent() (./qt-2.1.0/src/dialogs/qcolordialog.cpp:641)

void QColorShowLabel::dragLeaveEvent( QDragLeaveEvent * )
{
}


qt'QColorShowLabel::dropEvent() (./qt-2.1.0/src/dialogs/qcolordialog.cpp:645)

void QColorShowLabel::dropEvent( QDropEvent *e )
{
    if ( QColorDrag::canDecode( e ) ) {
	QColorDrag::decode( e, col );
	repaint( FALSE );
	emit colorDropped( col.rgb() );
	e->accept();
    } else {
	e->ignore();
    }
}


qt'QColorShowLabel::mouseReleaseEvent() (./qt-2.1.0/src/dialogs/qcolordialog.cpp:657)

void QColorShowLabel::mouseReleaseEvent( QMouseEvent * )
{
    if ( !mousePressed )
	return;
    mousePressed = FALSE;
}