~ubuntu-branches/ubuntu/natty/muon/natty

« back to all changes in this revision

Viewing changes to installer/ApplicationModel/ApplicationDelegate.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Thomas
  • Date: 2010-12-20 21:25:02 UTC
  • mfrom: (1.1.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20101220212502-jah7iubxtsmzh3t8
Tags: 1.0.90-0ubuntu1
* New upstream release:
  - Remove linker fix patch, applied upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
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>
4
5
 *
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
28
29
#include <QtGui/QTreeView>
29
30
 
30
31
// KDE includes
31
 
#include <KDebug>
 
32
#include <KApplication>
32
33
#include <KIconLoader>
33
34
#include <KGlobal>
34
35
#include <KLocale>
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")
 
54
    m_extender(0)
57
55
{
58
56
    // To get sizing.
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");
 
59
 
 
60
    button.setText(i18n("Install"));
 
61
    button.setIcon(icon);
 
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();
69
68
 
70
 
    // For icons later
71
 
    KGlobal::dirs()->addResourceDir("appicon", "/usr/share/app-install/icons/");
 
69
    m_ratingPainter = new KRatingPainter;
72
70
}
73
71
 
74
72
void ApplicationDelegate::paint(QPainter *painter,
102
100
    int top = opt.rect.top();
103
101
    int width = opt.rect.width();
104
102
 
105
 
    KRatingPainter ratingPainter;
106
103
    QRect rect = opt.rect;
107
104
 
108
105
    if (leftToRight) {
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
119
116
 
120
 
    ratingPainter.paint(painter, rect, index.data(ApplicationModel::PopconRole).toInt());
 
117
    bool transactionActive = index.data(ApplicationModel::ActiveRole).toBool();
 
118
 
 
119
    if (!transactionActive) {
 
120
        m_ratingPainter->paint(painter, rect, index.data(ApplicationModel::PopconRole).toInt());
 
121
    } else {
 
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);
 
130
    }
121
131
 
122
132
 
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";
148
158
    }
149
 
    KIcon icon(KIconLoader::global()->loadIcon(index.data(ApplicationModel::IconRole).toString(),
150
 
                                                       KIconLoader::User, 0, KIconLoader::DefaultState,
151
 
                                                       overlays, 0L, true));
152
 
    if (icon.isNull()) {
153
 
        icon = m_unknownIcon;
154
 
    }
 
159
    KIcon icon(index.data(ApplicationModel::IconRole).toString());
155
160
 
156
161
    int iconSize = calcItemHeight(option) - 2 * UNIVERSAL_PADDING;
157
162
    icon.paint(&p,