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 toggleDesktop();
115
116 void onRowsAboutToBeRemoved(const QModelIndex& parent, int start, int end);
117 void onRowsInserted(const QModelIndex& parent, int start, int end);
118 void onLayoutChanged();
119 void onModelSortFilterChanged();
120 void onFolderStartLoading();
121 void onFolderFinishLoading();
122 void onFilesAdded(const Fm::FileInfoList files);
123
124 void relayoutItems();
125 void onStickToCurrentPos(bool toggled);
126
127 // void updateWorkArea();
128
129 // file operations
130 void onCutActivated();
131 void onCopyActivated();
132 void onCopyFullPathActivated();
133 void onPasteActivated();
134 void onRenameActivated();
135 void onBulkRenameActivated();
136 void onDeleteActivated();
137 void onFilePropertiesActivated();
138
139 void updateTrashIcon();
140
141 void onInlineRenaming(const QString& oldName, const QString& newName);
142
143 void onDecidingDrop(bool accepted);
144
145private:
146 void removeBottomGap();
147 QRect getWorkArea(QScreen* screen) const;
148 void addDesktopActions(QMenu* menu);
149 void paintBackground(QPaintEvent* event);
150 void paintDropIndicator();
151 bool stickToPosition(const std::string& file, QPoint& pos,
152 const QRect& workArea, const QSize& grid,
153 const std::set<std::string>& droppedFiles, bool reachedLastCell);
154 static void alignToGrid(QPoint& pos, const QPoint& topLeft, const QSize& grid, const int spacing);
155
156 void updateShortcutsFromSettings(Settings& settings);
157 void createTrashShortcut(int items);
158 void createHomeShortcut();
159 void createComputerShortcut();
160 void createNetworkShortcut();
161
162 void createTrash();
163 static void onTrashChanged(GFileMonitor* monitor, GFile* gf, GFile* other, GFileMonitorEvent evt, DesktopWindow* pThis);
164 void trustOurDesktopShortcut(std::shared_ptr<const Fm::FileInfo> file);
165 bool isTrashCan(std::shared_ptr<const Fm::FileInfo> file) const;
166
167 QImage getWallpaperImage() const;
168
169 QModelIndex navigateWithKey(int key, Qt::KeyboardModifiers modifiers, const QModelIndex& start = QModelIndex());
170
171 QModelIndex indexForPos(bool* isTrash, const QPoint& pos, const QRect& workArea, const QSize& grid) const;
172
173private:
174 Fm::ProxyFolderModel* proxyModel_;
175 Fm::FolderModel* model_;
176 std::shared_ptr<Fm::Folder> folder_;
177 Fm::FolderViewListView* listView_;
178
179 QColor fgColor_;
180 QColor bgColor_;
181 QColor shadowColor_;
182 QString wallpaperFile_;
183 WallpaperMode wallpaperMode_;
184 QString lastSlide_;
185 QString wallpaperDir_;
186 int slideShowInterval_;
187 QTimer* wallpaperTimer_;
188 bool wallpaperRandomize_;
189 QPixmap wallpaperPixmap_;
190 Launcher fileLauncher_;
191 bool desktopHideItems_;
192
193 int screenNum_;
194 std::unordered_map<std::string, QPoint> customItemPos_; // real custom positions
195 std::unordered_map<std::string, QPoint> customPosStorage_; // savable custom positions
196 QTimer* relayoutTimer_;
197 QTimer* selectionTimer_;
198
199 QRect dropRect_;
200
201 QTimer* trashUpdateTimer_;
202 GFileMonitor* trashMonitor_;
203
204 QStringList filesToTrust_;
205};
206
207}
208
209#endif // PCMANFM_DESKTOPWINDOW_H
Definition application.h:56
Definition desktopwindow.h:45
Definition launcher.h:30
Definition settings.h:154
Definition view.h:37