Debian Codegraph @

src/album/utils/baseutils.h

raw
1 /*
2 * Copyright (C) 2020 ~ 2021 Uniontech Software Technology Co., Ltd.
3 *
4 * Author: ZhangYong <[email protected]>
5 *
6 * Maintainer: ZhangYong <[email protected]>
7 *
8 * This program 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 * any later version.
12 *
13 * This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21 #ifndef BASEUTILS_H
22 #define BASEUTILS_H
23
24 #include <QObject>
25 #include <QTimer>
26 #include <QColor>
27 #include <QMimeData>
28
29 #if QT_VERSION >= 0x050500
30 #define TIMER_SINGLESHOT(Time, Code, captured, ...) \
31 { \
32 QTimer::singleShot(Time, [captured] { Code }); \
33 }
34 #else
35 #define TIMER_SINGLESHOT(Time, Code, captured...){ \
36 QTimer *timer = new QTimer;\
37 timer->setSingleShot(true);\
38 QObject::connect(timer, &QTimer::timeout, [timer, captured] {\
39 timer->deleteLater();\
40 Code\
41 });\
42 timer->start(Time);\
43 }
44
45 #endif
46
47 #define COMMON_STR_ALLPHOTOS "所有照片"
48 #define COMMON_STR_TIMELINE "时间线"
49 #define COMMON_STR_RECENT_IMPORTED "已导入"
50 #define COMMON_STR_TRASH "最近删除"
51 #define COMMON_STR_FAVORITES "我的收藏"
52 #define COMMON_STR_SEARCH "搜索"
53 #define ALBUM_PATHNAME_BY_PHONE "DCIM"
54 #define ALBUM_PATHTYPE_BY_PHONE "External Devices"
55 #define ALBUM_PATHTYPE_BY_U "U Devices"
56 #define COMMON_STR_SLIDESHOW "幻灯片放映"
57 #define COMMON_STR_CREATEALBUM "新建相册"
58 #define COMMON_STR_RENAMEALBUM "重命名相册"
59 #define COMMON_STR_EXPORT "导出相册"
60 #define COMMON_STR_DELETEALBUM "删除相册"
61 #define COMMON_STR_VIEW_TIMELINE "timelineview"
62 #define COMMON_STR_CUSTOM "自定义"
63
64
65 #define VIEW_CONTEXT_MENU "View"
66 #define FULLSCREEN_CONTEXT_MENU "Fullscreen"
67 #define PRINT_CONTEXT_MENU "Print"
68 #define SLIDESHOW_CONTEXT_MENU "Slide show"
69 #define PRINT_CONTEXT_MENU "Print"
70 #define EXPORT_CONTEXT_MENU "Export"
71 #define COPYTOCLIPBOARD_CONTEXT_MENU "Copy"
72 #define DELETE_CONTEXT_MENU "Delete"
73 #define THROWTOTRASH_CONTEXT_MENU "Move to trash"
74 #define REMOVEFROMALBUM_CONTEXT_MENU "Delete from album"
75 #define UNFAVORITE_CONTEXT_MENU "Unfavorite"
76 #define FAVORITE_CONTEXT_MENU "Favorite"
77 #define ROTATECLOCKWISE_CONTEXT_MENU "Rotate clockwise"
78 #define ROTATECOUNTERCLOCKWISE_CONTEXT_MENU "Rotate counterclockwise"
79 #define SETASWALLPAPER_CONTEXT_MENU "Set as wallpaper"
80 #define DISPLAYINFILEMANAGER_CONTEXT_MENU "Display in file manager"
81 #define ImageInfo_CONTEXT_MENU "Image info"
82 #define VideoInfo_CONTEXT_MENU "Video info"
83 #define BUTTON_RECOVERY "Recovery"
84 #define SHOW_SHORTCUT_PREVIEW "Show shortcut preview"
85
86 namespace utils {
87 namespace common {
88 const int TOP_TOOLBAR_THEIGHT = 40;
89 const int BOTTOM_TOOLBAR_HEIGHT = 22;
90
91 const int BORDER_RADIUS = 8;
92 const int SHADOW_BORDER_RADIUS = 14;
93 const int BORDER_WIDTH = 0;
94 const int BORDER_WIDTH_SELECTED = 7;
95 const int THUMBNAIL_MAX_SCALE_SIZE = 192;
96
97
98 const QColor DARK_BACKGROUND_COLOR = QColor("#252525");
99 const QColor DARK_BACKGROUND_COLOR2 = QColor(0, 0, 0, 76);
100 const QColor LIGHT_BACKGROUND_COLOR = QColor("#F8F8F8");
101
102 const QColor LIGHT_CHECKER_COLOR = QColor(0, 0, 0, 0);
103 const QColor DARK_CHECKER_COLOR = QColor("#CCCCCC00");
104
105 const QColor DARK_BORDER_COLOR = QColor(255, 255, 255, 26);
106 const QColor LIGHT_BORDER_COLOR = QColor(0, 0, 0, 15);
107
108 const QColor DARK_TITLE_COLOR = QColor("#FFFFFF");
109 const QColor LIGHT_TITLE_COLOR = QColor(48, 48, 48);
110
111 const QString DARK_DEFAULT_THUMBNAIL = ":/resources/dark/images/default_thumbnail.png";
112 const QString LIGHT_DEFAULT_THUMBNAIL = ":/resources/light/images/default_thumbnail.png";
113
114 const QColor BORDER_COLOR_UNSELECTED = QColor("white");
115 const QColor BORDER_COLOR_SELECTED = QColor("#c3c3c3");
116 const QColor SELECTED_RECT_COLOR = QColor(44, 167, 248, 26);
117 const QColor TOP_LINE2_COLOR_DARK = QColor(255, 255, 255, 13);
118 const QColor TOP_LINE2_COLOR_LIGHT = QColor(255, 255, 255, 153);
119 const QColor TITLE_SELECTED_COLOR = QColor("#2ca7f8");
120 const QString VIEW_ALLPIC_SRN = "viewAllpicSrn";
121 const QString VIEW_TIMELINE_SRN = "viewTimelineSrn";
122 const QString VIEW_SEARCH_SRN = "viewSearchSrn";
123 const QString SHORTCUTVIEW_GROUP = "SHORTCUTVIEW";
124
125 //快捷键
126 const QString ENTER_SHORTCUT = "Enter";
127 const QString RETURN_SHORTCUT = "Return";
128 const QString F11_SHORTCUT = "F11";
129 const QString F5_SHORTCUT = "F5";
130 const QString CTRLC_SHORTCUT = "Ctrl+C";
131 const QString DELETE_SHORTCUT = "Delete";
132 const QString SHIFTDEL_SHORTCUT = "Shift+Del";
133 const QString CTRLK_SHORTCUT = "Ctrl+K";
134 const QString CTRLSHIFTK_SHORTCUT = "Ctrl+Shift+K";
135 const QString CTRLR_SHORTCUT = "Ctrl+R";
136 const QString CTRLSHIFTR_SHORTCUT = "Ctrl+Shift+R";
137 //const QString CTRLF8_SHORTCUT = "Ctrl+F8";
138 const QString CTRLF9_SHORTCUT = "Ctrl+F9";
139 //const QString CTRLD_SHORTCUT = "Ctrl+D";
140 const QString ALTD_SHORTCUT = "Alt+D";
141 //const QString ALTRETURN_SHORTCUT = "Alt+Return";
142 const QString CTRLI_SHORTCUT = "Ctrl+I";
143 const QString CTRLSHIFTN_SHORTCUT = "Ctrl+Shift+N";
144 const QString F2_SHORTCUT = "F2";
145 const QString CTRLO_SHORTCUT = "Ctrl+O";
146 const QString CTRLQ_SHORTCUT = "Ctrl+Q";
147 const QString CTRLUP_SHORTCUT = "Ctrl+=";
148 const QString CTRLDOWN_SHORTCUT = "Ctrl+-";
149 const QString CTRLSHIFTSLASH_SHORTCUT = "Ctrl+Shift+/";
150 const QString CTRLE_SHORTCUT = "Ctrl+E";
151 const QString RECTRLUP_SHORTCUT = "Ctrl++";
152 const QString CTRLF_SHORTCUT = "Ctrl+F";
153 const QString SENTENCE_SHORTCUT = ".";
154 }
155 namespace timeline {
156 const QColor DARK_SEPERATOR_COLOR = QColor(255, 255, 255, 20);
157 const QColor LIGHT_SEPERATOR_COLOR = QColor(0, 0, 0, 20);
158 }
159 namespace album {
160 const QColor DARK_DATELABEL_COLOR = QColor(255, 255, 255, 153);
161 const QColor LIGHT_DATELABEL_COLOR = QColor(48, 48, 48, 255);
162
163 const QString DARK_CREATEALBUM_NORMALPIC = ":/resources/dark/images/"
164 "create_album_normal.png";
165 const QString DARK_CREATEALBUM_HOVERPIC = ":/resources/dark/images/"
166 "create_album_hover.png";
167 const QString DARK_CREATEALBUM_PRESSPIC = ":/resources/dark/images/"
168 "create_album_press.png";
169 const QString LIGHT_CREATEALBUM_NORMALPIC = ":/resources/light/images/"
170 "create_album_normal.png";
171 const QString LIGHT_CREATEALBUM_HOVERPIC = ":/resources/light/images/"
172 "create_album_hover.png";
173 const QString LIGHT_CREATEALBUM_PRESSPIC = ":/resources/light/images/"
174 "create_album_press.png";
175
176 const QString DARK_ADDPIC = ":/resources/dark/images/album_add.svg";
177 const QString LIGHT_ADDPIC = ":/resources/light/images/album_add.svg";
178
179 const QString DARK_ALBUM_BG_NORMALPIC = ":/resources/dark/images/"
180 "album_bg_normal.png";
181 const QString DARK_ALBUM_BG_PRESSPIC = ":/resources/dark/images/"
182 "album_bg_press.png";
183
184 const QString LIGHT_ALBUM_BG_NORMALPIC = ":/resources/light/images/"
185 "album_bg_normal.svg";
186 const QString LIGHT_ALBUM_BG_HOVERPIC = ":/resources/light/images/"
187 "album_bg_hover.svg";
188 const QString LIGHT_ALBUM_BG_PRESSPIC = ":/resources/light/images/"
189 "album_bg_press.svg";
190 }
191 namespace view {
192 const QString DARK_DEFAULT_THUMBNAIL =
193 ":/resources/dark/images/empty_defaultThumbnail.png";
194 const QString LIGHT_DEFAULT_THUMBNAIL =
195 ":/resources/light/images/empty_defaultThumbnail.png";
196 const QString DARK_LOADINGICON =
197 ":/resources/dark/images/dark_loading.gif";
198 const QString LIGHT_LOADINGICON =
199 ":/resources/light/images/light_loading.gif";
200 const QString DARK_DAMAGEICON =
201 ":/resources/images/other/picture damaged_dark.svg";
202 const QString LIGHT_DAMAGEICON =
203 ":/resources/images/other/picture damaged_light.svg";
204
205 namespace naviwindow {
206 const QString DARK_BG_IMG = ":/resources/dark/naviwindow_bg.svg";
207 const QColor DARK_BG_COLOR = QColor(0, 0, 0, 100);
208 const QColor DARK_MR_BG_COLOR = QColor(0, 0, 0, 150);
209 const QColor DARK_MR_BORDER_Color = QColor(255, 255, 255, 80);
210 const QColor DARK_IMG_R_BORDER_COLOR = QColor(255, 255, 255, 50);
211
212 const QString LIGHT_BG_IMG = ":/resources/light/naviwindow_bg.svg";
213 const QColor LIGHT_BG_COLOR = QColor(255, 255, 255, 104);
214 const QColor LIGHT_MR_BG_COLOR = QColor(0, 0, 0, 101);
215 const QColor LIGHT_MR_BORDER_Color = QColor(255, 255, 255, 80);
216 const QColor LIGHT_IMG_R_BORDER_COLOR = QColor(255, 255, 255, 50);
217 }
218 }
219
220 namespace base {
221 //时间之间相差天数
222 int daysDifferenceBetweenTime(const QDateTime &start, const QDateTime &end);
223 //void copyOneImageToClipboard(const QString &path);
224 void copyImageToClipboard(const QStringList &paths);
225 void showInFileManager(const QString &path);
226 int stringHeight(const QFont &f, const QString &str);
227 QString hashByString(const QString &str);
228 QString hashByData(const QString &str);
229 QString SpliteText(const QString &text, const QFont &font, int nLabelSize);
230 QDateTime stringToDateTime(const QString &time);
231 QString getFileContent(const QString &file);
232 QPixmap renderSVG(const QString &filePath, const QSize &size);
233 //bool checkMimeData(const QMimeData *mimeData);
234 bool checkMimeUrls(const QList<QUrl> urls);
235 QString mkMutiDir(const QString &path);
236 //根据源文件路径生产缩略图路径
237 QString filePathToThumbnailPath(const QString &filePath, QString dataHash = "");
238 QUrl UrlInfo(QString path); //main中的全局函数移至此处
239 //视频相关
240 static unsigned int DAYSECONDS = 86400;
241 const QStringList m_audioFiletypes = {"*.mp3", "*.ogg", "*.wav", "*.wma", "*.m4a", "*.aac", "*.ac3"
242 , "*.ape", "*.flac", "*.ra", "*.mka", "*.dts", "*.opus", "*.amr"
243 };
244 const QStringList m_videoFiletypes = {"*.avs2"/*支持avs2视频格式*/, "*.3g2", "*.3ga", "*.3gp", "*.3gp2"
245 , "*.3gpp", "*.amv", "*.asf", "*.asx", "*.avf", "*.avi", "*.bdm"
246 , "*.bdmv", "*.bik", "*.clpi", "*.cpi", "*.dat", "*.divx", "*.drc"
247 , "*.dv", "*.dvr-ms", "*.f4v", "*.flv", "*.gvi", "*.gxf", "*.hdmov"
248 , "*.hlv", "*.iso", "*.letv", "*.lrv", "*.m1v", "*.m2p", "*.m2t"
249 , "*.m2ts", "*.m2v", "*.m3u", "*.m3u8", "*.m4v", "*.mkv", "*.moov"
250 , "*.mov", "*.mov", "*.mp2", "*.mp2v", "*.mp4", "*.mp4v", "*.mpe"
251 , "*.mpeg", "*.mpeg1", "*.mpeg2", "*.mpeg4", "*.mpg", "*.mpl", "*.mpls"
252 , "*.mpv", "*.mpv2", "*.mqv", "*.mts", "*.mts", "*.mtv", "*.mxf", "*.mxg"
253 , "*.nsv", "*.nuv", "*.ogg", "*.ogm", "*.ogv", "*.ogx", "*.ps", "*.qt"
254 , "*.qtvr", "*.ram", "*.rec", "*.rm", "*.rm", "*.rmj", "*.rmm", "*.rms"
255 , "*.rmvb", "*.rmx", "*.rp", "*.rpl", "*.rv", "*.rvx", "*.thp", "*.tod"
256 , "*.tp", "*.trp", "*.ts", "*.tts", "*.txd", "*.vcd", "*.vdr", "*.vob"
257 , "*.vp8", "*.vro", "*.webm", "*.wm", "*.wmv", "*.wtv", "*.xesc", "*.xspf"
258 };
259 QString Time2str(const qint64 &seconds);
260 QString videoIndex2str(const int &index);
261 QString audioIndex2str(const int &index);
262 //判断是否视频
263 bool isVideo(QString path);
264 } // namespace base
265
266 } // namespace utils
267
268 #endif // BASEUTILS_H