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

KNewStuff

  • sources
  • kde-4.12
  • kdelibs
  • 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 
29 namespace KNS3
30 {
31 ItemsViewBaseDelegate::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 
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  KNS3::EntryInternal entry = index.data(Qt::UserRole).value<KNS3::EntryInternal>();
66  m_engine->contactAuthor(entry);
67 }
68 
69 void 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 
87 void 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 
98 void ItemsViewBaseDelegate::slotDetailsClicked()
99 {
100  QModelIndex index = focusedIndex();
101  slotDetailsClicked(index);
102 }
103 
104 void 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;
110 kDebug() << "Details: " << entry.name();
111  emit signalShowDetails(entry);
112  }
113 }
114 }
KWidgetItemDelegate::focusedIndex
QPersistentModelIndex focusedIndex() const
itemsviewbasedelegate.h
kdebug.h
KNS3::EntryInternal
KNewStuff data entry container.
Definition: entryinternal.h:54
KNS3::ItemsViewBaseDelegate::m_frameImage
QPixmap m_frameImage
Definition: itemsviewbasedelegate.h:78
KNS3::EntryInternal::isValid
bool isValid() const
Definition: entryinternal.cpp:119
KNS3::Engine
KNewStuff engine.
Definition: knewstuff3/core/engine.h:52
KNS3::EntryInternal::name
QString name() const
Retrieve the name of the data object.
Definition: entryinternal.cpp:124
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())
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::ItemsViewBaseDelegate::m_engine
Engine * m_engine
Definition: itemsviewbasedelegate.h:71
KNS3::ItemsViewBaseDelegate::~ItemsViewBaseDelegate
virtual ~ItemsViewBaseDelegate()
Definition: itemsviewbasedelegate.cpp:45
kiconloader.h
QString
QObject
kDebug
static QDebug kDebug(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
KWidgetItemDelegate
KNS3::ItemsViewBaseDelegate::eventFilter
bool eventFilter(QObject *watched, QEvent *event)
Definition: itemsviewbasedelegate.cpp:49
entrydetailsdialog.h
KNS3::ItemsViewBaseDelegate::signalShowDetails
void signalShowDetails(const KNS3::EntryInternal &entry)
KNS3::Entry::Installed
Definition: knewstuff3/entry.h:61
KNS3::ItemsViewBaseDelegate::slotInstallActionTriggered
void slotInstallActionTriggered(QAction *action)
Definition: itemsviewbasedelegate.cpp:87
KNS3::EntryInternal::status
Entry::Status status() const
Retrieves the entry's status.
Definition: entryinternal.cpp:367
KIcon
KNS3::Engine::install
void install(KNS3::EntryInternal entry, int linkId=1)
Installs an entry's payload file.
Definition: knewstuff3/core/engine.cpp:390
KNS3::ItemsViewBaseDelegate::ItemsViewBaseDelegate
ItemsViewBaseDelegate(QAbstractItemView *itemView, Engine *engine, QObject *parent=0)
Definition: itemsviewbasedelegate.cpp:31
QPoint
KNS3::ItemsViewBaseDelegate::m_itemView
QAbstractItemView * m_itemView
Definition: itemsviewbasedelegate.h:72
kstandarddirs.h
KNS3::ItemsViewBaseDelegate::slotDetailsClicked
void slotDetailsClicked()
Definition: itemsviewbasedelegate.cpp:98
SmallIcon
QPixmap SmallIcon(const QString &name, int force_size, int state, const QStringList &overlays)
itemsmodel.h
kicon.h
KNS3::ItemsViewBaseDelegate::slotInstallClicked
void slotInstallClicked()
Definition: itemsviewbasedelegate.cpp:69
QAction
KIconLoader
KNS3::Engine::uninstall
void uninstall(KNS3::EntryInternal entry)
Uninstalls an entry.
Definition: knewstuff3/core/engine.cpp:432
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:50:48 by doxygen 1.8.7 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 API Reference

Skip menu "kdelibs 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
  • kjsembed
  •   WTF
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Nepomuk-Core
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



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