Debian Codegraph @

src/Gui/ImageView.h

raw
1 // SPDX-License-Identifier: LGPL-2.1-or-later
2
3 /***************************************************************************
4 * Copyright (c) 2023 Werner Mayer <wmayer[at]users.sourceforge.net> *
5 * *
6 * This file is part of FreeCAD. *
7 * *
8 * FreeCAD is free software: you can redistribute it and/or modify it *
9 * under the terms of the GNU Lesser General Public License as *
10 * published by the Free Software Foundation, either version 2.1 of the *
11 * License, or (at your option) any later version. *
12 * *
13 * FreeCAD is distributed in the hope that it will be useful, but *
14 * WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
16 * Lesser General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU Lesser General Public *
19 * License along with FreeCAD. If not, see *
20 * <https://www.gnu.org/licenses/>. *
21 * *
22 **************************************************************************/
23
24 #ifndef GUI_IMAGE_VIEW_H
25 #define GUI_IMAGE_VIEW_H
26
27 #include <Gui/MDIView.h>
28
29 class QFileInfo;
30 class QLabel;
31 class QScrollArea;
32 class QScrollBar;
33 class QUrl;
34
35 namespace Gui
36 {
37
38 class GuiExport ImageView: public MDIView
39 {
40 Q_OBJECT
41
42 public:
43 explicit ImageView(QWidget* parent);
44 bool loadFile(const QString&);
45
46 const char* getName() const override
47 {
48 return "ImageView";
49 }
50
51 /// Message handler
52 bool onMsg(const char* pMsg, const char** ppReturn) override;
53 /// Message handler test
54 bool onHasMsg(const char* pMsg) const override;
55
56 /** @name Printing */
57 //@{
58 using MDIView::print;
59 void print(QPrinter* printer) override;
60 //@}
61
62 protected:
63 void contextMenuEvent(QContextMenuEvent* event) override;
64 void mousePressEvent(QMouseEvent* event) override;
65 void mouseReleaseEvent(QMouseEvent* event) override;
66 void mouseMoveEvent(QMouseEvent* event) override;
67 void dropEvent(QDropEvent* event) override;
68 void dragEnterEvent(QDragEnterEvent* event) override;
69
70 private:
71 void setImage(const QImage& image);
72 void scaleImage(double factor);
73 static void adjustScrollBar(QScrollBar* scrollBar, double factor);
74 bool canZoomIn() const;
75 bool canZoomOut() const;
76 void zoomIn();
77 void zoomOut();
78 void normalSize();
79 void fitToWindow(bool fitView);
80 bool isFitToWindow() const;
81 bool canDrag() const;
82 void startDrag();
83 void stopDrag();
84 bool isDragging() const;
85 void pasteImage();
86 bool canPasteImage() const;
87 static QImage imageFromClipboard();
88 static bool isImageFormat(const QFileInfo&);
89 void loadImageFromUrl(const QList<QUrl>&);
90
91 private:
92 QImage rawImage;
93 QLabel* imageLabel;
94 QScrollArea* scrollArea;
95 double scaleFactor;
96 bool dragging;
97 QPoint dragPos;
98 };
99
100 } // namespace Gui
101
102 #endif // GUI_IMAGE_VIEW_H