Page MenuHomePhorge

No OneTemporary

diff --git a/kdeui/itemviews/kwidgetitemdelegate.cpp b/kdeui/itemviews/kwidgetitemdelegate.cpp
index b4d5c9b22e..828e4980e3 100644
--- a/kdeui/itemviews/kwidgetitemdelegate.cpp
+++ b/kdeui/itemviews/kwidgetitemdelegate.cpp
@@ -1,286 +1,312 @@
/*
* This file is part of the KDE project
* Copyright (C) 2007-2008 Rafael Fernández López <ereslibre@kde.org>
* Copyright (C) 2008 Kevin Ottens <ervin@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 "kwidgetitemdelegate.h"
#include "kwidgetitemdelegate_p.h"
#include <QIcon>
#include <QSize>
#include <QStyle>
#include <QEvent>
#include <QHoverEvent>
#include <QFocusEvent>
#include <QCursor>
#include <QTimer>
#include <QBitmap>
#include <QLayout>
#include <QPainter>
#include <QScrollBar>
#include <QKeyEvent>
#include <QApplication>
#include <QStyleOption>
#include <QPaintEngine>
#include <QCoreApplication>
#include <QAbstractItemView>
#include <QAbstractProxyModel>
#include <QTreeView>
#include "kwidgetitemdelegatepool_p.h"
Q_DECLARE_METATYPE(QList<QEvent::Type>)
/**
Private class that helps to provide binary compatibility between releases.
@internal
*/
//@cond PRIVATE
KWidgetItemDelegatePrivate::KWidgetItemDelegatePrivate(KWidgetItemDelegate *q, QObject *parent)
: QObject(parent)
, itemView(0)
, widgetPool(new KWidgetItemDelegatePool(q))
, model(0)
+ , selectionModel(0)
, viewDestroyed(false)
, q(q)
{
}
KWidgetItemDelegatePrivate::~KWidgetItemDelegatePrivate()
{
if (!viewDestroyed) {
widgetPool->fullClear();
}
delete widgetPool;
}
void KWidgetItemDelegatePrivate::_k_slotRowsInserted(const QModelIndex &parent, int start, int end)
{
Q_UNUSED(end);
// We need to update the rows behind the inserted row as well because the widgets need to be
// moved to their new position
updateRowRange(parent, start, model->rowCount(parent), false);
}
void KWidgetItemDelegatePrivate::_k_slotRowsAboutToBeRemoved(const QModelIndex &parent, int start, int end)
{
updateRowRange(parent, start, end, true);
}
void KWidgetItemDelegatePrivate::_k_slotRowsRemoved(const QModelIndex &parent, int start, int end)
{
Q_UNUSED(end);
// We need to update the rows that come behind the deleted rows because the widgets need to be
// moved to the new position
updateRowRange(parent, start, model->rowCount(parent), false);
}
void KWidgetItemDelegatePrivate::_k_slotDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
{
for (int i = topLeft.row(); i <= bottomRight.row(); ++i) {
for (int j = topLeft.column(); j <= bottomRight.column(); ++j) {
const QModelIndex index = model->index(i, j, topLeft.parent());
QStyleOptionViewItemV4 optionView;
optionView.initFrom(itemView->viewport());
optionView.rect = itemView->visualRect(index);
widgetPool->findWidgets(index, optionView);
}
}
}
void KWidgetItemDelegatePrivate::_k_slotLayoutChanged()
{
foreach (QWidget *widget, widgetPool->invalidIndexesWidgets()) {
widget->setVisible(false);
}
QTimer::singleShot(0, this, SLOT(initializeModel()));
}
void KWidgetItemDelegatePrivate::_k_slotModelReset()
{
widgetPool->fullClear();
QTimer::singleShot(0, this, SLOT(initializeModel()));
}
+void KWidgetItemDelegatePrivate::_k_slotSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
+{
+ foreach (const QModelIndex &index, selected.indexes()) {
+ QStyleOptionViewItemV4 optionView;
+ optionView.initFrom(itemView->viewport());
+ optionView.rect = itemView->visualRect(index);
+ widgetPool->findWidgets(index, optionView);
+ }
+ foreach (const QModelIndex &index, deselected.indexes()) {
+ QStyleOptionViewItemV4 optionView;
+ optionView.initFrom(itemView->viewport());
+ optionView.rect = itemView->visualRect(index);
+ widgetPool->findWidgets(index, optionView);
+ }
+}
+
void KWidgetItemDelegatePrivate::updateRowRange(const QModelIndex &parent, int start, int end, bool isRemoving)
{
int i = start;
while (i <= end) {
for (int j = 0; j < model->columnCount(parent); ++j) {
const QModelIndex index = model->index(i, j, parent);
QStyleOptionViewItemV4 optionView;
optionView.initFrom(itemView->viewport());
optionView.rect = itemView->visualRect(index);
QList<QWidget*> widgetList = widgetPool->findWidgets(index, optionView, isRemoving ? KWidgetItemDelegatePool::NotUpdateWidgets
: KWidgetItemDelegatePool::UpdateWidgets);
if (isRemoving) {
widgetPool->d->allocatedWidgets.removeAll(widgetList);
foreach (QWidget *widget, widgetList) {
const QModelIndex idx = widgetPool->d->widgetInIndex[widget];
widgetPool->d->usedWidgets.remove(idx);
widgetPool->d->widgetInIndex.remove(widget);
delete widget;
}
}
}
i++;
}
}
void KWidgetItemDelegatePrivate::initializeModel(const QModelIndex &parent)
{
if (!model) {
return;
}
for (int i = 0; i < model->rowCount(parent); ++i) {
for (int j = 0; j < model->columnCount(parent); ++j) {
const QModelIndex index = model->index(i, j, parent);
if (index.isValid()) {
QStyleOptionViewItemV4 optionView;
optionView.initFrom(itemView->viewport());
optionView.rect = itemView->visualRect(index);
widgetPool->findWidgets(index, optionView);
}
}
// Check if we need to go recursively through the children of parent (if any) to initialize
// all possible indexes that are shown.
const QModelIndex index = model->index(i, 0, parent);
if (index.isValid() && model->hasChildren(index)) {
initializeModel(index);
}
}
}
//@endcond
KWidgetItemDelegate::KWidgetItemDelegate(QAbstractItemView *itemView, QObject *parent)
: QAbstractItemDelegate(parent)
, d(new KWidgetItemDelegatePrivate(this))
{
Q_ASSERT(itemView);
itemView->setMouseTracking(true);
itemView->viewport()->setAttribute(Qt::WA_Hover);
d->itemView = itemView;
itemView->viewport()->installEventFilter(d); // mouse events
itemView->installEventFilter(d); // keyboard events
if(qobject_cast<QTreeView*>(itemView)) {
connect(itemView, SIGNAL(collapsed(QModelIndex)),
d, SLOT(initializeModel()));
connect(itemView, SIGNAL(expanded(QModelIndex)),
d, SLOT(initializeModel()));
}
}
KWidgetItemDelegate::~KWidgetItemDelegate()
{
delete d;
}
QAbstractItemView *KWidgetItemDelegate::itemView() const
{
return d->itemView;
}
QPersistentModelIndex KWidgetItemDelegate::focusedIndex() const
{
const QPersistentModelIndex idx = d->widgetPool->d->widgetInIndex.value(QApplication::focusWidget());
if (idx.isValid()) {
return idx;
}
// Use the mouse position, if the widget refused to take keyboard focus.
const QPoint pos = d->itemView->viewport()->mapFromGlobal(QCursor::pos());
return d->itemView->indexAt(pos);
}
#ifndef KDE_NO_DEPRECATED
void KWidgetItemDelegate::paintWidgets(QPainter *painter, const QStyleOptionViewItem &option,
const QPersistentModelIndex &index) const
{
Q_UNUSED(painter);
Q_UNUSED(option);
Q_UNUSED(index);
}
#endif
//@cond PRIVATE
bool KWidgetItemDelegatePrivate::eventFilter(QObject *watched, QEvent *event)
{
if (event->type() == QEvent::Destroy) {
// we care for the view since it deletes the widgets (parentage).
// if the view hasn't been deleted, it might be that just the
// delegate is removed from it, in which case we need to remove the widgets
// manually, otherwise they still get drawn.
if (watched == itemView) {
viewDestroyed = true;
}
return false;
}
Q_ASSERT(itemView);
if (model != itemView->model()) {
if (model) {
disconnect(model, SIGNAL(rowsInserted(QModelIndex,int,int)), q, SLOT(_k_slotRowsInserted(QModelIndex,int,int)));
disconnect(model, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)), q, SLOT(_k_slotRowsAboutToBeRemoved(QModelIndex,int,int)));
disconnect(model, SIGNAL(rowsRemoved(QModelIndex,int,int)), q, SLOT(_k_slotRowsRemoved(QModelIndex,int,int)));
disconnect(model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), q, SLOT(_k_slotDataChanged(QModelIndex,QModelIndex)));
disconnect(model, SIGNAL(layoutChanged()), q, SLOT(_k_slotLayoutChanged()));
disconnect(model, SIGNAL(modelReset()), q, SLOT(_k_slotModelReset()));
}
model = itemView->model();
connect(model, SIGNAL(rowsInserted(QModelIndex,int,int)), q, SLOT(_k_slotRowsInserted(QModelIndex,int,int)));
connect(model, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)), q, SLOT(_k_slotRowsAboutToBeRemoved(QModelIndex,int,int)));
connect(model, SIGNAL(rowsRemoved(QModelIndex,int,int)), q, SLOT(_k_slotRowsRemoved(QModelIndex,int,int)));
connect(model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), q, SLOT(_k_slotDataChanged(QModelIndex,QModelIndex)));
connect(model, SIGNAL(layoutChanged()), q, SLOT(_k_slotLayoutChanged()));
connect(model, SIGNAL(modelReset()), q, SLOT(_k_slotModelReset()));
QTimer::singleShot(0, this, SLOT(initializeModel()));
}
+ if (selectionModel != itemView->selectionModel()) {
+ if (selectionModel) {
+ disconnect(selectionModel, SIGNAL(selectionChanged(QItemSelection,QItemSelection)), q, SLOT(_k_slotSelectionChanged(QItemSelection,QItemSelection)));
+ }
+ selectionModel = itemView->selectionModel();
+ connect(selectionModel, SIGNAL(selectionChanged(QItemSelection,QItemSelection)), q, SLOT(_k_slotSelectionChanged(QItemSelection,QItemSelection)));
+ QTimer::singleShot(0, this, SLOT(initializeModel()));
+ }
+
switch (event->type()) {
case QEvent::Polish:
case QEvent::Resize:
if (!qobject_cast<QAbstractItemView*>(watched)) {
QTimer::singleShot(0, this, SLOT(initializeModel()));
}
break;
default:
break;
}
return QObject::eventFilter(watched, event);
}
//@endcond
void KWidgetItemDelegate::setBlockedEventTypes(QWidget *widget, QList<QEvent::Type> types) const
{
widget->setProperty("goya:blockedEventTypes", qVariantFromValue(types));
}
QList<QEvent::Type> KWidgetItemDelegate::blockedEventTypes(QWidget *widget) const
{
return widget->property("goya:blockedEventTypes").value<QList<QEvent::Type> >();
}
#include "kwidgetitemdelegate.moc"
#include "kwidgetitemdelegate_p.moc"
diff --git a/kdeui/itemviews/kwidgetitemdelegate.h b/kdeui/itemviews/kwidgetitemdelegate.h
index f0a1e0a252..232864a68c 100644
--- a/kdeui/itemviews/kwidgetitemdelegate.h
+++ b/kdeui/itemviews/kwidgetitemdelegate.h
@@ -1,169 +1,171 @@
/**
* This file is part of the KDE project
* Copyright (C) 2007-2008 Rafael Fernández López <ereslibre@kde.org>
* Copyright (C) 2008 Kevin Ottens <ervin@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 KWIDGETITEMDELEGATE_H
#define KWIDGETITEMDELEGATE_H
#include <QtCore/QEvent>
#include <QtCore/QList>
#include <QtCore/QPersistentModelIndex>
#include <QtGui/QAbstractItemDelegate>
#include <kdeui_export.h>
class QObject;
class QPainter;
class QStyleOption;
class QStyleOptionViewItem;
class QAbstractItemView;
+class QItemSelection;
class KWidgetItemDelegatePrivate;
class KWidgetItemDelegatePool;
/**
* This class allows to create item delegates embedding simple widgets to interact
* with items. For instance you can add push buttons, line edits, etc. to your delegate
* and use them to modify the state of your model.
*
* @since 4.1
*/
class KDEUI_EXPORT KWidgetItemDelegate : public QAbstractItemDelegate
{
Q_OBJECT
public:
/**
* Creates a new ItemDelegate to be used with a given itemview.
*
* @param itemView the item view the new delegate will monitor
* @param parent the parent of this delegate
*/
explicit KWidgetItemDelegate(QAbstractItemView *itemView, QObject *parent = 0);
/**
* Destroys an ItemDelegate.
*/
virtual ~KWidgetItemDelegate();
/**
* Retrieves the item view this delegate is monitoring.
*
* @return the item view this delegate is monitoring
*/
QAbstractItemView *itemView() const;
/**
* Retrieves the currently focused index. An invalid index if none is focused.
*
* @return the current focused index, or QPersistentModelIndex() if none is focused.
*/
QPersistentModelIndex focusedIndex() const;
protected:
/**
* Creates the list of widgets needed for an item.
*
* @note No initialization of the widgets is supposed to happen here.
* The widgets will be initialized based on needs for a given item.
*
* @note If you want to connect some widget signals to any slot, you should
* do it here.
*
* @note If you want to know the index for which you are creating widgets, it is
* available as a QModelIndex Q_PROPERTY called "goya:creatingWidgetsForIndex".
* Ensure to add Q_DECLARE_METATYPE(QModelIndex) before your method definition
* to tell QVariant about QModelIndex.
*
* @return the list of newly created widgets which will be used to interact with an item.
* @see updateItemWidgets()
*/
virtual QList<QWidget*> createItemWidgets() const = 0;
/**
* Updates a list of widgets for its use inside of the delegate (painting or
* event handling).
*
* @note All the positioning and sizing should be done in item coordinates.
*
* @warning Do not make widget connections in here, since this method will
* be called very regularly.
*
* @param widgets the widgets to update
* @param option the current set of style options for the view.
* @param index the model index of the item currently manipulated.
*/
virtual void updateItemWidgets(const QList<QWidget*> widgets,
const QStyleOptionViewItem &option,
const QPersistentModelIndex &index) const = 0;
/**
* Paint the widgets of the item. This method is meant to be used in the paint()
* method of your item delegate implementation.
*
* @param painter the painter the widgets will be painted on.
* @param option the current set of style options for the view.
* @param index the model index of the item currently painted.
*
* @warning since 4.2 this method is not longer needed to be called. All widgets will kept
* updated without the need of calling paintWidgets() in your paint() event. For the
* widgets of a certain index to be updated your model has to emit dataChanged() on the
* indexes that want to be updated.
*/
#ifndef KDE_NO_DEPRECATED
KDE_DEPRECATED void paintWidgets(QPainter *painter, const QStyleOptionViewItem &option,
const QPersistentModelIndex &index) const;
#endif
/**
* Sets the list of event @p types that a @p widget will block.
*
* Blocked events are not passed to the view. This way you can prevent an item
* from being selected when a button is clicked for instance.
*
* @param widget the widget which must block events
* @param types the list of event types the widget must block
*/
void setBlockedEventTypes(QWidget *widget, QList<QEvent::Type> types) const;
/**
* Retrieves the list of blocked event types for the given widget.
*
* @param widget the specified widget.
*
* @return the list of blocked event types, can be empty if no events are blocked.
*/
QList<QEvent::Type> blockedEventTypes(QWidget *widget) const;
private:
//@cond PRIVATE
friend class KWidgetItemDelegatePool;
friend class KWidgetItemDelegateEventListener;
KWidgetItemDelegatePrivate *const d;
Q_PRIVATE_SLOT(d, void _k_slotRowsInserted(const QModelIndex&,int,int))
Q_PRIVATE_SLOT(d, void _k_slotRowsAboutToBeRemoved(const QModelIndex&,int,int))
Q_PRIVATE_SLOT(d, void _k_slotRowsRemoved(const QModelIndex&,int,int))
Q_PRIVATE_SLOT(d, void _k_slotDataChanged(const QModelIndex&,const QModelIndex&))
Q_PRIVATE_SLOT(d, void _k_slotLayoutChanged())
Q_PRIVATE_SLOT(d, void _k_slotModelReset())
+ Q_PRIVATE_SLOT(d, void _k_slotSelectionChanged(const QItemSelection&,const QItemSelection&))
//@endcond
};
#endif
diff --git a/kdeui/itemviews/kwidgetitemdelegate_p.h b/kdeui/itemviews/kwidgetitemdelegate_p.h
index a51d97a73b..7c1d2174ea 100644
--- a/kdeui/itemviews/kwidgetitemdelegate_p.h
+++ b/kdeui/itemviews/kwidgetitemdelegate_p.h
@@ -1,68 +1,70 @@
/**
* This file is part of the KDE project
* Copyright (C) 2008 Rafael Fernández López <ereslibre@kde.org>
* Copyright (C) 2008 Kevin Ottens <ervin@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.
*/
/**
* This class is necessary to be installed because of the templated method.
* It is private in the sense of having clean the public header.
* Do not forget that this file _has_ to be installed.
*/
#ifndef KWIDGETITEMDELEGATE_P_H
#define KWIDGETITEMDELEGATE_P_H
#include <QtGui/QItemSelectionModel>
class KWidgetItemDelegate;
class KWidgetItemDelegatePrivate
: public QObject
{
Q_OBJECT
public:
explicit KWidgetItemDelegatePrivate(KWidgetItemDelegate *q, QObject *parent = 0);
~KWidgetItemDelegatePrivate();
void _k_slotRowsInserted(const QModelIndex &parent, int start, int end);
void _k_slotRowsAboutToBeRemoved(const QModelIndex &parent, int start, int end);
void _k_slotRowsRemoved(const QModelIndex &parent, int start, int end);
void _k_slotDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);
void _k_slotLayoutChanged();
void _k_slotModelReset();
+ void _k_slotSelectionChanged (const QItemSelection &selected, const QItemSelection &deselected);
void updateRowRange(const QModelIndex &parent, int start, int end, bool isRemoving);
public Q_SLOTS:
void initializeModel(const QModelIndex &parent = QModelIndex());
protected:
virtual bool eventFilter(QObject *watched, QEvent *event);
public:
QAbstractItemView *itemView;
KWidgetItemDelegatePool *widgetPool;
QAbstractItemModel *model;
+ QItemSelectionModel *selectionModel;
bool viewDestroyed;
KWidgetItemDelegate *q;
};
#endif

File Metadata

Mime Type
text/x-diff
Expires
Fri, Nov 1, 9:57 AM (1 d, 19 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
10076247
Default Alt Text
(21 KB)

Event Timeline