author | leseb <leseb> | 2002-06-23 17:47:47 (UTC) |
---|---|---|
committer | leseb <leseb> | 2002-06-23 17:47:47 (UTC) |
commit | 6fd46f6d23538ec6e0f48209f6c0f0d939a2effe (patch) (unidiff) | |
tree | 2a5d407155f72dc5496d3a7d412922cc6be97e61 | |
parent | 3251c55f854ecbd4ece8bf169177ffac28081aaa (diff) | |
download | opie-6fd46f6d23538ec6e0f48209f6c0f0d939a2effe.zip opie-6fd46f6d23538ec6e0f48209f6c0f0d939a2effe.tar.gz opie-6fd46f6d23538ec6e0f48209f6c0f0d939a2effe.tar.bz2 |
Anti-aliasing as an option
-rw-r--r-- | noncore/graphics/drawpad/drawpad.cpp | 13 | ||||
-rw-r--r-- | noncore/graphics/drawpad/drawpad.h | 4 | ||||
-rw-r--r-- | noncore/graphics/drawpad/ellipsetool.cpp | 57 | ||||
-rw-r--r-- | noncore/graphics/drawpad/filledellipsetool.cpp | 60 | ||||
-rw-r--r-- | noncore/graphics/drawpad/linetool.cpp | 55 | ||||
-rw-r--r-- | noncore/graphics/drawpad/pointtool.cpp | 54 |
6 files changed, 140 insertions, 103 deletions
diff --git a/noncore/graphics/drawpad/drawpad.cpp b/noncore/graphics/drawpad/drawpad.cpp index 45fb886..b29f5ba 100644 --- a/noncore/graphics/drawpad/drawpad.cpp +++ b/noncore/graphics/drawpad/drawpad.cpp | |||
@@ -54,58 +54,64 @@ DrawPad::DrawPad(QWidget* parent, const char* name) | |||
54 | 54 | ||
55 | m_pDrawPadCanvas = new DrawPadCanvas(this, this); | 55 | m_pDrawPadCanvas = new DrawPadCanvas(this, this); |
56 | 56 | ||
57 | connect(m_pDrawPadCanvas, SIGNAL(pagesChanged()), this, SLOT(updateNavigationToolButtons())); | 57 | connect(m_pDrawPadCanvas, SIGNAL(pagesChanged()), this, SLOT(updateNavigationToolButtons())); |
58 | connect(m_pDrawPadCanvas, SIGNAL(pagesChanged()), this, SLOT(updateCaption())); | 58 | connect(m_pDrawPadCanvas, SIGNAL(pagesChanged()), this, SLOT(updateCaption())); |
59 | connect(m_pDrawPadCanvas, SIGNAL(pageBackupsChanged()), this, SLOT(updateUndoRedoToolButtons())); | 59 | connect(m_pDrawPadCanvas, SIGNAL(pageBackupsChanged()), this, SLOT(updateUndoRedoToolButtons())); |
60 | 60 | ||
61 | setCentralWidget(m_pDrawPadCanvas); | 61 | setCentralWidget(m_pDrawPadCanvas); |
62 | 62 | ||
63 | // init menu | 63 | // init menu |
64 | 64 | ||
65 | setToolBarsMovable(false); | 65 | setToolBarsMovable(false); |
66 | 66 | ||
67 | QPEToolBar* menuToolBar = new QPEToolBar(this); | 67 | QPEToolBar* menuToolBar = new QPEToolBar(this); |
68 | QPEMenuBar* menuBar = new QPEMenuBar(menuToolBar); | 68 | QPEMenuBar* menuBar = new QPEMenuBar(menuToolBar); |
69 | 69 | ||
70 | QPopupMenu *toolsPopupMenu = new QPopupMenu(menuBar); | 70 | QPopupMenu* toolsPopupMenu = new QPopupMenu(menuBar); |
71 | 71 | ||
72 | QAction* deleteAllAction = new QAction(tr("Delete All"), QString::null, 0, this); | 72 | QAction* deleteAllAction = new QAction(tr("Delete All"), QString::null, 0, this); |
73 | connect(deleteAllAction, SIGNAL(activated()), this, SLOT(deleteAll())); | 73 | connect(deleteAllAction, SIGNAL(activated()), this, SLOT(deleteAll())); |
74 | deleteAllAction->addTo(toolsPopupMenu); | 74 | deleteAllAction->addTo(toolsPopupMenu); |
75 | 75 | ||
76 | toolsPopupMenu->insertSeparator(); | 76 | toolsPopupMenu->insertSeparator(); |
77 | 77 | ||
78 | QAction* importPageAction = new QAction(tr("Import"), tr("Import..."), 0, this); | 78 | QAction* importPageAction = new QAction(tr("Import"), tr("Import..."), 0, this); |
79 | connect(importPageAction, SIGNAL(activated()), this, SLOT(importPage())); | 79 | connect(importPageAction, SIGNAL(activated()), this, SLOT(importPage())); |
80 | importPageAction->addTo(toolsPopupMenu); | 80 | importPageAction->addTo(toolsPopupMenu); |
81 | 81 | ||
82 | QAction* exportPageAction = new QAction(tr("Export"), tr("Export..."), 0, this); | 82 | QAction* exportPageAction = new QAction(tr("Export"), tr("Export..."), 0, this); |
83 | connect(exportPageAction, SIGNAL(activated()), this, SLOT(exportPage())); | 83 | connect(exportPageAction, SIGNAL(activated()), this, SLOT(exportPage())); |
84 | exportPageAction->addTo(toolsPopupMenu); | 84 | exportPageAction->addTo(toolsPopupMenu); |
85 | 85 | ||
86 | toolsPopupMenu->insertSeparator(); | 86 | toolsPopupMenu->insertSeparator(); |
87 | 87 | ||
88 | QAction* thumbnailViewAction = new QAction(tr("Thumbnail View"), tr("Thumbnail View..."), 0, this); | 88 | QAction* thumbnailViewAction = new QAction(tr("Thumbnail View"), tr("Thumbnail View..."), 0, this); |
89 | connect(thumbnailViewAction, SIGNAL(activated()), this, SLOT(thumbnailView())); | 89 | connect(thumbnailViewAction, SIGNAL(activated()), this, SLOT(thumbnailView())); |
90 | thumbnailViewAction->addTo(toolsPopupMenu); | 90 | thumbnailViewAction->addTo(toolsPopupMenu); |
91 | 91 | ||
92 | QAction* pageInformationAction = new QAction(tr("Page Information"), tr("Page Information..."), 0, this); | 92 | QAction* pageInformationAction = new QAction(tr("Page Information"), tr("Page Information..."), 0, this); |
93 | connect(pageInformationAction, SIGNAL(activated()), this, SLOT(pageInformation())); | 93 | connect(pageInformationAction, SIGNAL(activated()), this, SLOT(pageInformation())); |
94 | pageInformationAction->addTo(toolsPopupMenu); | 94 | pageInformationAction->addTo(toolsPopupMenu); |
95 | 95 | ||
96 | toolsPopupMenu->insertSeparator(); | ||
97 | |||
98 | m_pAntiAliasingAction = new QAction(tr("Anti-Aliasing"), QString::null, 0, this); | ||
99 | m_pAntiAliasingAction->setToggleAction(true); | ||
100 | m_pAntiAliasingAction->addTo(toolsPopupMenu); | ||
101 | |||
96 | menuBar->insertItem(tr("Tools"), toolsPopupMenu); | 102 | menuBar->insertItem(tr("Tools"), toolsPopupMenu); |
97 | 103 | ||
98 | // init page toolbar | 104 | // init page toolbar |
99 | 105 | ||
100 | QPEToolBar* pageToolBar = new QPEToolBar(this); | 106 | QPEToolBar* pageToolBar = new QPEToolBar(this); |
101 | 107 | ||
102 | QAction* newPageAction = new QAction(tr("New Page"), Resource::loadIconSet("new"), QString::null, 0, this); | 108 | QAction* newPageAction = new QAction(tr("New Page"), Resource::loadIconSet("new"), QString::null, 0, this); |
103 | connect(newPageAction, SIGNAL(activated()), this, SLOT(newPage())); | 109 | connect(newPageAction, SIGNAL(activated()), this, SLOT(newPage())); |
104 | newPageAction->addTo(pageToolBar); | 110 | newPageAction->addTo(pageToolBar); |
105 | 111 | ||
106 | QAction* clearPageAction = new QAction(tr("Clear Page"), Resource::loadIconSet("drawpad/clear"), QString::null, 0, this); | 112 | QAction* clearPageAction = new QAction(tr("Clear Page"), Resource::loadIconSet("drawpad/clear"), QString::null, 0, this); |
107 | connect(clearPageAction, SIGNAL(activated()), this, SLOT(clearPage())); | 113 | connect(clearPageAction, SIGNAL(activated()), this, SLOT(clearPage())); |
108 | clearPageAction->addTo(pageToolBar); | 114 | clearPageAction->addTo(pageToolBar); |
109 | 115 | ||
110 | QAction* deletePageAction = new QAction(tr("Delete Page"), Resource::loadIconSet("trash"), QString::null, 0, this); | 116 | QAction* deletePageAction = new QAction(tr("Delete Page"), Resource::loadIconSet("trash"), QString::null, 0, this); |
111 | connect(deletePageAction, SIGNAL(activated()), this, SLOT(deletePage())); | 117 | connect(deletePageAction, SIGNAL(activated()), this, SLOT(deletePage())); |
@@ -262,32 +268,37 @@ DrawPad::DrawPad(QWidget* parent, const char* name) | |||
262 | file.close(); | 268 | file.close(); |
263 | } else { | 269 | } else { |
264 | m_pDrawPadCanvas->initialPage(); | 270 | m_pDrawPadCanvas->initialPage(); |
265 | } | 271 | } |
266 | } | 272 | } |
267 | 273 | ||
268 | DrawPad::~DrawPad() | 274 | DrawPad::~DrawPad() |
269 | { | 275 | { |
270 | QFile file(Global::applicationFileName("drawpad", "drawpad.xml")); | 276 | QFile file(Global::applicationFileName("drawpad", "drawpad.xml")); |
271 | 277 | ||
272 | if (file.open(IO_WriteOnly)) { | 278 | if (file.open(IO_WriteOnly)) { |
273 | m_pDrawPadCanvas->save(&file); | 279 | m_pDrawPadCanvas->save(&file); |
274 | file.close(); | 280 | file.close(); |
275 | } | 281 | } |
276 | } | 282 | } |
277 | 283 | ||
284 | bool DrawPad::antiAliasing() | ||
285 | { | ||
286 | return (m_pAntiAliasingAction->isOn()); | ||
287 | } | ||
288 | |||
278 | void DrawPad::newPage() | 289 | void DrawPad::newPage() |
279 | { | 290 | { |
280 | QRect rect = m_pDrawPadCanvas->contentsRect(); | 291 | QRect rect = m_pDrawPadCanvas->contentsRect(); |
281 | 292 | ||
282 | NewPageDialog newPageDialog(rect.width(), rect.height(), m_pen.color(), m_brush.color(), this); | 293 | NewPageDialog newPageDialog(rect.width(), rect.height(), m_pen.color(), m_brush.color(), this); |
283 | 294 | ||
284 | if (newPageDialog.exec() == QDialog::Accepted) { | 295 | if (newPageDialog.exec() == QDialog::Accepted) { |
285 | m_pDrawPadCanvas->newPage(newPageDialog.selectedTitle(), newPageDialog.selectedWidth(), | 296 | m_pDrawPadCanvas->newPage(newPageDialog.selectedTitle(), newPageDialog.selectedWidth(), |
286 | newPageDialog.selectedHeight(), newPageDialog.selectedColor()); | 297 | newPageDialog.selectedHeight(), newPageDialog.selectedColor()); |
287 | } | 298 | } |
288 | } | 299 | } |
289 | 300 | ||
290 | void DrawPad::clearPage() | 301 | void DrawPad::clearPage() |
291 | { | 302 | { |
292 | QMessageBox messageBox(tr("Clear Page"), tr("Do you want to clear\nthe current page?"), | 303 | QMessageBox messageBox(tr("Clear Page"), tr("Do you want to clear\nthe current page?"), |
293 | QMessageBox::Information, QMessageBox::Yes, | 304 | QMessageBox::Information, QMessageBox::Yes, |
diff --git a/noncore/graphics/drawpad/drawpad.h b/noncore/graphics/drawpad/drawpad.h index ce62802..8e29c61 100644 --- a/noncore/graphics/drawpad/drawpad.h +++ b/noncore/graphics/drawpad/drawpad.h | |||
@@ -25,32 +25,34 @@ class QAction; | |||
25 | class QColor; | 25 | class QColor; |
26 | class QToolButton; | 26 | class QToolButton; |
27 | class QWidgetStack; | 27 | class QWidgetStack; |
28 | 28 | ||
29 | class DrawPad : public QMainWindow | 29 | class DrawPad : public QMainWindow |
30 | { | 30 | { |
31 | Q_OBJECT | 31 | Q_OBJECT |
32 | 32 | ||
33 | public: | 33 | public: |
34 | DrawPad(QWidget* parent = 0, const char* name = 0); | 34 | DrawPad(QWidget* parent = 0, const char* name = 0); |
35 | ~DrawPad(); | 35 | ~DrawPad(); |
36 | 36 | ||
37 | Tool* tool() { return m_pTool; } | 37 | Tool* tool() { return m_pTool; } |
38 | QPen pen() { return m_pen; } | 38 | QPen pen() { return m_pen; } |
39 | QBrush brush() { return m_brush; } | 39 | QBrush brush() { return m_brush; } |
40 | 40 | ||
41 | bool antiAliasing(); | ||
42 | |||
41 | private slots: | 43 | private slots: |
42 | void newPage(); | 44 | void newPage(); |
43 | void clearPage(); | 45 | void clearPage(); |
44 | void deletePage(); | 46 | void deletePage(); |
45 | 47 | ||
46 | void setPointTool(); | 48 | void setPointTool(); |
47 | void setLineTool(); | 49 | void setLineTool(); |
48 | void setRectangleTool(); | 50 | void setRectangleTool(); |
49 | void setFilledRectangleTool(); | 51 | void setFilledRectangleTool(); |
50 | void setEllipseTool(); | 52 | void setEllipseTool(); |
51 | void setFilledEllipseTool(); | 53 | void setFilledEllipseTool(); |
52 | void setTextTool(); | 54 | void setTextTool(); |
53 | void setFillTool(); | 55 | void setFillTool(); |
54 | void setEraseTool(); | 56 | void setEraseTool(); |
55 | 57 | ||
56 | void changePenWidth(int value); | 58 | void changePenWidth(int value); |
@@ -61,32 +63,34 @@ private slots: | |||
61 | void updateNavigationToolButtons(); | 63 | void updateNavigationToolButtons(); |
62 | void updateCaption(); | 64 | void updateCaption(); |
63 | 65 | ||
64 | void deleteAll(); | 66 | void deleteAll(); |
65 | void importPage(); | 67 | void importPage(); |
66 | void exportPage(); | 68 | void exportPage(); |
67 | void thumbnailView(); | 69 | void thumbnailView(); |
68 | void pageInformation(); | 70 | void pageInformation(); |
69 | 71 | ||
70 | private: | 72 | private: |
71 | DrawPadCanvas* m_pDrawPadCanvas; | 73 | DrawPadCanvas* m_pDrawPadCanvas; |
72 | 74 | ||
73 | Tool* m_pTool; | 75 | Tool* m_pTool; |
74 | QPen m_pen; | 76 | QPen m_pen; |
75 | QBrush m_brush; | 77 | QBrush m_brush; |
76 | 78 | ||
79 | QAction* m_pAntiAliasingAction; | ||
80 | |||
77 | QAction* m_pUndoAction; | 81 | QAction* m_pUndoAction; |
78 | QAction* m_pRedoAction; | 82 | QAction* m_pRedoAction; |
79 | 83 | ||
80 | QAction* m_pFirstPageAction; | 84 | QAction* m_pFirstPageAction; |
81 | QAction* m_pPreviousPageAction; | 85 | QAction* m_pPreviousPageAction; |
82 | QAction* m_pNextPageAction; | 86 | QAction* m_pNextPageAction; |
83 | QAction* m_pLastPageAction; | 87 | QAction* m_pLastPageAction; |
84 | 88 | ||
85 | QAction* m_pPointToolAction; | 89 | QAction* m_pPointToolAction; |
86 | QAction* m_pLineToolAction; | 90 | QAction* m_pLineToolAction; |
87 | QAction* m_pRectangleToolAction; | 91 | QAction* m_pRectangleToolAction; |
88 | QAction* m_pFilledRectangleToolAction; | 92 | QAction* m_pFilledRectangleToolAction; |
89 | QAction* m_pEllipseToolAction; | 93 | QAction* m_pEllipseToolAction; |
90 | QAction* m_pFilledEllipseToolAction; | 94 | QAction* m_pFilledEllipseToolAction; |
91 | QAction* m_pTextToolAction; | 95 | QAction* m_pTextToolAction; |
92 | QAction* m_pFillToolAction; | 96 | QAction* m_pFillToolAction; |
diff --git a/noncore/graphics/drawpad/ellipsetool.cpp b/noncore/graphics/drawpad/ellipsetool.cpp index 733bade..0cdb731 100644 --- a/noncore/graphics/drawpad/ellipsetool.cpp +++ b/noncore/graphics/drawpad/ellipsetool.cpp | |||
@@ -19,58 +19,63 @@ | |||
19 | #include <qimage.h> | 19 | #include <qimage.h> |
20 | #include <qpixmap.h> | 20 | #include <qpixmap.h> |
21 | 21 | ||
22 | EllipseTool::EllipseTool(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas) | 22 | EllipseTool::EllipseTool(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas) |
23 | : ShapeTool(drawPad, drawPadCanvas) | 23 | : ShapeTool(drawPad, drawPadCanvas) |
24 | { | 24 | { |
25 | } | 25 | } |
26 | 26 | ||
27 | EllipseTool::~EllipseTool() | 27 | EllipseTool::~EllipseTool() |
28 | { | 28 | { |
29 | } | 29 | } |
30 | 30 | ||
31 | void EllipseTool::drawFinalShape(QPainter& p) | 31 | void EllipseTool::drawFinalShape(QPainter& p) |
32 | { | 32 | { |
33 | p.setRasterOp(Qt::NotROP); | 33 | p.setRasterOp(Qt::NotROP); |
34 | p.drawRect(QRect(m_polyline[2], m_polyline[0])); | 34 | p.drawRect(QRect(m_polyline[2], m_polyline[0])); |
35 | p.setRasterOp(Qt::CopyROP); | ||
35 | 36 | ||
36 | QRect r = m_polyline.boundingRect(); | 37 | if (m_pDrawPad->antiAliasing()) { |
37 | r = r.normalize(); | 38 | QRect r = m_polyline.boundingRect(); |
38 | r.setLeft(r.left() - m_pDrawPad->pen().width()); | 39 | r = r.normalize(); |
39 | r.setTop(r.top() - m_pDrawPad->pen().width()); | 40 | r.setLeft(r.left() - m_pDrawPad->pen().width()); |
40 | r.setRight(r.right() + m_pDrawPad->pen().width()); | 41 | r.setTop(r.top() - m_pDrawPad->pen().width()); |
41 | r.setBottom(r.bottom() + m_pDrawPad->pen().width()); | 42 | r.setRight(r.right() + m_pDrawPad->pen().width()); |
43 | r.setBottom(r.bottom() + m_pDrawPad->pen().width()); | ||
42 | 44 | ||
43 | QPixmap areaPixmap(r.width(), r.height()); | 45 | QPixmap areaPixmap(r.width(), r.height()); |
44 | bitBlt(&areaPixmap, QPoint(0, 0), p.device(), r); | 46 | bitBlt(&areaPixmap, QPoint(0, 0), p.device(), r); |
45 | 47 | ||
46 | QImage areaImage = areaPixmap.convertToImage(); | 48 | QImage areaImage = areaPixmap.convertToImage(); |
47 | QImage bigAreaImage = areaImage.smoothScale(areaImage.width() * 3, areaImage.height() * 3); | 49 | QImage bigAreaImage = areaImage.smoothScale(areaImage.width() * 3, areaImage.height() * 3); |
48 | 50 | ||
49 | QPixmap bigAreaPixmap; | 51 | QPixmap bigAreaPixmap; |
50 | bigAreaPixmap.convertFromImage(bigAreaImage); | 52 | bigAreaPixmap.convertFromImage(bigAreaImage); |
51 | 53 | ||
52 | QPen bigAreaPen = m_pDrawPad->pen(); | 54 | QPen bigAreaPen = m_pDrawPad->pen(); |
53 | bigAreaPen.setWidth(bigAreaPen.width() * 3); | 55 | bigAreaPen.setWidth(bigAreaPen.width() * 3); |
54 | 56 | ||
55 | QPainter bigAreaPainter; | 57 | QPainter bigAreaPainter; |
56 | bigAreaPainter.begin(&bigAreaPixmap); | 58 | bigAreaPainter.begin(&bigAreaPixmap); |
57 | bigAreaPainter.setPen(bigAreaPen); | 59 | bigAreaPainter.setPen(bigAreaPen); |
58 | bigAreaPainter.drawEllipse(QRect(bigAreaPen.width() + 1, bigAreaPen.width() + 1, | 60 | bigAreaPainter.drawEllipse(QRect(bigAreaPen.width() + 1, bigAreaPen.width() + 1, |
59 | bigAreaPixmap.width() - 2 * (bigAreaPen.width() + 1), | 61 | bigAreaPixmap.width() - 2 * (bigAreaPen.width() + 1), |
60 | bigAreaPixmap.height() - 2 * (bigAreaPen.width() + 1))); | 62 | bigAreaPixmap.height() - 2 * (bigAreaPen.width() + 1))); |
61 | bigAreaPainter.end(); | 63 | bigAreaPainter.end(); |
62 | 64 | ||
63 | bigAreaImage = bigAreaPixmap.convertToImage(); | 65 | bigAreaImage = bigAreaPixmap.convertToImage(); |
64 | areaImage = bigAreaImage.smoothScale(bigAreaImage.width() / 3, bigAreaImage.height() / 3); | 66 | areaImage = bigAreaImage.smoothScale(bigAreaImage.width() / 3, bigAreaImage.height() / 3); |
65 | areaPixmap.convertFromImage(areaImage); | 67 | areaPixmap.convertFromImage(areaImage); |
66 | 68 | ||
67 | p.setRasterOp(Qt::CopyROP); | 69 | p.drawPixmap(r.x(), r.y(), areaPixmap); |
68 | p.drawPixmap(r.x(), r.y(), areaPixmap); | 70 | } else { |
71 | p.setPen(m_pDrawPad->pen()); | ||
72 | p.drawEllipse(QRect(m_polyline[2], m_polyline[0])); | ||
73 | } | ||
69 | } | 74 | } |
70 | 75 | ||
71 | void EllipseTool::drawTemporaryShape(QPainter& p) | 76 | void EllipseTool::drawTemporaryShape(QPainter& p) |
72 | { | 77 | { |
73 | p.setRasterOp(Qt::NotROP); | 78 | p.setRasterOp(Qt::NotROP); |
74 | p.drawRect(QRect(m_polyline[2], m_polyline[1])); | 79 | p.drawRect(QRect(m_polyline[2], m_polyline[1])); |
75 | p.drawRect(QRect(m_polyline[2], m_polyline[0])); | 80 | p.drawRect(QRect(m_polyline[2], m_polyline[0])); |
76 | } | 81 | } |
diff --git a/noncore/graphics/drawpad/filledellipsetool.cpp b/noncore/graphics/drawpad/filledellipsetool.cpp index 2f7ec8f..6b5bbc6 100644 --- a/noncore/graphics/drawpad/filledellipsetool.cpp +++ b/noncore/graphics/drawpad/filledellipsetool.cpp | |||
@@ -19,59 +19,65 @@ | |||
19 | #include <qimage.h> | 19 | #include <qimage.h> |
20 | #include <qpixmap.h> | 20 | #include <qpixmap.h> |
21 | 21 | ||
22 | FilledEllipseTool::FilledEllipseTool(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas) | 22 | FilledEllipseTool::FilledEllipseTool(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas) |
23 | : ShapeTool(drawPad, drawPadCanvas) | 23 | : ShapeTool(drawPad, drawPadCanvas) |
24 | { | 24 | { |
25 | } | 25 | } |
26 | 26 | ||
27 | FilledEllipseTool::~FilledEllipseTool() | 27 | FilledEllipseTool::~FilledEllipseTool() |
28 | { | 28 | { |
29 | } | 29 | } |
30 | 30 | ||
31 | void FilledEllipseTool::drawFinalShape(QPainter& p) | 31 | void FilledEllipseTool::drawFinalShape(QPainter& p) |
32 | { | 32 | { |
33 | p.setRasterOp(Qt::NotROP); | 33 | p.setRasterOp(Qt::NotROP); |
34 | p.drawRect(QRect(m_polyline[2], m_polyline[0])); | 34 | p.drawRect(QRect(m_polyline[2], m_polyline[0])); |
35 | p.setRasterOp(Qt::CopyROP); | ||
35 | 36 | ||
36 | QRect r = m_polyline.boundingRect(); | 37 | if (m_pDrawPad->antiAliasing()) { |
37 | r = r.normalize(); | 38 | QRect r = m_polyline.boundingRect(); |
38 | r.setLeft(r.left() - m_pDrawPad->pen().width()); | 39 | r = r.normalize(); |
39 | r.setTop(r.top() - m_pDrawPad->pen().width()); | 40 | r.setLeft(r.left() - m_pDrawPad->pen().width()); |
40 | r.setRight(r.right() + m_pDrawPad->pen().width()); | 41 | r.setTop(r.top() - m_pDrawPad->pen().width()); |
41 | r.setBottom(r.bottom() + m_pDrawPad->pen().width()); | 42 | r.setRight(r.right() + m_pDrawPad->pen().width()); |
43 | r.setBottom(r.bottom() + m_pDrawPad->pen().width()); | ||
42 | 44 | ||
43 | QPixmap areaPixmap(r.width(), r.height()); | 45 | QPixmap areaPixmap(r.width(), r.height()); |
44 | bitBlt(&areaPixmap, QPoint(0, 0), p.device(), r); | 46 | bitBlt(&areaPixmap, QPoint(0, 0), p.device(), r); |
45 | 47 | ||
46 | QImage areaImage = areaPixmap.convertToImage(); | 48 | QImage areaImage = areaPixmap.convertToImage(); |
47 | QImage bigAreaImage = areaImage.smoothScale(areaImage.width() * 3, areaImage.height() * 3); | 49 | QImage bigAreaImage = areaImage.smoothScale(areaImage.width() * 3, areaImage.height() * 3); |
48 | 50 | ||
49 | QPixmap bigAreaPixmap; | 51 | QPixmap bigAreaPixmap; |
50 | bigAreaPixmap.convertFromImage(bigAreaImage); | 52 | bigAreaPixmap.convertFromImage(bigAreaImage); |
51 | 53 | ||
52 | QPen bigAreaPen = m_pDrawPad->pen(); | 54 | QPen bigAreaPen = m_pDrawPad->pen(); |
53 | bigAreaPen.setWidth(bigAreaPen.width() * 3); | 55 | bigAreaPen.setWidth(bigAreaPen.width() * 3); |
54 | 56 | ||
55 | QPainter bigAreaPainter; | 57 | QPainter bigAreaPainter; |
56 | bigAreaPainter.begin(&bigAreaPixmap); | 58 | bigAreaPainter.begin(&bigAreaPixmap); |
57 | bigAreaPainter.setPen(bigAreaPen); | 59 | bigAreaPainter.setPen(bigAreaPen); |
58 | bigAreaPainter.setBrush(m_pDrawPad->brush()); | 60 | bigAreaPainter.setBrush(m_pDrawPad->brush()); |
59 | bigAreaPainter.drawEllipse(QRect(bigAreaPen.width() + 1, bigAreaPen.width() + 1, | 61 | bigAreaPainter.drawEllipse(QRect(bigAreaPen.width() + 1, bigAreaPen.width() + 1, |
60 | bigAreaPixmap.width() - 2 * (bigAreaPen.width() + 1), | 62 | bigAreaPixmap.width() - 2 * (bigAreaPen.width() + 1), |
61 | bigAreaPixmap.height() - 2 * (bigAreaPen.width() + 1))); | 63 | bigAreaPixmap.height() - 2 * (bigAreaPen.width() + 1))); |
62 | bigAreaPainter.end(); | 64 | bigAreaPainter.end(); |
63 | 65 | ||
64 | bigAreaImage = bigAreaPixmap.convertToImage(); | 66 | bigAreaImage = bigAreaPixmap.convertToImage(); |
65 | areaImage = bigAreaImage.smoothScale(bigAreaImage.width() / 3, bigAreaImage.height() / 3); | 67 | areaImage = bigAreaImage.smoothScale(bigAreaImage.width() / 3, bigAreaImage.height() / 3); |
66 | areaPixmap.convertFromImage(areaImage); | 68 | areaPixmap.convertFromImage(areaImage); |
67 | 69 | ||
68 | p.setRasterOp(Qt::CopyROP); | 70 | p.drawPixmap(r.x(), r.y(), areaPixmap); |
69 | p.drawPixmap(r.x(), r.y(), areaPixmap); | 71 | } else { |
72 | p.setPen(m_pDrawPad->pen()); | ||
73 | p.setBrush(m_pDrawPad->brush()); | ||
74 | p.drawEllipse(QRect(m_polyline[2], m_polyline[0])); | ||
75 | } | ||
70 | } | 76 | } |
71 | 77 | ||
72 | void FilledEllipseTool::drawTemporaryShape(QPainter& p) | 78 | void FilledEllipseTool::drawTemporaryShape(QPainter& p) |
73 | { | 79 | { |
74 | p.setRasterOp(Qt::NotROP); | 80 | p.setRasterOp(Qt::NotROP); |
75 | p.drawRect(QRect(m_polyline[2], m_polyline[1])); | 81 | p.drawRect(QRect(m_polyline[2], m_polyline[1])); |
76 | p.drawRect(QRect(m_polyline[2], m_polyline[0])); | 82 | p.drawRect(QRect(m_polyline[2], m_polyline[0])); |
77 | } | 83 | } |
diff --git a/noncore/graphics/drawpad/linetool.cpp b/noncore/graphics/drawpad/linetool.cpp index 99cd6de..b6baa2a 100644 --- a/noncore/graphics/drawpad/linetool.cpp +++ b/noncore/graphics/drawpad/linetool.cpp | |||
@@ -19,59 +19,64 @@ | |||
19 | #include <qimage.h> | 19 | #include <qimage.h> |
20 | #include <qpixmap.h> | 20 | #include <qpixmap.h> |
21 | 21 | ||
22 | LineTool::LineTool(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas) | 22 | LineTool::LineTool(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas) |
23 | : ShapeTool(drawPad, drawPadCanvas) | 23 | : ShapeTool(drawPad, drawPadCanvas) |
24 | { | 24 | { |
25 | } | 25 | } |
26 | 26 | ||
27 | LineTool::~LineTool() | 27 | LineTool::~LineTool() |
28 | { | 28 | { |
29 | } | 29 | } |
30 | 30 | ||
31 | void LineTool::drawFinalShape(QPainter& p) | 31 | void LineTool::drawFinalShape(QPainter& p) |
32 | { | 32 | { |
33 | p.setRasterOp(Qt::NotROP); | 33 | p.setRasterOp(Qt::NotROP); |
34 | p.drawLine(m_polyline[2], m_polyline[0]); | 34 | p.drawLine(m_polyline[2], m_polyline[0]); |
35 | p.setRasterOp(Qt::CopyROP); | ||
35 | 36 | ||
36 | QRect r = m_polyline.boundingRect(); | 37 | if (m_pDrawPad->antiAliasing()) { |
37 | r = r.normalize(); | 38 | QRect r = m_polyline.boundingRect(); |
38 | r.setLeft(r.left() - m_pDrawPad->pen().width()); | 39 | r = r.normalize(); |
39 | r.setTop(r.top() - m_pDrawPad->pen().width()); | 40 | r.setLeft(r.left() - m_pDrawPad->pen().width()); |
40 | r.setRight(r.right() + m_pDrawPad->pen().width()); | 41 | r.setTop(r.top() - m_pDrawPad->pen().width()); |
41 | r.setBottom(r.bottom() + m_pDrawPad->pen().width()); | 42 | r.setRight(r.right() + m_pDrawPad->pen().width()); |
43 | r.setBottom(r.bottom() + m_pDrawPad->pen().width()); | ||
42 | 44 | ||
43 | QPixmap areaPixmap(r.width(), r.height()); | 45 | QPixmap areaPixmap(r.width(), r.height()); |
44 | bitBlt(&areaPixmap, QPoint(0, 0), p.device(), r); | 46 | bitBlt(&areaPixmap, QPoint(0, 0), p.device(), r); |
45 | 47 | ||
46 | QImage areaImage = areaPixmap.convertToImage(); | 48 | QImage areaImage = areaPixmap.convertToImage(); |
47 | QImage bigAreaImage = areaImage.smoothScale(areaImage.width() * 3, areaImage.height() * 3); | 49 | QImage bigAreaImage = areaImage.smoothScale(areaImage.width() * 3, areaImage.height() * 3); |
48 | 50 | ||
49 | QPixmap bigAreaPixmap; | 51 | QPixmap bigAreaPixmap; |
50 | bigAreaPixmap.convertFromImage(bigAreaImage); | 52 | bigAreaPixmap.convertFromImage(bigAreaImage); |
51 | 53 | ||
52 | QPen bigAreaPen = m_pDrawPad->pen(); | 54 | QPen bigAreaPen = m_pDrawPad->pen(); |
53 | bigAreaPen.setWidth(bigAreaPen.width() * 3); | 55 | bigAreaPen.setWidth(bigAreaPen.width() * 3); |
54 | 56 | ||
55 | QPainter bigAreaPainter; | 57 | QPainter bigAreaPainter; |
56 | bigAreaPainter.begin(&bigAreaPixmap); | 58 | bigAreaPainter.begin(&bigAreaPixmap); |
57 | bigAreaPainter.setPen(bigAreaPen); | 59 | bigAreaPainter.setPen(bigAreaPen); |
58 | 60 | ||
59 | bigAreaPainter.drawLine((m_polyline[2].x() - r.x()) * 3 + 1, (m_polyline[2].y() - r.y()) * 3 + 1, | 61 | bigAreaPainter.drawLine((m_polyline[2].x() - r.x()) * 3 + 1, (m_polyline[2].y() - r.y()) * 3 + 1, |
60 | (m_polyline[0].x() - r.x()) * 3 + 1, (m_polyline[0].y() - r.y()) * 3 + 1); | 62 | (m_polyline[0].x() - r.x()) * 3 + 1, (m_polyline[0].y() - r.y()) * 3 + 1); |
61 | 63 | ||
62 | bigAreaPainter.end(); | 64 | bigAreaPainter.end(); |
63 | 65 | ||
64 | bigAreaImage = bigAreaPixmap.convertToImage(); | 66 | bigAreaImage = bigAreaPixmap.convertToImage(); |
65 | areaImage = bigAreaImage.smoothScale(bigAreaImage.width() / 3, bigAreaImage.height() / 3); | 67 | areaImage = bigAreaImage.smoothScale(bigAreaImage.width() / 3, bigAreaImage.height() / 3); |
66 | areaPixmap.convertFromImage(areaImage); | 68 | areaPixmap.convertFromImage(areaImage); |
67 | 69 | ||
68 | p.setRasterOp(Qt::CopyROP); | 70 | p.drawPixmap(r.x(), r.y(), areaPixmap); |
69 | p.drawPixmap(r.x(), r.y(), areaPixmap); | 71 | } else { |
72 | p.setPen(m_pDrawPad->pen()); | ||
73 | p.drawLine(m_polyline[2], m_polyline[0]); | ||
74 | } | ||
70 | } | 75 | } |
71 | 76 | ||
72 | void LineTool::drawTemporaryShape(QPainter& p) | 77 | void LineTool::drawTemporaryShape(QPainter& p) |
73 | { | 78 | { |
74 | p.setRasterOp(Qt::NotROP); | 79 | p.setRasterOp(Qt::NotROP); |
75 | p.drawLine(m_polyline[2], m_polyline[1]); | 80 | p.drawLine(m_polyline[2], m_polyline[1]); |
76 | p.drawLine(m_polyline[2], m_polyline[0]); | 81 | p.drawLine(m_polyline[2], m_polyline[0]); |
77 | } | 82 | } |
diff --git a/noncore/graphics/drawpad/pointtool.cpp b/noncore/graphics/drawpad/pointtool.cpp index 22bb089..a4f846e 100644 --- a/noncore/graphics/drawpad/pointtool.cpp +++ b/noncore/graphics/drawpad/pointtool.cpp | |||
@@ -40,66 +40,72 @@ void PointTool::mousePressEvent(QMouseEvent* e) | |||
40 | void PointTool::mouseReleaseEvent(QMouseEvent* e) | 40 | void PointTool::mouseReleaseEvent(QMouseEvent* e) |
41 | { | 41 | { |
42 | Q_UNUSED(e) | 42 | Q_UNUSED(e) |
43 | 43 | ||
44 | m_mousePressed = false; | 44 | m_mousePressed = false; |
45 | 45 | ||
46 | m_pDrawPadCanvas->backupPage(); | 46 | m_pDrawPadCanvas->backupPage(); |
47 | } | 47 | } |
48 | 48 | ||
49 | void PointTool::mouseMoveEvent(QMouseEvent* e) | 49 | void PointTool::mouseMoveEvent(QMouseEvent* e) |
50 | { | 50 | { |
51 | if (m_mousePressed) { | 51 | if (m_mousePressed) { |
52 | m_polyline[2] = m_polyline[1]; | 52 | m_polyline[2] = m_polyline[1]; |
53 | m_polyline[1] = m_polyline[0]; | 53 | m_polyline[1] = m_polyline[0]; |
54 | m_polyline[0] = e->pos(); | 54 | m_polyline[0] = e->pos(); |
55 | 55 | ||
56 | QPainter painter; | ||
57 | painter.begin(m_pDrawPadCanvas->currentPage()); | ||
58 | |||
59 | QRect r = m_polyline.boundingRect(); | 56 | QRect r = m_polyline.boundingRect(); |
60 | r = r.normalize(); | 57 | r = r.normalize(); |
61 | r.setLeft(r.left() - m_pDrawPad->pen().width()); | 58 | r.setLeft(r.left() - m_pDrawPad->pen().width()); |
62 | r.setTop(r.top() - m_pDrawPad->pen().width()); | 59 | r.setTop(r.top() - m_pDrawPad->pen().width()); |
63 | r.setRight(r.right() + m_pDrawPad->pen().width()); | 60 | r.setRight(r.right() + m_pDrawPad->pen().width()); |
64 | r.setBottom(r.bottom() + m_pDrawPad->pen().width()); | 61 | r.setBottom(r.bottom() + m_pDrawPad->pen().width()); |
65 | 62 | ||
66 | QPixmap areaPixmap(r.width(), r.height()); | 63 | QPainter painter; |
67 | bitBlt(&areaPixmap, QPoint(0, 0), painter.device(), r); | 64 | painter.begin(m_pDrawPadCanvas->currentPage()); |
65 | |||
66 | if (m_pDrawPad->antiAliasing()) { | ||
67 | QPixmap areaPixmap(r.width(), r.height()); | ||
68 | bitBlt(&areaPixmap, QPoint(0, 0), painter.device(), r); | ||
69 | |||
70 | QImage areaImage = areaPixmap.convertToImage(); | ||
71 | QImage bigAreaImage = areaImage.smoothScale(areaImage.width() * 3, areaImage.height() * 3); | ||
68 | 72 | ||
69 | QImage areaImage = areaPixmap.convertToImage(); | 73 | QPixmap bigAreaPixmap; |
70 | QImage bigAreaImage = areaImage.smoothScale(areaImage.width() * 3, areaImage.height() * 3); | 74 | bigAreaPixmap.convertFromImage(bigAreaImage); |
71 | 75 | ||
72 | QPixmap bigAreaPixmap; | 76 | QPen bigAreaPen = m_pDrawPad->pen(); |
73 | bigAreaPixmap.convertFromImage(bigAreaImage); | 77 | bigAreaPen.setWidth(bigAreaPen.width() * 3); |
74 | 78 | ||
75 | QPen bigAreaPen = m_pDrawPad->pen(); | 79 | QPainter bigAreaPainter; |
76 | bigAreaPen.setWidth(bigAreaPen.width() * 3); | 80 | bigAreaPainter.begin(&bigAreaPixmap); |
81 | bigAreaPainter.setPen(bigAreaPen); | ||
77 | 82 | ||
78 | QPainter bigAreaPainter; | 83 | QPointArray bigAreaPolyline(3); |
79 | bigAreaPainter.begin(&bigAreaPixmap); | 84 | bigAreaPolyline.setPoint(0, (m_polyline[0].x() - r.x()) * 3 + 1, (m_polyline[0].y() - r.y()) * 3 + 1); |
80 | bigAreaPainter.setPen(bigAreaPen); | 85 | bigAreaPolyline.setPoint(1, (m_polyline[1].x() - r.x()) * 3 + 1, (m_polyline[1].y() - r.y()) * 3 + 1); |
86 | bigAreaPolyline.setPoint(2, (m_polyline[2].x() - r.x()) * 3 + 1, (m_polyline[2].y() - r.y()) * 3 + 1); | ||
81 | 87 | ||
82 | QPointArray bigAreaPolyline(3); | 88 | bigAreaPainter.drawPolyline(bigAreaPolyline); |
83 | bigAreaPolyline.setPoint(0, (m_polyline[0].x() - r.x()) * 3 + 1, (m_polyline[0].y() - r.y()) * 3 + 1); | 89 | bigAreaPainter.end(); |
84 | bigAreaPolyline.setPoint(1, (m_polyline[1].x() - r.x()) * 3 + 1, (m_polyline[1].y() - r.y()) * 3 + 1); | ||
85 | bigAreaPolyline.setPoint(2, (m_polyline[2].x() - r.x()) * 3 + 1, (m_polyline[2].y() - r.y()) * 3 + 1); | ||
86 | 90 | ||
87 | bigAreaPainter.drawPolyline(bigAreaPolyline); | 91 | bigAreaImage = bigAreaPixmap.convertToImage(); |
88 | bigAreaPainter.end(); | 92 | areaImage = bigAreaImage.smoothScale(bigAreaImage.width() / 3, bigAreaImage.height() / 3); |
93 | areaPixmap.convertFromImage(areaImage); | ||
89 | 94 | ||
90 | bigAreaImage = bigAreaPixmap.convertToImage(); | 95 | painter.drawPixmap(r.x(), r.y(), areaPixmap); |
91 | areaImage = bigAreaImage.smoothScale(bigAreaImage.width() / 3, bigAreaImage.height() / 3); | 96 | } else { |
92 | areaPixmap.convertFromImage(areaImage); | 97 | painter.setPen(m_pDrawPad->pen()); |
98 | painter.drawPolyline(m_polyline); | ||
99 | } | ||
93 | 100 | ||
94 | painter.drawPixmap(r.x(), r.y(), areaPixmap); | ||
95 | painter.end(); | 101 | painter.end(); |
96 | 102 | ||
97 | QRect viewportRect(m_pDrawPadCanvas->contentsToViewport(r.topLeft()), | 103 | QRect viewportRect(m_pDrawPadCanvas->contentsToViewport(r.topLeft()), |
98 | m_pDrawPadCanvas->contentsToViewport(r.bottomRight())); | 104 | m_pDrawPadCanvas->contentsToViewport(r.bottomRight())); |
99 | 105 | ||
100 | bitBlt(m_pDrawPadCanvas->viewport(), viewportRect.x(), viewportRect.y(), | 106 | bitBlt(m_pDrawPadCanvas->viewport(), viewportRect.x(), viewportRect.y(), |
101 | m_pDrawPadCanvas->currentPage(), r.x(), r.y(), r.width(), r.height()); | 107 | m_pDrawPadCanvas->currentPage(), r.x(), r.y(), r.width(), r.height()); |
102 | 108 | ||
103 | m_pDrawPadCanvas->viewport()->update(viewportRect); | 109 | m_pDrawPadCanvas->viewport()->update(viewportRect); |
104 | } | 110 | } |
105 | } | 111 | } |