Move KCategorizedView to kdelibs. Use that one.

svn path=/trunk/KDE/kdebase/apps/; revision=760873
This commit is contained in:
Rafael Fernández López 2008-01-13 15:44:04 +00:00
parent 4addf79493
commit f6984788a8
7 changed files with 1 additions and 2082 deletions

View file

@ -25,8 +25,6 @@ set(dolphinprivate_LIB_SRCS
dolphincategorydrawer.cpp
dolphinview.cpp
iconmanager.cpp
kcategorizedview.cpp
kcategorydrawer.cpp
ratingpainter.cpp
renamedialog.cpp
viewproperties.cpp

View file

@ -21,7 +21,7 @@
#ifndef DOLPHINCATEGORYDRAWER_H
#define DOLPHINCATEGORYDRAWER_H
#include "kcategorydrawer.h"
#include <kcategorydrawer.h>
#include <QStyleOption>
#include <QModelIndex>

File diff suppressed because it is too large Load diff

View file

@ -1,119 +0,0 @@
/**
* This file is part of the KDE project
* Copyright (C) 2007 Rafael Fernández López <ereslibre@kde.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef KCATEGORIZEDVIEW_H
#define KCATEGORIZEDVIEW_H
#include <QtGui/QListView>
#include <libdolphin_export.h>
class KCategoryDrawer;
/**
* @short Item view for listing items
*
* KCategorizedView allows you to use it as it were a QListView. You can add an
* itemCategorizer to it, so your items became categorized depending on the
* KItemCategorizer inherited class rules.
*
* @see KItemCategorizer, KSortFilterProxyModel
*
* @author Rafael Fernández López <ereslibre@kde.org>
*/
class LIBDOLPHINPRIVATE_EXPORT KCategorizedView
: public QListView
{
Q_OBJECT
public:
KCategorizedView(QWidget *parent = 0);
~KCategorizedView();
virtual void setModel(QAbstractItemModel *model);
void setGridSize(const QSize &size);
virtual QRect visualRect(const QModelIndex &index) const;
KCategoryDrawer *categoryDrawer() const;
void setCategoryDrawer(KCategoryDrawer *categoryDrawer);
virtual QModelIndex indexAt(const QPoint &point) const;
public Q_SLOTS:
virtual void reset();
protected:
virtual void paintEvent(QPaintEvent *event);
virtual void resizeEvent(QResizeEvent *event);
virtual void setSelection(const QRect &rect,
QItemSelectionModel::SelectionFlags flags);
virtual void mouseMoveEvent(QMouseEvent *event);
virtual void mousePressEvent(QMouseEvent *event);
virtual void mouseReleaseEvent(QMouseEvent *event);
virtual void leaveEvent(QEvent *event);
virtual void startDrag(Qt::DropActions supportedActions);
virtual void dragMoveEvent(QDragMoveEvent *event);
virtual void dragLeaveEvent(QDragLeaveEvent *event);
virtual void dropEvent(QDropEvent *event);
virtual QModelIndex moveCursor(CursorAction cursorAction,
Qt::KeyboardModifiers modifiers);
protected Q_SLOTS:
virtual void rowsInserted(const QModelIndex &parent,
int start,
int end);
virtual void rowsInsertedArtifficial(const QModelIndex &parent,
int start,
int end);
virtual void rowsRemoved(const QModelIndex &parent,
int start,
int end);
virtual void updateGeometries();
virtual void slotLayoutChanged();
virtual void currentChanged(const QModelIndex &current,
const QModelIndex &previous);
private:
class Private;
Private *d;
};
#endif // KCATEGORIZEDVIEW_H

View file

@ -1,164 +0,0 @@
/**
* This file is part of the KDE project
* Copyright (C) 2007 Rafael Fernández López <ereslibre@kde.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef KCATEGORIZEDVIEW_P_H
#define KCATEGORIZEDVIEW_P_H
class KCategorizedSortFilterProxyModel;
class KCategoryDrawer;
/**
* @internal
*/
class KCategorizedView::Private
{
public:
Private(KCategorizedView *listView);
~Private();
// Methods
/**
* Returns the list of items that intersects with @p rect
*/
const QModelIndexList &intersectionSet(const QRect &rect);
/**
* Gets the item rect in the viewport for @p index
*/
QRect visualRectInViewport(const QModelIndex &index) const;
/**
* Returns the category rect in the viewport for @p category
*/
QRect visualCategoryRectInViewport(const QString &category) const;
/**
* Caches and returns the rect that corresponds to @p index
*/
const QRect &cacheIndex(const QModelIndex &index);
/**
* Caches and returns the rect that corresponds to @p category
*/
const QRect &cacheCategory(const QString &category);
/**
* Returns the rect that corresponds to @p index
* @note If the rect is not cached, it becomes cached
*/
const QRect &cachedRectIndex(const QModelIndex &index);
/**
* Returns the rect that corresponds to @p category
* @note If the rect is not cached, it becomes cached
*/
const QRect &cachedRectCategory(const QString &category);
/**
* Returns the visual rect (taking in count x and y offsets) for @p index
* @note If the rect is not cached, it becomes cached
*/
QRect visualRect(const QModelIndex &index);
/**
* Returns the visual rect (taking in count x and y offsets) for @p category
* @note If the rect is not cached, it becomes cached
*/
QRect categoryVisualRect(const QString &category);
/**
* This method will draw a new category represented by index
* @param index on the rect specified by @p option.rect, with
* painter @p painter
*/
void drawNewCategory(const QModelIndex &index,
int sortRole,
const QStyleOption &option,
QPainter *painter);
/**
* This method will update scrollbars ranges. Called when our model changes
* or when the view is resized
*/
void updateScrollbars();
/**
* This method will draw dragged items in the painting operation
*/
void drawDraggedItems(QPainter *painter);
/**
* This method will determine which rect needs to be updated because of a
* dragging operation
*/
void drawDraggedItems();
void layoutChanged(bool forceItemReload = false);
// Attributes
struct ElementInfo
{
QString category;
int relativeOffsetToCategory;
};
// Basic data
KCategorizedView *listView;
KCategoryDrawer *categoryDrawer;
QSize biggestItemSize;
// Behavior data
bool mouseButtonPressed;
bool rightMouseButtonPressed;
bool isDragging;
bool dragLeftViewport;
QModelIndex hovered;
QString hoveredCategory;
QPoint initialPressPosition;
QPoint mousePosition;
int forcedSelectionPosition;
// Cache data
// We cannot merge some of them into structs because it would affect
// performance
QHash<int, struct ElementInfo> elementsInfo;
QHash<int, QRect> elementsPosition;
QHash<QString, QModelIndexList> categoriesIndexes;
QHash<QString, QRect> categoriesPosition;
QStringList categories;
QModelIndexList intersectedIndexes;
QRect lastDraggedItemsRect;
int modelSortRole;
int modelSortColumn;
int modelLastRowCount;
bool modelCategorized;
Qt::SortOrder modelSortOrder;
QItemSelection lastSelection;
// Attributes for speed reasons
KCategorizedSortFilterProxyModel *proxyModel;
QModelIndexList modelIndexList;
};
#endif // KCATEGORIZEDVIEW_P_H

View file

@ -1,118 +0,0 @@
/**
* This file is part of the KDE project
* Copyright (C) 2007 Rafael Fernández López <ereslibre@kde.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "kcategorydrawer.h"
#include <QPainter>
#include <QStyleOption>
#include <kiconloader.h>
#include <kcategorizedsortfilterproxymodel.h>
KCategoryDrawer::KCategoryDrawer()
{
}
KCategoryDrawer::~KCategoryDrawer()
{
}
void KCategoryDrawer::drawCategory(const QModelIndex &index,
int /*sortRole*/,
const QStyleOption &option,
QPainter *painter) const
{
const QString category = index.model()->data(index, KCategorizedSortFilterProxyModel::CategoryDisplayRole).toString();
QColor color;
if (option.state & QStyle::State_Selected)
{
color = option.palette.color(QPalette::HighlightedText);
}
else
{
color = option.palette.color(QPalette::Text);
}
painter->save();
painter->setRenderHint(QPainter::Antialiasing);
if (option.state & QStyle::State_Selected)
{
QColor selected = option.palette.color(QPalette::Highlight);
QLinearGradient gradient(option.rect.topLeft(),
option.rect.bottomRight());
gradient.setColorAt(option.direction == Qt::LeftToRight ? 0
: 1, selected);
gradient.setColorAt(option.direction == Qt::LeftToRight ? 1
: 0, Qt::transparent);
painter->fillRect(option.rect, gradient);
}
else if (option.state & QStyle::State_MouseOver)
{
QColor hover = option.palette.color(QPalette::Highlight).light();
hover.setAlpha(88);
QLinearGradient gradient(option.rect.topLeft(),
option.rect.bottomRight());
gradient.setColorAt(option.direction == Qt::LeftToRight ? 0
: 1, hover);
gradient.setColorAt(option.direction == Qt::LeftToRight ? 1
: 0, Qt::transparent);
painter->fillRect(option.rect, gradient);
}
QFont painterFont = painter->font();
painterFont.setWeight(QFont::Bold);
QFontMetrics metrics(painterFont);
painter->setFont(painterFont);
QRect lineRect(option.rect.left(),
option.rect.bottom() - 1,
option.rect.width(),
1);
QLinearGradient gradient(option.rect.topLeft(),
option.rect.bottomRight());
gradient.setColorAt(option.direction == Qt::LeftToRight ? 0
: 1, color);
gradient.setColorAt(option.direction == Qt::LeftToRight ? 1
: 0, Qt::transparent);
painter->fillRect(lineRect, gradient);
painter->setPen(color);
painter->drawText(option.rect, Qt::AlignVCenter | Qt::AlignLeft,
metrics.elidedText(category, Qt::ElideRight, option.rect.width()));
painter->restore();
}
int KCategoryDrawer::categoryHeight(const QModelIndex &index, const QStyleOption &option) const
{
Q_UNUSED(index);
return option.fontMetrics.height() + 4 /* 3 separator; 1 gradient */;
}

View file

@ -1,52 +0,0 @@
/**
* This file is part of the KDE project
* Copyright (C) 2007 Rafael Fernández López <ereslibre@kde.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef KCATEGORYDRAWER_H
#define KCATEGORYDRAWER_H
#include <libdolphin_export.h>
class QPainter;
class QModelIndex;
class QStyleOption;
class LIBDOLPHINPRIVATE_EXPORT KCategoryDrawer
{
public:
KCategoryDrawer();
virtual ~KCategoryDrawer();
/**
* This method purpose is to draw a category represented by the given
* @param index with the given @param sortRole sorting role
*
* @note This method will be called one time per category, always with the
* first element in that category
*/
virtual void drawCategory(const QModelIndex &index,
int sortRole,
const QStyleOption &option,
QPainter *painter) const;
virtual int categoryHeight(const QModelIndex &index, const QStyleOption &option) const;
};
#endif // KCATEGORYDRAWER_H