~ubuntu-branches/ubuntu/saucy/digikam/saucy

« back to all changes in this revision

Viewing changes to utilities/searchwindow/ratingsearchutilities.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Scott Kitterman
  • Date: 2010-12-21 23:19:11 UTC
  • mfrom: (1.2.33 upstream) (3.1.7 experimental)
  • Revision ID: james.westby@ubuntu.com-20101221231911-z9jip7s5aht1jqn9
Tags: 2:1.7.0-1ubuntu1
* Merge from Debian Experimental. Remaining Ubuntu changes:
  - Export .pot name and copy to plugins in debian/rules
  - Version build-depends on kipi-plugins-dev to ensure build is against the
    same version on all archs
* Drop debian/patches/kubuntu_01_linker.diff, incoporated upstream
* Remove patches directory and unused patches

Show diffs side-by-side

added added

removed removed

Lines of Context:
67
67
    starPolygonSize = QSize(15, 15);
68
68
}
69
69
 
70
 
QRect RatingStarDrawer::drawStarPolygons(QPainter *painter, int numberOfStars) const
 
70
QRect RatingStarDrawer::drawStarPolygons(QPainter* painter, int numberOfStars) const
71
71
{
72
72
    QRect drawnRect(0, 0, 0, 0);
73
73
    QPolygon polygon(starPolygon);
74
74
 
75
75
    if (numberOfStars)
 
76
    {
76
77
        drawnRect.adjust(0, 0, 0, starPolygonSize.height());
 
78
    }
77
79
 
78
80
    for (int i=0; i<numberOfStars; ++i)
79
81
    {
87
89
 
88
90
// -------------------------------------------------------------------------
89
91
 
90
 
RatingComboBoxDelegate::RatingComboBoxDelegate(QObject *parent)
91
 
                      : QItemDelegate(parent)
 
92
RatingComboBoxDelegate::RatingComboBoxDelegate(QObject* parent)
 
93
    : QItemDelegate(parent)
92
94
{
93
95
}
94
96
 
95
 
QSize RatingComboBoxDelegate::sizeHint ( const QStyleOptionViewItem & option, const QModelIndex & index ) const
 
97
QSize RatingComboBoxDelegate::sizeHint ( const QStyleOptionViewItem& option, const QModelIndex& index ) const
96
98
{
97
99
    QVariant value = index.data(Qt::DisplayRole);
 
100
 
98
101
    if (value.type() == QVariant::Int)
99
102
    {
100
103
        return QSize(RatingMax * (starPolygonSize.width() + 1), starPolygonSize.height());
105
108
    }
106
109
}
107
110
 
108
 
void RatingComboBoxDelegate::paint(QPainter *painter, const QStyleOptionViewItem& option,
109
 
                                   const QModelIndex &index) const
 
111
void RatingComboBoxDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option,
 
112
                                   const QModelIndex& index) const
110
113
{
111
114
    QVariant value  = index.data(Qt::DisplayRole);
112
115
    bool selectable = index.flags() & Qt::ItemIsSelectable;
 
116
 
113
117
    if (value.type() == QVariant::Int)
114
118
    {
115
119
        painter->save();
128
132
    }
129
133
}
130
134
 
131
 
void RatingComboBoxDelegate::drawRating(QPainter *painter, const QRect& rect, int rating, bool selectable) const
 
135
void RatingComboBoxDelegate::drawRating(QPainter* painter, const QRect& rect, int rating, bool selectable) const
132
136
{
133
137
    painter->save();
134
138
 
137
141
    painter->setPen(ThemeEngine::instance()->textRegColor());
138
142
 
139
143
    if (!selectable)
 
144
    {
140
145
        painter->setOpacity(.1);
 
146
    }
141
147
 
142
148
    painter->setBrush(ThemeEngine::instance()->textSpecialRegColor());
143
149
    // move painter while drawing polygons
153
159
 
154
160
// -------------------------------------------------------------------------
155
161
 
156
 
RatingComboBoxModel::RatingComboBoxModel(QObject *parent)
157
 
                   : QAbstractListModel(parent)
 
162
RatingComboBoxModel::RatingComboBoxModel(QObject* parent)
 
163
    : QAbstractListModel(parent)
158
164
{
159
165
    for (int value = RatingComboBox::Null; value <= RatingComboBox::Rating5; ++value)
 
166
    {
160
167
        m_entries << (RatingComboBox::RatingValue)value;
 
168
    }
161
169
}
162
170
 
163
 
int RatingComboBoxModel::rowCount(const QModelIndex & parent) const
 
171
int RatingComboBoxModel::rowCount(const QModelIndex& parent) const
164
172
{
165
173
    if (parent.isValid())
 
174
    {
166
175
        return 0;
 
176
    }
 
177
 
167
178
    return m_entries.size();
168
179
}
169
180
 
172
183
    if (index.isValid())
173
184
    {
174
185
        RatingComboBox::RatingValue value = (RatingComboBox::RatingValue)index.internalId();
 
186
 
175
187
        if (role == Qt::DisplayRole)
 
188
        {
176
189
            return ratingValueToDisplay(value);
 
190
        }
177
191
        else if (role == RatingRole)
 
192
        {
178
193
            return (int)value;
 
194
        }
179
195
    }
 
196
 
180
197
    return QVariant();
181
198
}
182
199
 
196
213
        case RatingComboBox::Rating5:
197
214
            return (int)value;
198
215
    }
 
216
 
199
217
    return QVariant();
200
218
}
201
219
 
