5
* Copyright (C) 2010 David Hubner <hubnerd@ntlworld.com>
7
* This program is free software; you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation; either version 2 of the License, or
10
* (at your option) any later version.
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License
18
* along with this program; if not, write to the Free Software
19
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24
#include "sidepanel.h"
35
SidePanel::SidePanel(QWidget *parent) : QTreeView(parent)
37
setSortingEnabled(true);
39
sortByColumn(0, Qt::AscendingOrder);
40
m_model = new InfoKcmModel(this);
42
m_proxyModel = new InfoKcmProxyModel(this);
43
m_proxyModel->setSourceModel(m_model);
47
setMouseTracking(true);
48
setModel(m_proxyModel);
49
connect(this,SIGNAL(activated(const QModelIndex &)),this,SLOT(activatedSlot(const QModelIndex &)));
52
SidePanel::~SidePanel()
54
disconnect(this,SIGNAL(activated(const QModelIndex &)),this,SLOT(activatedSlot(const QModelIndex &)));
60
void SidePanel::activatedSlot(const QModelIndex &index)
62
if(index.isValid() == false) return;
64
const KcmTreeItem *item = static_cast<KcmTreeItem*>(m_proxyModel->mapToSource(index).internalPointer());
68
void SidePanel::changeToFirstValidItem()
70
QModelIndex rootIndex = m_proxyModel->mapFromSource(m_model->firstValid());
71
if(rootIndex.isValid() == false) return;
73
setCurrentIndex(rootIndex);
74
emit activatedSlot(rootIndex);
77
QModelIndex SidePanel::mapToProxySource(const QModelIndex& index)
79
QModelIndex tmp = m_proxyModel->mapToSource(index);
80
if(tmp.isValid() == true) return tmp;
84
void SidePanel::filterSideMenuSlot(const QString &pattern)
94
m_proxyModel->setFilterRegExp(QRegExp(pattern,Qt::CaseInsensitive));
97
void SidePanel::createMenuActions()
99
resetAct = new QAction(i18n("Clear Search"), this);
100
connect(resetAct, SIGNAL(triggered()), this, SLOT(resetSearchSlot()));
102
expAct = new QAction(i18n("Expand All Categories"), this);
103
connect(expAct, SIGNAL(triggered()), this, SLOT(expandAllSlot()));
105
colAct = new QAction(i18n("Collapse All Categories"), this);
106
connect(colAct, SIGNAL(triggered()), this, SLOT(collapseAllSlot()));
109
void SidePanel::contextMenuEvent(QContextMenuEvent *event)
113
menu.addAction(colAct);
114
menu.addAction(expAct);
115
menu.addAction(resetAct);
116
menu.exec(event->globalPos());
119
void SidePanel::collapseAllSlot()
124
void SidePanel::expandAllSlot()
129
QStringList SidePanel::allChildKeywords()
131
return m_model->allChildrenKeywords();
134
void SidePanel::resetSearchSlot()
136
filterSideMenuSlot("");