1 /*******************************************************************************************************
2  DkControlWidget.h
3  Created on:	31.08.2015
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  nomacs is free software: you can redistribute it and/or modify
14  it under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  nomacs is distributed in the hope that it will be useful,
19  but WITHOUT ANY WARRANTY; without even the implied warranty of
20  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  GNU General Public License for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with this program.  If not, see <http://www.gnu.org/licenses/>.
25 
26  *******************************************************************************************************/
27 
28 #pragma once
29 
30 #include "DkImageContainer.h"
31 #include "DkBaseWidgets.h"
32 
33 #pragma warning(push, 0)	// no warnings from includes - begin
34 #include <QWidget>
35 #include <QSharedPointer>
36 #pragma warning(pop)		// no warnings from includes - end
37 
38 #ifndef DllCoreExport
39 #ifdef DK_CORE_DLL_EXPORT
40 #define DllCoreExport Q_DECL_EXPORT
41 #elif DK_DLL_IMPORT
42 #define DllCoreExport Q_DECL_IMPORT
43 #else
44 #define DllCoreExport Q_DECL_IMPORT
45 #endif
46 #endif
47 
48 
49 #ifdef Q_OS_WIN
50 #pragma warning(disable: 4251)	// TODO: remove
51 #endif
52 
53 class QStackedLayout;
54 class QGridLayout;
55 class QLabel;
56 
57 namespace nmc {
58 
59 // some dummies
60 class DkFilePreview;
61 class DkThumbScrollWidget;
62 class DkMetaDataHUD;
63 class DkCommentWidget;
64 class DkViewPort;
65 class DkCropWidget;
66 class DkZoomWidget;
67 class DkPlayer;
68 class DkFolderScrollBar;
69 class DkRatingLabelBg;
70 class DkDelayedMessage;
71 class DkFileInfoLabel;
72 class DkHistogram;
73 class DkLabelBg;
74 class DkPluginViewPort;
75 class DkMetaDataT;
76 class DkDelayedInfo;
77 class DkOverview;
78 class DkViewPortInterface;
79 
80 class DllCoreExport DkControlWidget : public DkWidget {
81 	Q_OBJECT
82 
83 public:
84 
85 	enum VerPos {top_scroll = 0, top_thumbs, top_metadata, top_info, ver_center, bottom_info, bottom, bottom_metadata, bottom_thumbs, ver_pos_end};
86 	enum HorPos {left_thumbs = 0, left_metadata, left, hor_center, right, right_metadata, right_thumbs, hor_pos_end};
87 
88 	enum InfoPos {
89 		bottom_left_label,
90 		bottom_right_label,
91 		top_left_label
92 	};
93 
94 	enum Widgets {
95 		last_widget = -1,
96 		hud_widget,
97 		crop_widget,
98 
99 		widget_end
100 	};
101 
102 	DkControlWidget(DkViewPort *parent = 0, Qt::WindowFlags flags = Qt::WindowFlags());
~DkControlWidget()103 	virtual ~DkControlWidget() {};
104 
105 	void setFullScreen(bool fullscreen);
106 
107 	DkFilePreview* getFilePreview() const;
108 	DkFolderScrollBar* getScroller() const;
109 	DkMetaDataHUD* getMetaDataWidget() const;
110 	DkCommentWidget* getCommentWidget() const;
111 	DkOverview* getOverview() const;
112 	DkZoomWidget* getZoomWidget() const;
113 	DkPlayer* getPlayer() const;
114 	DkFileInfoLabel* getFileInfoLabel() const;
115 	DkHistogram* getHistogram() const;
116 	DkCropWidget* getCropWidget() const;
117 
118 	void stopLabels();
119 	void showWidgetsSettings();
120 	void setWidgetsVisible(bool visible, bool saveSettings = false);
121 
122 	void settingsChanged();
123 
124 public slots:
125 	void toggleHUD(bool hide);
126 	void showPreview(bool visible);
127 	void showMetaData(bool visible);
128 	void showFileInfo(bool visible);
129 	void showPlayer(bool visible);
130 	void startSlideshow(bool start = true);
131 	void hideCrop(bool hide = true);
132 	void showCrop(bool visible);
133 	void showOverview(bool visible);
134 	void showHistogram(bool visible);
135 	void showCommentWidget(bool visible);
136 	void switchWidget(QWidget* widget = 0);
137 	void changeMetaDataPosition(int pos);
138 	void changeThumbNailPosition(int pos);
139 	void showScroller(bool visible);
140 	void setPluginWidget(DkViewPortInterface* pluginWidget, bool removeWidget);
141 
142 	bool closePlugin(bool askForSaving, bool force = false);
143 	bool applyPluginChanges(bool askForSaving);
144 
145 	void updateImage(QSharedPointer<DkImageContainerT> imgC);
146 	void setInfo(const QString& msg, int time = 3000, int location = bottom_left_label);
147 	virtual void setInfoDelayed(const QString& msg, bool start = false, int delayTime = 1000);
148 	void updateRating(int rating);
149 
150 	void imageLoaded(bool loaded);
151 
152 	void update();
153 
154 protected:
155 
156 	// events
157 	void mousePressEvent(QMouseEvent *event) override;
158 	void mouseReleaseEvent(QMouseEvent *event) override;
159 	void mouseMoveEvent(QMouseEvent *event) override;
160 
161 	void keyPressEvent(QKeyEvent *event) override;
162 	void keyReleaseEvent(QKeyEvent *event) override;
163 
164 	// functions
165 	void init();
166 	void connectWidgets();
167 
168 	// layout (switching of HUD contexts)
169 	QVector<QWidget*> mWidgets;
170 	QStackedLayout* mLayout;
171 	QGridLayout* mHudLayout;
172 
173 	DkViewPort* mViewport;
174 	DkCropWidget* mCropWidget;
175 
176 	DkFilePreview* mFilePreview;
177 	DkMetaDataHUD* mMetaDataInfo;
178 	DkCommentWidget* mCommentWidget;
179 	DkZoomWidget* mZoomWidget;
180 	DkPlayer* mPlayer;
181 	DkHistogram* mHistogram;
182 
183 	DkFolderScrollBar* mFolderScroll;
184 	DkFileInfoLabel* mFileInfoLabel;
185 	DkRatingLabelBg* mRatingLabel;
186 
187 	DkDelayedMessage* mDelayedInfo;
188 
189 	DkLabelBg* mBottomLabel;
190 	DkLabelBg* mBottomLeftLabel;
191 
192 	DkPluginViewPort* mPluginViewport = 0;
193 
194 	QSharedPointer<DkImageContainerT> mImgC;
195 
196 	QLabel* mWheelButton;
197 
198 	QPointF mEnterPos;
199 
200 };
201 
202 }
203