File indexing completed on 2024-04-21 16:29:35

0001 /*
0002  *   Copyright (C) 2007 Ivan Cukic <ivan.cukic+kde@gmail.com>
0003  *   Copyright (C) 2008-2011 Daniel Nicoletti <dantti12@gmail.com>
0004  *
0005  *   This program is free software; you can redistribute it and/or modify
0006  *   it under the terms of the GNU Library/Lesser General Public License
0007  *   version 2, or (at your option) any later version, as published by the
0008  *   Free Software Foundation
0009  *
0010  *   This program is distributed in the hope that it will be useful,
0011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
0012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0013  *   GNU General Public License for more details
0014  *
0015  *   You should have received a copy of the GNU Library/Lesser General Public
0016  *   License along with this program; if not, write to the
0017  *   Free Software Foundation, Inc.,
0018  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
0019  */
0020 
0021 #ifndef APPLICATIONS_DELEGATE_H
0022 #define APPLICATIONS_DELEGATE_H
0023 
0024 #include <QStyledItemDelegate>
0025 
0026 #include <QIcon>
0027 
0028 /**
0029  * Delegate for displaying the packages
0030  */
0031 class Q_DECL_EXPORT ApplicationsDelegate: public QStyledItemDelegate
0032 {
0033     Q_OBJECT
0034 
0035 public:
0036     explicit ApplicationsDelegate(QAbstractItemView *parent);
0037 
0038     void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
0039     QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override;
0040     bool editorEvent(QEvent *event,
0041                      QAbstractItemModel *model,
0042                      const QStyleOptionViewItem &option,
0043                      const QModelIndex &index) override;
0044     void setCheckable(bool checkable);
0045 
0046 private:
0047     bool insideButton(const QRect &rect, const QPoint &pos) const;
0048 
0049     QWidget *m_viewport;
0050     QIcon    m_packageIcon;
0051     QIcon    m_installIcon;
0052     QString  m_installString;
0053     QIcon    m_removeIcon;
0054     QString  m_removeString;
0055     QIcon    m_undoIcon;
0056     QString  m_undoString;
0057     QIcon    m_checkedIcon;
0058     QSize    m_buttonSize;
0059     QSize    m_buttonIconSize;
0060     bool     m_checkable = false;
0061 };
0062 
0063 #endif