• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.10.3 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 
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 }
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Sat May 18 2013 11:42:10 by doxygen 1.8.3.1 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.10.3 API Reference

Skip menu "kdelibs-4.10.3 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