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

« back to all changes in this revision

Viewing changes to digikam/monthwidget.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:
93
93
};
94
94
 
95
95
MonthWidget::MonthWidget(QWidget* parent)
96
 
           : QWidget(parent), d(new MonthWidgetPriv)
 
96
    : QWidget(parent), d(new MonthWidgetPriv)
97
97
{
98
98
    setWindowFlags(Qt::WNoAutoErase);
99
99
    init();
161
161
    return QSize(d->width * 8, d->height * 9);
162
162
}
163
163
 
164
 
void MonthWidget::resizeEvent(QResizeEvent *e)
 
164
void MonthWidget::resizeEvent(QResizeEvent* e)
165
165
{
166
166
    QWidget::resizeEvent(e);
167
167
 
189
189
    int sx, sy;
190
190
    int index = 0;
191
191
    bool weekvisible;
 
192
 
192
193
    for (int j=3; j<9; ++j)
193
194
    {
194
195
        sy = d->currh * j;
199
200
            sx = d->currw * i;
200
201
            r.moveTopLeft(QPoint(sx,sy));
201
202
            rsmall = QRect(r.x()+1, r.y()+1, r.width()-2, r.height()-2);
 
203
 
202
204
            if (d->days[index].day != -1)
203
205
            {
204
206
                if (d->days[index].selected)
232
234
                p.drawText(rsmall, Qt::AlignVCenter|Qt::AlignHCenter,
233
235
                           QString::number(d->days[index].day));
234
236
 
235
 
                if(!weekvisible)
 
237
                if (!weekvisible)
236
238
                {
237
239
                    int weeknr = KGlobal::locale()->calendar()->weekNumber(QDate(d->year,
238
 
                                                                           d->month, d->days[index].day));
 
240
                                 d->month, d->days[index].day));
239
241
                    p.setPen(d->active ? Qt::black : Qt::gray);
240
242
                    p.setFont(fnBold);
241
243
                    p.fillRect(1, sy, d->currw-1, d->currh-1, QColor(210,210,210));
254
256
    p.setFont(fnBold);
255
257
 
256
258
    sy = 2*d->currh;
 
259
 
257
260
    for (int i=1; i<8; ++i)
258
261
    {
259
262
        sx = d->currw * i;
262
265
        rsmall.setWidth(r.width() - 2);
263
266
        rsmall.setHeight(r.height() - 2);
264
267
        p.drawText(rsmall, Qt::AlignVCenter|Qt::AlignHCenter,
265
 
                           KGlobal::locale()->calendar()->weekDayName(i, KCalendarSystem::ShortDayName)
266
 
                           .remove(2,1));
 
268
                   KGlobal::locale()->calendar()->weekDayName(i, KCalendarSystem::ShortDayName)
 
269
                   .remove(2,1));
267
270
        ++index;
268
271
    }
269
272
 
274
277
 
275
278
    p.drawText(r, Qt::AlignCenter,
276
279
               QString("%1 %2")
277
 
                .arg(KGlobal::locale()->calendar()->monthName(d->month, KCalendarSystem::LongDayName))
278
 
                .arg(KGlobal::locale()->calendar()->year(QDate(d->year,d->month,1))));
 
280
               .arg(KGlobal::locale()->calendar()->monthName(d->month, KCalendarSystem::LongDayName))
 
281
               .arg(KGlobal::locale()->calendar()->year(QDate(d->year,d->month,1))));
279
282
 
280
283
    p.end();
281
284
 
284
287
    p2.end();
285
288
}
286
289
 
287
 
void MonthWidget::mousePressEvent(QMouseEvent *e)
 
290
void MonthWidget::mousePressEvent(QMouseEvent* e)
288
291
{
289
292
    int firstSelected = 0, lastSelected = 0;
 
293
 
290
294
    if (e->modifiers() != Qt::ControlModifier)
291
295
    {
292
296
        for (int i=0; i<42; ++i)
294
298
            if (d->days[i].selected)
295
299
            {
296
300
                if (firstSelected==0)
 
301
                {
297
302
                    firstSelected = i;
 
303
                }
 
304
 
298
305
                lastSelected =i;
299
306
            }
 
307
 
300
308
            d->days[i].selected = false;
301
309
        }
302
310
    }
306
314
    QRect r3(d->currw, d->currh*2, d->currw*7, d->currh);
307
315
 
308
316
    // Click on a weekday
309
 
    if( r3.contains(e->pos()))
 
317
    if ( r3.contains(e->pos()))
