Changeset View
Changeset View
Standalone View
Standalone View
src/panels/folders/folderspanel.cpp
Show All 22 Lines | |||||
23 | #include "dolphin_generalsettings.h" | 23 | #include "dolphin_generalsettings.h" | ||
24 | #include "foldersitemlistwidget.h" | 24 | #include "foldersitemlistwidget.h" | ||
25 | #include "global.h" | 25 | #include "global.h" | ||
26 | #include "kitemviews/kfileitemlistview.h" | 26 | #include "kitemviews/kfileitemlistview.h" | ||
27 | #include "kitemviews/kfileitemmodel.h" | 27 | #include "kitemviews/kfileitemmodel.h" | ||
28 | #include "kitemviews/kitemlistcontainer.h" | 28 | #include "kitemviews/kitemlistcontainer.h" | ||
29 | #include "kitemviews/kitemlistcontroller.h" | 29 | #include "kitemviews/kitemlistcontroller.h" | ||
30 | #include "kitemviews/kitemlistselectionmanager.h" | 30 | #include "kitemviews/kitemlistselectionmanager.h" | ||
31 | #include "treeviewcontextmenu.h" | | |||
32 | #include "views/draganddrophelper.h" | 31 | #include "views/draganddrophelper.h" | ||
33 | 32 | | |||
34 | #include <KJobWidgets> | 33 | #include <KJobWidgets> | ||
35 | #include <KJobUiDelegate> | 34 | #include <KJobUiDelegate> | ||
36 | #include <KIO/CopyJob> | 35 | #include <KIO/CopyJob> | ||
37 | #include <KIO/DropJob> | 36 | #include <KIO/DropJob> | ||
38 | #include <KIO/FileUndoManager> | 37 | #include <KIO/FileUndoManager> | ||
39 | #include <KIO/RenameFileDialog> | 38 | #include <KIO/RenameFileDialog> | ||
39 | #include <KLocalizedString> | ||||
40 | #include <QAction> | ||||
41 | #include <QMenu> | ||||
40 | 42 | | |||
41 | #include <QApplication> | 43 | #include <QApplication> | ||
42 | #include <QBoxLayout> | 44 | #include <QBoxLayout> | ||
43 | #include <QGraphicsSceneDragDropEvent> | 45 | #include <QGraphicsSceneDragDropEvent> | ||
44 | #include <QGraphicsView> | 46 | #include <QGraphicsView> | ||
45 | #include <QPropertyAnimation> | 47 | #include <QPropertyAnimation> | ||
46 | #include <QTimer> | 48 | #include <QTimer> | ||
47 | 49 | | |||
▲ Show 20 Lines • Show All 127 Lines • ▼ Show 20 Line(s) | 144 | if (!m_controller) { | |||
175 | connect(m_controller, &KItemListController::itemDropEvent, this, &FoldersPanel::slotItemDropEvent); | 177 | connect(m_controller, &KItemListController::itemDropEvent, this, &FoldersPanel::slotItemDropEvent); | ||
176 | 178 | | |||
177 | KItemListContainer* container = new KItemListContainer(m_controller, this); | 179 | KItemListContainer* container = new KItemListContainer(m_controller, this); | ||
178 | container->setEnabledFrame(false); | 180 | container->setEnabledFrame(false); | ||
179 | 181 | | |||
180 | QVBoxLayout* layout = new QVBoxLayout(this); | 182 | QVBoxLayout* layout = new QVBoxLayout(this); | ||
181 | layout->setContentsMargins(0, 0, 0, 0); | 183 | layout->setContentsMargins(0, 0, 0, 0); | ||
182 | layout->addWidget(container); | 184 | layout->addWidget(container); | ||
185 | container->installEventFilter(this); | ||||
183 | } | 186 | } | ||
184 | 187 | | |||
185 | loadTree(url()); | 188 | loadTree(url()); | ||
186 | Panel::showEvent(event); | 189 | Panel::showEvent(event); | ||
187 | } | 190 | } | ||
188 | 191 | | |||
189 | void FoldersPanel::keyPressEvent(QKeyEvent* event) | 192 | void FoldersPanel::keyPressEvent(QKeyEvent* event) | ||
190 | { | 193 | { | ||
191 | const int key = event->key(); | 194 | const int key = event->key(); | ||
192 | if ((key == Qt::Key_Enter) || (key == Qt::Key_Return)) { | 195 | if ((key == Qt::Key_Enter) || (key == Qt::Key_Return)) { | ||
193 | event->accept(); | 196 | event->accept(); | ||
194 | } else { | 197 | } else { | ||
195 | Panel::keyPressEvent(event); | 198 | Panel::keyPressEvent(event); | ||
196 | } | 199 | } | ||
197 | } | 200 | } | ||
198 | 201 | | |||
202 | /** Activates the view if the item list container gets focus. */ | ||||
203 | bool FoldersPanel::eventFilter(QObject* watched, QEvent* event) | ||||
204 | { | ||||
205 | Q_UNUSED(watched) | ||||
206 | switch (event->type()) { | ||||
207 | case QEvent::FocusOut: | ||||
208 | focusedOut(); | ||||
209 | break; | ||||
210 | case QEvent::FocusIn: | ||||
211 | focused(); | ||||
212 | break; | ||||
213 | default: | ||||
214 | break; | ||||
215 | } | ||||
216 | return false; | ||||
217 | } | ||||
218 | | ||||
219 | KItemListSelectionManager* FoldersPanel::selectionManager() | ||||
220 | { | ||||
221 | return m_controller->selectionManager(); | ||||
222 | } | ||||
223 | | ||||
224 | KFileItemListView* FoldersPanel::view() | ||||
225 | { | ||||
226 | return qobject_cast<KFileItemListView *>(m_controller->view()); | ||||
227 | } | ||||
228 | | ||||
199 | void FoldersPanel::slotItemActivated(int index) | 229 | void FoldersPanel::slotItemActivated(int index) | ||
200 | { | 230 | { | ||
201 | const KFileItem item = m_model->fileItem(index); | 231 | const KFileItem item = m_model->fileItem(index); | ||
202 | if (!item.isNull()) { | 232 | if (!item.isNull()) { | ||
203 | emit folderActivated(item.url()); | 233 | emit folderActivated(item.url()); | ||
204 | } | 234 | } | ||
205 | } | 235 | } | ||
206 | 236 | | |||
207 | void FoldersPanel::slotItemMiddleClicked(int index) | 237 | void FoldersPanel::slotItemMiddleClicked(int index) | ||
208 | { | 238 | { | ||
209 | const KFileItem item = m_model->fileItem(index); | 239 | const KFileItem item = m_model->fileItem(index); | ||
210 | if (!item.isNull()) { | 240 | if (!item.isNull()) { | ||
211 | emit folderMiddleClicked(item.url()); | 241 | emit folderMiddleClicked(item.url()); | ||
212 | } | 242 | } | ||
213 | } | 243 | } | ||
214 | 244 | | |||
245 | QList<QAction *> FoldersPanel::folderPanelContextMenuActions() | ||||
246 | { | ||||
247 | QList<QAction *> actions; | ||||
248 | | ||||
249 | QAction* showHiddenFilesAction = new QAction(i18nc("@action:inmenu", "Show Hidden Files"), this); | ||||
250 | showHiddenFilesAction->setCheckable(true); | ||||
251 | showHiddenFilesAction->setChecked(showHiddenFiles()); | ||||
252 | actions.append(showHiddenFilesAction); | ||||
253 | connect(showHiddenFilesAction, &QAction::toggled, this, &FoldersPanel::setShowHiddenFiles); | ||||
254 | | ||||
255 | // insert 'Limit to Home Directory' | ||||
256 | QAction* limitFoldersPanelToHomeAction = new QAction(i18nc("@action:inmenu", "Limit to Home Directory"), this); | ||||
257 | limitFoldersPanelToHomeAction->setCheckable(true); | ||||
258 | limitFoldersPanelToHomeAction->setChecked(limitFoldersPanelToHome()); | ||||
259 | actions.append(limitFoldersPanelToHomeAction); | ||||
260 | connect(limitFoldersPanelToHomeAction, &QAction::toggled, this, &FoldersPanel::setLimitFoldersPanelToHome); | ||||
261 | | ||||
262 | // TODO: Temporary disabled. Horizontal autoscrolling will be implemented later either | ||||
263 | // in KItemViews or manually as part of the FoldersPanel | ||||
264 | /* | ||||
265 | // insert 'Automatic Scrolling' | ||||
266 | QAction* autoScrollingAction = new QAction(i18nc("@action:inmenu", "Automatic Scrolling"), this); | ||||
267 | autoScrollingAction->setCheckable(true); | ||||
268 | autoScrollingAction->setChecked(autoScrolling()); | ||||
269 | connect(autoScrollingAction, &QAction::toggled, this, &FoldersPanel::setAutoScrolling); | ||||
270 | actions->addAction(autoScrollingAction); | ||||
271 | */ | ||||
272 | | ||||
273 | const QList<QAction*> customActions = customContextMenuActions(); | ||||
274 | if (!customActions.isEmpty()) { | ||||
275 | QAction *separatorAction = new QAction(); | ||||
276 | separatorAction->setSeparator(true); | ||||
277 | actions.append(separatorAction); | ||||
278 | for (QAction* action: customActions) { | ||||
279 | actions.append(action); | ||||
280 | } | ||||
281 | } | ||||
282 | | ||||
283 | return actions; | ||||
284 | } | ||||
285 | | ||||
215 | void FoldersPanel::slotItemContextMenuRequested(int index, const QPointF& pos) | 286 | void FoldersPanel::slotItemContextMenuRequested(int index, const QPointF& pos) | ||
216 | { | 287 | { | ||
217 | const KFileItem fileItem = m_model->fileItem(index); | 288 | const KFileItem fileItem = m_model->fileItem(index); | ||
218 | 289 | | |||
219 | QPointer<TreeViewContextMenu> contextMenu = new TreeViewContextMenu(this, fileItem); | 290 | const auto view = qobject_cast<KFileItemListView *>(m_controller->view()); | ||
220 | contextMenu.data()->open(pos.toPoint()); | 291 | requestOpenContextMenu(pos.toPoint(), fileItem, fileItem.url(), folderPanelContextMenuActions(), m_controller->selectionManager(), view); | ||
221 | if (contextMenu.data()) { | | |||
222 | delete contextMenu.data(); | | |||
223 | } | | |||
224 | } | 292 | } | ||
225 | 293 | | |||
226 | void FoldersPanel::slotViewContextMenuRequested(const QPointF& pos) | 294 | void FoldersPanel::slotViewContextMenuRequested(const QPointF& pos) | ||
227 | { | 295 | { | ||
228 | QPointer<TreeViewContextMenu> contextMenu = new TreeViewContextMenu(this, KFileItem()); | 296 | QMenu* popup = new QMenu(this); | ||
229 | contextMenu.data()->open(pos.toPoint()); | 297 | popup->addActions(folderPanelContextMenuActions()); | ||
230 | if (contextMenu.data()) { | 298 | | ||
231 | delete contextMenu.data(); | 299 | QPointer<QMenu> popupPtr = popup; | ||
300 | popup->exec(pos.toPoint()); | ||||
301 | if (popupPtr.data()) { | ||||
302 | popupPtr.data()->deleteLater(); | ||||
232 | } | 303 | } | ||
233 | } | 304 | } | ||
234 | 305 | | |||
235 | void FoldersPanel::slotItemDropEvent(int index, QGraphicsSceneDragDropEvent* event) | 306 | void FoldersPanel::slotItemDropEvent(int index, QGraphicsSceneDragDropEvent* event) | ||
236 | { | 307 | { | ||
237 | if (index >= 0) { | 308 | if (index >= 0) { | ||
238 | KFileItem destItem = m_model->fileItem(index); | 309 | KFileItem destItem = m_model->fileItem(index); | ||
239 | if (destItem.isNull()) { | 310 | if (destItem.isNull()) { | ||
▲ Show 20 Lines • Show All 124 Lines • Show Last 20 Lines |