~ubuntu-branches/ubuntu/jaunty/digikam/jaunty

« back to all changes in this revision

Viewing changes to digikam/ratingwidget.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Luka Renko
  • Date: 2009-01-21 21:55:15 UTC
  • mfrom: (1.2.18 upstream)
  • Revision ID: james.westby@ubuntu.com-20090121215515-lry0s2pdep289o3u
Tags: 2:0.10.0~rc1-0ubuntu1
* New upstream release (release candididate 1)
* rules:
  - Simplify by including standard class/kde4.mk
* control:
  - Build-Depends on quilt (default patch system of kde4.mk)
  - Bump Standards-Version to 3.8.0
  - Bump debhelper dependancy to 7
  - Add ${misc:Depends} to make lintian happy
* {digikam|showfoto}.install:
  - Update icon paths
  - Do not package oxygen and apps icons: provided by kde-icons-oxygen
* patches/01-kubuntu-fix-armel.patch:
  - Fix cut&paste bug in the patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
 * Description : a widget to draw stars rating
8
8
 *
9
9
 * Copyright (C) 2005 by Owen Hirst <n8rider@sbcglobal.net>
10
 
 * Copyright (C) 2006-2008 by Gilles Caulier <caulier dot gilles at gmail dot com>
 
10
 * Copyright (C) 2006-2009 by Gilles Caulier <caulier dot gilles at gmail dot com>
11
11
 *
12
12
 * This program is free software; you can redistribute it
13
13
 * and/or modify it under the terms of the GNU General
50
50
 
51
51
    RatingWidgetPriv()
52
52
    {
53
 
        rating = 0;
 
53
        tracking = true;
 
54
        rating   = 0;
54
55
 
55
56
        // Pre-computed star polygon for a 15x15 pixmap.
56
57
        starPolygon << QPoint(0,  6);
65
66
        starPolygon << QPoint(4,  9);
66
67
    }
67
68
 
 
69
    bool     tracking;
 
70
 
68
71
    int      rating;
69
72
 
70
73
    QPolygon starPolygon;
95
98
 
96
99
void RatingWidget::setRating(int val)
97
100
{
98
 
    if (val < RatingMin || val > RatingMax) return;
 
101
    if ((val < RatingMin || val > RatingMax) && val != NoRating) return;
99
102
 
100
103
    d->rating = val;
101
104
    emit signalRatingChanged(d->rating);
107
110
    return d->rating;
108
111
}
109
112
 
 
113
void RatingWidget::setTracking(bool tracking)
 
114
{
 
115
    d->tracking = tracking;
 
116
}
 
117
 
 
118
bool RatingWidget::hasTracking() const
 
119
{
 
120
    return d->tracking;
 
121
}
 
122
 
 
123
void RatingWidget::mousePressEvent(QMouseEvent* e)
 
124
{
 
125
    int pos = e->x() / d->regPixmap.width() +1;
 
126
 
 
127
    if (d->rating == pos)
 
128
    {
 
129
        d->rating--;
 
130
    }
 
131
    else
 
132
    {
 
133
        d->rating = pos;
 
134
    }
 
135
 
 
136
    if (d->tracking)
 
137
        emit signalRatingChanged(d->rating);
 
138
 
 
139
    update();
 
140
}
 
141
 
110
142
void RatingWidget::mouseMoveEvent(QMouseEvent* e)
111
143
{
112
144
    int pos = e->x() / d->regPixmap.width() +1;
119
151
            pos = RatingMin;
120
152
 
121
153
        d->rating = pos;
122
 
        emit signalRatingChanged(d->rating);
 
154
 
 
155
        if (d->tracking)
 
156
            emit signalRatingChanged(d->rating);
 
157
 
123
158
        update();
124
159
    }
125
160
}
126
161
 
127
 
void RatingWidget::mousePressEvent(QMouseEvent* e)
 
162
void RatingWidget::mouseReleaseEvent(QMouseEvent*)
128
163
{
129
 
    int pos = e->x() / d->regPixmap.width() +1;
130
 
 
131
 
    if (d->rating == pos)
132
 
    {
133
 
        d->rating--;
134
 
    }
135
 
    else
136
 
    {
137
 
        d->rating = pos;
138
 
    }
139
 
 
140
164
    emit signalRatingChanged(d->rating);
141
 
 
142
 
    update();
143
165
}
144
166
 
145
167
void RatingWidget::paintEvent(QPaintEvent*)
153
175
        for (int i = 0; i < RatingMax; i++)
154
176
        {
155
177
            p.drawPixmap(x, 0, d->disPixmap);
156
 
            x += d->disPixmap.width();
 
178
            x += d->disPixmap.width()+1;
157
179
        }
158
180
    }
159
181
    else
162
184
        for (int i = 0; i < d->rating; i++)
163
185
        {
164
186
            p.drawPixmap(x, 0, d->selPixmap);
165
 
            x += d->selPixmap.width();
 
187
            x += d->selPixmap.width()+1;
166
188
        }
167
189
 
168
190
        for (int i = d->rating; i < RatingMax; i++)
169
191
        {
170
192
            p.drawPixmap(x, 0, d->regPixmap);
171
 
            x += d->regPixmap.width();
 
193
            x += d->regPixmap.width()+1;
172
194
        }
173
195
    }
174
196
 
225
247
    p3.drawPolygon(d->starPolygon, Qt::WindingFill);
226
248
    p3.end();
227
249
 
228
 
    setFixedSize(QSize(d->regPixmap.width()*RatingMax, d->regPixmap.height()));
 
250
    setFixedSize(QSize((d->regPixmap.width()+1)*RatingMax, d->regPixmap.height()));
229
251
    update();
230
252
}
231
253