2
Copyright (C) 2008 Jeremy Whiting <jpwhiting@kde.org>
3
Copyright (C) 2010 Reza Fatahilah Shah <rshah0385@kireihana.com>
4
Copyright (C) 2010 Frederik Gladhorn <gladhorn@kde.org>
6
This library is free software; you can redistribute it and/or
7
modify it under the terms of the GNU Lesser General Public
8
License as published by the Free Software Foundation; either
9
version 2.1 of the License, or (at your option) any later version.
11
This library is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
Lesser General Public License for more details.
16
You should have received a copy of the GNU Lesser General Public
17
License along with this library. If not, see <http://www.gnu.org/licenses/>.
19
#include "itemsviewbasedelegate_p.h"
21
#include "itemsmodel_p.h"
22
#include "entrydetailsdialog_p.h"
25
#include <qstandardpaths.h>
26
#include <kiconloader.h>
30
ItemsViewBaseDelegate::ItemsViewBaseDelegate(QAbstractItemView *itemView, Engine *engine, QObject *parent)
31
: KWidgetItemDelegate(itemView, parent)
33
, m_itemView(itemView)
34
, m_iconInvalid(QIcon::fromTheme("dialog-error"))
35
, m_iconInstall(QIcon::fromTheme("dialog-ok"))
36
, m_iconUpdate(QIcon::fromTheme("system-software-update"))
37
, m_iconDelete(QIcon::fromTheme("edit-delete"))
38
, m_noImage(SmallIcon("image-missing", KIconLoader::SizeLarge, KIconLoader::DisabledState))
40
QString framefile = QStandardPaths::locate(QStandardPaths::GenericDataLocation, "kf5/knewstuff/pics/thumb_frame.png");
41
m_frameImage = QPixmap(framefile);
44
ItemsViewBaseDelegate::~ItemsViewBaseDelegate()
48
bool ItemsViewBaseDelegate::eventFilter(QObject *watched, QEvent *event)
50
if (event->type() == QEvent::MouseButtonDblClick) {
55
return KWidgetItemDelegate::eventFilter(watched, event);
58
void ItemsViewBaseDelegate::slotLinkClicked(const QString &url)
61
QModelIndex index = focusedIndex();
62
Q_ASSERT(index.isValid());
64
KNS3::EntryInternal entry = index.data(Qt::UserRole).value<KNS3::EntryInternal>();
65
m_engine->contactAuthor(entry);
68
void ItemsViewBaseDelegate::slotInstallClicked()
70
QModelIndex index = focusedIndex();
71
if (index.isValid()) {
72
KNS3::EntryInternal entry = index.data(Qt::UserRole).value<KNS3::EntryInternal>();
73
if (!entry.isValid()) {
74
// qDebug() << "Invalid entry: " << entry.name();
78
if (entry.status() == Entry::Installed) {
79
m_engine->uninstall(entry);
81
m_engine->install(entry);
86
void ItemsViewBaseDelegate::slotInstallActionTriggered(QAction *action)
88
QPoint rowDownload = action->data().toPoint();
89
int row = rowDownload.x();
90
QModelIndex index = m_itemView->model()->index(row, 0);
91
if (index.isValid()) {
92
KNS3::EntryInternal entry = index.data(Qt::UserRole).value<KNS3::EntryInternal>();
93
m_engine->install(entry, rowDownload.y());
97
void ItemsViewBaseDelegate::slotDetailsClicked()
99
QModelIndex index = focusedIndex();
100
slotDetailsClicked(index);
103
void ItemsViewBaseDelegate::slotDetailsClicked(const QModelIndex &index)
105
if (index.isValid()) {
106
KNS3::EntryInternal entry = index.data(Qt::UserRole).value<KNS3::EntryInternal>();
107
if (!entry.isValid()) {
110
// qDebug() << "Details: " << entry.name();
111
emit signalShowDetails(entry);