blob: 24cfb263e36a9da3e5ab4d06eb61119bbca96f14 [file] [log] [blame]
Edric Milaret5d61a062015-06-12 11:16:08 -04001/***************************************************************************
Edric Milaretbab169d2016-01-07 15:13:33 -05002 * Copyright (C) 2015-2016 by Savoir-faire Linux *
Edric Milaret5d61a062015-06-12 11:16:08 -04003 * 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
19#include "accountstatedelegate.h"
20
21#include "accountmodel.h"
22#include "account.h"
23
24AccountStateDelegate::AccountStateDelegate(QObject *parent) :
25 QStyledItemDelegate(parent)
26{}
27
28void
29AccountStateDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
30{
31 QStyleOptionViewItemV4 opt = option;
32 initStyleOption(&opt, index);
33 if (index.column() == 0) {
34 auto name = index.model()->data(index, Qt::DisplayRole).toString();
Edric Milareted0b2802015-10-01 15:10:02 -040035 opt.text = QString();
Edric Milaret5d61a062015-06-12 11:16:08 -040036 QStyle *style = opt.widget ? opt.widget->style() : QApplication::style();
37 style->drawControl(QStyle::CE_ItemViewItem, &opt, painter, opt.widget);
38 auto rect = opt.rect;
39 QPalette::ColorGroup cg = opt.state & QStyle::State_Enabled ?
40 QPalette::Normal : QPalette::Disabled;
41 if (cg == QPalette::Normal && !(opt.state & QStyle::State_Active))
42 cg = QPalette::Inactive;
43 auto font = painter->font() ;
44 font.setBold(true);
45 painter->setFont(font);
Edric Milareta3e47282015-10-23 15:20:30 -040046 painter->setPen(AccountModel::instance().
Edric Milaret5d61a062015-06-12 11:16:08 -040047 getAccountByModelIndex(index)->stateColorName());
48 painter->setOpacity(1.0);
49 painter->drawText(QRect(rect.left()+25, rect.top(),
50 rect.width(), rect.height()),
51 opt.displayAlignment, name);
52 }
53}
54
55QSize
56AccountStateDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
57{
58 QSize result = QStyledItemDelegate::sizeHint(option, index);
59 return result;
60}