[KimDaBa] Date dialog : highlight days where pictures are available

Jean-Michel FAYARD jmfayard at gmail.com
Sat Dec 4 08:47:41 GMT 2004


Hello Jesper,

a patch I did last friday to higlight dates and dates-range of
pictures in the current
context in the "search by date" dialog, making it two times better...

I have no artistic sense, so you can probably fine-tune better
setCustomDatePainting()
http://developer.kde.org/documentation/library/cvs-api/kdeui/html/classKDateTable.html#a9

That´s not the current CVS, but a 2.0-pre just before the last change
on the date dialog.
Hope it works !

--- datefolder.h.orig	2004-09-23 21:44:54.000000000 +0200
+++ datefolder.h	2004-12-03 00:07:39.420181192 +0100
@@ -45,6 +45,10 @@
     void toDateChanged();
 
 private:
+    void highlightPossibleDates( KDatePicker* picker);
+
+    QDate  _prevFrom;
+    QDate  _prevTo;
     KDatePicker* _from;
     KDatePicker* _to;
     bool _toChanged;



--- datefolder.cpp.orig	2004-09-23 21:44:54.000000000 +0200
+++ datefolder.cpp	2004-12-03 03:05:50.689861152 +0100
@@ -24,6 +24,15 @@
 #include <kdatepicker.h>
 #include <qlabel.h>
 #include "contentfolder.h"
+
+#include "mainview.h"
+#include <kdatetbl.h> 
+#include <qdatetime.h>
+#include "imagedb.h"
+#include "imageinfo.h"
+#include "imagesearchinfo.h"
+#include <kdebug.h>
+
 DateFolder::DateFolder( const ImageSearchInfo& info, Browser* parent )
     :Folder( info, parent )
 {
@@ -80,6 +89,10 @@
 
     _from->setDate( QDate( QDate::currentDate().year(), 1, 1 ) );
     _to->setDate( QDate( QDate::currentDate().year()+1, 1, 1 ) );
+    _prevFrom = _from->date();
+    _prevTo   = _to   ->date();
+    highlightPossibleDates( _from );
+    highlightPossibleDates( _to   );
     connect( _from, SIGNAL( dateChanged( QDate ) ), this, SLOT(
fromDateChanged( QDate ) ) );
     connect( _to, SIGNAL( dateChanged( QDate ) ), this, SLOT(
toDateChanged() ) );
 }
@@ -96,13 +109,20 @@
 
 void DateSearchDialog::fromDateChanged( QDate date )
 {
+    if ( (_prevFrom.year() != date.year()) || (_prevFrom.month() !=
date.month() ) )
+	highlightPossibleDates( _from );
     if ( !_toChanged )
         _to->setDate( date );
+    _prevFrom = date;
 }
 
 void DateSearchDialog::toDateChanged()
 {
+    QDate date = _to->date();
+    if ( (_prevTo.year() != date.year()) || (_prevTo.month() !=
date.month() ) )
+	highlightPossibleDates( _to );
     _toChanged = true;
+    _prevTo = date;
 }
 
 QString DateFolder::countLabel() const
@@ -110,4 +130,54 @@
     return QString::null;
 }
 
+void DateSearchDialog::highlightPossibleDates( KDatePicker* picker)
+{
+    KDateTable * dateTable = picker->dateTable();
+    ImageSearchInfo context = MainView::theMainView()->currentContext();
+    ImageDate date = ImageDate( picker->date() );
+
+    int nbDays = date.getDate().daysInMonth() ;
+    bool picturesByDays[ nbDays ];
+    for (int i = 0 ; i < nbDays ; i++ ) { picturesByDays[i] = false; }
+    
+    date.setDay( 1 );
+    context.setStartDate( date );
+    date.setDay( date.getDate().daysInMonth() );
+    context.setEndDate( date );
+    ImageInfoList list = ImageDB::instance()->images( context, TRUE );
+     
+    ImageInfo* image;
+    for( image = list.first(); image ; image=list.next() )
+    {
+	int a,b;
+	QDate start = image->startDate().getDate();
+	a = start.day();
+	if ( date.year()  < start.year() )
+	    a = 1;
+	else if (date.month() < start.month() )
+	    a=1;
+
+	QDate end = image->endDate().getDate();
+	b = end.day();
+	if ( end.year() < date.year()  ) //TODO: how to check there is no
second date ?
+	    b = a;
+	else if (date.year()  > end.year())
+	    b = nbDays;
+	else if (date.month() > end.month() )
+	    b = nbDays;
+
+	for (int i = a ; i <= b ; i++ )
+	    picturesByDays[ i-1 ] = true;
+
+    }
+    for( int i = 0 ; i < nbDays ; i++ ) 
+    {
+	if (picturesByDays[ i ] == false)
+	    continue;
+	date.setDay( i+1 );
+	// TODO: pick the best parameter possible for this function
+	dateTable->setCustomDatePainting( date.getDate(), QColor( "red" ) );
+    }
+}
 #include "datefolder.moc"
-------------- next part --------------
A non-text attachment was scrubbed...
Name: datefolder.cpp
Type: application/octet-stream
Size: 5606 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/kphotoalbum/attachments/20041204/638f078c/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: datefolder.h
Type: application/octet-stream
Size: 1677 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/kphotoalbum/attachments/20041204/638f078c/attachment-0001.obj>


More information about the Kphotoalbum mailing list