2
2
* Copyright (C) 2007 Ivan Cukic <ivan.cukic+kde@gmail.com>
3
3
* Copyright (C) 2008 Daniel Nicoletti <dantti85-pk@yahoo.com.br>
4
* Copyright (C) 2010 Jonathan Thomas <echidnaman@kubuntu.org>
5
6
* This program is free software; you can redistribute it and/or modify
6
7
* it under the terms of the GNU Library/Lesser General Public License
50
51
ApplicationDelegate::ApplicationDelegate(QAbstractItemView *parent, ApplicationBackend *backend)
51
52
: KExtendableItemDelegate(parent),
52
53
m_appBackend(backend),
53
m_installString(i18n("Install")),
54
m_removeIcon("edit-delete"),
55
m_removeString(i18n("Remove")),
56
m_unknownIcon("applications-other")
59
57
QPushButton button, button2;
60
button.setText(m_installString);
61
button.setIcon(m_installIcon);
62
button2.setText(m_removeString);
63
button2.setIcon(m_removeIcon);
58
KIcon icon("edit-delete");
60
button.setText(i18n("Install"));
62
button2.setText(i18n("Remove"));
63
button2.setIcon(icon);
64
64
m_buttonSize = button.sizeHint();
65
65
int width = qMax(button.sizeHint().width(), button2.sizeHint().width());
66
66
width = qMax(width, button2.sizeHint().width());
67
67
m_buttonSize.setWidth(width);
68
m_buttonIconSize = button.iconSize();
71
KGlobal::dirs()->addResourceDir("appicon", "/usr/share/app-install/icons/");
69
m_ratingPainter = new KRatingPainter;
74
72
void ApplicationDelegate::paint(QPainter *painter,
117
114
rect.setTop(rect.top() + ((calcItemHeight(option) - m_buttonSize.height()) / 2));
118
115
rect.setSize(m_buttonSize); // the width and height sizes of the button
120
ratingPainter.paint(painter, rect, index.data(ApplicationModel::PopconRole).toInt());
117
bool transactionActive = index.data(ApplicationModel::ActiveRole).toBool();
119
if (!transactionActive) {
120
m_ratingPainter->paint(painter, rect, index.data(ApplicationModel::PopconRole).toInt());
122
QStyleOptionProgressBar progressBarOption;
123
progressBarOption.rect = rect;
124
progressBarOption.minimum = 0;
125
progressBarOption.maximum = 100;
126
progressBarOption.progress = index.data(ApplicationModel::ProgressRole).toInt();
127
progressBarOption.text = index.data(ApplicationModel::ProgressTextRole).toString();
128
progressBarOption.textVisible = true;
129
KApplication::style()->drawControl(QStyle::CE_ProgressBar, &progressBarOption, painter);
123
133
// selects the mode to paint the icon based on the info field
146
156
if (index.data(ApplicationModel::StatusRole).toInt() & QApt::Package::Installed) {
147
157
overlays << "installed";
149
KIcon icon(KIconLoader::global()->loadIcon(index.data(ApplicationModel::IconRole).toString(),
150
KIconLoader::User, 0, KIconLoader::DefaultState,
151
overlays, 0L, true));
153
icon = m_unknownIcon;
159
KIcon icon(index.data(ApplicationModel::IconRole).toString());
156
161
int iconSize = calcItemHeight(option) - 2 * UNIVERSAL_PADDING;