NDE-FileMAN
Loading...
Searching...
No Matches
desktopwindow.h
1/*
2
3 Copyright (C) 2013 Hong Jen Yee (PCMan) <pcman.tw@gmail.com>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18*/
19
20
21#ifndef NDEFILEMAN_DESKTOPWINDOW_H
22#define NDEFILEMAN_DESKTOPWINDOW_H
23
24#include "view.h"
25#include "launcher.h"
26#include <unordered_map>
27#include <string>
28
29#include <QHash>
30#include <QPoint>
31#include <QByteArray>
32#include <QScreen>
33#include <xcb/xcb.h>
34#include <libfm-qt-nde/core/folder.h>
35#include <QMenu>
36#include <QDesktopWidget>
37
38namespace Fm {
39class CachedFolderModel;
40class ProxyFolderModel;
41class FolderViewListView;
42}
43
44namespace NDEFileMAN {
45
46class Settings;
47
48class DesktopWindow : public View {
49 Q_OBJECT
50public:
51 friend class Application;
52
53 enum WallpaperMode {
54 WallpaperNone,
55 WallpaperStretch,
56 WallpaperFit,
57 WallpaperCenter,
58 WallpaperTile,
59 WallpaperZoom
60 };
61
62 explicit DesktopWindow(int screenNum);
63 virtual ~DesktopWindow();
64
65 void setForeground(const QColor& color);
66 void setShadow(const QColor& color);
67 void setBackground(const QColor& color);
68 void setDesktopFolder();
69 void setWallpaperFile(QString filename);
70 void setWallpaperMode(WallpaperMode mode = WallpaperStretch);
71 void setLastSlide(QString filename);
72 void setWallpaperDir(QString dirname);
73 void setSlideShowInterval(int interval);
74 void setWallpaperRandomize(bool randomize);
75
76 // void setWallpaperAlpha(qreal alpha);
77 void updateWallpaper();
78 bool pickWallpaper();
79 void nextWallpaper();
80 void updateFromSettings(Settings& settings, bool changeSlide = true);
81
82 void queueRelayout(int delay = 0);
83
84 int screenNum() const {
85 return screenNum_;
86 }
87
88 void setScreenNum(int num);
89
90 QScreen* getDesktopScreen() const;
91
92 bool isPanelPositionChange() {
93 return isPanelPositionChange_;
94 }
95 void setPanelPositionChange(bool change) {
96 isPanelPositionChange_ = change;
97 }
98
99protected:
100 virtual void prepareFolderMenu(Fm::FolderMenu* menu) override;
101 virtual void prepareFileMenu(Fm::FileMenu* menu) override;
102 virtual void resizeEvent(QResizeEvent* event) override;
103 virtual void onFileClicked(int type, const std::shared_ptr<const Fm::FileInfo>& fileInfo) override;
104
105 void loadItemPositions();
106 void saveItemPositions();
107
108 QImage loadWallpaperFile(QSize requiredSize);
109
110 virtual bool event(QEvent* event) override;
111 virtual bool eventFilter(QObject* watched, QEvent* event) override;
112
113 virtual void childDragMoveEvent(QDragMoveEvent* e) override;
114 virtual void childDropEvent(QDropEvent* e) override;
115 virtual void closeEvent(QCloseEvent* event) override;
116 virtual void paintEvent(QPaintEvent* event) override;
117
118protected Q_SLOTS:
119 void onOpenDirRequested(const Fm::FilePath& path, int target);
120 void onDesktopPreferences();
121 void selectAll();
122
123 void onRowsAboutToBeRemoved(const QModelIndex& parent, int start, int end);
124 void onRowsInserted(const QModelIndex& parent, int start, int end);
125 void onLayoutChanged();
126 void onModelSortFilterChanged();
127 void onDataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight);
128 void onFolderStartLoading();
129 void onFolderFinishLoading();
130 void onFilesAdded(const Fm::FileInfoList files);
131
132 void relayoutItems();
133 void onStickToCurrentPos(bool toggled);
134
135 // void updateWorkArea();
136
137 // file operations
138 void onCutActivated();
139 void onCopyActivated();
140 void onCopyFullPathActivated();
141 void onPasteActivated();
142 void onRenameActivated();
143 void onBulkRenameActivated();
144 void onDeleteActivated();
145 void onFilePropertiesActivated();
146 void onDesktopReloadActivated(); // 刷新
147
148 void updateTrashIcon();
149
150 void onOpenSystemInfo(); // 打开系统信息
151 void onCancelAllStickPos(); // 取消桌面图标所以固定座标
152 void onDisplaySettings(); // 显示设置
153 void onPersonalise(); // 个性化
154 void onDesktopSortActionTriggered(bool checked); //桌面排序
155 void desktopResize();
156 void toggleAutoSort(); // 自动排序
157
158private:
159 void removeBottomGap();
160 void addDesktopActions(QMenu* menu);
161 void paintBackground(QPaintEvent* event);
162 void paintDropIndicator();
163 bool stickToPosition(const std::string& file, QPoint& pos, const QRect& workArea, const QSize& grid, bool reachedLastCell = false);
164 static void alignToGrid(QPoint& pos, const QPoint& topLeft, const QSize& grid, const int spacing);
165
166 void updateShortcutsFromSettings(Settings& settings);
167 void createTrashShortcut(int items);
168 void createHomeShortcut();
169 void createComputerShortcut();
170 void createNetworkShortcut();
171
172 void createTrash();
173 static void onTrashChanged(GFileMonitor* monitor, GFile* gf, GFile* other, GFileMonitorEvent evt, DesktopWindow* pThis);
174 void trustOurDesktopShortcut(std::shared_ptr<const Fm::FileInfo> file);
175 bool isTrashCan(std::shared_ptr<const Fm::FileInfo> file);
176
177 void createDesktopViewMenu(QMenu* menu);
178 void createDesktopSortMenu(QMenu* menu);
179 void addDesktopSortMenuItem(QMenu* menu, const QString &title, int id);
180 void desktopAutoSort();
181 bool stickToAutoSortPosition(const std::string& file, QPoint& pos, const QPoint& selPos, const QRect& workArea, const QSize& grid, bool reachedLastCell = false);
182 void panelPositionChanged();
183 void removeItemsOnAutoSort();
184 void initsetting(void);
185
186private:
187 Fm::ProxyFolderModel* proxyModel_;
188 Fm::CachedFolderModel* model_;
189 std::shared_ptr<Fm::Folder> folder_;
190 Fm::FolderViewListView* listView_;
191 QDesktopWidget *desktopwidget;
192
193 QColor fgColor_;
194 QColor bgColor_;
195 QColor shadowColor_;
196 QString wallpaperFile_;
197 WallpaperMode wallpaperMode_;
198 QString lastSlide_;
199 QString wallpaperDir_;
200 int slideShowInterval_;
201 QTimer* wallpaperTimer_;
202 bool wallpaperRandomize_;
203 QPixmap wallpaperPixmap_;
204 Launcher fileLauncher_;
205 bool showWmMenu_;
206 //bool desktopHideItems_;
207 bool desktopAutoSort_;
208 bool isReoveItem_;
209 bool isInserted_;
210 bool isResizeDesktop_;
211 bool isPanelPositionChange_;
212 bool isAutoSortAndResize_;
213 bool isDesktopOrderRefresh_;
214 bool moveItem_;
215 bool isReload_;
216 bool isDesktopSort_;
217
218 int screenNum_;
219 std::unordered_map<std::string, QPoint> customItemPos_;
220 QHash<QModelIndex, QString> displayNames_; // only for desktop entries and shortcuts
221 QTimer* relayoutTimer_;
222 QTimer* selectionTimer_;
223
224 QRect dropRect_;
225
226 QTimer* trashUpdateTimer_;
227 GFileMonitor* trashMonitor_;
228
229 QMenu* desktopViewMenu_;
230 QMenu* desktopSortMenu_;
231 QActionGroup* desktopSortActionGroup_;
232 QPoint desktopWorkArea_; // 桌面图标左上角初始坐标
233};
234
235}
236
237#endif // NDEFILEMAN_DESKTOPWINDOW_H
Definition application.h:56
Definition desktopwindow.h:48
Definition launcher.h:30
Definition settings.h:170
Definition view.h:37