You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
171 lines
4.5 KiB
171 lines
4.5 KiB
15 years ago
|
/*
|
||
13 years ago
|
TDE Icon Editor - a small graphics drawing program for the TDE
|
||
15 years ago
|
Copyright (C) 1998 Thomas Tanghus (tanghus@kde.org)
|
||
|
|
||
|
This program is free software; you can redistribute it and/or
|
||
|
modify it under the terms of the GNU General Public
|
||
|
License as published by the Free Software Foundation; either
|
||
|
version 2 of the License, or (at your option) any later version.
|
||
|
|
||
|
This program is distributed in the hope that it will be useful,
|
||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
|
General Public License for more details.
|
||
|
|
||
|
You should have received a copy of the GNU Library General Public License
|
||
|
along with this library; see the file COPYING.LIB. If not, write to
|
||
|
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||
|
Boston, MA 02110-1301, USA.
|
||
|
*/
|
||
|
|
||
15 years ago
|
#include <tqpainter.h>
|
||
|
#include <tqdrawutil.h>
|
||
15 years ago
|
|
||
|
#include <kdebug.h>
|
||
|
|
||
11 years ago
|
#include "tdeiconcolors.h"
|
||
15 years ago
|
|
||
14 years ago
|
KDrawColors::KDrawColors(TQWidget *parent) : KColorGrid(parent, 0, 3)
|
||
15 years ago
|
{
|
||
|
kdDebug(4640) << "KDrawColors - constructor" << endl;
|
||
|
setCellSize(17);
|
||
|
setGrid(true);
|
||
|
setGridState(KColorGrid::Shaded);
|
||
|
selected = 0;
|
||
|
kdDebug(4640) << "KDrawColors - constructor - done" << endl;
|
||
|
}
|
||
|
|
||
15 years ago
|
void KDrawColors::paintCell( TQPainter *painter, int row, int col )
|
||
15 years ago
|
{
|
||
|
//KColorGrid::paintCell(painter, row, col);
|
||
|
uint c = colorAt( row * numCols() + col );
|
||
15 years ago
|
TQBrush brush(c);
|
||
15 years ago
|
int d = spacing();
|
||
|
|
||
|
qDrawShadePanel( painter, d, d, cellSize()-d, cellSize()-d,
|
||
13 years ago
|
colorGroup(), true, 1, &brush);
|
||
15 years ago
|
if ( row * numCols() + col == selected)
|
||
|
painter->drawWinFocusRect( d+1, d+1, cellSize()-(2*d)+1, cellSize()-(2*d)+1 );
|
||
|
}
|
||
|
|
||
15 years ago
|
void KDrawColors::mouseReleaseEvent( TQMouseEvent *e )
|
||
15 years ago
|
{
|
||
|
int row = findRow( e->pos().y() );
|
||
|
int col = findCol( e->pos().x() );
|
||
|
int cell = row * numCols() + col;
|
||
|
|
||
|
if ( selected != cell )
|
||
|
{
|
||
|
int prevSel = selected;
|
||
|
selected = cell;
|
||
|
updateCell( prevSel/numCols(), prevSel%numCols(), FALSE );
|
||
|
updateCell( row, col, FALSE );
|
||
|
}
|
||
|
|
||
|
emit newColor(colorAt(cell)|OPAQUE_MASK);
|
||
|
}
|
||
|
|
||
14 years ago
|
KSysColors::KSysColors(TQWidget *parent) : KDrawColors(parent)
|
||
15 years ago
|
{
|
||
|
kdDebug(4640) << "KSysColors - constructor" << endl;
|
||
|
|
||
|
setNumRows(7);
|
||
|
setNumCols(6);
|
||
|
//fill(backgroundColor().rgb()|OPAQUE_MASK);
|
||
|
setFixedSize(numCols()*cellSize(), numRows()*cellSize());
|
||
|
fill(TRANSPARENT|OPAQUE_MASK);
|
||
|
|
||
|
int numcells = 42;
|
||
|
|
||
|
kdDebug(4640) << "KSysColors - constructor - before setColor" << endl;
|
||
|
for(int i = 0; i < numcells; i++)
|
||
|
{
|
||
|
setColor(i, iconpalette[i]|OPAQUE_MASK);
|
||
|
}
|
||
|
kdDebug(4640) << "KSysColors - constructor - done" << endl;
|
||
|
}
|
||
|
|
||
14 years ago
|
KCustomColors::KCustomColors(TQWidget *parent) : KDrawColors(parent)
|
||
15 years ago
|
{
|
||
|
kdDebug(4640) << "KCustomColors - constructor" << endl;
|
||
|
setNumRows(3);
|
||
|
setNumCols(6);
|
||
|
fill(TRANSPARENT|OPAQUE_MASK);
|
||
|
setFixedSize(numCols()*cellSize(), numRows()*cellSize());
|
||
|
freecells = new bool[numRows()*numCols()];
|
||
|
for(int i = 0; i < numRows()*numCols(); i++)
|
||
|
freecells[i] = true;
|
||
|
kdDebug(4640) << "KCustomColors - constructor - done" << endl;
|
||
|
}
|
||
|
|
||
|
KCustomColors::~KCustomColors()
|
||
|
{
|
||
|
delete [] freecells;
|
||
|
}
|
||
|
|
||
15 years ago
|
void KCustomColors::mouseDoubleClickEvent(TQMouseEvent *e)
|
||
15 years ago
|
{
|
||
|
int row = findRow( e->pos().y() );
|
||
|
int col = findCol( e->pos().x() );
|
||
|
int cell = row * numCols() + col;
|
||
15 years ago
|
TQColor color=colorAt(cell);
|
||
15 years ago
|
if(KColorDialog::getColor(color))
|
||
|
{
|
||
|
setColor(cell, color.rgb());
|
||
|
emit newColor(color.rgb()|OPAQUE_MASK);
|
||
|
freecells[cell] = false;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void KCustomColors::addColor(uint c)
|
||
|
{
|
||
14 years ago
|
if(!contains(c))
|
||
15 years ago
|
{
|
||
|
int f = getFreeCell();
|
||
|
if(f != -1)
|
||
|
{
|
||
15 years ago
|
TQColor color(c);
|
||
15 years ago
|
if(!color.isValid())
|
||
|
{
|
||
|
kdDebug(4640) << "KCustomColors::addColor: Not a valid color: " << c << endl;
|
||
|
return;
|
||
|
}
|
||
14 years ago
|
//kdDebug(4640) << "KCustomColors::addColor: Adding color: " << c << " - " << tqRed(c) << " " << tqGreen(c) << " " << tqBlue(c) << endl;
|
||
15 years ago
|
setColor(f, c);
|
||
|
freecells[f] = false;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
int KCustomColors::getFreeCell()
|
||
|
{
|
||
|
for (int i = 0; i < numRows()*numCols(); i++)
|
||
|
{
|
||
|
if(freecells[i])
|
||
|
{
|
||
|
if(i+1 < numRows()*numCols())
|
||
|
freecells[i+1] = true;
|
||
|
else
|
||
|
freecells[0] = true;
|
||
|
return i;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
freeAllCells(); // start over again - not very elegant
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
void KCustomColors::freeAllCells()
|
||
|
{
|
||
|
for (int i = 0; i < numRows()*numCols(); i++)
|
||
|
freecells[i] = true;
|
||
|
}
|
||
|
|
||
|
void KCustomColors::clear()
|
||
|
{
|
||
|
fill(TRANSPARENT);
|
||
|
freeAllCells();
|
||
|
update();
|
||
|
}
|
||
11 years ago
|
#include "tdeiconcolors.moc"
|