coding style fixes.
svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=870188
This commit is contained in:
parent
fbd8bc850e
commit
a320742114
@ -26,7 +26,7 @@
|
||||
CustomDragTreeView::CustomDragTreeView(QWidget * parent)
|
||||
: QTreeView(parent) {}
|
||||
|
||||
void CustomDragTreeView::startDrag ( Qt::DropActions supportedActions )
|
||||
void CustomDragTreeView::startDrag(Qt::DropActions supportedActions)
|
||||
{
|
||||
Q_UNUSED(supportedActions);
|
||||
|
||||
@ -74,7 +74,6 @@ void CustomDragTreeView::startDrag ( Qt::DropActions supportedActions )
|
||||
}
|
||||
painter.end();
|
||||
|
||||
|
||||
QDrag *drag = new QDrag(this);
|
||||
drag->setPixmap(pixmap);
|
||||
drag->setMimeData(data);
|
||||
|
@ -28,13 +28,13 @@ class KCategorizedItemsView;
|
||||
class CustomDragTreeView: public QTreeView
|
||||
{
|
||||
public:
|
||||
CustomDragTreeView(QWidget * parent = 0);
|
||||
CustomDragTreeView(QWidget *parent = 0);
|
||||
|
||||
protected:
|
||||
void startDrag ( Qt::DropActions supportedActions );
|
||||
void startDrag(Qt::DropActions supportedActions);
|
||||
|
||||
private:
|
||||
KCategorizedItemsView * m_view;
|
||||
KCategorizedItemsView *m_view;
|
||||
|
||||
friend class KCategorizedItemsView;
|
||||
};
|
||||
|
@ -36,9 +36,9 @@ KCategorizedItemsView::KCategorizedItemsView(QWidget * parent, Qt::WindowFlags f
|
||||
itemsView->m_view = this;
|
||||
|
||||
textSearch->setClickMessage(i18n("Enter search phrase here"));
|
||||
|
||||
|
||||
textSearch->setFocus();
|
||||
|
||||
|
||||
connect(textSearch, SIGNAL(textChanged(QString)),
|
||||
this, SLOT(searchTermChanged(QString)));
|
||||
connect(comboFilters, SIGNAL(currentIndexChanged(int)),
|
||||
@ -80,38 +80,39 @@ KCategorizedItemsView::~KCategorizedItemsView()
|
||||
delete m_delegate;
|
||||
}
|
||||
|
||||
void KCategorizedItemsView::resizeEvent ( QResizeEvent * event )
|
||||
void KCategorizedItemsView::resizeEvent (QResizeEvent *event)
|
||||
{
|
||||
updateColumnsWidth();
|
||||
|
||||
QWidget::resizeEvent(event);
|
||||
}
|
||||
|
||||
bool KCategorizedItemsView::event ( QEvent * event )
|
||||
bool KCategorizedItemsView::event (QEvent *event)
|
||||
{
|
||||
switch (event->type()) {
|
||||
case QEvent::PolishRequest:
|
||||
case QEvent::Polish:
|
||||
updateColumnsWidth(true);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
case QEvent::PolishRequest:
|
||||
case QEvent::Polish:
|
||||
updateColumnsWidth(true);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return QWidget::event(event);
|
||||
}
|
||||
|
||||
void KCategorizedItemsView::setFilterModel(QStandardItemModel * model)
|
||||
void KCategorizedItemsView::setFilterModel(QStandardItemModel *model)
|
||||
{
|
||||
comboFilters->setModel(model);
|
||||
m_modelFilters = model;
|
||||
}
|
||||
|
||||
void KCategorizedItemsView::setItemModel(QStandardItemModel * model)
|
||||
void KCategorizedItemsView::setItemModel(QStandardItemModel *model)
|
||||
{
|
||||
if (!m_modelFilterItems) {
|
||||
m_modelFilterItems = new DefaultItemFilterProxyModel(this);
|
||||
connect(m_modelFilterItems, SIGNAL(searchTermChanged(QString)), this, SLOT(slotSearchTermChanged(QString)));
|
||||
connect(m_modelFilterItems, SIGNAL(searchTermChanged(QString)),
|
||||
this, SLOT(slotSearchTermChanged(QString)));
|
||||
}
|
||||
|
||||
m_modelItems = model;
|
||||
@ -127,7 +128,7 @@ void KCategorizedItemsView::setItemModel(QStandardItemModel * model)
|
||||
}
|
||||
}
|
||||
|
||||
void KCategorizedItemsView::searchTermChanged(const QString & text)
|
||||
void KCategorizedItemsView::searchTermChanged(const QString &text)
|
||||
{
|
||||
kDebug() << "EVENT\n" << text;
|
||||
if (m_modelFilterItems) {
|
||||
@ -143,31 +144,31 @@ void KCategorizedItemsView::filterChanged(int index)
|
||||
}
|
||||
}
|
||||
|
||||
void KCategorizedItemsView::itemActivated( const QModelIndex& index )
|
||||
void KCategorizedItemsView::itemActivated(const QModelIndex &index)
|
||||
{
|
||||
// don't emit activated signal for "favicon" and "remove applet"
|
||||
// columns so double clicking on these columns won't unexpectedly
|
||||
// add an applet to the containment
|
||||
if ( index.column() == 1 || index.column() == 2 ) {
|
||||
if (index.column() == 1 || index.column() == 2) {
|
||||
return;
|
||||
}
|
||||
|
||||
emit activated(index);
|
||||
}
|
||||
|
||||
void KCategorizedItemsView::itemDoubleClicked(const QModelIndex& index)
|
||||
void KCategorizedItemsView::itemDoubleClicked(const QModelIndex &index)
|
||||
{
|
||||
// don't emit activated signal for "favicon" and "remove applet"
|
||||
// columns so double clicking on these columns won't unexpectedly
|
||||
// add an applet to the containment
|
||||
if ( index.column() == 1 || index.column() == 2 ) {
|
||||
if (index.column() == 1 || index.column() == 2) {
|
||||
return;
|
||||
}
|
||||
|
||||
emit doubleClicked(index);
|
||||
}
|
||||
|
||||
void KCategorizedItemsView::slotSearchTermChanged( const QString& term )
|
||||
void KCategorizedItemsView::slotSearchTermChanged(const QString &term)
|
||||
{
|
||||
updateColumnsWidth();
|
||||
}
|
||||
@ -185,23 +186,25 @@ void KCategorizedItemsView::updateColumnsWidth(bool force)
|
||||
itemsView->setColumnWidth(2, m_delegate->columnWidth(2, m_viewWidth));
|
||||
}
|
||||
|
||||
void KCategorizedItemsView::addEmblem(const QString & title, const QIcon & icon, const Filter & filter) {
|
||||
void KCategorizedItemsView::addEmblem(const QString &title, const QIcon &icon,
|
||||
const Filter &filter)
|
||||
{
|
||||
m_emblems[title] = QPair<Filter, QIcon>(filter, icon);
|
||||
}
|
||||
|
||||
void KCategorizedItemsView::clearEmblems() {
|
||||
void KCategorizedItemsView::clearEmblems()
|
||||
{
|
||||
m_emblems.clear();
|
||||
}
|
||||
|
||||
AbstractItem * KCategorizedItemsView::getItemByProxyIndex(const QModelIndex & index) const {
|
||||
return (AbstractItem *) m_modelItems->itemFromIndex(
|
||||
m_modelFilterItems->mapToSource(index)
|
||||
);
|
||||
AbstractItem *KCategorizedItemsView::getItemByProxyIndex(const QModelIndex &index) const
|
||||
{
|
||||
return (AbstractItem *)m_modelItems->itemFromIndex(m_modelFilterItems->mapToSource(index));
|
||||
}
|
||||
|
||||
|
||||
QList < AbstractItem * > KCategorizedItemsView::selectedItems() const {
|
||||
QList < AbstractItem * > items;
|
||||
QList <AbstractItem *> KCategorizedItemsView::selectedItems() const
|
||||
{
|
||||
QList <AbstractItem *> items;
|
||||
foreach (const QModelIndex &index, itemsView->selectionModel()->selectedIndexes()) {
|
||||
if (index.column() == 0) {
|
||||
items << getItemByProxyIndex(index);
|
||||
|
@ -35,65 +35,65 @@ class KCategorizedItemsViewDelegate;
|
||||
* 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:
|
||||
|
||||
explicit KCategorizedItemsView(QWidget * parent = 0, Qt::WindowFlags f = 0);
|
||||
explicit KCategorizedItemsView(QWidget *parent = 0, Qt::WindowFlags f = 0);
|
||||
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
|
||||
void setFilterModel(QStandardItemModel *model); ///< Sets the filters model
|
||||
void setItemModel(QStandardItemModel *model); ///< Sets the item model, as mentioned items must implement AbstractItem class
|
||||
|
||||
void addEmblem(const QString & title, const QIcon & icon, const Filter & filter);
|
||||
void addEmblem(const QString &title, const QIcon &icon, const Filter &filter);
|
||||
void clearEmblems();
|
||||
|
||||
QList < AbstractItem * > selectedItems() const;
|
||||
|
||||
protected:
|
||||
virtual void resizeEvent ( QResizeEvent * event );
|
||||
virtual bool event ( QEvent * event );
|
||||
virtual void resizeEvent (QResizeEvent *event) ;
|
||||
virtual bool event (QEvent *event);
|
||||
|
||||
protected slots:
|
||||
void searchTermChanged(const QString &text);
|
||||
void filterChanged(int index);
|
||||
|
||||
private slots:
|
||||
void itemActivated( const QModelIndex& index );
|
||||
void itemDoubleClicked( const QModelIndex& index );
|
||||
void slotSearchTermChanged( const QString& term );
|
||||
void itemActivated(const QModelIndex &index);
|
||||
void itemDoubleClicked(const QModelIndex &index);
|
||||
void slotSearchTermChanged(const QString &term);
|
||||
|
||||
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 );
|
||||
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:
|
||||
void updateColumnsWidth(bool force = false);
|
||||
|
||||
QStandardItemModel * m_modelCategories;
|
||||
QStandardItemModel * m_modelFilters;
|
||||
QStandardItemModel * m_modelItems;
|
||||
QStandardItemModel *m_modelCategories;
|
||||
QStandardItemModel *m_modelFilters;
|
||||
QStandardItemModel *m_modelItems;
|
||||
|
||||
DefaultItemFilterProxyModel * m_modelFilterItems;
|
||||
KCategorizedItemsViewDelegate * m_delegate;
|
||||
DefaultItemFilterProxyModel *m_modelFilterItems;
|
||||
KCategorizedItemsViewDelegate *m_delegate;
|
||||
|
||||
int m_viewWidth;
|
||||
|
||||
QMap < QString, QPair < Filter, QIcon > > m_emblems;
|
||||
AbstractItem * getItemByProxyIndex(const QModelIndex & index) const;
|
||||
AbstractItem *getItemByProxyIndex(const QModelIndex &index) const;
|
||||
|
||||
friend class KCategorizedItemsViewDelegate;
|
||||
friend class CustomDragTreeView;
|
||||
|
@ -82,8 +82,9 @@ int KCategorizedItemsViewDelegate::calcItemHeight(const QStyleOptionViewItem &op
|
||||
return qMax(textHeight, MAIN_ICON_SIZE) + 2 * UNIVERSAL_PADDING;
|
||||
}
|
||||
|
||||
void KCategorizedItemsViewDelegate::paintColMain(QPainter *painter,
|
||||
const QStyleOptionViewItem &option, const KCategorizedItemsViewModels::AbstractItem * item) const
|
||||
void KCategorizedItemsViewDelegate::paintColMain(
|
||||
QPainter *painter, const QStyleOptionViewItem &option,
|
||||
const KCategorizedItemsViewModels::AbstractItem *item) const
|
||||
{
|
||||
const int left = option.rect.left();
|
||||
const int top = option.rect.top();
|
||||
@ -128,27 +129,32 @@ void KCategorizedItemsViewDelegate::paintColMain(QPainter *painter,
|
||||
Qt::AlignTop | Qt::AlignLeft, description);
|
||||
|
||||
// Main icon
|
||||
item->icon().paint(&p,
|
||||
leftToRight ? left + UNIVERSAL_PADDING : left + width - UNIVERSAL_PADDING - MAIN_ICON_SIZE,
|
||||
top + UNIVERSAL_PADDING,
|
||||
MAIN_ICON_SIZE, MAIN_ICON_SIZE, Qt::AlignCenter, iconMode);
|
||||
item->icon().paint(
|
||||
&p,
|
||||
leftToRight ? left + UNIVERSAL_PADDING : left + width - UNIVERSAL_PADDING - MAIN_ICON_SIZE,
|
||||
top + UNIVERSAL_PADDING,
|
||||
MAIN_ICON_SIZE,
|
||||
MAIN_ICON_SIZE,
|
||||
Qt::AlignCenter, iconMode);
|
||||
|
||||
// Counting the number of emblems for this item
|
||||
int emblemCount = 0;
|
||||
QPair < Filter, QIcon > emblem;
|
||||
foreach (emblem, m_parent->m_emblems) {
|
||||
if (item->passesFiltering(emblem.first)) ++emblemCount;
|
||||
if (item->passesFiltering(emblem.first)) {
|
||||
++emblemCount;
|
||||
}
|
||||
}
|
||||
|
||||
// Gradient part of the background - fading of the text at the end
|
||||
if (leftToRight) {
|
||||
gradient = QLinearGradient(left + width - UNIVERSAL_PADDING - FADE_LENGTH, 0,
|
||||
left + width - UNIVERSAL_PADDING, 0);
|
||||
gradient = QLinearGradient(left + width - UNIVERSAL_PADDING - FADE_LENGTH, 0,
|
||||
left + width - UNIVERSAL_PADDING, 0);
|
||||
gradient.setColorAt(0, Qt::white);
|
||||
gradient.setColorAt(1, Qt::transparent);
|
||||
} else {
|
||||
gradient = QLinearGradient(left + UNIVERSAL_PADDING, 0,
|
||||
left + UNIVERSAL_PADDING + FADE_LENGTH, 0);
|
||||
gradient = QLinearGradient(left + UNIVERSAL_PADDING, 0,
|
||||
left + UNIVERSAL_PADDING + FADE_LENGTH, 0);
|
||||
gradient.setColorAt(0, Qt::transparent);
|
||||
gradient.setColorAt(1, Qt::white);
|
||||
}
|
||||
@ -158,15 +164,15 @@ void KCategorizedItemsViewDelegate::paintColMain(QPainter *painter,
|
||||
p.fillRect(paintRect, gradient);
|
||||
|
||||
if (leftToRight) {
|
||||
gradient.setStart(left + width
|
||||
- emblemCount * (UNIVERSAL_PADDING + EMBLEM_ICON_SIZE) - FADE_LENGTH, 0);
|
||||
gradient.setFinalStop(left + width
|
||||
- emblemCount * (UNIVERSAL_PADDING + EMBLEM_ICON_SIZE), 0);
|
||||
gradient.setStart(
|
||||
left + width - emblemCount * (UNIVERSAL_PADDING + EMBLEM_ICON_SIZE) - FADE_LENGTH, 0);
|
||||
gradient.setFinalStop(
|
||||
left + width - emblemCount * (UNIVERSAL_PADDING + EMBLEM_ICON_SIZE), 0);
|
||||
} else {
|
||||
gradient.setStart(left + UNIVERSAL_PADDING
|
||||
+ emblemCount * (UNIVERSAL_PADDING + EMBLEM_ICON_SIZE), 0);
|
||||
gradient.setFinalStop(left + UNIVERSAL_PADDING
|
||||
+ emblemCount * (UNIVERSAL_PADDING + EMBLEM_ICON_SIZE) + FADE_LENGTH, 0);
|
||||
gradient.setStart(
|
||||
left + UNIVERSAL_PADDING + emblemCount * (UNIVERSAL_PADDING + EMBLEM_ICON_SIZE), 0);
|
||||
gradient.setFinalStop(
|
||||
left + UNIVERSAL_PADDING + emblemCount * (UNIVERSAL_PADDING + EMBLEM_ICON_SIZE) + FADE_LENGTH, 0);
|
||||
}
|
||||
paintRect.setHeight(UNIVERSAL_PADDING + MAIN_ICON_SIZE / 2);
|
||||
p.fillRect(paintRect, gradient);
|
||||
@ -176,8 +182,8 @@ void KCategorizedItemsViewDelegate::paintColMain(QPainter *painter,
|
||||
int emblemLeft = leftToRight ? (left + width - EMBLEM_ICON_SIZE) : left; // - FAV_ICON_SIZE - 2 * UNIVERSAL_PADDING
|
||||
foreach (emblem, m_parent->m_emblems) {
|
||||
if (item->passesFiltering(emblem.first)) {
|
||||
emblem.second.paint(&p,
|
||||
emblemLeft, top + UNIVERSAL_PADDING,
|
||||
emblem.second.paint(&p,
|
||||
emblemLeft, top + UNIVERSAL_PADDING,
|
||||
EMBLEM_ICON_SIZE, EMBLEM_ICON_SIZE, Qt::AlignCenter, iconMode);
|
||||
if (leftToRight) {
|
||||
emblemLeft -= UNIVERSAL_PADDING + EMBLEM_ICON_SIZE;
|
||||
@ -191,8 +197,9 @@ void KCategorizedItemsViewDelegate::paintColMain(QPainter *painter,
|
||||
painter->drawPixmap(option.rect.topLeft(), pixmap);
|
||||
}
|
||||
|
||||
void KCategorizedItemsViewDelegate::paintColFav(QPainter *painter,
|
||||
const QStyleOptionViewItem &option, const KCategorizedItemsViewModels::AbstractItem * item) const
|
||||
void KCategorizedItemsViewDelegate::paintColFav(
|
||||
QPainter *painter, const QStyleOptionViewItem &option,
|
||||
const KCategorizedItemsViewModels::AbstractItem *item) const
|
||||
{
|
||||
int left = option.rect.left();
|
||||
int top = option.rect.top();
|
||||
@ -200,30 +207,43 @@ void KCategorizedItemsViewDelegate::paintColFav(QPainter *painter,
|
||||
|
||||
// Painting favorite icon column
|
||||
|
||||
if (! (option.state & QStyle::State_MouseOver) && m_onFavoriteIconItem == item)
|
||||
if (! (option.state & QStyle::State_MouseOver) && m_onFavoriteIconItem == item) {
|
||||
m_onFavoriteIconItem = NULL;
|
||||
}
|
||||
|
||||
QIcon::Mode iconMode = QIcon::Normal;
|
||||
if (!item->isFavorite()) {
|
||||
iconMode = QIcon::Disabled;
|
||||
} else if (option.state & QStyle::State_MouseOver) {
|
||||
iconMode = QIcon::Active;
|
||||
}
|
||||
}
|
||||
|
||||
m_favoriteIcon.paint(painter,
|
||||
left + width - FAV_ICON_SIZE - UNIVERSAL_PADDING, top + UNIVERSAL_PADDING,
|
||||
FAV_ICON_SIZE, FAV_ICON_SIZE, Qt::AlignCenter, iconMode);
|
||||
m_favoriteIcon.paint(
|
||||
painter,
|
||||
left + width - FAV_ICON_SIZE - UNIVERSAL_PADDING,
|
||||
top + UNIVERSAL_PADDING,
|
||||
FAV_ICON_SIZE,
|
||||
FAV_ICON_SIZE,
|
||||
Qt::AlignCenter,
|
||||
iconMode);
|
||||
|
||||
const KIcon & icon = (item->isFavorite())? m_removeIcon : m_favoriteAddIcon;
|
||||
const KIcon &icon = (item->isFavorite())? m_removeIcon : m_favoriteAddIcon;
|
||||
|
||||
if ((option.state & QStyle::State_MouseOver) && (m_onFavoriteIconItem != item))
|
||||
icon.paint(painter,
|
||||
left + width - EMBLEM_ICON_SIZE - UNIVERSAL_PADDING, top + UNIVERSAL_PADDING,
|
||||
EMBLEM_ICON_SIZE, EMBLEM_ICON_SIZE, Qt::AlignCenter, iconMode);
|
||||
if ((option.state & QStyle::State_MouseOver) && (m_onFavoriteIconItem != item)) {
|
||||
icon.paint(
|
||||
painter,
|
||||
left + width - EMBLEM_ICON_SIZE - UNIVERSAL_PADDING,
|
||||
top + UNIVERSAL_PADDING,
|
||||
EMBLEM_ICON_SIZE,
|
||||
EMBLEM_ICON_SIZE,
|
||||
Qt::AlignCenter,
|
||||
iconMode);
|
||||
}
|
||||
}
|
||||
|
||||
void KCategorizedItemsViewDelegate::paintColRemove(QPainter *painter,
|
||||
const QStyleOptionViewItem &option, const KCategorizedItemsViewModels::AbstractItem * item) const
|
||||
void KCategorizedItemsViewDelegate::paintColRemove(
|
||||
QPainter *painter, const QStyleOptionViewItem &option,
|
||||
const KCategorizedItemsViewModels::AbstractItem *item) const
|
||||
{
|
||||
// Painting remove icon column
|
||||
int running = item->running();
|
||||
@ -238,10 +258,10 @@ void KCategorizedItemsViewDelegate::paintColRemove(QPainter *painter,
|
||||
QIcon::Mode iconMode = QIcon::Normal;
|
||||
if (option.state & QStyle::State_MouseOver) {
|
||||
iconMode = QIcon::Active;
|
||||
}
|
||||
}
|
||||
|
||||
m_removeIcon.paint(painter,
|
||||
left + width - FAV_ICON_SIZE - UNIVERSAL_PADDING, top + UNIVERSAL_PADDING,
|
||||
m_removeIcon.paint(painter,
|
||||
left + width - FAV_ICON_SIZE - UNIVERSAL_PADDING, top + UNIVERSAL_PADDING,
|
||||
FAV_ICON_SIZE, FAV_ICON_SIZE, Qt::AlignCenter, iconMode);
|
||||
|
||||
if (running == 1) {
|
||||
@ -253,19 +273,18 @@ void KCategorizedItemsViewDelegate::paintColRemove(QPainter *painter,
|
||||
painter->setPen(foregroundColor);
|
||||
painter->setFont(option.font);
|
||||
painter->drawText(
|
||||
left + UNIVERSAL_PADDING, //FIXME might be wrong
|
||||
top + UNIVERSAL_PADDING + MAIN_ICON_SIZE / 2,
|
||||
width - 2 * UNIVERSAL_PADDING, MAIN_ICON_SIZE / 2,
|
||||
Qt::AlignCenter, QString::number(running));
|
||||
left + UNIVERSAL_PADDING, //FIXME might be wrong
|
||||
top + UNIVERSAL_PADDING + MAIN_ICON_SIZE / 2,
|
||||
width - 2 * UNIVERSAL_PADDING, MAIN_ICON_SIZE / 2,
|
||||
Qt::AlignCenter, QString::number(running));
|
||||
}
|
||||
|
||||
bool KCategorizedItemsViewDelegate::editorEvent(QEvent *event,
|
||||
QAbstractItemModel *model,
|
||||
const QStyleOptionViewItem &option,
|
||||
const QModelIndex &index)
|
||||
bool KCategorizedItemsViewDelegate::editorEvent(
|
||||
QEvent *event, QAbstractItemModel *model,
|
||||
const QStyleOptionViewItem &option, const QModelIndex &index)
|
||||
{
|
||||
if (event->type() == QEvent::MouseButtonPress) {
|
||||
KCategorizedItemsViewModels::AbstractItem * item = getItemByProxyIndex(index);
|
||||
KCategorizedItemsViewModels::AbstractItem *item = getItemByProxyIndex(index);
|
||||
if (index.column() == 1) {
|
||||
m_onFavoriteIconItem = item;
|
||||
item->setFavorite(!item->isFavorite());
|
||||
@ -281,7 +300,7 @@ bool KCategorizedItemsViewDelegate::editorEvent(QEvent *event,
|
||||
}
|
||||
|
||||
QSize KCategorizedItemsViewDelegate::sizeHint(const QStyleOptionViewItem &option,
|
||||
const QModelIndex &index ) const
|
||||
const QModelIndex &index) const
|
||||
{
|
||||
int width = (index.column() == 0) ? 0 : FAV_ICON_SIZE;
|
||||
return QSize(width, calcItemHeight(option));
|
||||
@ -290,21 +309,22 @@ QSize KCategorizedItemsViewDelegate::sizeHint(const QStyleOptionViewItem &option
|
||||
int KCategorizedItemsViewDelegate::columnWidth (int column, int viewWidth) const {
|
||||
if (column != 0) {
|
||||
return FAV_ICON_SIZE + 2 * UNIVERSAL_PADDING;
|
||||
} else return viewWidth - 2 * columnWidth(1, viewWidth);
|
||||
} else {
|
||||
return viewWidth - 2 * columnWidth(1, viewWidth);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
KCategorizedItemsViewModels::AbstractItem * KCategorizedItemsViewDelegate::getItemByProxyIndex(const QModelIndex & index) const {
|
||||
return (AbstractItem *) m_parent->m_modelItems->itemFromIndex(
|
||||
m_parent->m_modelFilterItems->mapToSource(index)
|
||||
);
|
||||
KCategorizedItemsViewModels::AbstractItem *KCategorizedItemsViewDelegate::getItemByProxyIndex(
|
||||
const QModelIndex &index) const
|
||||
{
|
||||
return (AbstractItem *)m_parent->m_modelItems->itemFromIndex(m_parent->m_modelFilterItems->mapToSource(index));
|
||||
}
|
||||
|
||||
// KCategorizedItemsViewFilterDelegate
|
||||
|
||||
|
||||
KCategorizedItemsViewFilterDelegate::KCategorizedItemsViewFilterDelegate(QObject *parent)
|
||||
: QItemDelegate(parent) {
|
||||
: QItemDelegate(parent)
|
||||
{
|
||||
kDebug() << "KCategorizedItemsViewFilterDelegate(QObject *parent)\n";
|
||||
|
||||
}
|
||||
@ -318,13 +338,15 @@ void KCategorizedItemsViewFilterDelegate::paint(QPainter *painter,
|
||||
QStyleOptionViewItem separatorOption(option);
|
||||
int height = QItemDelegate::sizeHint(option, index).height() + 2 * DROPDOWN_PADDING;
|
||||
|
||||
separatorOption.state &= ~(QStyle::State_Selected
|
||||
| QStyle::State_MouseOver | QStyle::State_HasFocus);
|
||||
separatorOption.rect.setTop(separatorOption.rect.top() + separatorOption.rect.height() - height);
|
||||
separatorOption.state &= ~(QStyle::State_Selected |
|
||||
QStyle::State_MouseOver |
|
||||
QStyle::State_HasFocus);
|
||||
separatorOption.rect.setTop(
|
||||
separatorOption.rect.top() + separatorOption.rect.height() - height);
|
||||
separatorOption.rect.setHeight(height);
|
||||
QItemDelegate::paint(painter, separatorOption, index);
|
||||
/*painter->drawLine(
|
||||
option.rect.left(),
|
||||
option.rect.left(),
|
||||
option.rect.top() + 1,
|
||||
option.rect.left() + option.rect.width(),
|
||||
option.rect.top() + 1);*/
|
||||
@ -332,7 +354,7 @@ void KCategorizedItemsViewFilterDelegate::paint(QPainter *painter,
|
||||
}
|
||||
|
||||
QSize KCategorizedItemsViewFilterDelegate::sizeHint(const QStyleOptionViewItem &option,
|
||||
const QModelIndex &index ) const
|
||||
const QModelIndex &index) const
|
||||
{
|
||||
QSize size = QItemDelegate::sizeHint(option, index);
|
||||
if (index.flags() & Qt::ItemIsEnabled) {
|
||||
|
@ -39,14 +39,15 @@ namespace KCategorizedItemsViewModels {
|
||||
class KCategorizedItemsViewDelegate: public QItemDelegate
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
|
||||
public:
|
||||
KCategorizedItemsViewDelegate(QObject *parent = 0);
|
||||
|
||||
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
||||
QSize sizeHint ( const QStyleOptionViewItem & option, const QModelIndex & index ) const;
|
||||
|
||||
void paint(QPainter *painter, const QStyleOptionViewItem &option,
|
||||
const QModelIndex &index) const;
|
||||
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
||||
int columnWidth (int column, int viewWidth) const;
|
||||
|
||||
|
||||
bool editorEvent(QEvent *event,
|
||||
QAbstractItemModel *model,
|
||||
const QStyleOptionViewItem &option,
|
||||
@ -55,23 +56,22 @@ public:
|
||||
Q_SIGNALS:
|
||||
void destroyApplets(const QString name);
|
||||
private:
|
||||
|
||||
KCategorizedItemsView * m_parent;
|
||||
|
||||
KCategorizedItemsView *m_parent;
|
||||
KIcon m_favoriteIcon;
|
||||
KIcon m_favoriteAddIcon;
|
||||
KIcon m_removeIcon;
|
||||
|
||||
mutable KCategorizedItemsViewModels::AbstractItem * m_onFavoriteIconItem;
|
||||
|
||||
|
||||
KCategorizedItemsViewModels::AbstractItem * getItemByProxyIndex(const QModelIndex & index) const;
|
||||
void paintColMain(QPainter *painter,
|
||||
const QStyleOptionViewItem &option, const KCategorizedItemsViewModels::AbstractItem * item) const;
|
||||
void paintColFav(QPainter *painter,
|
||||
const QStyleOptionViewItem &option, const KCategorizedItemsViewModels::AbstractItem * item) const;
|
||||
void paintColRemove(QPainter *painter,
|
||||
const QStyleOptionViewItem &option, const KCategorizedItemsViewModels::AbstractItem * item) const;
|
||||
|
||||
|
||||
mutable KCategorizedItemsViewModels::AbstractItem *m_onFavoriteIconItem;
|
||||
|
||||
KCategorizedItemsViewModels::AbstractItem *getItemByProxyIndex(const QModelIndex & index) const;
|
||||
void paintColMain(QPainter *painter, const QStyleOptionViewItem &option,
|
||||
const KCategorizedItemsViewModels::AbstractItem * item) const;
|
||||
void paintColFav(QPainter *painter, const QStyleOptionViewItem &option,
|
||||
const KCategorizedItemsViewModels::AbstractItem * item) const;
|
||||
void paintColRemove(QPainter *painter, const QStyleOptionViewItem &option,
|
||||
const KCategorizedItemsViewModels::AbstractItem * item) const;
|
||||
|
||||
int calcItemHeight(const QStyleOptionViewItem &option) const;
|
||||
};
|
||||
|
||||
@ -81,12 +81,13 @@ private:
|
||||
class KCategorizedItemsViewFilterDelegate: public QItemDelegate
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
|
||||
public:
|
||||
KCategorizedItemsViewFilterDelegate(QObject *parent = 0);
|
||||
|
||||
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
||||
QSize sizeHint ( const QStyleOptionViewItem & option, const QModelIndex & index ) const;
|
||||
|
||||
void paint(QPainter *painter, const QStyleOptionViewItem &option,
|
||||
const QModelIndex &index) const;
|
||||
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
||||
};
|
||||
|
||||
#endif /*KCATEGORIZEDITEMSVIEWDELEGATE_H_*/
|
||||
|
@ -44,35 +44,38 @@ int AbstractItem::running() const
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool AbstractItem::matches(const QString & pattern) const
|
||||
bool AbstractItem::matches(const QString &pattern) const
|
||||
{
|
||||
return name().contains(pattern, Qt::CaseInsensitive) || description().contains(pattern, Qt::CaseInsensitive);
|
||||
return
|
||||
name().contains(pattern, Qt::CaseInsensitive) ||
|
||||
description().contains(pattern, Qt::CaseInsensitive);
|
||||
}
|
||||
|
||||
// DefaultFilterModel
|
||||
|
||||
DefaultFilterModel::DefaultFilterModel(QObject * parent) :
|
||||
DefaultFilterModel::DefaultFilterModel(QObject *parent) :
|
||||
QStandardItemModel(0, 1, parent)
|
||||
{
|
||||
setHeaderData(1, Qt::Horizontal, i18n("Filters"));
|
||||
}
|
||||
|
||||
void DefaultFilterModel::addFilter(const QString & caption,
|
||||
const Filter & filter, const KIcon & icon)
|
||||
void DefaultFilterModel::addFilter(const QString &caption, const Filter &filter, const KIcon &icon)
|
||||
{
|
||||
QList<QStandardItem *> newRow;
|
||||
QStandardItem * item = new QStandardItem(caption);
|
||||
QStandardItem *item = new QStandardItem(caption);
|
||||
item->setData(qVariantFromValue<Filter>(filter));
|
||||
if (!icon.isNull()) item->setIcon(icon);
|
||||
if (!icon.isNull()) {
|
||||
item->setIcon(icon);
|
||||
}
|
||||
|
||||
newRow << item;
|
||||
appendRow(newRow);
|
||||
}
|
||||
|
||||
void DefaultFilterModel::addSeparator(const QString & caption)
|
||||
void DefaultFilterModel::addSeparator(const QString &caption)
|
||||
{
|
||||
QList<QStandardItem *> newRow;
|
||||
QStandardItem * item = new QStandardItem(caption);
|
||||
QStandardItem *item = new QStandardItem(caption);
|
||||
item->setEnabled(false);
|
||||
|
||||
newRow << item;
|
||||
@ -81,12 +84,12 @@ void DefaultFilterModel::addSeparator(const QString & caption)
|
||||
|
||||
// DefaultItemFilterProxyModel
|
||||
|
||||
DefaultItemFilterProxyModel::DefaultItemFilterProxyModel(QObject * parent) :
|
||||
DefaultItemFilterProxyModel::DefaultItemFilterProxyModel(QObject *parent) :
|
||||
QSortFilterProxyModel(parent), m_innerModel(parent)
|
||||
{
|
||||
}
|
||||
|
||||
void DefaultItemFilterProxyModel::setSourceModel(QAbstractItemModel * sourceModel)
|
||||
void DefaultItemFilterProxyModel::setSourceModel(QAbstractItemModel *sourceModel)
|
||||
{
|
||||
QStandardItemModel *model = qobject_cast<QStandardItemModel*>(sourceModel);
|
||||
|
||||
@ -99,18 +102,18 @@ void DefaultItemFilterProxyModel::setSourceModel(QAbstractItemModel * sourceMode
|
||||
QSortFilterProxyModel::setSourceModel(&m_innerModel);
|
||||
}
|
||||
|
||||
QStandardItemModel * DefaultItemFilterProxyModel::sourceModel() const
|
||||
QStandardItemModel *DefaultItemFilterProxyModel::sourceModel() const
|
||||
{
|
||||
return m_innerModel.sourceModel();
|
||||
}
|
||||
|
||||
int DefaultItemFilterProxyModel::columnCount(const QModelIndex& index) const
|
||||
int DefaultItemFilterProxyModel::columnCount(const QModelIndex &index) const
|
||||
{
|
||||
Q_UNUSED(index);
|
||||
return 3;
|
||||
}
|
||||
|
||||
QVariant DefaultItemFilterProxyModel::data(const QModelIndex & index, int role) const
|
||||
QVariant DefaultItemFilterProxyModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
return m_innerModel.data(index, (index.column() == 1), role);
|
||||
}
|
||||
@ -118,31 +121,34 @@ QVariant DefaultItemFilterProxyModel::data(const QModelIndex & index, int role)
|
||||
bool DefaultItemFilterProxyModel::filterAcceptsRow(int sourceRow,
|
||||
const QModelIndex &sourceParent) const
|
||||
{
|
||||
QStandardItemModel * model = (QStandardItemModel *) sourceModel();
|
||||
QStandardItemModel *model = (QStandardItemModel *) sourceModel();
|
||||
|
||||
QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
|
||||
|
||||
AbstractItem * item = (AbstractItem *) model->itemFromIndex(index);
|
||||
AbstractItem *item = (AbstractItem *) model->itemFromIndex(index);
|
||||
//kDebug() << "ITEM " << (item ? "IS NOT " : "IS") << " NULL\n";
|
||||
|
||||
return (m_filter.first.isEmpty() || item->passesFiltering(m_filter))
|
||||
&&(m_searchPattern.isEmpty() || item->matches(m_searchPattern));
|
||||
return
|
||||
(m_filter.first.isEmpty() || item->passesFiltering(m_filter)) &&
|
||||
(m_searchPattern.isEmpty() || item->matches(m_searchPattern));
|
||||
}
|
||||
|
||||
bool DefaultItemFilterProxyModel::lessThan(const QModelIndex &left,
|
||||
const QModelIndex &right) const
|
||||
{
|
||||
return sourceModel()->data(left).toString().localeAwareCompare(sourceModel()->data(right).toString()) < 0;
|
||||
return
|
||||
sourceModel()->data(left).toString().localeAwareCompare(
|
||||
sourceModel()->data(right).toString()) < 0;
|
||||
}
|
||||
|
||||
void DefaultItemFilterProxyModel::setSearch(const QString & pattern)
|
||||
void DefaultItemFilterProxyModel::setSearch(const QString &pattern)
|
||||
{
|
||||
m_searchPattern = pattern;
|
||||
invalidateFilter();
|
||||
emit searchTermChanged(pattern);
|
||||
}
|
||||
|
||||
void DefaultItemFilterProxyModel::setFilter(const Filter & filter)
|
||||
void DefaultItemFilterProxyModel::setFilter(const Filter &filter)
|
||||
{
|
||||
m_filter = filter;
|
||||
invalidateFilter();
|
||||
@ -150,60 +156,62 @@ void DefaultItemFilterProxyModel::setFilter(const Filter & filter)
|
||||
|
||||
// DefaultItemFilterProxyModel::InnerProxyModel
|
||||
|
||||
DefaultItemFilterProxyModel::InnerProxyModel::InnerProxyModel(QObject * parent) :
|
||||
DefaultItemFilterProxyModel::InnerProxyModel::InnerProxyModel(QObject *parent) :
|
||||
QAbstractItemModel(parent), m_sourceModel(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
Qt::ItemFlags DefaultItemFilterProxyModel::InnerProxyModel::flags(
|
||||
const QModelIndex & index) const
|
||||
Qt::ItemFlags DefaultItemFilterProxyModel::InnerProxyModel::flags(const QModelIndex &index) const
|
||||
{
|
||||
if (!m_sourceModel)
|
||||
if (!m_sourceModel) {
|
||||
return 0;
|
||||
}
|
||||
return m_sourceModel->flags(index);
|
||||
}
|
||||
|
||||
QVariant DefaultItemFilterProxyModel::InnerProxyModel::data(
|
||||
const QModelIndex & index, bool favoriteColumn, int role) const
|
||||
const QModelIndex &index, bool favoriteColumn, int role) const
|
||||
{
|
||||
Q_UNUSED(favoriteColumn);
|
||||
return data(index, role);
|
||||
}
|
||||
|
||||
QVariant DefaultItemFilterProxyModel::InnerProxyModel::data(
|
||||
const QModelIndex & index, int role) const
|
||||
const QModelIndex &index, int role) const
|
||||
{
|
||||
if (!m_sourceModel)
|
||||
if (!m_sourceModel) {
|
||||
return QVariant();
|
||||
}
|
||||
return m_sourceModel->data(index, role);
|
||||
}
|
||||
|
||||
QVariant DefaultItemFilterProxyModel::InnerProxyModel::headerData(int section,
|
||||
Qt::Orientation orientation, int role) const
|
||||
QVariant DefaultItemFilterProxyModel::InnerProxyModel::headerData(
|
||||
int section, Qt::Orientation orientation, int role) const
|
||||
{
|
||||
Q_UNUSED(orientation);
|
||||
Q_UNUSED(role);
|
||||
return QVariant(section);
|
||||
}
|
||||
|
||||
int DefaultItemFilterProxyModel::InnerProxyModel::rowCount(
|
||||
const QModelIndex & parent) const
|
||||
int DefaultItemFilterProxyModel::InnerProxyModel::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
if (!m_sourceModel)
|
||||
if (!m_sourceModel) {
|
||||
return 0;
|
||||
}
|
||||
return m_sourceModel->rowCount(parent);
|
||||
}
|
||||
|
||||
bool DefaultItemFilterProxyModel::InnerProxyModel::setData(
|
||||
const QModelIndex & index, const QVariant & value, int role)
|
||||
const QModelIndex &index, const QVariant &value, int role)
|
||||
{
|
||||
if (!m_sourceModel)
|
||||
if (!m_sourceModel) {
|
||||
return false;
|
||||
}
|
||||
return m_sourceModel->setData(index, value, role);
|
||||
}
|
||||
|
||||
bool DefaultItemFilterProxyModel::InnerProxyModel::setHeaderData(int section,
|
||||
Qt::Orientation orientation, const QVariant & value, int role)
|
||||
bool DefaultItemFilterProxyModel::InnerProxyModel::setHeaderData(
|
||||
int section, Qt::Orientation orientation, const QVariant &value, int role)
|
||||
{
|
||||
Q_UNUSED(section);
|
||||
Q_UNUSED(value);
|
||||
@ -212,51 +220,51 @@ bool DefaultItemFilterProxyModel::InnerProxyModel::setHeaderData(int section,
|
||||
return false;
|
||||
}
|
||||
|
||||
QModelIndex DefaultItemFilterProxyModel::InnerProxyModel::index(int row,
|
||||
int column, const QModelIndex & parent) const
|
||||
QModelIndex DefaultItemFilterProxyModel::InnerProxyModel::index(
|
||||
int row, int column, const QModelIndex &parent) const
|
||||
{
|
||||
Q_UNUSED(column);
|
||||
if (!m_sourceModel)
|
||||
if (!m_sourceModel) {
|
||||
return QModelIndex();
|
||||
}
|
||||
return m_sourceModel->index(row, 0, parent);
|
||||
}
|
||||
|
||||
QModelIndex DefaultItemFilterProxyModel::InnerProxyModel::parent(
|
||||
const QModelIndex & index) const
|
||||
QModelIndex DefaultItemFilterProxyModel::InnerProxyModel::parent(const QModelIndex &index) const
|
||||
{
|
||||
if (!m_sourceModel)
|
||||
if (!m_sourceModel) {
|
||||
return QModelIndex();
|
||||
}
|
||||
return m_sourceModel->parent(index);
|
||||
}
|
||||
|
||||
QMimeData * DefaultItemFilterProxyModel::InnerProxyModel::mimeData(
|
||||
const QModelIndexList & indexes) const
|
||||
QMimeData *DefaultItemFilterProxyModel::InnerProxyModel::mimeData(
|
||||
const QModelIndexList &indexes) const
|
||||
{
|
||||
if (!m_sourceModel)
|
||||
if (!m_sourceModel) {
|
||||
return NULL;
|
||||
}
|
||||
return m_sourceModel->mimeData(indexes);
|
||||
}
|
||||
|
||||
int DefaultItemFilterProxyModel::InnerProxyModel::columnCount(
|
||||
const QModelIndex& index) const
|
||||
int DefaultItemFilterProxyModel::InnerProxyModel::columnCount(const QModelIndex &index) const
|
||||
{
|
||||
Q_UNUSED(index);
|
||||
return 3; //FIXME: a hardcoded magic number that appears in two places CANNOT be good
|
||||
}
|
||||
|
||||
void DefaultItemFilterProxyModel::InnerProxyModel::setSourceModel(
|
||||
QStandardItemModel * sourceModel)
|
||||
void DefaultItemFilterProxyModel::InnerProxyModel::setSourceModel(QStandardItemModel *sourceModel)
|
||||
{
|
||||
m_sourceModel = sourceModel;
|
||||
}
|
||||
|
||||
QStandardItemModel * DefaultItemFilterProxyModel::InnerProxyModel::sourceModel() const
|
||||
QStandardItemModel *DefaultItemFilterProxyModel::InnerProxyModel::sourceModel() const
|
||||
{
|
||||
return m_sourceModel;
|
||||
}
|
||||
|
||||
// DefaultItemModel
|
||||
|
||||
DefaultItemModel::DefaultItemModel(QObject * parent) :
|
||||
DefaultItemModel::DefaultItemModel(QObject *parent) :
|
||||
QStandardItemModel(parent) {}
|
||||
}
|
||||
|
@ -35,18 +35,18 @@ class AbstractItem : public QStandardItem
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Returns a localized string - name of the item
|
||||
* Returns a localized string - name of the item
|
||||
*/
|
||||
virtual QString name() const;
|
||||
|
||||
/**
|
||||
* Returns a localized string - description of the item
|
||||
* Returns a localized string - description of the item
|
||||
*/
|
||||
virtual QString description() const;
|
||||
|
||||
/**
|
||||
* Returns if the item is flagged as favorite
|
||||
* Default implementation checks if the item passes the Filter("favorite", "1") filter
|
||||
* Default implementation checks if the item passes the Filter("favorite", "1") filter
|
||||
*/
|
||||
virtual bool isFavorite() const;
|
||||
|
||||
@ -59,12 +59,12 @@ public:
|
||||
/**
|
||||
* Returns if the item contains string specified by pattern.
|
||||
* Default implementation checks whether name or description contain the
|
||||
* string (not needed to be exactly that string)
|
||||
* string (not needed to be exactly that string)
|
||||
*/
|
||||
virtual bool matches(const QString & pattern) const;
|
||||
virtual bool matches(const QString &pattern) const;
|
||||
|
||||
/**
|
||||
* sets the favorite flag for the item
|
||||
* sets the favorite flag for the item
|
||||
*/
|
||||
virtual void setFavorite(bool favorite) = 0;
|
||||
/**
|
||||
@ -73,9 +73,9 @@ public:
|
||||
virtual void setRunning(int count) = 0;
|
||||
|
||||
/**
|
||||
* Returns if the item passes the filter specified
|
||||
* Returns if the item passes the filter specified
|
||||
*/
|
||||
virtual bool passesFiltering(const Filter & filter) const = 0;
|
||||
virtual bool passesFiltering(const Filter &filter) const = 0;
|
||||
private:
|
||||
};
|
||||
|
||||
@ -85,20 +85,20 @@ private:
|
||||
class DefaultFilterModel : public QStandardItemModel
|
||||
{
|
||||
public:
|
||||
DefaultFilterModel(QObject * parent = 0);
|
||||
DefaultFilterModel(QObject *parent = 0);
|
||||
|
||||
/**
|
||||
* Adds a filter to the model
|
||||
* Adds a filter to the model
|
||||
* @param caption The localized string to be displayed as a name of the filter
|
||||
* @param filter The filter structure
|
||||
*/
|
||||
void addFilter(const QString & caption, const Filter & filter, const KIcon & icon = KIcon());
|
||||
void addFilter(const QString &caption, const Filter &filter, const KIcon &icon = KIcon());
|
||||
|
||||
/**
|
||||
* Adds a separator to the model
|
||||
* Adds a separator to the model
|
||||
* @param caption The localized string to be displayed as a name of the separator
|
||||
*/
|
||||
void addSeparator(const QString & caption);
|
||||
void addSeparator(const QString &caption);
|
||||
};
|
||||
|
||||
/**
|
||||
@ -109,21 +109,21 @@ class DefaultItemFilterProxyModel : public QSortFilterProxyModel
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
DefaultItemFilterProxyModel(QObject * parent = 0);
|
||||
DefaultItemFilterProxyModel(QObject *parent = 0);
|
||||
|
||||
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const;
|
||||
bool lessThan(const QModelIndex &left, const QModelIndex &right) const;
|
||||
|
||||
void setSearch(const QString & pattern);
|
||||
void setFilter(const Filter & filter);
|
||||
void setSearch(const QString &pattern);
|
||||
void setFilter(const Filter &filter);
|
||||
|
||||
void setSourceModel(QAbstractItemModel * sourceModel);
|
||||
void setSourceModel(QAbstractItemModel *sourceModel);
|
||||
|
||||
QStandardItemModel * sourceModel() const;
|
||||
QStandardItemModel *sourceModel() const;
|
||||
|
||||
int columnCount(const QModelIndex& index) const;
|
||||
int columnCount(const QModelIndex &index) const;
|
||||
|
||||
QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const;
|
||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
|
||||
|
||||
Q_SIGNALS:
|
||||
void searchTermChanged(const QString &term);
|
||||
@ -133,36 +133,35 @@ private:
|
||||
class InnerProxyModel : public QAbstractItemModel
|
||||
{
|
||||
public:
|
||||
InnerProxyModel(QObject * parent = 0);
|
||||
InnerProxyModel(QObject *parent = 0);
|
||||
|
||||
Qt::ItemFlags flags(const QModelIndex & index) const;
|
||||
Qt::ItemFlags flags(const QModelIndex &index) const;
|
||||
|
||||
QVariant data(const QModelIndex & index, bool favoriteColumn,
|
||||
int role = Qt::DisplayRole) const;
|
||||
QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const;
|
||||
bool setData(const QModelIndex & index, const QVariant & value,
|
||||
int role = Qt::EditRole);
|
||||
QVariant data(const QModelIndex &index, bool favoriteColumn,
|
||||
int role = Qt::DisplayRole) const;
|
||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
|
||||
bool setData(const QModelIndex &index, const QVariant &value,
|
||||
int role = Qt::EditRole);
|
||||
|
||||
QVariant headerData(int section, Qt::Orientation orientation,
|
||||
int role = Qt::DisplayRole) const;
|
||||
int role = Qt::DisplayRole) const;
|
||||
bool setHeaderData(int section, Qt::Orientation orientation,
|
||||
const QVariant & value, int role = Qt::EditRole);
|
||||
|
||||
int rowCount(const QModelIndex & parent = QModelIndex()) const;
|
||||
int columnCount(const QModelIndex& index) const;
|
||||
const QVariant &value, int role = Qt::EditRole);
|
||||
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
||||
int columnCount(const QModelIndex &index) const;
|
||||
|
||||
QModelIndex index(int row, int column,
|
||||
const QModelIndex & parent = QModelIndex()) const;
|
||||
QModelIndex parent(const QModelIndex & index) const;
|
||||
const QModelIndex &parent = QModelIndex()) const;
|
||||
QModelIndex parent(const QModelIndex &index) const;
|
||||
|
||||
QMimeData * mimeData(const QModelIndexList & indexes) const;
|
||||
QMimeData *mimeData(const QModelIndexList &indexes) const;
|
||||
|
||||
void setSourceModel(QStandardItemModel * sourceModel);
|
||||
QStandardItemModel * sourceModel() const;
|
||||
void setSourceModel(QStandardItemModel *sourceModel);
|
||||
QStandardItemModel *sourceModel() const;
|
||||
|
||||
private:
|
||||
QStandardItemModel * m_sourceModel;
|
||||
QStandardItemModel *m_sourceModel;
|
||||
};
|
||||
|
||||
Filter m_filter;
|
||||
@ -177,7 +176,7 @@ private:
|
||||
class DefaultItemModel : public QStandardItemModel
|
||||
{
|
||||
public:
|
||||
DefaultItemModel(QObject * parent = 0);
|
||||
DefaultItemModel(QObject *parent = 0);
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -83,7 +83,7 @@ OpenWidgetAssistant::OpenWidgetAssistant(QWidget *parent)
|
||||
addPage(m_filePage);
|
||||
|
||||
connect(this, SIGNAL(currentPageChanged(KPageWidgetItem*,KPageWidgetItem*)), SLOT(prepPage(KPageWidgetItem*,KPageWidgetItem*)));
|
||||
enableButton( KDialog::Help, false );
|
||||
enableButton(KDialog::Help, false);
|
||||
//connect( this, SIGNAL( helpClicked() ), this, SLOT( slotHelpClicked() ) );
|
||||
m_widgetTypeList->setFocus();
|
||||
resize(QSize(560, 400).expandedTo(minimumSizeHint()));
|
||||
@ -91,14 +91,15 @@ OpenWidgetAssistant::OpenWidgetAssistant(QWidget *parent)
|
||||
|
||||
void OpenWidgetAssistant::slotItemChanged()
|
||||
{
|
||||
enableButton( KDialog::User2, !m_widgetTypeList->selectedItems().isEmpty() );
|
||||
enableButton(KDialog::User2, !m_widgetTypeList->selectedItems().isEmpty());
|
||||
}
|
||||
|
||||
void OpenWidgetAssistant::prepPage(KPageWidgetItem *current, KPageWidgetItem *before)
|
||||
{
|
||||
Q_UNUSED(before)
|
||||
if ( m_widgetTypeList->selectedItems().isEmpty() )
|
||||
Q_UNUSED(before);
|
||||
if (m_widgetTypeList->selectedItems().isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (current != m_filePage) {
|
||||
return;
|
||||
@ -136,7 +137,7 @@ void OpenWidgetAssistant::prepPage(KPageWidgetItem *current, KPageWidgetItem *be
|
||||
} else {
|
||||
QString filter = m_packageStructureService->property("X-Plasma-PackageFileFilter").toString();
|
||||
if (!filter.isEmpty()) {
|
||||
m_fileDialog->setFilter( + '|' + m_packageStructureService->name());
|
||||
m_fileDialog->setFilter(+ '|' + m_packageStructureService->name());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -35,7 +35,9 @@ class OpenWidgetAssistant : public KAssistantDialog
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
enum { PackageStructureRole = Qt::UserRole + 1 };
|
||||
enum {
|
||||
PackageStructureRole = Qt::UserRole + 1
|
||||
};
|
||||
|
||||
OpenWidgetAssistant(QWidget *parent);
|
||||
|
||||
@ -44,6 +46,7 @@ protected Q_SLOTS:
|
||||
void finished();
|
||||
void slotHelpClicked();
|
||||
void slotItemChanged();
|
||||
|
||||
private:
|
||||
KPageWidgetItem *m_typePage;
|
||||
KPageWidgetItem *m_filePage;
|
||||
|
@ -21,8 +21,10 @@
|
||||
|
||||
#include <KSycoca>
|
||||
|
||||
PlasmaAppletItem::PlasmaAppletItem(PlasmaAppletItemModel * model, const QMap<QString, QVariant>& info,
|
||||
FilterFlags flags, QMap<QString, QVariant> * extraAttrs)
|
||||
PlasmaAppletItem::PlasmaAppletItem(PlasmaAppletItemModel *model,
|
||||
const QMap<QString, QVariant>& info,
|
||||
FilterFlags flags,
|
||||
QMap<QString, QVariant> *extraAttrs)
|
||||
: QObject(model), m_model(model)
|
||||
{
|
||||
QMap<QString, QVariant> attrs(info);
|
||||
@ -30,7 +32,9 @@ PlasmaAppletItem::PlasmaAppletItem(PlasmaAppletItemModel * model, const QMap<QSt
|
||||
attrs.insert("favorite", flags & Favorite ? true : false);
|
||||
attrs.insert("used", flags & Used ? true : false);
|
||||
//attrs.insert("recommended", flags & Recommended ? true : false);
|
||||
if (extraAttrs) attrs.unite(* extraAttrs);
|
||||
if (extraAttrs) {
|
||||
attrs.unite(* extraAttrs);
|
||||
}
|
||||
setText(info["name"].toString() + " - "+ info["category"].toString());
|
||||
setData(attrs);
|
||||
setIcon(qvariant_cast<QIcon>(info["icon"]));
|
||||
@ -105,7 +109,9 @@ void PlasmaAppletItemModel::populateModel()
|
||||
QMap < QString, QMap < QString, QVariant > > extraPluginAttrs;
|
||||
while (i.hasNext()) {
|
||||
i.next();
|
||||
if (!rx.exactMatch(i.key())) continue;
|
||||
if (!rx.exactMatch(i.key())) {
|
||||
continue;
|
||||
}
|
||||
QString id = rx.cap(1);
|
||||
|
||||
foreach (const QString &plugin, i.value().split(",")) {
|
||||
@ -114,8 +120,9 @@ void PlasmaAppletItemModel::populateModel()
|
||||
}
|
||||
|
||||
//TODO: get recommended, favorite, used, etc out of listAppletInfo()
|
||||
//kDebug() << "number of applets is" << Plasma::Applet::listAppletInfo(QString(), m_application).count();
|
||||
foreach (const KPluginInfo& info, Plasma::Applet::listAppletInfo(QString(), m_application)) {
|
||||
//kDebug() << "number of applets is"
|
||||
// << Plasma::Applet::listAppletInfo(QString(), m_application).count();
|
||||
foreach (const KPluginInfo &info, Plasma::Applet::listAppletInfo(QString(), m_application)) {
|
||||
//kDebug() << info.pluginName() << "NoDisplay" << info.property("NoDisplay").toBool();
|
||||
if (info.property("NoDisplay").toBool()) {
|
||||
// we don't want to show the hidden category
|
||||
@ -128,12 +135,11 @@ void PlasmaAppletItemModel::populateModel()
|
||||
attrs.insert("pluginName", info.pluginName());
|
||||
attrs.insert("description", info.comment());
|
||||
attrs.insert("category", info.category());
|
||||
attrs.insert("icon", static_cast<QIcon>(KIcon(info.icon().isEmpty()?"application-x-plasma":info.icon())));
|
||||
attrs.insert("icon",
|
||||
static_cast<QIcon>(KIcon(info.icon().isEmpty() ?
|
||||
"application-x-plasma" : info.icon())));
|
||||
|
||||
appendRow(new PlasmaAppletItem(this, attrs,
|
||||
((m_favorites.contains(info.pluginName())) ? PlasmaAppletItem::Favorite : PlasmaAppletItem::NoFilter) |
|
||||
((m_used.contains(info.pluginName())) ? PlasmaAppletItem::Used : PlasmaAppletItem::NoFilter)
|
||||
, &(extraPluginAttrs[info.pluginName()])));
|
||||
appendRow(new PlasmaAppletItem(this, attrs,((m_favorites.contains(info.pluginName())) ? PlasmaAppletItem::Favorite : PlasmaAppletItem::NoFilter) | ((m_used.contains(info.pluginName())) ? PlasmaAppletItem::Used : PlasmaAppletItem::NoFilter), &(extraPluginAttrs[info.pluginName()])));
|
||||
}
|
||||
}
|
||||
|
||||
@ -167,7 +173,7 @@ QStringList PlasmaAppletItemModel::mimeTypes() const
|
||||
return types;
|
||||
}
|
||||
|
||||
QMimeData* PlasmaAppletItemModel::mimeData(const QModelIndexList & indexes) const
|
||||
QMimeData *PlasmaAppletItemModel::mimeData(const QModelIndexList &indexes) const
|
||||
{
|
||||
kDebug() << "GETTING MIME DATA\n";
|
||||
if (indexes.count() <= 0) {
|
||||
@ -180,7 +186,7 @@ QMimeData* PlasmaAppletItemModel::mimeData(const QModelIndexList & indexes) cons
|
||||
return 0;
|
||||
}
|
||||
|
||||
QMimeData * data = new QMimeData();
|
||||
QMimeData *data = new QMimeData();
|
||||
|
||||
QString format = types.at(0);
|
||||
|
||||
@ -217,13 +223,13 @@ void PlasmaAppletItemModel::setFavorite(const QString &plugin, bool favorite)
|
||||
|
||||
}
|
||||
|
||||
void PlasmaAppletItemModel::setApplication(const QString& app)
|
||||
void PlasmaAppletItemModel::setApplication(const QString &app)
|
||||
{
|
||||
m_application = app;
|
||||
populateModel();
|
||||
}
|
||||
|
||||
QString& PlasmaAppletItemModel::Application()
|
||||
QString &PlasmaAppletItemModel::Application()
|
||||
{
|
||||
return m_application;
|
||||
}
|
||||
|
@ -36,14 +36,15 @@ class PlasmaAppletItem : public QObject, public KCategorizedItemsViewModels::Abs
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
enum FilterFlag {NoFilter = 0,
|
||||
enum FilterFlag {
|
||||
NoFilter = 0,
|
||||
Favorite = 1,
|
||||
Used = 2};
|
||||
Used = 2
|
||||
};
|
||||
|
||||
Q_DECLARE_FLAGS(FilterFlags, FilterFlag)
|
||||
|
||||
PlasmaAppletItem(PlasmaAppletItemModel * model, const QMap<QString, QVariant>& info,
|
||||
FilterFlags flags = NoFilter, QMap<QString, QVariant> * extraAttrs = NULL);
|
||||
PlasmaAppletItem(PlasmaAppletItemModel *model, const QMap<QString, QVariant>& info, FilterFlags flags = NoFilter, QMap<QString, QVariant> *extraAttrs = NULL);
|
||||
|
||||
virtual QString name() const;
|
||||
QString pluginName() const;
|
||||
@ -70,14 +71,15 @@ public:
|
||||
|
||||
QStringList mimeTypes() const;
|
||||
|
||||
QMimeData* mimeData(const QModelIndexList & indexes) const;
|
||||
|
||||
QMimeData *mimeData(const QModelIndexList &indexes) const;
|
||||
|
||||
void setFavorite(const QString &plugin, bool favorite);
|
||||
void setApplication(const QString& app);
|
||||
void setApplication(const QString &app);
|
||||
void setRunningApplets(const QHash<QString, int> &apps);
|
||||
void setRunningApplets(const QString &name, int count);
|
||||
|
||||
QString& Application();
|
||||
|
||||
QString &Application();
|
||||
|
||||
private:
|
||||
QString m_application;
|
||||
QStringList m_favorites;
|
||||
|
Loading…
Reference in New Issue
Block a user