Source Code (Use browser search to find items of interest.)
Class Index
kdelibs'KColorCells (./kdelibs/kdeui/kcolordlg.h:181)
class KColorCells : public QTableView
{
Q_OBJECT
public:
KColorCells( QWidget *parent, int rows, int cols );
~KColorCells();
void setColor( int colNum, const QColor &col );
QColor color( int indx )
{ return colors[indx]; }
int numCells()
{ return numRows() * numCols(); }
void setShading(bool _shade) { shade = _shade; }
void setAcceptDrags(bool _acceptDrags) { acceptDrags = _acceptDrags; }
int getSelected()
{ return selected; }
signals:
void colorSelected( int col );
protected:
virtual void paintCell( QPainter *painter, int row, int col );
virtual void resizeEvent( QResizeEvent * );
virtual void mouseReleaseEvent( QMouseEvent * );
virtual void mousePressEvent( QMouseEvent * );
virtual void mouseMoveEvent( QMouseEvent * );
virtual void dragEnterEvent( QDragEnterEvent *);
virtual void dropEvent( QDropEvent *);
int posToCell(const QPoint &pos, bool ignoreBorders=false);
QColor *colors;
bool inMouse;
QPoint mPos;
int selected;
bool shade;
bool acceptDrags;
private:
class KColorCellsPrivate;
KColorCellsPrivate *d;
};
/**
* Displays and signals a single colour selection.
*/
kdelibs'KColorCells::KColorCells() (./kdelibs/kdeui/kcolordlg.cpp:239)
KColorCells::KColorCells( QWidget *parent, int rows, int cols )
: QTableView( parent )
{
shade = true;
setNumRows( rows );
setNumCols( cols );
colors = new QColor [ rows * cols ];
for ( int i = 0; i < rows * cols; i++ )
colors[i] = QColor();
selected = 0;
inMouse = false;
// Drag'n'Drop
setAcceptDrops( true);
}
kdelibs'KColorCells::~KColorCells() (./kdelibs/kdeui/kcolordlg.cpp:257)
KColorCells::~KColorCells()
{
delete [] colors;
}
kdelibs'KColorCells::setColor() (./kdelibs/kdeui/kcolordlg.cpp:262)
void KColorCells::setColor( int colNum, const QColor &col )
{
colors[colNum] = col;
updateCell( colNum/numCols(), colNum%numCols() );
}
kdelibs'KColorCells::paintCell() (./kdelibs/kdeui/kcolordlg.cpp:268)
void KColorCells::paintCell( QPainter *painter, int row, int col )
{
QBrush brush;
int w = 1;
if (shade)
{
qDrawShadePanel( painter, 1, 1, cellWidth()-2,
cellHeight()-2, colorGroup(), TRUE, 1, &brush );
w = 2;
}
QColor color = colors[ row * numCols() + col ];
if (!color.isValid())
{
if (!shade) return;
color = backgroundColor();
}
painter->setPen( color );
painter->setBrush( QBrush( color ) );
painter->drawRect( w, w, cellWidth()-w*2, cellHeight()-w*2 );
if ( row * numCols() + col == selected )
painter->drawWinFocusRect( w, w, cellWidth()-w*2, cellHeight()-w*2 );
}
kdelibs'KColorCells::resizeEvent() (./kdelibs/kdeui/kcolordlg.cpp:294)
void KColorCells::resizeEvent( QResizeEvent * )
{
setCellWidth( width() / numCols() );
setCellHeight( height() / numRows() );
}
kdelibs'KColorCells::mousePressEvent() (./kdelibs/kdeui/kcolordlg.cpp:300)
void KColorCells::mousePressEvent( QMouseEvent *e )
{
inMouse = true;
mPos = e->pos();
}
kdelibs'KColorCells::posToCell() (./kdelibs/kdeui/kcolordlg.cpp:306)
int KColorCells::posToCell(const QPoint &pos, bool ignoreBorders)
{
int row = pos.y() / cellHeight();
int col = pos.x() / cellWidth();
int cell = row * numCols() + col;
if (!ignoreBorders)
{
int border = 2;
int x = pos.x() - col * cellWidth();
int y = pos.y() - row * cellHeight();
if ( (x < border) || (x > cellWidth()-border) ||
(y < border) || (y > cellHeight()-border))
return -1;
}
return cell;
}
kdelibs'KColorCells::mouseMoveEvent() (./kdelibs/kdeui/kcolordlg.cpp:324)
void KColorCells::mouseMoveEvent( QMouseEvent *e )
{
if( !(e->state() && LeftButton)) return;
if(inMouse) {
int delay = KGlobalSettings::dndEventDelay();
if(e->x() > mPos.x()+delay || e->x() < mPos.x()-delay ||
e->y() > mPos.y()+delay || e->y() < mPos.y()-delay){
// Drag color object
int cell = posToCell(mPos);
if ((cell != -1) && colors[cell].isValid())
{
KColorDrag *d = KColorDrag::makeDrag( colors[cell], this);
d->dragCopy();
}
}
}
}
kdelibs'KColorCells::dragEnterEvent() (./kdelibs/kdeui/kcolordlg.cpp:343)
void KColorCells::dragEnterEvent( QDragEnterEvent *event)
{
event->accept( acceptDrags && KColorDrag::canDecode( event));
}
kdelibs'KColorCells::dropEvent() (./kdelibs/kdeui/kcolordlg.cpp:348)
void KColorCells::dropEvent( QDropEvent *event)
{
QColor c;
if( KColorDrag::decode( event, c)) {
int cell = posToCell(event->pos(), true);
setColor(cell,c);
}
}
kdelibs'KColorCells::mouseReleaseEvent() (./kdelibs/kdeui/kcolordlg.cpp:357)
void KColorCells::mouseReleaseEvent( QMouseEvent *e )
{
int cell = posToCell(mPos);
int currentCell = posToCell(e->pos());
// If we release the mouse in another cell and we don't have
// a drag we should ignore this event.
if (currentCell != cell)
cell = -1;
if ( (cell != -1) && (selected != cell) )
{
int prevSel = selected;
selected = cell;
updateCell( prevSel/numCols(), prevSel%numCols(), FALSE );
updateCell( cell/numCols(), cell%numCols(), FALSE );
}
inMouse = false;
if (cell != -1)
emit colorSelected( cell );
}
//-----------------------------------------------------------------------------