KNewStuff

itemsviewbasedelegate.cpp
1 /*
2  Copyright (C) 2008 Jeremy Whiting <[email protected]>
3  Copyright (C) 2010 Reza Fatahilah Shah <[email protected]>
4  Copyright (C) 2010 Frederik Gladhorn <[email protected]>
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 "core/itemsmodel.h"
22 
23 #include "entrydetailsdialog_p.h"
24 
25 #include <QAction>
26 
27 #include <knewstuff_debug.h>
28 #include <qstandardpaths.h>
29 
30 namespace KNS3
31 {
32 ItemsViewBaseDelegate::ItemsViewBaseDelegate(QAbstractItemView *itemView, KNSCore::Engine *engine, QObject *parent)
33  : KWidgetItemDelegate(itemView, parent)
34  , m_engine(engine)
35  , m_itemView(itemView)
36  , m_iconInvalid(QIcon::fromTheme(QStringLiteral("dialog-error")))
37  , m_iconInstall(QIcon::fromTheme(QStringLiteral("dialog-ok")))
38  , m_iconUpdate(QIcon::fromTheme(QStringLiteral("system-software-update")))
39  , m_iconDelete(QIcon::fromTheme(QStringLiteral("edit-delete")))
40 {
41  const QString framefile = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("kf5/knewstuff/pics/thumb_frame.png"));
42  m_frameImage = QPixmap(framefile);
43 }
44 
45 ItemsViewBaseDelegate::~ItemsViewBaseDelegate()
46 {
47 }
48 
49 bool ItemsViewBaseDelegate::eventFilter(QObject *watched, QEvent *event)
50 {
51  if (event->type() == QEvent::MouseButtonDblClick) {
52  slotDetailsClicked();
53  return true;
54  }
55 
56  return KWidgetItemDelegate::eventFilter(watched, event);
57 }
58 
59 void ItemsViewBaseDelegate::slotLinkClicked(const QString &url)
60 {
61  Q_UNUSED(url)
62  QModelIndex index = focusedIndex();
63  Q_ASSERT(index.isValid());
64 
65  KNSCore::EntryInternal entry = index.data(Qt::UserRole).value<KNSCore::EntryInternal>();
66  m_engine->contactAuthor(entry);
67 }
68 
69 void ItemsViewBaseDelegate::slotInstallClicked()
70 {
71  QModelIndex index = focusedIndex();
72  if (index.isValid()) {
74  if (!entry.isValid()) {
75  qCDebug(KNEWSTUFF) << "Invalid entry: " << entry.name();
76  return;
77  }
78 
79  if (entry.status() == Entry::Installed) {
80  m_engine->uninstall(entry);
81  } else {
82  m_engine->install(entry);
83  }
84  }
85 }
86 
87 void ItemsViewBaseDelegate::slotInstallActionTriggered(QAction *action)
88 {
89  if (action->data().isNull())
90  return;
91 
92  QPoint rowDownload = action->data().toPoint();
93  int row = rowDownload.x();
94  QModelIndex index = m_itemView->model()->index(row, 0);
95  if (index.isValid()) {
97  m_engine->install(entry, rowDownload.y());
98  }
99 }
100 
101 void ItemsViewBaseDelegate::slotDetailsClicked()
102 {
103  QModelIndex index = focusedIndex();
104  slotDetailsClicked(index);
105 }
106 
107 void ItemsViewBaseDelegate::slotDetailsClicked(const QModelIndex &index)
108 {
109  if (index.isValid()) {
111  if (!entry.isValid()) {
112  return;
113  }
114  qCDebug(KNEWSTUFF) << "Details: " << entry.name();
115  emit signalShowDetails(entry);
116  }
117 }
118 }
MouseButtonDblClick
QEvent::Type type() const const
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const const =0
QVariant data() const const
Contains the core functionality for handling interaction with NewStuff providers. ...
T value() const const
int x() const const
int y() const const
virtual bool event(QEvent *e)
bool isValid() const const
bool isNull() const const
UserRole
virtual bool eventFilter(QObject *watched, QEvent *event)
const QAbstractItemModel * model() const const
QVariant data(int role) const const
KNewStuff data entry container.
Definition: entryinternal.h:60
KNewStuff engine.
Definition: engine.h:70
QPoint toPoint() const const
KNS3::Entry::Status status() const
Retrieves the entry&#39;s status.
Definition: button.cpp:29
QString name() const
Retrieve the name of the data object.
QString locate(QStandardPaths::StandardLocation type, const QString &fileName, QStandardPaths::LocateOptions options)
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sun Aug 9 2020 22:43:40 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.