• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.14.38 API Reference
  • KDE Home
  • Contact Us
 

KNewStuff

  • knewstuff
  • knewstuff3
  • ui
itemsviewbasedelegate.cpp
Go to the documentation of this file.
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.h"
20
21#include "itemsmodel.h"
22#include "entrydetailsdialog.h"
23
24#include <kdebug.h>
25#include <kicon.h>
26#include <kiconloader.h>
27#include <kstandarddirs.h>
28
29namespace KNS3
30{
31ItemsViewBaseDelegate::ItemsViewBaseDelegate(QAbstractItemView *itemView, Engine* engine, QObject * parent)
32 : KWidgetItemDelegate(itemView, parent)
33 , m_engine(engine)
34 , m_itemView(itemView)
35 , m_iconInvalid(KIcon("dialog-error"))
36 , m_iconInstall(KIcon("dialog-ok"))
37 , m_iconUpdate(KIcon("system-software-update"))
38 , m_iconDelete(KIcon("edit-delete"))
39 , m_noImage(SmallIcon( "image-missing", KIconLoader::SizeLarge, KIconLoader::DisabledState ))
40{
41 QString framefile = KStandardDirs::locate("data", "knewstuff/pics/thumb_frame.png");
42 m_frameImage = QPixmap(framefile);
43}
44
45ItemsViewBaseDelegate::~ItemsViewBaseDelegate()
46{
47}
48
49bool 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
59void ItemsViewBaseDelegate::slotLinkClicked(const QString & url)
60{
61 Q_UNUSED(url)
62 QModelIndex index = focusedIndex();
63 Q_ASSERT(index.isValid());
64
65 KNS3::EntryInternal entry = index.data(Qt::UserRole).value<KNS3::EntryInternal>();
66 m_engine->contactAuthor(entry);
67}
68
69void ItemsViewBaseDelegate::slotInstallClicked()
70{
71 QModelIndex index = focusedIndex();
72 if (index.isValid()) {
73 KNS3::EntryInternal entry = index.data(Qt::UserRole).value<KNS3::EntryInternal>();
74 if (!entry.isValid()) {
75 kDebug() << "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
87void ItemsViewBaseDelegate::slotInstallActionTriggered(QAction* action)
88{
89 QPoint rowDownload = action->data().toPoint();
90 int row = rowDownload.x();
91 QModelIndex index = m_itemView->model()->index(row, 0);
92 if (index.isValid()) {
93 KNS3::EntryInternal entry = index.data(Qt::UserRole).value<KNS3::EntryInternal>();
94 m_engine->install(entry, rowDownload.y());
95 }
96}
97
98void ItemsViewBaseDelegate::slotDetailsClicked()
99{
100 QModelIndex index = focusedIndex();
101 slotDetailsClicked(index);
102}
103
104void ItemsViewBaseDelegate::slotDetailsClicked(const QModelIndex& index)
105{
106 if (index.isValid()) {
107 KNS3::EntryInternal entry = index.data(Qt::UserRole).value<KNS3::EntryInternal>();
108 if ( !entry.isValid() )
109 return;
110kDebug() << "Details: " << entry.name();
111 emit signalShowDetails(entry);
112 }
113}
114}
KIconLoader
KIcon
KNS3::Engine
KNewStuff engine.
Definition: knewstuff3/core/engine.h:53
KNS3::Engine::install
void install(KNS3::EntryInternal entry, int linkId=1)
Installs an entry's payload file.
Definition: knewstuff3/core/engine.cpp:390
KNS3::Engine::uninstall
void uninstall(KNS3::EntryInternal entry)
Uninstalls an entry.
Definition: knewstuff3/core/engine.cpp:432
KNS3::Engine::contactAuthor
void contactAuthor(const EntryInternal &entry)
Try to contact the author of the entry by email or showing their homepage.
Definition: knewstuff3/core/engine.cpp:487
KNS3::EntryInternal
KNewStuff data entry container.
Definition: entryinternal.h:55
KNS3::EntryInternal::name
QString name() const
Retrieve the name of the data object.
Definition: entryinternal.cpp:124
KNS3::EntryInternal::status
Entry::Status status() const
Retrieves the entry's status.
Definition: entryinternal.cpp:367
KNS3::EntryInternal::isValid
bool isValid() const
Definition: entryinternal.cpp:119
KNS3::Entry::Installed
@ Installed
Definition: knewstuff3/entry.h:61
KNS3::ItemsViewBaseDelegate::~ItemsViewBaseDelegate
virtual ~ItemsViewBaseDelegate()
Definition: itemsviewbasedelegate.cpp:45
KNS3::ItemsViewBaseDelegate::signalShowDetails
void signalShowDetails(const KNS3::EntryInternal &entry)
KNS3::ItemsViewBaseDelegate::m_frameImage
QPixmap m_frameImage
Definition: itemsviewbasedelegate.h:78
KNS3::ItemsViewBaseDelegate::eventFilter
bool eventFilter(QObject *watched, QEvent *event)
Definition: itemsviewbasedelegate.cpp:49
KNS3::ItemsViewBaseDelegate::slotInstallClicked
void slotInstallClicked()
Definition: itemsviewbasedelegate.cpp:69
KNS3::ItemsViewBaseDelegate::m_itemView
QAbstractItemView * m_itemView
Definition: itemsviewbasedelegate.h:72
KNS3::ItemsViewBaseDelegate::slotDetailsClicked
void slotDetailsClicked(const QModelIndex &index)
Definition: itemsviewbasedelegate.cpp:104
KNS3::ItemsViewBaseDelegate::slotInstallActionTriggered
void slotInstallActionTriggered(QAction *action)
Definition: itemsviewbasedelegate.cpp:87
KNS3::ItemsViewBaseDelegate::m_engine
Engine * m_engine
Definition: itemsviewbasedelegate.h:71
KNS3::ItemsViewBaseDelegate::ItemsViewBaseDelegate
ItemsViewBaseDelegate(QAbstractItemView *itemView, Engine *engine, QObject *parent=0)
Definition: itemsviewbasedelegate.cpp:31
KNS3::ItemsViewBaseDelegate::slotLinkClicked
void slotLinkClicked(const QString &url)
Definition: itemsviewbasedelegate.cpp:59
KStandardDirs::locate
static QString locate(const char *type, const QString &filename, const KComponentData &cData=KGlobal::mainComponent())
KWidgetItemDelegate
KWidgetItemDelegate::focusedIndex
QPersistentModelIndex focusedIndex() const
QAction
QObject
entrydetailsdialog.h
kDebug
#define kDebug
itemsviewbasedelegate.h
kdebug.h
kicon.h
SmallIcon
QPixmap SmallIcon(const QString &name, int force_size, int state, const QStringList &overlays)
kiconloader.h
itemsmodel.h
kstandarddirs.h
KNS3
Definition: atticaprovider.cpp:36
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KNewStuff

Skip menu "KNewStuff"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdelibs-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal