mirror of
https://invent.kde.org/system/dolphin
synced 2024-09-12 12:54:29 +00:00
Rough draft for getting back the header for the details-view
This commit is contained in:
parent
8879f5e752
commit
f9bcd0a47c
|
@ -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
|
||||
|
|
42
src/kitemviews/kitemlistheader.cpp
Normal file
42
src/kitemviews/kitemlistheader.cpp
Normal file
|
@ -0,0 +1,42 @@
|
|||
/***************************************************************************
|
||||
* 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"
|
42
src/kitemviews/kitemlistheader_p.h
Normal file
42
src/kitemviews/kitemlistheader_p.h
Normal file
|
@ -0,0 +1,42 @@
|
|||
/***************************************************************************
|
||||
* 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
|
||||
|
||||
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
@ -97,6 +98,13 @@ public:
|
|||
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
|
||||
|
@ -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);
|
||||
|
@ -292,6 +302,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.
|
||||
|
@ -336,6 +352,8 @@ private:
|
|||
int m_autoScrollIncrement;
|
||||
QTimer* m_autoScrollTimer;
|
||||
|
||||
KItemListHeader* m_header;
|
||||
|
||||
friend class KItemListController;
|
||||
};
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue