|
Line 0
Link Here
|
|
|
1 |
/* |
| 2 |
TDE Icon Editor - a small graphics drawing program for the TDE. |
| 3 |
Copyright (C) 1998 Thomas Tanghus (tanghus@kde.org) |
| 4 |
|
| 5 |
Includes portions of code from TQt, |
| 6 |
Copyright (C) 1992-2000 Trolltech AS. |
| 7 |
|
| 8 |
This program is free software; you can redistribute it and/or |
| 9 |
modify it under the terms of the GNU General Public |
| 10 |
License as published by the Free Software Foundation; either |
| 11 |
version 2 of the License, or (at your option) any later version. |
| 12 |
|
| 13 |
This program is distributed in the hope that it will be useful, |
| 14 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 |
General Public License for more details. |
| 17 |
|
| 18 |
You should have received a copy of the GNU Library General Public License |
| 19 |
along with this library; see the file COPYING.LIB. If not, write to |
| 20 |
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 21 |
Boston, MA 02110-1301, USA. |
| 22 |
*/ |
| 23 |
|
| 24 |
#include <stdlib.h> |
| 25 |
|
| 26 |
#include <tqpainter.h> |
| 27 |
#include <tqwhatsthis.h> |
| 28 |
#include <tqscrollview.h> |
| 29 |
#include <tqbitmap.h> |
| 30 |
#include <tqclipboard.h> |
| 31 |
#include <tqdatetime.h> |
| 32 |
|
| 33 |
#include <kiconloader.h> |
| 34 |
#include <kruler.h> |
| 35 |
#include <tdelocale.h> |
| 36 |
#include <tdemessagebox.h> |
| 37 |
#include <kdebug.h> |
| 38 |
|
| 39 |
#include "kresize.h" |
| 40 |
#include "properties.h" |
| 41 |
#include "tdeicongrid.h" |
| 42 |
#include "tdeiconedit.h" |
| 43 |
#ifndef PICS_INCLUDED |
| 44 |
#include "pics/logo.xpm" |
| 45 |
#define PICS_INCLUDED |
| 46 |
#endif |
| 47 |
|
| 48 |
#include <X11/Xos.h> |
| 49 |
|
| 50 |
void DrawCommand::execute() |
| 51 |
{ |
| 52 |
oldcolor = *((uint*)image->scanLine(y) + x); |
| 53 |
*((uint*)image->scanLine(y) + x) = newcolor; |
| 54 |
int cell = y * grid->numCols() + x; |
| 55 |
grid->setUndoColor( cell, newcolor, false ); |
| 56 |
} |
| 57 |
|
| 58 |
void DrawCommand::unexecute() |
| 59 |
{ |
| 60 |
*((uint*)image->scanLine(y) + x) = oldcolor; |
| 61 |
int cell = y * grid->numCols() + x; |
| 62 |
grid->setUndoColor( cell, oldcolor, false ); |
| 63 |
} |
| 64 |
|
| 65 |
void RepaintCommand::execute() |
| 66 |
{ |
| 67 |
grid->update( area); |
| 68 |
} |
| 69 |
|
| 70 |
KGridView::KGridView(TQImage *image, KCommandHistory* history, TQWidget *parent, const char *name) |
| 71 |
: TQFrame(parent, name) |
| 72 |
{ |
| 73 |
_corner = 0L; |
| 74 |
_hruler = _vruler = 0L; |
| 75 |
_grid = 0L; |
| 76 |
|
| 77 |
acceptdrop = false; |
| 78 |
|
| 79 |
TDEIconEditProperties *props = TDEIconEditProperties::self(); |
| 80 |
|
| 81 |
viewport = new TQScrollView(this); |
| 82 |
TQ_CHECK_PTR(viewport); |
| 83 |
|
| 84 |
_grid = new TDEIconEditGrid(image, history, viewport->viewport()); |
| 85 |
TQ_CHECK_PTR(_grid); |
| 86 |
viewport->addChild(_grid); |
| 87 |
_grid->setGrid(props->showGrid()); |
| 88 |
_grid->setCellSize(props->gridScale()); |
| 89 |
|
| 90 |
TQString str = i18n( "Icon draw grid\n\nThe icon grid is the area where" |
| 91 |
" you draw the icons.\nYou can zoom in and out using the magnifying" |
| 92 |
" glasses on the toolbar.\n(Tip: Hold the magnify button down for a" |
| 93 |
" few seconds to zoom to a predefined scale)" ); |
| 94 |
TQWhatsThis::add( _grid, str ); |
| 95 |
|
| 96 |
if(props->bgMode() == FixedPixmap) |
| 97 |
{ |
| 98 |
TQPixmap pix(props->bgPixmap()); |
| 99 |
if(pix.isNull()) |
| 100 |
{ |
| 101 |
TQPixmap pmlogo((const char **)logo); |
| 102 |
pix = pmlogo; |
| 103 |
} |
| 104 |
viewport->viewport()->setBackgroundPixmap(pix); |
| 105 |
_grid->setBackgroundPixmap(pix); |
| 106 |
} |
| 107 |
else |
| 108 |
{ |
| 109 |
viewport->viewport()->setBackgroundColor(props->bgColor()); |
| 110 |
} |
| 111 |
|
| 112 |
_corner = new TQFrame(this); |
| 113 |
_corner->setFrameStyle(TQFrame::WinPanel | TQFrame::Raised); |
| 114 |
|
| 115 |
_hruler = new KRuler(Qt::Horizontal, this); |
| 116 |
_hruler->setEndLabel(i18n("width")); |
| 117 |
_hruler->setOffset( -2 ); |
| 118 |
_hruler->setRange(0, 1000); |
| 119 |
|
| 120 |
_vruler = new KRuler(Qt::Vertical, this); |
| 121 |
_vruler->setEndLabel(i18n("height")); |
| 122 |
_vruler->setOffset( -2 ); |
| 123 |
_vruler->setRange(0, 1000); |
| 124 |
|
| 125 |
str = i18n( "Rulers\n\nThis is a visual representation of the current" |
| 126 |
" cursor position" ); |
| 127 |
TQWhatsThis::add( _hruler, str ); |
| 128 |
TQWhatsThis::add( _vruler, str ); |
| 129 |
|
| 130 |
connect(_grid, TQT_SIGNAL(scalingchanged(int)), TQT_SLOT(scalingChange(int))); |
| 131 |
connect(_grid, TQT_SIGNAL(sizechanged(int, int)), TQT_SLOT(sizeChange(int, int))); |
| 132 |
connect(_grid, TQT_SIGNAL(needPainting()), TQT_SLOT(paintGrid())); |
| 133 |
connect( _grid, TQT_SIGNAL(xposchanged(int)), _hruler, TQT_SLOT(slotNewValue(int)) ); |
| 134 |
connect( _grid, TQT_SIGNAL(yposchanged(int)), _vruler, TQT_SLOT(slotNewValue(int)) ); |
| 135 |
connect(viewport, TQT_SIGNAL(contentsMoving(int, int)), TQT_SLOT(moving(int, int))); |
| 136 |
|
| 137 |
setSizes(); |
| 138 |
TQResizeEvent e(size(), size()); |
| 139 |
resizeEvent(&e); |
| 140 |
} |
| 141 |
|
| 142 |
void KGridView::paintGrid() |
| 143 |
{ |
| 144 |
_grid->update(viewRect()); |
| 145 |
} |
| 146 |
|
| 147 |
void KGridView::setSizes() |
| 148 |
{ |
| 149 |
if(TDEIconEditProperties::self()->showRulers()) |
| 150 |
{ |
| 151 |
_hruler->setLittleMarkDistance(_grid->scaling()); |
| 152 |
_vruler->setLittleMarkDistance(_grid->scaling()); |
| 153 |
|
| 154 |
_hruler->setMediumMarkDistance(5); |
| 155 |
_vruler->setMediumMarkDistance(5); |
| 156 |
|
| 157 |
_hruler->setBigMarkDistance(10); |
| 158 |
_vruler->setBigMarkDistance(10); |
| 159 |
|
| 160 |
_hruler->setShowTinyMarks(true); |
| 161 |
_hruler->setShowLittleMarks(false); |
| 162 |
_hruler->setShowMediumMarks(true); |
| 163 |
_hruler->setShowBigMarks(true); |
| 164 |
_hruler->setShowEndMarks(true); |
| 165 |
|
| 166 |
_vruler->setShowTinyMarks(true); |
| 167 |
_vruler->setShowLittleMarks(false); |
| 168 |
_vruler->setShowMediumMarks(true); |
| 169 |
_vruler->setShowBigMarks(true); |
| 170 |
_vruler->setShowEndMarks(true); |
| 171 |
|
| 172 |
_hruler->setPixelPerMark(_grid->scaling()); |
| 173 |
_vruler->setPixelPerMark(_grid->scaling()); |
| 174 |
|
| 175 |
_hruler->setMaxValue(_grid->width()+20); |
| 176 |
_vruler->setMaxValue(_grid->height()+20); |
| 177 |
|
| 178 |
_hruler->show(); |
| 179 |
_vruler->show(); |
| 180 |
|
| 181 |
_corner->show(); |
| 182 |
//resize(_grid->width()+_vruler->width(), _grid->height()+_hruler->height()); |
| 183 |
} |
| 184 |
else |
| 185 |
{ |
| 186 |
_hruler->hide(); |
| 187 |
_vruler->hide(); |
| 188 |
_corner->hide(); |
| 189 |
//resize(_grid->size()); |
| 190 |
} |
| 191 |
} |
| 192 |
|
| 193 |
void KGridView::sizeChange(int, int) |
| 194 |
{ |
| 195 |
setSizes(); |
| 196 |
} |
| 197 |
|
| 198 |
void KGridView::moving(int x, int y) |
| 199 |
{ |
| 200 |
_hruler->setOffset(abs(x)); |
| 201 |
_vruler->setOffset(abs(y)); |
| 202 |
} |
| 203 |
|
| 204 |
void KGridView::scalingChange(int) |
| 205 |
{ |
| 206 |
setSizes(); |
| 207 |
} |
| 208 |
|
| 209 |
void KGridView::setShowRulers(bool mode) |
| 210 |
{ |
| 211 |
TDEIconEditProperties::self()->setShowRulers( mode ); |
| 212 |
setSizes(); |
| 213 |
TQResizeEvent e(size(), size()); |
| 214 |
resizeEvent(&e); |
| 215 |
} |
| 216 |
|
| 217 |
void KGridView::setAcceptDrop(bool a) |
| 218 |
{ |
| 219 |
if(a == acceptdrop) return; |
| 220 |
acceptdrop = a; |
| 221 |
paintDropSite(); |
| 222 |
} |
| 223 |
|
| 224 |
void KGridView::checkClipboard() |
| 225 |
{ |
| 226 |
_grid->checkClipboard(); |
| 227 |
} |
| 228 |
|
| 229 |
const TQRect KGridView::viewRect() |
| 230 |
{ |
| 231 |
int x, y, cx, cy; |
| 232 |
if(viewport->horizontalScrollBar()->isVisible()) |
| 233 |
{ |
| 234 |
x = viewport->contentsX(); |
| 235 |
cx = viewport->viewport()->width(); |
| 236 |
} |
| 237 |
else |
| 238 |
{ |
| 239 |
x = 0; |
| 240 |
cx = viewport->contentsWidth(); |
| 241 |
} |
| 242 |
|
| 243 |
if(viewport->verticalScrollBar()->isVisible()) |
| 244 |
{ |
| 245 |
y = viewport->contentsY(); |
| 246 |
cy = viewport->viewport()->height(); |
| 247 |
} |
| 248 |
else |
| 249 |
{ |
| 250 |
y = 0; |
| 251 |
cy = viewport->contentsHeight(); |
| 252 |
} |
| 253 |
|
| 254 |
return TQRect(x, y, cx, cy); |
| 255 |
} |
| 256 |
|
| 257 |
void KGridView::paintDropSite() |
| 258 |
{ |
| 259 |
TQPainter p; |
| 260 |
p.begin( _grid ); |
| 261 |
p.setRasterOp (NotROP); |
| 262 |
p.drawRect(viewRect()); |
| 263 |
p.end(); |
| 264 |
} |
| 265 |
|
| 266 |
void KGridView::paintEvent(TQPaintEvent *) |
| 267 |
{ |
| 268 |
if(acceptdrop) |
| 269 |
paintDropSite(); |
| 270 |
} |
| 271 |
|
| 272 |
|
| 273 |
void KGridView::resizeEvent(TQResizeEvent*) |
| 274 |
{ |
| 275 |
kdDebug(4640) << "KGridView::resizeEvent" << endl; |
| 276 |
|
| 277 |
setSizes(); |
| 278 |
|
| 279 |
if(TDEIconEditProperties::self()->showRulers()) |
| 280 |
{ |
| 281 |
_hruler->setGeometry(_vruler->width(), 0, width(), _hruler->height()); |
| 282 |
_vruler->setGeometry(0, _hruler->height(), _vruler->width(), height()); |
| 283 |
|
| 284 |
_corner->setGeometry(0, 0, _vruler->width(), _hruler->height()); |
| 285 |
viewport->setGeometry(_corner->width(), _corner->height(), |
| 286 |
width()-_corner->width(), height()-_corner->height()); |
| 287 |
} |
| 288 |
else |
| 289 |
viewport->setGeometry(0, 0, width(), height()); |
| 290 |
} |
| 291 |
|
| 292 |
|
| 293 |
TDEIconEditGrid::TDEIconEditGrid(TQImage *image, KCommandHistory* h, TQWidget *parent, const char *name) |
| 294 |
: KColorGrid(parent, name, 1) |
| 295 |
{ |
| 296 |
img = image; |
| 297 |
history = h; |
| 298 |
selected = 0; |
| 299 |
m_command = 0; |
| 300 |
|
| 301 |
// the 42 normal kde colors - there can be an additional |
| 302 |
// 18 custom colors in the custom colors palette |
| 303 |
for(uint i = 0; i < 42; i++) |
| 304 |
iconcolors.append(iconpalette[i]); |
| 305 |
|
| 306 |
setupImageHandlers(); |
| 307 |
btndown = isselecting = ispasting = modified = false; |
| 308 |
|
| 309 |
img->create(32, 32, 32); |
| 310 |
img->setAlphaBuffer(true); |
| 311 |
clearImage(img); |
| 312 |
|
| 313 |
currentcolor = tqRgb(0,0,0)|OPAQUE_MASK; |
| 314 |
emit colorSelected(currentcolor); |
| 315 |
|
| 316 |
setMouseTracking(true); |
| 317 |
|
| 318 |
setNumRows(32); |
| 319 |
setNumCols(32); |
| 320 |
fill(TRANSPARENT); |
| 321 |
|
| 322 |
connect( kapp->clipboard(), TQT_SIGNAL(dataChanged()), TQT_SLOT(checkClipboard())); |
| 323 |
connect( h, TQT_SIGNAL(commandExecuted()), this, TQT_SLOT(updatePreviewPixmap() )); |
| 324 |
createCursors(); |
| 325 |
|
| 326 |
TDEIconEditProperties *props = TDEIconEditProperties::self(); |
| 327 |
|
| 328 |
setTransparencyDisplayType(props->transparencyDisplayType()); |
| 329 |
setTransparencySolidColor(props->transparencySolidColor()); |
| 330 |
setCheckerboardColor1(props->checkerboardColor1()); |
| 331 |
setCheckerboardColor2(props->checkerboardColor2()); |
| 332 |
setCheckerboardSize(props->checkerboardSize()); |
| 333 |
} |
| 334 |
|
| 335 |
TDEIconEditGrid::~TDEIconEditGrid() |
| 336 |
{ |
| 337 |
kdDebug(4640) << "TDEIconEditGrid - destructor: done" << endl; |
| 338 |
} |
| 339 |
|
| 340 |
void TDEIconEditGrid::paintEvent(TQPaintEvent *e) |
| 341 |
{ |
| 342 |
const TQRect cellsRect(0, 0, numCols() * cellSize(), numRows() * cellSize()); |
| 343 |
const TQRect paintCellsRect = cellsRect.intersect(e->rect()); |
| 344 |
|
| 345 |
if(!paintCellsRect.isEmpty()) |
| 346 |
{ |
| 347 |
//TQTime time; |
| 348 |
|
| 349 |
//time.start(); |
| 350 |
|
| 351 |
TQRgb *imageBuffer = new TQRgb[paintCellsRect.width() * paintCellsRect.height()]; |
| 352 |
const int cellsize = cellSize(); |
| 353 |
const int firstCellPixelsRemaining = cellsize - paintCellsRect.left() % cellsize; |
| 354 |
|
| 355 |
if(transparencyDisplayType() == TRD_SOLIDCOLOR) |
| 356 |
{ |
| 357 |
const TQRgb backgroundColor = transparencySolidColor().rgb(); |
| 358 |
const int backgroundRed = transparencySolidColor().red(); |
| 359 |
const int backgroundGreen = transparencySolidColor().green(); |
| 360 |
const int backgroundBlue = transparencySolidColor().blue(); |
| 361 |
const int firstCellX = paintCellsRect.left() / cellsize; |
| 362 |
|
| 363 |
for(int y = paintCellsRect.top(); y <= paintCellsRect.bottom(); y++) |
| 364 |
{ |
| 365 |
TQRgb *dest = imageBuffer + (y - paintCellsRect.top()) * paintCellsRect.width(); |
| 366 |
|
| 367 |
if(y % cellsize == 0 || dest == imageBuffer) |
| 368 |
{ |
| 369 |
// Paint the first scanline in each block of cellSize() identical lines. |
| 370 |
// The remaineder can just be copied from this one. |
| 371 |
const int cellY = y / cellsize; |
| 372 |
TQRgb *src = gridcolors.data() + cellY * numCols() + firstCellX; |
| 373 |
|
| 374 |
TQRgb sourcePixel = *src++; |
| 375 |
int sourceAlpha = tqAlpha(sourcePixel); |
| 376 |
|
| 377 |
TQRgb c; |
| 378 |
|
| 379 |
if(sourceAlpha == 255) |
| 380 |
{ |
| 381 |
c = sourcePixel; |
| 382 |
} |
| 383 |
else |
| 384 |
if(sourceAlpha == 0) |
| 385 |
{ |
| 386 |
c = backgroundColor; |
| 387 |
} |
| 388 |
else |
| 389 |
{ |
| 390 |
const int sourceRed = tqRed(sourcePixel); |
| 391 |
const int sourceGreen = tqGreen(sourcePixel); |
| 392 |
const int sourceBlue = tqBlue(sourcePixel); |
| 393 |
|
| 394 |
int r = (sourceAlpha * (sourceRed - backgroundRed)) + 0x80; |
| 395 |
r = backgroundRed + ((r + (r >> 8)) >> 8); |
| 396 |
|
| 397 |
int g = (sourceAlpha * (sourceGreen - backgroundGreen)) + 0x80; |
| 398 |
g = backgroundGreen + ((g + (g >> 8)) >> 8); |
| 399 |
|
| 400 |
int b = (sourceAlpha * (sourceBlue - backgroundBlue)) + 0x80; |
| 401 |
b = backgroundBlue + ((b + (b >> 8)) >> 8); |
| 402 |
|
| 403 |
c = tqRgb(r, g, b); |
| 404 |
} |
| 405 |
|
| 406 |
int cellPixelsRemaining = firstCellPixelsRemaining; |
| 407 |
|
| 408 |
for(int x = paintCellsRect.left(); x <= paintCellsRect.right(); x++) |
| 409 |
{ |
| 410 |
if(cellPixelsRemaining == 0) |
| 411 |
{ |
| 412 |
cellPixelsRemaining = cellsize; |
| 413 |
|
| 414 |
// Fetch the next source pixel |
| 415 |
sourcePixel = *src++; |
| 416 |
sourceAlpha = tqAlpha(sourcePixel); |
| 417 |
|
| 418 |
if(sourceAlpha == 255) |
| 419 |
{ |
| 420 |
c = sourcePixel; |
| 421 |
} |
| 422 |
else |
| 423 |
if(sourceAlpha == 0) |
| 424 |
{ |
| 425 |
c = backgroundColor; |
| 426 |
} |
| 427 |
else |
| 428 |
{ |
| 429 |
const int sourceRed = tqRed(sourcePixel); |
| 430 |
const int sourceGreen = tqGreen(sourcePixel); |
| 431 |
const int sourceBlue = tqBlue(sourcePixel); |
| 432 |
|
| 433 |
//int r = backgroundRed + (sourceAlpha * (sourceRed - backgroundRed)) / 255; |
| 434 |
//int g = backgroundGreen + (sourceAlpha * (sourceGreen - backgroundGreen)) / 255; |
| 435 |
//int b = backgroundBlue + (sourceAlpha * (sourceBlue - backgroundBlue)) / 255; |
| 436 |
|
| 437 |
int r = (sourceAlpha * (sourceRed - backgroundRed)) + 0x80; |
| 438 |
r = backgroundRed + ((r + (r >> 8)) >> 8); |
| 439 |
|
| 440 |
int g = (sourceAlpha * (sourceGreen - backgroundGreen)) + 0x80; |
| 441 |
g = backgroundGreen + ((g + (g >> 8)) >> 8); |
| 442 |
|
| 443 |
int b = (sourceAlpha * (sourceBlue - backgroundBlue)) + 0x80; |
| 444 |
b = backgroundBlue + ((b + (b >> 8)) >> 8); |
| 445 |
|
| 446 |
c = tqRgb(r, g, b); |
| 447 |
} |
| 448 |
} |
| 449 |
|
| 450 |
cellPixelsRemaining--; |
| 451 |
|
| 452 |
*dest++ = c; |
| 453 |
} |
| 454 |
} |
| 455 |
else |
| 456 |
{ |
| 457 |
// Copy the scanline above. |
| 458 |
memcpy(dest, dest - paintCellsRect.width(), paintCellsRect.width() * sizeof(TQRgb)); |
| 459 |
} |
| 460 |
} |
| 461 |
} |
| 462 |
else |
| 463 |
{ |
| 464 |
int squareSize; |
| 465 |
const int fixedPointMultiplier = 4; |
| 466 |
|
| 467 |
if(checkerboardSize() == CHK_SMALL) |
| 468 |
{ |
| 469 |
squareSize = (cellSize() * fixedPointMultiplier) / 4; |
| 470 |
} |
| 471 |
else |
| 472 |
if(checkerboardSize() == CHK_MEDIUM) |
| 473 |
{ |
| 474 |
squareSize = (cellSize() * fixedPointMultiplier) / 2; |
| 475 |
} |
| 476 |
else |
| 477 |
{ |
| 478 |
squareSize = (2 * cellSize() * fixedPointMultiplier) / 2; |
| 479 |
} |
| 480 |
|
| 481 |
TQRgb *color1ScanLine = new TQRgb[paintCellsRect.width()]; |
| 482 |
TQRgb *color2ScanLine = new TQRgb[paintCellsRect.width()]; |
| 483 |
TQRgb *color1Buffer = color1ScanLine; |
| 484 |
TQRgb *color2Buffer = color2ScanLine; |
| 485 |
|
| 486 |
for(int x = paintCellsRect.left(); x <= paintCellsRect.right(); x++) |
| 487 |
{ |
| 488 |
if((((x * fixedPointMultiplier) / squareSize) & 1) == 0) |
| 489 |
{ |
| 490 |
*color1Buffer++ = checkerboardColor1().rgb(); |
| 491 |
*color2Buffer++ = checkerboardColor2().rgb(); |
| 492 |
} |
| 493 |
else |
| 494 |
{ |
| 495 |
*color1Buffer++ = checkerboardColor2().rgb(); |
| 496 |
*color2Buffer++ = checkerboardColor1().rgb(); |
| 497 |
} |
| 498 |
} |
| 499 |
|
| 500 |
const int firstCellX = paintCellsRect.left() / cellsize; |
| 501 |
const int firstCellPixelsRemaining = cellsize - paintCellsRect.left() % cellsize; |
| 502 |
int lastCellY = -1; |
| 503 |
int lastLineFirstSquareColour = 0; |
| 504 |
|
| 505 |
for(int y = paintCellsRect.top(); y <= paintCellsRect.bottom(); y++) |
| 506 |
{ |
| 507 |
TQRgb *dest = imageBuffer + (y - paintCellsRect.top()) * paintCellsRect.width(); |
| 508 |
const int cellY = y / cellsize; |
| 509 |
|
| 510 |
int firstSquareColour; |
| 511 |
const TQRgb *checkerboardSrc; |
| 512 |
|
| 513 |
if((((y * fixedPointMultiplier) / squareSize) & 1) == 0) |
| 514 |
{ |
| 515 |
firstSquareColour = 1; |
| 516 |
checkerboardSrc = color1ScanLine; |
| 517 |
} |
| 518 |
else |
| 519 |
{ |
| 520 |
firstSquareColour = 2; |
| 521 |
checkerboardSrc = color2ScanLine; |
| 522 |
} |
| 523 |
|
| 524 |
if(cellY == lastCellY && firstSquareColour == lastLineFirstSquareColour) |
| 525 |
{ |
| 526 |
// Copy the scanline above. |
| 527 |
memcpy(dest, dest - paintCellsRect.width(), paintCellsRect.width() * sizeof(TQRgb)); |
| 528 |
} |
| 529 |
else |
| 530 |
{ |
| 531 |
TQRgb *src = gridcolors.data() + cellY * numCols() + firstCellX; |
| 532 |
|
| 533 |
TQRgb sourcePixel = *src++; |
| 534 |
int sourceRed = tqRed(sourcePixel); |
| 535 |
int sourceGreen = tqGreen(sourcePixel); |
| 536 |
int sourceBlue = tqBlue(sourcePixel); |
| 537 |
int sourceAlpha = tqAlpha(sourcePixel); |
| 538 |
|
| 539 |
int cellPixelsRemaining = firstCellPixelsRemaining; |
| 540 |
|
| 541 |
for(int x = paintCellsRect.left(); x <= paintCellsRect.right(); x++) |
| 542 |
{ |
| 543 |
if(cellPixelsRemaining == 0) |
| 544 |
{ |
| 545 |
cellPixelsRemaining = cellsize; |
| 546 |
|
| 547 |
// Fetch the next source pixel |
| 548 |
sourcePixel = *src++; |
| 549 |
sourceRed = tqRed(sourcePixel); |
| 550 |
sourceGreen = tqGreen(sourcePixel); |
| 551 |
sourceBlue = tqBlue(sourcePixel); |
| 552 |
sourceAlpha = tqAlpha(sourcePixel); |
| 553 |
} |
| 554 |
|
| 555 |
cellPixelsRemaining--; |
| 556 |
|
| 557 |
TQRgb c; |
| 558 |
|
| 559 |
if(sourceAlpha == 255) |
| 560 |
{ |
| 561 |
c = sourcePixel; |
| 562 |
} |
| 563 |
else |
| 564 |
if(sourceAlpha == 0) |
| 565 |
{ |
| 566 |
c = *checkerboardSrc; |
| 567 |
} |
| 568 |
else |
| 569 |
{ |
| 570 |
const int backgroundColor = *checkerboardSrc; |
| 571 |
const int backgroundRed = tqRed(backgroundColor); |
| 572 |
const int backgroundGreen = tqGreen(backgroundColor); |
| 573 |
const int backgroundBlue = tqBlue(backgroundColor); |
| 574 |
|
| 575 |
//int r = backgroundRed + (sourceAlpha * (sourceRed - backgroundRed)) / 255; |
| 576 |
//int g = backgroundGreen + (sourceAlpha * (sourceGreen - backgroundGreen)) / 255; |
| 577 |
//int b = backgroundBlue + (sourceAlpha * (sourceBlue - backgroundBlue)) / 255; |
| 578 |
|
| 579 |
int r = (sourceAlpha * (sourceRed - backgroundRed)) + 0x80; |
| 580 |
r = backgroundRed + ((r + (r >> 8)) >> 8); |
| 581 |
|
| 582 |
int g = (sourceAlpha * (sourceGreen - backgroundGreen)) + 0x80; |
| 583 |
g = backgroundGreen + ((g + (g >> 8)) >> 8); |
| 584 |
|
| 585 |
int b = (sourceAlpha * (sourceBlue - backgroundBlue)) + 0x80; |
| 586 |
b = backgroundBlue + ((b + (b >> 8)) >> 8); |
| 587 |
|
| 588 |
c = tqRgb(r, g, b); |
| 589 |
} |
| 590 |
|
| 591 |
*dest++ = c; |
| 592 |
checkerboardSrc++; |
| 593 |
} |
| 594 |
} |
| 595 |
|
| 596 |
lastCellY = cellY; |
| 597 |
lastLineFirstSquareColour = firstSquareColour; |
| 598 |
} |
| 599 |
|
| 600 |
delete [] color1ScanLine; |
| 601 |
delete [] color2ScanLine; |
| 602 |
} |
| 603 |
|
| 604 |
TQImage image((uchar *)(imageBuffer), paintCellsRect.width(), paintCellsRect.height(), 32, 0, 0, |
| 605 |
#if X_BYTE_ORDER == X_LITTLE_ENDIAN |
| 606 |
TQImage::LittleEndian); |
| 607 |
#else |
| 608 |
TQImage::BigEndian); |
| 609 |
#endif |
| 610 |
Q_ASSERT(!image.isNull()); |
| 611 |
|
| 612 |
TQPixmap _pixmap; |
| 613 |
_pixmap.convertFromImage(image); |
| 614 |
|
| 615 |
TQPainter p; |
| 616 |
p.begin(&_pixmap); |
| 617 |
paintForeground(&p, e); |
| 618 |
p.end(); |
| 619 |
|
| 620 |
bitBlt(this, paintCellsRect.left(), paintCellsRect.top(), &_pixmap); |
| 621 |
|
| 622 |
//kdDebug(4640) << "Image render elapsed: " << time.elapsed() << endl; |
| 623 |
|
| 624 |
delete [] imageBuffer; |
| 625 |
} |
| 626 |
} |
| 627 |
|
| 628 |
void TDEIconEditGrid::paintForeground(TQPainter* p, TQPaintEvent* e) |
| 629 |
{ |
| 630 |
TQWMatrix matrix; |
| 631 |
|
| 632 |
matrix.translate(-e->rect().x(), -e->rect().y()); |
| 633 |
p->setWorldMatrix( matrix ); |
| 634 |
|
| 635 |
TQRect cellsRect(0, 0, numCols() * cellSize(), numRows() * cellSize()); |
| 636 |
TQRect paintCellsRect = cellsRect.intersect(e->rect()); |
| 637 |
|
| 638 |
if(!paintCellsRect.isEmpty()) |
| 639 |
{ |
| 640 |
int firstColumn = paintCellsRect.left() / cellSize(); |
| 641 |
int lastColumn = paintCellsRect.right() / cellSize(); |
| 642 |
|
| 643 |
int firstRow = paintCellsRect.top() / cellSize(); |
| 644 |
int lastRow = paintCellsRect.bottom() / cellSize(); |
| 645 |
|
| 646 |
p->setPen(TQColor(0, 0, 0)); |
| 647 |
p->setBrush(TQColor(0, 0, 0)); |
| 648 |
|
| 649 |
for(int column = firstColumn; column <= lastColumn; column++) |
| 650 |
{ |
| 651 |
for(int row = firstRow; row <= lastRow; row++) |
| 652 |
{ |
| 653 |
int x = column * cellSize(); |
| 654 |
int y = row * cellSize(); |
| 655 |
|
| 656 |
if((ispasting || isselecting) && isMarked(column, row)) |
| 657 |
{ |
| 658 |
p->drawWinFocusRect(x + 1, y + 1, cellSize() - 2, cellSize() - 2); |
| 659 |
} |
| 660 |
else |
| 661 |
{ |
| 662 |
switch( tool ) |
| 663 |
{ |
| 664 |
case FilledRect: |
| 665 |
case Rect: |
| 666 |
case Ellipse: |
| 667 |
case Circle: |
| 668 |
case FilledEllipse: |
| 669 |
case FilledCircle: |
| 670 |
case Line: |
| 671 |
if(btndown && isMarked(column, row)) |
| 672 |
{ |
| 673 |
if(cellSize() > 1) |
| 674 |
{ |
| 675 |
p->drawWinFocusRect( x + 1, y + 1, cellSize() - 2, cellSize() - 2); |
| 676 |
} |
| 677 |
else |
| 678 |
{ |
| 679 |
p->drawPoint(x, y); |
| 680 |
} |
| 681 |
} |
| 682 |
break; |
| 683 |
|
| 684 |
default: |
| 685 |
break; |
| 686 |
} |
| 687 |
} |
| 688 |
} |
| 689 |
} |
| 690 |
} |
| 691 |
|
| 692 |
if(hasGrid()&& !(cellSize()==1)) |
| 693 |
{ |
| 694 |
p->setPen(TQColor(0, 0, 0)); |
| 695 |
int x = e->rect().x() - ((e->rect().x() % cellSize()) + cellSize()); |
| 696 |
if(x < 0) x = 0; |
| 697 |
int y = e->rect().y() - ((e->rect().y() % cellSize()) + cellSize()); |
| 698 |
if(y < 0) y = 0; |
| 699 |
int cx = e->rect().right() + cellSize(); |
| 700 |
int cy = e->rect().bottom() + cellSize(); |
| 701 |
|
| 702 |
// draw grid lines |
| 703 |
for(int i = x; i < cx; i += cellSize()) |
| 704 |
p->drawLine(i, y, i, cy); |
| 705 |
|
| 706 |
for(int i = y; i < cy; i += cellSize()) |
| 707 |
p->drawLine(x, i, cx, i); |
| 708 |
} |
| 709 |
} |
| 710 |
|
| 711 |
void TDEIconEditGrid::mousePressEvent( TQMouseEvent *e ) |
| 712 |
{ |
| 713 |
if(!e || (e->button() != Qt::LeftButton)) |
| 714 |
return; |
| 715 |
|
| 716 |
int row = findRow( e->pos().y() ); |
| 717 |
int col = findCol( e->pos().x() ); |
| 718 |
//int cell = row * numCols() + col; |
| 719 |
|
| 720 |
if(!img->valid(col, row)) |
| 721 |
return; |
| 722 |
|
| 723 |
btndown = true; |
| 724 |
start.setX(col); |
| 725 |
start.setY(row); |
| 726 |
|
| 727 |
if(ispasting) |
| 728 |
{ |
| 729 |
ispasting = false; |
| 730 |
editPaste(true); |
| 731 |
} |
| 732 |
|
| 733 |
if(isselecting) |
| 734 |
{ |
| 735 |
TQPointArray a(pntarray.copy()); |
| 736 |
pntarray.resize(0); |
| 737 |
drawPointArray(a, Mark); |
| 738 |
emit selecteddata(false); |
| 739 |
} |
| 740 |
|
| 741 |
switch( tool ) |
| 742 |
{ |
| 743 |
case SelectRect: |
| 744 |
case SelectCircle: |
| 745 |
isselecting = true; |
| 746 |
break; |
| 747 |
default: |
| 748 |
break; |
| 749 |
} |
| 750 |
} |
| 751 |
|
| 752 |
void TDEIconEditGrid::mouseMoveEvent( TQMouseEvent *e ) |
| 753 |
{ |
| 754 |
if(!e) return; |
| 755 |
|
| 756 |
int row = findRow( e->pos().y() ); |
| 757 |
int col = findCol( e->pos().x() ); |
| 758 |
int cell = row * numCols() + col; |
| 759 |
|
| 760 |
if(img->valid(col, row)) |
| 761 |
{ |
| 762 |
//kdDebug(4640) << col << " X " << row << endl; |
| 763 |
emit poschanged(col, row); |
| 764 |
// for the rulers |
| 765 |
emit xposchanged((col*scaling())+scaling()/2); |
| 766 |
emit yposchanged((row*scaling())+scaling()/2); |
| 767 |
} |
| 768 |
|
| 769 |
TQPoint tmpp(col, row); |
| 770 |
if(tmpp == end) return; |
| 771 |
|
| 772 |
// need to use intersection of rectangles to allow pasting |
| 773 |
// only that part of clip image which intersects -jwc- |
| 774 |
if(ispasting && !btndown && img->valid(col, row)) |
| 775 |
{ |
| 776 |
if( (col + cbsize.width()) > (numCols()-1) ) |
| 777 |
insrect.setX(numCols()-insrect.width()); |
| 778 |
else |
| 779 |
insrect.setX(col); |
| 780 |
if( (row + cbsize.height()) > (numRows()-1) ) |
| 781 |
insrect.setY(numRows()-insrect.height()); |
| 782 |
else |
| 783 |
insrect.setY(row); |
| 784 |
|
| 785 |
insrect.setSize(cbsize); |
| 786 |
start = insrect.topLeft(); |
| 787 |
end = insrect.bottomRight(); |
| 788 |
drawRect(false); |
| 789 |
return; |
| 790 |
} |
| 791 |
|
| 792 |
if(!img->valid(col, row) || !btndown) |
| 793 |
return; |
| 794 |
|
| 795 |
end.setX(col); |
| 796 |
end.setY(row); |
| 797 |
|
| 798 |
if(isselecting) |
| 799 |
{ |
| 800 |
if(tool == SelectRect) |
| 801 |
drawRect(false); |
| 802 |
else |
| 803 |
drawEllipse(false); |
| 804 |
return; |
| 805 |
} |
| 806 |
|
| 807 |
bool erase=false; |
| 808 |
switch( tool ) |
| 809 |
{ |
| 810 |
case Eraser: |
| 811 |
erase=true; |
| 812 |
|
| 813 |
case Freehand: |
| 814 |
{ |
| 815 |
if( !m_command ) |
| 816 |
m_command = new KMacroCommand( i18n("Free Hand") ); |
| 817 |
|
| 818 |
if(erase) |
| 819 |
setColor( cell, TRANSPARENT ); |
| 820 |
else |
| 821 |
setColor( cell, currentcolor ); |
| 822 |
|
| 823 |
if ( selected != cell ) |
| 824 |
{ |
| 825 |
setModified( true ); |
| 826 |
int prevSel = selected; |
| 827 |
selected = cell; |
| 828 |
TQRect area = TQRect( col*cellsize,row*cellsize, cellsize, cellsize ).unite( |
| 829 |
TQRect ( (prevSel%numCols())*cellsize,(prevSel/numCols())*cellsize, cellsize, cellsize ) ); |
| 830 |
|
| 831 |
m_command->addCommand( new RepaintCommand( area, this ) ); |
| 832 |
DrawCommand* dc = new DrawCommand( col, row, colorAt(cell), img, this ); |
| 833 |
RepaintCommand* rp = new RepaintCommand( area, this ); |
| 834 |
dc->execute(); |
| 835 |
rp->execute(); |
| 836 |
m_command->addCommand( dc ); |
| 837 |
m_command->addCommand( rp ); |
| 838 |
} |
| 839 |
break; |
| 840 |
} |
| 841 |
case Find: |
| 842 |
{ |
| 843 |
iconcolors.closestMatch(colorAt(cell)); |
| 844 |
if ( selected != cell ) |
| 845 |
{ |
| 846 |
int prevSel = selected; |
| 847 |
selected = cell; |
| 848 |
update((prevSel%numCols())*cellsize,(prevSel/numCols())*cellsize, cellsize, cellsize); |
| 849 |
update(col*cellsize,row*cellsize, cellsize, cellsize); |
| 850 |
emit colorSelected(colorAt(selected)); |
| 851 |
} |
| 852 |
break; |
| 853 |
} |
| 854 |
case Ellipse: |
| 855 |
case Circle: |
| 856 |
case FilledEllipse: |
| 857 |
case FilledCircle: |
| 858 |
{ |
| 859 |
drawEllipse(false); |
| 860 |
break; |
| 861 |
} |
| 862 |
case FilledRect: |
| 863 |
case Rect: |
| 864 |
{ |
| 865 |
drawRect(false); |
| 866 |
break; |
| 867 |
} |
| 868 |
case Line: |
| 869 |
{ |
| 870 |
drawLine(false, false); |
| 871 |
break; |
| 872 |
} |
| 873 |
case Spray: |
| 874 |
{ |
| 875 |
drawSpray(TQPoint(col, row)); |
| 876 |
setModified(true); |
| 877 |
break; |
| 878 |
} |
| 879 |
default: |
| 880 |
break; |
| 881 |
} |
| 882 |
|
| 883 |
p = *img; |
| 884 |
emit changed(TQPixmap(p)); |
| 885 |
} |
| 886 |
|
| 887 |
void TDEIconEditGrid::mouseReleaseEvent( TQMouseEvent *e ) |
| 888 |
{ |
| 889 |
if(!e || (e->button() != Qt::LeftButton)) |
| 890 |
return; |
| 891 |
|
| 892 |
int row = findRow( e->pos().y() ); |
| 893 |
int col = findCol( e->pos().x() ); |
| 894 |
btndown = false; |
| 895 |
end.setX(col); |
| 896 |
end.setY(row); |
| 897 |
int cell = row * numCols() + col; |
| 898 |
bool erase=false; |
| 899 |
switch( tool ) |
| 900 |
{ |
| 901 |
case Eraser: |
| 902 |
erase=true; |
| 903 |
//currentcolor = TRANSPARENT; |
| 904 |
case Freehand: |
| 905 |
{ |
| 906 |
if(!img->valid(col, row)) |
| 907 |
return; |
| 908 |
if(erase) |
| 909 |
setColor( cell, TRANSPARENT ); |
| 910 |
else |
| 911 |
setColor( cell, currentcolor ); |
| 912 |
//if ( selected != cell ) |
| 913 |
//{ |
| 914 |
setModified( true ); |
| 915 |
int prevSel = selected; |
| 916 |
selected = cell; |
| 917 |
update((prevSel%numCols())*cellsize,(prevSel/numCols())*cellsize, cellsize, cellsize); |
| 918 |
update(col*cellsize,row*cellsize, cellsize, cellsize); |
| 919 |
//updateCell( prevSel/numCols(), prevSel%numCols(), FALSE ); |
| 920 |
//updateCell( row, col, FALSE ); |
| 921 |
*((uint*)img->scanLine(row) + col) = colorAt(cell); |
| 922 |
p = *img; |
| 923 |
//} |
| 924 |
|
| 925 |
if( m_command ) { |
| 926 |
history->addCommand( m_command, false ); |
| 927 |
m_command = 0; |
| 928 |
} |
| 929 |
|
| 930 |
break; |
| 931 |
} |
| 932 |
case Ellipse: |
| 933 |
case Circle: |
| 934 |
case FilledEllipse: |
| 935 |
case FilledCircle: |
| 936 |
{ |
| 937 |
drawEllipse(true); |
| 938 |
break; |
| 939 |
} |
| 940 |
case FilledRect: |
| 941 |
case Rect: |
| 942 |
{ |
| 943 |
drawRect(true); |
| 944 |
break; |
| 945 |
} |
| 946 |
case Line: |
| 947 |
{ |
| 948 |
drawLine(true, false); |
| 949 |
break; |
| 950 |
} |
| 951 |
case Spray: |
| 952 |
{ |
| 953 |
drawSpray(TQPoint(col, row)); |
| 954 |
break; |
| 955 |
} |
| 956 |
case FloodFill: |
| 957 |
{ |
| 958 |
TQApplication::setOverrideCursor(waitCursor); |
| 959 |
drawFlood(col, row, colorAt(cell)); |
| 960 |
TQApplication::restoreOverrideCursor(); |
| 961 |
updateColors(); |
| 962 |
emit needPainting(); |
| 963 |
p = *img; |
| 964 |
break; |
| 965 |
} |
| 966 |
case Find: |
| 967 |
{ |
| 968 |
currentcolor = colorAt(cell); |
| 969 |
if ( selected != cell ) |
| 970 |
{ |
| 971 |
int prevSel = selected; |
| 972 |
selected = cell; |
| 973 |
update((prevSel%numCols())*cellsize,(prevSel/numCols())*cellsize, cellsize, cellsize); |
| 974 |
update(col*cellsize,row*cellsize, cellsize, cellsize); |
| 975 |
emit colorSelected(currentcolor); |
| 976 |
//updateCell( prevSel/numCols(), prevSel%numCols(), FALSE ); |
| 977 |
//updateCell( row, col, FALSE ); |
| 978 |
} |
| 979 |
|
| 980 |
break; |
| 981 |
} |
| 982 |
default: |
| 983 |
break; |
| 984 |
} |
| 985 |
|
| 986 |
emit changed(TQPixmap(p)); |
| 987 |
//emit colorschanged(numColors(), data()); |
| 988 |
} |
| 989 |
|
| 990 |
//void TDEIconEditGrid::setColorSelection( const TQColor &color ) |
| 991 |
void TDEIconEditGrid::setColorSelection( uint c ) |
| 992 |
{ |
| 993 |
currentcolor = c; |
| 994 |
emit colorSelected(currentcolor); |
| 995 |
} |
| 996 |
|
| 997 |
void TDEIconEditGrid::loadBlank( int w, int h ) |
| 998 |
{ |
| 999 |
img->create(w, h, 32); |
| 1000 |
img->setAlphaBuffer(true); |
| 1001 |
clearImage(img); |
| 1002 |
setNumRows(h); |
| 1003 |
setNumCols(w); |
| 1004 |
fill(TRANSPARENT); |
| 1005 |
emit sizechanged(numCols(), numRows()); |
| 1006 |
emit colorschanged(numColors(), data()); |
| 1007 |
history->clear(); |
| 1008 |
} |
| 1009 |
|
| 1010 |
|
| 1011 |
|
| 1012 |
void TDEIconEditGrid::load( TQImage *image) |
| 1013 |
{ |
| 1014 |
kdDebug(4640) << "TDEIconEditGrid::load" << endl; |
| 1015 |
|
| 1016 |
setUpdatesEnabled(false); |
| 1017 |
|
| 1018 |
if(image == 0L) |
| 1019 |
{ |
| 1020 |
TQString msg = i18n("There was an error loading a blank image.\n"); |
| 1021 |
KMessageBox::error(this, msg); |
| 1022 |
return; |
| 1023 |
} |
| 1024 |
|
| 1025 |
*img = image->convertDepth(32); |
| 1026 |
img->setAlphaBuffer(true); |
| 1027 |
setNumRows(img->height()); |
| 1028 |
setNumCols(img->width()); |
| 1029 |
|
| 1030 |
for(int y = 0; y < numRows(); y++) |
| 1031 |
{ |
| 1032 |
uint *l = (uint*)img->scanLine(y); |
| 1033 |
for(int x = 0; x < numCols(); x++, l++) |
| 1034 |
{ |
| 1035 |
setColor((y*numCols())+x, *l, false); |
| 1036 |
} |
| 1037 |
//kdDebug(4640) << "Row: " << y << endl; |
| 1038 |
kapp->processEvents(200); |
| 1039 |
} |
| 1040 |
|
| 1041 |
updateColors(); |
| 1042 |
emit sizechanged(numCols(), numRows()); |
| 1043 |
emit colorschanged(numColors(), data()); |
| 1044 |
emit changed(pixmap()); |
| 1045 |
setUpdatesEnabled(true); |
| 1046 |
emit needPainting(); |
| 1047 |
//repaint(viewRect(), false); |
| 1048 |
history->clear(); |
| 1049 |
} |
| 1050 |
|
| 1051 |
const TQPixmap &TDEIconEditGrid::pixmap() |
| 1052 |
{ |
| 1053 |
if(!img->isNull()) |
| 1054 |
p = *img; |
| 1055 |
//p.convertFromImage(*img, 0); |
| 1056 |
return(p); |
| 1057 |
} |
| 1058 |
|
| 1059 |
void TDEIconEditGrid::getImage(TQImage *image) |
| 1060 |
{ |
| 1061 |
kdDebug(4640) << "TDEIconEditGrid::getImage" << endl; |
| 1062 |
*image = *img; |
| 1063 |
} |
| 1064 |
|
| 1065 |
bool TDEIconEditGrid::zoomTo(int scale) |
| 1066 |
{ |
| 1067 |
TQApplication::setOverrideCursor(waitCursor); |
| 1068 |
setUpdatesEnabled(false); |
| 1069 |
setCellSize( scale ); |
| 1070 |
setUpdatesEnabled(true); |
| 1071 |
emit needPainting(); |
| 1072 |
TQApplication::restoreOverrideCursor(); |
| 1073 |
emit scalingchanged(cellSize()); |
| 1074 |
|
| 1075 |
if(scale == 1) |
| 1076 |
return false; |
| 1077 |
return true; |
| 1078 |
} |
| 1079 |
|
| 1080 |
bool TDEIconEditGrid::zoom(Direction d) |
| 1081 |
{ |
| 1082 |
int f = (d == DirIn) ? (cellSize()+1) : (cellSize()-1); |
| 1083 |
TQApplication::setOverrideCursor(waitCursor); |
| 1084 |
setUpdatesEnabled(false); |
| 1085 |
setCellSize( f ); |
| 1086 |
setUpdatesEnabled(true); |
| 1087 |
//emit needPainting(); |
| 1088 |
TQApplication::restoreOverrideCursor(); |
| 1089 |
|
| 1090 |
emit scalingchanged(cellSize()); |
| 1091 |
if(d == DirOut && cellSize() <= 1) |
| 1092 |
return false; |
| 1093 |
return true; |
| 1094 |
} |
| 1095 |
|
| 1096 |
void TDEIconEditGrid::checkClipboard() |
| 1097 |
{ |
| 1098 |
bool ok = false; |
| 1099 |
TQImage tmp = clipboardImage(ok); |
| 1100 |
if(ok) |
| 1101 |
emit clipboarddata(true); |
| 1102 |
else |
| 1103 |
{ |
| 1104 |
emit clipboarddata(false); |
| 1105 |
} |
| 1106 |
} |
| 1107 |
|
| 1108 |
TQImage TDEIconEditGrid::clipboardImage(bool &ok) |
| 1109 |
{ |
| 1110 |
//###### Remove me later. |
| 1111 |
//Workaround TQt bug -- check whether format provided first. |
| 1112 |
//Code below is from TQDragObject, to match the mimetype list.... |
| 1113 |
|
| 1114 |
TQStrList fileFormats = TQImageIO::inputFormats(); |
| 1115 |
fileFormats.first(); |
| 1116 |
bool oneIsSupported = false; |
| 1117 |
while ( fileFormats.current() ) |
| 1118 |
{ |
| 1119 |
TQCString format = fileFormats.current(); |
| 1120 |
TQCString type = "image/" + format.lower(); |
| 1121 |
if (kapp->clipboard()->data()->provides(type ) ) |
| 1122 |
{ |
| 1123 |
oneIsSupported = true; |
| 1124 |
} |
| 1125 |
fileFormats.next(); |
| 1126 |
} |
| 1127 |
if (!oneIsSupported) |
| 1128 |
{ |
| 1129 |
ok = false; |
| 1130 |
return TQImage(); |
| 1131 |
} |
| 1132 |
|
| 1133 |
TQImage image = kapp->clipboard()->image(); |
| 1134 |
ok = !image.isNull(); |
| 1135 |
if ( ok ) |
| 1136 |
{ |
| 1137 |
image = image.convertDepth(32); |
| 1138 |
image.setAlphaBuffer(true); |
| 1139 |
} |
| 1140 |
return image; |
| 1141 |
} |
| 1142 |
|
| 1143 |
|
| 1144 |
void TDEIconEditGrid::editSelectAll() |
| 1145 |
{ |
| 1146 |
start.setX(0); |
| 1147 |
start.setY(0); |
| 1148 |
end.setX(numCols()-1); |
| 1149 |
end.setY(numRows()-1); |
| 1150 |
isselecting = true; |
| 1151 |
drawRect(false); |
| 1152 |
emit newmessage(i18n("All selected")); |
| 1153 |
} |
| 1154 |
|
| 1155 |
void TDEIconEditGrid::editClear() |
| 1156 |
{ |
| 1157 |
clearImage(img); |
| 1158 |
fill(TRANSPARENT); |
| 1159 |
update(); |
| 1160 |
setModified(true); |
| 1161 |
p = *img; |
| 1162 |
emit changed(p); |
| 1163 |
emit newmessage(i18n("Cleared")); |
| 1164 |
} |
| 1165 |
|
| 1166 |
TQImage TDEIconEditGrid::getSelection(bool cut) |
| 1167 |
{ |
| 1168 |
const TQRect rect = pntarray.boundingRect(); |
| 1169 |
int nx = 0, ny = 0, nw = 0, nh = 0; |
| 1170 |
rect.rect(&nx, &ny, &nw, &nh); |
| 1171 |
|
| 1172 |
TQImage tmp(nw, nh, 32); |
| 1173 |
tmp.setAlphaBuffer(true); |
| 1174 |
clearImage(&tmp); |
| 1175 |
|
| 1176 |
int s = pntarray.size(); |
| 1177 |
|
| 1178 |
for(int i = 0; i < s; i++) |
| 1179 |
{ |
| 1180 |
int x = pntarray[i].x(); |
| 1181 |
int y = pntarray[i].y(); |
| 1182 |
if(img->valid(x, y) && rect.contains(TQPoint(x, y))) |
| 1183 |
{ |
| 1184 |
*((uint*)tmp.scanLine(y-ny) + (x-nx)) = *((uint*)img->scanLine(y) + x); |
| 1185 |
if(cut) |
| 1186 |
{ |
| 1187 |
*((uint*)img->scanLine(y) + x) = TRANSPARENT; |
| 1188 |
setColor( (y*numCols()) + x, TRANSPARENT, false ); |
| 1189 |
} |
| 1190 |
} |
| 1191 |
} |
| 1192 |
|
| 1193 |
TQPointArray a(pntarray.copy()); |
| 1194 |
pntarray.resize(0); |
| 1195 |
drawPointArray(a, Mark); |
| 1196 |
emit selecteddata(false); |
| 1197 |
if(cut) |
| 1198 |
{ |
| 1199 |
updateColors(); |
| 1200 |
update(rect.x()*cellSize(), rect.y()*cellSize(), |
| 1201 |
rect.width()*cellSize(), rect.height()*cellSize()); |
| 1202 |
p = *img; |
| 1203 |
emit changed(p); |
| 1204 |
emit colorschanged(numColors(), data()); |
| 1205 |
emit newmessage(i18n("Selected area cut")); |
| 1206 |
setModified(true); |
| 1207 |
} |
| 1208 |
else |
| 1209 |
emit newmessage(i18n("Selected area copied")); |
| 1210 |
|
| 1211 |
return tmp; |
| 1212 |
} |
| 1213 |
|
| 1214 |
void TDEIconEditGrid::editCopy(bool cut) |
| 1215 |
{ |
| 1216 |
kapp->clipboard()->setImage(getSelection(cut)); |
| 1217 |
isselecting = false; |
| 1218 |
} |
| 1219 |
|
| 1220 |
|
| 1221 |
void TDEIconEditGrid::editPaste(bool paste) |
| 1222 |
{ |
| 1223 |
bool ok = false; |
| 1224 |
TQImage tmp = clipboardImage(ok); |
| 1225 |
|
| 1226 |
TDEIconEditProperties *props = TDEIconEditProperties::self(); |
| 1227 |
|
| 1228 |
if(ok) |
| 1229 |
{ |
| 1230 |
if( (tmp.size().width() > img->size().width()) |
| 1231 |
|| (tmp.size().height() > img->size().height()) ) |
| 1232 |
{ |
| 1233 |
if(KMessageBox::warningYesNo(this, |
| 1234 |
i18n("The clipboard image is larger than the current" |
| 1235 |
" image!\nPaste as new image?"),TQString(),i18n("Paste"), i18n("Do Not Paste")) == 0) |
| 1236 |
{ |
| 1237 |
editPasteAsNew(); |
| 1238 |
} |
| 1239 |
return; |
| 1240 |
} |
| 1241 |
else if(!paste) |
| 1242 |
{ |
| 1243 |
ispasting = true; |
| 1244 |
cbsize = tmp.size(); |
| 1245 |
return; |
| 1246 |
// emit newmessage(i18n("Pasting")); |
| 1247 |
} |
| 1248 |
else |
| 1249 |
{ |
| 1250 |
//kdDebug(4640) << "TDEIconEditGrid: Pasting at: " << insrect.x() << " x " << insrect.y() << endl; |
| 1251 |
TQApplication::setOverrideCursor(waitCursor); |
| 1252 |
|
| 1253 |
for(int y = insrect.y(), ny = 0; y < numRows() && ny < insrect.height(); y++, ny++) |
| 1254 |
{ |
| 1255 |
uint *l = ((uint*)img->scanLine(y)+insrect.x()); |
| 1256 |
uint *cl = (uint*)tmp.scanLine(ny); |
| 1257 |
for(int x = insrect.x(), nx = 0; x < numCols() && nx < insrect.width(); x++, nx++, l++, cl++) |
| 1258 |
{ |
| 1259 |
if(props->pasteTransparent()) |
| 1260 |
{ |
| 1261 |
*l = *cl; |
| 1262 |
} |
| 1263 |
else |
| 1264 |
{ |
| 1265 |
// Porter-Duff Over composition |
| 1266 |
double alphaS = tqAlpha(*cl) / 255.0; |
| 1267 |
double alphaD = tqAlpha(*l) / 255.0; |
| 1268 |
|
| 1269 |
double r = tqRed(*cl) * alphaS + (1 - alphaS) * tqRed(*l) * alphaD; |
| 1270 |
double g = tqGreen(*cl) * alphaS + (1 - alphaS) * tqGreen(*l) * alphaD; |
| 1271 |
double b = tqBlue(*cl) * alphaS + (1 - alphaS) * tqBlue(*l) * alphaD; |
| 1272 |
double a = alphaS + (1 - alphaS) * alphaD; |
| 1273 |
|
| 1274 |
// Remove multiplication by alpha |
| 1275 |
|
| 1276 |
if(a > 0) |
| 1277 |
{ |
| 1278 |
r /= a; |
| 1279 |
g /= a; |
| 1280 |
b /= a; |
| 1281 |
} |
| 1282 |
else |
| 1283 |
{ |
| 1284 |
r = 0; |
| 1285 |
g = 0; |
| 1286 |
b = 0; |
| 1287 |
} |
| 1288 |
|
| 1289 |
int ir = (int)(r + 0.5); |
| 1290 |
|
| 1291 |
if(ir < 0) |
| 1292 |
{ |
| 1293 |
ir = 0; |
| 1294 |
} |
| 1295 |
else |
| 1296 |
if(ir > 255) |
| 1297 |
{ |
| 1298 |
ir = 255; |
| 1299 |
} |
| 1300 |
|
| 1301 |
int ig = (int)(g + 0.5); |
| 1302 |
|
| 1303 |
if(ig < 0) |
| 1304 |
{ |
| 1305 |
ig = 0; |
| 1306 |
} |
| 1307 |
else |
| 1308 |
if(ig > 255) |
| 1309 |
{ |
| 1310 |
ig = 255; |
| 1311 |
} |
| 1312 |
|
| 1313 |
int ib = (int)(b + 0.5); |
| 1314 |
|
| 1315 |
if(ib < 0) |
| 1316 |
{ |
| 1317 |
ib = 0; |
| 1318 |
} |
| 1319 |
else |
| 1320 |
if(ib > 255) |
| 1321 |
{ |
| 1322 |
ib = 255; |
| 1323 |
} |
| 1324 |
|
| 1325 |
int ia = (int)((a * 255) + 0.5); |
| 1326 |
|
| 1327 |
if(ia < 0) |
| 1328 |
{ |
| 1329 |
ia = 0; |
| 1330 |
} |
| 1331 |
else |
| 1332 |
if(ia > 255) |
| 1333 |
{ |
| 1334 |
ia = 255; |
| 1335 |
} |
| 1336 |
|
| 1337 |
*l = tqRgba(ir, ig, ib, ia); |
| 1338 |
} |
| 1339 |
|
| 1340 |
setColor((y*numCols())+x, (uint)*l, false); |
| 1341 |
} |
| 1342 |
} |
| 1343 |
updateColors(); |
| 1344 |
update(insrect.x()*cellSize(), insrect.y()*cellSize(), |
| 1345 |
insrect.width()*cellSize(), insrect.height()*cellSize()); |
| 1346 |
|
| 1347 |
TQApplication::restoreOverrideCursor(); |
| 1348 |
|
| 1349 |
setModified(true); |
| 1350 |
p = *img; |
| 1351 |
emit changed(TQPixmap(p)); |
| 1352 |
emit sizechanged(numCols(), numRows()); |
| 1353 |
emit colorschanged(numColors(), data()); |
| 1354 |
emit newmessage(i18n("Done pasting")); |
| 1355 |
} |
| 1356 |
} |
| 1357 |
else |
| 1358 |
{ |
| 1359 |
TQString msg = i18n("Invalid pixmap data in clipboard!\n"); |
| 1360 |
KMessageBox::sorry(this, msg); |
| 1361 |
} |
| 1362 |
} |
| 1363 |
|
| 1364 |
|
| 1365 |
void TDEIconEditGrid::editPasteAsNew() |
| 1366 |
{ |
| 1367 |
bool ok = false; |
| 1368 |
TQImage tmp = clipboardImage(ok); |
| 1369 |
|
| 1370 |
if(ok) |
| 1371 |
{ |
| 1372 |
if(isModified()) |
| 1373 |
{ |
| 1374 |
TDEIconEdit *w = new TDEIconEdit(tmp); |
| 1375 |
TQ_CHECK_PTR(w); |
| 1376 |
} |
| 1377 |
else |
| 1378 |
{ |
| 1379 |
*img = tmp; |
| 1380 |
load(img); |
| 1381 |
setModified(true); |
| 1382 |
//repaint(viewRect(), false); |
| 1383 |
|
| 1384 |
p = *img; |
| 1385 |
emit changed(TQPixmap(p)); |
| 1386 |
emit sizechanged(numCols(), numRows()); |
| 1387 |
emit colorschanged(numColors(), data()); |
| 1388 |
emit newmessage(i18n("Done pasting")); |
| 1389 |
history->clear(); |
| 1390 |
} |
| 1391 |
} |
| 1392 |
else |
| 1393 |
{ |
| 1394 |
TQString msg = i18n("Invalid pixmap data in clipboard!\n"); |
| 1395 |
KMessageBox::error(this, msg); |
| 1396 |
} |
| 1397 |
} |
| 1398 |
|
| 1399 |
|
| 1400 |
void TDEIconEditGrid::editResize() |
| 1401 |
{ |
| 1402 |
kdDebug(4640) << "TDEIconGrid::editResize" << endl; |
| 1403 |
KResizeDialog *rs = new KResizeDialog(this, 0, TQSize(numCols(), numRows())); |
| 1404 |
if(rs->exec()) |
| 1405 |
{ |
| 1406 |
const TQSize s = rs->getSize(); |
| 1407 |
*img = img->smoothScale(s.width(), s.height()); |
| 1408 |
load(img); |
| 1409 |
|
| 1410 |
setModified(true); |
| 1411 |
} |
| 1412 |
delete rs; |
| 1413 |
} |
| 1414 |
|
| 1415 |
|
| 1416 |
void TDEIconEditGrid::setSize(const TQSize s) |
| 1417 |
{ |
| 1418 |
kdDebug(4640) << "::setSize: " << s.width() << " x " << s.height() << endl; |
| 1419 |
|
| 1420 |
img->create(s.width(), s.height(), 32); |
| 1421 |
img->setAlphaBuffer(true); |
| 1422 |
clearImage(img); |
| 1423 |
load(img); |
| 1424 |
} |
| 1425 |
|
| 1426 |
|
| 1427 |
void TDEIconEditGrid::createCursors() |
| 1428 |
{ |
| 1429 |
TQBitmap mask(22, 22); |
| 1430 |
TQPixmap pix; |
| 1431 |
|
| 1432 |
cursor_normal = TQCursor(arrowCursor); |
| 1433 |
|
| 1434 |
pix = BarIcon("colorpicker-cursor"); |
| 1435 |
if(pix.isNull()) |
| 1436 |
{ |
| 1437 |
cursor_colorpicker = cursor_normal; |
| 1438 |
kdDebug(4640) << "TDEIconEditGrid: Error loading colorpicker-cursor.xpm" << endl; |
| 1439 |
} |
| 1440 |
else |
| 1441 |
{ |
| 1442 |
mask = TQPixmap(pix.createHeuristicMask()); |
| 1443 |
pix.setMask(mask); |
| 1444 |
cursor_colorpicker = TQCursor(pix, 1, 21); |
| 1445 |
} |
| 1446 |
|
| 1447 |
pix = BarIcon("paintbrush-cursor"); |
| 1448 |
if(pix.isNull()) |
| 1449 |
{ |
| 1450 |
cursor_paint = cursor_normal; |
| 1451 |
kdDebug(4640) << "TDEIconEditGrid: Error loading paintbrush.xpm" << endl; |
| 1452 |
} |
| 1453 |
else |
| 1454 |
{ |
| 1455 |
mask = TQPixmap(pix.createHeuristicMask()); |
| 1456 |
pix.setMask(mask); |
| 1457 |
cursor_paint = TQCursor(pix, 0, 19); |
| 1458 |
} |
| 1459 |
|
| 1460 |
pix = BarIcon("fill-cursor"); |
| 1461 |
if(pix.isNull()) |
| 1462 |
{ |
| 1463 |
cursor_flood = cursor_normal; |
| 1464 |
kdDebug(4640) << "TDEIconEditGrid: Error loading fill-cursor.xpm" << endl; |
| 1465 |
} |
| 1466 |
else |
| 1467 |
{ |
| 1468 |
mask = TQPixmap(pix.createHeuristicMask()); |
| 1469 |
pix.setMask(mask); |
| 1470 |
cursor_flood = TQCursor(pix, 3, 20); |
| 1471 |
} |
| 1472 |
|
| 1473 |
pix = BarIcon("aim-cursor"); |
| 1474 |
if(pix.isNull()) |
| 1475 |
{ |
| 1476 |
cursor_aim = cursor_normal; |
| 1477 |
kdDebug(4640) << "TDEIconEditGrid: Error loading aim-cursor.xpm" << endl; |
| 1478 |
} |
| 1479 |
else |
| 1480 |
{ |
| 1481 |
mask = TQPixmap(pix.createHeuristicMask()); |
| 1482 |
pix.setMask(mask); |
| 1483 |
cursor_aim = TQCursor(pix, 10, 10); |
| 1484 |
} |
| 1485 |
|
| 1486 |
pix = BarIcon("airbrush-cursor"); |
| 1487 |
if(pix.isNull()) |
| 1488 |
{ |
| 1489 |
cursor_spray = cursor_normal; |
| 1490 |
kdDebug(4640) << "TDEIconEditGrid: Error loading airbrush-cursor.xpm" << endl; |
| 1491 |
} |
| 1492 |
else |
| 1493 |
{ |
| 1494 |
mask = TQPixmap(pix.createHeuristicMask(true)); |
| 1495 |
pix.setMask(mask); |
| 1496 |
cursor_spray = TQCursor(pix, 0, 20); |
| 1497 |
} |
| 1498 |
|
| 1499 |
pix = BarIcon("eraser-cursor"); |
| 1500 |
if(pix.isNull()) |
| 1501 |
{ |
| 1502 |
cursor_erase = cursor_normal; |
| 1503 |
kdDebug(4640) << "TDEIconEditGrid: Error loading eraser-cursor.xpm" << endl; |
| 1504 |
} |
| 1505 |
else |
| 1506 |
{ |
| 1507 |
mask = TQPixmap(pix.createHeuristicMask(true)); |
| 1508 |
pix.setMask(mask); |
| 1509 |
cursor_erase = TQCursor(pix, 1, 16); |
| 1510 |
} |
| 1511 |
} |
| 1512 |
|
| 1513 |
|
| 1514 |
|
| 1515 |
void TDEIconEditGrid::setTool(DrawTool t) |
| 1516 |
{ |
| 1517 |
btndown = false; |
| 1518 |
tool = t; |
| 1519 |
|
| 1520 |
if(tool != SelectRect && tool != SelectCircle) |
| 1521 |
isselecting = false; |
| 1522 |
|
| 1523 |
switch( tool ) |
| 1524 |
{ |
| 1525 |
case SelectRect: |
| 1526 |
isselecting = true; |
| 1527 |
setCursor(cursor_aim); |
| 1528 |
break; |
| 1529 |
case SelectCircle: |
| 1530 |
isselecting = true; |
| 1531 |
setCursor(cursor_aim); |
| 1532 |
break; |
| 1533 |
case Line: |
| 1534 |
case Ellipse: |
| 1535 |
case Circle: |
| 1536 |
case FilledEllipse: |
| 1537 |
case FilledCircle: |
| 1538 |
case FilledRect: |
| 1539 |
case Rect: |
| 1540 |
setCursor(cursor_aim); |
| 1541 |
break; |
| 1542 |
case Freehand: |
| 1543 |
setCursor(cursor_paint); |
| 1544 |
break; |
| 1545 |
case Spray: |
| 1546 |
setCursor(cursor_spray); |
| 1547 |
break; |
| 1548 |
case Eraser: |
| 1549 |
setCursor(cursor_erase); |
| 1550 |
break; |
| 1551 |
case FloodFill: |
| 1552 |
setCursor(cursor_flood); |
| 1553 |
break; |
| 1554 |
case Find: |
| 1555 |
setCursor(cursor_colorpicker); |
| 1556 |
break; |
| 1557 |
default: |
| 1558 |
break; |
| 1559 |
} |
| 1560 |
} |
| 1561 |
|
| 1562 |
|
| 1563 |
void TDEIconEditGrid::drawFlood(int x, int y, uint oldcolor) |
| 1564 |
{ |
| 1565 |
if((!img->valid(x, y)) |
| 1566 |
|| (colorAt((y * numCols())+x) != oldcolor) |
| 1567 |
|| (colorAt((y * numCols())+x) == currentcolor)) |
| 1568 |
return; |
| 1569 |
|
| 1570 |
*((uint*)img->scanLine(y) + x) = currentcolor; |
| 1571 |
setColor((y*numCols())+x, currentcolor, false); |
| 1572 |
|
| 1573 |
setModified(true); |
| 1574 |
|
| 1575 |
drawFlood(x, y-1, oldcolor); |
| 1576 |
drawFlood(x, y+1, oldcolor); |
| 1577 |
drawFlood(x-1, y, oldcolor); |
| 1578 |
drawFlood(x+1, y, oldcolor); |
| 1579 |
//TODO: add undo |
| 1580 |
} |
| 1581 |
|
| 1582 |
|
| 1583 |
void TDEIconEditGrid::drawSpray(TQPoint point) |
| 1584 |
{ |
| 1585 |
int x = (point.x()-5); |
| 1586 |
int y = (point.y()-5); |
| 1587 |
|
| 1588 |
//kdDebug(4640) << "drawSpray() - " << x << " X " << y << endl; |
| 1589 |
|
| 1590 |
pntarray.resize(0); |
| 1591 |
int points = 0; |
| 1592 |
for(int i = 1; i < 4; i++, points++) |
| 1593 |
{ |
| 1594 |
int dx = (rand() % 10); |
| 1595 |
int dy = (rand() % 10); |
| 1596 |
pntarray.putPoints(points, 1, x+dx, y+dy); |
| 1597 |
} |
| 1598 |
|
| 1599 |
drawPointArray(pntarray, Draw); |
| 1600 |
} |
| 1601 |
|
| 1602 |
|
| 1603 |
//This routine is from TQt sources -- it's the branch of TQPointArray::makeEllipse( int x, int y, int w, int h ) that's not normally compiled |
| 1604 |
//It seems like TDEIconEdit relied on the TQt1 semantics for makeEllipse, which broke |
| 1605 |
//the tool with reasonably recent TQt versions. |
| 1606 |
//Thankfully, TQt includes the old code #ifdef'd, which is hence included here |
| 1607 |
static void TQPA_makeEllipse(TQPointArray& ar, int x, int y, int w, int h ) |
| 1608 |
{ // midpoint, 1/4 ellipse |
| 1609 |
if ( w <= 0 || h <= 0 ) { |
| 1610 |
if ( w == 0 || h == 0 ) { |
| 1611 |
ar.resize( 0 ); |
| 1612 |
return; |
| 1613 |
} |
| 1614 |
if ( w < 0 ) { // negative width |
| 1615 |
w = -w; |
| 1616 |
x -= w; |
| 1617 |
} |
| 1618 |
if ( h < 0 ) { // negative height |
| 1619 |
h = -h; |
| 1620 |
y -= h; |
| 1621 |
} |
| 1622 |
} |
| 1623 |
int s = (w+h+2)/2; // max size of xx,yy array |
| 1624 |
int *px = new int[s]; // 1/4th of ellipse |
| 1625 |
int *py = new int[s]; |
| 1626 |
int xx, yy, i=0; |
| 1627 |
double d1, d2; |
| 1628 |
double a2=(w/2)*(w/2), b2=(h/2)*(h/2); |
| 1629 |
xx = 0; |
| 1630 |
yy = int(h/2); |
| 1631 |
d1 = b2 - a2*(h/2) + 0.25*a2; |
| 1632 |
px[i] = xx; |
| 1633 |
py[i] = yy; |
| 1634 |
i++; |
| 1635 |
while ( a2*(yy-0.5) > b2*(xx+0.5) ) { // region 1 |
| 1636 |
if ( d1 < 0 ) { |
| 1637 |
d1 = d1 + b2*(3.0+2*xx); |
| 1638 |
xx++; |
| 1639 |
} else { |
| 1640 |
d1 = d1 + b2*(3.0+2*xx) + 2.0*a2*(1-yy); |
| 1641 |
xx++; |
| 1642 |
yy--; |
| 1643 |
} |
| 1644 |
px[i] = xx; |
| 1645 |
py[i] = yy; |
| 1646 |
i++; |
| 1647 |
} |
| 1648 |
d2 = b2*(xx+0.5)*(xx+0.5) + a2*(yy-1)*(yy-1) - a2*b2; |
| 1649 |
while ( yy > 0 ) { // region 2 |
| 1650 |
if ( d2 < 0 ) { |
| 1651 |
d2 = d2 + 2.0*b2*(xx+1) + a2*(3-2*yy); |
| 1652 |
xx++; |
| 1653 |
yy--; |
| 1654 |
} else { |
| 1655 |
d2 = d2 + a2*(3-2*yy); |
| 1656 |
yy--; |
| 1657 |
} |
| 1658 |
px[i] = xx; |
| 1659 |
py[i] = yy; |
| 1660 |
i++; |
| 1661 |
} |
| 1662 |
s = i; |
| 1663 |
ar.resize( 4*s ); // make full point array |
| 1664 |
x += w/2; |
| 1665 |
y += h/2; |
| 1666 |
for ( i=0; i<s; i++ ) { // mirror |
| 1667 |
xx = px[i]; |
| 1668 |
yy = py[i]; |
| 1669 |
ar.setPoint( s-i-1, x+xx, y-yy ); |
| 1670 |
ar.setPoint( s+i, x-xx, y-yy ); |
| 1671 |
ar.setPoint( 3*s-i-1, x-xx, y+yy ); |
| 1672 |
ar.setPoint( 3*s+i, x+xx, y+yy ); |
| 1673 |
} |
| 1674 |
delete[] px; |
| 1675 |
delete[] py; |
| 1676 |
} |
| 1677 |
|
| 1678 |
|
| 1679 |
|
| 1680 |
void TDEIconEditGrid::drawEllipse(bool drawit) |
| 1681 |
{ |
| 1682 |
if(drawit) |
| 1683 |
{ |
| 1684 |
drawPointArray(pntarray, Draw); |
| 1685 |
p = *img; |
| 1686 |
emit changed(p); |
| 1687 |
return; |
| 1688 |
} |
| 1689 |
|
| 1690 |
TQPointArray a(pntarray.copy()); |
| 1691 |
int x = start.x(), y = start.y(), cx, cy; |
| 1692 |
|
| 1693 |
if(x > end.x()) |
| 1694 |
{ |
| 1695 |
cx = x - end.x(); |
| 1696 |
x = x - cx; |
| 1697 |
} |
| 1698 |
else |
| 1699 |
cx = end.x() - x; |
| 1700 |
if(y > end.y()) |
| 1701 |
{ |
| 1702 |
cy = y - end.y(); |
| 1703 |
y = y - cy; |
| 1704 |
} |
| 1705 |
else |
| 1706 |
cy = end.y() - y; |
| 1707 |
|
| 1708 |
int d = (cx > cy) ? cx : cy; |
| 1709 |
|
| 1710 |
//kdDebug(4640) << x << ", " << y << " - " << d << " " << d << endl; |
| 1711 |
pntarray.resize(0); |
| 1712 |
drawPointArray(a, Mark); |
| 1713 |
|
| 1714 |
if(tool == Circle || tool == FilledCircle || tool == SelectCircle) |
| 1715 |
TQPA_makeEllipse(pntarray, x, y, d, d); |
| 1716 |
else if(tool == Ellipse || tool == FilledEllipse) |
| 1717 |
TQPA_makeEllipse(pntarray, x, y, cx, cy); |
| 1718 |
|
| 1719 |
if((tool == FilledEllipse) || (tool == FilledCircle) |
| 1720 |
|| (tool == SelectCircle)) |
| 1721 |
{ |
| 1722 |
int s = pntarray.size(); |
| 1723 |
int points = s; |
| 1724 |
for(int i = 0; i < s; i++) |
| 1725 |
{ |
| 1726 |
int x = pntarray[i].x(); |
| 1727 |
int y = pntarray[i].y(); |
| 1728 |
for(int j = 0; j < s; j++) |
| 1729 |
{ |
| 1730 |
if((pntarray[j].y() == y) && (pntarray[j].x() > x)) |
| 1731 |
{ |
| 1732 |
for(int k = x; k < pntarray[j].x(); k++, points++) |
| 1733 |
pntarray.putPoints(points, 1, k, y); |
| 1734 |
break; |
| 1735 |
} |
| 1736 |
} |
| 1737 |
} |
| 1738 |
} |
| 1739 |
|
| 1740 |
drawPointArray(pntarray, Mark); |
| 1741 |
|
| 1742 |
if(tool == SelectCircle && pntarray.size() > 0 && !ispasting) |
| 1743 |
emit selecteddata(true); |
| 1744 |
} |
| 1745 |
|
| 1746 |
|
| 1747 |
void TDEIconEditGrid::drawRect(bool drawit) |
| 1748 |
{ |
| 1749 |
if(drawit) |
| 1750 |
{ |
| 1751 |
drawPointArray(pntarray, Draw); |
| 1752 |
p = *img; |
| 1753 |
emit changed(p); |
| 1754 |
return; |
| 1755 |
} |
| 1756 |
|
| 1757 |
TQPointArray a(pntarray.copy()); |
| 1758 |
int x = start.x(), y = start.y(), cx, cy; |
| 1759 |
|
| 1760 |
if(x > end.x()) |
| 1761 |
{ |
| 1762 |
cx = x - end.x(); |
| 1763 |
x = x - cx; |
| 1764 |
} |
| 1765 |
else |
| 1766 |
cx = end.x() - x; |
| 1767 |
if(y > end.y()) |
| 1768 |
{ |
| 1769 |
cy = y - end.y(); |
| 1770 |
y = y - cy; |
| 1771 |
} |
| 1772 |
else |
| 1773 |
cy = end.y() - y; |
| 1774 |
|
| 1775 |
//kdDebug(4640) << x << ", " << y << " - " << cx << " " << cy << endl; |
| 1776 |
pntarray.resize(0); |
| 1777 |
drawPointArray(a, Mark); // remove previous marking |
| 1778 |
|
| 1779 |
int points = 0; |
| 1780 |
bool pasting = ispasting; |
| 1781 |
|
| 1782 |
if(tool == FilledRect || (tool == SelectRect)) |
| 1783 |
{ |
| 1784 |
for(int i = x; i <= x + (pasting ? cx + 1 : cx); i++) |
| 1785 |
{ |
| 1786 |
for(int j = y; j <= y+cy; j++, points++) |
| 1787 |
pntarray.putPoints(points, 1, i, j); |
| 1788 |
} |
| 1789 |
} |
| 1790 |
else |
| 1791 |
{ |
| 1792 |
for(int i = x; i <= x+cx; i++, points++) |
| 1793 |
pntarray.putPoints(points, 1, i, y); |
| 1794 |
for(int i = y; i <= y+cy; i++, points++) |
| 1795 |
pntarray.putPoints(points, 1, x, i); |
| 1796 |
for(int i = x; i <= x+cx; i++, points++) |
| 1797 |
pntarray.putPoints(points, 1, i, y+cy); |
| 1798 |
for(int i = y; i <= y+cy; i++, points++) |
| 1799 |
pntarray.putPoints(points, 1, x+cx, i); |
| 1800 |
} |
| 1801 |
|
| 1802 |
drawPointArray(pntarray, Mark); |
| 1803 |
|
| 1804 |
if(tool == SelectRect && pntarray.size() > 0 && !ispasting) |
| 1805 |
emit selecteddata(true); |
| 1806 |
} |
| 1807 |
|
| 1808 |
|
| 1809 |
void TDEIconEditGrid::drawLine(bool drawit, bool drawStraight) |
| 1810 |
{ |
| 1811 |
if(drawit) |
| 1812 |
{ |
| 1813 |
drawPointArray(pntarray, Draw); |
| 1814 |
p = *img; |
| 1815 |
emit changed(p); |
| 1816 |
return; |
| 1817 |
} |
| 1818 |
|
| 1819 |
TQPointArray a(pntarray.copy()); |
| 1820 |
pntarray.resize(0); |
| 1821 |
|
| 1822 |
// remove previous marking |
| 1823 |
drawPointArray(a, Mark); |
| 1824 |
|
| 1825 |
int x, y, dx, dy, delta; |
| 1826 |
|
| 1827 |
dx = end.x() - start.x(); |
| 1828 |
dy = end.y() - start.y(); |
| 1829 |
x = start.x(); |
| 1830 |
y = start.y(); |
| 1831 |
|
| 1832 |
delta = TQMAX(abs(dx), abs(dy)); |
| 1833 |
int deltaX = abs(dx); |
| 1834 |
int deltaY = abs(dy); |
| 1835 |
|
| 1836 |
if ((drawStraight) && (delta > 0)) |
| 1837 |
{ |
| 1838 |
dx /= delta; |
| 1839 |
dy /= delta; |
| 1840 |
|
| 1841 |
for(int i = 0; i <= delta; i++) |
| 1842 |
{ |
| 1843 |
pntarray.putPoints(i, 1, x, y); |
| 1844 |
x += dx; |
| 1845 |
y += dy; |
| 1846 |
} |
| 1847 |
} |
| 1848 |
|
| 1849 |
else if ((delta > 0) && (deltaX >= deltaY)) |
| 1850 |
{ |
| 1851 |
for(int i = 0; i <= deltaX; i++) |
| 1852 |
{ |
| 1853 |
pntarray.putPoints(i, 1, x, y); |
| 1854 |
|
| 1855 |
if(dx > 0) |
| 1856 |
x++; |
| 1857 |
else |
| 1858 |
x--; |
| 1859 |
|
| 1860 |
if(dy >= 0) |
| 1861 |
y = start.y() + (abs(start.x() - x) * deltaY) / deltaX; |
| 1862 |
else |
| 1863 |
y = start.y() - (abs(start.x() - x) * deltaY) / deltaX; |
| 1864 |
} |
| 1865 |
} |
| 1866 |
|
| 1867 |
else if ((delta > 0) && (deltaY > deltaX)) |
| 1868 |
{ |
| 1869 |
for(int i = 0; i <= deltaY; i++) |
| 1870 |
{ |
| 1871 |
pntarray.putPoints(i, 1, x, y); |
| 1872 |
|
| 1873 |
if(dy > 0) |
| 1874 |
y++; |
| 1875 |
else |
| 1876 |
y--; |
| 1877 |
|
| 1878 |
if(dx >= 0) |
| 1879 |
x = start.x() + (abs(start.y() - y) * deltaX) / deltaY; |
| 1880 |
else |
| 1881 |
x = start.x() - (abs(start.y() - y) * deltaX) / deltaY; |
| 1882 |
} |
| 1883 |
} |
| 1884 |
|
| 1885 |
drawPointArray(pntarray, Mark); |
| 1886 |
} |
| 1887 |
|
| 1888 |
|
| 1889 |
void TDEIconEditGrid::drawPointArray(TQPointArray a, DrawAction action) |
| 1890 |
{ |
| 1891 |
TQRect area( a.boundingRect().x()*cellSize()-1, a.boundingRect().y()*cellSize()-1, |
| 1892 |
a.boundingRect().width()*cellSize()+1, a.boundingRect().height()*cellSize()+1 ); |
| 1893 |
|
| 1894 |
KMacroCommand* macro = 0; |
| 1895 |
bool doupdate = false; |
| 1896 |
|
| 1897 |
if( a.size() > 0 && action == Draw ) { |
| 1898 |
// might cause a memmory leak, if |
| 1899 |
// macro is never used and never |
| 1900 |
// added to the history! TODO: Fix this |
| 1901 |
macro = new KMacroCommand( i18n("Drawn Array") ); |
| 1902 |
RepaintCommand* rc = new RepaintCommand( area, this ); |
| 1903 |
macro->addCommand( rc ); |
| 1904 |
} |
| 1905 |
|
| 1906 |
int s = a.size(); //((rect.size().width()) * (rect.size().height())); |
| 1907 |
for(int i = 0; i < s; i++) |
| 1908 |
{ |
| 1909 |
int x = a[i].x(); |
| 1910 |
int y = a[i].y(); |
| 1911 |
|
| 1912 |
if(img->valid(x, y) && TQT_TQRECT_OBJECT(a.boundingRect()).contains(a[ i ])) |
| 1913 |
{ |
| 1914 |
//kdDebug(4640) << "x: " << x << " - y: " << y << endl; |
| 1915 |
switch( action ) |
| 1916 |
{ |
| 1917 |
case Draw: |
| 1918 |
{ |
| 1919 |
DrawCommand* dc = new DrawCommand( x, y, currentcolor, img, this ); |
| 1920 |
dc->execute(); |
| 1921 |
//*((uint*)img->scanLine(y) + x) = currentcolor; //colors[cell]|OPAQUE; |
| 1922 |
//int cell = y * numCols() + x; |
| 1923 |
//setColor( cell, currentcolor, false ); |
| 1924 |
doupdate = true; |
| 1925 |
//updateCell( y, x, FALSE ); |
| 1926 |
macro->addCommand( dc ); |
| 1927 |
break; |
| 1928 |
} |
| 1929 |
|
| 1930 |
case Mark: |
| 1931 |
case UnMark: |
| 1932 |
update(x*cellsize,y*cellsize, cellsize, cellsize); |
| 1933 |
//updateCell( y, x, true ); |
| 1934 |
break; |
| 1935 |
|
| 1936 |
default: |
| 1937 |
break; |
| 1938 |
} |
| 1939 |
} |
| 1940 |
} |
| 1941 |
|
| 1942 |
|
| 1943 |
if(doupdate) |
| 1944 |
{ |
| 1945 |
setModified( true ); |
| 1946 |
updateColors(); |
| 1947 |
RepaintCommand* rc = new RepaintCommand( area, this ); |
| 1948 |
rc->execute(); |
| 1949 |
macro->addCommand( rc ); |
| 1950 |
pntarray.resize(0); |
| 1951 |
// add to undo/redo history |
| 1952 |
history->addCommand( macro, false ); } |
| 1953 |
} |
| 1954 |
|
| 1955 |
void TDEIconEditGrid::updatePreviewPixmap() |
| 1956 |
{ |
| 1957 |
p = *img; |
| 1958 |
emit changed(TQPixmap(p)); |
| 1959 |
} |
| 1960 |
|
| 1961 |
|
| 1962 |
bool TDEIconEditGrid::isMarked(TQPoint point) |
| 1963 |
{ |
| 1964 |
return isMarked(point.x(), point.y()); |
| 1965 |
} |
| 1966 |
|
| 1967 |
|
| 1968 |
bool TDEIconEditGrid::isMarked(int x, int y) |
| 1969 |
{ |
| 1970 |
if(((y * numCols()) + x) == selected) |
| 1971 |
return true; |
| 1972 |
|
| 1973 |
int s = pntarray.size(); |
| 1974 |
for(int i = 0; i < s; i++) |
| 1975 |
{ |
| 1976 |
if(y == pntarray[i].y() && x == pntarray[i].x()) |
| 1977 |
return true; |
| 1978 |
} |
| 1979 |
|
| 1980 |
return false; |
| 1981 |
} |
| 1982 |
|
| 1983 |
|
| 1984 |
// Fast diffuse dither to 3x3x3 color cube |
| 1985 |
// Based on TQt's image conversion functions |
| 1986 |
static bool kdither_32_to_8( const TQImage *src, TQImage *dst ) |
| 1987 |
{ |
| 1988 |
register TQRgb *p; |
| 1989 |
uchar *b; |
| 1990 |
int y; |
| 1991 |
|
| 1992 |
//printf("kconvert_32_to_8\n"); |
| 1993 |
|
| 1994 |
if ( !dst->create(src->width(), src->height(), 8, 256) ) { |
| 1995 |
kdWarning() << "OImage: destination image not valid" << endl; |
| 1996 |
return FALSE; |
| 1997 |
} |
| 1998 |
|
| 1999 |
int ncols = 256; |
| 2000 |
|
| 2001 |
static uint bm[16][16]; |
| 2002 |
static int init=0; |
| 2003 |
if (!init) |
| 2004 |
{ |
| 2005 |
// Build a Bayer Matrix for dithering |
| 2006 |
init = 1; |
| 2007 |
int n, i, j; |
| 2008 |
|
| 2009 |
bm[0][0]=0; |
| 2010 |
|
| 2011 |
for (n=1; n<16; n*=2) |
| 2012 |
{ |
| 2013 |
for (i=0; i<n; i++) |
| 2014 |
{ |
| 2015 |
for (j=0; j<n; j++) |
| 2016 |
{ |
| 2017 |
bm[i][j]*=4; |
| 2018 |
bm[i+n][j]=bm[i][j]+2; |
| 2019 |
bm[i][j+n]=bm[i][j]+3; |
| 2020 |
bm[i+n][j+n]=bm[i][j]+1; |
| 2021 |
} |
| 2022 |
} |
| 2023 |
} |
| 2024 |
|
| 2025 |
for (i=0; i<16; i++) |
| 2026 |
for (j=0; j<16; j++) |
| 2027 |
bm[i][j]<<=8; |
| 2028 |
} |
| 2029 |
|
| 2030 |
dst->setNumColors( ncols ); |
| 2031 |
|
| 2032 |
#define MAX_R 2 |
| 2033 |
#define MAX_G 2 |
| 2034 |
#define MAX_B 2 |
| 2035 |
#define INDEXOF(r,g,b) (((r)*(MAX_G+1)+(g))*(MAX_B+1)+(b)) |
| 2036 |
|
| 2037 |
int rc, gc, bc; |
| 2038 |
|
| 2039 |
for ( rc=0; rc<=MAX_R; rc++ ) // build 2x2x2 color cube |
| 2040 |
for ( gc=0; gc<=MAX_G; gc++ ) |
| 2041 |
for ( bc=0; bc<=MAX_B; bc++ ) |
| 2042 |
{ |
| 2043 |
dst->setColor( INDEXOF(rc,gc,bc), |
| 2044 |
tqRgb( rc*255/MAX_R, gc*255/MAX_G, bc*255/MAX_B ) ); |
| 2045 |
} |
| 2046 |
|
| 2047 |
int sw = src->width(); |
| 2048 |
int* line1[3]; |
| 2049 |
int* line2[3]; |
| 2050 |
int* pv[3]; |
| 2051 |
|
| 2052 |
line1[0] = new int[src->width()]; |
| 2053 |
line2[0] = new int[src->width()]; |
| 2054 |
line1[1] = new int[src->width()]; |
| 2055 |
line2[1] = new int[src->width()]; |
| 2056 |
line1[2] = new int[src->width()]; |
| 2057 |
line2[2] = new int[src->width()]; |
| 2058 |
pv[0] = new int[sw]; |
| 2059 |
pv[1] = new int[sw]; |
| 2060 |
pv[2] = new int[sw]; |
| 2061 |
|
| 2062 |
for ( y=0; y < src->height(); y++ ) |
| 2063 |
{ |
| 2064 |
p = (TQRgb *)src->scanLine(y); |
| 2065 |
b = dst->scanLine(y); |
| 2066 |
int endian = (TQImage::systemByteOrder() == TQImage::BigEndian); |
| 2067 |
int x; |
| 2068 |
uchar* q = const_cast<TQImage*>(src)->scanLine(y); |
| 2069 |
uchar* q2 = const_cast<TQImage*>(src)->scanLine(y+1 < src->height() ? y + 1 : 0); |
| 2070 |
for (int chan = 0; chan < 3; chan++) |
| 2071 |
{ |
| 2072 |
b = dst->scanLine(y); |
| 2073 |
int *l1 = (y&1) ? line2[chan] : line1[chan]; |
| 2074 |
int *l2 = (y&1) ? line1[chan] : line2[chan]; |
| 2075 |
if ( y == 0 ) |
| 2076 |
{ |
| 2077 |
for (int i=0; i<sw; i++) |
| 2078 |
l1[i] = q[i*4+chan+endian]; |
| 2079 |
} |
| 2080 |
if ( y+1 < src->height() ) |
| 2081 |
{ |
| 2082 |
for (int i=0; i<sw; i++) |
| 2083 |
l2[i] = q2[i*4+chan+endian]; |
| 2084 |
} |
| 2085 |
// Bi-directional error diffusion |
| 2086 |
if ( y&1 ) |
| 2087 |
{ |
| 2088 |
for (x=0; x<sw; x++) |
| 2089 |
{ |
| 2090 |
int pix = TQMAX(TQMIN(2, (l1[x] * 2 + 128)/ 255), 0); |
| 2091 |
int err = l1[x] - pix * 255 / 2; |
| 2092 |
pv[chan][x] = pix; |
| 2093 |
|
| 2094 |
// Spread the error around... |
| 2095 |
if ( x+1<sw ) |
| 2096 |
{ |
| 2097 |
l1[x+1] += (err*7)>>4; |
| 2098 |
l2[x+1] += err>>4; |
| 2099 |
} |
| 2100 |
l2[x]+=(err*5)>>4; |
| 2101 |
if (x>1) |
| 2102 |
l2[x-1]+=(err*3)>>4; |
| 2103 |
} |
| 2104 |
} |
| 2105 |
else |
| 2106 |
{ |
| 2107 |
for (x=sw; x-->0; ) |
| 2108 |
{ |
| 2109 |
int pix = TQMAX(TQMIN(2, (l1[x] * 2 + 128)/ 255), 0); |
| 2110 |
int err = l1[x] - pix * 255 / 2; |
| 2111 |
pv[chan][x] = pix; |
| 2112 |
|
| 2113 |
// Spread the error around... |
| 2114 |
if ( x > 0 ) |
| 2115 |
{ |
| 2116 |
l1[x-1] += (err*7)>>4; |
| 2117 |
l2[x-1] += err>>4; |
| 2118 |
} |
| 2119 |
l2[x]+=(err*5)>>4; |
| 2120 |
if (x+1 < sw) |
| 2121 |
l2[x+1]+=(err*3)>>4; |
| 2122 |
} |
| 2123 |
} |
| 2124 |
} |
| 2125 |
if (endian) |
| 2126 |
{ |
| 2127 |
for (x=0; x<sw; x++) |
| 2128 |
{ |
| 2129 |
*b++ = INDEXOF(pv[2][x],pv[1][x],pv[0][x]); |
| 2130 |
} |
| 2131 |
} |
| 2132 |
else |
| 2133 |
{ |
| 2134 |
for (x=0; x<sw; x++) |
| 2135 |
{ |
| 2136 |
*b++ = INDEXOF(pv[0][x],pv[1][x],pv[2][x]); |
| 2137 |
} |
| 2138 |
} |
| 2139 |
} |
| 2140 |
|
| 2141 |
delete [] line1[0]; |
| 2142 |
delete [] line2[0]; |
| 2143 |
delete [] line1[1]; |
| 2144 |
delete [] line2[1]; |
| 2145 |
delete [] line1[2]; |
| 2146 |
delete [] line2[2]; |
| 2147 |
delete [] pv[0]; |
| 2148 |
delete [] pv[1]; |
| 2149 |
delete [] pv[2]; |
| 2150 |
|
| 2151 |
#undef MAX_R |
| 2152 |
#undef MAX_G |
| 2153 |
#undef MAX_B |
| 2154 |
#undef INDEXOF |
| 2155 |
|
| 2156 |
return TRUE; |
| 2157 |
} |
| 2158 |
|
| 2159 |
// this doesn't work the way it should but the way KPixmap does. |
| 2160 |
void TDEIconEditGrid::mapToKDEPalette() |
| 2161 |
{ |
| 2162 |
TQImage dest; |
| 2163 |
|
| 2164 |
kdither_32_to_8(img, &dest); |
| 2165 |
*img = dest.convertDepth(32); |
| 2166 |
|
| 2167 |
for(int y = 0; y < img->height(); y++) |
| 2168 |
{ |
| 2169 |
uint *l = (uint*)img->scanLine(y); |
| 2170 |
for(int x = 0; x < img->width(); x++, l++) |
| 2171 |
{ |
| 2172 |
if(*l < 0xff000000) |
| 2173 |
{ |
| 2174 |
*l = *l | 0xff000000; |
| 2175 |
} |
| 2176 |
} |
| 2177 |
} |
| 2178 |
|
| 2179 |
load(img); |
| 2180 |
return; |
| 2181 |
|
| 2182 |
/* |
| 2183 |
#if [[[TQT_VERSION IS DEPRECATED]]] > 140 |
| 2184 |
*img = img->convertDepthWithPalette(32, iconpalette, 42); |
| 2185 |
load(img); |
| 2186 |
return; |
| 2187 |
#endif |
| 2188 |
*/ |
| 2189 |
|
| 2190 |
TQApplication::setOverrideCursor(waitCursor); |
| 2191 |
for(int y = 0; y < numRows(); y++) |
| 2192 |
{ |
| 2193 |
uint *l = (uint*)img->scanLine(y); |
| 2194 |
for(int x = 0; x < numCols(); x++, l++) |
| 2195 |
{ |
| 2196 |
if(*l != TRANSPARENT) |
| 2197 |
{ |
| 2198 |
if(!iconcolors.contains(*l)) |
| 2199 |
*l = iconcolors.closestMatch(*l); |
| 2200 |
} |
| 2201 |
} |
| 2202 |
} |
| 2203 |
|
| 2204 |
load(img); |
| 2205 |
setModified(true); |
| 2206 |
TQApplication::restoreOverrideCursor(); |
| 2207 |
} |
| 2208 |
|
| 2209 |
|
| 2210 |
void TDEIconEditGrid::grayScale() |
| 2211 |
{ |
| 2212 |
for(int y = 0; y < numRows(); y++) |
| 2213 |
{ |
| 2214 |
uint *l = (uint*)img->scanLine(y); |
| 2215 |
for(int x = 0; x < numCols(); x++, l++) |
| 2216 |
{ |
| 2217 |
if(*l != TRANSPARENT) |
| 2218 |
{ |
| 2219 |
uint c = tqGray(*l); |
| 2220 |
*l = tqRgba(c, c, c, tqAlpha(*l)); |
| 2221 |
} |
| 2222 |
} |
| 2223 |
} |
| 2224 |
|
| 2225 |
load(img); |
| 2226 |
setModified(true); |
| 2227 |
} |
| 2228 |
|
| 2229 |
|
| 2230 |
void TDEIconEditGrid::clearImage(TQImage *image) |
| 2231 |
{ |
| 2232 |
if(image->depth() != 32) |
| 2233 |
{ |
| 2234 |
image->fill(TRANSPARENT); |
| 2235 |
} |
| 2236 |
else |
| 2237 |
{ |
| 2238 |
// TQImage::fill() does not set the alpha channel so do it |
| 2239 |
// manually. |
| 2240 |
for(int y = 0; y < image->height(); y++) |
| 2241 |
{ |
| 2242 |
uint *l = (uint*)image->scanLine(y); |
| 2243 |
for(int x = 0; x < image->width(); x++, l++) |
| 2244 |
{ |
| 2245 |
*l = TRANSPARENT; |
| 2246 |
} |
| 2247 |
} |
| 2248 |
} |
| 2249 |
} |
| 2250 |
|
| 2251 |
|
| 2252 |
void TDEIconEditGrid::setModified(bool m) |
| 2253 |
{ |
| 2254 |
if(m != modified) |
| 2255 |
{ |
| 2256 |
modified = m; |
| 2257 |
emit modifiedchanged(m); |
| 2258 |
} |
| 2259 |
} |
| 2260 |
|
| 2261 |
|
| 2262 |
#include "tdeicongrid.moc" |
| 2263 |
// vim: set ts=4: |