202
220
QModelIndex RatingComboBoxModel::index(int row, int column, const QModelIndex& parent) const
203
221
{
204
222
    if (parent.isValid() || column != 0 || row >= m_entries.size())
 
223
    {
205
224
        return QModelIndex();
 
225
    }
206
226
 
207
227
    // third argument: RatingValue as internal data
208
228
    return createIndex(row, column, m_entries[row]);
211
231
QModelIndex RatingComboBoxModel::indexForRatingValue(RatingComboBox::RatingValue value) const
212
232
{
213
233
    int row = m_entries.indexOf(value);
 
234
 
214
235
    if (row != -1)
 
236
    {
215
237
        return createIndex(row, 0, value);
 
238
    }
 
239
 
216
240
    return QModelIndex();
217
241
}
218
242
 
219
243
// -------------------------------------------------------------------------
220
244
 
221
 
RatingComboBoxWidget::RatingComboBoxWidget(QWidget *parent)
222
 
                    : RatingWidget(parent)
 
245
RatingComboBoxWidget::RatingComboBoxWidget(QWidget* parent)
 
246
    : RatingWidget(parent)
223
247
{
224
248
    m_value = RatingComboBox::Null;
225
249
 
241
265
void RatingComboBoxWidget::setRatingValue(RatingComboBox::RatingValue value)
242
266
{
243
267
    if (m_value == value)
 
268
    {
244
269
        return;
 
270
    }
245
271
 
246
272
    m_value = value;
247
273
 
248
274
    // sync with base class
249
275
    blockSignals(true);
 
276
 
250
277
    if (m_value >= RatingComboBox::Rating0)
 
278
    {
251
279
        setRating(value);
 
280
    }
252
281
    else
 
282
    {
253
283
        setRating(0);
 
284
    }
 
285
 
254
286
    blockSignals(false);
255
287
 
256
288
    update();
260
292
void RatingComboBoxWidget::slotRatingChanged(int rating)
261
293
{
262
294
    RatingComboBox::RatingValue newValue = (RatingComboBox::RatingValue)rating;
 
295
 
263
296
    if (m_value != newValue)
264
297
    {
265
298
        m_value = newValue;
267
300
    }
268
301
}
269
302
 
270
 
void RatingComboBoxWidget::paintEvent(QPaintEvent *e)
 
303
void RatingComboBoxWidget::paintEvent(QPaintEvent* e)
271
304
{
272
305
    if (m_value >= RatingComboBox::Rating0)
273
306
    {
289
322
    else if (m_value == RatingComboBox::Null)
290
323
    {
291
324
        QPainter p(this);
 
325
 
292
326
        if (underMouse() && isEnabled())
293
327
        {
294
328
            QPixmap pix = starPixmap();
295
329
            int x = 0;
 
330
 
296
331
            for (int i = 0; i < RatingMax; ++i)
297
332
            {
298
333
                p.drawPixmap(x, 0, pix);
328
363
 
329
364
// -------------------------------------------------------------------------
330
365
 
331
 
RatingComboBox::RatingComboBox(QWidget *parent)
332
 
              : ModelIndexBasedComboBox(parent)
 
366
RatingComboBox::RatingComboBox(QWidget* parent)
 
367
    : ModelIndexBasedComboBox(parent)
333
368
{
334
369
    m_syncing = false;
335
370
 
338
373
    setModel(m_model);
339
374
 
340
375
    // set a custom delegate which draws rating stars
341
 
    RatingComboBoxDelegate *delegate = new RatingComboBoxDelegate(this);
 
376
    RatingComboBoxDelegate* delegate = new RatingComboBoxDelegate(this);
342
377
    view()->setItemDelegate(delegate);
343
378
 
344
379
    // set a line edit that carries a RatingWidget
345
 
    ProxyLineEdit *lineEdit = new ProxyLineEdit;
 
380
    ProxyLineEdit* lineEdit = new ProxyLineEdit;
346
381
    m_ratingWidget = new RatingComboBoxWidget;
347
382
    lineEdit->setWidget(m_ratingWidget);
348
383
    setLineEdit(lineEdit);
349
384
 
350
 
    connect(view()->selectionModel(), SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)),
351
 
            this, SLOT(currentValueChanged(const QModelIndex &, const QModelIndex &)));
 
385
    connect(view()->selectionModel(), SIGNAL(currentChanged(const QModelIndex&, const QModelIndex&)),
 
386
            this, SLOT(currentValueChanged(const QModelIndex&, const QModelIndex&)));
352
387
 
353
388
    connect(m_ratingWidget, SIGNAL(ratingValueChanged(int)),
354
389
            this, SLOT(ratingWidgetChanged(int)));
357
392
void RatingComboBox::setRatingValue(RatingComboBox::RatingValue value)
358
393
{
359
394
    if (value > Rating5)
 
395
    {
360
396
        value = Rating5;
 
397
    }
361
398
    else if (value < Null)
 
399
    {
362
400
        value = Null;
 
401
    }
 
402
 
363
403
    setCurrentIndex(m_model->indexForRatingValue(value));
364
404
}
365
405
 
368
408
    return (RatingValue)view()->currentIndex().data(RatingComboBoxModel::RatingRole).toInt();
369
409
}
370
410
 
371
 
void RatingComboBox::currentValueChanged(const QModelIndex& current, const QModelIndex &)
 
411
void RatingComboBox::currentValueChanged(const QModelIndex& current, const QModelIndex&)
372
412
{
373
413
    if (m_syncing)
 
414
    {
374
415
        return;
 
416
    }
375
417
 
376
418
    RatingValue value = (RatingValue)current.data(RatingComboBoxModel::RatingRole).toInt();
377
419
 
385
427
void RatingComboBox::ratingWidgetChanged(int rv)
386
428
{
387
429
    if (m_syncing)
 
430
    {
388
431
        return;
 
432
    }
389
433
 
390
434
    RatingValue value = (RatingValue)rv;
391
435
    QModelIndex index = m_model->indexForRatingValue(value);