Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 1 | /*************************************************************************** |
Edric Milaret | bab169d | 2016-01-07 15:13:33 -0500 | [diff] [blame] | 2 | * Copyright (C) 2015-2016 by Savoir-faire Linux * |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 3 | * Author: Edric Ladent Milaret <edric.ladent-milaret@savoirfairelinux.com>* |
| 4 | * * |
| 5 | * This program is free software; you can redistribute it and/or modify * |
| 6 | * it under the terms of the GNU General Public License as published by * |
| 7 | * the Free Software Foundation; either version 3 of the License, or * |
| 8 | * (at your option) any later version. * |
| 9 | * * |
| 10 | * This program is distributed in the hope that it will be useful, * |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
| 13 | * GNU General Public License for more details. * |
| 14 | * * |
| 15 | * You should have received a copy of the GNU General Public License * |
| 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. * |
| 17 | **************************************************************************/ |
| 18 | |
Edric Milaret | 5f316da | 2015-09-28 11:57:42 -0400 | [diff] [blame] | 19 | #pragma once |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 20 | |
Edric Milaret | ed0b280 | 2015-10-01 15:10:02 -0400 | [diff] [blame] | 21 | #include <QObject> |
Edric Milaret | a0ebd06 | 2016-01-13 12:18:23 -0500 | [diff] [blame] | 22 | #include <QItemDelegate> |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 23 | |
Edric Milaret | ed0b280 | 2015-10-01 15:10:02 -0400 | [diff] [blame] | 24 | class QPainter; |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 25 | |
Edric Milaret | a0ebd06 | 2016-01-13 12:18:23 -0500 | [diff] [blame] | 26 | class SmartListDelegate : public QItemDelegate |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 27 | { |
| 28 | Q_OBJECT |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 29 | public: |
Nicolas Jager | 97a21b4 | 2015-12-03 16:55:45 -0500 | [diff] [blame] | 30 | explicit SmartListDelegate(QObject* parent = 0); |
| 31 | inline void setRowHighlighted(int i){rowHighlighted_ = i;}; |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 32 | |
Edric Milaret | ed0b280 | 2015-10-01 15:10:02 -0400 | [diff] [blame] | 33 | protected: |
Nicolas Jager | 97a21b4 | 2015-12-03 16:55:45 -0500 | [diff] [blame] | 34 | void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const; |
| 35 | QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const; |
| 36 | |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 37 | private: |
Nicolas Jager | 97a21b4 | 2015-12-03 16:55:45 -0500 | [diff] [blame] | 38 | constexpr static int sizeImage_ = 48; |
| 39 | constexpr static int cellHeight_ = 60; |
Edric Milaret | a0ebd06 | 2016-01-13 12:18:23 -0500 | [diff] [blame] | 40 | constexpr static int dy_ = 6; |
| 41 | constexpr static int dx_ = 12; |
| 42 | constexpr static int fontSize_ = 10; |
Edric Milaret | 23fd3fa | 2016-01-15 15:37:35 -0500 | [diff] [blame] | 43 | constexpr static int pinSize_ = 12; |
Nicolas Jager | 97a21b4 | 2015-12-03 16:55:45 -0500 | [diff] [blame] | 44 | int rowHighlighted_ = -1; |
| 45 | |
| 46 | signals: |
| 47 | void rowSelected(const QRect& rect) const; |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 48 | }; |