OSDN Git Service

高速化の試み
[gefu/Gefu.git] / foldermodel.h
1 #ifndef FOLDERMODEL_H\r
2 #define FOLDERMODEL_H\r
3 \r
4 #include <QAbstractTableModel>\r
5 #include <QDir>\r
6 #include <QFileIconProvider>\r
7 #include <QFileSystemWatcher>\r
8 #include <QBrush>\r
9 #include <QFont>\r
10 #include <QMutex>\r
11 #include <QPalette>\r
12 class Preferences;\r
13 \r
14 class FolderModel : public QAbstractTableModel\r
15 {\r
16     Q_OBJECT\r
17 public:\r
18     enum Column {\r
19         Name = 0,\r
20         Extension,\r
21         Size,\r
22         LastModified,\r
23         ColumnCount,\r
24     };\r
25     typedef QVector<QString> History;\r
26 \r
27     explicit FolderModel(QObject *parent = 0);\r
28 \r
29     void            clearPixmapCache();\r
30     QString         error() const;\r
31     QIcon           fileIcon(const QModelIndex &index) const;\r
32     QFileInfo       fileInfo(const QModelIndex &index) const;\r
33     QString         fileName(const QModelIndex &index) const;\r
34     QString         filePath(const QModelIndex &index) const;\r
35     QDir::Filters   filter() const;\r
36     const History&  history() const;\r
37     bool            isActive() const;\r
38     bool            isDir(const QModelIndex &index) const;\r
39     bool            isHistoryBegin() const;\r
40     bool            isHistoryEnd() const;\r
41     bool            isMarked(const QModelIndex &index) const;\r
42     QFileInfoList   markedItems() const;\r
43     QModelIndex     mkdir(const QString &name);\r
44     QStringList     nameFilters() const;\r
45     QPixmap         pixmap(const QModelIndex &index, const QSize &size) const;\r
46     QString         rootPath() const;\r
47     QModelIndex     search(const QString &value, const QModelIndex &start = QModelIndex(), int step = 1);\r
48     void            setActive();\r
49     void            setFilter(QDir::Filters filters);\r
50     void            setHistoryAt(const QString &path);\r
51     void            setNameFilters(const QStringList &nameFiltes);\r
52     void            setRootPath(const QString &path, bool addHistory = true);\r
53     void            setSorting(QDir::SortFlags sort);\r
54     QDir::SortFlags sorting() const;\r
55     QModelIndex     touch(const QString &name);\r
56     void            updateAppearance(const Preferences &prefs);\r
57 \r
58     static FolderModel* activeModel();\r
59 \r
60 signals:\r
61 \r
62 public slots:\r
63     void    fsWatcher_directoryChanged(const QString &path);\r
64     void    onCdHome();\r
65     void    onCdRoot();\r
66     void    onCdUp();\r
67     void    onHistoryBack();\r
68     void    onHistoryForward();\r
69     void    onMarkAll();\r
70     void    onMarkAllFiles();\r
71     void    onMarkAllOff();\r
72     void    onMarkInvert();\r
73     void    refresh();\r
74     void    thumbnail_Ready(const QString &path, const QPixmap &pixmap);\r
75 \r
76 private:\r
77     static FolderModel* m_activeModel;\r
78 \r
79     typedef QMap<QString, int> CheckContainer;\r
80     typedef QMap<QString, QPixmap> PixmapContainer;\r
81 \r
82     QString             m_error;\r
83     QDir                m_dir;\r
84     QFileInfoList       m_fileInfoList;\r
85     CheckContainer      m_checkStates;\r
86     QFileIconProvider   m_IconProvider;\r
87     QFileSystemWatcher  m_fsWatcher;\r
88     History             m_history;\r
89     int                 m_historyPos;\r
90     PixmapContainer     m_pixmapCache;\r
91     QMutex              m_pixmapCacheMutex;\r
92     QPalette            m_Palette;\r
93     QFont               m_font;\r
94 \r
95     bool    isDotFile(const QModelIndex &index) const;\r
96     void    setError(const QString &error = QString());\r
97 \r
98     const QBrush&   base() const;\r
99     const QBrush&   text() const;\r
100     const QBrush&   marked() const;\r
101     const QBrush&   markedText() const;\r
102     const QBrush&   hidden() const;\r
103     const QBrush&   readOnly() const;\r
104     const QBrush&   system() const;\r
105 \r
106     // QAbstractItemModel interface\r
107 public:\r
108     int rowCount(const QModelIndex &parent = QModelIndex()) const;\r
109     int columnCount(const QModelIndex &parent = QModelIndex()) const;\r
110     QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;\r
111     QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;\r
112     Qt::ItemFlags flags(const QModelIndex &index) const;\r
113     bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);\r
114     Qt::DropActions supportedDropActions() const;\r
115     QStringList mimeTypes() const;\r
116 };\r
117 \r
118 inline QString FolderModel::error() const\r
119 {\r
120     return m_error;\r
121 }\r
122 \r
123 inline QFileInfo FolderModel::fileInfo(const QModelIndex &index) const\r
124 {\r
125     Q_ASSERT(index.isValid());\r
126     return m_fileInfoList[index.row()];\r
127 }\r
128 \r
129 inline QString FolderModel::fileName(const QModelIndex &index) const\r
130 {\r
131     Q_ASSERT(index.isValid());\r
132     return m_fileInfoList[index.row()].fileName();\r
133 }\r
134 \r
135 inline QString FolderModel::filePath(const QModelIndex &index) const\r
136 {\r
137     Q_ASSERT(index.isValid());\r
138     return m_fileInfoList[index.row()].absoluteFilePath();\r
139 }\r
140 \r
141 inline QDir::Filters FolderModel::filter() const\r
142 {\r
143     return m_dir.filter();\r
144 }\r
145 \r
146 inline const FolderModel::History &FolderModel::history() const\r
147 {\r
148     return m_history;\r
149 }\r
150 \r
151 inline bool FolderModel::isActive() const\r
152 {\r
153     return m_activeModel == this;\r
154 }\r
155 \r
156 inline bool FolderModel::isDir(const QModelIndex &index) const\r
157 {\r
158     return m_fileInfoList[index.row()].isDir();\r
159 }\r
160 \r
161 inline bool FolderModel::isHistoryBegin() const\r
162 {\r
163     return m_historyPos == 0;\r
164 }\r
165 \r
166 inline bool FolderModel::isHistoryEnd() const\r
167 {\r
168     return m_historyPos == m_history.size() - 1;\r
169 }\r
170 \r
171 inline bool FolderModel::isDotFile(const QModelIndex &index) const\r
172 {\r
173     return fileName(index).lastIndexOf(".") == 0;\r
174 }\r
175 \r
176 inline QStringList FolderModel::nameFilters() const\r
177 {\r
178     return m_dir.nameFilters();\r
179 }\r
180 \r
181 inline void FolderModel::refresh()\r
182 {\r
183     setRootPath(rootPath());\r
184 }\r
185 \r
186 inline QString FolderModel::rootPath() const\r
187 {\r
188     return m_dir.absolutePath();\r
189 }\r
190 \r
191 inline void FolderModel::setActive()\r
192 {\r
193     m_activeModel = this;\r
194 }\r
195 \r
196 inline void FolderModel::setError(const QString &error)\r
197 {\r
198     m_error = error;\r
199 }\r
200 \r
201 inline void FolderModel::setFilter(QDir::Filters filters)\r
202 {\r
203     m_dir.setFilter(filters);\r
204 }\r
205 \r
206 inline void FolderModel::setSorting(QDir::SortFlags sort)\r
207 {\r
208     m_dir.setSorting(sort);\r
209 }\r
210 \r
211 inline void FolderModel::setNameFilters(const QStringList &nameFiltes)\r
212 {\r
213     m_dir.setNameFilters(nameFiltes);\r
214 }\r
215 \r
216 inline QDir::SortFlags FolderModel::sorting() const\r
217 {\r
218     return m_dir.sorting();\r
219 }\r
220 \r
221 inline void FolderModel::fsWatcher_directoryChanged(const QString &path)\r
222 {\r
223     Q_UNUSED(path);\r
224     refresh();\r
225 }\r
226 \r
227 inline const QBrush& FolderModel::base() const\r
228 {\r
229     return m_Palette.base();\r
230 }\r
231 inline const QBrush& FolderModel::text() const\r
232 {\r
233     return m_Palette.text();\r
234 }\r
235 inline const QBrush& FolderModel::marked() const\r
236 {\r
237     return m_Palette.highlight();\r
238 }\r
239 inline const QBrush& FolderModel::markedText() const\r
240 {\r
241     return m_Palette.highlightedText();\r
242 }\r
243 inline const QBrush& FolderModel::hidden() const\r
244 {\r
245     return m_Palette.dark();\r
246 }\r
247 inline const QBrush& FolderModel::readOnly() const\r
248 {\r
249     return m_Palette.light();\r
250 }\r
251 inline const QBrush& FolderModel::system() const\r
252 {\r
253     return m_Palette.mid();\r
254 }\r
255 #endif // FOLDERMODEL_H\r