summaryrefslogtreecommitdiff
authormouse <mouse>2004-03-31 13:23:53 (UTC)
committer mouse <mouse>2004-03-31 13:23:53 (UTC)
commit859e524e4c55bedc4a73e3208f34a75013cb37f5 (patch) (side-by-side diff)
treee46dc8a969254869e8a5d3cdc99b2c845f3e59e5
parentc74a24cbd04cb74d832908eb2b373aed7b3cea71 (diff)
downloadopie-859e524e4c55bedc4a73e3208f34a75013cb37f5.zip
opie-859e524e4c55bedc4a73e3208f34a75013cb37f5.tar.gz
opie-859e524e4c55bedc4a73e3208f34a75013cb37f5.tar.bz2
added missed include file for QColorDrag
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libqtaux/qcolordialog.cpp4
1 files changed, 4 insertions, 0 deletions
diff --git a/libqtaux/qcolordialog.cpp b/libqtaux/qcolordialog.cpp
index 907c2aa..ccef0ad 100644
--- a/libqtaux/qcolordialog.cpp
+++ b/libqtaux/qcolordialog.cpp
@@ -1,822 +1,826 @@
/****************************************************************************
** $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 "qapplication.h"
//////////// QWellArray BEGIN
#include "qobjectdict.h"
+#ifndef QT_NO_DRAGANDDROP
+#include "qdragobject.h"
+#endif
+
//
// 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;
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;
} 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 ( (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 );
}
}
drawContents( p, row, col, QRect(b, b, w - 2*b, h - 2*b) );
}
/*!
Pass-through to QTableView::drawContents() to avoid hiding.
*/
void QWellArray::drawContents( QPainter *p )
{
QTableView::drawContents(p);
}
/*!
Reimplement this function to change the contents of the well array.
*/
void QWellArray::drawContents( QPainter *p, int row, int col, const QRect &r )
{
if ( d ) {
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() );
}
}
/*\reimp
*/
void QWellArray::mousePressEvent( QMouseEvent* e )
{
// The current cell marker is set to the cell the mouse is pressed
// in.
QPoint pos = e->pos();
setCurrent( findRow( pos.y() ), findCol( pos.x() ) );
}
/*\reimp
*/
void QWellArray::mouseReleaseEvent( QMouseEvent* )
{
// The current cell marker is set to the cell the mouse is clicked
// in.
setSelected( curRow, curCol );
}
/*\reimp
*/
void QWellArray::mouseMoveEvent( QMouseEvent* e )
{
// The current cell marker is set to the cell the mouse is
// clicked in.
if ( smallStyle ) {
QPoint pos = e->pos();
setCurrent( findRow( pos.y() ), findCol( pos.x() ) );
}
}
/*
Sets the cell currently having the focus. This is not necessarily
the same as the currently selected cell.
*/
void QWellArray::setCurrent( int row, int col )
{
if ( (curRow == row) && (curCol == col) )
return;
if ( row < 0 || col < 0 )
row = col = -1;
int oldRow = curRow;
int oldCol = curCol;
curRow = row;
curCol = col;
updateCell( oldRow, oldCol );
updateCell( curRow, curCol );
}
/*!
Sets the currently selected cell to \a row, \a col. If \a row or \a
col are less than zero, the current cell is unselected.
Does not set the position of the focus indicator.
*/
void QWellArray::setSelected( int row, int col )
{
if ( (selRow == row) && (selCol == col) )
return;
int oldRow = selRow;
int oldCol = selCol;
if ( row < 0 || col < 0 )
row = col = -1;
selCol = col;
selRow = row;
updateCell( oldRow, oldCol );
updateCell( selRow, selCol );
if ( row >= 0 )
emit selected( row, col );
if ( isVisible() && parentWidget() && parentWidget()->inherits("QPopupMenu") )
parentWidget()->close();
}
/*!\reimp
*/
void QWellArray::focusInEvent( QFocusEvent* )
{
updateCell( curRow, curCol );
}
/*!
Sets the size of the well array to be \c rows cells by \c cols.
Resets any brush info set by setCellBrush().
Must be called by reimplementors.
*/
void QWellArray::setDimension( int rows, int cols )
{
nRows = rows;
nCols = cols;
if ( d ) {
if ( d->brush )
delete[] d->brush;
delete d;
d = 0;
}
setNumCols( nCols );
setNumRows( nRows );
}
void QWellArray::setCellBrush( int row, int col, const QBrush &b )
{
if ( !d ) {
d = new QWellArrayData;
d->brush = new QBrush[nRows*nCols];
}
if ( row >= 0 && row < nRows && col >= 0 && col < nCols )
d->brush[row*nCols+col] = b;
#ifdef CHECK_RANGE
else
qWarning( "QWellArray::setCellBrush( %d, %d ) out of range", row, col );
#endif
}
/*!
Returns the brush set for the cell at \a row, \a col. If no brush is set,
\c NoBrush is returned.
*/
QBrush QWellArray::cellBrush( int row, int col )
{
if ( d && row >= 0 && row < nRows && col >= 0 && col < nCols )
return d->brush[row*nCols+col];
return NoBrush;
}
/*!\reimp
*/
void QWellArray::focusOutEvent( QFocusEvent* )
{
updateCell( curRow, curCol );
}
/*\reimp
*/
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;
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;
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;
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;
}
}
//////////// QWellArray END
static bool initrgb = FALSE;
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++ ) {
QColor c( hue, sat, y2val(y+coff), QColor::Hsv );
QRgb r = c.rgb();