author | umopapisdn <umopapisdn> | 2003-05-05 21:44:39 (UTC) |
---|---|---|
committer | umopapisdn <umopapisdn> | 2003-05-05 21:44:39 (UTC) |
commit | 3b193b852133a82b5c1708b68a7e460c63629768 (patch) (side-by-side diff) | |
tree | 8cd0ff3adc14f0b937d24ab99fca327fb3f16875 | |
parent | 12a700f8903eedeba03d3aba7990b9d660410045 (diff) | |
download | opie-3b193b852133a82b5c1708b68a7e460c63629768.zip opie-3b193b852133a82b5c1708b68a7e460c63629768.tar.gz opie-3b193b852133a82b5c1708b68a7e460c63629768.tar.bz2 |
UI and code cleanup. Both UI and code is now more consistent. Also removed menus in favor of toolbuttons. (why were they even available as menus in the first place?)
-rw-r--r-- | core/pim/datebook/datebook.cpp | 276 | ||||
-rw-r--r-- | core/pim/datebook/datebookweek.cpp | 179 | ||||
-rw-r--r-- | core/pim/datebook/datebookweek.h | 2 | ||||
-rw-r--r-- | core/pim/datebook/datebookweekheader.ui | 62 | ||||
-rw-r--r-- | core/pim/datebook/datebookweekheaderimpl.cpp | 137 | ||||
-rw-r--r-- | core/pim/datebook/datebookweekheaderimpl.h | 19 | ||||
-rw-r--r-- | core/pim/datebook/datebookweeklst.cpp | 212 | ||||
-rw-r--r-- | core/pim/datebook/datebookweeklst.h | 41 | ||||
-rw-r--r-- | core/pim/datebook/datebookweeklstheader.ui | 127 |
9 files changed, 453 insertions, 602 deletions
diff --git a/core/pim/datebook/datebook.cpp b/core/pim/datebook/datebook.cpp index cf1eeca..b7e89b0 100644 --- a/core/pim/datebook/datebook.cpp +++ b/core/pim/datebook/datebook.cpp @@ -1,1087 +1,1063 @@ /********************************************************************** ** Copyright (C) 2000 Trolltech AS. All rights reserved. ** ** This file is part of Qtopia Environment. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** ** $Id$ ** **********************************************************************/ #define QTOPIA_INTERNAL_FD #include "datebook.h" #include "datebookday.h" #include "datebooksettings.h" #include "datebookweek.h" #include "datebookweeklst.h" #include "dateentryimpl.h" #include <qpe/datebookmonth.h> #include <qpe/qpeapplication.h> #include <qpe/config.h> #include <qpe/qpedebug.h> #include <qpe/event.h> #include <qpe/finddialog.h> #include <qpe/ir.h> #include <qpe/qpemenubar.h> #include <qpe/qpemessagebox.h> #include <qpe/resource.h> #include <qpe/sound.h> #include <qpe/timestring.h> #include <qpe/qpetoolbar.h> #include <qpe/tzselect.h> #include <qpe/xmlreader.h> #include <qaction.h> #include <qcopchannel_qws.h> #include <qdatetime.h> #include <qdialog.h> #include <qfile.h> #include <qlabel.h> #include <qlayout.h> #include <qmessagebox.h> #include <qpopupmenu.h> #include <qpushbutton.h> #include <qregexp.h> #include <qtextcodec.h> #include <qtextstream.h> #include <qtimer.h> #include <qtl.h> #include <qwidgetstack.h> #include <qwindowsystem_qws.h> #include <sys/stat.h> #include <sys/types.h> #include <fcntl.h> #include <unistd.h> #include <stdlib.h> DateBook::DateBook( QWidget *parent, const char *, WFlags f ) : QMainWindow( parent, "datebook", f ), aPreset( FALSE ), presetTime( -1 ), startTime( 8 ), // an acceptable default rowStyle( 0 ), bJumpToCurTime(FALSE), syncing(FALSE), inSearch(FALSE), alarmCounter(0) { - bool needEvilHack= false; // if we need an Evil Hack - QTime t; - t.start(); - db = new DateBookDBHack; - qDebug("loading db t=%d", t.elapsed() ); - loadSettings(); - setCaption( tr("Calendar") ); - setIcon( Resource::loadPixmap( "datebook_icon" ) ); - - setToolBarsMovable( FALSE ); - - views = new QWidgetStack( this ); - setCentralWidget( views ); - - dayView = 0; - weekView = 0; - weekLstView = 0; - monthView = 0; - - QPEToolBar *bar = new QPEToolBar( this ); - bar->setHorizontalStretchable( TRUE ); - - QPEMenuBar *mb = new QPEMenuBar( bar ); - mb->setMargin( 0 ); - - QPEToolBar *sub_bar = new QPEToolBar(this); - - QPopupMenu *view = new QPopupMenu( this ); - QPopupMenu *settings = new QPopupMenu( this ); - - mb->insertItem( tr( "View" ), view ); - mb->insertItem( tr( "Settings" ), settings ); - - QActionGroup *g = new QActionGroup( this ); - g->setExclusive( TRUE ); - - QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), - QString::null, 0, this, 0 ); - connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) ); - a->addTo( sub_bar ); - - a = new QAction( tr( "Today" ), Resource::loadPixmap( "datebook/to_day" ), QString::null, 0, g, 0 ); - connect( a, SIGNAL( activated() ), this, SLOT( slotToday() ) ); - a->addTo( sub_bar ); - a->addTo( view ); - - a = new QAction( tr( "Day" ), Resource::loadPixmap( "day" ), QString::null, 0, g, 0 ); - connect( a, SIGNAL( activated() ), this, SLOT( viewDay() ) ); - a->addTo( sub_bar ); - a->addTo( view ); - a->setToggleAction( TRUE ); - a->setOn( TRUE ); - dayAction = a; - - a = new QAction( tr( "Week" ), Resource::loadPixmap( "week" ), QString::null, 0, g, 0 ); - connect( a, SIGNAL( activated() ), this, SLOT( viewWeek() ) ); - a->addTo( sub_bar ); - a->addTo( view ); - a->setToggleAction( TRUE ); - weekAction = a; - - a = new QAction( tr( "WeekLst" ), Resource::loadPixmap( "datebook/weeklst" ), QString::null, 0, g, 0 ); - connect( a, SIGNAL( activated() ), this, SLOT( viewWeekLst() ) ); - a->addTo( sub_bar ); - a->addTo( view ); - a->setToggleAction( TRUE ); - weekLstAction = a; - - a = new QAction( tr( "Month" ), Resource::loadPixmap( "month" ), QString::null, 0, g, 0 ); - connect( a, SIGNAL( activated() ), this, SLOT( viewMonth() ) ); - a->addTo( sub_bar ); - a->addTo( view ); - a->setToggleAction( TRUE ); - monthAction = a; - - a = new QAction( tr( "Find" ), Resource::loadPixmap( "mag" ), QString::null, 0, g, 0 ); - connect( a, SIGNAL(activated()), this, SLOT(slotFind()) ); - a->addTo( sub_bar ); - - a = new QAction( tr( "Edit..." ), QString::null, 0, 0 ); - connect( a, SIGNAL( activated() ), this, SLOT( slotSettings() ) ); - a->addTo( settings ); + bool needEvilHack= false; // if we need an Evil Hack + QTime t; + t.start(); + db = new DateBookDBHack; + qDebug("loading db t=%d", t.elapsed() ); + loadSettings(); + setCaption( tr("Calendar") ); + setIcon( Resource::loadPixmap( "datebook_icon" ) ); + + setToolBarsMovable( FALSE ); + + views = new QWidgetStack( this ); + setCentralWidget( views ); + + dayView = 0; + weekView = 0; + weekLstView = 0; + monthView = 0; + +// QPEToolBar *bar = new QPEToolBar( this ); +// bar->setHorizontalStretchable( TRUE ); + +// QPEMenuBar *mb = new QPEMenuBar( bar ); +// mb->setMargin( 0 ); + +// QPopupMenu *view = new QPopupMenu( this ); +// mb->insertItem( tr( "View" ), view ); + + QPEToolBar *sub_bar = new QPEToolBar(this); + sub_bar->setHorizontalStretchable(TRUE); + + QActionGroup *g = new QActionGroup( this ); + g->setExclusive( TRUE ); + + QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), QString::null, 0, this, 0 ); + connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) ); + a->addTo( sub_bar ); + + sub_bar->addSeparator(); + + a = new QAction( tr( "Today" ), Resource::loadPixmap( "datebook/to_day" ), QString::null, 0, g, 0 ); + connect( a, SIGNAL( activated() ), this, SLOT( slotToday() ) ); + a->addTo( sub_bar ); +// a->addTo( view ); + + sub_bar->addSeparator(); + + a = new QAction( tr( "Day" ), Resource::loadPixmap( "day" ), QString::null, 0, g, 0 ); + connect( a, SIGNAL( activated() ), this, SLOT( viewDay() ) ); + a->addTo( sub_bar ); +// a->addTo( view ); + a->setToggleAction( TRUE ); + a->setOn( TRUE ); + dayAction = a; + + a = new QAction( tr( "Week" ), Resource::loadPixmap( "week" ), QString::null, 0, g, 0 ); + connect( a, SIGNAL( activated() ), this, SLOT( viewWeek() ) ); + a->addTo( sub_bar ); +// a->addTo( view ); + a->setToggleAction( TRUE ); + weekAction = a; + + a = new QAction( tr( "WeekLst" ), Resource::loadPixmap( "datebook/weeklst" ), QString::null, 0, g, 0 ); + connect( a, SIGNAL( activated() ), this, SLOT( viewWeekLst() ) ); + a->addTo( sub_bar ); +// a->addTo( view ); + a->setToggleAction( TRUE ); + weekLstAction = a; + + a = new QAction( tr( "Month" ), Resource::loadPixmap( "month" ), QString::null, 0, g, 0 ); + connect( a, SIGNAL( activated() ), this, SLOT( viewMonth() ) ); + a->addTo( sub_bar ); +// a->addTo( view ); + a->setToggleAction( TRUE ); + monthAction = a; + + sub_bar->addSeparator(); + + a = new QAction( tr( "Find" ), Resource::loadPixmap( "mag" ), QString::null, 0, this, 0 ); + connect( a, SIGNAL(activated()), this, SLOT(slotFind()) ); + a->addTo( sub_bar ); + + a = new QAction( tr( "Edit..." ), Resource::loadPixmap("SettingsIcon"), QString::null, 0, this, 0 ); + connect( a, SIGNAL( activated() ), this, SLOT( slotSettings() ) ); + a->addTo( sub_bar ); if(defaultView==DAY) viewDay(); if(defaultView==WEEK) needEvilHack=true; // viewWeek(); if(defaultView==WEEKLST) viewWeekLst(); if(defaultView==MONTH) viewMonth(); connect( qApp, SIGNAL(clockChanged(bool)), this, SLOT(changeClock(bool)) ); - connect( qApp, SIGNAL(weekChanged(bool)), this, SLOT(changeWeek(bool)) ); + connect( qApp, SIGNAL(weekChanged(bool)), this, SLOT(changeWeek(bool)) ); #if defined(Q_WS_QWS) && !defined(QT_NO_COP) - connect( qApp, SIGNAL(appMessage(const QCString&, const QByteArray&)), this, SLOT(appMessage(const QCString&, const QByteArray&)) ); + connect( qApp, SIGNAL(appMessage(const QCString&, const QByteArray&)), this, SLOT(appMessage(const QCString&, const QByteArray&)) ); #endif // listen on QPE/System #if defined(Q_WS_QWS) #if !defined(QT_NO_COP) - QCopChannel *channel = new QCopChannel( "QPE/System", this ); - connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), this, SLOT(receive(const QCString&, const QByteArray&)) ); - channel = new QCopChannel( "QPE/Datebook", this ); - connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), this, SLOT(receive(const QCString&, const QByteArray&)) ); - qDebug("olle\n"); + QCopChannel *channel = new QCopChannel( "QPE/System", this ); + connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), this, SLOT(receive(const QCString&, const QByteArray&)) ); + channel = new QCopChannel( "QPE/Datebook", this ); + connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), this, SLOT(receive(const QCString&, const QByteArray&)) ); + qDebug("olle\n"); #endif #endif - qDebug("done t=%d", t.elapsed() ); + qDebug("done t=%d", t.elapsed() ); /* * Here is a problem description: * When Weekview is the default view * a DateBookWeekView get's created * redraw() get's called. So what? * Remember that we're still in the c'tor * and no final layout has happened? Ok * now all Events get arranged. Their x * position get's determined by a QHeader * position. But the QHeader isn't layouted or * at the right position. redraw() is a slot * so we'll call it then via a singleShot * from view() */ if( needEvilHack ){ QTimer::singleShot( 500, this, SLOT(viewWeek()) ); } } void DateBook::receive( const QCString &msg, const QByteArray &data ) { QDataStream stream( data, IO_ReadOnly ); if ( msg == "timeChange(QString)" ) { // update active view! if ( dayAction->isOn() ) viewDay(); else if ( weekAction->isOn() ) viewWeek(); else if ( monthAction->isOn() ) viewMonth(); } else if (msg == "editEvent(int)") { int uid; stream >> uid; Event e=db->eventByUID(uid); editEvent(e); } } DateBook::~DateBook() { } void DateBook::slotSettings() { DateBookSettings frmSettings( ampm, this ); frmSettings.setStartTime( startTime ); frmSettings.setAlarmPreset( aPreset, presetTime ); frmSettings.setJumpToCurTime( bJumpToCurTime ); frmSettings.setRowStyle( rowStyle ); frmSettings.comboDefaultView->setCurrentItem(defaultView-1); frmSettings.comboWeekListView->setCurrentItem(weeklistviewconfig); bool found=false; for (int i=0; i<(frmSettings.comboLocation->count()); i++) { if ( frmSettings.comboLocation->text(i) == defaultLocation ) { frmSettings.comboLocation->setCurrentItem(i); found=true; break; } } if(!found) { frmSettings.comboLocation->insertItem(defaultLocation); frmSettings.comboLocation->setCurrentItem(frmSettings.comboLocation->count()-1); } frmSettings.comboCategory->setCategories(defaultCategories,"Calendar", tr("Calendar")); #if defined (Q_WS_QWS) || defined(_WS_QWS_) frmSettings.showMaximized(); #endif if ( frmSettings.exec() ) { aPreset = frmSettings.alarmPreset(); presetTime = frmSettings.presetTime(); startTime = frmSettings.startTime(); bJumpToCurTime = frmSettings.jumpToCurTime(); rowStyle = frmSettings.rowStyle(); defaultView=frmSettings.comboDefaultView->currentItem()+1; weeklistviewconfig=frmSettings.comboWeekListView->currentItem(); defaultLocation=frmSettings.comboLocation->currentText(); defaultCategories=frmSettings.comboCategory->currentCategories(); if ( dayView ) { dayView->setStartViewTime( startTime ); dayView->setJumpToCurTime( bJumpToCurTime ); dayView->setRowStyle( rowStyle ); } if ( weekView ) { weekView->setStartViewTime( startTime ); } saveSettings(); // make the change obvious if ( views->visibleWidget() ) { if ( views->visibleWidget() == dayView ) dayView->redraw(); else if ( views->visibleWidget() == weekView ) weekView->redraw(); else if ( views->visibleWidget() == weekLstView ) weekLstView->redraw(); } } } void DateBook::fileNew() { slotNewEventFromKey(""); } QString DateBook::checkEvent(const Event &e) { /* check if overlaps with itself */ bool checkFailed = FALSE; /* check the next 12 repeats. should catch most problems */ QDate current_date = e.start().date(); Event previous = e; for(int i = 0; i < 12; i++) { QDateTime next; if (!nextOccurance(previous, current_date.addDays(1), next)) { break; // no more repeats } if(next < previous.end()) { checkFailed = TRUE; break; } current_date = next.date(); } if(checkFailed) return tr("Event duration is potentially longer\n" "than interval between repeats."); return QString::null; } QDate DateBook::currentDate() { QDate d = QDate::currentDate(); if ( dayView && views->visibleWidget() == dayView ) { d = dayView->date(); } else if ( weekView && views->visibleWidget() == weekView ) { d = weekView->date(); } else if ( weekLstView && views->visibleWidget() == weekLstView ) { d = weekLstView->date(); } else if ( monthView && views->visibleWidget() == monthView ) { d = monthView->selectedDate(); } return d; } void DateBook::view(int v, const QDate &d) { if (v==DAY) { initDay(); dayAction->setOn( TRUE ); dayView->setDate( d ); views->raiseWidget( dayView ); dayView->redraw(); } else if (v==WEEK) { initWeek(); weekAction->setOn( TRUE ); weekView->setDate( d ); views->raiseWidget( weekView ); weekView->redraw(); } else if (v==WEEKLST) { initWeekLst(); weekLstAction->setOn( TRUE ); weekLstView->setDate(d); views->raiseWidget( weekLstView ); weekLstView->redraw(); } else if (v==MONTH) { initMonth(); monthAction->setOn( TRUE ); monthView->setDate( d.year(), d.month(), d.day() ); views->raiseWidget( monthView ); monthView->redraw(); } } void DateBook::viewDefault(const QDate &d) { -/* - Config config("DateBook"); - config.setGroup("Main"); - int current=config.readNumEntry("defaultview", DAY); - - view(current,d); -*/ view(defaultView,d); } void DateBook::viewDay() { - view(DAY,currentDate()); + view(DAY,currentDate()); } void DateBook::viewWeek() { - view(WEEK,currentDate()); + view(WEEK,currentDate()); } void DateBook::viewWeekLst() { - view(WEEKLST,currentDate()); + view(WEEKLST,currentDate()); } void DateBook::viewMonth() { - view(MONTH,currentDate()); + view(MONTH,currentDate()); } void DateBook::insertEvent( const Event &e ) { Event dupEvent=e; dupEvent.setLocation(defaultLocation); dupEvent.setCategories(defaultCategories); db->addEvent(dupEvent); emit newEvent(); } void DateBook::duplicateEvent( const Event &e ) { qWarning("Hmmm..."); // Alot of code duplication, as this is almost like editEvent(); if (syncing) { QMessageBox::warning( this, tr("Calendar"), tr( "Can not edit data, currently syncing") ); return; } Event dupevent(e); // Make a duplicate. // workaround added for text input. QDialog editDlg( this, 0, TRUE ); DateEntry *entry; editDlg.setCaption( tr("Duplicate Event") ); QVBoxLayout *vb = new QVBoxLayout( &editDlg ); QScrollView *sv = new QScrollView( &editDlg, "scrollview" ); sv->setResizePolicy( QScrollView::AutoOneFit ); // KLUDGE!!! sv->setHScrollBarMode( QScrollView::AlwaysOff ); vb->addWidget( sv ); entry = new DateEntry( onMonday, dupevent, ampm, &editDlg, "editor" ); entry->timezone->setEnabled( FALSE ); sv->addChild( entry ); #if defined(Q_WS_QWS) || defined(_WS_QWS_) editDlg.showMaximized(); #endif while (editDlg.exec() ) { Event newEv = entry->event(); QString error = checkEvent(newEv); if (!error.isNull()) { if (QMessageBox::warning(this, "error box", error, "Fix it", "Continue", 0, 0, 1) == 0) continue; } db->addEvent(newEv); emit newEvent(); break; } } void DateBook::editEvent( const Event &e ) { if (syncing) { QMessageBox::warning( this, tr("Calendar"), tr( "Can not edit data, currently syncing") ); return; } // workaround added for text input. QDialog editDlg( this, 0, TRUE ); DateEntry *entry; editDlg.setCaption( tr("Edit Event") ); QVBoxLayout *vb = new QVBoxLayout( &editDlg ); QScrollView *sv = new QScrollView( &editDlg, "scrollview" ); sv->setResizePolicy( QScrollView::AutoOneFit ); // KLUDGE!!! sv->setHScrollBarMode( QScrollView::AlwaysOff ); vb->addWidget( sv ); entry = new DateEntry( onMonday, e, ampm, &editDlg, "editor" ); entry->timezone->setEnabled( FALSE ); sv->addChild( entry ); #if defined(Q_WS_QWS) || defined(_WS_QWS_) editDlg.showMaximized(); #endif while (editDlg.exec() ) { Event newEv = entry->event(); if(newEv.description().isEmpty() && newEv.notes().isEmpty() ) break; newEv.setUid(e.uid()); // FIXME: Hack not to clear uid QString error = checkEvent(newEv); if (!error.isNull()) { if (QMessageBox::warning(this, "error box", error, "Fix it", "Continue", 0, 0, 1) == 0) continue; } db->editEvent(e, newEv); emit newEvent(); break; } } void DateBook::removeEvent( const Event &e ) { if (syncing) { QMessageBox::warning( this, tr("Calendar"), tr( "Can not edit data, currently syncing") ); return; } QString strName = e.description(); if ( !QPEMessageBox::confirmDelete( this, tr( "Calendar" ),strName ) ) return; db->removeEvent( e ); if ( views->visibleWidget() == dayView && dayView ) dayView->redraw(); } void DateBook::addEvent( const Event &e ) { QDate d = e.start().date(); initDay(); dayView->setDate( d ); } void DateBook::showDay( int year, int month, int day ) { QDate d(year, month, day); view(DAY,d); } void DateBook::initDay() { if ( !dayView ) { dayView = new DateBookDay( ampm, onMonday, db, views, "day view" ); views->addWidget( dayView, DAY ); dayView->setStartViewTime( startTime ); dayView->setJumpToCurTime( bJumpToCurTime ); dayView->setRowStyle( rowStyle ); - connect( this, SIGNAL( newEvent() ), - dayView, SLOT( redraw() ) ); - connect( dayView, SIGNAL( newEvent() ), - this, SLOT( fileNew() ) ); - connect( dayView, SIGNAL( removeEvent( const Event & ) ), - this, SLOT( removeEvent( const Event & ) ) ); - connect( dayView, SIGNAL( editEvent( const Event & ) ), - this, SLOT( editEvent( const Event & ) ) ); - connect( dayView, SIGNAL( duplicateEvent( const Event & ) ), - this, SLOT( duplicateEvent( const Event & ) ) ); - connect( dayView, SIGNAL( beamEvent( const Event & ) ), - this, SLOT( beamEvent( const Event & ) ) ); - connect( dayView, SIGNAL(sigNewEvent(const QString &)), - this, SLOT(slotNewEventFromKey(const QString &)) ); - } + connect( this, SIGNAL( newEvent() ), dayView, SLOT( redraw() ) ); + connect( dayView, SIGNAL( newEvent() ), this, SLOT( fileNew() ) ); + connect( dayView, SIGNAL( removeEvent( const Event & ) ), this, SLOT( removeEvent( const Event & ) ) ); + connect( dayView, SIGNAL( editEvent( const Event & ) ), this, SLOT( editEvent( const Event & ) ) ); + connect( dayView, SIGNAL( duplicateEvent( const Event & ) ), this, SLOT( duplicateEvent( const Event & ) ) ); + connect( dayView, SIGNAL( beamEvent( const Event & ) ), this, SLOT( beamEvent( const Event & ) ) ); + connect( dayView, SIGNAL(sigNewEvent(const QString &)), this, SLOT(slotNewEventFromKey(const QString &)) ); + } } void DateBook::initWeek() { if ( !weekView ) { weekView = new DateBookWeek( ampm, onMonday, db, views, "week view" ); weekView->setStartViewTime( startTime ); views->addWidget( weekView, WEEK ); - connect( weekView, SIGNAL( showDate( int, int, int ) ), - this, SLOT( showDay( int, int, int ) ) ); - connect( this, SIGNAL( newEvent() ), - weekView, SLOT( redraw() ) ); + connect( weekView, SIGNAL( showDate( int, int, int ) ), this, SLOT( showDay( int, int, int ) ) ); + connect( this, SIGNAL( newEvent() ), weekView, SLOT( redraw() ) ); } //But also get it right: the year that we display can be different //from the year of the current date. So, first find the year //number of the current week. int yearNumber, totWeeks; calcWeek( currentDate(), totWeeks, yearNumber, onMonday ); QDate d = QDate( yearNumber, 12, 31 ); calcWeek( d, totWeeks, yearNumber, onMonday ); while ( totWeeks == 1 ) { d = d.addDays( -1 ); calcWeek( d, totWeeks, yearNumber, onMonday ); } - if ( totWeeks != weekView->totalWeeks() ) - weekView->setTotalWeeks( totWeeks ); } void DateBook::initWeekLst() { - if ( !weekLstView ) { - weekLstView = new DateBookWeekLst( ampm, onMonday, db, - views, "weeklst view" ); - views->addWidget( weekLstView, WEEKLST ); - - //weekLstView->setStartViewTime( startTime ); - connect( weekLstView, SIGNAL( showDate( int, int, int ) ), - this, SLOT( showDay( int, int, int ) ) ); - connect( weekLstView, SIGNAL( addEvent( const QDateTime &, - const QDateTime &, - const QString & , const QString &) ), - this, SLOT( slotNewEntry( const QDateTime &, - const QDateTime &, - const QString & , const QString &) ) ); - connect( this, SIGNAL( newEvent() ), - weekLstView, SLOT( redraw() ) ); - connect( weekLstView, SIGNAL( editEvent( const Event & ) ), - this, SLOT( editEvent( const Event & ) ) ); - } + if ( !weekLstView ) { + weekLstView = new DateBookWeekLst( ampm, onMonday, db, views, "weeklst view" ); + views->addWidget( weekLstView, WEEKLST ); + + //weekLstView->setStartViewTime( startTime ); + connect( weekLstView, SIGNAL( showDate( int, int, int ) ), this, SLOT( showDay( int, int, int ) ) ); + connect( weekLstView, SIGNAL( addEvent( const QDateTime &, const QDateTime &, const QString & , const QString &) ), + this, SLOT( slotNewEntry( const QDateTime &, const QDateTime &, const QString & , const QString &) ) ); + connect( this, SIGNAL( newEvent() ), weekLstView, SLOT( redraw() ) ); + connect( weekLstView, SIGNAL( editEvent( const Event & ) ), this, SLOT( editEvent( const Event & ) ) ); + } } void DateBook::initMonth() { - if ( !monthView ) { - monthView = new DateBookMonth( views, "month view", FALSE, db ); - views->addWidget( monthView, MONTH ); - connect( monthView, SIGNAL( dateClicked( int, int, int ) ), - this, SLOT( showDay( int, int, int ) ) ); - connect( this, SIGNAL( newEvent() ), - monthView, SLOT( redraw() ) ); - qApp->processEvents(); - } + if ( !monthView ) { + monthView = new DateBookMonth( views, "month view", FALSE, db ); + views->addWidget( monthView, MONTH ); + connect( monthView, SIGNAL( dateClicked( int, int, int ) ), this, SLOT( showDay( int, int, int ) ) ); + connect( this, SIGNAL( newEvent() ), monthView, SLOT( redraw() ) ); + qApp->processEvents(); + } } void DateBook::loadSettings() { Config qpeconfig( "qpe" ); qpeconfig.setGroup("Time"); ampm = qpeconfig.readBoolEntry( "AMPM", TRUE ); onMonday = qpeconfig.readBoolEntry( "MONDAY" ); Config config("DateBook"); config.setGroup("Main"); startTime = config.readNumEntry("startviewtime", 8); aPreset = config.readBoolEntry("alarmpreset"); presetTime = config.readNumEntry("presettime"); bJumpToCurTime = config.readBoolEntry("jumptocurtime"); rowStyle = config.readNumEntry("rowstyle"); defaultView = config.readNumEntry("defaultview",DAY); weeklistviewconfig = config.readNumEntry("weeklistviewconfig",NORMAL); defaultLocation=config.readEntry("defaultLocation"); QString tmpString=config.readEntry("defaultCategories"); QStringList tmpStringList=QStringList::split(",",tmpString); defaultCategories.truncate(0); + for( QStringList::Iterator i=tmpStringList.begin(); i!=tmpStringList.end(); i++) { defaultCategories.resize(defaultCategories.count()+1); defaultCategories[defaultCategories.count()-1]=(*i).toInt(); } } void DateBook::saveSettings() { Config config( "qpe" ); Config configDB( "DateBook" ); configDB.setGroup( "Main" ); configDB.writeEntry("startviewtime",startTime); configDB.writeEntry("alarmpreset",aPreset); configDB.writeEntry("presettime",presetTime); configDB.writeEntry("jumptocurtime", bJumpToCurTime); configDB.writeEntry("rowstyle", rowStyle); configDB.writeEntry("defaultview",defaultView); configDB.writeEntry("weeklistviewconfig",weeklistviewconfig); configDB.writeEntry("defaultLocation",defaultLocation); QStringList tmpStringList; for( uint i=0; i<defaultCategories.count(); i++) { tmpStringList << QString::number(defaultCategories[i]); } configDB.writeEntry("defaultCategories",tmpStringList.join(",")); } void DateBook::appMessage(const QCString& msg, const QByteArray& data) { bool needShow = FALSE; if ( msg == "alarm(QDateTime,int)" ) { QDataStream ds(data,IO_ReadOnly); QDateTime when; int warn; ds >> when >> warn; // check to make it's okay to continue, // this is the case that the time was set ahead, and // we are forced given a stale alarm... QDateTime current = QDateTime::currentDateTime(); if ( current.time().hour() != when.time().hour() && current.time().minute() != when.time().minute() ) return; QValueList<EffectiveEvent> list = db->getEffectiveEvents(when.addSecs(warn*60)); if ( list.count() > 0 ) { QString msg; bool bSound = FALSE; int stopTimer = 0; bool found = FALSE; for ( QValueList<EffectiveEvent>::ConstIterator it=list.begin(); it!=list.end(); ++it ) { if ( (*it).event().hasAlarm() ) { found = TRUE; msg += "<CENTER><B>" + (*it).description() + "</B>" + "<BR>" + (*it).location() + "<BR>" + TimeString::dateString((*it).event().start(),ampm) + (warn ? tr(" (in " + QString::number(warn) + tr(" minutes)")) : QString("")) + "<BR>" + (*it).notes() + "</CENTER>"; if ( (*it).event().alarmSound() != Event::Silent ) { bSound = TRUE; } } } if ( found ) { if ( bSound ) { Sound::soundAlarm(); alarmCounter = 0; stopTimer = startTimer( 5000 ); } QDialog dlg( this, 0, TRUE ); QVBoxLayout *vb = new QVBoxLayout( &dlg ); QScrollView *view = new QScrollView( &dlg, "scrollView"); view->setResizePolicy( QScrollView::AutoOneFit ); vb->addWidget( view ); QLabel *lblMsg = new QLabel( msg, &dlg ); view->addChild( lblMsg ); QPushButton *cmdOk = new QPushButton( tr("OK"), &dlg ); connect( cmdOk, SIGNAL(clicked()), &dlg, SLOT(accept()) ); vb->addWidget( cmdOk ); #if defined(Q_WS_QWS) || defined(_WS_QWS_) dlg.showMaximized(); #endif needShow = dlg.exec(); if ( bSound ) killTimer( stopTimer ); } } } else if ( msg == "nextView()" ) { if ( !qApp-> activeWindow ( )) { needShow = TRUE; } else { QWidget* cur = views->visibleWidget(); if ( cur ) { if ( cur == dayView ) viewWeek(); else if ( cur == weekView ) viewWeekLst(); else if ( cur == weekLstView ) viewMonth(); else if ( cur == monthView ) viewDay(); needShow = TRUE; } } } if ( needShow ) { #if defined(Q_WS_QWS) || defined(_WS_QWS_) showMaximized(); #else show(); #endif raise(); QPEApplication::setKeepRunning(); setActiveWindow(); } } void DateBook::reload() { db->reload(); if ( dayAction->isOn() ) viewDay(); else if ( weekAction->isOn() ) viewWeek(); else if ( monthAction->isOn() ) viewMonth(); syncing = FALSE; } void DateBook::flush() { syncing = TRUE; db->save(); } void DateBook::timerEvent( QTimerEvent *e ) { if ( alarmCounter < 10 ) { alarmCounter++; Sound::soundAlarm(); } else { killTimer( e->timerId() ); } } void DateBook::changeClock( bool newClock ) { ampm = newClock; // repaint the affected objects... if (dayView) dayView->redraw(); if (weekView) weekView->redraw(); if (weekLstView) weekLstView->redraw(); } void DateBook::changeWeek( bool m ) { /* no need to redraw, each widget catches. Do need to store though for widgets we haven't made yet */ onMonday = m; } void DateBook::slotToday() { // we need to view today using default view view(defaultView,QDate::currentDate()); } void DateBook::closeEvent( QCloseEvent *e ) { if(syncing) { /* no need to save, did that at flush */ e->accept(); return; } // save settings will generate it's own error messages, no // need to do checking ourselves. saveSettings(); if ( db->save() ) { e->accept(); } else { if ( QMessageBox::critical( this, tr( "Out of space" ), tr("Calendar was unable to save\n" "your changes.\n" "Free up some space and try again.\n" "\nQuit anyway?"), QMessageBox::Yes|QMessageBox::Escape, QMessageBox::No|QMessageBox::Default ) != QMessageBox::No ) e->accept(); else e->ignore(); } } // Entering directly from the "keyboard" void DateBook::slotNewEventFromKey( const QString &str ) { if (syncing) { QMessageBox::warning( this, tr("Calendar"), tr( "Can not edit data, currently syncing") ); return; } // We get to here from a key pressed in the Day View // So we can assume some things. We want the string // passed in to be part of the description. QDateTime start, end; if ( views->visibleWidget() == dayView ) { dayView->selectedDates( start, end ); } else if ( views->visibleWidget() == monthView ) { QDate d = monthView->selectedDate(); start = end = d; start.setTime( QTime( 10, 0 ) ); end.setTime( QTime( 12, 0 ) ); } else if ( views->visibleWidget() == weekView ) { QDate d = weekView->date(); start = end = d; start.setTime( QTime( 10, 0 ) ); end.setTime( QTime( 12, 0 ) ); } else if ( views->visibleWidget() == weekLstView ) { QDate d = weekLstView->date(); start = end = d; start.setTime( QTime( 10, 0 ) ); end.setTime( QTime( 12, 0 ) ); } slotNewEntry(start, end, str); } void DateBook::slotNewEntry(const QDateTime &start, const QDateTime &end, const QString &str, const QString &location) { // argh! This really needs to be encapsulated in a class // or function. QDialog newDlg( this, 0, TRUE ); newDlg.setCaption( DateEntryBase::tr("New Event") ); DateEntry *e; QVBoxLayout *vb = new QVBoxLayout( &newDlg ); QScrollView *sv = new QScrollView( &newDlg ); sv->setResizePolicy( QScrollView::AutoOneFit ); sv->setFrameStyle( QFrame::NoFrame ); sv->setHScrollBarMode( QScrollView::AlwaysOff ); vb->addWidget( sv ); Event ev; ev.setDescription( str ); // When the new gui comes in, change this... if(location==0) { if(defaultLocation.isEmpty()) { ev.setLocation(tr("(Unknown)")); } else { ev.setLocation( defaultLocation ); } } else { ev.setLocation(location); } ev.setCategories(defaultCategories); ev.setStart( start ); ev.setEnd( end ); e = new DateEntry( onMonday, ev, ampm, &newDlg ); e->setAlarmEnabled( aPreset, presetTime, Event::Loud ); sv->addChild( e ); #if defined(Q_WS_QWS) || defined(_WS_QWS_) newDlg.showMaximized(); #endif while (newDlg.exec()) { ev = e->event(); ev.assignUid(); QString error = checkEvent( ev ); if ( !error.isNull() ) { if ( QMessageBox::warning( this, tr("Error!"), error, tr("Fix it"), tr("Continue"), 0, 0, 1 ) == 0 ) continue; } db->addEvent( ev ); emit newEvent(); break; } } void DateBook::setDocument( const QString &filename ) { if ( filename.find(".vcs") != int(filename.length()) - 4 ) return; QValueList<Event> tl = Event::readVCalendar( filename ); for( QValueList<Event>::Iterator it = tl.begin(); it != tl.end(); ++it ) { db->addEvent( *it ); } } static const char * beamfile = "/tmp/obex/event.vcs"; void DateBook::beamEvent( const Event &e ) { qDebug("trying to beamn"); unlink( beamfile ); // delete if exists mkdir("/tmp/obex/", 0755); Event::writeVCalendar( beamfile, e ); Ir *ir = new Ir( this ); connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) ); QString description = e.description(); ir->send( beamfile, description, "text/x-vCalendar" ); } void DateBook::beamDone( Ir *ir ) { delete ir; unlink( beamfile ); } void DateBook::slotFind() { // move it to the day view... viewDay(); FindDialog frmFind( "Calendar", this ); frmFind.setUseDate( true ); frmFind.setDate( currentDate() ); QObject::connect( &frmFind, SIGNAL(signalFindClicked(const QString&, const QDate&, bool, bool, int)), this, SLOT(slotDoFind(const QString&, const QDate&, bool, bool, int)) ); QObject::connect( this, SIGNAL(signalNotFound()), &frmFind, SLOT(slotNotFound()) ); QObject::connect( this, SIGNAL(signalWrapAround()), &frmFind, SLOT(slotWrapAround()) ); frmFind.move(0,0); frmFind.exec(); inSearch = false; } bool catComp( QArray<int> cats, int category ) { bool returnMe; int i, count; count = int(cats.count()); returnMe = false; if ( (category == -1 && count == 0) || category == -2 ) returnMe = true; else { for ( i = 0; i < count; i++ ) { if ( category == cats[i] ) { returnMe = true; break; } } } return returnMe; } void DateBook::slotDoFind( const QString& txt, const QDate &dt, bool caseSensitive, bool /*backwards*/, int category ) { QDateTime dtEnd( QDate(3001, 1, 1), QTime(0, 0, 0) ), next; QRegExp r( txt ); r.setCaseSensitive( caseSensitive ); static Event rev, nonrev; if ( !inSearch ) { rev.setStart( QDateTime(QDate(1960, 1, 1), QTime(0, 0, 0)) ); nonrev.setStart( rev.start() ); inSearch = true; } static QDate searchDate = dt; static bool wrapAround = true; bool candidtate; candidtate = false; QValueList<Event> repeats = db->getRawRepeats(); // find the candidate for the first repeat that matches... QValueListConstIterator<Event> it; QDate start = dt; for ( it = repeats.begin(); it != repeats.end(); ++it ) { if ( catComp( (*it).categories(), category ) ) { while ( nextOccurance( *it, start, next ) ) { if ( next < dtEnd ) { if ( (*it).match( r ) && !(next <= rev.start()) ) { rev = *it; dtEnd = next; rev.setStart( next ); candidtate = true; wrapAround = true; start = dt; break; } else start = next.date().addDays( 1 ); } } } } // now the for first non repeat... QValueList<Event> nonRepeats = db->getNonRepeatingEvents( dt, dtEnd.date() ); qHeapSort( nonRepeats.begin(), nonRepeats.end() ); for ( it = nonRepeats.begin(); it != nonRepeats.end(); ++it ) { if ( catComp( (*it).categories(), category ) ) { if ( (*it).start() < dtEnd ) { if ( (*it).match( r ) && !(*it <= nonrev) ) { nonrev = *it; dtEnd = nonrev.start(); candidtate = true; wrapAround = true; break; } } } } if ( candidtate ) { dayView->setStartViewTime( dtEnd.time().hour() ); dayView->setDate( dtEnd.date().year(), dtEnd.date().month(), dtEnd.date().day() ); } else { if ( wrapAround ) { emit signalWrapAround(); rev.setStart( QDateTime(QDate(1960, 1, 1), QTime(0, 0, 0)) ); nonrev.setStart( rev.start() ); } else emit signalNotFound(); wrapAround = !wrapAround; } } Event DateBookDBHack::eventByUID(int uid) { // FIXME: Dirty Hacks to get hold of the private event lists QDate start; QDate end=start.addDays(-1); QValueList<Event> myEventList=getNonRepeatingEvents(start,end); QValueList<Event> myRepeatEvents=getRawRepeats(); QValueList<Event>::ConstIterator it; for (it = myEventList.begin(); it != myEventList.end(); it++) { if ((*it).uid() == uid) return *it; } for (it = myRepeatEvents.begin(); it != myRepeatEvents.end(); it++) { if ((*it).uid() == uid) return *it; } qDebug("Event not found: uid=%d\n", uid); Event ev; return ev; // return at least } diff --git a/core/pim/datebook/datebookweek.cpp b/core/pim/datebook/datebookweek.cpp index 8241655..3ae4610 100644 --- a/core/pim/datebook/datebookweek.cpp +++ b/core/pim/datebook/datebookweek.cpp @@ -1,706 +1,679 @@ /********************************************************************** ** Copyright (C) 2000 Trolltech AS. All rights reserved. ** ** This file is part of Qtopia Environment. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** **********************************************************************/ #include "datebookweek.h" #include "datebookweekheaderimpl.h" #include <qpe/calendar.h> #include <qpe/datebookdb.h> #include <qpe/event.h> #include <qpe/qpeapplication.h> #include <qpe/timestring.h> #include <qdatetime.h> #include <qheader.h> #include <qlabel.h> #include <qlayout.h> #include <qpainter.h> #include <qpopupmenu.h> #include <qtimer.h> #include <qspinbox.h> #include <qstyle.h> //----------------------------------------------------------------- DateBookWeekItem::DateBookWeekItem( const EffectiveEvent e ) : ev( e ) { // with the current implementation change the color for all day events if ( ev.event().type() == Event::AllDay && !ev.event().hasAlarm() ) { c = Qt::green; } else { c = ev.event().hasAlarm() ? Qt::red : Qt::blue; } } void DateBookWeekItem::setGeometry( int x, int y, int w, int h ) { r.setRect( x, y, w, h ); } //------------------=--------------------------------------------- DateBookWeekView::DateBookWeekView( bool ap, bool startOnMonday, QWidget *parent, const char *name ) : QScrollView( parent, name ), ampm( ap ), bOnMonday( startOnMonday ), showingEvent( false ) { items.setAutoDelete( true ); viewport()->setBackgroundMode( PaletteBase ); header = new QHeader( this ); header->addLabel( "" ); header->setMovingEnabled( false ); header->setResizeEnabled( false ); header->setClickEnabled( false, 0 ); initNames(); connect( header, SIGNAL(clicked(int)), this, SIGNAL(showDay(int)) ); QObject::connect(qApp, SIGNAL(clockChanged(bool)), this, SLOT(slotChangeClock(bool))); QFontMetrics fm( font() ); rowHeight = fm.height()+2; resizeContents( width(), 24*rowHeight ); } void DateBookWeekView::initNames() { static bool bFirst = true; if ( bFirst ) { if ( bOnMonday ) { header->addLabel( tr("M", "Monday" ) ); header->addLabel( tr("T", "Tuesday") ); header->addLabel( tr("W", "Wednesday" ) ); header->addLabel( tr("T", "Thursday" ) ); header->addLabel( tr("F", "Friday" ) ); header->addLabel( tr("S", "Saturday" ) ); header->addLabel( tr("S", "Sunday" ) ); } else { header->addLabel( tr("S", "Sunday" ) ); header->addLabel( tr("M", "Monday") ); header->addLabel( tr("T", "Tuesday") ); header->addLabel( tr("W", "Wednesday" ) ); header->addLabel( tr("T", "Thursday" ) ); header->addLabel( tr("F", "Friday" ) ); header->addLabel( tr("S", "Saturday" ) ); } bFirst = false; } else { // we are change things... if ( bOnMonday ) { header->setLabel( 1, tr("M", "Monday") ); header->setLabel( 2, tr("T", "Tuesday") ); header->setLabel( 3, tr("W", "Wednesday" ) ); header->setLabel( 4, tr("T", "Thursday" ) ); header->setLabel( 5, tr("F", "Friday" ) ); header->setLabel( 6, tr("S", "Saturday" ) ); header->setLabel( 7, tr("S", "Sunday" ) ); } else { header->setLabel( 1, tr("S", "Sunday" ) ); header->setLabel( 2, tr("M", "Monday") ); header->setLabel( 3, tr("T", "Tuesday") ); header->setLabel( 4, tr("W", "Wednesday" ) ); header->setLabel( 5, tr("T", "Thursday" ) ); header->setLabel( 6, tr("F", "Friday" ) ); header->setLabel( 7, tr("S", "Saturday" ) ); } } } void DateBookWeekView::showEvents( QValueList<EffectiveEvent> &ev ) { items.clear(); QValueListIterator<EffectiveEvent> it; for ( it = ev.begin(); it != ev.end(); ++it ) { DateBookWeekItem *i = new DateBookWeekItem( *it ); if(!((i->event().end().hour()==0) && (i->event().end().minute()==0) && (i->event().startDate()!=i->event().date()))) { // Skip events ending at 00:00 starting at another day. positionItem( i ); items.append( i ); } } viewport()->update(); } void DateBookWeekView::moveToHour( int h ) { int offset = h*rowHeight; setContentsPos( 0, offset ); } void DateBookWeekView::keyPressEvent( QKeyEvent *e ) { e->ignore(); } void DateBookWeekView::slotChangeClock( bool c ) { ampm = c; viewport()->update(); } static inline int db_round30min( int m ) { if ( m < 15 ) m = 0; else if ( m < 45 ) m = 1; else m = 2; return m; } void DateBookWeekView::alterDay( int day ) { if ( !bOnMonday ) { day--; } emit showDay( day ); } void DateBookWeekView::positionItem( DateBookWeekItem *i ) { const int Width = 8; const EffectiveEvent ev = i->event(); // 30 minute intervals int y = ev.start().hour() * 2; y += db_round30min( ev.start().minute() ); int y2 = ev.end().hour() * 2; y2 += db_round30min( ev.end().minute() ); if ( y > 47 ) y = 47; if ( y2 > 48 ) y2 = 48; y = (y * rowHeight) / 2; y2 = (y2 * rowHeight) / 2; int h; if ( ev.event().type() == Event::AllDay ) { h = (48 * rowHeight) / 2; y = 0; } else { h=y2-y; if ( h < (1*rowHeight)/2 ) h = (1*rowHeight)/2; } int dow = ev.date().dayOfWeek(); if ( !bOnMonday ) { if ( dow == 7 ) dow = 1; else dow++; } int x = header->sectionPos( dow ) - 1; int xlim = header->sectionPos( dow ) + header->sectionSize( dow ); DateBookWeekItem *isect = 0; do { i->setGeometry( x, y, Width, h ); isect = intersects( i ); x += Width - 1; } while ( isect && x < xlim ); } DateBookWeekItem *DateBookWeekView::intersects( const DateBookWeekItem *item ) { QRect geom = item->geometry(); // We allow the edges to overlap geom.moveBy( 1, 1 ); geom.setSize( geom.size()-QSize(2,2) ); QListIterator<DateBookWeekItem> it(items); for ( ; it.current(); ++it ) { DateBookWeekItem *i = it.current(); if ( i != item ) { if ( i->geometry().intersects( geom ) ) { return i; } } } return 0; } void DateBookWeekView::contentsMousePressEvent( QMouseEvent *e ) { QListIterator<DateBookWeekItem> it(items); for ( ; it.current(); ++it ) { DateBookWeekItem *i = it.current(); if ( i->geometry().contains( e->pos() ) ) { showingEvent = true; emit signalShowEvent( i->event() ); break; } } } void DateBookWeekView::contentsMouseReleaseEvent( QMouseEvent *e ) { if ( showingEvent ) { showingEvent = false; emit signalHideEvent(); } else { int d = header->sectionAt( e->pos().x() ); if ( d > 0 ) { // if ( !bOnMonday ) // d--; emit showDay( d ); } } } void DateBookWeekView::drawContents( QPainter *p, int cx, int cy, int cw, int ch ) { QRect ur( cx, cy, cw, ch ); p->setPen( lightGray ); for ( int i = 1; i <= 7; i++ ) p->drawLine( header->sectionPos(i)-2, cy, header->sectionPos(i)-2, cy+ch ); p->setPen( black ); for ( int t = 0; t < 24; t++ ) { int y = t*rowHeight; if ( QRect( 1, y, 20, rowHeight ).intersects( ur ) ) { QString s; if ( ampm ) { if ( t == 0 ) s = QString::number( 12 ); else if ( t == 12 ) s = QString::number(12) + tr( "p" ); else if ( t > 12 ) { if ( t - 12 < 10 ) s = " "; else s = ""; s += QString::number( t - 12 ) + tr("p"); } else { if ( 12 - t < 3 ) s = ""; else s = " "; s += QString::number( t ); } } else { s = QString::number( t ); if ( s.length() == 1 ) s.prepend( "0" ); } p->drawText( 1, y+p->fontMetrics().ascent()+1, s ); } } QListIterator<DateBookWeekItem> it(items); for ( ; it.current(); ++it ) { DateBookWeekItem *i = it.current(); if ( i->geometry().intersects( ur ) ) { p->setBrush( i->color() ); p->drawRect( i->geometry() ); } } } void DateBookWeekView::resizeEvent( QResizeEvent *e ) { const int hourWidth = 20; QScrollView::resizeEvent( e ); int avail = width()-qApp->style().scrollBarExtent().width()-1; header->setGeometry( 0, 0, avail, header->sizeHint().height() ); setMargins( 0, header->height(), 0, 0 ); header->resizeSection( 0, hourWidth ); int sw = (avail - hourWidth) / 7; for ( int i = 1; i < 7; i++ ) header->resizeSection( i, sw ); header->resizeSection( 7, avail - hourWidth - sw*6 ); } void DateBookWeekView::setStartOfWeek( bool bStartOnMonday ) { bOnMonday = bStartOnMonday; initNames(); } //------------------------------------------------------------------- DateBookWeek::DateBookWeek( bool ap, bool startOnMonday, DateBookDB *newDB, QWidget *parent, const char *name ) : QWidget( parent, name ), db( newDB ), startTime( 0 ), ampm( ap ), bStartOnMonday( startOnMonday ) { - setFocusPolicy(StrongFocus); - QVBoxLayout *vb = new QVBoxLayout( this ); - header = new DateBookWeekHeader( bStartOnMonday, this ); - view = new DateBookWeekView( ampm, startOnMonday, this ); - vb->addWidget( header ); - vb->addWidget( view ); - - lblDesc = new QLabel( this, "event label" ); - lblDesc->setFrameStyle( QFrame::Plain | QFrame::Box ); - lblDesc->setBackgroundColor( yellow ); - lblDesc->hide(); - - tHide = new QTimer( this ); - - connect( view, SIGNAL( showDay( int ) ), - this, SLOT( showDay( int ) ) ); - connect( view, SIGNAL(signalShowEvent(const EffectiveEvent&)), - this, SLOT(slotShowEvent(const EffectiveEvent&)) ); - connect( view, SIGNAL(signalHideEvent()), - this, SLOT(slotHideEvent()) ); - connect( header, SIGNAL( dateChanged( int, int ) ), - this, SLOT( dateChanged( int, int ) ) ); - connect( tHide, SIGNAL( timeout() ), - lblDesc, SLOT( hide() ) ); - connect( header->spinYear, SIGNAL(valueChanged(int)), - this, SLOT(slotYearChanged(int)) ); - connect( qApp, SIGNAL(weekChanged(bool)), - this, SLOT(slotWeekChanged(bool)) ); - connect( qApp, SIGNAL(clockChanged(bool)), - this, SLOT(slotClockChanged(bool))); - setDate(QDate::currentDate()); - + setFocusPolicy(StrongFocus); + QVBoxLayout *vb = new QVBoxLayout( this ); + header = new DateBookWeekHeader( bStartOnMonday, this ); + view = new DateBookWeekView( ampm, startOnMonday, this ); + vb->addWidget( header ); + vb->addWidget( view ); + + lblDesc = new QLabel( this, "event label" ); + lblDesc->setFrameStyle( QFrame::Plain | QFrame::Box ); + lblDesc->setBackgroundColor( yellow ); + lblDesc->hide(); + + tHide = new QTimer( this ); + + connect( view, SIGNAL( showDay( int ) ), this, SLOT( showDay( int ) ) ); + connect( view, SIGNAL(signalShowEvent(const EffectiveEvent&)), this, SLOT(slotShowEvent(const EffectiveEvent&)) ); + connect( view, SIGNAL(signalHideEvent()), this, SLOT(slotHideEvent()) ); + connect( header, SIGNAL( dateChanged( int, int ) ), this, SLOT( dateChanged( int, int ) ) ); + connect( tHide, SIGNAL( timeout() ), lblDesc, SLOT( hide() ) ); + connect( qApp, SIGNAL(weekChanged(bool)), this, SLOT(slotWeekChanged(bool)) ); + connect( qApp, SIGNAL(clockChanged(bool)), this, SLOT(slotClockChanged(bool))); + setDate(QDate::currentDate()); } void DateBookWeek::keyPressEvent(QKeyEvent *e) { switch(e->key()) { case Key_Up: view->scrollBy(0, -20); break; case Key_Down: view->scrollBy(0, 20); break; case Key_Left: setDate(date().addDays(-7)); break; case Key_Right: setDate(date().addDays(7)); break; default: e->ignore(); } } void DateBookWeek::showDay( int day ) { - QDate d; - d = dateFromWeek( _week, year, bStartOnMonday ); - day--; - d = d.addDays( day ); - emit showDate( d.year(), d.month(), d.day() ); + QDate d; + d = dateFromWeek( _week, year, bStartOnMonday ); + day--; + d = d.addDays( day ); + emit showDate( d.year(), d.month(), d.day() ); } void DateBookWeek::setDate( int y, int m, int d ) { - QDate date; - date.setYMD( y, m, d ); - setDate(QDate(y, m, d)); + setDate(QDate(y, m, d)); } void DateBookWeek::setDate(QDate date) { - dow = date.dayOfWeek(); - int w, y; - calcWeek( date, w, y, bStartOnMonday ); - header->setDate( y, w ); + dow = date.dayOfWeek(); + int w, y; + calcWeek( date, w, y, bStartOnMonday ); + header->setDate( date ); } void DateBookWeek::dateChanged( int y, int w ) { - year = y; - _week = w; - getEvents(); + year = y; + _week = w; + getEvents(); } QDate DateBookWeek::date() const { - QDate d; - d = dateFromWeek( _week - 1, year, bStartOnMonday ); - if ( bStartOnMonday ) - d = d.addDays( 7 + dow - 1 ); - else { - if ( dow == 7 ) - d = d.addDays( dow ); - else - d = d.addDays( 7 + dow ); - } - return d; + QDate d; + d = dateFromWeek( _week - 1, year, bStartOnMonday ); + if ( bStartOnMonday ) + d = d.addDays( 7 + dow - 1 ); + else { + if ( dow == 7 ) + d = d.addDays( dow ); + else + d = d.addDays( 7 + dow ); + } + return d; } void DateBookWeek::getEvents() { - QDate startWeek = weekDate(); + QDate startWeek = weekDate(); - QDate endWeek = startWeek.addDays( 6 ); - QValueList<EffectiveEvent> eventList = db->getEffectiveEvents(startWeek, - endWeek); - view->showEvents( eventList ); - view->moveToHour( startTime ); + QDate endWeek = startWeek.addDays( 6 ); + QValueList<EffectiveEvent> eventList = db->getEffectiveEvents(startWeek, endWeek); + view->showEvents( eventList ); + view->moveToHour( startTime ); } void DateBookWeek::generateAllDayTooltext( QString& text ) { - text += "<b>" + tr("This is an all day event.") + "</b><br>"; + text += "<b>" + tr("This is an all day event.") + "</b><br>"; } -void DateBookWeek::generateNormalTooltext( QString& str, - const EffectiveEvent &ev ) { - str += "<b>" + QObject::tr("Start") + "</b>: "; - str += TimeString::timeString( ev.event().start().time(), ampm, FALSE ); - if( ev.startDate()!=ev.endDate() ) { - str += " <i>" + TimeString::longDateString( ev.startDate() )+"</i>"; - } - str += "<br>"; - str += "<b>" + QObject::tr("End") + "</b>: "; - str += TimeString::timeString( ev.event().end().time(), ampm, FALSE ); - if( ev.startDate()!=ev.endDate() ) { - str += " <i>" + TimeString::longDateString( ev.endDate() ) + "</i>"; - } +void DateBookWeek::generateNormalTooltext( QString& str, const EffectiveEvent &ev ) { + str += "<b>" + QObject::tr("Start") + "</b>: "; + str += TimeString::timeString( ev.event().start().time(), ampm, FALSE ); + if( ev.startDate()!=ev.endDate() ) { + str += " <i>" + TimeString::longDateString( ev.startDate() )+"</i>"; + } + str += "<br>"; + str += "<b>" + QObject::tr("End") + "</b>: "; + str += TimeString::timeString( ev.event().end().time(), ampm, FALSE ); + if( ev.startDate()!=ev.endDate() ) { + str += " <i>" + TimeString::longDateString( ev.endDate() ) + "</i>"; + } } void DateBookWeek::slotShowEvent( const EffectiveEvent &ev ) { if ( tHide->isActive() ) tHide->stop(); // why would someone use "<"? Oh well, fix it up... // I wonder what other things may be messed up... QString strDesc = ev.description(); int where = strDesc.find( "<" ); while ( where != -1 ) { strDesc.remove( where, 1 ); strDesc.insert( where, "<" ); where = strDesc.find( "<", where ); } QString strCat; // ### FIX later... // QString strCat = ev.category(); // where = strCat.find( "<" ); // while ( where != -1 ) { // strCat.remove( where, 1 ); // strCat.insert( where, "<" ); // where = strCat.find( "<", where ); // } QString strLocation = ev.location(); while ( where != -1 ) { strLocation.remove( where, 1 ); strLocation.insert( where, "<" ); where = strLocation.find( "<", where ); } QString strNote = ev.notes(); where = strNote.find( "<" ); while ( where != -1 ) { strNote.remove( where, 1 ); strNote.insert( where, "<" ); where = strNote.find( "<", where ); } QString str = "<b>" + strDesc + "</b><br>" + strLocation + "<br>" + "<i>" + strCat + "</i>" + "<br>" + TimeString::longDateString( ev.date() ) + "<br>"; if (ev.event().type() == Event::Normal ) generateNormalTooltext( str, ev ); else generateAllDayTooltext( str ); str += "<br><br>" + strNote; lblDesc->setText( str ); lblDesc->resize( lblDesc->sizeHint() ); // move the label so it is "centerd" horizontally... lblDesc->move( QMAX(0,(width() - lblDesc->width()) / 2), 0 ); lblDesc->show(); } void DateBookWeek::slotHideEvent() { tHide->start( 2000, true ); } void DateBookWeek::setStartViewTime( int startHere ) { startTime = startHere; view->moveToHour( startTime ); } int DateBookWeek::startViewTime() const { return startTime; } void DateBookWeek::redraw() { getEvents(); } void DateBookWeek::slotYearChanged( int y ) { - int totWeek; - QDate d( y, 12, 31 ); - int throwAway; - calcWeek( d, totWeek, throwAway, bStartOnMonday ); - while ( totWeek == 1 ) { - d = d.addDays( -1 ); + int totWeek; + QDate d( y, 12, 31 ); + int throwAway; calcWeek( d, totWeek, throwAway, bStartOnMonday ); - } - if ( totWeek != totalWeeks() ) - setTotalWeeks( totWeek ); -} - - -void DateBookWeek::setTotalWeeks( int numWeeks ) -{ - header->spinWeek->setMaxValue( numWeeks ); -} - -int DateBookWeek::totalWeeks() const -{ - return header->spinWeek->maxValue(); + while ( totWeek == 1 ) { + d = d.addDays( -1 ); + calcWeek( d, totWeek, throwAway, bStartOnMonday ); + } } void DateBookWeek::slotWeekChanged( bool onMonday ) { - bStartOnMonday = onMonday; - view->setStartOfWeek( bStartOnMonday ); - header->setStartOfWeek( bStartOnMonday ); - redraw(); + bStartOnMonday = onMonday; + view->setStartOfWeek( bStartOnMonday ); + header->setStartOfWeek( bStartOnMonday ); + redraw(); } void DateBookWeek::slotClockChanged( bool ap ) { - ampm = ap; + ampm = ap; } // return the date at the beginning of the week... QDate DateBookWeek::weekDate() const { return dateFromWeek( _week, year, bStartOnMonday ); } // this used to only be needed by datebook.cpp, but now we need it inside // week view since // we need to be able to figure out our total number of weeks on the fly... // this is probably the best place to put it.. // For Weeks that start on Monday... (EASY!) // At the moment we will use ISO 8601 method for computing // the week. Granted, other countries use other methods, // bet we aren't doing any Locale stuff at the moment. So, // this should pass. This Algorithim is public domain and // available at: // http://personal.ecu.edu/mccartyr/ISOwdALG.txt // the week number is return, and the year number is returned in year // for Instance 2001/12/31 is actually the first week in 2002. // There is a more mathematical definition, but I will implement it when // we are pass our deadline. // For Weeks that start on Sunday... (ahh... home rolled) // okay, if Jan 1 is on Friday or Saturday, // it will go to the pervious // week... bool calcWeek( const QDate &d, int &week, int &year, bool startOnMonday ) { int weekNumber; int yearNumber; // remove a pesky warning, (Optimizations on g++) weekNumber = -1; int jan1WeekDay = QDate(d.year(), 1, 1).dayOfWeek(); int dayOfWeek = d.dayOfWeek(); if ( !d.isValid() ) return false; if ( startOnMonday ) { // find the Jan1Weekday; if ( d.dayOfYear() <= ( 8 - jan1WeekDay) && jan1WeekDay > 4 ) { yearNumber = d.year() - 1; if ( jan1WeekDay == 5 || ( jan1WeekDay == 6 && QDate::leapYear(yearNumber) ) ) weekNumber = 53; else weekNumber = 52; } else yearNumber = d.year(); if ( yearNumber == d.year() ) { int totalDays = 365; if ( QDate::leapYear(yearNumber) ) totalDays++; if ( ((totalDays - d.dayOfYear()) < (4 - dayOfWeek) ) || (jan1WeekDay == 7) && (totalDays - d.dayOfYear()) < 3) { yearNumber++; weekNumber = 1; } } if ( yearNumber == d.year() ) { int j = d.dayOfYear() + (7 - dayOfWeek) + ( jan1WeekDay - 1 ); weekNumber = j / 7; if ( jan1WeekDay > 4 ) weekNumber--; } } else { // it's better to keep these cases separate... if ( d.dayOfYear() <= (7 - jan1WeekDay) && jan1WeekDay > 4 && jan1WeekDay != 7 ) { yearNumber = d.year() - 1; if ( jan1WeekDay == 6 || (jan1WeekDay == 7 && QDate::leapYear(yearNumber) ) ) { weekNumber = 53; }else weekNumber = 52; } else yearNumber = d.year(); if ( yearNumber == d.year() ) { int totalDays = 365; if ( QDate::leapYear( yearNumber ) ) totalDays++; if ( ((totalDays - d.dayOfYear()) < (4 - dayOfWeek % 7)) ) { yearNumber++; weekNumber = 1; } } if ( yearNumber == d.year() ) { int j = d.dayOfYear() + (7 - dayOfWeek % 7) + ( jan1WeekDay - 1 ); weekNumber = j / 7; if ( jan1WeekDay > 4 ) { weekNumber--; } } } year = yearNumber; week = weekNumber; return true; } diff --git a/core/pim/datebook/datebookweek.h b/core/pim/datebook/datebookweek.h index acbc2c7..8c5e06d 100644 --- a/core/pim/datebook/datebookweek.h +++ b/core/pim/datebook/datebookweek.h @@ -1,168 +1,166 @@ /********************************************************************** ** Copyright (C) 2000 Trolltech AS. All rights reserved. ** ** This file is part of Qtopia Environment. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** **********************************************************************/ #ifndef DATEBOOKWEEK #define DATEBOOKWEEK #include <qpe/event.h> #include <qlist.h> #include <qscrollview.h> #include <qstring.h> #include <qvaluelist.h> class DateBookDB; class DateBookWeekHeader; class QDate; class QLabel; class QResizeEvent; class QSpinBox; class QTimer; class QHeader; class DateBookWeekItem { public: DateBookWeekItem( const EffectiveEvent e ); void setGeometry( int x, int y, int w, int h ); QRect geometry() const { return r; } const QColor &color() const { return c; } const EffectiveEvent event() const { return ev; } private: const EffectiveEvent ev; QRect r; QColor c; }; class DateBookWeekView : public QScrollView { Q_OBJECT public: DateBookWeekView( bool ampm, bool weekOnMonday, QWidget *parent = 0, const char *name = 0 ); bool whichClock() const; void showEvents( QValueList<EffectiveEvent> &ev ); void moveToHour( int h ); void setStartOfWeek( bool bOnMonday ); signals: void showDay( int d ); void signalShowEvent( const EffectiveEvent & ); void signalHideEvent(); protected slots: void keyPressEvent(QKeyEvent *); private slots: void slotChangeClock( bool ); void alterDay( int ); private: void positionItem( DateBookWeekItem *i ); DateBookWeekItem *intersects( const DateBookWeekItem * ); void drawContents( QPainter *p, int cx, int cy, int cw, int ch ); void contentsMousePressEvent( QMouseEvent * ); void contentsMouseReleaseEvent( QMouseEvent * ); void resizeEvent( QResizeEvent * ); void initNames(); private: bool ampm; bool bOnMonday; QHeader *header; QList<DateBookWeekItem> items; int rowHeight; bool showingEvent; }; class DateBookWeek : public QWidget { Q_OBJECT public: DateBookWeek( bool ampm, bool weekOnMonday, DateBookDB *newDB, QWidget *parent = 0, const char *name = 0 ); void setDate( int y, int m, int d ); void setDate( QDate d ); QDate date() const; DateBookWeekView *weekView() const { return view; } void setStartViewTime( int startHere ); int startViewTime() const; int week() const { return _week; }; - void setTotalWeeks( int totalWeeks ); - int totalWeeks() const; QDate weekDate() const; public slots: void redraw(); void slotWeekChanged( bool bStartOnMonday ); void slotClockChanged( bool a ); signals: void showDate( int y, int m, int d ); protected slots: void keyPressEvent(QKeyEvent *); private slots: void showDay( int day ); void dateChanged( int y, int w ); void slotShowEvent( const EffectiveEvent & ); void slotHideEvent(); void slotYearChanged( int ); private: void getEvents(); /** * Wow that's a hell lot of code duplication * in datebook. I vote for a common base class * but never the less. This add a note * that the Event is an all day event * */ void generateAllDayTooltext( QString& text ); /** * This will add the times to the text * It will be shown in the Tooltip bubble */ void generateNormalTooltext( QString& text, const EffectiveEvent &ev); int year; int _week; int dow; DateBookWeekHeader *header; DateBookWeekView *view; DateBookDB *db; QLabel *lblDesc; QTimer *tHide; int startTime; bool ampm; bool bStartOnMonday; }; bool calcWeek( const QDate &d, int &week, int &year, bool startOnMonday = false ); #endif diff --git a/core/pim/datebook/datebookweekheader.ui b/core/pim/datebook/datebookweekheader.ui index 591b625..b2e0e36 100644 --- a/core/pim/datebook/datebookweekheader.ui +++ b/core/pim/datebook/datebookweekheader.ui @@ -1,335 +1,275 @@ <!DOCTYPE UI><UI> <class>DateBookWeekHeaderBase</class> <comment>********************************************************************* ** Copyright (C) 2000 Trolltech AS. All rights reserved. ** ** This file is part of Qtopia Environment. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** *********************************************************************</comment> <widget> <class>QWidget</class> <property stdset="1"> <name>name</name> <cstring>DateBookWeekHeaderBase</cstring> </property> <property stdset="1"> <name>geometry</name> <rect> <x>0</x> <y>0</y> <width>249</width> <height>26</height> </rect> </property> <property> <name>layoutMargin</name> </property> <property> <name>layoutSpacing</name> </property> <hbox> <property stdset="1"> <name>margin</name> <number>0</number> </property> <property stdset="1"> <name>spacing</name> <number>0</number> </property> <widget> <class>QToolButton</class> <property stdset="1"> <name>name</name> <cstring>backmonth</cstring> </property> <property stdset="1"> <name>text</name> <string></string> </property> <property stdset="1"> <name>pixmap</name> <pixmap></pixmap> </property> <property stdset="1"> <name>toggleButton</name> <bool>false</bool> </property> <property stdset="1"> <name>autoRepeat</name> <bool>true</bool> </property> <property stdset="1"> <name>autoRaise</name> <bool>true</bool> </property> <property stdset="1"> <name>toggleButton</name> <bool>false</bool> </property> <property> <name>toolTip</name> <string></string> </property> </widget> <widget> <class>QToolButton</class> <property stdset="1"> <name>name</name> <cstring>backweek</cstring> </property> <property stdset="1"> <name>text</name> <string></string> </property> <property stdset="1"> <name>pixmap</name> <pixmap></pixmap> </property> <property stdset="1"> <name>toggleButton</name> <bool>false</bool> </property> <property stdset="1"> <name>autoRepeat</name> <bool>true</bool> </property> <property stdset="1"> <name>autoRaise</name> <bool>true</bool> </property> <property stdset="1"> <name>toggleButton</name> <bool>false</bool> </property> <property> <name>toolTip</name> <string></string> </property> </widget> - <widget> - <class>QSpinBox</class> - <property stdset="1"> - <name>name</name> - <cstring>spinYear</cstring> - </property> - <property stdset="1"> - <name>sizePolicy</name> - <sizepolicy> - <hsizetype>0</hsizetype> - <vsizetype>0</vsizetype> - </sizepolicy> - </property> - <property stdset="1"> - <name>prefix</name> - <string>Y: </string> - </property> - <property stdset="1"> - <name>maxValue</name> - <number>2037</number> - </property> - <property stdset="1"> - <name>minValue</name> - <number>1970</number> - </property> - <property stdset="1"> - <name>value</name> - <number>2002</number> - </property> - </widget> - <widget> - <class>QSpinBox</class> - <property stdset="1"> - <name>name</name> - <cstring>spinWeek</cstring> - </property> - <property stdset="1"> - <name>sizePolicy</name> - <sizepolicy> - <hsizetype>0</hsizetype> - <vsizetype>0</vsizetype> - </sizepolicy> - </property> - <property stdset="1"> - <name>prefix</name> - <string>W: </string> - </property> - <property stdset="1"> - <name>maxValue</name> - <number>52</number> - </property> - <property stdset="1"> - <name>minValue</name> - <number>1</number> - </property> - <property stdset="1"> - <name>value</name> - <number>1</number> - </property> - </widget> <spacer> <property> <name>name</name> <cstring>Spacer1_1</cstring> </property> <property stdset="1"> <name>orientation</name> <enum>Horizontal</enum> </property> <property stdset="1"> <name>sizeType</name> <enum>Expanding</enum> </property> <property> <name>sizeHint</name> <size> <width>20</width> <height>20</height> </size> </property> </spacer> <widget> <class>QToolButton</class> <property stdset="1"> <name>name</name> <cstring>labelDate</cstring> </property> <property stdset="1"> <name>sizePolicy</name> <sizepolicy> <hsizetype>3</hsizetype> <vsizetype>1</vsizetype> </sizepolicy> </property> <property stdset="1"> <name>font</name> <font> <bold>1</bold> </font> </property> <property stdset="1"> <name>text</name> <string>00. Jan-00. Jan</string> </property> </widget> <spacer> <property> <name>name</name> <cstring>Spacer1_2</cstring> </property> <property stdset="1"> <name>orientation</name> <enum>Horizontal</enum> </property> <property stdset="1"> <name>sizeType</name> <enum>Expanding</enum> </property> <property> <name>sizeHint</name> <size> <width>20</width> <height>20</height> </size> </property> </spacer> <widget> <class>QToolButton</class> <property stdset="1"> <name>name</name> <cstring>forwardweek</cstring> </property> <property stdset="1"> <name>text</name> <string></string> </property> <property stdset="1"> <name>pixmap</name> <pixmap></pixmap> </property> <property stdset="1"> <name>autoRepeat</name> <bool>true</bool> </property> <property stdset="1"> <name>autoRaise</name> <bool>true</bool> </property> </widget> <widget> <class>QToolButton</class> <property stdset="1"> <name>name</name> <cstring>forwardmonth</cstring> </property> <property stdset="1"> <name>text</name> <string></string> </property> <property stdset="1"> <name>pixmap</name> <pixmap></pixmap> </property> <property stdset="1"> <name>autoRepeat</name> <bool>true</bool> </property> <property stdset="1"> <name>autoRaise</name> <bool>true</bool> </property> </widget> </hbox> </widget> <connections> <connection> <sender>backmonth</sender> <signal>clicked()</signal> <receiver>DateBookWeekHeaderBase</receiver> <slot>prevMonth()</slot> </connection> <connection> <sender>backweek</sender> <signal>clicked()</signal> <receiver>DateBookWeekHeaderBase</receiver> <slot>prevWeek()</slot> </connection> <connection> <sender>forwardweek</sender> <signal>clicked()</signal> <receiver>DateBookWeekHeaderBase</receiver> <slot>nextWeek()</slot> </connection> <connection> <sender>forwardmonth</sender> <signal>clicked()</signal> <receiver>DateBookWeekHeaderBase</receiver> <slot>nextMonth()</slot> </connection> <connection> <sender>labelDate</sender> <signal>clicked()</signal> <receiver>DateBookWeekHeaderBase</receiver> <slot>pickDate()</slot> </connection> <slot access="public">yearChanged( int )</slot> <slot access="public">nextWeek()</slot> <slot access="public">prevWeek()</slot> <slot access="public">weekChanged( int )</slot> <slot access="public">nextMonth()</slot> <slot access="public">prevMonth()</slot> - <slot access="public">pickDate()</slot> + <slot access="public">pickDate()</slot> </connections> </UI> diff --git a/core/pim/datebook/datebookweekheaderimpl.cpp b/core/pim/datebook/datebookweekheaderimpl.cpp index 5f555d5..fd792e2 100644 --- a/core/pim/datebook/datebookweekheaderimpl.cpp +++ b/core/pim/datebook/datebookweekheaderimpl.cpp @@ -1,180 +1,139 @@ /********************************************************************** ** Copyright (C) 2000 Trolltech AS. All rights reserved. ** ** This file is part of Qtopia Environment. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** **********************************************************************/ #include "datebookweekheaderimpl.h" #include "datebookweekheader.h" #include "datebookweek.h" #include <qlabel.h> #include <qspinbox.h> #include <qdatetime.h> #include <qpe/resource.h> #include <qpe/datebookmonth.h> #include <qtoolbutton.h> /* * Constructs a DateBookWeekHeader which is a child of 'parent', with the * name 'name' and widget flags set to 'f' */ -DateBookWeekHeader::DateBookWeekHeader( bool startOnMonday, QWidget* parent, - const char* name, WFlags fl ) +DateBookWeekHeader::DateBookWeekHeader( bool startOnMonday, QWidget* parent, const char* name, WFlags fl ) : DateBookWeekHeaderBase( parent, name, fl ), bStartOnMonday( startOnMonday ) { - setBackgroundMode( PaletteButton ); - labelDate->setBackgroundMode( PaletteButton ); - - backmonth->setPixmap( Resource::loadPixmap("fastback") ); - backweek->setPixmap( Resource::loadPixmap("back") ); - forwardweek->setPixmap( Resource::loadPixmap("forward") ); - forwardmonth->setPixmap( Resource::loadPixmap("fastforward") ); - spinYear->hide(); - spinWeek->hide(); + setBackgroundMode( PaletteButton ); + labelDate->setBackgroundMode( PaletteButton ); + backmonth->setPixmap( Resource::loadPixmap("fastback") ); + backweek->setPixmap( Resource::loadPixmap("back") ); + forwardweek->setPixmap( Resource::loadPixmap("forward") ); + forwardmonth->setPixmap( Resource::loadPixmap("fastforward") ); } /* * Destroys the object and frees any allocated resources */ DateBookWeekHeader::~DateBookWeekHeader() { // no need to delete child widgets, Qt does it all for us } void DateBookWeekHeader::pickDate() { static QPopupMenu *m1 = 0; static DateBookMonth *picker = 0; - QDate currDate = dateFromWeek( week, year, bStartOnMonday ); if ( !m1 ) { m1 = new QPopupMenu( this ); picker = new DateBookMonth( m1, 0, TRUE ); m1->insertItem( picker ); - connect( picker, SIGNAL( dateClicked( int, int, int ) ), - this, SLOT( setDate( int, int, int ) ) ); -// connect( m1, SIGNAL( aboutToHide() ), -// this, SLOT( gotHide() ) ); + connect( picker, SIGNAL( dateClicked( int, int, int ) ), this, SLOT( setDate( int, int, int ) ) ); +// connect( m1, SIGNAL( aboutToHide() ), this, SLOT( gotHide() ) ); } - picker->setDate( currDate.year(), currDate.month(), currDate.day() ); + picker->setDate( date.year(), date.month(), date.day() ); m1->popup(mapToGlobal(labelDate->pos()+QPoint(0,labelDate->height()))); picker->setFocus(); } -/* - * public slot - */ -void DateBookWeekHeader::yearChanged( int y ) -{ - setDate( y, week ); -} + void DateBookWeekHeader::nextMonth() { - QDate mydate = dateFromWeek( week, year, bStartOnMonday ); // Get current week - calcWeek( mydate.addDays(28), week, year, bStartOnMonday ); // Add 4 weeks. - setDate( year, week ); // update view + setDate(date.addDays(28)); } void DateBookWeekHeader::prevMonth() { - QDate mydate = dateFromWeek( week, year, bStartOnMonday ); // Get current week - calcWeek( mydate.addDays(-28), week, year, bStartOnMonday ); // Subtract 4 weeks - setDate( year, week ); // update view + setDate(date.addDays(-28)); } -/* - * public slot - */ void DateBookWeekHeader::nextWeek() { - QDate mydate = dateFromWeek( week, year, bStartOnMonday ); // Get current week - calcWeek( mydate.addDays(7), week, year, bStartOnMonday); // Add 1 week -// if ( week < 52 ) -// week++; - setDate( year, week ); + setDate(date.addDays(7)); } -/* - * public slot - */ void DateBookWeekHeader::prevWeek() { - QDate mydate = dateFromWeek( week, year, bStartOnMonday ); // Get current week - calcWeek( mydate.addDays(-7), week, year, bStartOnMonday); // Add 1 week -// if ( week > 1 ) -// week--; - setDate( year, week ); -} -/* - * public slot - */ -void DateBookWeekHeader::weekChanged( int w ) -{ - setDate( year, w ); + setDate(date.addDays(-7)); } void DateBookWeekHeader::setDate( int y, int m, int d ) { - calcWeek( QDate(y,m,d), week, year, bStartOnMonday ); - setDate( year, week ); + setDate(QDate(y,m,d)); } -void DateBookWeekHeader::setDate( int y, int w ) -{ - year = y; - week = w; - spinYear->setValue( y ); - spinWeek->setValue( w ); - - QDate d = dateFromWeek( week, year, bStartOnMonday ); - - QString s = QString::number( d.day() ) + ". " + d.monthName( d.month() ) - + "-"; - d = d.addDays( 6 ); - s += QString::number( d.day() ) + ". " + d.monthName( d.month() ); - s += " ("+tr("week")+":"+QString::number( w )+")"; - labelDate->setText( s ); +void DateBookWeekHeader::setDate(const QDate &d) { + int year,week,dayofweek; + date=d; + dayofweek=d.dayOfWeek(); + if(bStartOnMonday) dayofweek--; + date=date.addDays(-dayofweek); - emit dateChanged( y, w ); + calcWeek(date,week,year,bStartOnMonday); + QDate start=date; + QDate stop=start.addDays(6); + labelDate->setText( QString::number(start.day()) + "." + + start.monthName(start.month()) + "-" + + QString::number(stop.day()) + "." + + start.monthName(stop.month()) +" ("+ + tr("w")+":"+QString::number( week ) +")"); + emit dateChanged(year,week); } void DateBookWeekHeader::setStartOfWeek( bool onMonday ) { - bStartOnMonday = onMonday; - setDate( year, week ); + bStartOnMonday = onMonday; + setDate( date ); } // dateFromWeek // compute the date from the week in the year - QDate dateFromWeek( int week, int year, bool startOnMonday ) { - QDate d; - d.setYMD( year, 1, 1 ); - int dayOfWeek = d.dayOfWeek(); - if ( startOnMonday ) { - if ( dayOfWeek <= 4 ) { - d = d.addDays( ( week - 1 ) * 7 - dayOfWeek + 1 ); - } else { - d = d.addDays( (week) * 7 - dayOfWeek + 1 ); - } - } else { - if ( dayOfWeek <= 4 || dayOfWeek == 7) { - d = d.addDays( ( week - 1 ) * 7 - dayOfWeek % 7 ); + QDate d; + d.setYMD( year, 1, 1 ); + int dayOfWeek = d.dayOfWeek(); + if ( startOnMonday ) { + if ( dayOfWeek <= 4 ) { + d = d.addDays( ( week - 1 ) * 7 - dayOfWeek + 1 ); + } else { + d = d.addDays( (week) * 7 - dayOfWeek + 1 ); + } } else { - d = d.addDays( ( week ) * 7 - dayOfWeek % 7 ); + if ( dayOfWeek <= 4 || dayOfWeek == 7) { + d = d.addDays( ( week - 1 ) * 7 - dayOfWeek % 7 ); + } else { + d = d.addDays( ( week ) * 7 - dayOfWeek % 7 ); + } } - } - return d; + return d; } diff --git a/core/pim/datebook/datebookweekheaderimpl.h b/core/pim/datebook/datebookweekheaderimpl.h index 2e5a6ca..1ab1d52 100644 --- a/core/pim/datebook/datebookweekheaderimpl.h +++ b/core/pim/datebook/datebookweekheaderimpl.h @@ -1,66 +1,59 @@ /********************************************************************** ** Copyright (C) 2000 Trolltech AS. All rights reserved. ** ** This file is part of Qtopia Environment. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** **********************************************************************/ #ifndef DATEBOOKDAYHEADER_H #define DATEBOOKDAYHEADER_H #include <qdatetime.h> #include "datebookweekheader.h" class DateBookWeekHeader : public DateBookWeekHeaderBase { Q_OBJECT public: DateBookWeekHeader( bool startOnMonday, QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); ~DateBookWeekHeader(); - void setDate( int y, int w ); - void setStartOfWeek( bool onMonday ); + void setDate(const QDate &d); + void setStartOfWeek( bool onMonday ); signals: - void dateChanged( int y, int w ); + void dateChanged( int y, int w ); public slots: void pickDate(); - void yearChanged( int ); void nextMonth(); void prevMonth(); void nextWeek(); void prevWeek(); - void weekChanged( int ); void setDate( int y, int m, int d); protected slots: - void keyPressEvent(QKeyEvent *e) - { - e->ignore(); - } + void keyPressEvent(QKeyEvent *e) { e->ignore(); } private: - int year, - week; - bool bStartOnMonday; - + QDate date; + bool bStartOnMonday; }; QDate dateFromWeek( int week, int year, bool startOnMonday ); #endif // DATEBOOKDAYHEADER_H diff --git a/core/pim/datebook/datebookweeklst.cpp b/core/pim/datebook/datebookweeklst.cpp index 3c8fc89..a39ff40 100644 --- a/core/pim/datebook/datebookweeklst.cpp +++ b/core/pim/datebook/datebookweeklst.cpp @@ -1,390 +1,398 @@ #include "datebookweeklst.h" #include "datebookweekheaderimpl.h" #include "datebook.h" #include <qpe/calendar.h> #include <qpe/datebookdb.h> #include <qpe/event.h> #include <qpe/qpeapplication.h> #include <qpe/timestring.h> #include <qpe/datebookmonth.h> #include <qpe/config.h> #include <qpe/resource.h> #include <qdatetime.h> #include <qheader.h> #include <qlabel.h> #include <qlayout.h> #include <qpainter.h> #include <qpopupmenu.h> #include <qtimer.h> #include <qstyle.h> #include <qtoolbutton.h> #include <qvbox.h> #include <qsizepolicy.h> #include <qabstractlayout.h> #include <qtl.h> -bool calcWeek(const QDate &d, int &week, int &year, - bool startOnMonday = false); +bool calcWeek(const QDate &d, int &week, int &year,bool startOnMonday = false); -DateBookWeekLstHeader::DateBookWeekLstHeader(bool onM, QWidget* parent, - const char* name, WFlags fl) +DateBookWeekLstHeader::DateBookWeekLstHeader(bool onM, QWidget* parent, const char* name, WFlags fl) : DateBookWeekLstHeaderBase(parent, name, fl) { - setBackgroundMode( PaletteButton ); - labelDate->setBackgroundMode( PaletteButton ); - labelWeek->setBackgroundMode( PaletteButton ); - forward->setBackgroundMode( PaletteButton ); - forward->setPixmap( Resource::loadPixmap("forward") ); - back->setBackgroundMode( PaletteButton ); - back->setPixmap( Resource::loadPixmap("back") ); - DateBookWeekLstHeaderBaseLayout->setSpacing(0); - DateBookWeekLstHeaderBaseLayout->setMargin(0); - //setSizePolicy(QSizePolicy(QSizePolicy::Fixed,QSizePolicy::Expanding)); - setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed)); - - connect(back, SIGNAL(clicked()), this, SLOT(prevWeek())); - connect(forward, SIGNAL(clicked()), this, SLOT(nextWeek())); - connect(labelWeek, SIGNAL(clicked()), this, SLOT(pickDate())); - connect(dbl, SIGNAL(toggled(bool)), this, SIGNAL(setDbl(bool))); - onMonday=onM; + setBackgroundMode( PaletteButton ); + labelDate->setBackgroundMode( PaletteButton ); + forwardweek->setBackgroundMode( PaletteButton ); + forwardweek->setPixmap( Resource::loadPixmap("forward") ); + forwardmonth->setBackgroundMode( PaletteButton ); + forwardmonth->setPixmap( Resource::loadPixmap("fastforward") ); + backweek->setBackgroundMode( PaletteButton ); + backweek->setPixmap( Resource::loadPixmap("back") ); + backmonth->setBackgroundMode( PaletteButton ); + backmonth->setPixmap( Resource::loadPixmap("fastback") ); + DateBookWeekLstHeaderBaseLayout->setSpacing(0); + DateBookWeekLstHeaderBaseLayout->setMargin(0); + //setSizePolicy(QSizePolicy(QSizePolicy::Fixed,QSizePolicy::Expanding)); + setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed)); + + connect(backmonth, SIGNAL(clicked()), this, SLOT(prevMonth())); + connect(backweek, SIGNAL(clicked()), this, SLOT(prevWeek())); + connect(forwardweek, SIGNAL(clicked()), this, SLOT(nextWeek())); + connect(forwardmonth, SIGNAL(clicked()), this, SLOT(nextMonth())); + connect(labelDate, SIGNAL(clicked()), this, SLOT(pickDate())); + connect(dbl, SIGNAL(toggled(bool)), this, SIGNAL(setDbl(bool))); + bStartOnMonday=onM; } DateBookWeekLstHeader::~DateBookWeekLstHeader(){} + void DateBookWeekLstHeader::setDate(const QDate &d) { - date=d; - - int year,week; - calcWeek(d,week,year,onMonday); - labelWeek->setText(tr( "W: %1" ).arg( ( QString::number(week)) ) ); - - QDate start=date; - QDate stop=start.addDays(6); - labelDate->setText( QString::number(start.day()) + " " + - start.monthName(start.month()) + " - " + - QString::number(stop.day()) + " " + - start.monthName(stop.month()) ); - emit dateChanged(year,week); + int year,week,dayofweek; + date=d; + dayofweek=d.dayOfWeek(); + if(bStartOnMonday) dayofweek--; + date=date.addDays(-dayofweek); + + calcWeek(date,week,year,bStartOnMonday); + QDate start=date; + QDate stop=start.addDays(6); + labelDate->setText( QString::number(start.day()) + "." + + start.monthName(start.month()) + "-" + + QString::number(stop.day()) + "." + + start.monthName(stop.month()) +" ("+ + tr("w")+":"+QString::number( week ) +")"); + emit dateChanged(year,week); } + void DateBookWeekLstHeader::pickDate() { - static QPopupMenu *m1 = 0; - static DateBookMonth *picker = 0; - if ( !m1 ) { - m1 = new QPopupMenu( this ); - picker = new DateBookMonth( m1, 0, TRUE ); - m1->insertItem( picker ); - connect( picker, SIGNAL( dateClicked( int, int, int ) ), - this, SLOT( setDate( int, int, int ) ) ); - //connect( m1, SIGNAL( aboutToHide() ), - //this, SLOT( gotHide() ) ); - } - picker->setDate( date.year(), date.month(), date.day() ); - m1->popup(mapToGlobal(labelWeek->pos()+QPoint(0,labelWeek->height()))); - picker->setFocus(); + static QPopupMenu *m1 = 0; + static DateBookMonth *picker = 0; + if ( !m1 ) { + m1 = new QPopupMenu( this ); + picker = new DateBookMonth( m1, 0, TRUE ); + m1->insertItem( picker ); + connect( picker, SIGNAL( dateClicked( int, int, int ) ),this, SLOT( setDate( int, int, int ) ) ); + //connect( m1, SIGNAL( aboutToHide() ), + //this, SLOT( gotHide() ) ); + } + picker->setDate( date.year(), date.month(), date.day() ); + m1->popup(mapToGlobal(labelDate->pos()+QPoint(0,labelDate->height()))); + picker->setFocus(); } void DateBookWeekLstHeader::setDate(int y, int m, int d) { - QDate new_date(y,m,d); - setDate(new_date); + setDate(QDate(y,m,d)); } void DateBookWeekLstHeader::nextWeek() { - setDate(date.addDays(7)); + setDate(date.addDays(7)); } void DateBookWeekLstHeader::prevWeek() { - setDate(date.addDays(-7)); + setDate(date.addDays(-7)); +} +void DateBookWeekLstHeader::nextMonth() +{ + setDate(date.addDays(28)); +} +void DateBookWeekLstHeader::prevMonth() +{ + setDate(date.addDays(-28)); } DateBookWeekLstDayHdr::DateBookWeekLstDayHdr(const QDate &d, bool /*onM*/, QWidget* parent, const char* name, WFlags fl ) : DateBookWeekLstDayHdrBase(parent, name, fl) { - date=d; - - static const char *wdays={"MTWTFSS"}; - char day=wdays[d.dayOfWeek()-1]; - - label->setText( QString(QObject::tr(QString(QChar(day)))) + " " + - QString::number(d.day()) ); - add->setText("+"); - - if (d == QDate::currentDate()) { - QPalette pal=label->palette(); - pal.setColor(QColorGroup::Foreground, QColor(0,0,255)); - label->setPalette(pal); - - /* - QFont f=label->font(); - f.setItalic(true); - label->setFont(f); - label->setPalette(QPalette(QColor(0,0,255),label->backgroundColor())); - */ - } else if (d.dayOfWeek() == 7) { // FIXME: Match any holiday - QPalette pal=label->palette(); - pal.setColor(QColorGroup::Foreground, QColor(255,0,0)); - label->setPalette(pal); - } - + date=d; + + static const char *wdays={"MTWTFSS"}; + char day=wdays[d.dayOfWeek()-1]; + + label->setText( QString(QObject::tr(QString(QChar(day)))) + " " +QString::number(d.day()) ); + add->setText("+"); + + if (d == QDate::currentDate()) { + QPalette pal=label->palette(); + pal.setColor(QColorGroup::Foreground, QColor(0,0,255)); + label->setPalette(pal); + + /* + QFont f=label->font(); + f.setItalic(true); + label->setFont(f); + label->setPalette(QPalette(QColor(0,0,255),label->backgroundColor())); + */ + } else if (d.dayOfWeek() == 7) { // FIXME: Match any holiday + QPalette pal=label->palette(); + pal.setColor(QColorGroup::Foreground, QColor(255,0,0)); + label->setPalette(pal); + } - connect (label, SIGNAL(clicked()), this, SLOT(showDay())); - connect (add, SIGNAL(clicked()), this, SLOT(newEvent())); + connect (label, SIGNAL(clicked()), this, SLOT(showDay())); + connect (add, SIGNAL(clicked()), this, SLOT(newEvent())); } void DateBookWeekLstDayHdr::showDay() { - emit showDate(date.year(), date.month(), date.day()); + emit showDate(date.year(), date.month(), date.day()); } + void DateBookWeekLstDayHdr::newEvent() { QDateTime start, stop; start=stop=date; start.setTime(QTime(10,0)); stop.setTime(QTime(12,0)); emit addEvent(start,stop,"",0); } DateBookWeekLstEvent::DateBookWeekLstEvent(const EffectiveEvent &ev, int weeklistviewconfig, QWidget* parent, const char* name, WFlags fl ) : OClickableLabel(parent,name,fl), event(ev) { // old values... lastday = "__|__", middle=" |---", Firstday="00:00", QString s,start,middle,end,day; qDebug("weeklistviewconfig=%d",weeklistviewconfig); if(weeklistviewconfig==NONE) { // No times displayed. // start.sprintf("%.2d:%.2d-",ev.start().hour(),ev.start().minute()); // middle.sprintf("<--->"); // end.sprintf("-%.2d:%.2d",ev.end().hour(),ev.end().minute()); // day.sprintf("%.2d:%.2d-%.2d:%.2d",ev.start().hour(),ev.start().minute(),ev.end().hour(),ev.end().minute()); } else if(weeklistviewconfig==NORMAL) { // "Normal", only display start time. start.sprintf("%.2d:%.2d",ev.start().hour(),ev.start().minute()); middle.sprintf(" |---"); end.sprintf("__|__"); day.sprintf("%.2d:%.2d",ev.start().hour(),ev.start().minute()); } else if(weeklistviewconfig==EXTENDED) { // Extended mode, display start and end times. start.sprintf("%.2d:%.2d-",ev.start().hour(),ev.start().minute()); middle.sprintf("<--->"); end.sprintf("-%.2d:%.2d",ev.end().hour(),ev.end().minute()); day.sprintf("%.2d:%.2d-%.2d:%.2d",ev.start().hour(),ev.start().minute(),ev.end().hour(),ev.end().minute()); } if(ev.event().type() == Event::Normal) { if(ev.startDate()==ev.date() && ev.endDate()==ev.date()) { // day event. s=day; } else if(ev.startDate()==ev.date()) { // start event. s=start; } else if(ev.endDate()==ev.date()) { // end event. s=end; } else { // middle day. s=middle; } } else { s=""; } setText(QString(s) + " " + ev.description()); connect(this, SIGNAL(clicked()), this, SLOT(editMe())); setAlignment( int( QLabel::WordBreak | QLabel::AlignLeft ) ); } void DateBookWeekLstEvent::editMe() { emit editEvent(event.event()); } DateBookWeekLstView::DateBookWeekLstView(QValueList<EffectiveEvent> &ev, const QDate &d, bool onM, QWidget* parent, const char* name, WFlags fl) : QWidget( parent, name, fl ) { Config config("DateBook"); config.setGroup("Main"); int weeklistviewconfig=config.readNumEntry("weeklistviewconfig", NORMAL); qDebug("Read weeklistviewconfig: %d",weeklistviewconfig); - onMonday=onM; + bStartOnMonday=onM; setPalette(white); setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding)); QVBoxLayout *layout = new QVBoxLayout( this ); qBubbleSort(ev); QValueListIterator<EffectiveEvent> it; it=ev.begin(); int dayOrder[7]; - if (onMonday) { + if (bStartOnMonday) { for (int d=0; d<7; d++) dayOrder[d]=d+1; } else { for (int d=0; d<7; d++) dayOrder[d]=d; dayOrder[0]=7; } for (int i=0; i<7; i++) { // Header - DateBookWeekLstDayHdr *hdr=new DateBookWeekLstDayHdr(d.addDays(i), onMonday,this); - connect(hdr, SIGNAL(showDate(int,int,int)), - this, SIGNAL(showDate(int,int,int))); + DateBookWeekLstDayHdr *hdr=new DateBookWeekLstDayHdr(d.addDays(i), bStartOnMonday,this); + connect(hdr, SIGNAL(showDate(int,int,int)), this, SIGNAL(showDate(int,int,int))); connect(hdr, SIGNAL(addEvent(const QDateTime &, const QDateTime &, const QString &, const QString &)), this, SIGNAL(addEvent(const QDateTime &, const QDateTime &, const QString &, const QString &))); layout->addWidget(hdr); // Events while ( (*it).date().dayOfWeek() == dayOrder[i] && it!=ev.end() ) { if(!(((*it).end().hour()==0) && ((*it).end().minute()==0) && ((*it).startDate()!=(*it).date()))) { // Skip events ending at 00:00 starting at another day. DateBookWeekLstEvent *l=new DateBookWeekLstEvent(*it,weeklistviewconfig,this); layout->addWidget(l); connect (l, SIGNAL(editEvent(const Event &)), this, SIGNAL(editEvent(const Event &))); } it++; } layout->addItem(new QSpacerItem(1,1, QSizePolicy::Minimum, QSizePolicy::Expanding)); } } DateBookWeekLstView::~DateBookWeekLstView(){} void DateBookWeekLstView::keyPressEvent(QKeyEvent *e) {e->ignore();} DateBookWeekLstDblView::DateBookWeekLstDblView(QValueList<EffectiveEvent> &ev1, QValueList<EffectiveEvent> &ev2, QDate &d, bool onM, QWidget* parent, const char* name, WFlags fl) : QWidget( parent, name, fl ) { QHBoxLayout *layout = new QHBoxLayout( this ); DateBookWeekLstView *w=new DateBookWeekLstView(ev1,d,onM,this); layout->addWidget(w); connect (w, SIGNAL(editEvent(const Event &)), this, SIGNAL(editEvent(const Event &))); connect (w, SIGNAL(showDate(int,int,int)), this, SIGNAL(showDate(int,int,int))); connect (w, SIGNAL(addEvent(const QDateTime &, const QDateTime &, const QString &,const QString &)), this, SIGNAL(addEvent(const QDateTime &, const QDateTime &, const QString &, const QString &))); w=new DateBookWeekLstView(ev2,d.addDays(7),onM,this); layout->addWidget(w); connect (w, SIGNAL(editEvent(const Event &)), this, SIGNAL(editEvent(const Event &))); connect (w, SIGNAL(showDate(int,int,int)), this, SIGNAL(showDate(int,int,int))); connect (w, SIGNAL(addEvent(const QDateTime &, const QDateTime &, const QString &, const QString &)), this, SIGNAL(addEvent(const QDateTime &, const QDateTime &, const QString &, const QString &))); } DateBookWeekLst::DateBookWeekLst( bool ap, bool onM, DateBookDB *newDB, QWidget *parent, const char *name ) : QWidget( parent, name ), db( newDB ), startTime( 0 ), ampm( ap ), - onMonday(onM) + bStartOnMonday(onM) { - setFocusPolicy(StrongFocus); - layout = new QVBoxLayout( this ); - layout->setMargin(0); + setFocusPolicy(StrongFocus); + layout = new QVBoxLayout( this ); + layout->setMargin(0); - header=new DateBookWeekLstHeader(onM, this); - layout->addWidget( header ); - connect(header, SIGNAL(dateChanged(int,int)), this, SLOT(dateChanged(int,int))); - connect(header, SIGNAL(setDbl(bool)), this, SLOT(setDbl(bool))); + header=new DateBookWeekLstHeader(onM, this); + layout->addWidget( header ); + connect(header, SIGNAL(dateChanged(int,int)), this, SLOT(dateChanged(int,int))); + connect(header, SIGNAL(setDbl(bool)), this, SLOT(setDbl(bool))); scroll=new QScrollView(this); - //scroll->setVScrollBarMode(QScrollView::AlwaysOn); - //scroll->setHScrollBarMode(QScrollView::AlwaysOff); scroll->setResizePolicy(QScrollView::AutoOneFit); layout->addWidget(scroll); view=NULL; Config config("DateBook"); config.setGroup("Main"); dbl=config.readBoolEntry("weeklst_dbl", false); header->dbl->setOn(dbl); } DateBookWeekLst::~DateBookWeekLst(){ Config config("DateBook"); config.setGroup("Main"); config.writeEntry("weeklst_dbl", dbl); } void DateBookWeekLst::setDate(const QDate &d) { int w,y; - calcWeek(d,w,y,onMonday); + calcWeek(d,w,y,bStartOnMonday); year=y; _week=w; header->setDate(date()); } void DateBookWeekLst::setDbl(bool on) { dbl=on; redraw(); } void DateBookWeekLst::redraw() {getEvents();} QDate DateBookWeekLst::date() const { QDate d; d.setYMD(year,1,1); int dow= d.dayOfWeek(); - if (!onMonday) + if (!bStartOnMonday) if (dow==7) { dow=1; } else { dow++; } d=d.addDays( (_week-1)*7 - dow + 1 ); return d; } void DateBookWeekLst::getEvents() { QDate start = date(); QDate stop = start.addDays(6); QValueList<EffectiveEvent> el = db->getEffectiveEvents(start, stop); if (view) delete view; if (dbl) { QDate start2=start.addDays(7); stop=start2.addDays(6); QValueList<EffectiveEvent> el2 = db->getEffectiveEvents(start2, stop); - view=new DateBookWeekLstDblView(el,el2,start,onMonday,scroll); + view=new DateBookWeekLstDblView(el,el2,start,bStartOnMonday,scroll); } else { - view=new DateBookWeekLstView(el,start,onMonday,scroll); + view=new DateBookWeekLstView(el,start,bStartOnMonday,scroll); } connect (view, SIGNAL(editEvent(const Event &)), this, SIGNAL(editEvent(const Event &))); connect (view, SIGNAL(showDate(int,int,int)), this, SIGNAL(showDate(int,int,int))); connect (view, SIGNAL(addEvent(const QDateTime &, const QDateTime &, const QString &, const QString &)), this, SIGNAL(addEvent(const QDateTime &, const QDateTime &, const QString &, const QString &))); scroll->addChild(view); view->show(); scroll->updateScrollBars(); } void DateBookWeekLst::dateChanged(int y, int w) { year=y; _week=w; getEvents(); } void DateBookWeekLst::keyPressEvent(QKeyEvent *e) { switch(e->key()) { case Key_Up: scroll->scrollBy(0, -20); break; case Key_Down: scroll->scrollBy(0, 20); break; case Key_Left: header->prevWeek(); break; case Key_Right: header->nextWeek(); break; default: e->ignore(); } -} - +}
\ No newline at end of file diff --git a/core/pim/datebook/datebookweeklst.h b/core/pim/datebook/datebookweeklst.h index 17dc01f..f858c4f 100644 --- a/core/pim/datebook/datebookweeklst.h +++ b/core/pim/datebook/datebookweeklst.h @@ -1,151 +1,154 @@ #ifndef DATEBOOKWEEKLST #define DATEBOOKWEEKLST #include <qwidget.h> #include <qdatetime.h> #include <qpe/event.h> #include <qlabel.h> #include <qscrollview.h> #include "datebookweeklstheader.h" #include "datebookweeklstdayhdr.h" #include <opie/oclickablelabel.h> class QDateTime; class DateBookDB; class DateBookWeekLstHeader: public DateBookWeekLstHeaderBase { Q_OBJECT public: DateBookWeekLstHeader(bool onM, QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); ~DateBookWeekLstHeader(); void setDate(const QDate &d); public slots: - void nextWeek(); - void prevWeek(); - void pickDate(); - void setDate(int y, int m, int d); + void nextWeek(); + void prevWeek(); + void nextMonth(); + void prevMonth(); + void pickDate(); + void setDate(int y, int m, int d); signals: - void dateChanged(int y, int w); - void setDbl(bool on); + void dateChanged(int y, int w); + void setDbl(bool on); private: - QDate date; - bool onMonday; + QDate date; +// bool onMonday; + bool bStartOnMonday; }; class DateBookWeekLstDayHdr: public DateBookWeekLstDayHdrBase { Q_OBJECT public: DateBookWeekLstDayHdr(const QDate &d, bool onM, QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); public slots: void showDay(); void newEvent(); signals: void showDate(int y, int m, int d); void addEvent(const QDateTime &start, const QDateTime &stop, const QString &str, const QString &location); private: QDate date; }; class DateBookWeekLstEvent: public OClickableLabel { Q_OBJECT public: DateBookWeekLstEvent(const EffectiveEvent &ev, int weeklistviewconfig =1, QWidget* parent = 0, const char* name = 0, WFlags fl = 0); signals: void editEvent(const Event &e); private slots: void editMe(); private: const EffectiveEvent event; }; class DateBookWeekLstView: public QWidget { Q_OBJECT public: DateBookWeekLstView(QValueList<EffectiveEvent> &ev, const QDate &d, bool onM, QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); ~DateBookWeekLstView(); signals: - void editEvent(const Event &e); - void showDate(int y, int m, int d); - void addEvent(const QDateTime &start, const QDateTime &stop, - const QString &str, const QString &location); + void editEvent(const Event &e); + void showDate(int y, int m, int d); + void addEvent(const QDateTime &start, const QDateTime &stop, + const QString &str, const QString &location); private: - bool onMonday; + bool bStartOnMonday; protected slots: - void keyPressEvent(QKeyEvent *); + void keyPressEvent(QKeyEvent *); }; class DateBookWeekLstDblView: public QWidget { Q_OBJECT public: DateBookWeekLstDblView(QValueList<EffectiveEvent> &ev1, QValueList<EffectiveEvent> &ev2, QDate &d, bool onM, QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); signals: void editEvent(const Event &e); void showDate(int y, int m, int d); void addEvent(const QDateTime &start, const QDateTime &stop, const QString &str, const QString &location); }; class DateBookWeekLst : public QWidget { Q_OBJECT public: DateBookWeekLst( bool ampm, bool onM, DateBookDB *newDB, QWidget *parent = 0, const char *name = 0 ); ~DateBookWeekLst(); void setDate( int y, int w ); void setDate(const QDate &d ); int week() const { return _week; }; QDate date() const; public slots: void redraw(); void dateChanged(int y, int w); protected slots: void keyPressEvent(QKeyEvent *); void setDbl(bool on); signals: - void showDate(int y, int m, int d); - void addEvent(const QDateTime &start, const QDateTime &stop, - const QString &str, const QString &location); - void editEvent(const Event &e); + void showDate(int y, int m, int d); + void addEvent(const QDateTime &start, const QDateTime &stop, + const QString &str, const QString &location); + void editEvent(const Event &e); private: DateBookDB *db; int startTime; bool ampm; - bool onMonday; + bool bStartOnMonday; bool dbl; int year, _week; DateBookWeekLstHeader *header; QWidget *view; QVBoxLayout *layout; QScrollView *scroll; void getEvents(); }; #endif diff --git a/core/pim/datebook/datebookweeklstheader.ui b/core/pim/datebook/datebookweeklstheader.ui index c71e046..e925ec3 100644 --- a/core/pim/datebook/datebookweeklstheader.ui +++ b/core/pim/datebook/datebookweeklstheader.ui @@ -1,305 +1,306 @@ <!DOCTYPE UI><UI> <class>DateBookWeekLstHeaderBase</class> <widget> <class>QWidget</class> <property stdset="1"> <name>name</name> <cstring>DateBookWeekLstHeaderBase</cstring> </property> <property stdset="1"> <name>geometry</name> <rect> <x>0</x> <y>183</y> <width>447</width> <height>45</height> </rect> </property> <property stdset="1"> <name>sizePolicy</name> <sizepolicy> <hsizetype>7</hsizetype> <vsizetype>0</vsizetype> </sizepolicy> </property> <property> <name>layoutMargin</name> </property> <property> <name>layoutSpacing</name> </property> <hbox> <property stdset="1"> <name>margin</name> <number>11</number> </property> <property stdset="1"> <name>spacing</name> <number>6</number> </property> <widget> <class>QToolButton</class> <property stdset="1"> <name>name</name> - <cstring>back</cstring> + <cstring>backmonth</cstring> + </property> + <property stdset="1"> + <name>text</name> + <string></string> + </property> + <property stdset="1"> + <name>pixmap</name> + <pixmap></pixmap> + </property> + <property stdset="1"> + <name>toggleButton</name> + <bool>false</bool> + </property> + <property stdset="1"> + <name>autoRepeat</name> + <bool>true</bool> + </property> + <property stdset="1"> + <name>autoRaise</name> + <bool>true</bool> + </property> + <property stdset="1"> + <name>toggleButton</name> + <bool>false</bool> + </property> + <property> + <name>toolTip</name> + <string></string> + </property> + </widget> + <widget> + <class>QToolButton</class> + <property stdset="1"> + <name>name</name> + <cstring>backweek</cstring> </property> <property stdset="1"> <name>sizePolicy</name> <sizepolicy> <hsizetype>7</hsizetype> <vsizetype>0</vsizetype> </sizepolicy> </property> <property stdset="1"> <name>text</name> <string></string> </property> <property stdset="1"> <name>pixmap</name> <pixmap></pixmap> </property> <property stdset="1"> <name>toggleButton</name> <bool>false</bool> </property> <property stdset="1"> <name>autoRepeat</name> <bool>true</bool> </property> <property stdset="1"> <name>autoRaise</name> <bool>true</bool> </property> <property stdset="1"> <name>toggleButton</name> <bool>false</bool> </property> <property> <name>toolTip</name> <string></string> </property> </widget> - <spacer> + <spacer> <property> <name>name</name> <cstring>Spacer1_3</cstring> </property> <property stdset="1"> <name>orientation</name> <enum>Horizontal</enum> </property> <property stdset="1"> <name>sizeType</name> <enum>Expanding</enum> </property> <property> <name>sizeHint</name> <size> <width>20</width> <height>20</height> </size> </property> </spacer> <widget> <class>QToolButton</class> <property stdset="1"> <name>name</name> - <cstring>labelWeek</cstring> + <cstring>labelDate</cstring> </property> <property stdset="1"> <name>sizePolicy</name> <sizepolicy> <hsizetype>7</hsizetype> <vsizetype>0</vsizetype> </sizepolicy> </property> <property stdset="1"> <name>font</name> <font> <bold>1</bold> </font> </property> <property stdset="1"> <name>text</name> <string>W: 00,00</string> </property> <property stdset="1"> <name>toggleButton</name> <bool>false</bool> </property> <property stdset="1"> <name>autoRaise</name> <bool>false</bool> </property> <property stdset="1"> <name>toggleButton</name> <bool>false</bool> </property> <property> <name>toolTip</name> <string></string> </property> </widget> - <spacer> - <property> - <name>name</name> - <cstring>Spacer1</cstring> - </property> - <property stdset="1"> - <name>orientation</name> - <enum>Horizontal</enum> - </property> - <property stdset="1"> - <name>sizeType</name> - <enum>Expanding</enum> - </property> - <property> - <name>sizeHint</name> - <size> - <width>20</width> - <height>20</height> - </size> - </property> - </spacer> <widget> <class>QToolButton</class> <property stdset="1"> <name>name</name> <cstring>dbl</cstring> </property> <property stdset="1"> <name>sizePolicy</name> <sizepolicy> <hsizetype>3</hsizetype> <vsizetype>0</vsizetype> </sizepolicy> </property> <property stdset="1"> <name>font</name> <font> <bold>1</bold> </font> </property> <property stdset="1"> <name>text</name> <string>2</string> </property> <property stdset="1"> <name>toggleButton</name> <bool>true</bool> </property> <property stdset="1"> <name>autoRaise</name> <bool>false</bool> </property> <property stdset="1"> <name>toggleButton</name> <bool>true</bool> </property> <property> <name>toolTip</name> <string></string> </property> </widget> <spacer> <property> <name>name</name> <cstring>Spacer1_3_2</cstring> </property> <property stdset="1"> <name>orientation</name> <enum>Horizontal</enum> </property> <property stdset="1"> <name>sizeType</name> <enum>Expanding</enum> </property> <property> <name>sizeHint</name> <size> <width>20</width> <height>20</height> </size> </property> </spacer> <widget> - <class>QLabel</class> + <class>QToolButton</class> <property stdset="1"> <name>name</name> - <cstring>labelDate</cstring> + <cstring>forwardweek</cstring> </property> <property stdset="1"> <name>sizePolicy</name> <sizepolicy> - <hsizetype>3</hsizetype> - <vsizetype>7</vsizetype> + <hsizetype>1</hsizetype> + <vsizetype>0</vsizetype> </sizepolicy> </property> <property stdset="1"> - <name>font</name> - <font> - <bold>1</bold> - </font> - </property> - <property stdset="1"> <name>text</name> - <string>00 Jan-00 Jan</string> - </property> - <property> - <name>hAlign</name> - </property> - </widget> - <spacer> - <property> - <name>name</name> - <cstring>Spacer1_2</cstring> + <string></string> </property> <property stdset="1"> - <name>orientation</name> - <enum>Horizontal</enum> + <name>pixmap</name> + <pixmap></pixmap> </property> <property stdset="1"> - <name>sizeType</name> - <enum>Expanding</enum> + <name>autoRepeat</name> + <bool>true</bool> </property> - <property> - <name>sizeHint</name> - <size> - <width>20</width> - <height>20</height> - </size> + <property stdset="1"> + <name>autoRaise</name> + <bool>true</bool> </property> - </spacer> + </widget> <widget> <class>QToolButton</class> <property stdset="1"> <name>name</name> - <cstring>forward</cstring> - </property> - <property stdset="1"> - <name>sizePolicy</name> - <sizepolicy> - <hsizetype>1</hsizetype> - <vsizetype>0</vsizetype> - </sizepolicy> + <cstring>forwardmonth</cstring> </property> <property stdset="1"> <name>text</name> <string></string> </property> <property stdset="1"> <name>pixmap</name> <pixmap></pixmap> </property> <property stdset="1"> + <name>toggleButton</name> + <bool>false</bool> + </property> + <property stdset="1"> <name>autoRepeat</name> <bool>true</bool> </property> <property stdset="1"> <name>autoRaise</name> <bool>true</bool> </property> + <property stdset="1"> + <name>toggleButton</name> + <bool>false</bool> + </property> + <property> + <name>toolTip</name> + <string></string> + </property> </widget> </hbox> </widget> </UI> |