┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src/panels
diff options
context:
space:
mode:
authorPeter Penz <[email protected]>2012-04-21 21:28:16 +0200
committerPeter Penz <[email protected]>2012-04-21 21:32:42 +0200
commitae4d11d918938fd9087f2035dac247969c1f2313 (patch)
tree0303667797c81814b46b9ed5ed20b48ef31f2d71 /src/panels
parent47d7cdffdd2d2c04067a5088eaeff67add53dde3 (diff)
Prepare view-engine for non-KFileItem usecase
Up to now the view-engine only provided a model-implementation that supports file-items. The view-engine always had been designed to be able to work with any kind of model, so now a KStandardItemModel is available. The plan is to convert the places panel to the new view-engine. It should be no problem to fix this until the feature freeze - in the worst case the places-panel code could be reverted while still keeping the KStandardItemModel changes.
Diffstat (limited to 'src/panels')
-rw-r--r--src/panels/folders/folderspanel.cpp84
-rw-r--r--src/panels/folders/folderspanel.h3
-rw-r--r--src/panels/places/placespanel.cpp66
-rw-r--r--src/panels/places/placespanel.h19
4 files changed, 85 insertions, 87 deletions
diff --git a/src/panels/folders/folderspanel.cpp b/src/panels/folders/folderspanel.cpp
index 40e5eca8d..5e8286cdc 100644
--- a/src/panels/folders/folderspanel.cpp
+++ b/src/panels/folders/folderspanel.cpp
@@ -48,7 +48,8 @@
FoldersPanel::FoldersPanel(QWidget* parent) :
Panel(parent),
m_updateCurrentItem(false),
- m_controller(0)
+ m_controller(0),
+ m_model(0)
{
setLayoutDirection(Qt::LeftToRight);
}
@@ -67,7 +68,7 @@ FoldersPanel::~FoldersPanel()
void FoldersPanel::setShowHiddenFiles(bool show)
{
FoldersPanelSettings::setHiddenFilesShown(show);
- fileItemModel()->setShowHiddenFiles(show);
+ m_model->setShowHiddenFiles(show);
}
bool FoldersPanel::showHiddenFiles() const
@@ -88,8 +89,8 @@ bool FoldersPanel::autoScrolling() const
void FoldersPanel::rename(const KFileItem& item)
{
- const int index = fileItemModel()->index(item);
- m_controller->view()->editRole(index, "name");
+ const int index = m_model->index(item);
+ m_controller->view()->editRole(index, "text");
}
bool FoldersPanel::urlChanged()
@@ -115,21 +116,10 @@ void FoldersPanel::showEvent(QShowEvent* event)
}
if (!m_controller) {
- // Postpone the creating of the dir lister to the first show event.
- // This assures that no performance and memory overhead is given when the TreeView is not
- // used at all (see FoldersPanel::setUrl()).
+ // Postpone the creating of the controller to the first show event.
+ // This assures that no performance and memory overhead is given when the folders panel is not
+ // used at all and stays invisible.
KFileItemListView* view = new KFileItemListView();
- view->setWidgetCreator(new KItemListWidgetCreator<KFileItemListWidget>());
-
- KItemListStyleOption styleOption = view->styleOption();
- styleOption.padding = 2;
- styleOption.iconSize = KIconLoader::SizeSmall;
- styleOption.extendedSelectionRegion = true;
- view->setStyleOption(styleOption);
-
- const qreal itemHeight = qMax(int(KIconLoader::SizeSmall), styleOption.fontMetrics.height());
- view->setItemSize(QSizeF(-1, itemHeight + 2 * styleOption.padding));
- view->setItemLayout(KFileItemListView::DetailsLayout);
view->setSupportsItemExpanding(true);
// Set the opacity to 0 initially. The opacity will be increased after the loading of the initial tree
// has been finished in slotLoadingCompleted(). This prevents an unnecessary animation-mess when
@@ -139,17 +129,14 @@ void FoldersPanel::showEvent(QShowEvent* event)
connect(view, SIGNAL(roleEditingFinished(int,QByteArray,QVariant)),
this, SLOT(slotRoleEditingFinished(int,QByteArray,QVariant)));
- KFileItemModel* model = new KFileItemModel(this);
- model->setShowDirectoriesOnly(true);
- model->setShowHiddenFiles(FoldersPanelSettings::hiddenFilesShown());
+ m_model = new KFileItemModel(this);
+ m_model->setShowDirectoriesOnly(true);
+ m_model->setShowHiddenFiles(FoldersPanelSettings::hiddenFilesShown());
// Use a QueuedConnection to give the view the possibility to react first on the
// finished loading.
- connect(model, SIGNAL(directoryLoadingCompleted()), this, SLOT(slotLoadingCompleted()), Qt::QueuedConnection);
+ connect(m_model, SIGNAL(directoryLoadingCompleted()), this, SLOT(slotLoadingCompleted()), Qt::QueuedConnection);
- KItemListContainer* container = new KItemListContainer(this);
- m_controller = container->controller();
- m_controller->setView(view);
- m_controller->setModel(model);
+ m_controller = new KItemListController(m_model, view, this);
m_controller->setSelectionBehavior(KItemListController::SingleSelection);
m_controller->setAutoActivationDelay(750);
m_controller->setSingleClickActivation(true);
@@ -160,21 +147,8 @@ void FoldersPanel::showEvent(QShowEvent* event)
connect(m_controller, SIGNAL(viewContextMenuRequested(QPointF)), this, SLOT(slotViewContextMenuRequested(QPointF)));
connect(m_controller, SIGNAL(itemDropEvent(int,QGraphicsSceneDragDropEvent*)), this, SLOT(slotItemDropEvent(int,QGraphicsSceneDragDropEvent*)));
- // TODO: Check whether it makes sense to make an explicit API for KItemListContainer
- // to make the background transparent.
- container->setFrameShape(QFrame::NoFrame);
- QGraphicsView* graphicsView = qobject_cast<QGraphicsView*>(container->viewport());
- if (graphicsView) {
- // Make the background of the container transparent and apply the window-text color
- // to the text color, so that enough contrast is given for all color
- // schemes
- QPalette p = graphicsView->palette();
- p.setColor(QPalette::Active, QPalette::Text, p.color(QPalette::Active, QPalette::WindowText));
- p.setColor(QPalette::Inactive, QPalette::Text, p.color(QPalette::Inactive, QPalette::WindowText));
- p.setColor(QPalette::Disabled, QPalette::Text, p.color(QPalette::Disabled, QPalette::WindowText));
- graphicsView->setPalette(p);
- graphicsView->viewport()->setAutoFillBackground(false);
- }
+ KItemListContainer* container = new KItemListContainer(m_controller, this);
+ container->setEnabledFrame(false);
QVBoxLayout* layout = new QVBoxLayout(this);
layout->setMargin(0);
@@ -197,7 +171,7 @@ void FoldersPanel::keyPressEvent(QKeyEvent* event)
void FoldersPanel::slotItemActivated(int index)
{
- const KFileItem item = fileItemModel()->fileItem(index);
+ const KFileItem item = m_model->fileItem(index);
if (!item.isNull()) {
emit changeUrl(item.url(), Qt::LeftButton);
}
@@ -205,7 +179,7 @@ void FoldersPanel::slotItemActivated(int index)
void FoldersPanel::slotItemMiddleClicked(int index)
{
- const KFileItem item = fileItemModel()->fileItem(index);
+ const KFileItem item = m_model->fileItem(index);
if (!item.isNull()) {
emit changeUrl(item.url(), Qt::MiddleButton);
}
@@ -215,7 +189,7 @@ void FoldersPanel::slotItemContextMenuRequested(int index, const QPointF& pos)
{
Q_UNUSED(pos);
- const KFileItem fileItem = fileItemModel()->fileItem(index);
+ const KFileItem fileItem = m_model->fileItem(index);
QWeakPointer<TreeViewContextMenu> contextMenu = new TreeViewContextMenu(this, fileItem);
contextMenu.data()->open();
@@ -238,7 +212,7 @@ void FoldersPanel::slotViewContextMenuRequested(const QPointF& pos)
void FoldersPanel::slotItemDropEvent(int index, QGraphicsSceneDragDropEvent* event)
{
if (index >= 0) {
- KFileItem destItem = fileItemModel()->fileItem(index);
+ KFileItem destItem = m_model->fileItem(index);
if (destItem.isNull()) {
return;
}
@@ -255,8 +229,8 @@ void FoldersPanel::slotItemDropEvent(int index, QGraphicsSceneDragDropEvent* eve
void FoldersPanel::slotRoleEditingFinished(int index, const QByteArray& role, const QVariant& value)
{
- if (role == "name") {
- const KFileItem item = fileItemModel()->fileItem(index);
+ if (role == "text") {
+ const KFileItem item = m_model->fileItem(index);
const QString newName = value.toString();
if (!newName.isEmpty() && newName != item.text() && newName != QLatin1String(".") && newName != QLatin1String("..")) {
KonqOperations::rename(this, item.url(), newName);
@@ -280,7 +254,7 @@ void FoldersPanel::slotLoadingCompleted()
return;
}
- const int index = fileItemModel()->index(url());
+ const int index = m_model->index(url());
updateCurrentItem(index);
m_updateCurrentItem = false;
}
@@ -311,18 +285,17 @@ void FoldersPanel::loadTree(const KUrl& url)
baseUrl.setPath(QString('/'));
}
- KFileItemModel* model = fileItemModel();
- if (model->directory() != baseUrl) {
+ if (m_model->directory() != baseUrl) {
m_updateCurrentItem = true;
- model->refreshDirectory(baseUrl);
+ m_model->refreshDirectory(baseUrl);
}
- const int index = model->index(url);
+ const int index = m_model->index(url);
if (index >= 0) {
updateCurrentItem(index);
} else {
m_updateCurrentItem = true;
- model->expandParentDirectories(url);
+ m_model->expandParentDirectories(url);
// slotLoadingCompleted() will be invoked after the model has
// expanded the url
}
@@ -338,9 +311,4 @@ void FoldersPanel::updateCurrentItem(int index)
m_controller->view()->scrollToItem(index);
}
-KFileItemModel* FoldersPanel::fileItemModel() const
-{
- return static_cast<KFileItemModel*>(m_controller->model());
-}
-
#include "folderspanel.moc"
diff --git a/src/panels/folders/folderspanel.h b/src/panels/folders/folderspanel.h
index 10a30d1f7..b21ecabad 100644
--- a/src/panels/folders/folderspanel.h
+++ b/src/panels/folders/folderspanel.h
@@ -96,11 +96,10 @@ private:
*/
void updateCurrentItem(int index);
- KFileItemModel* fileItemModel() const;
-
private:
bool m_updateCurrentItem;
KItemListController* m_controller;
+ KFileItemModel* m_model;
};
#endif // FOLDERSPANEL_H
diff --git a/src/panels/places/placespanel.cpp b/src/panels/places/placespanel.cpp
index 902c436cf..4ac822760 100644
--- a/src/panels/places/placespanel.cpp
+++ b/src/panels/places/placespanel.cpp
@@ -1,5 +1,5 @@
/***************************************************************************
- * Copyright (C) 2008 by Peter Penz <[email protected]> *
+ * Copyright (C) 2008-2012 by Peter Penz <[email protected]> *
* Copyright (C) 2010 by Christian Muehlhaeuser <[email protected]> *
* *
* This program is free software; you can redistribute it and/or modify *
@@ -20,40 +20,70 @@
#include "placespanel.h"
-#include <KFileItem>
-#include <konq_operations.h>
+#include <KIcon>
+#include <kitemviews/kitemlistcontainer.h>
+#include <kitemviews/kitemlistcontroller.h>
+#include <kitemviews/kstandarditem.h>
+#include <kitemviews/kstandarditemlistview.h>
+#include <kitemviews/kstandarditemmodel.h>
#include <views/draganddrophelper.h>
+#include <QVBoxLayout>
+#include <QShowEvent>
PlacesPanel::PlacesPanel(QWidget* parent) :
- KFilePlacesView(parent),
- m_mouseButtons(Qt::NoButton)
+ Panel(parent),
+ m_controller(0),
+ m_model(0)
{
- setDropOnPlaceEnabled(true);
- connect(this, SIGNAL(urlsDropped(KUrl,QDropEvent*,QWidget*)),
- this, SLOT(slotUrlsDropped(KUrl,QDropEvent*,QWidget*)));
- connect(this, SIGNAL(urlChanged(KUrl)),
- this, SLOT(emitExtendedUrlChangedSignal(KUrl)));
}
PlacesPanel::~PlacesPanel()
{
}
-void PlacesPanel::mousePressEvent(QMouseEvent* event)
+bool PlacesPanel::urlChanged()
{
- m_mouseButtons = event->buttons();
- KFilePlacesView::mousePressEvent(event);
+ return true;
}
-void PlacesPanel::slotUrlsDropped(const KUrl& dest, QDropEvent* event, QWidget* parent)
+void PlacesPanel::showEvent(QShowEvent* event)
{
- Q_UNUSED(parent);
- DragAndDropHelper::dropUrls(KFileItem(), dest, event);
+ if (event->spontaneous()) {
+ Panel::showEvent(event);
+ return;
+ }
+
+ if (!m_controller) {
+ // Postpone the creating of the controller to the first show event.
+ // This assures that no performance and memory overhead is given when the folders panel is not
+ // used at all and stays invisible.
+ KStandardItemListView* view = new KStandardItemListView();
+ m_model = new KStandardItemModel(this);
+ m_model->appendItem(new KStandardItem("Temporary"));
+ m_model->appendItem(new KStandardItem("out of"));
+ m_model->appendItem(new KStandardItem("order. Press"));
+ m_model->appendItem(new KStandardItem("F9 and use"));
+ m_model->appendItem(new KStandardItem("the left icon"));
+ m_model->appendItem(new KStandardItem("of the location"));
+ m_model->appendItem(new KStandardItem("bar instead."));
+
+ m_controller = new KItemListController(m_model, view, this);
+
+ KItemListContainer* container = new KItemListContainer(m_controller, this);
+ container->setEnabledFrame(false);
+
+ QVBoxLayout* layout = new QVBoxLayout(this);
+ layout->setMargin(0);
+ layout->addWidget(container);
+ }
+
+ Panel::showEvent(event);
}
-void PlacesPanel::emitExtendedUrlChangedSignal(const KUrl& url)
+void PlacesPanel::slotUrlsDropped(const KUrl& dest, QDropEvent* event, QWidget* parent)
{
- emit urlChanged(url, m_mouseButtons);
+ Q_UNUSED(parent);
+ DragAndDropHelper::dropUrls(KFileItem(), dest, event);
}
#include "placespanel.moc"
diff --git a/src/panels/places/placespanel.h b/src/panels/places/placespanel.h
index 903f2cadb..1c46cd57d 100644
--- a/src/panels/places/placespanel.h
+++ b/src/panels/places/placespanel.h
@@ -1,5 +1,5 @@
/***************************************************************************
- * Copyright (C) 2008 by Peter Penz <[email protected]> *
+ * Copyright (C) 2008-2012 by Peter Penz <[email protected]> *
* Copyright (C) 2010 by Christian Muehlhaeuser <[email protected]> *
* *
* This program is free software; you can redistribute it and/or modify *
@@ -21,12 +21,15 @@
#ifndef PLACESPANEL_H
#define PLACESPANEL_H
-#include <kfileplacesview.h>
+#include <panels/panel.h>
+
+class KItemListController;
+class KStandardItemModel;
/**
* @brief Combines bookmarks and mounted devices as list.
*/
-class PlacesPanel : public KFilePlacesView
+class PlacesPanel : public Panel
{
Q_OBJECT
@@ -34,18 +37,16 @@ public:
PlacesPanel(QWidget* parent);
virtual ~PlacesPanel();
-signals:
- void urlChanged(const KUrl& url, Qt::MouseButtons buttons);
-
protected:
- virtual void mousePressEvent(QMouseEvent* event);
+ virtual bool urlChanged();
+ virtual void showEvent(QShowEvent* event);
private slots:
void slotUrlsDropped(const KUrl& dest, QDropEvent* event, QWidget* parent);
- void emitExtendedUrlChangedSignal(const KUrl& url);
private:
- Qt::MouseButtons m_mouseButtons;
+ KItemListController* m_controller;
+ KStandardItemModel* m_model;
};
#endif // PLACESPANEL_H