Changeset View
Changeset View
Standalone View
Standalone View
sidebar/tree_module/tree_module.cpp
Show All 15 Lines | 1 | /* | |||
---|---|---|---|---|---|
16 | along with this library; see the file COPYING.LIB. If not, write to | 16 | along with this library; see the file COPYING.LIB. If not, write to | ||
17 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 17 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
18 | Boston, MA 02110-1301, USA. | 18 | Boston, MA 02110-1301, USA. | ||
19 | */ | 19 | */ | ||
20 | 20 | | |||
21 | /* | 21 | /* | ||
22 | 22 | | |||
23 | TODO: | 23 | TODO: | ||
24 | -sidepanel not triggering changes in session properly | ||||
25 | -"Configure sidebar" > "Add new" has no option to actually add anything there | ||||
24 | -places panel does not respond to view location changes | 26 | -places panel does not respond to view location changes | ||
25 | -detect icon size for places panel | 27 | -detect icon size for places panel | ||
28 | -doubleclick on image (to open kuickview) causes sidebar to deselect | ||||
29 | | ||||
30 | -"View mode" to "sidebar" causes crash and ruins session -- cannot undo | ||||
31 | | ||||
26 | 32 | | |||
27 | BUGS: | 33 | BUGS: | ||
28 | -(konq bug) sftp cannot save file being edited, because: "A file named sftp://hostname/path/to/file already exists." | 34 | -(konq bug) sftp cannot save file being edited, because: "A file named sftp://hostname/path/to/file already exists." | ||
29 | maybe: https://phabricator.kde.org/D23384 , or https://phabricator.kde.org/D15318 | 35 | maybe: https://phabricator.kde.org/D23384 , or https://phabricator.kde.org/D15318 | ||
30 | -(konq bug) loading session from cmdline causes crash, but not when konq is loaded fresh | 36 | -(konq bug) loading session from cmdline causes crash, but not when konq is loaded fresh | ||
31 | 37 | | |||
32 | */ | 38 | */ | ||
33 | 39 | | |||
Show All 14 Lines | |||||
48 | 54 | | |||
49 | KonqSideBarTreeModule::KonqSideBarTreeModule(QWidget *parent, | 55 | KonqSideBarTreeModule::KonqSideBarTreeModule(QWidget *parent, | ||
50 | const KConfigGroup &configGroup) | 56 | const KConfigGroup &configGroup) | ||
51 | : KonqSidebarModule(parent, configGroup) | 57 | : KonqSidebarModule(parent, configGroup) | ||
52 | { | 58 | { | ||
53 | m_initURL = cleanupURL(QUrl(configGroup.readPathEntry("URL", QString()))); // because the .desktop file url might be "~" | 59 | m_initURL = cleanupURL(QUrl(configGroup.readPathEntry("URL", QString()))); // because the .desktop file url might be "~" | ||
54 | treeView = new QTreeView(parent); | 60 | treeView = new QTreeView(parent); | ||
55 | treeView->setHeaderHidden(true); | 61 | treeView->setHeaderHidden(true); | ||
56 | treeView->header()->setStretchLastSection(false); | 62 | treeView->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded); | ||
57 | treeView->header()->setSectionResizeMode(QHeaderView::ResizeToContents); | 63 | treeView->setTextElideMode(Qt::ElideMiddle); | ||
58 | 64 | | |||
59 | model = new KDirModel(this); | 65 | model = new KDirModel(this); | ||
60 | sorted_model = new KDirSortFilterProxyModel(this); | 66 | sorted_model = new KDirSortFilterProxyModel(this); | ||
61 | sorted_model->setSortFoldersFirst(true); | 67 | sorted_model->setSortFoldersFirst(true); | ||
62 | sorted_model->setSourceModel(model); | 68 | sorted_model->setSourceModel(model); | ||
63 | model->dirLister()->setDirOnlyMode(true); | 69 | model->dirLister()->setDirOnlyMode(true); | ||
70 | model->dirLister()->setShowingDotFiles(configGroup.readEntry("ShowHiddenFolders", false)); | ||||
64 | 71 | | |||
65 | model->openUrl(m_initURL, KDirModel::ShowRoot); | 72 | model->openUrl(m_initURL, KDirModel::ShowRoot); | ||
66 | 73 | | |||
67 | treeView->setModel(sorted_model); | 74 | treeView->setModel(sorted_model); | ||
68 | 75 | | |||
69 | for (int i = 1; i <= 6; i++) { | 76 | for (int i = 1; i <= 6; i++) { | ||
dfaure: Please don't add dead code. | |||||
Yeah this was by mistake, I somehow missed it while doing code cleanup and only realized it was still in after I had already submitted the new commit. rrosch: Yeah this was by mistake, I somehow missed it while doing code cleanup and only realized it was… | |||||
70 | treeView->setColumnHidden(i, true); | 77 | treeView->setColumnHidden(i, true); | ||
71 | } | 78 | } | ||
72 | 79 | | |||
80 | connect(treeView, &QTreeView::expanded, | ||||
81 | this, &KonqSideBarTreeModule::slotUpdateColWidth); | ||||
82 | connect(treeView, &QTreeView::collapsed, | ||||
83 | this, &KonqSideBarTreeModule::slotUpdateColWidth); | ||||
84 | | ||||
73 | model->expandToUrl(m_initURL); // KDirModel is async, we'll just have to wait for slotKDirCompleted() | 85 | model->expandToUrl(m_initURL); // KDirModel is async, we'll just have to wait for slotKDirCompleted() | ||
74 | connect(model, &KDirModel::expand, | 86 | connect(model, &KDirModel::expand, | ||
75 | this, &KonqSideBarTreeModule::slotKDirExpand_setRootIndex); | 87 | this, &KonqSideBarTreeModule::slotKDirExpand_setRootIndex); | ||
76 | 88 | | |||
77 | QItemSelectionModel *selectionModel = treeView->selectionModel(); | 89 | QItemSelectionModel *selectionModel = treeView->selectionModel(); | ||
78 | connect(selectionModel, &QItemSelectionModel::selectionChanged, | 90 | connect(selectionModel, &QItemSelectionModel::selectionChanged, | ||
79 | this, &KonqSideBarTreeModule::slotSelectionChanged); | 91 | this, &KonqSideBarTreeModule::slotSelectionChanged); | ||
80 | } | 92 | } | ||
▲ Show 20 Lines • Show All 81 Lines • ▼ Show 20 Line(s) | |||||
162 | void KonqSideBarTreeModule::slotSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected) | 174 | void KonqSideBarTreeModule::slotSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected) | ||
163 | { | 175 | { | ||
164 | QModelIndex index = treeView->selectionModel()->currentIndex(); | 176 | QModelIndex index = treeView->selectionModel()->currentIndex(); | ||
165 | 177 | | |||
166 | QUrl urlFromIndex = getUrlFromIndex(index); | 178 | QUrl urlFromIndex = getUrlFromIndex(index); | ||
167 | if (index.isValid() && m_lastURL != urlFromIndex) { | 179 | if (index.isValid() && m_lastURL != urlFromIndex) { | ||
168 | emit openUrlRequest(urlFromIndex); | 180 | emit openUrlRequest(urlFromIndex); | ||
169 | } | 181 | } | ||
182 | slotUpdateColWidth(); | ||||
170 | } | 183 | } | ||
171 | 184 | | |||
185 | // needed because when there is only one column, QTreeView does not trigger resize | ||||
186 | void KonqSideBarTreeModule::slotUpdateColWidth() | ||||
187 | { | ||||
188 | treeView->resizeColumnToContents(0); | ||||
189 | } | ||||
172 | 190 | | |||
173 | // needed because KDirModel is async | 191 | // needed because KDirModel is async | ||
174 | void KonqSideBarTreeModule::slotKDirExpand_setRootIndex() | 192 | void KonqSideBarTreeModule::slotKDirExpand_setRootIndex() | ||
175 | { | 193 | { | ||
176 | QModelIndex index = getIndexFromUrl(m_initURL); | 194 | QModelIndex index = getIndexFromUrl(m_initURL); | ||
177 | if (index.isValid()) { | 195 | if (index.isValid()) { | ||
178 | disconnect(model, &KDirModel::expand, | 196 | disconnect(model, &KDirModel::expand, | ||
179 | this, &KonqSideBarTreeModule::slotKDirExpand_setRootIndex); | 197 | this, &KonqSideBarTreeModule::slotKDirExpand_setRootIndex); | ||
180 | treeView->setRootIndex(index.parent()); | 198 | treeView->setRootIndex(index.parent()); | ||
181 | treeView->expand(index); | 199 | treeView->expand(index); | ||
182 | } | 200 | } | ||
183 | } | 201 | } | ||
184 | 202 | | |||
185 | void KonqSideBarTreeModule::slotKDirExpand_setSelection(const QModelIndex &index) | 203 | void KonqSideBarTreeModule::slotKDirExpand_setSelection(const QModelIndex &index) | ||
186 | { | 204 | { | ||
187 | QUrl urlFromIndex = getUrlFromIndex(index); // these are only going to be valid | 205 | QUrl urlFromIndex = getUrlFromIndex(index); // these are only going to be valid | ||
188 | if (urlFromIndex == m_lastURL) { | 206 | if (urlFromIndex == m_lastURL) { | ||
189 | disconnect(model, &KDirModel::expand, | 207 | disconnect(model, &KDirModel::expand, | ||
190 | this, &KonqSideBarTreeModule::slotKDirExpand_setSelection); | 208 | this, &KonqSideBarTreeModule::slotKDirExpand_setSelection); | ||
191 | setSelection(m_lastURL, false); | 209 | setSelection(m_lastURL, false); | ||
192 | } | 210 | } | ||
211 | slotUpdateColWidth(); | ||||
193 | } | 212 | } | ||
194 | 213 | | |||
195 | 214 | | |||
196 | // resolves index to the correct model (due to use of KDirSortFilterProxyModel) | 215 | // resolves index to the correct model (due to use of KDirSortFilterProxyModel) | ||
197 | QModelIndex KonqSideBarTreeModule::resolveIndex(const QModelIndex &index) | 216 | QModelIndex KonqSideBarTreeModule::resolveIndex(const QModelIndex &index) | ||
198 | { | 217 | { | ||
199 | if (index.isValid() && index.model() != model && model != nullptr) { | 218 | if (index.isValid() && index.model() != model && model != nullptr) { | ||
200 | return static_cast<const KDirSortFilterProxyModel*>(index.model())->mapToSource(index); | 219 | return static_cast<const KDirSortFilterProxyModel*>(index.model())->mapToSource(index); | ||
Show All 11 Lines | 229 | if (index.isValid()) { | |||
212 | if (!itemForIndex.isNull()) { | 231 | if (!itemForIndex.isNull()) { | ||
213 | resolvedUrl = itemForIndex.url(); | 232 | resolvedUrl = itemForIndex.url(); | ||
214 | } | 233 | } | ||
215 | } | 234 | } | ||
216 | 235 | | |||
217 | return resolvedUrl; | 236 | return resolvedUrl; | ||
218 | } | 237 | } | ||
219 | 238 | | |||
220 | const QModelIndex KonqSideBarTreeModule::getIndexFromUrl(const QUrl &url) | 239 | QModelIndex KonqSideBarTreeModule::getIndexFromUrl(const QUrl &url) const | ||
221 | { | 240 | { | ||
222 | return sorted_model->mapFromSource(model->indexForUrl(url)); | 241 | return sorted_model->mapFromSource(model->indexForUrl(url)); | ||
223 | } | 242 | } | ||
224 | 243 | | |||
225 | 244 | | |||
226 | class KonqSidebarTreePlugin : public KonqSidebarPlugin | 245 | class KonqSidebarTreePlugin : public KonqSidebarPlugin | ||
227 | { | 246 | { | ||
228 | public: | 247 | public: | ||
▲ Show 20 Lines • Show All 55 Lines • Show Last 20 Lines |
Please don't add dead code.