~ubuntu-branches/ubuntu/karmic/kleansweep/karmic

« back to all changes in this revision

Viewing changes to src/summarylabel.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Mercatante
  • Date: 2006-01-20 11:26:41 UTC
  • Revision ID: james.westby@ubuntu.com-20060120112641-xd1rmv568k0vvz3u
Tags: upstream-0.2.5
ImportĀ upstreamĀ versionĀ 0.2.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * This file is a part of KleanSweep.
 
3
 *
 
4
 * Copyright (C) 2005 Pawel Stolowski <pawel.stolowski@wp.pl>
 
5
 *
 
6
 * KleanSweep is free software; you can redestribute it and/or modify it
 
7
 * under terms of GNU General Public License by Free Software Foundation.
 
8
 *
 
9
 * This program is distributed in the hope that it will be useful, but
 
10
 * WITHOUT ANY WARRANTY. See GPL for more details.
 
11
 */
 
12
 
 
13
#include "summarylabel.h"
 
14
#include <qlabel.h>
 
15
#include <qframe.h>
 
16
#include <klocale.h>
 
17
 
 
18
SummaryLabel::SummaryLabel(QWidget *parent): QHBox(parent), selsize(-1), selitems(-1), totsize(-1), totitems(-1)
 
19
{
 
20
        setSpacing(5);
 
21
        setMargin(5);
 
22
        setFrameStyle(QFrame::Panel | QFrame::Sunken);
 
23
 
 
24
        new QLabel(i18n("Found") + ":", this);
 
25
        l_totitems = new QLabel(this);
 
26
        l_totitems->setAlignment(Qt::AlignRight);
 
27
        l_totsize = new QLabel(this);
 
28
        l_totsize->setAlignment(Qt::AlignRight);
 
29
        new QLabel(i18n("Selected") + ":", this);
 
30
        l_selitems = new QLabel(this);
 
31
        l_selitems->setAlignment(Qt::AlignRight);
 
32
        l_selsize = new QLabel(this);
 
33
        l_selsize->setAlignment(Qt::AlignRight);
 
34
 
 
35
        reset();
 
36
}
 
37
 
 
38
SummaryLabel::~SummaryLabel()
 
39
{
 
40
}
 
41
 
 
42
void SummaryLabel::reset()
 
43
{
 
44
        setSelectedItems(0);
 
45
        setSelectedSize(0);
 
46
        setTotalSize(0);
 
47
        setTotalItems(0);
 
48
}
 
49
 
 
50
QString SummaryLabel::formatSize(int n)
 
51
{
 
52
        static const float mb = 1.0f/(1024.0f*1024.0f);
 
53
        static const float kb = 1.0f/1024.0f;
 
54
        float x = n;
 
55
        char *p;
 
56
        if (n >= 1024*1024)
 
57
        {
 
58
                x *= mb;
 
59
                p = "(%1 M)";
 
60
        }
 
61
        else if (n >= 1024)
 
62
        {
 
63
                x *= kb;
 
64
                p = "(%1 K)";
 
65
        }
 
66
        else
 
67
        {
 
68
                return QString("(%1 b)").arg(n);
 
69
        }
 
70
        return QString(p).arg(x, 0, 'f', 2);
 
71
}
 
72
 
 
73
void SummaryLabel::setTotalItems(int n)
 
74
{
 
75
        if (totitems != n)
 
76
        {
 
77
                totitems = n;
 
78
                l_totitems->setText(QString::number(n));
 
79
        }
 
80
}
 
81
 
 
82
void SummaryLabel::setSelectedItems(int n)
 
83
{
 
84
        if (selitems != n)
 
85
        {
 
86
                selitems = n;
 
87
                l_selitems->setText(QString::number(selitems));
 
88
        }
 
89
}
 
90
 
 
91
void SummaryLabel::setSelectedSize(int size)
 
92
{
 
93
        if (selsize != size)
 
94
        {
 
95
                selsize = size;
 
96
                l_selsize->setText(formatSize(selsize));
 
97
        }
 
98
}
 
99
 
 
100
void SummaryLabel::updateSelectedInfo(int d, unsigned int size)
 
101
{
 
102
        selitems += d;
 
103
        if (size != 0)
 
104
        {
 
105
                if (d<0)
 
106
                        selsize -= size;
 
107
                else
 
108
                        selsize += size;
 
109
                l_selsize->setText(formatSize(selsize));
 
110
        }
 
111
        l_selitems->setText(QString::number(selitems));
 
112
}
 
113
 
 
114
void SummaryLabel::setTotalSize(int size)
 
115
{
 
116
        if (totsize != size)
 
117
        {
 
118
                totsize = size;
 
119
                l_totsize->setText(formatSize(totsize));
 
120
        }
 
121
}
 
122
 
 
123
void SummaryLabel::setTotals(int n, unsigned int size)
 
124
{
 
125
        setTotalItems(n);
 
126
        setTotalSize(size);
 
127
}
 
128
 
 
129
#include "summarylabel.moc"