PCManFM-Qt
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#ifndef PCMANFM_DESKTOPWINDOW_H
21#define PCMANFM_DESKTOPWINDOW_H
22
23#include "view.h"
24#include "launcher.h"
25#include <unordered_map>
26#include <string>
27
28#include <QHash>
29#include <QPoint>
30#include <QByteArray>
31#include <QScreen>
32#include <xcb/xcb.h>
33#include <libfm-qt6/core/folder.h>
34
35namespace Fm {
36class CachedFolderModel;
37class ProxyFolderModel;
38class FolderViewListView;
39}
40
41namespace PCManFM {
42
43class Settings;
44
45class DesktopWindow : public View {
46 Q_OBJECT
47public:
48 friend class Application;
49
50 enum WallpaperMode {
51 WallpaperNone,
52 WallpaperStretch,
53 WallpaperFit,
54 WallpaperCenter,
55 WallpaperTile,
56 WallpaperZoom
57 };
58
59 explicit DesktopWindow(int screenNum);
60 virtual ~DesktopWindow();
61
62 void setForeground(const QColor& color);
63 void setShadow(const QColor& color);
64 void setBackground(const QColor& color);
65 void setDesktopFolder();
66 void setWallpaperFile(const QString& filename);
67 void setWallpaperMode(WallpaperMode mode = WallpaperStretch);
68 void setLastSlide(const QString& filename);
69 void setWallpaperDir(const QString& dirname);
70 void setSlideShowInterval(int interval);
71 void setWallpaperRandomize(bool randomize);
72
73 // void setWallpaperAlpha(qreal alpha);
74 void updateWallpaper(bool checkMTime = false);
75 bool pickWallpaper();
76 void nextWallpaper();
77 void updateFromSettings(Settings& settings, bool changeSlide = true);
78
79 void queueRelayout(int delay = 0);
80
81 int screenNum() const {
82 return screenNum_;
83 }
84
85 void setScreenNum(int num);
86
87 QScreen* getDesktopScreen() const;
88
89protected:
90 virtual void prepareFolderMenu(Fm::FolderMenu* menu) override;
91 virtual void prepareFileMenu(Fm::FileMenu* menu) override;
92 virtual void resizeEvent(QResizeEvent* event) override;
93 virtual void onFileClicked(int type, const std::shared_ptr<const Fm::FileInfo>& fileInfo) override;
94
95 void loadItemPositions();
96 void saveItemPositions();
97 void retrieveCustomPos();
98 void storeCustomPos();
99
100 QImage loadWallpaperFile(QSize requiredSize, bool checkMTime);
101
102 virtual bool event(QEvent* event) override;
103 virtual bool eventFilter(QObject* watched, QEvent* event) override;
104
105 virtual void childDragMoveEvent(QDragMoveEvent* e) override;
106 virtual void childDropEvent(QDropEvent* e) override;
107 virtual void closeEvent(QCloseEvent* event) override;
108 virtual void paintEvent(QPaintEvent* event) override;
109
110protected Q_SLOTS:
111 void onDesktopPreferences();
112 void onCreatingShortcut();
113 void selectAll();
114 void invertSelection();
115 void toggleDesktop();
116
117 void onRowsAboutToBeRemoved(const QModelIndex& parent, int start, int end);
118 void onRowsInserted(const QModelIndex& parent, int start, int end);
119 void onLayoutChanged();
120 void onModelSortFilterChanged();
121 void onFolderStartLoading();
122 void onFolderFinishLoading();
123 void onFilesAdded(const Fm::FileInfoList files);
124
125 void relayoutItems();
126 void onStickToCurrentPos(bool toggled);
127
128 // void updateWorkArea();
129
130 // file operations
131 void onCutActivated();
132 void onCopyActivated();
133 void onCopyFullPathActivated();
134 void onPasteActivated();
135 void onRenameActivated();
136 void onBulkRenameActivated();
137 void onDeleteActivated();
138 void onFilePropertiesActivated();
139
140 void updateTrashIcon();
141
142 void onInlineRenaming(const QString& oldName, const QString& newName);
143
144 void onDecidingDrop(bool accepted);
145
146private:
147 void removeBottomGap();
148 QRect getWorkArea(QScreen* screen) const;
149 void addDesktopActions(QMenu* menu);
150 void paintBackground(QPaintEvent* event);
151 void paintDropIndicator();
152 bool stickToPosition(const std::string& file, QPoint& pos,
153 const QRect& workArea, const QSize& grid,
154 const std::set<std::string>& droppedFiles, bool reachedLastCell);
155 static void alignToGrid(QPoint& pos, const QPoint& topLeft, const QSize& grid, const int spacing);
156
157 void updateShortcutsFromSettings(Settings& settings);
158 void createTrashShortcut(int items);
159 void createHomeShortcut();
160 void createComputerShortcut();
161 void createNetworkShortcut();
162
163 void createTrash();
164 static void onTrashChanged(GFileMonitor* monitor, GFile* gf, GFile* other, GFileMonitorEvent evt, DesktopWindow* pThis);
165 void trustOurDesktopShortcut(std::shared_ptr<const Fm::FileInfo> file);
166 bool isTrashCan(std::shared_ptr<const Fm::FileInfo> file) const;
167
168 QImage getWallpaperImage() const;
169
170 QModelIndex navigateWithKey(int key, Qt::KeyboardModifiers modifiers, const QModelIndex& start = QModelIndex());
171
172 QModelIndex indexForPos(bool* isTrash, const QPoint& pos, const QRect& workArea, const QSize& grid) const;
173
174private:
175 Fm::ProxyFolderModel* proxyModel_;
176 Fm::FolderModel* model_;
177 std::shared_ptr<Fm::Folder> folder_;
178 Fm::FolderViewListView* listView_;
179
180 QColor fgColor_;
181 QColor bgColor_;
182 QColor shadowColor_;
183 QString wallpaperFile_;
184 WallpaperMode wallpaperMode_;
185 QString lastSlide_;
186 QString wallpaperDir_;
187 int slideShowInterval_;
188 QTimer* wallpaperTimer_;
189 bool wallpaperRandomize_;
190 QPixmap wallpaperPixmap_;
191 Launcher fileLauncher_;
192 bool desktopHideItems_;
193
194 int screenNum_;
195 std::unordered_map<std::string, QPoint> customItemPos_; // real custom positions
196 std::unordered_map<std::string, QPoint> customPosStorage_; // savable custom positions
197 QTimer* relayoutTimer_;
198 QTimer* selectionTimer_;
199
200 QRect dropRect_;
201
202 QTimer* trashUpdateTimer_;
203 GFileMonitor* trashMonitor_;
204
205 QStringList filesToTrust_;
206};
207
208}
209
210#endif // PCMANFM_DESKTOPWINDOW_H
Definition application.h:56
Definition desktopwindow.h:45
Definition launcher.h:30
Definition settings.h:154
Definition view.h:37