Changeset View
Changeset View
Standalone View
Standalone View
filters/karbon/image/ImageExportOptionsWidget.cpp
1 | /* This file is part of the KDE project | 1 | /* This file is part of the KDE project | ||
---|---|---|---|---|---|
2 | * Copyright (C) 2008 Jan Hambrecht <jaham@gmx.net> | 2 | * Copyright (C) 2008 Jan Hambrecht <jaham@gmx.net> | ||
3 | * Copyright (C) 2019 Dag Andersen <danders@get2net.dk> | ||||
3 | * | 4 | * | ||
4 | * This library is free software; you can redistribute it and/or | 5 | * This library is free software; you can redistribute it and/or | ||
5 | * modify it under the terms of the GNU Library General Public | 6 | * modify it under the terms of the GNU Library General Public | ||
6 | * License as published by the Free Software Foundation; either | 7 | * License as published by the Free Software Foundation; either | ||
7 | * version 2 of the License, or (at your option) any later version. | 8 | * version 2 of the License, or (at your option) any later version. | ||
8 | * | 9 | * | ||
9 | * This library is distributed in the hope that it will be useful, | 10 | * This library is distributed in the hope that it will be useful, | ||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
12 | * Library General Public License for more details. | 13 | * Library General Public License for more details. | ||
13 | * | 14 | * | ||
14 | * You should have received a copy of the GNU Library General Public License | 15 | * You should have received a copy of the GNU Library General Public License | ||
15 | * along with this library; see the file COPYING.LIB. If not, write to | 16 | * along with this library; see the file COPYING.LIB. If not, write to | ||
16 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 17 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
17 | * Boston, MA 02110-1301, USA. | 18 | * Boston, MA 02110-1301, USA. | ||
18 | */ | 19 | */ | ||
19 | 20 | | |||
20 | #include "ImageExportOptionsWidget.h" | 21 | #include "ImageExportOptionsWidget.h" | ||
21 | 22 | | |||
23 | #include <KarbonDocument.h> | ||||
24 | #include <KoPAPageBase.h> | ||||
25 | | ||||
22 | #include <KoUnit.h> // for POINT_TO_INCH | 26 | #include <KoUnit.h> // for POINT_TO_INCH | ||
23 | #include <KoDpi.h> | 27 | #include <KoDpi.h> | ||
28 | #include <KoShapePainter.h> | ||||
29 | #include <KoZoomHandler.h> | ||||
24 | 30 | | |||
25 | ImageExportOptionsWidget::ImageExportOptionsWidget(const QSizeF &pointSize, QWidget * parent) | 31 | ImageExportOptionsWidget::ImageExportOptionsWidget(KarbonDocument *doc, QWidget * parent) | ||
26 | : QWidget(parent), m_pointSize(pointSize) | 32 | : QWidget(parent), m_doc(doc) | ||
27 | { | 33 | { | ||
28 | KoUnit unit; | 34 | KoUnit unit; | ||
29 | 35 | | |||
30 | widget.setupUi(this); | 36 | widget.setupUi(this); | ||
31 | 37 | | |||
32 | widget.pxWidth->setRange(1, 10000); | 38 | widget.pxWidth->setRange(1, 10000); | ||
33 | widget.pxWidth->setAlignment(Qt::AlignRight); | 39 | widget.pxWidth->setAlignment(Qt::AlignRight); | ||
34 | widget.pxWidth->setSuffix(" px"); | 40 | widget.pxWidth->setSuffix(" px"); | ||
Show All 9 Lines | |||||
44 | widget.pxAspect->setKeepAspectRatio(true); | 50 | widget.pxAspect->setKeepAspectRatio(true); | ||
45 | widget.unitAspect->setKeepAspectRatio(true); | 51 | widget.unitAspect->setKeepAspectRatio(true); | ||
46 | widget.unit->addItems(KoUnit::listOfUnitNameForUi(KoUnit::HidePixel)); | 52 | widget.unit->addItems(KoUnit::listOfUnitNameForUi(KoUnit::HidePixel)); | ||
47 | widget.unit->setCurrentIndex(unit.indexInListForUi(KoUnit::HidePixel)); | 53 | widget.unit->setCurrentIndex(unit.indexInListForUi(KoUnit::HidePixel)); | ||
48 | widget.backColor->setColor(Qt::white); | 54 | widget.backColor->setColor(Qt::white); | ||
49 | widget.opacity->setMinimum(0.0); | 55 | widget.opacity->setMinimum(0.0); | ||
50 | widget.opacity->setMaximum(100.0); | 56 | widget.opacity->setMaximum(100.0); | ||
51 | widget.opacity->setValue(0.0); | 57 | widget.opacity->setValue(0.0); | ||
52 | widget.unitWidth->changeValue(pointSize.width()); | 58 | | ||
53 | widget.unitHeight->changeValue(pointSize.height()); | 59 | for (int i = 0; i < doc->pageCount(); ++i) { | ||
54 | updateFromPointSize(pointSize); | 60 | widget.pageCombo->addItem(i18n("Page %1", i+1)); | ||
61 | } | ||||
62 | setPage(0); | ||||
63 | | ||||
64 | widget.unitWidth->changeValue(m_pointSize.width()); | ||||
65 | widget.unitHeight->changeValue(m_pointSize.height()); | ||||
55 | 66 | | |||
56 | connect(widget.unitWidth, SIGNAL(valueChangedPt(qreal)), this, SLOT(unitWidthChanged(qreal))); | 67 | connect(widget.unitWidth, SIGNAL(valueChangedPt(qreal)), this, SLOT(unitWidthChanged(qreal))); | ||
57 | connect(widget.unitHeight, SIGNAL(valueChangedPt(qreal)), this, SLOT(unitHeightChanged(qreal))); | 68 | connect(widget.unitHeight, SIGNAL(valueChangedPt(qreal)), this, SLOT(unitHeightChanged(qreal))); | ||
58 | connect(widget.pxWidth, SIGNAL(valueChanged(int)), this, SLOT(pxWidthChanged(int))); | 69 | connect(widget.pxWidth, SIGNAL(valueChanged(int)), this, SLOT(pxWidthChanged(int))); | ||
59 | connect(widget.pxHeight, SIGNAL(valueChanged(int)), this, SLOT(pxHeightChanged(int))); | 70 | connect(widget.pxHeight, SIGNAL(valueChanged(int)), this, SLOT(pxHeightChanged(int))); | ||
60 | connect(widget.dpi, SIGNAL(valueChanged(int)), this, SLOT(dpiChanged(int))); | 71 | connect(widget.dpi, SIGNAL(valueChanged(int)), this, SLOT(dpiChanged(int))); | ||
61 | connect(widget.unit, SIGNAL(activated(int)), this, SLOT(unitChanged(int))); | 72 | connect(widget.unit, SIGNAL(activated(int)), this, SLOT(unitChanged(int))); | ||
62 | connect(widget.pxAspect, SIGNAL(keepAspectRatioChanged(bool)), this, SLOT(aspectChanged(bool))); | 73 | connect(widget.pxAspect, SIGNAL(keepAspectRatioChanged(bool)), this, SLOT(aspectChanged(bool))); | ||
63 | connect(widget.unitAspect, SIGNAL(keepAspectRatioChanged(bool)), this, SLOT(aspectChanged(bool))); | 74 | connect(widget.unitAspect, SIGNAL(keepAspectRatioChanged(bool)), this, SLOT(aspectChanged(bool))); | ||
75 | connect(widget.pageCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(setPage(int))); | ||||
76 | } | ||||
77 | | ||||
78 | void ImageExportOptionsWidget::setPage(int idx) | ||||
79 | { | ||||
80 | KoPAPageBase *page = m_doc->pages().value(idx); | ||||
81 | if (!page) { | ||||
82 | page = m_doc->pages().first(); | ||||
83 | } | ||||
84 | KoShapePainter painter; | ||||
85 | painter.setShapes(page->shapes()); | ||||
86 | // get the bounding rect of the content | ||||
87 | QRectF shapesRect = painter.contentRect(); | ||||
88 | // get the size in point | ||||
89 | m_pointSize = shapesRect.size(); | ||||
90 | updateFromPointSize(m_pointSize); | ||||
91 | } | ||||
92 | | ||||
93 | KoPAPageBase *ImageExportOptionsWidget::page() const | ||||
94 | { | ||||
95 | return m_doc->pages().value(widget.pageCombo->currentIndex()); | ||||
64 | } | 96 | } | ||
65 | 97 | | |||
66 | void ImageExportOptionsWidget::setUnit(const KoUnit &unit) | 98 | void ImageExportOptionsWidget::setUnit(const KoUnit &unit) | ||
67 | { | 99 | { | ||
68 | widget.unitWidth->setUnit(unit); | 100 | widget.unitWidth->setUnit(unit); | ||
69 | widget.unitHeight->setUnit(unit); | 101 | widget.unitHeight->setUnit(unit); | ||
70 | widget.unit->setCurrentIndex(unit.indexInListForUi(KoUnit::HidePixel)); | 102 | widget.unit->setCurrentIndex(unit.indexInListForUi(KoUnit::HidePixel)); | ||
71 | } | 103 | } | ||
▲ Show 20 Lines • Show All 151 Lines • Show Last 20 Lines |