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 "ScaleWidget.h"
21
22 namespace kImageAnnotator {
23
ScaleWidget()24 kImageAnnotator::ScaleWidget::ScaleWidget() :
25 mAnnotationArea(nullptr),
26 mView(new QGraphicsView),
27 mMainLayout(new QVBoxLayout(this))
28 {
29 initGui();
30 }
31
~ScaleWidget()32 ScaleWidget::~ScaleWidget()
33 {
34 delete mView;
35 }
36
activate(AnnotationArea * annotationArea)37 void ScaleWidget::activate(AnnotationArea *annotationArea)
38 {
39 Q_ASSERT(annotationArea != nullptr);
40
41 mAnnotationArea = annotationArea;
42 mView->setScene(annotationArea);
43 showDialog();
44 }
45
initGui()46 void ScaleWidget::initGui()
47 {
48 mMainLayout->addWidget(mView);
49 setLayout(mMainLayout);
50 }
51
showDialog()52 void ScaleWidget::showDialog()
53 {
54 auto sceneSize = mAnnotationArea->sceneRect().size();
55 ScaleDialog scaleDialog(sceneSize.toSize(), this);
56 connect(&scaleDialog, &ScaleDialog::finished, this, &ScaleWidget::scale);
57 scaleDialog.exec();
58
59 emit closing();
60 }
61
scale(const QSize & newSize)62 void ScaleWidget::scale(const QSize &newSize)
63 {
64 mAnnotationArea->scale(newSize);
65 }
66
67 } // namespace kImageAnnotator
68