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 
109  void onRowsAboutToBeRemoved(const QModelIndex& parent, int start, int end);
110  void onRowsInserted(const QModelIndex& parent, int start, int end);
111  void onLayoutChanged();
112  void onModelSortFilterChanged();
113  void onIndexesMoved(const QModelIndexList& indexes);
114  void onDataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight);
115 
116  void relayoutItems();
117  void onStickToCurrentPos(bool toggled);
118 
119  // void updateWorkArea();
120 
121  // file operations
122  void onCutActivated();
123  void onCopyActivated();
124  void onPasteActivated();
125  void onRenameActivated();
126  void onDeleteActivated();
127  void onFilePropertiesActivated();
128 
129 private:
130  void removeBottomGap();
131  void paintBackground(QPaintEvent* event);
132  static void alignToGrid(QPoint& pos, const QPoint& topLeft, const QSize& grid, const int spacing);
133 
134 private:
135  Fm::ProxyFolderModel* proxyModel_;
136  Fm::CachedFolderModel* model_;
137  std::shared_ptr<Fm::Folder> folder_;
138  Fm::FolderViewListView* listView_;
139 
140  QColor fgColor_;
141  QColor bgColor_;
142  QColor shadowColor_;
143  QString wallpaperFile_;
144  WallpaperMode wallpaperMode_;
145  QString lastSlide_;
146  QString wallpaperDir_;
147  int slideShowInterval_;
148  QTimer* wallpaperTimer_;
149  bool wallpaperRandomize_;
150  QPixmap wallpaperPixmap_;
151  Launcher fileLauncher_;
152  bool showWmMenu_;
153 
154  int screenNum_;
155  std::unordered_map<std::string, QPoint> customItemPos_;
156  QHash<QModelIndex, QString> displayNames_; // only for desktop entries and shortcuts
157  QTimer* relayoutTimer_;
158 };
159 
160 }
161 
162 #endif // PCMANFM_DESKTOPWINDOW_H
Definition: desktopwindow.h:35
Definition: application.h:56
Definition: settings.h:121
Definition: view.h:37
Definition: application.cpp:59
Definition: launcher.h:30
Definition: desktopwindow.h:45