1 /*
2 * Copyright (C) 2018 Damir Porobic <damir.porobic@gmx.com>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19
20 #include "AbstractRectResizeHandles.h"
21
22 namespace kImageAnnotator {
23
update()24 void AbstractRectResizeHandles::update()
25 {
26 auto rect = getRect();
27 auto offset = getOffset();
28 mHandles[0].moveCenter(ShapeHelper::rectTopLeftWithOffset(rect, offset));
29 mHandles[0].setAnchor(rect.topLeft());
30 mHandles[1].moveCenter(ShapeHelper::rectTopWithOffset(rect, offset));
31 mHandles[1].setAnchor(ShapeHelper::rectTop(rect));
32 mHandles[2].moveCenter(ShapeHelper::rectTopRightWithOffset(rect, offset));
33 mHandles[2].setAnchor(rect.topRight());
34 mHandles[3].moveCenter(ShapeHelper::rectRightWithOffset(rect, offset));
35 mHandles[3].setAnchor(ShapeHelper::rectRight(rect));
36 mHandles[4].moveCenter(ShapeHelper::rectBottomRightWithOffset(rect, offset));
37 mHandles[4].setAnchor(rect.bottomRight());
38 mHandles[5].moveCenter(ShapeHelper::rectBottomWithOffset(rect, offset));
39 mHandles[5].setAnchor(ShapeHelper::rectBottom(rect));
40 mHandles[6].moveCenter(ShapeHelper::rectBottomLeftWithOffset(rect, offset));
41 mHandles[6].setAnchor(rect.bottomLeft());
42 mHandles[7].moveCenter(ShapeHelper::rectLeftWithOffset(rect, offset));
43 mHandles[7].setAnchor(ShapeHelper::rectLeft(rect));
44
45 updateRectCursors();
46 }
47
initCursors()48 void AbstractRectResizeHandles::initCursors()
49 {
50 mCursors.clear();
51 mCursors.append(CursorHelper::fDiagResizeCursor());
52 mCursors.append(CursorHelper::verticalResizeCursor());
53 mCursors.append(CursorHelper::bDiagResizeCursor());
54 mCursors.append(CursorHelper::horizontalResizeCursor());
55 mCursors.append(CursorHelper::fDiagResizeCursor());
56 mCursors.append(CursorHelper::verticalResizeCursor());
57 mCursors.append(CursorHelper::bDiagResizeCursor());
58 mCursors.append(CursorHelper::horizontalResizeCursor());
59 }
60
updateRectCursors()61 void AbstractRectResizeHandles::updateRectCursors()
62 {
63 if (mCursors.isEmpty()) {
64 return;
65 }
66
67 auto rect = getItemBoundingRect();
68 mCursors[indexOfHandleWithAnchorAt(rect.topLeft())] = CursorHelper::fDiagResizeCursor();
69 mCursors[indexOfHandleWithAnchorAt(rect.topRight())] = CursorHelper::bDiagResizeCursor();
70 mCursors[indexOfHandleWithAnchorAt(rect.bottomRight())] = CursorHelper::fDiagResizeCursor();
71 mCursors[indexOfHandleWithAnchorAt(rect.bottomLeft())] = CursorHelper::bDiagResizeCursor();
72 }
73
74 } // namespace kImageAnnotator
75