Edric Milaret | 83b248c | 2015-06-02 11:42:23 -0400 | [diff] [blame] | 1 | /*************************************************************************** |
Anthony LĂ©onard | 2fde81d | 2017-04-17 10:06:55 -0400 | [diff] [blame] | 2 | * Copyright (C) 2015-2017 by Savoir-faire Linux * |
Edric Milaret | 83b248c | 2015-06-02 11:42:23 -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 | 83b248c | 2015-06-02 11:42:23 -0400 | [diff] [blame] | 20 | |
Edric Milaret | 83b248c | 2015-06-02 11:42:23 -0400 | [diff] [blame] | 21 | #include <QPainter> |
| 22 | #include <QStyledItemDelegate> |
Edric Milaret | 83b248c | 2015-06-02 11:42:23 -0400 | [diff] [blame] | 23 | |
| 24 | class ImDelegate : public QStyledItemDelegate |
| 25 | { |
| 26 | Q_OBJECT |
| 27 | public: |
| 28 | explicit ImDelegate(QObject *parent = 0); |
| 29 | enum DisplayOptions { |
| 30 | AUTHOR = 1, |
| 31 | DATE |
| 32 | }; |
| 33 | |
Edric Milaret | 83b248c | 2015-06-02 11:42:23 -0400 | [diff] [blame] | 34 | protected: |
Edric Milaret | a0ebd06 | 2016-01-13 12:18:23 -0500 | [diff] [blame] | 35 | void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const; |
| 36 | QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const; |
Edric Milaret | 83b248c | 2015-06-02 11:42:23 -0400 | [diff] [blame] | 37 | private: |
Edric Milaret | a0ebd06 | 2016-01-13 12:18:23 -0500 | [diff] [blame] | 38 | void formatMsg(const QModelIndex& index, QString& msg) const; |
| 39 | QRect getBoundingRect(const Qt::AlignmentFlag& dir, const QString& msg, const QStyleOptionViewItem &option) const; |
| 40 | |
Nicolas Jager | d0b3375 | 2016-01-17 00:00:40 -0500 | [diff] [blame] | 41 | const QFont fontMsg_ = QFont("Arial", 10); |
Edric Milaret | a0ebd06 | 2016-01-13 12:18:23 -0500 | [diff] [blame] | 42 | const QSize iconSize_ {38,38}; |
Nicolas Jager | d0b3375 | 2016-01-17 00:00:40 -0500 | [diff] [blame] | 43 | |
Edric Milaret | a0ebd06 | 2016-01-13 12:18:23 -0500 | [diff] [blame] | 44 | constexpr static int padding_ = 5; |
Edric Milaret | 83b248c | 2015-06-02 11:42:23 -0400 | [diff] [blame] | 45 | }; |
| 46 | |