2007-09-26 09:44:06 +02:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2007 Ivan Cukic <ivan.cukic+kde@gmail.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
2007-10-12 10:44:02 +02:00
|
|
|
* it under the terms of the GNU Library/Lesser General Public License
|
|
|
|
* version 2, or (at your option) any later version, as published by the
|
|
|
|
* Free Software Foundation
|
2007-09-26 09:44:06 +02:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*
|
2007-10-12 10:44:02 +02:00
|
|
|
* You should have received a copy of the GNU Library/Lesser General Public
|
2007-09-26 09:44:06 +02:00
|
|
|
* 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 KCategorizedItemsView_H
|
|
|
|
#define KCategorizedItemsView_H
|
|
|
|
|
2007-12-10 20:38:31 +01:00
|
|
|
#include <QtGui/QtGui>
|
|
|
|
#include <QtCore/QtCore>
|
2007-09-27 20:51:31 +02:00
|
|
|
|
|
|
|
#include "kcategorizeditemsviewmodels_p.h"
|
2007-09-26 09:44:06 +02:00
|
|
|
|
|
|
|
#include "ui_kcategorizeditemsviewbase.h"
|
|
|
|
|
|
|
|
using namespace KCategorizedItemsViewModels;
|
|
|
|
class KCategorizedItemsViewDelegate;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* QT4 View Widget for displaying a list of categorized items with special
|
|
|
|
* filtering capabilities.
|
|
|
|
*
|
|
|
|
* To use it, you need to implement KCategorizedItemsView::AbstractItem
|
|
|
|
*
|
|
|
|
* For convenience, there are default implementations of category model
|
|
|
|
* (DefaultCategoryModel), filters model (DefaultFilterModel) and the
|
|
|
|
* default item mode (DefaultItemModel), but you do not need to use them.
|
|
|
|
*
|
|
|
|
* One constraint is that DefaultItemModel *must* hold the items that
|
|
|
|
* are subclassed from KCategorizedItemsView::AbstractItem
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
class KCategorizedItemsView: public QWidget, public Ui::KCategorizedItemsViewBase
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2007-09-27 19:50:31 +02:00
|
|
|
|
2008-02-19 09:32:32 +01:00
|
|
|
explicit KCategorizedItemsView(QWidget * parent = 0, Qt::WindowFlags f = 0);
|
2007-09-26 09:44:06 +02:00
|
|
|
virtual ~KCategorizedItemsView();
|
|
|
|
|
|
|
|
void setFilterModel(QStandardItemModel * model); ///< Sets the filters model
|
|
|
|
void setItemModel(QStandardItemModel * model); ///< Sets the item model, as mentioned items must implement AbstractItem class
|
2007-09-27 19:50:31 +02:00
|
|
|
|
2007-09-26 09:44:06 +02:00
|
|
|
void addEmblem(const QString & title, QIcon * icon, const Filter & filter);
|
|
|
|
void clearEmblems();
|
2007-09-27 19:50:31 +02:00
|
|
|
|
|
|
|
QList < AbstractItem * > selectedItems() const;
|
|
|
|
|
2008-02-18 21:55:50 +01:00
|
|
|
protected:
|
|
|
|
virtual void resizeEvent ( QResizeEvent * event );
|
|
|
|
virtual bool event ( QEvent * event );
|
|
|
|
|
2007-09-26 09:44:06 +02:00
|
|
|
protected slots:
|
|
|
|
void searchTermChanged(const QString &text);
|
|
|
|
void filterChanged(int index);
|
2007-09-27 19:50:31 +02:00
|
|
|
|
2008-03-13 17:10:11 +01:00
|
|
|
private slots:
|
|
|
|
void itemActivated( const QModelIndex& index );
|
|
|
|
|
2007-09-26 09:44:06 +02:00
|
|
|
Q_SIGNALS:
|
|
|
|
void activated ( const QModelIndex & index );
|
|
|
|
void clicked ( const QModelIndex & index );
|
|
|
|
void doubleClicked ( const QModelIndex & index );
|
|
|
|
void entered ( const QModelIndex & index );
|
|
|
|
void pressed ( const QModelIndex & index );
|
|
|
|
|
|
|
|
private:
|
2008-02-18 21:55:50 +01:00
|
|
|
void updateColumnsWidth(bool force = false);
|
|
|
|
|
2007-09-26 09:44:06 +02:00
|
|
|
QStandardItemModel * m_modelCategories;
|
|
|
|
QStandardItemModel * m_modelFilters;
|
|
|
|
QStandardItemModel * m_modelItems;
|
2007-09-27 19:50:31 +02:00
|
|
|
|
2007-09-26 09:44:06 +02:00
|
|
|
DefaultItemFilterProxyModel * m_modelFilterItems;
|
|
|
|
KCategorizedItemsViewDelegate * m_delegate;
|
2007-09-27 19:50:31 +02:00
|
|
|
|
2007-09-26 09:44:06 +02:00
|
|
|
int m_viewWidth;
|
2007-09-27 19:50:31 +02:00
|
|
|
|
2007-09-26 09:44:06 +02:00
|
|
|
QMap < QString, QPair < Filter, QIcon * > > m_emblems;
|
2007-09-27 19:50:31 +02:00
|
|
|
AbstractItem * getItemByProxyIndex(const QModelIndex & index) const;
|
2007-09-26 09:44:06 +02:00
|
|
|
|
|
|
|
friend class KCategorizedItemsViewDelegate;
|
2007-09-29 21:11:27 +02:00
|
|
|
friend class CustomDragTreeView;
|
2007-09-26 09:44:06 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
//Q_DECLARE_METATYPE(KCategorizedItemsView::Filter)
|
|
|
|
|
|
|
|
#endif
|