310
318
    {
311
319
        int j = (e->pos().x() - d->currw)/d->currw;
 
320
 
312
321
        for (int i=0; i<6; ++i)
313
322
        {
314
323
            d->days[i*7+j].selected = !d->days[i*7+j].selected;
318
327
    else if (r1.contains(e->pos()))
319
328
    {
320
329
        int j = (e->pos().y() - 3*d->currh)/d->currh;
 
330
 
321
331
        for (int i=0; i<7; ++i)
322
332
        {
323
333
            d->days[j*7+i].selected = !d->days[j*7+i].selected;
329
339
        int i, j;
330
340
        i = (e->pos().x() - d->currw)/d->currw;
331
341
        j = (e->pos().y() - 3*d->currh)/d->currh;
 
342
 
332
343
        if (e->modifiers() == Qt::ShiftModifier)
333
344
        {
334
345
            int endSelection = j*7+i;
 
346
 
335
347
            if (endSelection > firstSelected)
336
348
                for (int i2=firstSelected ; i2 <= endSelection; ++i2)
 
349
                {
337
350
                    d->days[i2].selected = true;
 
351
                }
338
352
            else if (endSelection < firstSelected)
339
353
                for (int i2=lastSelected ; i2 >= endSelection; --i2)
 
354
                {
340
355
                    d->days[i2].selected = true;
 
356
                }
341
357
        }
342
358
        else
 
359
        {
343
360
            d->days[j*7+i].selected = !d->days[j*7+i].selected;
 
361
        }
344
362
    }
345
363
 
346
364
    QList<QDateTime> filterDays;
 
365
 
347
366
    for (int i=0; i<42; ++i)
348
367
    {
349
368
        if (d->days[i].selected && d->days[i].day != -1)
 
369
        {
350
370
            filterDays.append(QDateTime(QDate(d->year, d->month, d->days[i].day), QTime()));
 
371
        }
351
372
    }
352
373
 
353
374
    if (d->model)
 
375
    {
354
376
        d->model->setDayFilter(filterDays);
 
377
    }
355
378
 
356
379
    update();
357
380
}
359
382
void MonthWidget::setActive(bool val)
360
383
{
361
384
    if (d->active == val)
 
385
    {
362
386
        return;
 
387
    }
363
388
 
364
389
    d->active = val;
365
390
 
381
406
    }
382
407
}
383
408
 
384
 
void MonthWidget::setImageModel(ImageFilterModel *model)
 
409
void MonthWidget::setImageModel(ImageFilterModel* model)
385
410
{
386
411
    if (d->model)
 
412
    {
387
413
        disconnect(d->model, 0, this, 0);
 
414
    }
388
415
 
389
416
    d->model = model;
390
417
    connectModel();
404
431
                this, SLOT(triggerUpdateDays()));
405
432
        connect(d->model, SIGNAL(modelReset()),
406
433
                this, SLOT(triggerUpdateDays()));
407
 
//        connect(d->model, SIGNAL(triggerUpdateDays()),
408
 
//                this, SLOT(triggerUpdateDays()));
 
434
        //        connect(d->model, SIGNAL(triggerUpdateDays()),
 
435
        //                this, SLOT(triggerUpdateDays()));
409
436
        //connect(d->model, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
410
 
          //      this, SLOT(triggerUpdateDays()));
 
437
        //      this, SLOT(triggerUpdateDays()));
411
438
    }
412
439
}
413
440
 
414
441
void MonthWidget::triggerUpdateDays()
415
442
{
416
443
    if (!d->timer->isActive())
 
444
    {
417
445
        d->timer->start();
 
446
    }
418
447
}
419
448
 
420
449
void MonthWidget::resetDayCounts()
429
458
void MonthWidget::updateDays()
430
459
{
431
460
    if (!d->active)
 
461
    {
432
462
        return;
 
463
    }
433
464
 
434
465
    resetDayCounts();
435
466
 
436
467
    if (!d->model)
 
468
    {
437
469
        return;
 
470
    }
438
471
 
439
472
    const int size = d->model->rowCount();
 
473
 
440
474
    for (int i=0; i<size; i++)
441
475
    {
442
476
        QModelIndex index = d->model->index(i, 0);
 
477
 
443
478
        if (!index.isValid())
 
479
        {
444
480
            continue;
 
481
        }
 
482
 
445
483
        QDateTime dt = d->model->data(index, ImageModel::CreationDateRole).toDateTime();
 
484
 
446
485
        if (dt.isNull())
 
486
        {
447
487
            continue;
 
488
        }
448
489
 
449
490
        for (int i=0; i<42; ++i)
450
491
        {