]> Shamusworld >> Repos - ttedit/blob - src/editwindow.cpp
Added individual polygon rotation tool.
[ttedit] / src / editwindow.cpp
1 //
2 // TTEDIT.CPP - The TrueType Editor
3 // by James L. Hammons
4 // (C) 2004 Underground Software
5 //
6 // JLH = James L. Hammons <jlhamm@acm.org>
7 //
8 // Who  When        What
9 // ---  ----------  -------------------------------------------------------------
10 // JLH  08/28/2008  Created this file
11 // JLH  09/02/2008  Separated scrolling from dedicated tool to MMB drag
12 // JLH  03/13/2009  Converted from wxWidgets to Qt
13 //
14
15 // FIXED:
16 //
17 // - Fixed scrolling
18 //
19 // STILL TO BE DONE:
20 //
21 // - Fix bug in Glyphpoints when dragging on an empty canvas or loading a font
22 // - Fix zooming, settings (ini)
23 // - Fix point adding bug 1: should be able to add points to empty canvas
24 // - Fix point adding bug 2: should be able to add point successfully to single
25 //   point on screen
26 // - Add poly multi-select
27 // - Add point multi-select
28 // - Undo system
29 //
30
31 // Uncomment this for debugging...
32 #define DEBUG
33 #define DEBUGFOO            // Various tool debugging...
34 #define DEBUGTP                         // Toolpalette debugging...
35
36 #include "editwindow.h"
37 #include "charwindow.h"
38 #include "debug.h"
39 #include "graphicprimitives.h"
40 #include "mainwindow.h"
41 #include "ttedit.h"
42 #include "vector.h"
43
44
45 EditWindow::EditWindow(QWidget * parent/*= NULL*/): QWidget(parent),
46         scale(1.0), offsetX(-10), offsetY(-10), tool(TOOLSelect),
47         ptHighlight(-1), oldPtHighlight(-1), ptNextHighlight(-1), oldPtNextHighlight(-1),
48         polyFirstPoint(true), showRotationCenter(false), haveZeroPoint(false)
49 {
50         setBackgroundRole(QPalette::Base);
51         setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
52
53         toolPalette = new ToolWindow();
54         CreateCursors();
55         setCursor(cur[TOOLSelect]);
56         setMouseTracking(true);
57 }
58
59
60 QSize EditWindow::minimumSizeHint() const
61 {
62         return QSize(50, 50);
63 }
64
65
66 QSize EditWindow::sizeHint() const
67 {
68         return QSize(400, 400);
69 }
70
71
72 void EditWindow::CreateCursors(void)
73 {
74         int hotx[10] = {  1,  1, 11, 15,  1,  1,  1,  1,  1,  1 };
75         int hoty[10] = {  1,  1, 11, 13,  1,  1,  1,  1,  1,  1 };
76         char cursorName[10][48] = { "select", "select-poly", "scroll", "zoom", "add-point",
77                 "add-poly", "del-point", "del-poly", "rotate", "rotate" };
78
79         for(int i=0; i<10; i++)
80         {
81                 QString s;
82                 s.sprintf(":/res/cursor-%s.png", cursorName[i]);
83                 QPixmap pmTmp(s);
84                 cur[i] = QCursor(pmTmp, hotx[i], hoty[i]);
85         }
86 }
87
88
89 QPoint EditWindow::GetAdjustedMousePosition(QMouseEvent * event)
90 {
91         QSize winSize = size();
92         // This is undoing the transform, e.g. going from client coords to local coords.
93         // In essence, the height - y is height + (y * -1), the (y * -1) term doing the
94         // conversion of the y-axis from increasing bottom to top.
95         return QPoint(offsetX + event->x(), offsetY + (winSize.height() - event->y()));
96 }
97
98
99 QPoint EditWindow::GetAdjustedClientPosition(int x, int y)
100 {
101         QSize winSize = size();
102
103         // VOODOO ALERT (ON Y COMPONENT!!!!)
104         return QPoint(-offsetX + x, (winSize.height() - (-offsetY + y)) * +1.0);
105 }
106
107
108 /*
109 TODO:
110  o  Different colors for polys on selected points
111  o  Different colors for handles on non-selected polys
112  o  Line of sight (dashed, dotted) for off-curve points
113  o  Repaints for press/release of CTRL/SHIFT during point creation
114 */
115 void EditWindow::paintEvent(QPaintEvent * /*event*/)
116 {
117         QPainter p(this);
118 //hm, causes lockup (or does it???)
119         p.setRenderHint(QPainter::Antialiasing);
120 //Doesn't do crap!
121 //dc.SetBackground(*wxWHITE_BRUSH);
122
123 // Due to the screwiness of wxWidgets coord system, the origin is ALWAYS
124 // the upper left corner--regardless of axis orientation, etc...
125 //      int width, height;
126 //      dc.GetSize(&width, &height);
127         QSize winSize = size();
128
129 //      dc.SetDeviceOrigin(-offsetX, height - (-offsetY));
130 //      dc.SetAxisOrientation(true, true);
131         p.translate(QPoint(-offsetX, winSize.height() - (-offsetY)));
132         p.scale(1.0, -1.0);
133
134 // Scrolling can be done by using OffsetViewportOrgEx
135 // Scaling can be done by adjusting SetWindowExtEx (it's denominator of txform)
136 // you'd use: % = ViewportExt / WindowExt
137 // But it makes the window look like crap: fuggetuboutit.
138 // Instead, we have to scale EVERYTHING by hand. Crap!
139 // It's not *that* bad, but not as convenient either...
140
141 //      dc.SetPen(*(wxThePenList->FindOrCreatePen(wxColour(0x00, 0x00, 0xFF), 1, wxDOT)));
142 ////    dc.DrawLine(0, 0, 10, 10);
143         p.setPen(QPen(Qt::blue, 1.0, Qt::DotLine));
144
145         // Draw coordinate axes
146
147 //      dc.CrossHair(0, 0);
148         p.drawLine(0, -16384, 0, 16384);
149         p.drawLine(-16384, 0, 16384, 0);
150
151         // Draw rotation center (if active)
152
153         if (showRotationCenter)
154         {
155                 p.setPen(QPen(Qt::red, 2.0, Qt::SolidLine));
156                 p.drawLine(rotationCenter.x() + 7, rotationCenter.y(), rotationCenter.x() - 7, rotationCenter.y());
157                 p.drawLine(rotationCenter.x(), rotationCenter.y() + 7, rotationCenter.x(), rotationCenter.y() - 7);
158         }
159
160         // Draw points
161
162         for(int i=0; i<pts.GetNumPoints(); i++)
163         {
164                 if (i == ptHighlight)
165                 {
166                         p.setPen(QPen(Qt::red, 1.0, Qt::SolidLine));
167
168                         if (pts.GetOnCurve(i))
169                         {
170                                 DrawSquareDotN(p, pts.GetX(i), pts.GetY(i), 7);
171                                 DrawSquareDotN(p, pts.GetX(i), pts.GetY(i), 9);
172                         }
173                         else
174                         {
175                                 DrawRoundDotN(p, pts.GetX(i), pts.GetY(i), 7);
176                                 DrawRoundDotN(p, pts.GetX(i), pts.GetY(i), 9);
177                         }
178                 }
179                 else if ((i == ptHighlight || i == ptNextHighlight) && tool == TOOLAddPt)
180                 {
181                         p.setPen(QPen(Qt::green, 1.0, Qt::SolidLine));
182
183                         if (pts.GetOnCurve(i))
184                         {
185                                 DrawSquareDotN(p, pts.GetX(i), pts.GetY(i), 7);
186                                 DrawSquareDotN(p, pts.GetX(i), pts.GetY(i), 9);
187                         }
188                         else
189                         {
190                                 DrawRoundDotN(p, pts.GetX(i), pts.GetY(i), 7);
191                                 DrawRoundDotN(p, pts.GetX(i), pts.GetY(i), 9);
192                         }
193                 }
194                 else
195                 {
196                         p.setPen(QPen(Qt::black, 1.0, Qt::SolidLine));
197
198                         if (pts.GetOnCurve(i))
199                                 DrawSquareDot(p, pts.GetX(i), pts.GetY(i));
200                         else
201                                 DrawRoundDot(p, pts.GetX(i), pts.GetY(i));
202                 }
203
204                 if (tool == TOOLDelPt && i == ptHighlight)
205                 {
206                         p.setPen(QPen(Qt::red, 1.0, Qt::SolidLine));
207                         p.drawLine(pts.GetX(i) - 5, pts.GetY(i) - 5, pts.GetX(i) + 5, pts.GetY(i) + 5);
208                         p.drawLine(pts.GetX(i) + 5, pts.GetY(i) - 5, pts.GetX(i) - 5, pts.GetY(i) + 5);
209                 }
210         }
211
212         // Draw curve formed by points
213
214         p.setPen(QPen(Qt::black, 1.0, Qt::SolidLine));
215         DrawGlyph(p, pts);
216
217         if (haveZeroPoint)
218         {
219                 // Rotation code
220                 GlyphPoints rotated = pts;
221
222                 if (tool == TOOLRotate)
223                         rotated.RotatePoints(rotationAngle, IPoint(rotationCenter.x(), rotationCenter.y()));
224                 else if (tool == TOOLRotatePoly)
225                 {
226                         uint16 poly = rotated.GetPolyForPointNumber(ptHighlight);
227                         rotated.RotatePolyAroundCentroid(poly, rotationAngle);
228                 }
229
230                 p.setPen(QPen(QColor(255, 0, 255), 1.0, Qt::SolidLine));
231                 DrawGlyph(p, rotated);
232         }
233 }
234
235
236 void EditWindow::DrawGlyph(QPainter & p, GlyphPoints & glyph)
237 {
238         for(int poly=0; poly<glyph.GetNumPolys(); poly++)
239         {
240                 if (glyph.GetNumPoints(poly) > 2)
241                 {
242                         // Initial move...
243                         // If it's not on curve, then move to it, otherwise move to last point...
244
245                         int x, y;
246
247                         if (glyph.GetOnCurve(poly, glyph.GetNumPoints(poly) - 1))
248                                 x = (int)glyph.GetX(poly, glyph.GetNumPoints(poly) - 1), y = (int)glyph.GetY(poly, glyph.GetNumPoints(poly) - 1);
249                         else
250                                 x = (int)glyph.GetX(poly, 0), y = (int)glyph.GetY(poly, 0);
251
252                         for(int i=0; i<glyph.GetNumPoints(poly); i++)
253                         {
254                                 if (glyph.GetOnCurve(poly, i))
255                                 {
256                                         p.drawLine(x, y, glyph.GetX(poly, i), glyph.GetY(poly, i));
257                                         x = (int)glyph.GetX(poly, i), y = (int)glyph.GetY(poly, i);
258                                 }
259                                 else
260                                 {
261                                         uint32 prev = glyph.GetPrev(poly, i), next = glyph.GetNext(poly, i);
262                                         float px = glyph.GetX(poly, prev), py = glyph.GetY(poly, prev),
263                                                 nx = glyph.GetX(poly, next), ny = glyph.GetY(poly, next);
264
265                                         if (!glyph.GetOnCurve(poly, prev))
266                                                 px = (px + glyph.GetX(poly, i)) / 2.0f,
267                                                 py = (py + glyph.GetY(poly, i)) / 2.0f;
268
269                                         if (!glyph.GetOnCurve(poly, next))
270                                                 nx = (nx + glyph.GetX(poly, i)) / 2.0f,
271                                                 ny = (ny + glyph.GetY(poly, i)) / 2.0f;
272
273                                         Bezier(p, point(px, py), point(glyph.GetX(poly, i), glyph.GetY(poly, i)), point(nx, ny));
274                                         x = (int)nx, y = (int)ny;
275
276                                         if (glyph.GetOnCurve(poly, next))
277                                                 i++;                                    // Following point is on curve, so move past it
278                                 }
279                         }
280                 }
281         }
282 }
283
284
285 void EditWindow::mousePressEvent(QMouseEvent * event)
286 {
287         if (event->button() == Qt::RightButton)
288         {
289                 toolPalette->move(event->globalPos());
290                 toolPalette->setVisible(true);
291                 setCursor(cur[TOOLSelect]);
292                 toolPalette->prevTool = TOOLSelect;
293         }
294         else if (event->button() == Qt::MidButton)
295         {
296                 setCursor(cur[2]);                                                      // Scrolling cursor
297         }
298         else if (event->button() == Qt::LeftButton)
299         {
300                 if (tool == TOOLScroll || tool == TOOLZoom)
301 ;//meh                  CaptureMouse();                                         // Make sure we capture the mouse when in scroll/zoom mode
302                 else if (tool == TOOLAddPt)             // "Add Point" tool
303                 {
304                         if (pts.GetNumPoints() > 0)
305                         {
306                                 QPoint pt = GetAdjustedMousePosition(event);
307                                 pts.InsertPoint(pts.GetNext(ptHighlight), pt.x(), pt.y(), ((event->modifiers() == Qt::ShiftModifier || event->modifiers() == Qt::ControlModifier) ? false : true));
308                                 ptHighlight = ptNextHighlight;
309                                 update();
310                         }
311                 }
312                 else if (tool == TOOLAddPoly)   // "Add Poly" tool
313                 {
314 #ifdef DEBUGFOO
315 WriteLogMsg("Adding point... # polys: %u, # points: %u", pts.GetNumPolys(), pts.GetNumPoints());
316 #endif
317                         if (polyFirstPoint)
318                         {
319                                 polyFirstPoint = false;
320                                 pts.AddNewPolyAtEnd();
321                         }
322
323                         QPoint pt = GetAdjustedMousePosition(event);
324 //printf("GetAdjustedMousePosition = %i, %i\n", pt.x(), pt.y());
325                         // Append a point to the end of the structure
326                         pts += IPoint(pt.x(), pt.y(), ((event->modifiers() == Qt::ShiftModifier || event->modifiers() == Qt::ControlModifier) ? false : true));
327                         ptHighlight = pts.GetNumPoints() - 1;
328                         update();
329 #ifdef DEBUGFOO
330 WriteLogMsg(" --> [# polys: %u, # points: %u]\n", pts.GetNumPolys(), pts.GetNumPoints());
331 #endif
332                 }
333                 else if (tool == TOOLSelect || tool == TOOLPolySelect)
334                 {
335                         if (pts.GetNumPoints() > 0)
336                         {
337                                 pt = GetAdjustedClientPosition(pts.GetX(ptHighlight), pts.GetY(ptHighlight));
338 //printf("GetAdjustedClientPosition = %i, %i\n", pt.x(), pt.y());
339 //                              WarpPointer(pt.x, pt.y);
340                                 QCursor::setPos(mapToGlobal(pt));
341
342                                 if (event->modifiers() == Qt::ShiftModifier || event->modifiers() == Qt::ControlModifier)
343                                 {
344                                         pts.SetOnCurve(ptHighlight, !pts.GetOnCurve(ptHighlight));
345                                         update();
346                                 }
347                         }
348                 }
349                 else if (tool == TOOLDelPt)
350                 {
351                         if (pts.GetNumPoints() > 0)
352 //Or could use:
353 //                      if (ptHighlight != -1)
354                         {
355 //This assumes that WM_MOUSEMOVE happens before this!
356 //The above commented out line should take care of this contingency... !!! FIX !!!
357                                 pts.DeletePoint(ptHighlight);
358                                 update();
359                         }
360                 }
361                 else if (tool == TOOLRotate)
362                 {
363                         // I think what's needed here is to keep the initial mouse click,
364                         // paint the rotation center, then use the 1st mouse move event to establish
365                         // the rotation "zero line", which becomes the line of reference to all
366                         // subsequent mouse moves.
367                         rotationCenter = GetAdjustedMousePosition(event);
368                         showRotationCenter = true;
369                         haveZeroPoint = false;
370                         rotationAngle = 0;
371                         update();
372                 }
373                 else if (tool == TOOLRotatePoly)
374                 {
375                         IPoint centroid = pts.GetPolyCentroid(pts.GetPolyForPointNumber(ptHighlight));
376                         rotationCenter = QPoint(centroid.x, centroid.y);
377                         showRotationCenter = true;
378                         pt = GetAdjustedClientPosition(pts.GetX(ptHighlight), pts.GetY(ptHighlight));
379                         QCursor::setPos(mapToGlobal(pt));
380                         rotationZeroPoint = QPoint(pts.GetX(ptHighlight), pts.GetY(ptHighlight));
381                         haveZeroPoint = true;
382                         rotationAngle = 0;
383                         update();
384                 }
385         }
386
387         event->accept();
388 }
389
390
391 void EditWindow::mouseMoveEvent(QMouseEvent * event)
392 {
393         if (event->buttons() == Qt::RightButton)
394         {
395                 ToolType newTool = toolPalette->FindSelectedTool();
396
397                 if (newTool != toolPalette->prevTool)
398                 {
399                         toolPalette->prevTool = newTool;
400                         toolPalette->repaint();
401                 }
402         }
403         else if (event->buttons() == Qt::MidButton)
404         {
405                 // Calc offset from previous point
406                 pt = event->pos();
407                 ptOffset = QPoint(pt.x() - ptPrevious.x(), pt.y() - ptPrevious.y());
408
409 // Then multiply it by the scaling factor. Whee!
410                 // This looks wacky because we're using screen coords for the offset...
411                 // Otherwise, we would subtract both offsets!
412                 offsetX -= ptOffset.x(), offsetY += ptOffset.y();
413                 update();
414                 ptPrevious = pt;
415         }
416         else if (event->buttons() == Qt::LeftButton)
417         {
418                 if (tool == TOOLAddPt || tool == TOOLAddPoly || tool == TOOLSelect)
419                 {
420                         if (tool != TOOLAddPt || pts.GetNumPoints() > 0)//yecch.
421                         {
422 //temporary, for testing. BTW, Select drag bug is here...!
423 #if 1
424                                 QPoint pt2 = GetAdjustedMousePosition(event);
425                                 pts.SetXY(ptHighlight, pt2.x(), pt2.y());
426                                 update();
427 #endif
428                         }
429                 }
430                 else if (tool == TOOLPolySelect)
431                 {
432                         if (pts.GetNumPoints() > 0)
433                         {
434                                 QPoint pt2 = GetAdjustedMousePosition(event);
435                                 // Should also set onCurve here as well, depending on keystate
436 //Or should we?
437                                 pts.OffsetPoly(pts.GetPoly(ptHighlight), pt2.x() - pts.GetX(ptHighlight), pt2.y() - pts.GetY(ptHighlight));
438                                 update();
439                         }
440                 }
441                 else if (tool == TOOLRotate || tool == TOOLRotatePoly)
442                 {
443                         if (pts.GetNumPoints() > 0)
444                         {
445                                 if (!haveZeroPoint)
446                                 {
447                                         rotationZeroPoint = GetAdjustedMousePosition(event);
448                                         haveZeroPoint = true;
449                                 }
450                                 else
451                                 {
452                                         // Figure out the angle between the "zero" vector and the current one,
453                                         // then rotate all points relative to the "zero" vector (done by paint())
454                                         QPoint currentPoint = GetAdjustedMousePosition(event);
455                                         Vector v1(rotationZeroPoint.x(), rotationZeroPoint.y(), 0,
456                                                 rotationCenter.x(), rotationCenter.y(), 0);
457                                         Vector v2(currentPoint.x(), currentPoint.y(), 0,
458                                                 rotationCenter.x(), rotationCenter.y(), 0);
459 //                                      rotationAngle = v1.Angle(v2);
460                                         rotationAngle = v2.Angle(v1);
461
462                                         QString s;
463                                         s.sprintf("%.3f degrees", rotationAngle * 180.0 / 3.14159265358979323);
464                                         ((TTEdit *)qApp)->mainWindow->statusBar()->showMessage(s);
465                                 }
466
467                                 update();
468                         }
469                 }
470         }
471         else if (event->buttons() == Qt::NoButton)
472         {
473                 // Moving, not dragging...
474                 if (tool == TOOLSelect || tool == TOOLDelPt || tool == TOOLAddPt
475                         || tool == TOOLPolySelect || tool == TOOLRotatePoly)
476                 {
477                         QPoint pt2 = GetAdjustedMousePosition(event);
478                         double closest = 1.0e+99;
479
480                         for(int i=0; i<pts.GetNumPoints(); i++)
481                         {
482                                 double dist = ((pt2.x() - pts.GetX(i)) * (pt2.x() - pts.GetX(i)))
483                                         + ((pt2.y() - pts.GetY(i)) * (pt2.y() - pts.GetY(i)));
484
485                                 if (dist < closest)
486                                         closest = dist, ptHighlight = i;
487                         }
488
489                         if (ptHighlight != oldPtHighlight)
490                         {
491                                 oldPtHighlight = ptHighlight;
492                                 update();
493                         }
494
495                         // What follows here looks like voodoo, but is really simple. What we do is
496                         // check to see if the mouse point has a perpendicular intersection with any of
497                         // the line segments. If it does, calculate the length of the perpendicular
498                         // and choose the smallest length. If there is no perpendicular, then choose the
499                         // length of line connecting the closer of either the first endpoint or the
500                         // second and choose the smallest of those.
501
502                         // There is one bit of math that looks like voodoo to me ATM--will explain once
503                         // I understand it better (the calculation of the length of the perpendicular).
504
505                         if (pts.GetNumPoints() > 1 && tool == TOOLAddPt)
506                         {
507                                 double smallest = 1.0e+99;
508
509                                 for(int i=0; i<pts.GetNumPoints(); i++)
510                                 {
511                                         int32 p1x = pts.GetX(i), p1y = pts.GetY(i),
512                                                 p2x = pts.GetX(pts.GetNext(i)), p2y = pts.GetY(pts.GetNext(i));
513
514                                         Vector ls(p2x, p2y, 0, p1x, p1y, 0), v1(pt2.x(), pt2.y(), 0, p1x, p1y, 0),
515                                                 v2(pt2.x(), pt2.y(), 0, p2x, p2y, 0);
516                                         double pp = ls.Dot(v1) / ls.Magnitude(), dist;
517 // Geometric interpretation:
518 // pp is the paremeterized point on the vector ls where the perpendicular intersects ls.
519 // If pp < 0, then the perpendicular lies beyond the 1st endpoint. If pp > length of ls,
520 // then the perpendicular lies beyond the 2nd endpoint.
521
522                                         if (pp < 0.0)
523                                                 dist = v1.Magnitude();
524                                         else if (pp > ls.Magnitude())
525                                                 dist = v2.Magnitude();
526                                         else                                    // distance = ?Det?(ls, v1) / |ls|
527                                                 dist = fabs((ls.x * v1.y - v1.x * ls.y) / ls.Magnitude());
528
529 //The answer to the above looks like it might be found here:
530 //
531 //If the segment endpoints are s and e, and the point is p, then the test for the perpendicular
532 //intercepting the segment is equivalent to insisting that the two dot products {s-e}.{s-p} and
533 //{e-s}.{e-p} are both non-negative.  Perpendicular distance from the point to the segment is
534 //computed by first computing the area of the triangle the three points form, then dividing by the
535 //length of the segment.  Distances are done just by the Pythagorean theorem.  Twice the area of the
536 //triangle formed by three points is the determinant of the following matrix:
537 //
538 //sx sy 1
539 //ex ey 1
540 //px py 1
541 //
542 //By translating the start point to the origin, this can be rewritten as:
543 //By subtracting row 1 from all rows, you get the following:
544 //[because sx = sy = 0. you could leave out the -sx/y terms below. because we subtracted
545 // row 1 from all rows (including row 1) row 1 turns out to be zero. duh!]
546 //
547 //0         0         0
548 //(ex - sx) (ey - sy) 0
549 //(px - sx) (py - sy) 0
550 //
551 //which greatly simplifies the calculation of the determinant.
552
553                                         if (dist < smallest)
554                                                 smallest = dist, ptNextHighlight = pts.GetNext(i), ptHighlight = i;
555                                 }
556
557                                 if (ptNextHighlight != oldPtNextHighlight)
558                                 {
559                                         oldPtNextHighlight = ptNextHighlight;
560                                         update();
561                                 }
562                         }
563                 }
564
565                 ptPrevious = event->pos();
566         }
567
568         event->accept();
569 }
570
571
572 void EditWindow::mouseReleaseEvent(QMouseEvent * event)
573 {
574         if (event->button() == Qt::RightButton)
575         {
576                 ToolType newTool = toolPalette->FindSelectedTool();
577
578                 // We only change the tool if a new one was actually selected. Otherwise, we do nothing.
579                 if (newTool != TOOLNone)
580                 {
581                         tool = newTool;
582
583                         if (tool == TOOLScroll || tool == TOOLZoom || tool == TOOLAddPoly
584                                 || tool == TOOLDelPoly)
585                                 ptHighlight = -1;
586
587                         if (tool == TOOLAddPoly)
588                                 polyFirstPoint = true;
589                 }
590
591                 toolPalette->setVisible(false);
592                 setCursor(cur[tool]);
593                 // Just in case we changed highlighting style with the new tool...
594                 update();
595         }
596         else if (event->button() == Qt::MidButton)
597         {
598                 setCursor(cur[tool]);                                           // Restore previous cursor
599         }
600         else if (event->button() == Qt::LeftButton)
601         {
602                 if (showRotationCenter)
603                 {
604                         showRotationCenter = false;
605                         haveZeroPoint = false;
606
607                         if (tool == TOOLRotate)
608                                 pts.RotatePoints(rotationAngle, IPoint(rotationCenter.x(), rotationCenter.y()));
609                         else
610                         {
611                                 uint16 poly = pts.GetPolyForPointNumber(ptHighlight);
612                                 pts.RotatePolyAroundCentroid(poly, rotationAngle);
613                         }
614
615                         update();
616                         ((TTEdit *)qApp)->mainWindow->statusBar()->showMessage("");
617                 }
618
619 //              if (tool == TOOLScroll || tool == TOOLZoom)
620 //                      ReleaseMouse();
621 //this is prolly too much
622                 ((TTEdit *)qApp)->charWnd->MakePathFromPoints(&pts);
623                 ((TTEdit *)qApp)->charWnd->update();
624
625         }
626
627         event->accept();
628 }