author | leseb <leseb> | 2002-07-10 21:59:27 (UTC) |
---|---|---|
committer | leseb <leseb> | 2002-07-10 21:59:27 (UTC) |
commit | f568737c20bea96fb79d85681a72e142ec05d66f (patch) (unidiff) | |
tree | 80d08b351bbdeec5be93885a4c18ba0207ef990a /noncore/graphics/drawpad/filltool.cpp | |
parent | 01b04adb73c8bc49938b71a4bebe6fb6a5477f75 (diff) | |
download | opie-f568737c20bea96fb79d85681a72e142ec05d66f.zip opie-f568737c20bea96fb79d85681a72e142ec05d66f.tar.gz opie-f568737c20bea96fb79d85681a72e142ec05d66f.tar.bz2 |
Undo/redo reimplemented
Diffstat (limited to 'noncore/graphics/drawpad/filltool.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/graphics/drawpad/filltool.cpp | 46 |
1 files changed, 23 insertions, 23 deletions
diff --git a/noncore/graphics/drawpad/filltool.cpp b/noncore/graphics/drawpad/filltool.cpp index 0177e1c..2a39d04 100644 --- a/noncore/graphics/drawpad/filltool.cpp +++ b/noncore/graphics/drawpad/filltool.cpp | |||
@@ -26,51 +26,51 @@ FillTool::FillTool(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas) | |||
26 | { | 26 | { |
27 | } | 27 | } |
28 | 28 | ||
29 | FillTool::~FillTool() | 29 | FillTool::~FillTool() |
30 | { | 30 | { |
31 | } | 31 | } |
32 | 32 | ||
33 | void FillTool::mousePressEvent(QMouseEvent* e) | 33 | void FillTool::mousePressEvent(QMouseEvent* e) |
34 | { | 34 | { |
35 | int x = e->x(); | 35 | int x = e->x(); |
36 | int y = e->y(); | 36 | int y = e->y(); |
37 | 37 | ||
38 | m_image = m_pDrawPadCanvas->currentPage()->convertToImage(); | 38 | m_image = m_pDrawPadCanvas->currentPage()->pixmap()->convertToImage(); |
39 | m_fillRgb = m_pDrawPad->brush().color().rgb(); | 39 | m_fillRgb = m_pDrawPad->brush().color().rgb(); |
40 | m_oldRgb = m_image.pixel(x, y); | 40 | m_oldRgb = m_image.pixel(x, y); |
41 | 41 | ||
42 | if (m_oldRgb != m_fillRgb) { | 42 | if (m_oldRgb != m_fillRgb) { |
43 | m_pDrawPadCanvas->backupPage(); | ||
44 | |||
43 | if (m_pDrawPad->antiAliasing()) { | 45 | if (m_pDrawPad->antiAliasing()) { |
44 | m_mask.create(m_image.width(), m_image.height(), 8, 2); | 46 | m_mask.create(m_image.width(), m_image.height(), 8, 2); |
45 | m_mask.fill(0); | 47 | m_mask.fill(0); |
46 | 48 | ||
47 | fillMaskLine(x, y); | 49 | fillMaskLine(x, y); |
48 | 50 | ||
49 | for (int i = 0; i < m_image.width(); i++) { | 51 | for (int i = 0; i < m_image.width(); i++) { |
50 | for (int j = 0; j < m_image.height(); j++) { | 52 | for (int j = 0; j < m_image.height(); j++) { |
51 | if (m_mask.pixelIndex(i, j) == 1) { | 53 | if (m_mask.pixelIndex(i, j) == 1) { |
52 | setInterpolatedPixel(i, j); | 54 | setInterpolatedPixel(i, j); |
53 | } | 55 | } |
54 | } | 56 | } |
55 | } | 57 | } |
56 | 58 | ||
57 | } else { | 59 | } else { |
58 | fillLine(x, y); | 60 | fillLine(x, y); |
59 | } | 61 | } |
60 | 62 | ||
61 | m_pDrawPadCanvas->currentPage()->convertFromImage(m_image); | 63 | m_pDrawPadCanvas->currentPage()->pixmap()->convertFromImage(m_image); |
62 | m_pDrawPadCanvas->viewport()->update(); | 64 | m_pDrawPadCanvas->viewport()->update(); |
63 | |||
64 | m_pDrawPadCanvas->backupPage(); | ||
65 | } | 65 | } |
66 | } | 66 | } |
67 | 67 | ||
68 | void FillTool::mouseReleaseEvent(QMouseEvent* e) | 68 | void FillTool::mouseReleaseEvent(QMouseEvent* e) |
69 | { | 69 | { |
70 | Q_UNUSED(e) | 70 | Q_UNUSED(e) |
71 | } | 71 | } |
72 | 72 | ||
73 | void FillTool::mouseMoveEvent(QMouseEvent* e) | 73 | void FillTool::mouseMoveEvent(QMouseEvent* e) |
74 | { | 74 | { |
75 | Q_UNUSED(e) | 75 | Q_UNUSED(e) |
76 | } | 76 | } |
@@ -102,49 +102,49 @@ void FillTool::fillLine(int x, int y) | |||
102 | 102 | ||
103 | for (int i = x1 + 1; i < x2; i++) { | 103 | for (int i = x1 + 1; i < x2; i++) { |
104 | fillLine(i, y + 1); | 104 | fillLine(i, y + 1); |
105 | } | 105 | } |
106 | } | 106 | } |
107 | } | 107 | } |
108 | } | 108 | } |
109 | 109 | ||
110 | void FillTool::fillMaskLine(int x, int y) | 110 | void FillTool::fillMaskLine(int x, int y) |
111 | { | 111 | { |
112 | if ((x >= 0) && (x < m_image.width()) && (y >= 0) && (y < m_image.height())) { | 112 | if ((x >= 0) && (x < m_image.width()) && (y >= 0) && (y < m_image.height())) { |
113 | if (m_mask.pixelIndex(x, y) == 0) { | 113 | if (m_mask.pixelIndex(x, y) == 0) { |
114 | if (rgbDistance(m_image.pixel(x, y), m_oldRgb) < FILL_THRESHOLD) { | 114 | if (rgbDistance(m_image.pixel(x, y), m_oldRgb) < FILL_THRESHOLD) { |
115 | int x1, x2; | 115 | int x1, x2; |
116 | 116 | ||
117 | x1 = x - 1; | 117 | x1 = x - 1; |
118 | x2 = x + 1; | 118 | x2 = x + 1; |
119 | 119 | ||
120 | while ((x1 >= 0) && (rgbDistance(m_image.pixel(x1, y), m_oldRgb) < FILL_THRESHOLD)) { | 120 | while ((x1 >= 0) && (rgbDistance(m_image.pixel(x1, y), m_oldRgb) < FILL_THRESHOLD)) { |
121 | x1--; | 121 | x1--; |
122 | } | 122 | } |
123 | 123 | ||
124 | while ((x2 < m_image.width()) && (rgbDistance(m_image.pixel(x2, y), m_oldRgb) < FILL_THRESHOLD)) { | 124 | while ((x2 < m_image.width()) && (rgbDistance(m_image.pixel(x2, y), m_oldRgb) < FILL_THRESHOLD)) { |
125 | x2++; | 125 | x2++; |
126 | } | 126 | } |
127 | 127 | ||
128 | for (int i = x1 + 1; i < x2; i++) { | 128 | for (int i = x1 + 1; i < x2; i++) { |
129 | m_mask.setPixel(i, y, 1); | 129 | m_mask.setPixel(i, y, 1); |
130 | } | 130 | } |
131 | 131 | ||
132 | for (int i = x1 + 1; i < x2; i++) { | 132 | for (int i = x1 + 1; i < x2; i++) { |
133 | fillMaskLine(i, y - 1); | 133 | fillMaskLine(i, y - 1); |
134 | } | 134 | } |
135 | 135 | ||
136 | for (int i = x1 + 1; i < x2; i++) { | 136 | for (int i = x1 + 1; i < x2; i++) { |
137 | fillMaskLine(i, y + 1); | 137 | fillMaskLine(i, y + 1); |
138 | } | 138 | } |
139 | } | 139 | } |
140 | } | 140 | } |
141 | } | 141 | } |
142 | } | 142 | } |
143 | 143 | ||
144 | void FillTool::setInterpolatedPixel(int x, int y) | 144 | void FillTool::setInterpolatedPixel(int x, int y) |
145 | { | 145 | { |
146 | int fillRed = QMIN(QMAX(qRed(m_fillRgb) + qRed(m_image.pixel(x, y)) - qRed(m_oldRgb), 0), 255); | 146 | int fillRed = QMIN(QMAX(qRed(m_fillRgb) + qRed(m_image.pixel(x, y)) - qRed(m_oldRgb), 0), 255); |
147 | int fillGreen = QMIN(QMAX(qGreen(m_fillRgb) + qGreen(m_image.pixel(x, y)) - qGreen(m_oldRgb), 0), 255); | 147 | int fillGreen = QMIN(QMAX(qGreen(m_fillRgb) + qGreen(m_image.pixel(x, y)) - qGreen(m_oldRgb), 0), 255); |
148 | int fillBlue = QMIN(QMAX(qBlue(m_fillRgb) + qBlue(m_image.pixel(x, y)) - qBlue(m_oldRgb), 0), 255); | 148 | int fillBlue = QMIN(QMAX(qBlue(m_fillRgb) + qBlue(m_image.pixel(x, y)) - qBlue(m_oldRgb), 0), 255); |
149 | 149 | ||
150 | m_image.setPixel(x, y, qRgb(fillRed, fillGreen, fillBlue)); | 150 | m_image.setPixel(x, y, qRgb(fillRed, fillGreen, fillBlue)); |