1 /*******************************************************************************************************
2  DkNoMacs.h
3  Created on:	21.04.2011
4 
5  nomacs is a fast and small image viewer with the capability of synchronizing multiple instances
6 
7  Copyright (C) 2011-2013 Markus Diem <markus@nomacs.org>
8  Copyright (C) 2011-2013 Stefan Fiel <stefan@nomacs.org>
9  Copyright (C) 2011-2013 Florian Kleber <florian@nomacs.org>
10 
11  This file is part of nomacs.
12 
13  This file is part of nomacs.
14 
15  nomacs is free software: you can redistribute it and/or modify
16  it under the terms of the GNU General Public License as published by
17  the Free Software Foundation, either version 3 of the License, or
18  (at your option) any later version.
19 
20  nomacs is distributed in the hope that it will be useful,
21  but WITHOUT ANY WARRANTY; without even the implied warranty of
22  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23  GNU General Public License for more details.
24 
25  You should have received a copy of the GNU General Public License
26  along with this program.  If not, see <http://www.gnu.org/licenses/>.
27 
28  *******************************************************************************************************/
29 
30 #pragma once
31 
32 // Qt
33 #pragma warning(push, 0)	// no warnings from includes - begin
34 #include <QMainWindow>
35 #include <QProcess>
36 #pragma warning(pop)		// no warnings from includes - end
37 
38 #include "DkImageContainer.h"
39 
40 #ifdef Q_OS_WIN
41 	#pragma warning(disable: 4996)
42 	#pragma warning(disable: 4251)	// TODO: remove
43 #endif
44 
45 #ifndef DllCoreExport
46 #ifdef DK_CORE_DLL_EXPORT
47 #define DllCoreExport Q_DECL_EXPORT
48 #elif DK_DLL_IMPORT
49 #define DllCoreExport Q_DECL_IMPORT
50 #else
51 #define DllCoreExport Q_DECL_IMPORT
52 #endif
53 #endif
54 
55 // Qt defines
56 class QFileDialog;
57 class QProgressDialog;
58 class QDesktopWidget;
59 class QLabel;
60 class QShortcut;
61 
62 namespace nmc {
63 
64 class DkCompressDialog;
65 class DkOpacityDialog;
66 class DkUpdateDialog;
67 class DkForceThumbDialog;
68 class DkTrainDialog;
69 #ifdef WITH_QUAZIP
70 class DkArchiveExtractionDialog;
71 #endif
72 class DkBrowseExplorer;
73 class DkMetaDataDock;
74 class DkEditDock;
75 class DkHistoryDock;
76 class DkLogDock;
77 class DkExportTiffDialog;
78 class DkUpdater;
79 class DkInstallUpdater;
80 class DkTranslationUpdater;
81 class DkPluginManagerDialog;
82 class DkThumbsSaver;
83 class DkPrintPreviewDialog;
84 class DkBatchContainer;
85 class DkCentralWidget;
86 class DkDockWidget;
87 class DkQuickAccess;
88 class DkImageLoader;
89 class DkQuickAccessEdit;
90 class DkDialogManager;
91 
92 /*! A custom event filter for OSX.
93 Its main purpose is to provide Mac OS X "open file from finder"
94 functionality for nomacs. It *has* to be catched on the
95 QApplication level in the event().
96 */
97 class DkNomacsOSXEventFilter : public QObject {
98 	Q_OBJECT
99 
100 public:
101 	DkNomacsOSXEventFilter(QObject *parent = 0);
102 
103 signals:
104 	void loadFile(const QString& fi) const;
105 
106 protected:
107 	/*! Handle QFileOpenEvent for mac here */
108 	bool eventFilter(QObject *obj, QEvent *event) override;
109 
110 };
111 
112 class DkMenuBar;
113 
114 enum PluginMenuActions {
115 	menu_plugin_manager,
116 
117 	menu_plugins_end,	// nothing beyond this point
118 };
119 
120 
121 class DllCoreExport DkNoMacs : public QMainWindow {
122 	Q_OBJECT
123 
124 public:
125 
126 	virtual ~DkNoMacs();
127 
128 	virtual DkCentralWidget* getTabWidget() const;
129 
130 	void loadFile(const QString& filePath);
131 
132 	bool mSaveSettings = true;
133 
134 signals:
135 	void sendArrangeSignal(bool overlaid) const;
136 	void closeSignal() const;
137 	void sendQuitLocalClientsSignal() const;
138 
139 public slots:
140 	void toggleFullScreen();
141 	void enterFullScreen();
142 	void exitFullScreen();
143 	void toggleDocks(bool hide);
144 	void restoreDocks();
145 	void showExplorer(bool show, bool saveSettings = true);
146 	void showMetaDataDock(bool show, bool saveSettings = true);
147 	void showEditDock(bool show, bool saveSettings = true);
148 	void showHistoryDock(bool show, bool saveSettings = true);
149 	void showLogDock(bool show, bool saveSettings = true);
150 	void showThumbsDock(bool show);
151 	void thumbsDockAreaChanged();
152 	void openDir();
153 	void openFile();
154 	void openQuickLaunch();
155 	void openFileList();
156 	void saveFileList();
157 	void renameFile();
158 	void changeSorting(bool change);
159 	void goTo();
160 	void find(bool filterAction = true);
161 	void extractImagesFromArchive();
162 	void trainFormat();
163 	void exportTiff();
164 	void cleanSettings();
165 	void newInstance(const QString& filePath = QString());
166 	void showMenuBar(bool show);
167 	void openFileWith(QAction* action);
168 	void aboutDialog();
169 	void openDocumentation();
170 	void bugReport();
171 	void loadRecursion();
172 	void setWindowTitle(QSharedPointer<DkImageContainerT> imgC);
173 	void setWindowTitle(const QString& filePath, const QSize& size = QSize(), bool edited = false, const QString& attr = QString());
174 	void showOpacityDialog();
175 	void opacityUp();
176 	void opacityDown();
177 	void changeOpacity(float change);
178 	void animateChangeOpacity();
179 	void animateOpacityUp();
180 	void animateOpacityDown();
181 	void lockWindow(bool lock);
182 	void tcpSetWindowRect(QRect newRect, bool opacity, bool overlaid);
183 	void tcpSendWindowRect();
184 	void tcpSendArrange();
185 	void newClientConnected(bool connected);
186 	virtual void settingsChanged();
187 	void showUpdaterMessage(QString msg, QString title);
188 	void showUpdateDialog(QString msg, QString title);
189 	void performUpdate();
190 	void updateProgress(qint64 received, qint64 total);
191 	void updateProgressTranslations(qint64 received, qint64 total);
192 	void startSetup(QString);
193 	void updateTranslations();
194 	void checkForUpdate(bool silent = false);
195 	void startPong() const;
196 	void fitFrame();
197 	void setRecursiveScan(bool recursive);
198 	void openPluginManager();
199 	void clearFileHistory();
200 	void clearFolderHistory();
201 	void restartWithTranslationUpdate();
202 	void restartWithPseudoColor(bool contrast);
203 	void restartFrameless(bool frameless);
204 	void showRecentFilesOnStartUp();
205 
206 	// batch actions
207 	void computeThumbsBatch();
208 	void onWindowLoaded();
209 
210 protected:
211 
212 	// mouse events
213 	void mouseDoubleClickEvent(QMouseEvent* event) override;
214 	void mousePressEvent(QMouseEvent* event) override;
215 	void mouseReleaseEvent(QMouseEvent *event) override;
216 	void mouseMoveEvent(QMouseEvent *event) override;
217 
218 	// mouse events
219 	void moveEvent(QMoveEvent *event) override;
220 
221 	// window events
222 	void contextMenuEvent(QContextMenuEvent *event) override;
223 	bool eventFilter(QObject *obj, QEvent *event) override;
224 	void resizeEvent(QResizeEvent *event) override;
225 	void closeEvent(QCloseEvent *event) override;
226 
227 	void keyPressEvent(QKeyEvent *event) override;
228 	void keyReleaseEvent(QKeyEvent* event) override;
229 
230 	//bool gestureEvent(QGestureEvent *event);
231 
232 	// needed to hide menu
233 	bool mOtherKeyPressed = true;
234 	QPoint mPosGrabKey;
235 	bool mOverlaid = false;
236 
237 	// menu
238 	DkMenuBar* mMenu = 0;
239 	QMenu* mPluginsMenu = 0;
240 	QMenu* mSyncMenu = 0;
241 
242 	QPoint mMousePos;
243 
244 	// quick access
245 	DkQuickAccessEdit* mQuickAccessEdit = 0;
246 	DkQuickAccess* mQuickAccess = 0;
247 
248 	// file dialog
249 	QFileDialog* mOpenDialog = 0;
250 	QFileDialog* mSaveDialog = 0;
251 	DkOpacityDialog* mOpacityDialog = 0;
252 	DkUpdateDialog* mUpdateDialog = 0;
253 	QProgressDialog* mProgressDialog = 0;
254 	QProgressDialog* mProgressDialogTranslations = 0;
255 	DkForceThumbDialog* mForceDialog = 0;
256 	DkTrainDialog* mTrainDialog = 0;
257 #ifdef WITH_QUAZIP
258 	DkArchiveExtractionDialog* mArchiveExtractionDialog = 0;
259 #endif
260 	DkBrowseExplorer* mExplorer = 0;
261 	DkMetaDataDock* mMetaDataDock = 0;
262 	DkEditDock* mEditDock = 0;
263 	DkHistoryDock* mHistoryDock = 0;
264 	DkLogDock* mLogDock = 0;
265 	DkDockWidget* mThumbsDock = 0;
266 	DkExportTiffDialog* mExportTiffDialog = 0;
267 	DkThumbsSaver* mThumbSaver = 0;
268 
269 	DkPrintPreviewDialog* mPrintPreviewDialog = 0;
270 
271 	DkInstallUpdater* mInstallUpdater = 0;
272 	DkUpdater* mUpdater = 0;
273 	DkTranslationUpdater* mTranslationUpdater = 0;
274 
275 	QRect mOldGeometry;
276 	QProcess mProcess;
277 
278 	// functions
279 	DkNoMacs(QWidget *parent = 0, Qt::WindowFlags flags = Qt::WindowFlags());
280 
281 	virtual void init();
282 
283 	void loadStyleSheet();
284 	virtual void createActions();
285 	virtual void createMenu();
286 	virtual void createContextMenu();
287 	virtual void createStatusBar();
288 
289 	virtual void readSettings();
290 
291 	// plugin functions
292 	bool mPluginMenuCreated = false;
293 };
294 
295 class DllCoreExport DkNoMacsSync : public DkNoMacs {
296 	Q_OBJECT
297 
298 public:
299 	DkNoMacsSync(QWidget *parent = 0, Qt::WindowFlags flags = Qt::WindowFlags());
300 	~DkNoMacsSync();
301 
302 signals:
303 	void startRCServerSignal(bool start);
304 
305 protected:
306 
307 	// mouse events
308 	void dragEnterEvent(QDragEnterEvent *event) override;
309 	void dropEvent(QDropEvent *event) override;
310 	void mouseMoveEvent(QMouseEvent *event) override;
311 
312 	// gui
313 	virtual void createActions() override;
314 };
315 
316 class DllCoreExport DkNoMacsIpl : public DkNoMacsSync {
317 	Q_OBJECT
318 
319 public:
320 	DkNoMacsIpl(QWidget *parent = 0, Qt::WindowFlags flags = Qt::WindowFlags());
321 };
322 
323 
324 
325 class DllCoreExport DkNoMacsFrameless : public DkNoMacs {
326 	Q_OBJECT
327 
328 public:
329 	DkNoMacsFrameless(QWidget *parent = 0, Qt::WindowFlags flags = Qt::WindowFlags());
330 
331 	virtual ~DkNoMacsFrameless();
332 
333 public slots:
334 	void chooseMonitor(bool force = true);
335 
336 protected:
337 	void closeEvent(QCloseEvent *event) override;
338 	bool eventFilter(QObject *obj, QEvent *event) override;
339 	virtual void createContextMenu() override;
340 
341 	QDesktopWidget* mDesktop = 0;
342 };
343 
344 class DllCoreExport DkNoMacsContrast : public DkNoMacsSync {
345 	Q_OBJECT
346 
347 public:
348 	DkNoMacsContrast(QWidget *parent = 0, Qt::WindowFlags flags = Qt::WindowFlags());
349 
350 	virtual ~DkNoMacsContrast();
351 
352 };
353 }
354