┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/CMakeLists.txt1
-rw-r--r--src/kitemviews/kitemlistheader.cpp42
-rw-r--r--src/kitemviews/kitemlistheader_p.h42
-rw-r--r--src/kitemviews/kitemlistview.cpp38
-rw-r--r--src/kitemviews/kitemlistview.h20
-rw-r--r--src/kitemviews/kitemlistviewlayouter.cpp17
-rw-r--r--src/kitemviews/kitemlistviewlayouter_p.h9
-rw-r--r--src/views/dolphinitemlistcontainer.cpp7
8 files changed, 171 insertions, 5 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 9c2a86766..0eedece94 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -25,6 +25,7 @@ set(dolphinprivate_LIB_SRCS
kitemviews/kitemlistcontainer.cpp
kitemviews/kitemlistcontroller.cpp
kitemviews/kitemlistgroupheader.cpp
+ kitemviews/kitemlistheader.cpp
kitemviews/kitemlistkeyboardsearchmanager.cpp
kitemviews/kitemlistrubberband.cpp
kitemviews/kitemlistselectionmanager.cpp
diff --git a/src/kitemviews/kitemlistheader.cpp b/src/kitemviews/kitemlistheader.cpp
new file mode 100644
index 000000000..89b28bcce
--- /dev/null
+++ b/src/kitemviews/kitemlistheader.cpp
@@ -0,0 +1,42 @@
+/***************************************************************************
+ * Copyright (C) 2011 by Peter Penz <[email protected]> *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
+ ***************************************************************************/
+
+#include "kitemlistheader_p.h"
+
+#include <QPainter>
+
+KItemListHeader::KItemListHeader(QGraphicsWidget* parent) :
+ QGraphicsWidget(parent)
+{
+ resize(0, 20); // TODO...
+}
+
+KItemListHeader::~KItemListHeader()
+{
+}
+
+void KItemListHeader::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
+{
+ Q_UNUSED(option);
+ Q_UNUSED(widget);
+ painter->setPen(Qt::red);
+ painter->drawRect(rect());
+}
+
+#include "kitemlistheader_p.moc"
diff --git a/src/kitemviews/kitemlistheader_p.h b/src/kitemviews/kitemlistheader_p.h
new file mode 100644
index 000000000..6f04ac94b
--- /dev/null
+++ b/src/kitemviews/kitemlistheader_p.h
@@ -0,0 +1,42 @@
+/***************************************************************************
+ * Copyright (C) 2011 by Peter Penz <[email protected]> *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
+ ***************************************************************************/
+
+#ifndef KITEMLISTHEADER_H
+#define KITEMLISTHEADER_H
+
+#include <libdolphin_export.h>
+#include <QGraphicsWidget>
+
+/**
+ * @brief Header for KItemListView that shows the currently used roles.
+ */
+class LIBDOLPHINPRIVATE_EXPORT KItemListHeader : public QGraphicsWidget
+{
+ Q_OBJECT
+
+public:
+ KItemListHeader(QGraphicsWidget* parent = 0);
+ virtual ~KItemListHeader();
+
+ virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0);
+};
+
+#endif
+
+
diff --git a/src/kitemviews/kitemlistview.cpp b/src/kitemviews/kitemlistview.cpp
index 2a7b0e4cd..1dc05e38f 100644
--- a/src/kitemviews/kitemlistview.cpp
+++ b/src/kitemviews/kitemlistview.cpp
@@ -24,6 +24,7 @@
#include "kitemlistcontroller.h"
#include "kitemlistgroupheader.h"
+#include "kitemlistheader_p.h"
#include "kitemlistrubberband_p.h"
#include "kitemlistselectionmanager.h"
#include "kitemlistsizehintresolver_p.h"
@@ -74,7 +75,8 @@ KItemListView::KItemListView(QGraphicsWidget* parent) :
m_rubberBand(0),
m_mousePos(),
m_autoScrollIncrement(0),
- m_autoScrollTimer(0)
+ m_autoScrollTimer(0),
+ m_header(0)
{
setAcceptHoverEvents(true);
@@ -223,6 +225,24 @@ bool KItemListView::autoScroll() const
return m_autoScrollTimer != 0;
}
+void KItemListView::setHeaderShown(bool show)
+{
+ if (show && !m_header) {
+ m_header = new KItemListHeader(this);
+ updateHeaderWidth();
+ m_layouter->setHeaderHeight(m_header->size().height());
+ } else if (!show && m_header) {
+ delete m_header;
+ m_header = 0;
+ m_layouter->setHeaderHeight(0);
+ }
+}
+
+bool KItemListView::isHeaderShown() const
+{
+ return m_header != 0;
+}
+
KItemListController* KItemListView::controller() const
{
return m_controller;
@@ -532,6 +552,12 @@ QList<KItemListWidget*> KItemListView::visibleItemListWidgets() const
return m_visibleItems.values();
}
+void KItemListView::resizeEvent(QGraphicsSceneResizeEvent* event)
+{
+ QGraphicsWidget::resizeEvent(event);
+ updateHeaderWidth();
+}
+
void KItemListView::slotItemsInserted(const KItemRangeList& itemRanges)
{
markVisibleRolesSizesAsDirty();
@@ -1295,6 +1321,16 @@ void KItemListView::updateWidgetProperties(KItemListWidget* widget, int index)
widget->setData(m_model->data(index));
}
+void KItemListView::updateHeaderWidth()
+{
+ if (!m_header) {
+ return;
+ }
+
+ // TODO 1: Use the required width of all roles
+ m_header->resize(size().width(), m_header->size().height());
+}
+
int KItemListView::calculateAutoScrollingIncrement(int pos, int range, int oldInc)
{
int inc = 0;
diff --git a/src/kitemviews/kitemlistview.h b/src/kitemviews/kitemlistview.h
index 55a5c3344..a2fa23f3e 100644
--- a/src/kitemviews/kitemlistview.h
+++ b/src/kitemviews/kitemlistview.h
@@ -33,14 +33,15 @@
#include <QSet>
class KItemListController;
-class KItemListWidgetCreatorBase;
class KItemListGroupHeader;
class KItemListGroupHeaderCreatorBase;
+class KItemListHeader;
class KItemListSizeHintResolver;
class KItemListRubberBand;
class KItemListViewAnimation;
class KItemListViewLayouter;
class KItemListWidget;
+class KItemListWidgetCreatorBase;
class KItemListViewCreatorBase;
class QTimer;
@@ -98,6 +99,13 @@ public:
bool autoScroll() const;
/**
+ * Turns on the header if \p show is true. Per default the
+ * header is not shown.
+ */
+ void setHeaderShown(bool show);
+ bool isHeaderShown() const;
+
+ /**
* @return Controller of the item-list. The controller gets
* initialized by KItemListController::setView() and will
* result in calling KItemListController::onControllerChanged().
@@ -206,6 +214,8 @@ protected:
QList<KItemListWidget*> visibleItemListWidgets() const;
+ virtual void resizeEvent(QGraphicsSceneResizeEvent* event);
+
protected slots:
virtual void slotItemsInserted(const KItemRangeList& itemRanges);
virtual void slotItemsRemoved(const KItemRangeList& itemRanges);
@@ -293,6 +303,12 @@ private:
void updateWidgetProperties(KItemListWidget* widget, int index);
/**
+ * Updates the width of the KItemListHeader corresponding to the required width of
+ * the roles.
+ */
+ void updateHeaderWidth();
+
+ /**
* Helper function for triggerAutoScrolling().
* @param pos Logical position of the mouse relative to the range.
* @param range Range of the visible area.
@@ -336,6 +352,8 @@ private:
int m_autoScrollIncrement;
QTimer* m_autoScrollTimer;
+ KItemListHeader* m_header;
+
friend class KItemListController;
};
diff --git a/src/kitemviews/kitemlistviewlayouter.cpp b/src/kitemviews/kitemlistviewlayouter.cpp
index 4adb612e9..78688c941 100644
--- a/src/kitemviews/kitemlistviewlayouter.cpp
+++ b/src/kitemviews/kitemlistviewlayouter.cpp
@@ -39,6 +39,7 @@ KItemListViewLayouter::KItemListViewLayouter(QObject* parent) :
m_scrollOrientation(Qt::Vertical),
m_size(),
m_itemSize(128, 128),
+ m_headerHeight(0),
m_model(0),
m_sizeHintResolver(0),
m_offset(0),
@@ -98,6 +99,19 @@ QSizeF KItemListViewLayouter::itemSize() const
return m_itemSize;
}
+void KItemListViewLayouter::setHeaderHeight(qreal height)
+{
+ if (m_headerHeight != height) {
+ m_headerHeight = height;
+ m_dirty = true;
+ }
+}
+
+qreal KItemListViewLayouter::headerHeight() const
+{
+ return m_headerHeight;
+}
+
void KItemListViewLayouter::setOffset(qreal offset)
{
if (m_offset != offset) {
@@ -216,7 +230,6 @@ void KItemListViewLayouter::doLayout()
QElapsedTimer timer;
timer.start();
#endif
-
m_visibleIndexesDirty = true;
QSizeF itemSize = m_itemSize;
@@ -250,7 +263,7 @@ void KItemListViewLayouter::doLayout()
m_itemBoundingRects.reserve(itemCount);
- qreal y = 0;
+ qreal y = m_headerHeight;
int rowIndex = 0;
int index = 0;
diff --git a/src/kitemviews/kitemlistviewlayouter_p.h b/src/kitemviews/kitemlistviewlayouter_p.h
index f774814eb..18ffb4caa 100644
--- a/src/kitemviews/kitemlistviewlayouter_p.h
+++ b/src/kitemviews/kitemlistviewlayouter_p.h
@@ -47,6 +47,14 @@ public:
void setItemSize(const QSizeF& size);
QSizeF itemSize() const;
+ /**
+ * Sets the height of the header that is always aligned
+ * at the top. A height of <= 0.0 means that no header is
+ * used.
+ */
+ void setHeaderHeight(qreal height);
+ qreal headerHeight() const;
+
// TODO: add note that offset can be < 0 or > maximumOffset!
void setOffset(qreal offset);
qreal offset() const;
@@ -95,6 +103,7 @@ private:
QSizeF m_size;
QSizeF m_itemSize;
+ qreal m_headerHeight;
const KItemModelBase* m_model;
const KItemListSizeHintResolver* m_sizeHintResolver;
diff --git a/src/views/dolphinitemlistcontainer.cpp b/src/views/dolphinitemlistcontainer.cpp
index 1ee8f8aa4..404b1d92b 100644
--- a/src/views/dolphinitemlistcontainer.cpp
+++ b/src/views/dolphinitemlistcontainer.cpp
@@ -189,11 +189,16 @@ void DolphinItemListContainer::setItemLayout(KFileItemListView::Layout layout)
switch (layout) {
case KFileItemListView::IconsLayout:
- case KFileItemListView::DetailsLayout:
m_fileItemListView->setScrollOrientation(Qt::Vertical);
+ m_fileItemListView->setHeaderShown(false);
break;
case KFileItemListView::CompactLayout:
m_fileItemListView->setScrollOrientation(Qt::Horizontal);
+ m_fileItemListView->setHeaderShown(false);
+ break;
+ case KFileItemListView::DetailsLayout:
+ m_fileItemListView->setScrollOrientation(Qt::Vertical);
+ m_fileItemListView->setHeaderShown(true);
break;
default:
Q_ASSERT(false);