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

KNewStuff

itemsviewbasedelegate.cpp
Go to the documentation of this file.
00001 /*
00002     Copyright (C) 2008 Jeremy Whiting <jpwhiting@kde.org>
00003     Copyright (C) 2010 Reza Fatahilah Shah <rshah0385@kireihana.com>
00004     Copyright (C) 2010 Frederik Gladhorn <gladhorn@kde.org>
00005 
00006     This library is free software; you can redistribute it and/or
00007     modify it under the terms of the GNU Lesser General Public
00008     License as published by the Free Software Foundation; either
00009     version 2.1 of the License, or (at your option) any later version.
00010 
00011     This library is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014     Lesser General Public License for more details.
00015 
00016     You should have received a copy of the GNU Lesser General Public
00017     License along with this library.  If not, see <http://www.gnu.org/licenses/>.
00018 */
00019 #include "itemsviewbasedelegate.h"
00020 
00021 #include "itemsmodel.h"
00022 #include "entrydetailsdialog.h"
00023 
00024 #include <kdebug.h>
00025 #include <kicon.h>
00026 #include <kiconloader.h>
00027 #include <kstandarddirs.h>
00028 
00029 namespace KNS3
00030 {
00031 ItemsViewBaseDelegate::ItemsViewBaseDelegate(QAbstractItemView *itemView, Engine* engine, QObject * parent)
00032         : KWidgetItemDelegate(itemView, parent)
00033         , m_engine(engine)
00034         , m_itemView(itemView)
00035         , m_iconInvalid(KIcon("dialog-error"))
00036         , m_iconInstall(KIcon("dialog-ok"))
00037         , m_iconUpdate(KIcon("system-software-update"))
00038         , m_iconDelete(KIcon("edit-delete"))
00039         , m_noImage(SmallIcon( "image-missing", KIconLoader::SizeLarge, KIconLoader::DisabledState ))
00040 {
00041     QString framefile = KStandardDirs::locate("data", "knewstuff/pics/thumb_frame.png");
00042     m_frameImage = QPixmap(framefile);   
00043 }
00044 
00045 ItemsViewBaseDelegate::~ItemsViewBaseDelegate()
00046 {
00047 }
00048 
00049 bool ItemsViewBaseDelegate::eventFilter(QObject *watched, QEvent *event)
00050 {
00051    if (event->type() == QEvent::MouseButtonDblClick) {
00052        slotDetailsClicked();
00053        return true;
00054    }
00055 
00056    return KWidgetItemDelegate::eventFilter(watched, event);
00057 }
00058 
00059 void ItemsViewBaseDelegate::slotLinkClicked(const QString & url)
00060 {
00061     Q_UNUSED(url)
00062     QModelIndex index = focusedIndex();
00063     Q_ASSERT(index.isValid());
00064 
00065     KNS3::EntryInternal entry = index.data(Qt::UserRole).value<KNS3::EntryInternal>();
00066     m_engine->contactAuthor(entry);
00067 }
00068 
00069 void ItemsViewBaseDelegate::slotInstallClicked()
00070 {
00071     QModelIndex index = focusedIndex();
00072     if (index.isValid()) {
00073         KNS3::EntryInternal entry = index.data(Qt::UserRole).value<KNS3::EntryInternal>();
00074         if (!entry.isValid()) {
00075             kDebug() << "Invalid entry: " << entry.name();
00076             return;
00077         }
00078 
00079         if (entry.status() == Entry::Installed) {
00080             m_engine->uninstall(entry);
00081         } else {
00082             m_engine->install(entry);
00083         }
00084     }
00085 }
00086 
00087 void ItemsViewBaseDelegate::slotInstallActionTriggered(QAction* action)
00088 {
00089     QPoint rowDownload = action->data().toPoint();
00090     int row = rowDownload.x();
00091     QModelIndex index = m_itemView->model()->index(row, 0);
00092     if (index.isValid()) {
00093         KNS3::EntryInternal entry = index.data(Qt::UserRole).value<KNS3::EntryInternal>();
00094         m_engine->install(entry, rowDownload.y());
00095     }
00096 }
00097 
00098 void ItemsViewBaseDelegate::slotDetailsClicked()
00099 {
00100     QModelIndex index = focusedIndex();
00101     slotDetailsClicked(index);
00102 }
00103 
00104 void ItemsViewBaseDelegate::slotDetailsClicked(const QModelIndex& index)
00105 {
00106     if (index.isValid()) {
00107         KNS3::EntryInternal entry = index.data(Qt::UserRole).value<KNS3::EntryInternal>();
00108         if ( !entry.isValid() )
00109             return;
00110 kDebug() << "Details: " << entry.name();
00111         emit signalShowDetails(entry);
00112     }
00113 }
00114 }
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Thu May 10 2012 20:57:20 by doxygen 1.8.0 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.8.3 API Reference

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