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
|
/***************************************************************************
* *
* DrawPad - a drawing program for Opie Environment *
* *
* (C) 2002 by S. Prud'homme <prudhomme@laposte.net> *
* *
* 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. *
* *
***************************************************************************/
#include "filldrawmode.h"
#include "drawpad.h"
#include "drawpadcanvas.h"
#include <qimage.h>
#include <qpixmap.h>
FillDrawMode::FillDrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas)
: DrawMode(drawPad, drawPadCanvas)
{
}
FillDrawMode::~FillDrawMode()
{
}
void FillDrawMode::mousePressEvent(QMouseEvent* e)
{
int x = e->x();
int y = e->y();
m_image = m_pDrawPadCanvas->currentPage()->convertToImage();
m_fillRgb = m_pDrawPad->brush().color().rgb();
m_oldRgb = m_image.pixel(x, y);
if (m_oldRgb != m_fillRgb) {
m_image.setPixel(x, y, m_fillRgb);
fillEast(x + 1, y);
fillSouth(x, y + 1);
fillWest(x - 1, y);
fillNorth(x, y - 1);
m_pDrawPadCanvas->currentPage()->convertFromImage(m_image);
m_pDrawPadCanvas->repaint();
}
}
void FillDrawMode::mouseReleaseEvent(QMouseEvent* e)
{
Q_UNUSED(e)
}
void FillDrawMode::mouseMoveEvent(QMouseEvent* e)
{
Q_UNUSED(e)
}
void FillDrawMode::fillEast(int x, int y)
{
if (x < m_image.width()) {
if (m_image.pixel(x, y) == m_oldRgb) {
m_image.setPixel(x, y, m_fillRgb);
fillEast(x + 1, y);
fillSouth(x, y + 1);
fillNorth(x, y - 1);
}
}
}
void FillDrawMode::fillSouth(int x, int y)
{
if (y < m_image.height()) {
if (m_image.pixel(x, y) == m_oldRgb) {
m_image.setPixel(x, y, m_fillRgb);
fillEast(x + 1, y);
fillSouth(x, y + 1);
fillWest(x - 1, y);
}
}
}
void FillDrawMode::fillWest(int x, int y)
{
if (x >= 0) {
if (m_image.pixel(x, y) == m_oldRgb) {
m_image.setPixel(x, y, m_fillRgb);
fillSouth(x, y + 1);
fillWest(x - 1, y);
fillNorth(x, y - 1);
}
}
}
void FillDrawMode::fillNorth(int x, int y)
{
if (y >= 0) {
if (m_image.pixel(x, y) == m_oldRgb) {
m_image.setPixel(x, y, m_fillRgb);
fillEast(x + 1, y);
fillWest(x - 1, y);
fillNorth(x, y - 1);
}
}
}
|