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 | 837 | ||||
-rw-r--r-- | libqtaux/qcolordialog.h | 315 |
2 files changed, 563 insertions, 589 deletions
diff --git a/libqtaux/qcolordialog.cpp b/libqtaux/qcolordialog.cpp index 5881a89..1574841 100644 --- a/libqtaux/qcolordialog.cpp +++ b/libqtaux/qcolordialog.cpp @@ -39,14 +39,11 @@ -#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> @@ -54,3 +51,3 @@ -#include "qobjectdict.h" +#include <qobjectdict.h> @@ -67,104 +64,5 @@ - -#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 ) + popup ? (WStyle_Customize|WStyle_Tool|WStyle_NoBorder) : 0 ) { @@ -175,4 +73,4 @@ QWellArray::QWellArray( QWidget *parent, const char * name, bool popup ) nRows = 7; - int w = 24; // cell width - int h = 21; // cell height + int w = 24; // cell width + int h = 21; // cell height smallStyle = popup; @@ -180,9 +78,9 @@ QWellArray::QWellArray( QWidget *parent, const char * name, bool popup ) if ( popup ) { - w = h = 18; - if ( style() == WindowsStyle ) - setFrameStyle( QFrame::WinPanel | QFrame::Raised ); - else - setFrameStyle( QFrame::Panel | QFrame::Raised ); - setMargin( 1 ); - setLineWidth( 2 ); + w = h = 18; + if ( style() == WindowsStyle ) + setFrameStyle( QFrame::WinPanel | QFrame::Raised ); + else + setFrameStyle( QFrame::Panel | QFrame::Raised ); + setMargin( 1 ); + setLineWidth( 2 ); } @@ -198,3 +96,3 @@ QWellArray::QWellArray( QWidget *parent, const char * name, bool popup ) if ( smallStyle ) - setMouseTracking( TRUE ); + setMouseTracking( TRUE ); setOffset( 5 , 10 ); @@ -218,4 +116,4 @@ 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 w = cellWidth( col ); // width of cell in pixels + int h = cellHeight( row ); // height of cell in pixels int b = 1; @@ -223,3 +121,3 @@ void QWellArray::paintCell( QPainter* p, int row, int col ) if ( !smallStyle ) - b = 3; + b = 3; @@ -228,5 +126,5 @@ void QWellArray::paintCell( QPainter* p, int row, int col ) if ( !smallStyle && row ==selRow && col == selCol && - style() != MotifStyle ) { - int n = 2; - p->drawRect( n, n, w-2*n, h-2*n ); + style() != MotifStyle ) { + int n = 2; + p->drawRect( n, n, w-2*n, h-2*n ); } @@ -235,17 +133,17 @@ void QWellArray::paintCell( QPainter* p, int row, int col ) if ( style() == WindowsStyle ) { - qDrawWinPanel( p, b, b , w - 2*b, h - 2*b, - g, TRUE ); - b += 2; + qDrawWinPanel( p, b, b , w - 2*b, h - 2*b, + g, TRUE ); + b += 2; } else { - if ( smallStyle ) { - qDrawShadePanel( p, b, b , w - 2*b, h - 2*b, - g, TRUE, 2 ); - b += 2; - } else { - int t = ( row == selRow && col == selCol ) ? 2 : 0; - b -= t; - qDrawShadePanel( p, b, b , w - 2*b, h - 2*b, - g, TRUE, 2 ); - b += 2 + t; - } + if ( smallStyle ) { + qDrawShadePanel( p, b, b , w - 2*b, h - 2*b, + g, TRUE, 2 ); + b += 2; + } else { + int t = ( row == selRow && col == selCol ) ? 2 : 0; + b -= t; + qDrawShadePanel( p, b, b , w - 2*b, h - 2*b, + g, TRUE, 2 ); + b += 2 + t; + } } @@ -254,12 +152,12 @@ void QWellArray::paintCell( QPainter* p, int row, int col ) if ( (row == curRow) && (col == curCol) ) { - if ( smallStyle ) { - p->setPen ( white ); - p->drawRect( 1, 1, w-2, h-2 ); - p->setPen ( black ); - p->drawRect( 0, 0, w, h ); - p->drawRect( 2, 2, w-4, h-4 ); - b = 3; - } else if ( hasFocus() ) { - style().drawFocusRect(p, QRect(0,0,w,h), g ); - } + if ( smallStyle ) { + p->setPen ( white ); + p->drawRect( 1, 1, w-2, h-2 ); + p->setPen ( black ); + p->drawRect( 0, 0, w, h ); + p->drawRect( 2, 2, w-4, h-4 ); + b = 3; + } else if ( hasFocus() ) { + style().drawFocusRect(p, QRect(0,0,w,h), g ); + } } @@ -283,8 +181,8 @@ void QWellArray::drawContents( QPainter *p, int row, int col, const QRect &r ) if ( d ) { - p->fillRect( r, d->brush[row*nCols+col] ); + p->fillRect( r, d->brush[row*nCols+col] ); } else { - p->fillRect( r, white ); - p->setPen( black ); - p->drawLine( r.topLeft(), r.bottomRight() ); - p->drawLine( r.topRight(), r.bottomLeft() ); + p->fillRect( r, white ); + p->setPen( black ); + p->drawLine( r.topLeft(), r.bottomRight() ); + p->drawLine( r.topRight(), r.bottomLeft() ); } @@ -320,4 +218,4 @@ void QWellArray::mouseMoveEvent( QMouseEvent* e ) if ( smallStyle ) { - QPoint pos = e->pos(); - setCurrent( findRow( pos.y() ), findCol( pos.x() ) ); + QPoint pos = e->pos(); + setCurrent( findRow( pos.y() ), findCol( pos.x() ) ); } @@ -334,6 +232,6 @@ void QWellArray::setCurrent( int row, int col ) if ( (curRow == row) && (curCol == col) ) - return; + return; if ( row < 0 || col < 0 ) - row = col = -1; + row = col = -1; @@ -360,3 +258,3 @@ void QWellArray::setSelected( int row, int col ) if ( (selRow == row) && (selCol == col) ) - return; + return; @@ -366,3 +264,3 @@ void QWellArray::setSelected( int row, int col ) if ( row < 0 || col < 0 ) - row = col = -1; + row = col = -1; @@ -374,6 +272,6 @@ void QWellArray::setSelected( int row, int col ) if ( row >= 0 ) - emit selected( row, col ); + emit selected( row, col ); if ( isVisible() && parentWidget() && parentWidget()->inherits("QPopupMenu") ) - parentWidget()->close(); + parentWidget()->close(); @@ -402,6 +300,6 @@ void QWellArray::setDimension( int rows, int cols ) if ( d ) { - if ( d->brush ) - delete[] d->brush; - delete d; - d = 0; + if ( d->brush ) + delete[] d->brush; + delete d; + d = 0; } @@ -414,10 +312,10 @@ void QWellArray::setCellBrush( int row, int col, const QBrush &b ) if ( !d ) { - d = new QWellArrayData; - d->brush = new QBrush[nRows*nCols]; + d = new QWellArrayData; + d->brush = new QBrush[nRows*nCols]; } if ( row >= 0 && row < nRows && col >= 0 && col < nCols ) - d->brush[row*nCols+col] = b; + d->brush[row*nCols+col] = b; #ifdef CHECK_RANGE else - qWarning( "QWellArray::setCellBrush( %d, %d ) out of range", row, col ); + qWarning( "QWellArray::setCellBrush( %d, %d ) out of range", row, col ); #endif @@ -435,3 +333,3 @@ QBrush QWellArray::cellBrush( int row, int col ) if ( d && row >= 0 && row < nRows && col >= 0 && col < nCols ) - return d->brush[row*nCols+col]; + return d->brush[row*nCols+col]; return NoBrush; @@ -453,37 +351,37 @@ void QWellArray::keyPressEvent( QKeyEvent* e ) { - switch( e->key() ) { // Look at the key code - case Key_Left: // If 'left arrow'-key, - if( curCol > 0 ) { // and cr't not in leftmost col - setCurrent( curRow, curCol - 1); // set cr't to next left column - int edge = leftCell(); // find left edge - if ( curCol < edge ) // if we have moved off edge, - setLeftCell( edge - 1 ); // scroll view to rectify - } - break; - case Key_Right: // Correspondingly... - if( curCol < numCols()-1 ) { - setCurrent( curRow, curCol + 1); - int edge = lastColVisible(); - if ( curCol >= edge ) - setLeftCell( leftCell() + 1 ); - } - break; + switch( e->key() ) { // Look at the key code + case Key_Left: // If 'left arrow'-key, + if( curCol > 0 ) { // and cr't not in leftmost col + setCurrent( curRow, curCol - 1); // set cr't to next left column + int edge = leftCell(); // find left edge + if ( curCol < edge ) // if we have moved off edge, + setLeftCell( edge - 1 ); // scroll view to rectify + } + break; + case Key_Right: // Correspondingly... + if( curCol < numCols()-1 ) { + setCurrent( curRow, curCol + 1); + int edge = lastColVisible(); + if ( curCol >= edge ) + setLeftCell( leftCell() + 1 ); + } + break; case Key_Up: - if( curRow > 0 ) { - setCurrent( curRow - 1, curCol); - int edge = topCell(); - if ( curRow < edge ) - setTopCell( edge - 1 ); - } else if ( smallStyle ) - focusNextPrevChild( FALSE ); - break; + if( curRow > 0 ) { + setCurrent( curRow - 1, curCol); + int edge = topCell(); + if ( curRow < edge ) + setTopCell( edge - 1 ); + } else if ( smallStyle ) + focusNextPrevChild( FALSE ); + break; case Key_Down: - if( curRow < numRows()-1 ) { - setCurrent( curRow + 1, curCol); - int edge = lastRowVisible(); - if ( curRow >= edge ) - setTopCell( topCell() + 1 ); - } else if ( smallStyle ) - focusNextPrevChild( TRUE ); - break; + if( curRow < numRows()-1 ) { + setCurrent( curRow + 1, curCol); + int edge = lastRowVisible(); + if ( curRow >= edge ) + setTopCell( topCell() + 1 ); + } else if ( smallStyle ) + focusNextPrevChild( TRUE ); + break; case Key_Space: @@ -491,7 +389,7 @@ void QWellArray::keyPressEvent( QKeyEvent* e ) case Key_Enter: - setSelected( curRow, curCol ); - break; - default: // If not an interesting key, - e->ignore(); // we don't accept the event - return; + setSelected( curRow, curCol ); + break; + default: // If not an interesting key, + e->ignore(); // we don't accept the event + return; } @@ -510,3 +408,3 @@ static void initRGB() if ( initrgb ) - return; + return; initrgb = TRUE; @@ -514,8 +412,8 @@ static void initRGB() 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 ( 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); + cusrgb[i] = qRgb(0xff,0xff,0xff); } @@ -539,5 +437,5 @@ QRgb QColorDialog::customColor( int i ) #ifdef CHECK_RANGE - qWarning( "QColorDialog::customColor() index %d out of range", i ); -#endif - i = 0; + qWarning( "QColorDialog::customColor() index %d out of range", i ); +#endif + i = 0; } @@ -554,5 +452,5 @@ void QColorDialog::setCustomColor( int i, QRgb c ) #ifdef CHECK_RANGE - qWarning( "QColorDialog::customColor() index %d out of range", i ); -#endif - return; + qWarning( "QColorDialog::customColor() index %d out of range", i ); +#endif + return; } @@ -568,31 +466,2 @@ static inline void rgb2hsv( QRgb rgb, int&h, int&s, int&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 @@ -621,16 +490,16 @@ void QColorWell::mouseMoveEvent( QMouseEvent *e ) if ( !mousePressed ) - return; + 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(); + 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(); } @@ -644,5 +513,5 @@ void QColorWell::dragEnterEvent( QDragEnterEvent *e ) if ( QColorDrag::canDecode( e ) ) - e->accept(); + e->accept(); else - e->ignore(); + e->ignore(); } @@ -652,3 +521,3 @@ void QColorWell::dragLeaveEvent( QDragLeaveEvent * ) if ( hasFocus() ) - parentWidget()->setFocus(); + parentWidget()->setFocus(); } @@ -658,6 +527,6 @@ void QColorWell::dragMoveEvent( QDragMoveEvent *e ) if ( QColorDrag::canDecode( e ) ) { - setCurrent( findRow( e->pos().y() ), findCol( e->pos().x() ) ); - e->accept(); + setCurrent( findRow( e->pos().y() ), findCol( e->pos().x() ) ); + e->accept(); } else - e->ignore(); + e->ignore(); } @@ -667,10 +536,10 @@ 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(); + 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(); + e->ignore(); } @@ -683,3 +552,3 @@ void QColorWell::mouseReleaseEvent( QMouseEvent *e ) if ( !mousePressed ) - return; + return; QWellArray::mouseReleaseEvent( e ); @@ -688,34 +557,2 @@ void QColorWell::mouseReleaseEvent( QMouseEvent *e ) -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; @@ -723,37 +560,2 @@ 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 ) @@ -771,3 +573,3 @@ int QColorLuminancePicker::val2y( int v ) QColorLuminancePicker::QColorLuminancePicker(QWidget* parent, - const char* name) + const char* name) :QWidget( parent, name ) @@ -796,3 +598,3 @@ void QColorLuminancePicker::setVal( int v ) if ( val == v ) - return; + return; val = QMAX( 0, QMIN(v,255)); @@ -818,14 +620,14 @@ void QColorLuminancePicker::paintEvent( QPaintEvent * ) if ( !pix || pix->height() != hi || pix->width() != wi ) { - delete pix; - QImage img( wi, hi, 32 ); - int y; - for ( y = 0; y < hi; y++ ) { - QColor c( hue, sat, y2val(y+coff), QColor::Hsv ); - QRgb r = c.rgb(); - int x; - for ( x = 0; x < wi; x++ ) - img.setPixel( x, y, r ); - } - pix = new QPixmap; - pix->convertFromImage(img); + delete pix; + QImage img( wi, hi, 32 ); + int y; + for ( y = 0; y < hi; y++ ) { + QColor c( hue, sat, y2val(y+coff), QColor::Hsv ); + QRgb r = c.rgb(); + int x; + for ( x = 0; x < wi; x++ ) + img.setPixel( x, y, r ); + } + pix = new QPixmap; + pix->convertFromImage(img); } @@ -871,7 +673,7 @@ QColorPicker::QColorPicker(QWidget* parent, const char* name ) for ( y = 0; y < pHeight; y++ ) - for ( x = 0; x < pWidth; x++ ) { - QPoint p( x, y ); - img.setPixel( x, y, QColor(huePt(p), satPt(p), - 200, QColor::Hsv).rgb() ); - } + for ( x = 0; x < pWidth; x++ ) { + QPoint p( x, y ); + img.setPixel( x, y, QColor(huePt(p), satPt(p), + 200, QColor::Hsv).rgb() ); + } pix = new QPixmap; @@ -901,3 +703,3 @@ void QColorPicker::setCol( int h, int s ) if ( nhue == hue && nsat == sat ) - return; + return; QRect r( colPt(), QSize(20,20) ); @@ -937,16 +739,2 @@ void QColorPicker::drawContents(QPainter* p) -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 @@ -955,12 +743,12 @@ QValidator::State QColIntValidator::validate( QString &s, int &pos ) const 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(); - } + 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(); + } } @@ -969,98 +757,2 @@ QValidator::State QColIntValidator::validate( QString &s, int &pos ) const - - -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 ) @@ -1073,7 +765,7 @@ void QColorShower::showAlpha( bool b ) if ( b ) { - alphaLab->show(); - alphaEd->show(); + alphaLab->show(); + alphaEd->show(); } else { - alphaLab->hide(); - alphaEd->hide(); + alphaLab->hide(); + alphaEd->hide(); } @@ -1091,13 +783,13 @@ void QColorShowLabel::mouseMoveEvent( QMouseEvent *e ) if ( !mousePressed ) - return; + 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(); + 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(); } @@ -1110,5 +802,5 @@ void QColorShowLabel::dragEnterEvent( QDragEnterEvent *e ) if ( QColorDrag::canDecode( e ) ) - e->accept(); + e->accept(); else - e->ignore(); + e->ignore(); } @@ -1122,8 +814,8 @@ void QColorShowLabel::dropEvent( QDropEvent *e ) if ( QColorDrag::canDecode( e ) ) { - QColorDrag::decode( e, col ); - repaint( FALSE ); - emit colorDropped( col.rgb() ); - e->accept(); + QColorDrag::decode( e, col ); + repaint( FALSE ); + emit colorDropped( col.rgb() ); + e->accept(); } else { - e->ignore(); + e->ignore(); } @@ -1135,3 +827,3 @@ void QColorShowLabel::mouseReleaseEvent( QMouseEvent * ) if ( !mousePressed ) - return; + return; mousePressed = FALSE; @@ -1151,5 +843,5 @@ QColorShower::QColorShower( QWidget *parent, const char *name ) connect( lab, SIGNAL( colorDropped(QRgb) ), - this, SIGNAL( newCol(QRgb) ) ); + this, SIGNAL( newCol(QRgb) ) ); connect( lab, SIGNAL( colorDropped(QRgb) ), - this, SLOT( setRgb(QRgb) ) ); + this, SLOT( setRgb(QRgb) ) ); @@ -1288,31 +980,2 @@ void QColorShower::setHsv( int h, int s, int v ) -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 @@ -1362,3 +1025,3 @@ QColorDialogPrivate::QColorDialogPrivate( QColorDialog *dialog ) : if ( qApp->desktop()->width() < 480 || qApp->desktop()->height() < 350 ) - compact = TRUE; + compact = TRUE; @@ -1368,3 +1031,3 @@ QColorDialogPrivate::QColorDialogPrivate( QColorDialog *dialog ) : if ( compact ) - border = 6; + border = 6; QHBoxLayout *topLay = new QHBoxLayout( dialog, border, 6 ); @@ -1373,3 +1036,3 @@ QColorDialogPrivate::QColorDialogPrivate( QColorDialog *dialog ) : if ( !compact ) - leftLay = new QVBoxLayout( topLay ); + leftLay = new QVBoxLayout( topLay ); @@ -1378,31 +1041,31 @@ QColorDialogPrivate::QColorDialogPrivate( QColorDialog *dialog ) : if ( !compact ) { - standard = new QColorWell( dialog, 6, 8, stdrgb ); - standard->setCellSize( 28, 24 ); - QLabel * lab = new QLabel( standard, - QColorDialog::tr( "&Basic colors"), dialog ); - connect( standard, SIGNAL(selected(int,int)), SLOT(newStandard(int,int))); - leftLay->addWidget( lab ); - leftLay->addWidget( standard ); - - - leftLay->addStretch(); - - custom = new QColorWell( dialog, 2, 8, cusrgb ); - custom->setCellSize( 28, 24 ); - custom->setAcceptDrops( TRUE ); - - connect( custom, SIGNAL(selected(int,int)), SLOT(newCustom(int,int))); - lab = new QLabel( custom, QColorDialog::tr( "&Custom colors") , dialog ); - leftLay->addWidget( lab ); - leftLay->addWidget( custom ); - - QPushButton *custbut = - new QPushButton( QColorDialog::tr("&Define Custom Colors >>"), - dialog ); - custbut->setEnabled( FALSE ); - leftLay->addWidget( custbut ); + standard = new QColorWell( dialog, 6, 8, stdrgb ); + standard->setCellSize( 28, 24 ); + QLabel * lab = new QLabel( standard, + QColorDialog::tr( "&Basic colors"), dialog ); + connect( standard, SIGNAL(selected(int,int)), SLOT(newStandard(int,int))); + leftLay->addWidget( lab ); + leftLay->addWidget( standard ); + + + leftLay->addStretch(); + + custom = new QColorWell( dialog, 2, 8, cusrgb ); + custom->setCellSize( 28, 24 ); + custom->setAcceptDrops( TRUE ); + + connect( custom, SIGNAL(selected(int,int)), SLOT(newCustom(int,int))); + lab = new QLabel( custom, QColorDialog::tr( "&Custom colors") , dialog ); + leftLay->addWidget( lab ); + leftLay->addWidget( custom ); + + QPushButton *custbut = + new QPushButton( QColorDialog::tr("&Define Custom Colors >>"), + dialog ); + custbut->setEnabled( FALSE ); + leftLay->addWidget( custbut ); } else { - // better color picker size for small displays - pWidth = 150; - pHeight = 100; + // better color picker size for small displays + pWidth = 150; + pHeight = 100; } @@ -1436,5 +1099,5 @@ QColorDialogPrivate::QColorDialogPrivate( QColorDialog *dialog ) : if ( compact ) - buttons = new QHBoxLayout( rightLay ); + buttons = new QHBoxLayout( rightLay ); else - buttons = new QHBoxLayout( leftLay ); + buttons = new QHBoxLayout( leftLay ); @@ -1451,7 +1114,7 @@ QColorDialogPrivate::QColorDialogPrivate( QColorDialog *dialog ) : if ( !compact ) { - QPushButton *addCusBt = new QPushButton( - QColorDialog::tr("&Add To Custom Colors"), - dialog ); - rightLay->addWidget( addCusBt ); - connect( addCusBt, SIGNAL(clicked()), this, SLOT(addCustom()) ); + QPushButton *addCusBt = new QPushButton( + QColorDialog::tr("&Add To Custom Colors"), + dialog ); + rightLay->addWidget( addCusBt ); + connect( addCusBt, SIGNAL(clicked()), this, SLOT(addCustom()) ); } @@ -1512,3 +1175,3 @@ QColorDialog::QColorDialog(QWidget* parent, const char* name, bool modal) : QColor QColorDialog::getColor( QColor initial, QWidget *parent, - const char *name ) + const char *name ) { @@ -1517,5 +1180,5 @@ QColor QColorDialog::getColor( QColor initial, QWidget *parent, if ( parent && parent->icon() && !parent->icon()->isNull() ) - dlg->setIcon( *parent->icon() ); + dlg->setIcon( *parent->icon() ); else if ( qApp->mainWidget() && qApp->mainWidget()->icon() && !qApp->mainWidget()->icon()->isNull() ) - dlg->setIcon( *qApp->mainWidget()->icon() ); + dlg->setIcon( *qApp->mainWidget()->icon() ); @@ -1527,3 +1190,3 @@ QColor QColorDialog::getColor( QColor initial, QWidget *parent, if ( resultCode == QDialog::Accepted ) - result = dlg->color(); + result = dlg->color(); QColor::destroyAllocContext(allocContext); @@ -1545,3 +1208,3 @@ QColor QColorDialog::getColor( QColor initial, QWidget *parent, QRgb QColorDialog::getRgba( QRgb initial, bool *ok, - QWidget *parent, const char* name ) + QWidget *parent, const char* name ) { @@ -1555,8 +1218,8 @@ QRgb QColorDialog::getRgba( QRgb initial, bool *ok, if ( resultCode == QDialog::Accepted ) { - QRgb c = dlg->color().rgb(); - int alpha = dlg->selectedAlpha(); - result = qRgba( qRed(c), qGreen(c), qBlue(c), alpha ); + QRgb c = dlg->color().rgb(); + int alpha = dlg->selectedAlpha(); + result = qRgba( qRed(c), qGreen(c), qBlue(c), alpha ); } if ( ok ) - *ok = resultCode == QDialog::Accepted; + *ok = resultCode == QDialog::Accepted; diff --git a/libqtaux/qcolordialog.h b/libqtaux/qcolordialog.h index 89c6283..50c6482 100644 --- a/libqtaux/qcolordialog.h +++ b/libqtaux/qcolordialog.h @@ -44,2 +44,284 @@ +#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; @@ -53,3 +335,3 @@ public: static QRgb getRgba( QRgb, bool* ok = 0, - QWidget *parent=0, const char* name=0 ); + QWidget *parent=0, const char* name=0 ); @@ -76,3 +358,3 @@ private: -private: // Disabled copy constructor and operator= +private: // Disabled copy constructor and operator= #if defined(Q_DISABLE_COPY) @@ -83,2 +365,31 @@ private: // Disabled copy constructor and operator= +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 |