author | drw <drw> | 2004-02-21 22:54:19 (UTC) |
---|---|---|
committer | drw <drw> | 2004-02-21 22:54:19 (UTC) |
commit | f36efd3490299fb9402a2dc2a6bd2a029fcd93cb (patch) (side-by-side diff) | |
tree | 701f649c97a730794a45f47a94e09b9d2ce670d0 | |
parent | 1a89ecd8e2d11d48a8e80b2fd8b1e95b738a286c (diff) | |
download | opie-f36efd3490299fb9402a2dc2a6bd2a029fcd93cb.zip opie-f36efd3490299fb9402a2dc2a6bd2a029fcd93cb.tar.gz opie-f36efd3490299fb9402a2dc2a6bd2a029fcd93cb.tar.bz2 |
Moved class defines in qcolordialog.cpp to header so that apps can properly link to libqtaux
-rw-r--r-- | libqtaux/qcolordialog.cpp | 357 | ||||
-rw-r--r-- | libqtaux/qcolordialog.h | 311 |
2 files changed, 321 insertions, 347 deletions
diff --git a/libqtaux/qcolordialog.cpp b/libqtaux/qcolordialog.cpp index 5881a89..1574841 100644 --- a/libqtaux/qcolordialog.cpp +++ b/libqtaux/qcolordialog.cpp @@ -1,230 +1,128 @@ /**************************************************************************** ** $Id$ ** ** Implementation of QColorDialog class ** ** Created : 990222 ** ** Copyright (C) 1999-2000 Trolltech AS. All rights reserved. ** ** This file is part of the dialogs module of the Qt GUI Toolkit. ** ** This file may be distributed under the terms of the Q Public License ** as defined by Trolltech AS of Norway and appearing in the file ** LICENSE.QPL included in the packaging of this file. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition ** licenses may use this file in accordance with the Qt Commercial License ** Agreement provided with the Software. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for ** information about Qt Commercial License Agreements. ** See http://www.trolltech.com/qpl/ for QPL licensing information. ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** **********************************************************************/ #include "qcolordialog.h" -#include "qpainter.h" -#include "qlayout.h" -#include "qlabel.h" -#include "qpushbutton.h" -#include "qlineedit.h" -#include "qimage.h" -#include "qpixmap.h" -#include "qdrawutil.h" -#include "qvalidator.h" -#include "qdragobject.h" -#include "qapplication.h" -#include "qdragobject.h" +#include <qpainter.h> +#include <qlayout.h> +#include <qpushbutton.h> +#include <qimage.h> +#include <qpixmap.h> +#include <qdrawutil.h> +#include <qdragobject.h> +#include <qapplication.h> +#include <qdragobject.h> //////////// QWellArray BEGIN -#include "qobjectdict.h" +#include <qobjectdict.h> // // W A R N I N G // ------------- // // This file is not part of the Qt API. It exists for the convenience // of qwellarray.cpp and qcolordialog.cpp. // This header file may change from version to version without notice, // or even be removed. // // - -#include "qtableview.h" - - -struct QWellArrayData; - -class QWellArray : public QTableView -{ - Q_OBJECT - Q_PROPERTY( int numCols READ numCols ) - Q_PROPERTY( int numRows READ numRows ) - Q_PROPERTY( int selectedColumn READ selectedColumn ) - Q_PROPERTY( int selectedRow READ selectedRow ) - -public: - QWellArray( QWidget *parent=0, const char *name=0, bool popup = FALSE ); - - ~QWellArray() {} - QString cellContent( int row, int col ) const; - // ### Paul !!! virtual void setCellContent( int row, int col, const QString &); - - // ##### Obsolete since not const - int numCols() { return nCols; } - int numRows() { return nRows; } - - int numCols() const { return nCols; } - int numRows() const { return nRows; } - - // ##### Obsolete since not const - int selectedColumn() { return selCol; } - int selectedRow() { return selRow; } - - int selectedColumn() const { return selCol; } - int selectedRow() const { return selRow; } - - virtual void setSelected( int row, int col ); - - void setCellSize( int w, int h ) { setCellWidth(w);setCellHeight( h ); } - - QSize sizeHint() const; - - virtual void setDimension( int rows, int cols ); - virtual void setCellBrush( int row, int col, const QBrush & ); - QBrush cellBrush( int row, int col ); - -signals: - void selected( int row, int col ); - -protected: - virtual void setCurrent( int row, int col ); - - virtual void drawContents( QPainter *, int row, int col, const QRect& ); - void drawContents( QPainter * ); - - void paintCell( QPainter*, int row, int col ); - void mousePressEvent( QMouseEvent* ); - void mouseReleaseEvent( QMouseEvent* ); - void mouseMoveEvent( QMouseEvent* ); - void keyPressEvent( QKeyEvent* ); - void focusInEvent( QFocusEvent* ); - void focusOutEvent( QFocusEvent* ); - -private: - int curRow; - int curCol; - int selRow; - int selCol; - int nCols; - int nRows; - bool smallStyle; - QWellArrayData *d; - -private: // Disabled copy constructor and operator= -#if defined(Q_DISABLE_COPY) - QWellArray( const QWellArray & ); - QWellArray& operator=( const QWellArray & ); -#endif -}; - - - -// non-interface ... - - - -struct QWellArrayData { - QBrush *brush; -}; - -// NOT REVISED -/* WARNING, NOT - \class QWellArray qwellarray_p.h - \brief .... - - .... - - \ingroup advanced -*/ - QWellArray::QWellArray( QWidget *parent, const char * name, bool popup ) : QTableView( parent, name, popup ? (WStyle_Customize|WStyle_Tool|WStyle_NoBorder) : 0 ) { d = 0; setFocusPolicy( StrongFocus ); setBackgroundMode( PaletteButton ); nCols = 7; nRows = 7; int w = 24; // cell width int h = 21; // cell height smallStyle = popup; if ( popup ) { w = h = 18; if ( style() == WindowsStyle ) setFrameStyle( QFrame::WinPanel | QFrame::Raised ); else setFrameStyle( QFrame::Panel | QFrame::Raised ); setMargin( 1 ); setLineWidth( 2 ); } setNumCols( nCols ); setNumRows( nRows ); setCellWidth( w ); setCellHeight( h ); curCol = 0; curRow = 0; selCol = -1; selRow = -1; if ( smallStyle ) setMouseTracking( TRUE ); setOffset( 5 , 10 ); resize( sizeHint() ); } QSize QWellArray::sizeHint() const { constPolish(); int f = frameWidth() * 2; int w = nCols * cellWidth() + f; int h = nRows * cellHeight() + f; return QSize( w, h ); } void QWellArray::paintCell( QPainter* p, int row, int col ) { int w = cellWidth( col ); // width of cell in pixels int h = cellHeight( row ); // height of cell in pixels int b = 1; if ( !smallStyle ) b = 3; const QColorGroup & g = colorGroup(); p->setPen( QPen( black, 0, SolidLine ) ); if ( !smallStyle && row ==selRow && col == selCol && style() != MotifStyle ) { int n = 2; @@ -505,318 +403,222 @@ static QRgb stdrgb[6*8]; static QRgb cusrgb[2*8]; static void initRGB() { if ( initrgb ) return; initrgb = TRUE; int i = 0; for ( int g = 0; g < 4; g++ ) for ( int r = 0; r < 4; r++ ) for ( int b = 0; b < 3; b++ ) stdrgb[i++] = qRgb( r*255/3, g*255/3, b*255/2 ); for ( i = 0; i < 2*8; i++ ) cusrgb[i] = qRgb(0xff,0xff,0xff); } /*! Returns the number of custom colors supported by QColorDialog. All color dialogs share the same custom colors. */ int QColorDialog::customCount() { return 2*8; } /*! Returns custom color number \a i as a QRgb. */ QRgb QColorDialog::customColor( int i ) { initRGB(); if ( i < 0 || i >= customCount() ) { #ifdef CHECK_RANGE qWarning( "QColorDialog::customColor() index %d out of range", i ); #endif i = 0; } return cusrgb[i]; } /*! Sets custom color number \a i to the QRgb value \a c. */ void QColorDialog::setCustomColor( int i, QRgb c ) { initRGB(); if ( i < 0 || i >= customCount() ) { #ifdef CHECK_RANGE qWarning( "QColorDialog::customColor() index %d out of range", i ); #endif return; } cusrgb[i] = c; } static inline void rgb2hsv( QRgb rgb, int&h, int&s, int&v ) { QColor c; c.setRgb( rgb ); c.getHsv(h,s,v); } -class QColorWell : public QWellArray -{ -public: - QColorWell( QWidget *parent, int r, int c, QRgb *vals ) - :QWellArray( parent, "" ), values( vals ), mousePressed( FALSE ), oldCurrent( -1, -1 ) - { setDimension(r,c); setWFlags( WResizeNoErase ); } - QSizePolicy sizePolicy() const; - -protected: - void drawContents( QPainter *, int row, int col, const QRect& ); - void drawContents( QPainter *p ) { QWellArray::drawContents(p); } - void mousePressEvent( QMouseEvent *e ); - void mouseMoveEvent( QMouseEvent *e ); - void mouseReleaseEvent( QMouseEvent *e ); -#ifndef QT_NO_DRAGANDDROP - void dragEnterEvent( QDragEnterEvent *e ); - void dragLeaveEvent( QDragLeaveEvent *e ); - void dragMoveEvent( QDragMoveEvent *e ); - void dropEvent( QDropEvent *e ); -#endif - -private: - QRgb *values; - bool mousePressed; - QPoint pressPos; - QPoint oldCurrent; - -}; - QSizePolicy QColorWell::sizePolicy() const { return QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum ); } void QColorWell::drawContents( QPainter *p, int row, int col, const QRect &r ) { int i = row + col*numRows(); p->fillRect( r, QColor( values[i] ) ); } void QColorWell::mousePressEvent( QMouseEvent *e ) { oldCurrent = QPoint( selectedRow(), selectedColumn() ); QWellArray::mousePressEvent( e ); mousePressed = TRUE; pressPos = e->pos(); } void QColorWell::mouseMoveEvent( QMouseEvent *e ) { QWellArray::mouseMoveEvent( e ); #ifndef QT_NO_DRAGANDDROP if ( !mousePressed ) return; if ( ( pressPos - e->pos() ).manhattanLength() > QApplication::startDragDistance() ) { setCurrent( oldCurrent.x(), oldCurrent.y() ); int i = findRow( e->y() ) + findCol( e->x() ) * numRows(); QColor col( values[ i ] ); QColorDrag *drg = new QColorDrag( col, this ); QPixmap pix( cellWidth(), cellHeight() ); pix.fill( col ); QPainter p( &pix ); p.drawRect( 0, 0, pix.width(), pix.height() ); p.end(); drg->setPixmap( pix ); mousePressed = FALSE; drg->dragCopy(); } #endif } #ifndef QT_NO_DRAGANDDROP void QColorWell::dragEnterEvent( QDragEnterEvent *e ) { setFocus(); if ( QColorDrag::canDecode( e ) ) e->accept(); else e->ignore(); } void QColorWell::dragLeaveEvent( QDragLeaveEvent * ) { if ( hasFocus() ) parentWidget()->setFocus(); } void QColorWell::dragMoveEvent( QDragMoveEvent *e ) { if ( QColorDrag::canDecode( e ) ) { setCurrent( findRow( e->pos().y() ), findCol( e->pos().x() ) ); e->accept(); } else e->ignore(); } void QColorWell::dropEvent( QDropEvent *e ) { if ( QColorDrag::canDecode( e ) ) { int i = findRow( e->pos().y() ) + findCol( e->pos().x() ) * numRows(); QColor col; QColorDrag::decode( e, col ); values[ i ] = col.rgb(); repaint( FALSE ); e->accept(); } else { e->ignore(); } } #endif // QT_NO_DRAGANDDROP void QColorWell::mouseReleaseEvent( QMouseEvent *e ) { if ( !mousePressed ) return; QWellArray::mouseReleaseEvent( e ); mousePressed = FALSE; } -class QColorPicker : public QFrame -{ - Q_OBJECT -public: - QColorPicker(QWidget* parent=0, const char* name=0); - ~QColorPicker(); - -public slots: - void setCol( int h, int s ); - -signals: - void newCol( int h, int s ); - -protected: - QSize sizeHint() const; - QSizePolicy sizePolicy() const; - void drawContents(QPainter* p); - void mouseMoveEvent( QMouseEvent * ); - void mousePressEvent( QMouseEvent * ); - -private: - int hue; - int sat; - - QPoint colPt(); - int huePt( const QPoint &pt ); - int satPt( const QPoint &pt ); - void setCol( const QPoint &pt ); - - QPixmap *pix; -}; - static int pWidth = 200; static int pHeight = 200; -class QColorLuminancePicker : public QWidget -{ - Q_OBJECT -public: - QColorLuminancePicker(QWidget* parent=0, const char* name=0); - ~QColorLuminancePicker(); - -public slots: - void setCol( int h, int s, int v ); - void setCol( int h, int s ); - -signals: - void newHsv( int h, int s, int v ); - -protected: -// QSize sizeHint() const; -// QSizePolicy sizePolicy() const; - void paintEvent( QPaintEvent*); - void mouseMoveEvent( QMouseEvent * ); - void mousePressEvent( QMouseEvent * ); - -private: - enum { foff = 3, coff = 4 }; //frame and contents offset - int val; - int hue; - int sat; - - int y2val( int y ); - int val2y( int val ); - void setVal( int v ); - - QPixmap *pix; -}; - - int QColorLuminancePicker::y2val( int y ) { int d = height() - 2*coff - 1; return 255 - (y - coff)*255/d; } int QColorLuminancePicker::val2y( int v ) { int d = height() - 2*coff - 1; return coff + (255-v)*d/255; } QColorLuminancePicker::QColorLuminancePicker(QWidget* parent, const char* name) :QWidget( parent, name ) { hue = 100; val = 100; sat = 100; pix = 0; // setBackgroundMode( NoBackground ); } QColorLuminancePicker::~QColorLuminancePicker() { delete pix; } void QColorLuminancePicker::mouseMoveEvent( QMouseEvent *m ) { setVal( y2val(m->y()) ); } void QColorLuminancePicker::mousePressEvent( QMouseEvent *m ) { setVal( y2val(m->y()) ); } void QColorLuminancePicker::setVal( int v ) { if ( val == v ) return; val = QMAX( 0, QMIN(v,255)); delete pix; pix=0; repaint( FALSE ); //### emit newHsv( hue, sat, val ); } //receives from a hue,sat chooser and relays. void QColorLuminancePicker::setCol( int h, int s ) { setCol( h, s, val ); emit newHsv( h, s, val ); } void QColorLuminancePicker::paintEvent( QPaintEvent * ) { int w = width() - 5; QRect r( 0, foff, w, height() - 2*foff ); int wi = r.width() - 2; int hi = r.height() - 2; if ( !pix || pix->height() != hi || pix->width() != wi ) { delete pix; QImage img( wi, hi, 32 ); int y; for ( y = 0; y < hi; y++ ) { @@ -874,256 +676,146 @@ QColorPicker::QColorPicker(QWidget* parent, const char* name ) img.setPixel( x, y, QColor(huePt(p), satPt(p), 200, QColor::Hsv).rgb() ); } pix = new QPixmap; pix->convertFromImage(img); setBackgroundMode( NoBackground ); } QColorPicker::~QColorPicker() { delete pix; } QSize QColorPicker::sizeHint() const { return QSize( pWidth + 2*frameWidth(), pHeight + 2*frameWidth() ); } QSizePolicy QColorPicker::sizePolicy() const { return QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ); } void QColorPicker::setCol( int h, int s ) { int nhue = QMIN( QMAX(0,h), 360 ); int nsat = QMIN( QMAX(0,s), 255); if ( nhue == hue && nsat == sat ) return; QRect r( colPt(), QSize(20,20) ); hue = nhue; sat = nsat; r = r.unite( QRect( colPt(), QSize(20,20) ) ); r.moveBy( contentsRect().x()-9, contentsRect().y()-9 ); // update( r ); repaint( r, FALSE ); } void QColorPicker::mouseMoveEvent( QMouseEvent *m ) { QPoint p = m->pos() - contentsRect().topLeft(); setCol( p ); emit newCol( hue, sat ); } void QColorPicker::mousePressEvent( QMouseEvent *m ) { QPoint p = m->pos() - contentsRect().topLeft(); setCol( p ); emit newCol( hue, sat ); } void QColorPicker::drawContents(QPainter* p) { QRect r = contentsRect(); p->drawPixmap( r.topLeft(), *pix ); QPoint pt = colPt() + r.topLeft(); p->setPen( QPen(black) ); p->fillRect( pt.x()-9, pt.y(), 20, 2, black ); p->fillRect( pt.x(), pt.y()-9, 2, 20, black ); } -class QColorShowLabel; - - - -class QColIntValidator: public QIntValidator -{ -public: - QColIntValidator( int bottom, int top, - QWidget * parent, const char *name = 0 ) - :QIntValidator( bottom, top, parent, name ) {} - - QValidator::State validate( QString &, int & ) const; -}; - QValidator::State QColIntValidator::validate( QString &s, int &pos ) const { State state = QIntValidator::validate(s,pos); if ( state == Valid ) { long int val = s.toLong(); // This is not a general solution, assumes that top() > 0 and // bottom >= 0 if ( val < 0 ) { s = "0"; pos = 1; } else if ( val > top() ) { s.setNum( top() ); pos = s.length(); } } return state; } - - -class QColNumLineEdit : public QLineEdit -{ -public: - QColNumLineEdit( QWidget *parent, const char* name = 0 ) - : QLineEdit( parent, name ) { setMaxLength( 3 );} - QSize sizeHint() const { - return QSize( 30, //##### - QLineEdit::sizeHint().height() ); } - void setNum( int i ) { - QString s; - s.setNum(i); - bool block = signalsBlocked(); - blockSignals(TRUE); - setText( s ); - blockSignals(block); - } - int val() const { return text().toInt(); } -}; - - -class QColorShower : public QWidget -{ - Q_OBJECT -public: - QColorShower( QWidget *parent, const char *name = 0 ); - - //things that don't emit signals - void setHsv( int h, int s, int v ); - - int currentAlpha() const { return alphaEd->val(); } - void setCurrentAlpha( int a ) { alphaEd->setNum( a ); } - void showAlpha( bool b ); - - - QRgb currentColor() const { return curCol; } - -public slots: - void setRgb( QRgb rgb ); - -signals: - void newCol( QRgb rgb ); -private slots: - void rgbEd(); - void hsvEd(); -private: - void showCurrentColor(); - int hue, sat, val; - QRgb curCol; - QColNumLineEdit *hEd; - QColNumLineEdit *sEd; - QColNumLineEdit *vEd; - QColNumLineEdit *rEd; - QColNumLineEdit *gEd; - QColNumLineEdit *bEd; - QColNumLineEdit *alphaEd; - QLabel *alphaLab; - QColorShowLabel *lab; - bool rgbOriginal; -}; - -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 ); -#ifndef QT_NO_DRAGANDDROP - void dragEnterEvent( QDragEnterEvent *e ); - void dragLeaveEvent( QDragLeaveEvent *e ); - void dropEvent( QDropEvent *e ); -#endif - -private: - QColor col; - bool mousePressed; - QPoint pressPos; - -}; - void QColorShowLabel::drawContents( QPainter *p ) { p->fillRect( contentsRect(), col ); } void QColorShower::showAlpha( bool b ) { if ( b ) { alphaLab->show(); alphaEd->show(); } else { alphaLab->hide(); alphaEd->hide(); } } void QColorShowLabel::mousePressEvent( QMouseEvent *e ) { mousePressed = TRUE; pressPos = e->pos(); } void QColorShowLabel::mouseMoveEvent( QMouseEvent *e ) { #ifndef QT_NO_DRAGANDDROP 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(); } #endif } #ifndef QT_NO_DRAGANDDROP void QColorShowLabel::dragEnterEvent( QDragEnterEvent *e ) { if ( QColorDrag::canDecode( e ) ) e->accept(); else e->ignore(); } void QColorShowLabel::dragLeaveEvent( QDragLeaveEvent * ) { } void QColorShowLabel::dropEvent( QDropEvent *e ) { if ( QColorDrag::canDecode( e ) ) { QColorDrag::decode( e, col ); repaint( FALSE ); emit colorDropped( col.rgb() ); e->accept(); } else { e->ignore(); } @@ -1225,157 +917,128 @@ void QColorShower::rgbEd() curCol = qRgb( rEd->val(), gEd->val(), bEd->val() ); rgb2hsv(currentColor(), hue, sat, val ); hEd->setNum( hue ); sEd->setNum( sat ); vEd->setNum( val ); showCurrentColor(); emit newCol( currentColor() ); } void QColorShower::hsvEd() { rgbOriginal = FALSE; hue = hEd->val(); sat = sEd->val(); val = vEd->val(); curCol = QColor( hue, sat, val, QColor::Hsv ).rgb(); rEd->setNum( qRed(currentColor()) ); gEd->setNum( qGreen(currentColor()) ); bEd->setNum( qBlue(currentColor()) ); showCurrentColor(); emit newCol( currentColor() ); } void QColorShower::setRgb( QRgb rgb ) { rgbOriginal = TRUE; curCol = rgb; rgb2hsv( currentColor(), hue, sat, val ); hEd->setNum( hue ); sEd->setNum( sat ); vEd->setNum( val ); rEd->setNum( qRed(currentColor()) ); gEd->setNum( qGreen(currentColor()) ); bEd->setNum( qBlue(currentColor()) ); showCurrentColor(); } void QColorShower::setHsv( int h, int s, int v ) { rgbOriginal = FALSE; hue = h; val = v; sat = s; //Range check### curCol = QColor( hue, sat, val, QColor::Hsv ).rgb(); hEd->setNum( hue ); sEd->setNum( sat ); vEd->setNum( val ); rEd->setNum( qRed(currentColor()) ); gEd->setNum( qGreen(currentColor()) ); bEd->setNum( qBlue(currentColor()) ); showCurrentColor(); } -class QColorDialogPrivate : public QObject -{ -Q_OBJECT -public: - QColorDialogPrivate( QColorDialog *p ); - QRgb currentColor() const { return cs->currentColor(); } - void setCurrentColor( QRgb rgb ); - - int currentAlpha() const { return cs->currentAlpha(); } - void setCurrentAlpha( int a ) { cs->setCurrentAlpha( a ); } - void showAlpha( bool b ) { cs->showAlpha( b ); } - -private slots: - void addCustom(); - - void newHsv( int h, int s, int v ); - void newColorTypedIn( QRgb rgb ); - void newCustom( int, int ); - void newStandard( int, int ); -private: - QColorPicker *cp; - QColorLuminancePicker *lp; - QWellArray *custom; - QWellArray *standard; - QColorShower *cs; - int nextCust; - bool compact; -}; - //sets all widgets to display h,s,v void QColorDialogPrivate::newHsv( int h, int s, int v ) { cs->setHsv( h, s, v ); cp->setCol( h, s ); lp->setCol( h, s, v ); } //sets all widgets to display rgb void QColorDialogPrivate::setCurrentColor( QRgb rgb ) { cs->setRgb( rgb ); newColorTypedIn( rgb ); } //sets all widgets exept cs to display rgb void QColorDialogPrivate::newColorTypedIn( QRgb rgb ) { int h, s, v; rgb2hsv(rgb, h, s, v ); cp->setCol( h, s ); lp->setCol( h, s, v); } void QColorDialogPrivate::newCustom( int r, int c ) { int i = r+2*c; setCurrentColor( cusrgb[i] ); nextCust = i; standard->setSelected(-1,-1); } void QColorDialogPrivate::newStandard( int r, int c ) { setCurrentColor( stdrgb[r+c*6] ); custom->setSelected(-1,-1); } QColorDialogPrivate::QColorDialogPrivate( QColorDialog *dialog ) : QObject(dialog) { compact = FALSE; // small displays (e.g. PDAs cannot fit the full color dialog, // so just use the color picker. if ( qApp->desktop()->width() < 480 || qApp->desktop()->height() < 350 ) compact = TRUE; nextCust = 0; const int lumSpace = 3; int border = 12; if ( compact ) border = 6; QHBoxLayout *topLay = new QHBoxLayout( dialog, border, 6 ); QVBoxLayout *leftLay = 0; if ( !compact ) leftLay = new QVBoxLayout( topLay ); initRGB(); if ( !compact ) { standard = new QColorWell( dialog, 6, 8, stdrgb ); standard->setCellSize( 28, 24 ); QLabel * lab = new QLabel( standard, diff --git a/libqtaux/qcolordialog.h b/libqtaux/qcolordialog.h index 89c6283..50c6482 100644 --- a/libqtaux/qcolordialog.h +++ b/libqtaux/qcolordialog.h @@ -1,84 +1,395 @@ /**************************************************************************** ** $Id$ ** ** Definition of QColorDialog class ** ** Created : 990222 ** ** Copyright (C) 1992-2000 Trolltech AS. All rights reserved. ** ** This file is part of the dialogs module of the Qt GUI Toolkit. ** ** This file may be distributed under the terms of the Q Public License ** as defined by Trolltech AS of Norway and appearing in the file ** LICENSE.QPL included in the packaging of this file. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition ** licenses may use this file in accordance with the Qt Commercial License ** Agreement provided with the Software. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for ** information about Qt Commercial License Agreements. ** See http://www.trolltech.com/qpl/ for QPL licensing information. ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** **********************************************************************/ #ifndef QCOLORDIALOG_H #define QCOLORDIALOG_H #ifndef QT_H #include <qdialog.h> #endif // QT_H +#include <qlabel.h> +#include <qlineedit.h> +#include <qtableview.h> +#include <qvalidator.h> + +struct QWellArrayData; + +class QWellArray : public QTableView +{ + Q_OBJECT +// Q_PROPERTY( int numCols READ numCols ) +// Q_PROPERTY( int numRows READ numRows ) +// Q_PROPERTY( int selectedColumn READ selectedColumn ) +// Q_PROPERTY( int selectedRow READ selectedRow ) + +public: + QWellArray( QWidget *parent=0, const char *name=0, bool popup = FALSE ); + + ~QWellArray() {} + QString cellContent( int row, int col ) const; + // ### Paul !!! virtual void setCellContent( int row, int col, const QString &); + + // ##### Obsolete since not const + int numCols() { return nCols; } + int numRows() { return nRows; } + + int numCols() const { return nCols; } + int numRows() const { return nRows; } + + // ##### Obsolete since not const + int selectedColumn() { return selCol; } + int selectedRow() { return selRow; } + + int selectedColumn() const { return selCol; } + int selectedRow() const { return selRow; } + + virtual void setSelected( int row, int col ); + + void setCellSize( int w, int h ) { setCellWidth(w);setCellHeight( h ); } + + QSize sizeHint() const; + + virtual void setDimension( int rows, int cols ); + virtual void setCellBrush( int row, int col, const QBrush & ); + QBrush cellBrush( int row, int col ); + +signals: + void selected( int row, int col ); + +protected: + virtual void setCurrent( int row, int col ); + + virtual void drawContents( QPainter *, int row, int col, const QRect& ); + void drawContents( QPainter * ); + + void paintCell( QPainter*, int row, int col ); + void mousePressEvent( QMouseEvent* ); + void mouseReleaseEvent( QMouseEvent* ); + void mouseMoveEvent( QMouseEvent* ); + void keyPressEvent( QKeyEvent* ); + void focusInEvent( QFocusEvent* ); + void focusOutEvent( QFocusEvent* ); + +private: + int curRow; + int curCol; + int selRow; + int selCol; + int nCols; + int nRows; + bool smallStyle; + QWellArrayData *d; + +private: // Disabled copy constructor and operator= +#if defined(Q_DISABLE_COPY) + QWellArray( const QWellArray & ); + QWellArray& operator=( const QWellArray & ); +#endif +}; + +struct QWellArrayData { + QBrush *brush; +}; + +class QColNumLineEdit : public QLineEdit +{ +public: + QColNumLineEdit( QWidget *parent, const char* name = 0 ) + : QLineEdit( parent, name ) { setMaxLength( 3 );} + QSize sizeHint() const { + return QSize( 30, //##### + QLineEdit::sizeHint().height() ); } + void setNum( int i ) { + QString s; + s.setNum(i); + bool block = signalsBlocked(); + blockSignals(TRUE); + setText( s ); + blockSignals(block); + } + int val() const { return text().toInt(); } +}; + +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 ); +#ifndef QT_NO_DRAGANDDROP + void dragEnterEvent( QDragEnterEvent *e ); + void dragLeaveEvent( QDragLeaveEvent *e ); + void dropEvent( QDropEvent *e ); +#endif + +private: + QColor col; + bool mousePressed; + QPoint pressPos; + +}; + +class QColorShower : public QWidget +{ + Q_OBJECT +public: + QColorShower( QWidget *parent, const char *name = 0 ); + + //things that don't emit signals + void setHsv( int h, int s, int v ); + + int currentAlpha() const { return alphaEd->val(); } + void setCurrentAlpha( int a ) { alphaEd->setNum( a ); } + void showAlpha( bool b ); + + + QRgb currentColor() const { return curCol; } + +public slots: + void setRgb( QRgb rgb ); + +signals: + void newCol( QRgb rgb ); +private slots: + void rgbEd(); + void hsvEd(); +private: + void showCurrentColor(); + int hue, sat, val; + QRgb curCol; + QColNumLineEdit *hEd; + QColNumLineEdit *sEd; + QColNumLineEdit *vEd; + QColNumLineEdit *rEd; + QColNumLineEdit *gEd; + QColNumLineEdit *bEd; + QColNumLineEdit *alphaEd; + QLabel *alphaLab; + QColorShowLabel *lab; + bool rgbOriginal; +}; + +class QColorPicker : public QFrame +{ + Q_OBJECT +public: + QColorPicker(QWidget* parent=0, const char* name=0); + ~QColorPicker(); + +public slots: + void setCol( int h, int s ); + +signals: + void newCol( int h, int s ); + +protected: + QSize sizeHint() const; + QSizePolicy sizePolicy() const; + void drawContents(QPainter* p); + void mouseMoveEvent( QMouseEvent * ); + void mousePressEvent( QMouseEvent * ); + +private: + int hue; + int sat; + + QPoint colPt(); + int huePt( const QPoint &pt ); + int satPt( const QPoint &pt ); + void setCol( const QPoint &pt ); + + QPixmap *pix; +}; + +class QColorLuminancePicker : public QWidget +{ + Q_OBJECT +public: + QColorLuminancePicker(QWidget* parent=0, const char* name=0); + ~QColorLuminancePicker(); + +public slots: + void setCol( int h, int s, int v ); + void setCol( int h, int s ); + +signals: + void newHsv( int h, int s, int v ); + +protected: +// QSize sizeHint() const; +// QSizePolicy sizePolicy() const; + void paintEvent( QPaintEvent*); + void mouseMoveEvent( QMouseEvent * ); + void mousePressEvent( QMouseEvent * ); + +private: + enum { foff = 3, coff = 4 }; //frame and contents offset + int val; + int hue; + int sat; + + int y2val( int y ); + int val2y( int val ); + void setVal( int v ); + + QPixmap *pix; +}; + +class QColorWell : public QWellArray +{ +public: + QColorWell( QWidget *parent, int r, int c, QRgb *vals ) + :QWellArray( parent, "" ), values( vals ), mousePressed( FALSE ), oldCurrent( -1, -1 ) + { setDimension(r,c); setWFlags( WResizeNoErase ); } + QSizePolicy sizePolicy() const; + +protected: + void drawContents( QPainter *, int row, int col, const QRect& ); + void drawContents( QPainter *p ) { QWellArray::drawContents(p); } + void mousePressEvent( QMouseEvent *e ); + void mouseMoveEvent( QMouseEvent *e ); + void mouseReleaseEvent( QMouseEvent *e ); +#ifndef QT_NO_DRAGANDDROP + void dragEnterEvent( QDragEnterEvent *e ); + void dragLeaveEvent( QDragLeaveEvent *e ); + void dragMoveEvent( QDragMoveEvent *e ); + void dropEvent( QDropEvent *e ); +#endif + +private: + QRgb *values; + bool mousePressed; + QPoint pressPos; + QPoint oldCurrent; + +}; + +class QColIntValidator: public QIntValidator +{ +public: + QColIntValidator( int bottom, int top, + QWidget * parent, const char *name = 0 ) + :QIntValidator( bottom, top, parent, name ) {} + + QValidator::State validate( QString &, int & ) const; +}; + class QColorDialogPrivate; class Q_EXPORT QColorDialog : public QDialog { Q_OBJECT public: static QColor getColor( QColor, QWidget *parent=0, const char* name=0 ); // ### 3.0: make const QColor& static QRgb getRgba( QRgb, bool* ok = 0, QWidget *parent=0, const char* name=0 ); static int customCount(); static QRgb customColor( int ); static void setCustomColor( int, QRgb ); private: ~QColorDialog(); QColorDialog( QWidget* parent=0, const char* name=0, bool modal=FALSE ); void setColor( QColor ); // ### 3.0: make const QColor& QColor color() const; private: void setSelectedAlpha( int ); int selectedAlpha() const; void showCustom( bool=TRUE ); private: QColorDialogPrivate *d; friend class QColorDialogPrivate; private: // Disabled copy constructor and operator= #if defined(Q_DISABLE_COPY) QColorDialog( const QColorDialog & ); QColorDialog& operator=( const QColorDialog & ); #endif }; +class QColorDialogPrivate : public QObject +{ +Q_OBJECT +public: + QColorDialogPrivate( QColorDialog *p ); + QRgb currentColor() const { return cs->currentColor(); } + void setCurrentColor( QRgb rgb ); + + int currentAlpha() const { return cs->currentAlpha(); } + void setCurrentAlpha( int a ) { cs->setCurrentAlpha( a ); } + void showAlpha( bool b ) { cs->showAlpha( b ); } + +private slots: + void addCustom(); + + void newHsv( int h, int s, int v ); + void newColorTypedIn( QRgb rgb ); + void newCustom( int, int ); + void newStandard( int, int ); +private: + QColorPicker *cp; + QColorLuminancePicker *lp; + QWellArray *custom; + QWellArray *standard; + QColorShower *cs; + int nextCust; + bool compact; +}; + #endif |