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, const QString& screenName = QString());
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 void setScreenNum(int num);
85
86 QString screenName() const {
87 return screenName_;
88 }
89
90 QScreen* getDesktopScreen() const;
91
92protected:
93 virtual void prepareFolderMenu(Fm::FolderMenu* menu) override;
94 virtual void prepareFileMenu(Fm::FileMenu* menu) override;
95 virtual void resizeEvent(QResizeEvent* event) override;
96 virtual void onFileClicked(int type, const std::shared_ptr<const Fm::FileInfo>& fileInfo) override;
97
98 void loadItemPositions();
99 void saveItemPositions();
100 void retrieveCustomPos();
101 void storeCustomPos();
102
103 QImage loadWallpaperFile(QSize requiredSize, bool checkMTime);
104
105 virtual bool event(QEvent* event) override;
106 virtual bool eventFilter(QObject* watched, QEvent* event) override;
107
108 virtual void childDragMoveEvent(QDragMoveEvent* e) override;
109 virtual void childDropEvent(QDropEvent* e) override;
110 virtual void closeEvent(QCloseEvent* event) override;
111 virtual void paintEvent(QPaintEvent* event) override;
112
113protected Q_SLOTS:
114 void onDesktopPreferences();
115 void onCreatingShortcut();
116 void selectAll();
117 void invertSelection();
118 void toggleDesktop();
119
120 void onRowsAboutToBeRemoved(const QModelIndex& parent, int start, int end);
121 void onRowsInserted(const QModelIndex& parent, int start, int end);
122 void onLayoutChanged();
123 void onModelSortFilterChanged();
124 void onFolderStartLoading();
125 void onFolderFinishLoading();
126 void onFilesAdded(const Fm::FileInfoList files);
127
128 void relayoutItems();
129 void onStickToCurrentPos(bool toggled);
130
131 // void updateWorkArea();
132
133 // file operations
134 void onCutActivated();
135 void onCopyActivated();
136 void onCopyFullPathActivated();
137 void onPasteActivated();
138 void onRenameActivated();
139 void onBulkRenameActivated();
140 void onDeleteActivated();
141 void onFilePropertiesActivated();
142
143 void updateTrashIcon();
144
145 void onInlineRenaming(const QString& oldName, const QString& newName);
146
147 void onDecidingDrop(bool accepted);
148
149private:
150 void removeBottomGap();
151 QRect getWorkArea(QScreen* screen) const;
152 void addDesktopActions(QMenu* menu);
153 void paintBackground(QPaintEvent* event);
154 void paintDropIndicator();
155 bool stickToPosition(const std::string& file, QPoint& pos,
156 const QRect& workArea, const QSize& grid,
157 bool reachedLastCell,
158 const std::set<std::string>& droppedFiles,
159 const std::set<std::string>& draggedFiles = std::set<std::string>{});
160 static void alignToGrid(QPoint& pos, const QPoint& topLeft, const QSize& grid, const int spacing);
161
162 void updateShortcutsFromSettings(Settings& settings);
163 void createTrashShortcut(int items);
164 void createHomeShortcut();
165 void createComputerShortcut();
166 void createNetworkShortcut();
167
168 void createTrash();
169 static void onTrashChanged(GFileMonitor* monitor, GFile* gf, GFile* other, GFileMonitorEvent evt, DesktopWindow* pThis);
170 void trustOurDesktopShortcut(std::shared_ptr<const Fm::FileInfo> file);
171 bool isTrashCan(std::shared_ptr<const Fm::FileInfo> file) const;
172
173 QImage getWallpaperImage() const;
174
175 QModelIndex navigateWithKey(int key, Qt::KeyboardModifiers modifiers, const QModelIndex& start = QModelIndex());
176
177 QModelIndex indexForPos(bool* isTrash, const QPoint& pos, const QRect& workArea, const QSize& grid) const;
178
179private:
180 Fm::ProxyFolderModel* proxyModel_;
181 Fm::FolderModel* model_;
182 std::shared_ptr<Fm::Folder> folder_;
183 Fm::FolderViewListView* listView_;
184
185 QColor fgColor_;
186 QColor bgColor_;
187 QColor shadowColor_;
188 QString wallpaperFile_;
189 WallpaperMode wallpaperMode_;
190 QString lastSlide_;
191 QString wallpaperDir_;
192 int slideShowInterval_;
193 QTimer* wallpaperTimer_;
194 bool wallpaperRandomize_;
195 QPixmap wallpaperPixmap_;
196 Launcher fileLauncher_;
197 bool desktopHideItems_;
198
199 int screenNum_; // for X11
200 QString screenName_; // for Wayland
201 std::unordered_map<std::string, QPoint> customItemPos_; // real custom positions
202 std::unordered_map<std::string, QPoint> customPosStorage_; // savable custom positions
203 QTimer* relayoutTimer_;
204 QTimer* selectionTimer_;
205
206 QRect dropRect_;
207
208 QTimer* trashUpdateTimer_;
209 GFileMonitor* trashMonitor_;
210
211 QStringList filesToTrust_;
212};
213
214}
215
216#endif // PCMANFM_DESKTOPWINDOW_H
Definition launcher.h:30
Definition settings.h:154