PCManFM-Qt
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 PCMANFM_DESKTOPWINDOW_H
22 #define PCMANFM_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 <xcb/xcb.h>
33 #include <libfm-qt/core/folder.h>
34 
35 namespace Fm {
36 class CachedFolderModel;
37 class ProxyFolderModel;
38 class FolderViewListView;
39 }
40 
41 namespace PCManFM {
42 
43 class Settings;
44 
45 class DesktopWindow : public View {
46  Q_OBJECT
47 public:
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(QString filename);
67  void setWallpaperMode(WallpaperMode mode = WallpaperStretch);
68  void setLastSlide(QString filename);
69  void setWallpaperDir(QString dirname);
70  void setSlideShowInterval(int interval);
71  void setWallpaperRandomize(bool randomize);
72 
73  // void setWallpaperAlpha(qreal alpha);
74  void updateWallpaper();
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 protected:
88  virtual void prepareFolderMenu(Fm::FolderMenu* menu) override;
89  virtual void prepareFileMenu(Fm::FileMenu* menu) override;
90  virtual void resizeEvent(QResizeEvent* event) override;
91  virtual void onFileClicked(int type, const std::shared_ptr<const Fm::FileInfo>& fileInfo) override;
92 
93  void loadItemPositions();
94  void saveItemPositions();
95 
96  QImage loadWallpaperFile(QSize requiredSize);
97 
98  virtual bool event(QEvent* event) override;
99  virtual bool eventFilter(QObject* watched, QEvent* event) override;
100 
101  virtual void childDropEvent(QDropEvent* e) override;
102  virtual void closeEvent(QCloseEvent* event) override;
103  virtual void paintEvent(QPaintEvent *event) override;
104 
105 protected Q_SLOTS:
106  void onOpenDirRequested(const Fm::FilePath& path, int target);
107  void onDesktopPreferences();
108  void selectAll();
109  void toggleDesktop();
110 
111  void onRowsAboutToBeRemoved(const QModelIndex& parent, int start, int end);
112  void onRowsInserted(const QModelIndex& parent, int start, int end);
113  void onLayoutChanged();
114  void onModelSortFilterChanged();
115  void onIndexesMoved(const QModelIndexList& indexes);
116  void onDataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight);
117  void onFolderStartLoading();
118  void onFolderFinishLoading();
119  void onFilesAdded(const Fm::FileInfoList files);
120 
121  void relayoutItems();
122  void onStickToCurrentPos(bool toggled);
123 
124  // void updateWorkArea();
125 
126  // file operations
127  void onCutActivated();
128  void onCopyActivated();
129  void onPasteActivated();
130  void onRenameActivated();
131  void onBulkRenameActivated();
132  void onDeleteActivated();
133  void onFilePropertiesActivated();
134 
135 private:
136  void removeBottomGap();
137  void addDesktopActions(QMenu* menu);
138  void paintBackground(QPaintEvent* event);
139  static void alignToGrid(QPoint& pos, const QPoint& topLeft, const QSize& grid, const int spacing);
140 
141 private:
142  Fm::ProxyFolderModel* proxyModel_;
143  Fm::CachedFolderModel* model_;
144  std::shared_ptr<Fm::Folder> folder_;
145  Fm::FolderViewListView* listView_;
146 
147  QColor fgColor_;
148  QColor bgColor_;
149  QColor shadowColor_;
150  QString wallpaperFile_;
151  WallpaperMode wallpaperMode_;
152  QString lastSlide_;
153  QString wallpaperDir_;
154  int slideShowInterval_;
155  QTimer* wallpaperTimer_;
156  bool wallpaperRandomize_;
157  QPixmap wallpaperPixmap_;
158  Launcher fileLauncher_;
159  bool showWmMenu_;
160  bool desktopHideItems_;
161 
162  int screenNum_;
163  std::unordered_map<std::string, QPoint> customItemPos_;
164  QHash<QModelIndex, QString> displayNames_; // only for desktop entries and shortcuts
165  QTimer* relayoutTimer_;
166  QTimer* selectionTimer_;
167 };
168 
169 }
170 
171 #endif // PCMANFM_DESKTOPWINDOW_H
Definition: desktopwindow.h:35
Definition: application.h:56
Definition: settings.h:122
Definition: view.h:37
Definition: application.cpp:58
Definition: launcher.h:30
Definition: desktopwindow.h:45