kitemviews/kitemlistcontainer.cpp
kitemviews/kitemlistcontroller.cpp
kitemviews/kitemlistgroupheader.cpp
+ kitemviews/kitemlistheader.cpp
kitemviews/kitemlistkeyboardsearchmanager.cpp
kitemviews/kitemlistrubberband.cpp
kitemviews/kitemlistselectionmanager.cpp
--- /dev/null
+/***************************************************************************
+ * Copyright (C) 2011 by Peter Penz <peter.penz19@gmail.com> *
+ * *
+ * 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"
--- /dev/null
+/***************************************************************************
+ * Copyright (C) 2011 by Peter Penz <peter.penz19@gmail.com> *
+ * *
+ * 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
+
+
#include "kitemlistcontroller.h"
#include "kitemlistgroupheader.h"
+#include "kitemlistheader_p.h"
#include "kitemlistrubberband_p.h"
#include "kitemlistselectionmanager.h"
#include "kitemlistsizehintresolver_p.h"
m_rubberBand(0),
m_mousePos(),
m_autoScrollIncrement(0),
- m_autoScrollTimer(0)
+ m_autoScrollTimer(0),
+ m_header(0)
{
setAcceptHoverEvents(true);
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;
return m_visibleItems.values();
}
+void KItemListView::resizeEvent(QGraphicsSceneResizeEvent* event)
+{
+ QGraphicsWidget::resizeEvent(event);
+ updateHeaderWidth();
+}
+
void KItemListView::slotItemsInserted(const KItemRangeList& itemRanges)
{
markVisibleRolesSizesAsDirty();
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;
#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;
void setAutoScroll(bool enabled);
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
QList<KItemListWidget*> visibleItemListWidgets() const;
+ virtual void resizeEvent(QGraphicsSceneResizeEvent* event);
+
protected slots:
virtual void slotItemsInserted(const KItemRangeList& itemRanges);
virtual void slotItemsRemoved(const KItemRangeList& itemRanges);
*/
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.
int m_autoScrollIncrement;
QTimer* m_autoScrollTimer;
+ KItemListHeader* m_header;
+
friend class KItemListController;
};
m_scrollOrientation(Qt::Vertical),
m_size(),
m_itemSize(128, 128),
+ m_headerHeight(0),
m_model(0),
m_sizeHintResolver(0),
m_offset(0),
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) {
QElapsedTimer timer;
timer.start();
#endif
-
m_visibleIndexesDirty = true;
QSizeF itemSize = m_itemSize;
m_itemBoundingRects.reserve(itemCount);
- qreal y = 0;
+ qreal y = m_headerHeight;
int rowIndex = 0;
int index = 0;
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;
QSizeF m_size;
QSizeF m_itemSize;
+ qreal m_headerHeight;
const KItemModelBase* m_model;
const KItemListSizeHintResolver* m_sizeHintResolver;
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);