1 /************************************************************************
2 **
3 **  Copyright (C) 2019-2020 Kevin B. Hendricks, Stratford Ontario, Canada
4 **  Copyright (C) 2009-2011 Strahinja Markovic  <strahinja.markovic@gmail.com>
5 **
6 **  This file is part of Sigil.
7 **
8 **  Sigil is free software: you can redistribute it and/or modify
9 **  it under the terms of the GNU General Public License as published by
10 **  the Free Software Foundation, either version 3 of the License, or
11 **  (at your option) any later version.
12 **
13 **  Sigil is distributed in the hope that it will be useful,
14 **  but WITHOUT ANY WARRANTY; without even the implied warranty of
15 **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 **  GNU General Public License for more details.
17 **
18 **  You should have received a copy of the GNU General Public License
19 **  along with Sigil.  If not, see <http://www.gnu.org/licenses/>.
20 **
21 *************************************************************************/
22 
23 #pragma once
24 #ifndef IMAGETAB_H
25 #define IMAGETAB_H
26 
27 #include <QtCore/QUrl>
28 #include <QPointer>
29 
30 #include "Tabs/ContentTab.h"
31 
32 class ImageResource;
33 class QWebEngineView;
34 class QAction;
35 class QMenu;
36 
37 class ImageTab : public ContentTab
38 {
39     Q_OBJECT
40 
41 public:
42 
43     ImageTab(ImageResource *resource, QWidget *parent = 0);
44     ~ImageTab();
45 
46     // Overrides inherited from ContentTab
47     float GetZoomFactor() const;
48 
49     void SetZoomFactor(float new_zoom_factor);
50 
51     void UpdateDisplay();
52 
53 public slots:
54     void RefreshContent();
55 
56     void openWith();
57     void openWithEditor(int);
58 
59     void saveAs();
60     void copyImage();
61 
62     void Print();
63     void PrintPreview();
64 
65 private slots:
66 
67     /**
68      * Opens the context menu at the requested point.
69      *
70      * @param point The point at which the menu should be opened.
71      */
72     void OpenContextMenu(const QPoint &point);
73 
74 private:
75 
76     /**
77      * Creates all the context menu actions.
78      */
79     void CreateContextMenuActions();
80 
81     /**
82      * Tries to setup the context menu for the specified point,
83      * and returns true on success.
84      *
85      * @param point The point at which the menu should be opened.
86      * @return \c true if the menu could be set up.
87      */
88     bool SuccessfullySetupContextMenu(const QPoint &point);
89 
90     void ConnectSignalsToSlots();
91 
92     void Zoom();
93 
94     ///////////////////////////////
95     // PRIVATE MEMBER VARIABLES
96     ///////////////////////////////
97 
98     QWebEngineView *m_WebView;
99 
100     QPointer<QMenu> m_ContextMenu;
101     QMenu *m_OpenWithContextMenu;
102 
103     QAction *m_OpenWith;
104     QAction *m_OpenWithEditor0;
105     QAction *m_OpenWithEditor1;
106     QAction *m_OpenWithEditor2;
107     QAction *m_OpenWithEditor3;
108     QAction *m_OpenWithEditor4;
109     QSignalMapper *m_openWithMapper;
110 
111     QAction *m_SaveAs;
112     QAction *m_CopyImage;
113 
114     float m_CurrentZoomFactor;
115 };
116 
117 #endif // IMAGETAB_H
118