~ubuntu-branches/debian/stretch/knewstuff/stretch

« back to all changes in this revision

Viewing changes to src/ui/itemsviewbasedelegate.cpp

  • Committer: Package Import Robot
  • Author(s): Scarlett Clark
  • Date: 2014-07-15 16:22:19 UTC
  • Revision ID: package-import@ubuntu.com-20140715162219-y23ejdtgskj0wwzq
Tags: upstream-5.0.0
ImportĀ upstreamĀ versionĀ 5.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
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>
 
5
 
 
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.
 
10
 
 
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.
 
15
 
 
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/>.
 
18
*/
 
19
#include "itemsviewbasedelegate_p.h"
 
20
 
 
21
#include "itemsmodel_p.h"
 
22
#include "entrydetailsdialog_p.h"
 
23
 
 
24
#include <QDebug>
 
25
#include <qstandardpaths.h>
 
26
#include <kiconloader.h>
 
27
 
 
28
namespace KNS3
 
29
{
 
30
ItemsViewBaseDelegate::ItemsViewBaseDelegate(QAbstractItemView *itemView, Engine *engine, QObject *parent)
 
31
    : KWidgetItemDelegate(itemView, parent)
 
32
    , m_engine(engine)
 
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))
 
39
{
 
40
    QString framefile = QStandardPaths::locate(QStandardPaths::GenericDataLocation, "kf5/knewstuff/pics/thumb_frame.png");
 
41
    m_frameImage = QPixmap(framefile);
 
42
}
 
43
 
 
44
ItemsViewBaseDelegate::~ItemsViewBaseDelegate()
 
45
{
 
46
}
 
47
 
 
48
bool ItemsViewBaseDelegate::eventFilter(QObject *watched, QEvent *event)
 
49
{
 
50
    if (event->type() == QEvent::MouseButtonDblClick) {
 
51
        slotDetailsClicked();
 
52
        return true;
 
53
    }
 
54
 
 
55
    return KWidgetItemDelegate::eventFilter(watched, event);
 
56
}
 
57
 
 
58
void ItemsViewBaseDelegate::slotLinkClicked(const QString &url)
 
59
{
 
60
    Q_UNUSED(url)
 
61
    QModelIndex index = focusedIndex();
 
62
    Q_ASSERT(index.isValid());
 
63
 
 
64
    KNS3::EntryInternal entry = index.data(Qt::UserRole).value<KNS3::EntryInternal>();
 
65
    m_engine->contactAuthor(entry);
 
66
}
 
67
 
 
68
void ItemsViewBaseDelegate::slotInstallClicked()
 
69
{
 
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();
 
75
            return;
 
76
        }
 
77
 
 
78
        if (entry.status() == Entry::Installed) {
 
79
            m_engine->uninstall(entry);
 
80
        } else {
 
81
            m_engine->install(entry);
 
82
        }
 
83
    }
 
84
}
 
85
 
 
86
void ItemsViewBaseDelegate::slotInstallActionTriggered(QAction *action)
 
87
{
 
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());
 
94
    }
 
95
}
 
96
 
 
97
void ItemsViewBaseDelegate::slotDetailsClicked()
 
98
{
 
99
    QModelIndex index = focusedIndex();
 
100
    slotDetailsClicked(index);
 
101
}
 
102
 
 
103
void ItemsViewBaseDelegate::slotDetailsClicked(const QModelIndex &index)
 
104
{
 
105
    if (index.isValid()) {
 
106
        KNS3::EntryInternal entry = index.data(Qt::UserRole).value<KNS3::EntryInternal>();
 
107
        if (!entry.isValid()) {
 
108
            return;
 
109
        }
 
110
// qDebug() << "Details: " << entry.name();
 
111
        emit signalShowDetails(entry);
 
112
    }
 
113
}
 
114
}