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 /libqtaux | |
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 @@ -38,20 +38,17 @@ #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> // @@ -66,106 +63,7 @@ // - -#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 ) { d = 0; @@ -174,16 +72,16 @@ QWellArray::QWellArray( QWidget *parent, const char * name, bool popup ) nCols = 7; nRows = 7; - int w = 24; // cell width - int h = 21; // cell height + 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 ); + w = h = 18; + if ( style() == WindowsStyle ) + setFrameStyle( QFrame::WinPanel | QFrame::Raised ); + else + setFrameStyle( QFrame::Panel | QFrame::Raised ); + setMargin( 1 ); + setLineWidth( 2 ); } setNumCols( nCols ); @@ -197,5 +95,5 @@ QWellArray::QWellArray( QWidget *parent, const char * name, bool popup ) if ( smallStyle ) - setMouseTracking( TRUE ); + setMouseTracking( TRUE ); setOffset( 5 , 10 ); @@ -217,50 +115,50 @@ QSize QWellArray::sizeHint() const 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; if ( !smallStyle ) - b = 3; + b = 3; const QColorGroup & g = colorGroup(); p->setPen( QPen( black, 0, SolidLine ) ); 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 ); } 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; + } } 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 ); + } } drawContents( p, row, col, QRect(b, b, w - 2*b, h - 2*b) ); @@ -282,10 +180,10 @@ 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() ); } } @@ -319,6 +217,6 @@ void QWellArray::mouseMoveEvent( QMouseEvent* e ) // clicked in. if ( smallStyle ) { - QPoint pos = e->pos(); - setCurrent( findRow( pos.y() ), findCol( pos.x() ) ); + QPoint pos = e->pos(); + setCurrent( findRow( pos.y() ), findCol( pos.x() ) ); } } @@ -333,8 +231,8 @@ 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; int oldRow = curRow; @@ -359,5 +257,5 @@ void QWellArray::setSelected( int row, int col ) { if ( (selRow == row) && (selCol == col) ) - return; + return; int oldRow = selRow; @@ -365,5 +263,5 @@ void QWellArray::setSelected( int row, int col ) if ( row < 0 || col < 0 ) - row = col = -1; + row = col = -1; selCol = col; @@ -373,8 +271,8 @@ void QWellArray::setSelected( int row, int col ) updateCell( selRow, selCol ); if ( row >= 0 ) - emit selected( row, col ); + emit selected( row, col ); if ( isVisible() && parentWidget() && parentWidget()->inherits("QPopupMenu") ) - parentWidget()->close(); + parentWidget()->close(); } @@ -401,8 +299,8 @@ void QWellArray::setDimension( int rows, int cols ) nCols = cols; if ( d ) { - if ( d->brush ) - delete[] d->brush; - delete d; - d = 0; + if ( d->brush ) + delete[] d->brush; + delete d; + d = 0; } setNumCols( nCols ); @@ -413,12 +311,12 @@ 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 } @@ -434,5 +332,5 @@ 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; } @@ -452,47 +350,47 @@ void QWellArray::focusOutEvent( QFocusEvent* ) 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: case Key_Return: 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; } @@ -509,14 +407,14 @@ static void initRGB() { if ( initrgb ) - return; + 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 ( 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); } @@ -538,7 +436,7 @@ QRgb QColorDialog::customColor( int i ) if ( i < 0 || i >= customCount() ) { #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; } return cusrgb[i]; @@ -553,7 +451,7 @@ void QColorDialog::setCustomColor( int i, QRgb c ) if ( i < 0 || i >= customCount() ) { #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; } cusrgb[i] = c; @@ -567,33 +465,4 @@ 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 { @@ -620,18 +489,18 @@ void QColorWell::mouseMoveEvent( QMouseEvent *e ) #ifndef QT_NO_DRAGANDDROP 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(); } #endif @@ -643,7 +512,7 @@ void QColorWell::dragEnterEvent( QDragEnterEvent *e ) setFocus(); if ( QColorDrag::canDecode( e ) ) - e->accept(); + e->accept(); else - e->ignore(); + e->ignore(); } @@ -651,5 +520,5 @@ void QColorWell::dragLeaveEvent( QDragLeaveEvent * ) { if ( hasFocus() ) - parentWidget()->setFocus(); + parentWidget()->setFocus(); } @@ -657,8 +526,8 @@ 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(); } @@ -666,12 +535,12 @@ 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(); } } @@ -682,79 +551,12 @@ void QColorWell::mouseReleaseEvent( QMouseEvent *e ) { if ( !mousePressed ) - return; + 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 ) { @@ -770,5 +572,5 @@ int QColorLuminancePicker::val2y( int v ) QColorLuminancePicker::QColorLuminancePicker(QWidget* parent, - const char* name) + const char* name) :QWidget( parent, name ) { @@ -795,5 +597,5 @@ void QColorLuminancePicker::setVal( int v ) { if ( val == v ) - return; + return; val = QMAX( 0, QMIN(v,255)); delete pix; pix=0; @@ -817,16 +619,16 @@ void QColorLuminancePicker::paintEvent( QPaintEvent * ) 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++ ) { - 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); } QPainter p(this); @@ -870,9 +672,9 @@ QColorPicker::QColorPicker(QWidget* parent, const char* name ) int x,y; 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; pix->convertFromImage(img); @@ -900,5 +702,5 @@ void QColorPicker::setCol( int h, int s ) int nsat = QMIN( QMAX(0,s), 255); if ( nhue == hue && nsat == sat ) - return; + return; QRect r( colPt(), QSize(20,20) ); hue = nhue; sat = nsat; @@ -936,132 +738,22 @@ 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 { 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(); - } + 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 ) { @@ -1072,9 +764,9 @@ void QColorShower::showAlpha( bool b ) { if ( b ) { - alphaLab->show(); - alphaEd->show(); + alphaLab->show(); + alphaEd->show(); } else { - alphaLab->hide(); - alphaEd->hide(); + alphaLab->hide(); + alphaEd->hide(); } } @@ -1090,15 +782,15 @@ void QColorShowLabel::mouseMoveEvent( QMouseEvent *e ) #ifndef QT_NO_DRAGANDDROP 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(); } #endif @@ -1109,7 +801,7 @@ void QColorShowLabel::dragEnterEvent( QDragEnterEvent *e ) { if ( QColorDrag::canDecode( e ) ) - e->accept(); + e->accept(); else - e->ignore(); + e->ignore(); } @@ -1121,10 +813,10 @@ 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(); } } @@ -1134,5 +826,5 @@ void QColorShowLabel::mouseReleaseEvent( QMouseEvent * ) { if ( !mousePressed ) - return; + return; mousePressed = FALSE; } @@ -1150,7 +842,7 @@ QColorShower::QColorShower( QWidget *parent, const char *name ) gl->addMultiCellWidget(lab, 0,-1,0,0); 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) ) ); hEd = new QColNumLineEdit( this ); @@ -1287,33 +979,4 @@ 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 void QColorDialogPrivate::newHsv( int h, int s, int v ) @@ -1361,5 +1024,5 @@ QColorDialogPrivate::QColorDialogPrivate( QColorDialog *dialog ) : // so just use the color picker. if ( qApp->desktop()->width() < 480 || qApp->desktop()->height() < 350 ) - compact = TRUE; + compact = TRUE; nextCust = 0; @@ -1367,43 +1030,43 @@ QColorDialogPrivate::QColorDialogPrivate( QColorDialog *dialog ) : int border = 12; if ( compact ) - border = 6; + border = 6; QHBoxLayout *topLay = new QHBoxLayout( dialog, border, 6 ); QVBoxLayout *leftLay = 0; if ( !compact ) - leftLay = new QVBoxLayout( topLay ); + leftLay = new QVBoxLayout( topLay ); initRGB(); 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; } @@ -1435,7 +1098,7 @@ QColorDialogPrivate::QColorDialogPrivate( QColorDialog *dialog ) : QHBoxLayout *buttons; if ( compact ) - buttons = new QHBoxLayout( rightLay ); + buttons = new QHBoxLayout( rightLay ); else - buttons = new QHBoxLayout( leftLay ); + buttons = new QHBoxLayout( leftLay ); QPushButton *ok, *cancel; @@ -1450,9 +1113,9 @@ 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()) ); } } @@ -1511,12 +1174,12 @@ QColorDialog::QColorDialog(QWidget* parent, const char* name, bool modal) : QColor QColorDialog::getColor( QColor initial, QWidget *parent, - const char *name ) + const char *name ) { int allocContext = QColor::enterAllocContext(); QColorDialog *dlg = new QColorDialog( parent, name, TRUE ); //modal 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() ); dlg->setCaption( QColorDialog::tr( "Select color" ) ); @@ -1526,5 +1189,5 @@ QColor QColorDialog::getColor( QColor initial, QWidget *parent, QColor result; if ( resultCode == QDialog::Accepted ) - result = dlg->color(); + result = dlg->color(); QColor::destroyAllocContext(allocContext); delete dlg; @@ -1544,5 +1207,5 @@ QColor QColorDialog::getColor( QColor initial, QWidget *parent, QRgb QColorDialog::getRgba( QRgb initial, bool *ok, - QWidget *parent, const char* name ) + QWidget *parent, const char* name ) { int allocContext = QColor::enterAllocContext(); @@ -1554,10 +1217,10 @@ QRgb QColorDialog::getRgba( QRgb initial, bool *ok, QRgb result = initial; 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; QColor::destroyAllocContext(allocContext); diff --git a/libqtaux/qcolordialog.h b/libqtaux/qcolordialog.h index 89c6283..50c6482 100644 --- a/libqtaux/qcolordialog.h +++ b/libqtaux/qcolordialog.h @@ -43,4 +43,286 @@ #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; @@ -52,5 +334,5 @@ 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 ); + QWidget *parent=0, const char* name=0 ); @@ -75,5 +357,5 @@ private: friend class QColorDialogPrivate; -private: // Disabled copy constructor and operator= +private: // Disabled copy constructor and operator= #if defined(Q_DISABLE_COPY) QColorDialog( const QColorDialog & ); @@ -82,3 +364,32 @@ 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 |