File indexing completed on 2024-05-12 05:46:43
0001 /* 0002 * Copyright (c) 2016 Boudewijn Rempt <boud@valdyas.org> 0003 * 0004 * This program is free software; you can redistribute it and/or modify 0005 * it under the terms of the GNU Lesser General Public License as published by 0006 * the Free Software Foundation; either version 2 of the License, or 0007 * (at your option) any later version. 0008 * 0009 * This program is distributed in the hope that it will be useful, 0010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0012 * GNU General Public License for more details. 0013 * 0014 * You should have received a copy of the GNU Lesser General Public License 0015 * along with this program; if not, write to the Free Software 0016 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 0017 */ 0018 #include "Canvas.h" 0019 #include <KoCanvasBase.h> 0020 #include <kis_canvas2.h> 0021 #include <KisView.h> 0022 #include <KoCanvasController.h> 0023 #include <kis_canvas_controller.h> 0024 #include <kis_zoom_manager.h> 0025 #include <QPointer> 0026 #include <View.h> 0027 0028 struct Canvas::Private { 0029 Private() {} 0030 KisCanvas2 *canvas {0}; 0031 }; 0032 0033 Canvas::Canvas(KoCanvasBase *canvas, QObject *parent) 0034 : QObject(parent) 0035 , d(new Private) 0036 { 0037 d->canvas = static_cast<KisCanvas2*>(canvas); 0038 } 0039 0040 Canvas::~Canvas() 0041 { 0042 delete d; 0043 } 0044 0045 0046 bool Canvas::operator==(const Canvas &other) const 0047 { 0048 return (d->canvas == other.d->canvas); 0049 } 0050 0051 bool Canvas::operator!=(const Canvas &other) const 0052 { 0053 return !(operator==(other)); 0054 } 0055 0056 0057 qreal Canvas::zoomLevel() const 0058 { 0059 if (!d->canvas) return 1.0; 0060 return d->canvas->imageView()->zoomManager()->zoom(); 0061 } 0062 0063 void Canvas::setZoomLevel(qreal value) 0064 { 0065 if (!d->canvas) return; 0066 d->canvas->imageView()->zoomController()->setZoom(KoZoomMode::ZOOM_CONSTANT, value); 0067 } 0068 0069 void Canvas::resetZoom() 0070 { 0071 if (!d->canvas) return; 0072 d->canvas->imageView()->zoomManager()->zoomTo100(); 0073 } 0074 0075 0076 void Canvas::resetRotation() 0077 { 0078 if (!d->canvas) return; 0079 d->canvas->imageView()->canvasController()->resetCanvasRotation(); 0080 } 0081 0082 qreal Canvas::rotation() const 0083 { 0084 if (!d->canvas) return 0; 0085 return d->canvas->imageView()->canvasController()->rotation(); 0086 } 0087 0088 void Canvas::setRotation(qreal angle) 0089 { 0090 if (!d->canvas) return; 0091 d->canvas->imageView()->canvasController()->rotateCanvas(angle - rotation()); 0092 } 0093 0094 0095 bool Canvas::mirror() const 0096 { 0097 if (!d->canvas) return false; 0098 return d->canvas->imageView()->canvasIsMirrored(); 0099 } 0100 0101 void Canvas::setMirror(bool value) 0102 { 0103 if (!d->canvas) return; 0104 d->canvas->imageView()->canvasController()->mirrorCanvas(value); 0105 } 0106 0107 View *Canvas::view() const 0108 { 0109 if (!d->canvas) return 0; 0110 View *view = new View(d->canvas->imageView()); 0111 return view; 0112 } 0113 0114 KisDisplayColorConverter *Canvas::displayColorConverter() const 0115 { 0116 if (!d->canvas) return 0; 0117 return d->canvas->displayColorConverter(); 0118 } 0119 0120 bool Canvas::wrapAroundMode() const 0121 { 0122 if (!d->canvas) return false; 0123 return d->canvas->imageView()->canvasController()->wrapAroundMode(); 0124 } 0125 0126 void Canvas::setWrapAroundMode(bool enable) 0127 { 0128 if (!d->canvas) return; 0129 d->canvas->imageView()->canvasController()->slotToggleWrapAroundMode(enable); 0130 } 0131 0132 bool Canvas::levelOfDetailMode() const 0133 { 0134 if (!d->canvas) return false; 0135 return d->canvas->imageView()->canvasController()->levelOfDetailMode(); 0136 } 0137 0138 void Canvas::setLevelOfDetailMode(bool enable) 0139 { 0140 if (!d->canvas) return; 0141 return d->canvas->imageView()->canvasController()->slotToggleLevelOfDetailMode(enable); 0142 }