Changeset View
Changeset View
Standalone View
Standalone View
krusader/Panel/krinterview.cpp
Show All 13 Lines | |||||
14 | * GNU General Public License for more details. * | 14 | * GNU General Public License for more details. * | ||
15 | * * | 15 | * * | ||
16 | * You should have received a copy of the GNU General Public License * | 16 | * You should have received a copy of the GNU General Public License * | ||
17 | * along with this package; if not, write to the Free Software * | 17 | * along with this package; if not, write to the Free Software * | ||
18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * | 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * | ||
19 | *****************************************************************************/ | 19 | *****************************************************************************/ | ||
20 | 20 | | |||
21 | #include "krinterview.h" | 21 | #include "krinterview.h" | ||
22 | #include "krvfsmodel.h" | 22 | | ||
23 | #include "krinterviewitem.h" | | |||
24 | #include "krcolorcache.h" | 23 | #include "krcolorcache.h" | ||
25 | #include "krmousehandler.h" | 24 | #include "krmousehandler.h" | ||
26 | #include "krpreviews.h" | 25 | #include "krpreviews.h" | ||
26 | #include "krvfsmodel.h" | ||||
27 | #include "krviewitem.h" | ||||
27 | #include "../VFS/vfilecontainer.h" | 28 | #include "../VFS/vfilecontainer.h" | ||
28 | 29 | | |||
29 | KrInterView::KrInterView(KrViewInstance &instance, KConfig *cfg, | 30 | KrInterView::KrInterView(KrViewInstance &instance, KConfig *cfg, | ||
30 | QAbstractItemView *itemView) : | 31 | QAbstractItemView *itemView) : | ||
31 | KrView(instance, cfg), _itemView(itemView), _mouseHandler(0) | 32 | KrView(instance, cfg), _itemView(itemView), _mouseHandler(0) | ||
32 | { | 33 | { | ||
33 | _model = new KrVfsModel(this); | 34 | _model = new KrVfsModel(this); | ||
34 | 35 | | |||
35 | // fix the context menu problem | 36 | // fix the context menu problem | ||
36 | int j = QFontMetrics(_itemView->font()).height() * 2; | 37 | int j = QFontMetrics(_itemView->font()).height() * 2; | ||
37 | _mouseHandler = new KrMouseHandler(this, j); | 38 | _mouseHandler = new KrMouseHandler(this, j); | ||
38 | } | 39 | } | ||
39 | 40 | | |||
40 | KrInterView::~KrInterView() | 41 | KrInterView::~KrInterView() | ||
41 | { | 42 | { | ||
42 | // any references to the model should be cleared ar this point, | 43 | // any references to the model should be cleared ar this point, | ||
43 | // but sometimes for some reason it is still referenced by | 44 | // but sometimes for some reason it is still referenced by | ||
44 | // QPersistentModelIndex instances held by QAbstractItemView and/or QItemSelectionModel(child object) - | 45 | // QPersistentModelIndex instances held by QAbstractItemView and/or QItemSelectionModel(child object) - | ||
45 | // so schedule _model for later deletion | 46 | // so schedule _model for later deletion | ||
46 | _model->clear(); | 47 | _model->clear(); | ||
47 | _model->deleteLater(); | 48 | _model->deleteLater(); | ||
48 | _model = 0; | 49 | _model = 0; | ||
49 | delete _mouseHandler; | 50 | delete _mouseHandler; | ||
50 | _mouseHandler = 0; | 51 | _mouseHandler = 0; | ||
51 | QHashIterator< vfile *, KrInterViewItem *> it(_itemHash); | 52 | QHashIterator< vfile *, KrViewItem *> it(_itemHash); | ||
52 | while (it.hasNext()) | 53 | while (it.hasNext()) | ||
53 | delete it.next().value(); | 54 | delete it.next().value(); | ||
54 | _itemHash.clear(); | 55 | _itemHash.clear(); | ||
55 | } | 56 | } | ||
56 | 57 | | |||
57 | void KrInterView::selectRegion(KrViewItem *i1, KrViewItem *i2, bool select) | 58 | void KrInterView::selectRegion(KrViewItem *i1, KrViewItem *i2, bool select) | ||
58 | { | 59 | { | ||
59 | vfile* vf1 = (vfile *)i1->getVfile(); | 60 | vfile* vf1 = (vfile *)i1->getVfile(); | ||
Show All 40 Lines | |||||
100 | KrViewItem* KrInterView::findItemByName(const QString &name) | 101 | KrViewItem* KrInterView::findItemByName(const QString &name) | ||
101 | { | 102 | { | ||
102 | if (!_model->ready()) | 103 | if (!_model->ready()) | ||
103 | return 0; | 104 | return 0; | ||
104 | 105 | | |||
105 | QModelIndex ndx = _model->nameIndex(name); | 106 | QModelIndex ndx = _model->nameIndex(name); | ||
106 | if (!ndx.isValid()) | 107 | if (!ndx.isValid()) | ||
107 | return 0; | 108 | return 0; | ||
108 | return getKrInterViewItem(ndx); | 109 | return getKrViewItem(ndx); | ||
109 | } | 110 | } | ||
110 | 111 | | |||
111 | QString KrInterView::getCurrentItem() const | 112 | QString KrInterView::getCurrentItem() const | ||
112 | { | 113 | { | ||
113 | if (!_model->ready()) | 114 | if (!_model->ready()) | ||
114 | return QString(); | 115 | return QString(); | ||
115 | 116 | | |||
116 | vfile *vf = _model->vfileAt(_itemView->currentIndex()); | 117 | vfile *vf = _model->vfileAt(_itemView->currentIndex()); | ||
117 | if (vf == 0) | 118 | if (vf == 0) | ||
118 | return QString(); | 119 | return QString(); | ||
119 | return vf->vfile_getName(); | 120 | return vf->vfile_getName(); | ||
120 | } | 121 | } | ||
121 | 122 | | |||
122 | KrViewItem* KrInterView::getCurrentKrViewItem() | 123 | KrViewItem* KrInterView::getCurrentKrViewItem() | ||
123 | { | 124 | { | ||
124 | if (!_model->ready()) | 125 | if (!_model->ready()) | ||
125 | return 0; | 126 | return 0; | ||
126 | 127 | | |||
127 | return getKrInterViewItem(_itemView->currentIndex()); | 128 | return getKrViewItem(_itemView->currentIndex()); | ||
128 | } | 129 | } | ||
129 | 130 | | |||
130 | KrViewItem* KrInterView::getFirst() | 131 | KrViewItem* KrInterView::getFirst() | ||
131 | { | 132 | { | ||
132 | if (!_model->ready()) | 133 | if (!_model->ready()) | ||
133 | return 0; | 134 | return 0; | ||
134 | 135 | | |||
135 | return getKrInterViewItem(_model->index(0, 0, QModelIndex())); | 136 | return getKrViewItem(_model->index(0, 0, QModelIndex())); | ||
136 | } | 137 | } | ||
137 | 138 | | |||
138 | KrViewItem* KrInterView::getLast() | 139 | KrViewItem* KrInterView::getLast() | ||
139 | { | 140 | { | ||
140 | if (!_model->ready()) | 141 | if (!_model->ready()) | ||
141 | return 0; | 142 | return 0; | ||
142 | 143 | | |||
143 | return getKrInterViewItem(_model->index(_model->rowCount() - 1, 0, QModelIndex())); | 144 | return getKrViewItem(_model->index(_model->rowCount() - 1, 0, QModelIndex())); | ||
144 | } | 145 | } | ||
145 | 146 | | |||
146 | KrViewItem* KrInterView::getNext(KrViewItem *current) | 147 | KrViewItem* KrInterView::getNext(KrViewItem *current) | ||
147 | { | 148 | { | ||
148 | vfile* vf = (vfile *)current->getVfile(); | 149 | vfile* vf = (vfile *)current->getVfile(); | ||
149 | QModelIndex ndx = _model->vfileIndex(vf); | 150 | QModelIndex ndx = _model->vfileIndex(vf); | ||
150 | if (ndx.row() >= _model->rowCount() - 1) | 151 | if (ndx.row() >= _model->rowCount() - 1) | ||
151 | return 0; | 152 | return 0; | ||
152 | return getKrInterViewItem(_model->index(ndx.row() + 1, 0, QModelIndex())); | 153 | return getKrViewItem(_model->index(ndx.row() + 1, 0, QModelIndex())); | ||
153 | } | 154 | } | ||
154 | 155 | | |||
155 | KrViewItem* KrInterView::getPrev(KrViewItem *current) | 156 | KrViewItem* KrInterView::getPrev(KrViewItem *current) | ||
156 | { | 157 | { | ||
157 | vfile* vf = (vfile *)current->getVfile(); | 158 | vfile* vf = (vfile *)current->getVfile(); | ||
158 | QModelIndex ndx = _model->vfileIndex(vf); | 159 | QModelIndex ndx = _model->vfileIndex(vf); | ||
159 | if (ndx.row() <= 0) | 160 | if (ndx.row() <= 0) | ||
160 | return 0; | 161 | return 0; | ||
161 | return getKrInterViewItem(_model->index(ndx.row() - 1, 0, QModelIndex())); | 162 | return getKrViewItem(_model->index(ndx.row() - 1, 0, QModelIndex())); | ||
162 | } | 163 | } | ||
163 | 164 | | |||
164 | KrViewItem* KrInterView::getKrViewItemAt(const QPoint &vp) | 165 | KrViewItem* KrInterView::getKrViewItemAt(const QPoint &vp) | ||
165 | { | 166 | { | ||
166 | if (!_model->ready()) | 167 | if (!_model->ready()) | ||
167 | return 0; | 168 | return 0; | ||
168 | 169 | | |||
169 | return getKrInterViewItem(_itemView->indexAt(vp)); | 170 | return getKrViewItem(_itemView->indexAt(vp)); | ||
170 | } | 171 | } | ||
171 | 172 | | |||
172 | KrViewItem *KrInterView::findItemByVfile(vfile *vf) { | 173 | KrViewItem *KrInterView::findItemByVfile(vfile *vf) { | ||
173 | return getKrInterViewItem(vf); | 174 | return getKrViewItem(vf); | ||
174 | } | 175 | } | ||
175 | 176 | | |||
176 | KrInterViewItem * KrInterView::getKrInterViewItem(vfile *vf) | 177 | KrViewItem * KrInterView::getKrViewItem(vfile *vf) | ||
177 | { | 178 | { | ||
178 | QHash<vfile *, KrInterViewItem*>::iterator it = _itemHash.find(vf); | 179 | QHash<vfile *, KrViewItem*>::iterator it = _itemHash.find(vf); | ||
179 | if (it == _itemHash.end()) { | 180 | if (it == _itemHash.end()) { | ||
180 | KrInterViewItem * newItem = new KrInterViewItem(this, vf); | 181 | KrViewItem * newItem = new KrViewItem(vf, this); | ||
181 | _itemHash[ vf ] = newItem; | 182 | _itemHash[ vf ] = newItem; | ||
182 | return newItem; | 183 | return newItem; | ||
183 | } | 184 | } | ||
184 | return *it; | 185 | return *it; | ||
185 | } | 186 | } | ||
186 | 187 | | |||
187 | KrInterViewItem * KrInterView::getKrInterViewItem(const QModelIndex & ndx) | 188 | KrViewItem * KrInterView::getKrViewItem(const QModelIndex & ndx) | ||
188 | { | 189 | { | ||
189 | if (!ndx.isValid()) | 190 | if (!ndx.isValid()) | ||
190 | return 0; | 191 | return 0; | ||
191 | vfile * vf = _model->vfileAt(ndx); | 192 | vfile * vf = _model->vfileAt(ndx); | ||
192 | if (vf == 0) | 193 | if (vf == 0) | ||
193 | return 0; | 194 | return 0; | ||
194 | else | 195 | else | ||
195 | return getKrInterViewItem(vf); | 196 | return getKrViewItem(vf); | ||
196 | } | 197 | } | ||
197 | 198 | | |||
198 | void KrInterView::makeCurrentVisible() | 199 | void KrInterView::makeCurrentVisible() | ||
199 | { | 200 | { | ||
200 | _itemView->scrollTo(_itemView->currentIndex()); | 201 | _itemView->scrollTo(_itemView->currentIndex()); | ||
201 | } | 202 | } | ||
202 | 203 | | |||
203 | void KrInterView::makeItemVisible(const KrViewItem *item) | 204 | void KrInterView::makeItemVisible(const KrViewItem *item) | ||
Show All 39 Lines | |||||
243 | } | 244 | } | ||
244 | 245 | | |||
245 | void KrInterView::clear() | 246 | void KrInterView::clear() | ||
246 | { | 247 | { | ||
247 | _selection.clear(); | 248 | _selection.clear(); | ||
248 | _itemView->clearSelection(); | 249 | _itemView->clearSelection(); | ||
249 | _itemView->setCurrentIndex(QModelIndex()); | 250 | _itemView->setCurrentIndex(QModelIndex()); | ||
250 | _model->clear(); | 251 | _model->clear(); | ||
251 | QHashIterator< vfile *, KrInterViewItem *> it(_itemHash); | 252 | QHashIterator< vfile *, KrViewItem *> it(_itemHash); | ||
252 | while (it.hasNext()) | 253 | while (it.hasNext()) | ||
253 | delete it.next().value(); | 254 | delete it.next().value(); | ||
254 | _itemHash.clear(); | 255 | _itemHash.clear(); | ||
255 | 256 | | |||
256 | KrView::clear(); | 257 | KrView::clear(); | ||
257 | } | 258 | } | ||
258 | 259 | | |||
259 | void KrInterView::populate(const QList<vfile*> &vfiles, vfile *dummy) | 260 | void KrInterView::populate(const QList<vfile*> &vfiles, vfile *dummy) | ||
260 | { | 261 | { | ||
261 | _model->populate(vfiles, dummy); | 262 | _model->populate(vfiles, dummy); | ||
262 | _itemView->setCurrentIndex(_model->index(0, 0)); | 263 | _itemView->setCurrentIndex(_model->index(0, 0)); | ||
263 | } | 264 | } | ||
264 | 265 | | |||
265 | KrViewItem* KrInterView::preAddItem(vfile *vf) | 266 | KrViewItem* KrInterView::preAddItem(vfile *vf) | ||
266 | { | 267 | { | ||
267 | QModelIndex idx = _model->addItem(vf); | 268 | QModelIndex idx = _model->addItem(vf); | ||
268 | if(_model->rowCount() == 1) // if this is the fist item to be added, make it current | 269 | if(_model->rowCount() == 1) // if this is the fist item to be added, make it current | ||
269 | _itemView->setCurrentIndex(idx); | 270 | _itemView->setCurrentIndex(idx); | ||
270 | return getKrInterViewItem(idx); | 271 | return getKrViewItem(idx); | ||
271 | } | 272 | } | ||
272 | 273 | | |||
273 | void KrInterView::preDelItem(KrViewItem *item) | 274 | void KrInterView::preDelItem(KrViewItem *item) | ||
274 | { | 275 | { | ||
275 | setSelected(item->getVfile(), false); | 276 | setSelected(item->getVfile(), false); | ||
276 | QModelIndex ndx = _model->removeItem((vfile *)item->getVfile()); | 277 | QModelIndex ndx = _model->removeItem((vfile *)item->getVfile()); | ||
277 | if (ndx.isValid()) | 278 | if (ndx.isValid()) | ||
278 | _itemView->setCurrentIndex(ndx); | 279 | _itemView->setCurrentIndex(ndx); | ||
▲ Show 20 Lines • Show All 96 Lines • Show Last 20 Lines |