summaryrefslogtreecommitdiffstats
path: root/kiconedit/kiconcolors.cpp
blob: 3bfc872dce5867bc519483b92afc333024beedef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/*
    KDE Icon Editor - a small graphics drawing program for the KDE
    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.
*/  

#include <tqpainter.h>
#include <tqdrawutil.h>

#include <kdebug.h>

#include "kiconcolors.h"

KDrawColors::KDrawColors(TQWidget *tqparent) : KColorGrid(tqparent, 0, 3)
{
  kdDebug(4640) << "KDrawColors - constructor" << endl;
  setCellSize(17);
  setGrid(true);
  setGridState(KColorGrid::Shaded);
  selected = 0;
  kdDebug(4640) << "KDrawColors - constructor - done" << endl;
}

void KDrawColors::paintCell( TQPainter *painter, int row, int col )
{
  //KColorGrid::paintCell(painter, row, col);
  uint c = colorAt( row * numCols() + col );
  TQBrush brush(c);
  int d = spacing();

  qDrawShadePanel( painter, d, d, cellSize()-d, cellSize()-d,
                tqcolorGroup(), true, 1, &brush);
  if ( row * numCols() + col == selected)
     painter->drawWinFocusRect( d+1, d+1, cellSize()-(2*d)+1, cellSize()-(2*d)+1 );
}

void KDrawColors::mouseReleaseEvent( TQMouseEvent *e )
{
  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);
}

KSysColors::KSysColors(TQWidget *tqparent) : KDrawColors(tqparent)
{
  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;
}

KCustomColors::KCustomColors(TQWidget *tqparent) : KDrawColors(tqparent)
{
  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;
}

void KCustomColors::mouseDoubleClickEvent(TQMouseEvent *e)
{
  int row = findRow( e->pos().y() );
  int col = findCol( e->pos().x() );
  int cell = row * numCols() + col;
  TQColor color=colorAt(cell);
  if(KColorDialog::getColor(color))
  {
    setColor(cell, color.rgb());
    emit newColor(color.rgb()|OPAQUE_MASK);
    freecells[cell] = false;
  }
}

void KCustomColors::addColor(uint c)
{
  if(!contains(c))
  {
    int f = getFreeCell();
    if(f != -1)
    {
      TQColor color(c);
      if(!color.isValid())
      {
        kdDebug(4640) << "KCustomColors::addColor: Not a valid color: " << c << endl;
        return;
      }
      //kdDebug(4640) << "KCustomColors::addColor: Adding color: " << c << " - " << tqRed(c) << " " << tqGreen(c) << " " << tqBlue(c) << endl;
      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();
}
#include "kiconcolors.moc"