KNewStuff

itemsviewbasedelegate.cpp
1 /*
2  SPDX-FileCopyrightText: 2008 Jeremy Whiting <[email protected]>
3  SPDX-FileCopyrightText: 2010 Reza Fatahilah Shah <[email protected]>
4  SPDX-FileCopyrightText: 2010 Frederik Gladhorn <[email protected]>
5 
6  SPDX-License-Identifier: LGPL-2.1-or-later
7 */
8 
9 #include "itemsviewbasedelegate_p.h"
10 
11 #include "core/itemsmodel.h"
12 
13 #include "entrydetailsdialog_p.h"
14 
15 #include <QAction>
16 
17 #include <knewstuff_debug.h>
18 #include <qstandardpaths.h>
19 
20 namespace KNS3
21 {
22 ItemsViewBaseDelegate::ItemsViewBaseDelegate(QAbstractItemView *itemView, KNSCore::Engine *engine, QObject *parent)
23  : KWidgetItemDelegate(itemView, parent)
24  , m_engine(engine)
25  , m_itemView(itemView)
26  , m_iconInvalid(QIcon::fromTheme(QStringLiteral("dialog-error")))
27  , m_iconInstall(QIcon::fromTheme(QStringLiteral("dialog-ok")))
28  , m_iconUpdate(QIcon::fromTheme(QStringLiteral("system-software-update")))
29  , m_iconDelete(QIcon::fromTheme(QStringLiteral("edit-delete")))
30 {
31  const QString framefile = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("kf5/knewstuff/pics/thumb_frame.png"));
32  m_frameImage = QPixmap(framefile);
33 }
34 
35 ItemsViewBaseDelegate::~ItemsViewBaseDelegate()
36 {
37 }
38 
39 bool ItemsViewBaseDelegate::eventFilter(QObject *watched, QEvent *event)
40 {
41  if (event->type() == QEvent::MouseButtonDblClick) {
42  slotDetailsClicked();
43  return true;
44  }
45 
46  return KWidgetItemDelegate::eventFilter(watched, event);
47 }
48 
49 void ItemsViewBaseDelegate::slotLinkClicked(const QString &url)
50 {
51  Q_UNUSED(url)
52  QModelIndex index = focusedIndex();
53  Q_ASSERT(index.isValid());
54 
55  KNSCore::EntryInternal entry = index.data(Qt::UserRole).value<KNSCore::EntryInternal>();
56  m_engine->contactAuthor(entry);
57 }
58 
59 void ItemsViewBaseDelegate::slotInstallClicked()
60 {
61  QModelIndex index = focusedIndex();
62  if (index.isValid()) {
64  if (!entry.isValid()) {
65  qCDebug(KNEWSTUFF) << "Invalid entry: " << entry.name();
66  return;
67  }
68 
69  if (entry.status() == Entry::Installed) {
70  m_engine->uninstall(entry);
71  } else {
72  m_engine->install(entry);
73  }
74  }
75 }
76 
77 void ItemsViewBaseDelegate::slotInstallActionTriggered(QAction *action)
78 {
79  if (action->data().isNull())
80  return;
81 
82  QPoint rowDownload = action->data().toPoint();
83  int row = rowDownload.x();
84  QModelIndex index = m_itemView->model()->index(row, 0);
85  if (index.isValid()) {
87  m_engine->install(entry, rowDownload.y());
88  }
89 }
90 
91 void ItemsViewBaseDelegate::slotDetailsClicked()
92 {
93  QModelIndex index = focusedIndex();
94  slotDetailsClicked(index);
95 }
96 
97 void ItemsViewBaseDelegate::slotDetailsClicked(const QModelIndex &index)
98 {
99  if (index.isValid()) {
101  if (!entry.isValid()) {
102  return;
103  }
104  qCDebug(KNEWSTUFF) << "Details: " << entry.name();
105  Q_EMIT signalShowDetails(entry);
106  }
107 }
108 }
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:49
KNewStuff engine.
Definition: engine.h:59
QPoint toPoint() const const
KNS3::Entry::Status status() const
Retrieves the entry&#39;s status.
The namespace for the KNewStuff classes.
Definition: button.cpp:19
QString name() const
Retrieve the name of the data object.
Q_EMITQ_EMIT
QString locate(QStandardPaths::StandardLocation type, const QString &fileName, QStandardPaths::LocateOptions options)
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Mon Jan 18 2021 22:43:50 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.