Krita Source Code Documentation
Loading...
Searching...
No Matches
kis_image_manager.cc
Go to the documentation of this file.
1/* This file is part of the KDE project
2 * SPDX-FileCopyrightText: 2006 Boudewijn Rempt <boud@valdyas.org>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
7#include "kis_image_manager.h"
8
9#include <QString>
10#include <QStandardPaths>
11
12#include <QAction>
13#include <QUrl>
14#include <QColorDialog>
15
16#include <klocalizedstring.h>
17
18#include <KoColor.h>
19#include <KoFileDialog.h>
20
21#include <kis_types.h>
22#include <kis_image.h>
23#include <kis_icon.h>
25#include "kis_import_catcher.h"
26#include "KisViewManager.h"
27#include "KisDocument.h"
30#include "kis_action.h"
31#include "kis_action_manager.h"
32#include "kis_layer_utils.h"
33#include "kis_canvas2.h"
34
36
37
39 : m_view(view)
40{
41}
42
44{
45 Q_UNUSED(imageView);
46}
47
49{
50
51 KisAction *action = actionManager->createAction("import_layer_from_file");
52 connect(action, SIGNAL(triggered()), this, SLOT(slotImportLayerFromFile()));
53
54 action = actionManager->createAction("image_properties");
55 connect(action, SIGNAL(triggered()), this, SLOT(slotImageProperties()));
56
57 action = actionManager->createAction("import_layer_as_paint_layer");
58 connect(action, SIGNAL(triggered()), this, SLOT(slotImportLayerFromFile()));
59
60 action = actionManager->createAction("import_layer_as_transparency_mask");
61 connect(action, SIGNAL(triggered()), this, SLOT(slotImportLayerAsTransparencyMask()));
62
63 action = actionManager->createAction("import_layer_as_filter_mask");
64 connect(action, SIGNAL(triggered()), this, SLOT(slotImportLayerAsFilterMask()));
65
66 action = actionManager->createAction("import_layer_as_selection_mask");
67 connect(action, SIGNAL(triggered()), this, SLOT(slotImportLayerAsSelectionMask()));
68
69 action = actionManager->createAction("image_color");
70 connect(action, SIGNAL(triggered()), this, SLOT(slotImageColor()));
71}
72
74{
75 importImage(QUrl(), "KisPaintLayer");
76}
77
79{
80 importImage(QUrl(), "KisTransparencyMask");
81}
82
84{
85 importImage(QUrl(), "KisFilterMask");
86}
87
89{
90 importImage(QUrl(), "KisSelectionMask");
91}
92
93
94qint32 KisImageManager::importImage(const QUrl &urlArg, const QString &layerType)
95{
96 KisImageWSP currentImage = m_view->image();
97
98 if (!currentImage) {
99 return 0;
100 }
101
102 QList<QString> paths;
103 qint32 rc = 0;
104
105 if (urlArg.isEmpty()) {
107 dialog.setCaption(i18n("Import Image"));
108 dialog.setDefaultDir(QStandardPaths::writableLocation(QStandardPaths::PicturesLocation));
110 QStringList fileNames = dialog.filenames();
111 Q_FOREACH (const QString &fileName, fileNames) {
112 paths << fileName;
113 }
114
115 } else {
116 paths.push_back(urlArg.toLocalFile());
117 }
118
119 if (paths.empty()) {
120 return 0;
121 }
122
123 Q_FOREACH(const QString &path, paths) {
124 if (path.endsWith("svg")) {
125 rc += (new KisImportCatcher(path, m_view, "KisShapeLayer"))->numLayersImported();
126 }
127 else {
128 rc += (new KisImportCatcher(path, m_view, layerType))->numLayersImported();
129 }
130 }
131
132 m_view->canvas()->update();
133
134 return rc;
135}
136
137void KisImageManager::resizeCurrentImage(qint32 w, qint32 h, qint32 xOffset, qint32 yOffset)
138{
139 if (!m_view->image()) return;
140
141 m_view->image()->resizeImage(QRect(-xOffset, -yOffset, w, h));
142}
143
144void KisImageManager::scaleCurrentImage(const QSize &size, qreal xres, qreal yres, KisFilterStrategy *filterStrategy)
145{
146 if (!m_view->image()) return;
147 m_view->image()->scaleImage(size, xres, yres, filterStrategy);
148}
149
151{
152 if (!m_view->image()) return;
153 m_view->image()->rotateImage(radians);
154}
155
156void KisImageManager::shearCurrentImage(double angleX, double angleY)
157{
158 if (!m_view->image()) return;
159 m_view->image()->shear(angleX, angleY);
160}
161
162
164{
165 KisImageWSP image = m_view->image();
166 if (!image) return;
167
169 if (dlg->exec() == QDialog::Accepted) {
170 if (dlg->convertLayerPixels()) {
171 image->convertImageColorSpace(dlg->colorSpace(),
174
175 } else {
176 image->convertImageProjectionColorSpace(dlg->colorSpace());
177 }
178 }
179 delete dlg;
180}
181
182void updateImageBackgroundColor(KisImageSP image, const QColorDialog *dlg)
183{
184 QColor newColor = dlg->currentColor();
185 KoColor bg = image->defaultProjectionColor();
186 bg.fromQColor(newColor);
187
189}
190
192{
193 KisImageWSP image = m_view->image();
194 if (!image) return;
195
196 QColorDialog dlg;
197 dlg.setOption(QColorDialog::ShowAlphaChannel, true);
198 dlg.setWindowTitle(i18n("Select a Color"));
199 KoColor oldBgColor = image->defaultProjectionColor();
200 dlg.setCurrentColor(oldBgColor.toQColor());
201
203
204 std::function<void ()> updateCall(std::bind(updateImageBackgroundColor, image, &dlg));
205 SignalToFunctionProxy proxy(updateCall);
206
207 connect(&dlg, SIGNAL(currentColorChanged(QColor)), &compressor, SLOT(start()));
208 connect(&compressor, SIGNAL(timeout()), &proxy, SLOT(start()));
209
210 if (dlg.exec() == QDialog::Accepted) {
211 if (compressor.isActive()) {
212 compressor.stop();
213 updateCall();
214 }
215 } else {
217 }
218}
219
220
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
A KisActionManager class keeps track of KisActions. These actions are always associated with the GUI....
KisAction * createAction(const QString &name)
KisDisplayColorConverter displayColorConverter
qint32 importImage(const QUrl &url, const QString &layerType="KisPaintLayer")
void scaleCurrentImage(const QSize &size, qreal xres, qreal yres, KisFilterStrategy *filterStrategy)
void setView(QPointer< KisView >imageView)
KisImageManager(KisViewManager *view)
void slotImportLayerAsSelectionMask()
void slotImportLayerAsFilterMask()
void rotateCurrentImage(double radians)
void slotImportLayerAsTransparencyMask()
void setup(KisActionManager *actionManager)
KisViewManager * m_view
void resizeCurrentImage(qint32 w, qint32 h, qint32 xOffset, qint32 yOffset)
void shearCurrentImage(double angleX, double angleY)
void resizeImage(const QRect &newRect)
start asynchronous operation on resizing the image
Definition kis_image.cc:865
void shear(double angleX, double angleY)
start asynchronous operation on shearing the image
void convertImageColorSpace(const KoColorSpace *dstColorSpace, KoColorConversionTransformation::Intent renderingIntent, KoColorConversionTransformation::ConversionFlags conversionFlags)
void rotateImage(double radians)
start asynchronous operation on rotating the image
void scaleImage(const QSize &size, qreal xres, qreal yres, KisFilterStrategy *filterStrategy)
start asynchronous operation on scaling the image
Definition kis_image.cc:961
KoColor defaultProjectionColor() const
void convertImageProjectionColorSpace(const KoColorSpace *dstColorSpace)
static QStringList supportedMimeTypes(Direction direction)
KisCanvas2 * canvasBase() const
Return the canvas base class.
QWidget * canvas() const
Return the actual widget that is displaying the current image.
QWidget * mainWindowAsQWidget() const
KisImageWSP image() const
Return the image this view is displaying.
void fromQColor(const QColor &c)
Convenient function for converting from a QColor.
Definition KoColor.cpp:213
void toQColor(QColor *c) const
a convenience method for the above.
Definition KoColor.cpp:198
void updateImageBackgroundColor(KisImageSP image, const QColorDialog *dlg)
typedef void(QOPENGLF_APIENTRYP PFNGLINVALIDATEBUFFERDATAPROC)(GLuint buffer)
void changeImageDefaultProjectionColor(KisImageSP image, const KoColor &color)