summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/pim/datebook/datebookday.cpp10
-rw-r--r--core/pim/datebook/datebookday.h2
-rw-r--r--core/pim/datebook/datebookdayallday.cpp11
-rw-r--r--core/pim/datebook/datebookweek.cpp4
4 files changed, 13 insertions, 14 deletions
diff --git a/core/pim/datebook/datebookday.cpp b/core/pim/datebook/datebookday.cpp
index 4d64099..751a1da 100644
--- a/core/pim/datebook/datebookday.cpp
+++ b/core/pim/datebook/datebookday.cpp
@@ -414,520 +414,522 @@ static int place( const DateBookDayWidget *item, bool *used, int maxn )
start++;
}
return place;
}
void DateBookDay::relayoutPage( bool fromResize )
{
setUpdatesEnabled( FALSE );
if ( !fromResize ) {
getEvents(); // no need we already have them!
if (m_allDays->items() > 0 )
m_allDays->show();
/*
* else if ( m_allDays->items() == 0 ) already hide in getEvents
*/
}
widgetList.sort();
//sorts the widgetList by the heights of the widget so that the tallest widgets are at the beginning
//this is needed for the simple algo below to work correctly, otherwise some widgets would be drawn outside the view
int wCount = widgetList.count();
int wid = view->columnWidth(0)-1;
int wd;
int n = 1;
QArray<int> anzIntersect(wCount); //this stores the number of maximal intersections of each widget
for (int i = 0; i<wCount; anzIntersect[i] = 1, i++);
if ( wCount < 20 ) {
QArray<QRect> geometries(wCount);
for (int i = 0; i < wCount; geometries[i] = widgetList.at(i)->geometry(), i++); //stores geometry for each widget in vector
for ( int i = 0; i < wCount; i++) {
QValueList<int> intersectedWidgets;
//find all widgets intersecting with widgetList.at(i)
for ( int j = 0; j < wCount; j++) {
if (i != j)
if (geometries[j].intersects(geometries[i]))
intersectedWidgets.append(j);
}
//for each of these intersecting widgets find out how many widgets are they intersecting with
for ( uint j = 0; j < intersectedWidgets.count(); j++)
{
QArray<int> inter(wCount);
inter[j]=1;
if (intersectedWidgets[j] != -1)
for ( uint k = j; k < intersectedWidgets.count(); k++) {
if (j != k && intersectedWidgets[k] != -1)
if (geometries[intersectedWidgets[k]].intersects(geometries[intersectedWidgets[j]])) {
inter[j]++;
intersectedWidgets[k] = -1;
}
if (inter[j] > anzIntersect[i]) anzIntersect[i] = inter[j] + 1;
}
}
if (anzIntersect[i] == 1 && intersectedWidgets.count()) anzIntersect[i]++;
}
for ( int i = 0; i < wCount; i++) {
DateBookDayWidget *w = widgetList.at(i);
QRect geom = w->geometry();
geom.setX( 0 );
wd = (view->columnWidth(0)-1) / anzIntersect[i] - (anzIntersect[i]>1?2:0);
geom.setWidth( wd );
while ( intersects( w, geom ) ) {
geom.moveBy( wd + 2 + 1, 0 );
}
w->setGeometry( geom );
}
if (jumpToCurTime && this->date() == QDate::currentDate()) {
view->setContentsPos( 0, QTime::currentTime().hour() * view->rowHeight(0) ); //set listview to current hour
} else {
view->setContentsPos( 0, startTime * view->rowHeight(0) );
}
} else {
int hours[24];
memset( hours, 0, 24*sizeof( int ) );
bool overFlow = FALSE;
for ( int i = 0; i < wCount; i++ ) {
DateBookDayWidget *w = widgetList.at(i);
int start = w->event().start().hour();
QTime e = w->event().end();
int end = e.hour();
if ( e.minute() < 5 )
end--;
if ( end < start )
end = start;
while( start <= end ) {
hours[start]++;
if ( hours[start] >= 10 )
overFlow = TRUE;
++start;
}
if ( overFlow )
break;
}
for ( int i = 0; i < 24; i++ ) {
n = QMAX( n, hours[i] );
}
wid = ( view->columnWidth(0)-1 ) / n;
bool used[24*10];
memset( used, FALSE, 24*10*sizeof( bool ) );
for ( int i = 0; i < wCount; i++ ) {
DateBookDayWidget *w = widgetList.at(i);
int xp = place( w, used, n );
if ( xp != -1 ) {
QRect geom = w->geometry();
geom.setX( xp*(wid+2) );
geom.setWidth( wid );
w->setGeometry( geom );
}
}
if (jumpToCurTime && this->date() == QDate::currentDate()) {
view->setContentsPos( 0, QTime::currentTime().hour() * view->rowHeight(0) ); //set listview to current hour
} else {
view->setContentsPos( 0, startTime * view->rowHeight(0) );
}
}
timeMarker->setTime( QTime::currentTime() ); //display timeMarker
timeMarker->raise(); //on top of all widgets
if (this->date() == QDate::currentDate()) { //only show timeMarker on current day
timeMarker->show();
} else {
timeMarker->hide();
}
setUpdatesEnabled( TRUE );
return;
}
DateBookDayWidget *DateBookDay::intersects( const DateBookDayWidget *item, const QRect &geom )
{
int i = 0;
DateBookDayWidget *w = widgetList.at(i);
int wCount = widgetList.count();
while ( i < wCount && w != item ) {
if ( w->geometry().intersects( geom ) ) {
return w;
}
w = widgetList.at(++i);
}
return 0;
}
QDate DateBookDay::date() const
{
return currDate;
}
void DateBookDay::setStartViewTime( int startHere )
{
startTime = startHere;
dayView()->clearSelection();
QTableSelection ts;
if (jumpToCurTime && this->date() == QDate::currentDate()) { //this should probably be in datebook.cpp where it's called?
ts.init( QTime::currentTime().hour(), 0);
ts.expandTo( QTime::currentTime().hour(), 0);
} else {
ts.init( startTime, 0 );
ts.expandTo( startTime, 0 );
}
dayView()->addSelection( ts );
}
int DateBookDay::startViewTime() const
{
return startTime;
}
void DateBookDay::slotWeekChanged( bool bStartOnMonday )
{
header->setStartOfWeek( bStartOnMonday );
// redraw();
}
void DateBookDay::keyPressEvent(QKeyEvent *e)
{
switch(e->key()) {
case Key_Up:
view->moveUp();
break;
case Key_Down:
view->moveDown();
break;
case Key_Left:
setDate(QDate(currDate).addDays(-1));
break;
case Key_Right:
setDate(QDate(currDate).addDays(1));
break;
default:
e->ignore();
}
}
//===========================================================================
DateBookDayWidget::DateBookDayWidget( const EffectiveEvent &e, DateBookDay *db )
: QWidget( db->dayView()->viewport() ), ev( e ), dateBook( db )
{
// 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, "&#60;" );
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, "&#60;" );
// where = strCat.find( "<", where );
// }
QString strNote = ev.notes();
where = strNote.find( "<" );
while ( where != -1 ) {
strNote.remove( where, 1 );
strNote.insert( where, "&#60;" );
where = strNote.find( "<", where );
}
text = "<b>" + strDesc + "</b><br>" + "<i>";
if ( !strCat.isEmpty() ) {
text += strCat + "</i><br>";
}
if (ev.event().type() == Event::Normal ) {
setEventText( text );
} else {
setAllDayText( text );
}
text += "<br><br>" + strNote;
setBackgroundMode( PaletteBase );
QTime start = ev.start();
QTime end = ev.end();
int y = start.hour()*60+start.minute();
int h = end.hour()*60+end.minute()-y;
int rh = dateBook->dayView()->rowHeight(0);
y = y*rh/60;
h = h*rh/60;
if ( h < 12 ) h = 12; // Make sure the widget is no smaller than 12 pixels high, so that it's possible to read atleast the first line.
if ( y > ((24*rh)-12) ) y=(24*rh)-12; // Make sure the widget fits inside the dayview.
geom.setY( y );
geom.setHeight( h );
geom.setX( 0 );
geom.setWidth(dateBook->dayView()->columnWidth(0)-1);
}
void DateBookDayWidget::setAllDayText( QString &text ) {
text += "<b>" + tr("This is an all day event.") + "</b>";
}
void DateBookDayWidget::setEventText( QString& text ) {
bool whichClock = dateBook->dayView()->whichClock();
if ( ev.startDate() != ev.endDate() ) {
text += "<b>" + tr("Start") + "</b>: ";
text += TimeString::timeString( ev.event().start().time(), whichClock, FALSE );
text += " - " + TimeString::longDateString( ev.startDate() ) + "<br>";
text += "<b>" + tr("End") + "</b>: ";
text += TimeString::timeString( ev.event().end().time(), whichClock, FALSE );
text += " - " + TimeString::longDateString( ev.endDate() );
} else {
text += "<b>" + tr("Time") + "</b>: ";
text += TimeString::timeString( ev.start(), whichClock, FALSE );
text += "<b>" + tr(" - ") + "</b>";
text += TimeString::timeString( ev.end(), whichClock, FALSE );
}
}
DateBookDayWidget::~DateBookDayWidget()
{
}
void DateBookDayWidget::paintEvent( QPaintEvent *e )
{
QPainter p( this );
if (dateBook->getSelectedWidget() == this) {
p.setBrush( QColor( 155, 240, 230 ) ); // selected item
} else {
if (dateBook->date() == QDate::currentDate()) {
QTime curTime = QTime::currentTime();
if (ev.end() < curTime) {
p.setBrush( QColor( 180, 180, 180 ) ); // grey, inactive
} else {
//change color in dependence of the time till the event starts
int duration = curTime.secsTo(ev.start());
if (duration < 0) duration = 0;
int colChange = duration*160/86400; //86400: secs per day, 160: max color shift
p.setBrush( QColor( 200-colChange, 200-colChange, 255 ) ); //blue
}
} else {
p.setBrush( QColor( 220, 220, 220 ) ); //light grey, inactive (not current date)
//perhaps make a distinction between future/past dates
}
}
p.setPen( QColor(100, 100, 100) );
p.drawRect(rect());
// p.drawRect(0,0, 5, height());
int y = 0;
int d = 0;
if ( ev.event().hasAlarm() ) {
p.drawPixmap( width() - 16, 0, Resource::loadPixmap( "bell" ) );
y = 20;
d = 20;
}
if ( ev.event().hasRepeat() ) {
p.drawPixmap( width() - 16, y, Resource::loadPixmap( "repeat" ) );
d = 20;
y += 20;
}
QSimpleRichText rt( text, font() );
rt.setWidth( geom.width() - d - 6 );
rt.draw( &p, 7, 0, e->region(), colorGroup() );
}
/*
* we need to find the real start date for a uid
* we need to check from one day to another...
*/
QDate DateBookDay::findRealStart( int uid, const QDate& isIncluded , DateBookDB* db) {
QDate dt( isIncluded );
QDate fnd = dt;
bool doAgain = true;
do{
dt = dt.addDays( -1 );
QValueList<EffectiveEvent> events = db->getEffectiveEvents( dt, dt );
for (QValueList<EffectiveEvent>::Iterator it = events.begin(); it != events.end(); ++it ) {
EffectiveEvent ev = (*it);
if ( uid == ev.event().uid() && ev.start() != QTime(0, 0, 0 ) )
return ev.date();
}
}while (doAgain );
return fnd;
}
void DateBookDayWidget::mousePressEvent( QMouseEvent *e )
{
DateBookDayWidget *item;
item = dateBook->getSelectedWidget();
if (item)
item->update();
dateBook->setSelectedWidget(this);
update();
dateBook->repaint();
+ Event eve = ev.event();
+
QPopupMenu m;
m.insertItem( tr( "Edit" ), 1 );
m.insertItem( tr( "Duplicate" ), 4 );
m.insertItem( tr( "Delete" ), 2 );
if(Ir::supported()) m.insertItem( tr( "Beam" ), 3 );
if(Ir::supported() && ev.event().doRepeat() ) m.insertItem( tr( "Beam this occurence"), 5 );
int r = m.exec( e->globalPos() );
if ( r == 1 ) {
- emit editMe( ev.event() );
+ emit editMe( eve );
} else if ( r == 2 ) {
- emit deleteMe( ev.event() );
+ emit deleteMe( eve );
} else if ( r == 3 ) {
- emit beamMe( ev.event() );
+ emit beamMe( eve );
} else if ( r == 4 ) {
- emit duplicateMe( ev.event() );
+ emit duplicateMe( eve );
} else if ( r == 5 ) {
// create an Event and beam it...
/*
* Start with the easy stuff. If start and end date is the same we can just use
* the values of effective events
* If it is a multi day event we need to find the real start and end date...
*/
if ( ev.event().start().date() == ev.event().end().date() ) {
Event event( ev.event() );
QDateTime dt( ev.date(), ev.start() );
event.setStart( dt );
dt.setTime( ev.end() );
event.setEnd( dt );
emit beamMe( event );
}else {
/*
* at least the the Times are right now
*/
QDateTime start( ev.event().start() );
QDateTime end ( ev.event().end () );
/*
* ok we know the start date or we need to find it
*/
if ( ev.start() != QTime( 0, 0, 0 ) ) {
start.setDate( ev.date() );
}else {
QDate dt = DateBookDay::findRealStart( ev.event().uid(), ev.date(), dateBook->db );
start.setDate( dt );
}
/*
* ok we know now the end date...
* else
* get to know the offset btw the real start and real end
* and then add it to the new start date...
*/
if ( ev.end() != QTime(23, 59, 59 ) ) {
end.setDate( ev.date() );
}else{
int days = ev.event().start().date().daysTo( ev.event().end().date() );
end.setDate( start.date().addDays( days ) );
}
Event event( ev.event() );
event.setStart( start );
event.setEnd ( end );
emit beamMe( event );
}
}
}
void DateBookDayWidget::setGeometry( const QRect &r )
{
geom = r;
setFixedSize( r.width()+1, r.height()+1 );
dateBook->dayView()->moveChild( this, r.x(), r.y()-1 );
show();
}
//---------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------
DateBookDayTimeMarker::DateBookDayTimeMarker( DateBookDay *db )
: QWidget( db->dayView()->viewport() ), dateBook( db )
{
setBackgroundMode( PaletteBase );
}
DateBookDayTimeMarker::~DateBookDayTimeMarker()
{
}
void DateBookDayTimeMarker::paintEvent( QPaintEvent */*e*/ )
{
QPainter p( this );
p.setBrush( QColor( 255, 0, 0 ) );
QPen pen;
pen.setStyle(NoPen);
p.setPen( pen );
p.drawRect(rect());
}
void DateBookDayTimeMarker::setTime( const QTime &t )
{
int y = t.hour()*60+t.minute();
int rh = dateBook->dayView()->rowHeight(0);
y = y*rh/60;
geom.setX( 0 );
int x = dateBook->dayView()->columnWidth(0)-1;
geom.setWidth( x );
geom.setY( y );
geom.setHeight( 1 );
setGeometry( geom );
time = t;
}
void DateBookDayTimeMarker::setGeometry( const QRect &r )
{
geom = r;
setFixedSize( r.width()+1, r.height()+1 );
dateBook->dayView()->moveChild( this, r.x(), r.y()-1 );
show();
}
diff --git a/core/pim/datebook/datebookday.h b/core/pim/datebook/datebookday.h
index 3898cbc..c8cb26b 100644
--- a/core/pim/datebook/datebookday.h
+++ b/core/pim/datebook/datebookday.h
@@ -1,236 +1,236 @@
/**********************************************************************
** 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 DATEBOOKDAY_H
#define DATEBOOKDAY_H
#include <qpe/event.h>
#include <qdatetime.h>
#include <qtable.h>
#include <qvbox.h>
#include <qlist.h>
#include "datebook.h"
#include <qlineedit.h>
class DateBookDayHeader;
class DateBookDB;
class DatebookdayAllday;
class QDateTime;
class QMouseEvent;
class QPaintEvent;
class QResizeEvent;
class DateBookDayViewQuickLineEdit : public QLineEdit
{
Q_OBJECT
public:
DateBookDayViewQuickLineEdit(const QDateTime &start, const QDateTime &end,QWidget * parent, const char *name=0);
protected:
Event quickEvent;
int active;
void focusOutEvent( QFocusEvent *e );
protected slots:
void slotReturnPressed(void);
void finallyCallClose();
signals:
void insertEvent(const Event &e);
};
class DateBookDayView : public QTable
{
Q_OBJECT
public:
DateBookDayView( bool hourClock, QWidget *parent, const char *name );
bool whichClock() const;
void setRowStyle( int style );
public slots:
void moveUp();
void moveDown();
void slotDateChanged( int year, int month, int day );
signals:
void sigColWidthChanged();
void sigCapturedKey( const QString &txt );
protected slots:
void slotChangeClock( bool );
protected:
virtual void paintCell( QPainter *p, int row, int col, const QRect &cr, bool selected );
virtual void paintFocus( QPainter *p, const QRect &cr );
virtual void resizeEvent( QResizeEvent *e );
void keyPressEvent( QKeyEvent *e );
void contentsMouseReleaseEvent( QMouseEvent *e );
void initHeader();
private:
bool ampm;
QDate currDate;
DateBookDayViewQuickLineEdit *quickLineEdit;
};
class DateBookDay;
class DateBookDayWidget : public QWidget
{
Q_OBJECT
public:
DateBookDayWidget( const EffectiveEvent &e, DateBookDay *db );
~DateBookDayWidget();
const QRect &geometry() { return geom; }
void setGeometry( const QRect &r );
const EffectiveEvent &event() const { return ev; }
signals:
void deleteMe( const Event &e );
void duplicateMe( const Event &e );
void editMe( const Event &e );
void beamMe( const Event &e );
protected:
void paintEvent( QPaintEvent *e );
void mousePressEvent( QMouseEvent *e );
private:
/**
* Sets the text for an all day Event
* All day events have no time associated
*/
void setAllDayText( QString& text );
/**
* Sets the EventText
* it got a start and an end Time
*/
void setEventText( QString& text );
- const EffectiveEvent ev;
+ EffectiveEvent ev;
DateBookDay *dateBook;
QString text;
QRect geom;
};
//Marker for current time in the dayview
class DateBookDayTimeMarker : public QWidget
{
Q_OBJECT
public:
DateBookDayTimeMarker( DateBookDay *db );
~DateBookDayTimeMarker();
const QRect &geometry() { return geom; }
void setGeometry( const QRect &r );
void setTime( const QTime &t );
signals:
protected:
void paintEvent( QPaintEvent *e );
private:
QRect geom;
QTime time;
DateBookDay *dateBook;
};
//reimplemented the compareItems function so that it sorts DayWidgets by geometry heights
class WidgetListClass : public QList<DateBookDayWidget>
{
private:
int compareItems( QCollection::Item s1, QCollection::Item s2 )
{
//hmm, don't punish me for that ;)
if (reinterpret_cast<DateBookDayWidget*>(s1)->geometry().height() > reinterpret_cast<DateBookDayWidget*>(s2)->geometry().height())
{
return -1;
} else
{
return 1;
}
}
};
class DateBookDay : public QVBox
{
Q_OBJECT
friend class DateBookDayWidget; // for beam this occurence and access to DateBookDB
public:
DateBookDay( bool ampm, bool startOnMonday, DateBookDB *newDb,
QWidget *parent, const char *name );
void selectedDates( QDateTime &start, QDateTime &end );
QDate date() const;
DateBookDayView *dayView() const { return view; }
void setStartViewTime( int startHere );
int startViewTime() const;
void setSelectedWidget( DateBookDayWidget * );
DateBookDayWidget * getSelectedWidget( void );
void setJumpToCurTime( bool bJump );
void setRowStyle( int style );
static QDate findRealStart( int uid, const QDate& isIncluded,
DateBookDB* );
public slots:
void setDate( int y, int m, int d );
void setDate( QDate );
void redraw();
void slotWeekChanged( bool bStartOnMonday );
void updateView(); //updates TimeMarker and DayWidget-colors
signals:
void removeEvent( const Event& );
void editEvent( const Event& );
void duplicateEvent( const Event& );
void beamEvent( const Event& );
void newEvent();
void sigNewEvent( const QString & );
protected slots:
void keyPressEvent(QKeyEvent *);
private slots:
void dateChanged( int y, int m, int d );
void slotColWidthChanged() { relayoutPage(); };
private:
void getEvents();
void relayoutPage( bool fromResize = false );
DateBookDayWidget *intersects( const DateBookDayWidget *item, const QRect &geom );
QDate currDate;
DateBookDayView *view;
DateBookDayHeader *header;
DatebookdayAllday *m_allDays;
DateBookDB *db;
WidgetListClass widgetList; //reimplemented QList for sorting widgets by height
int startTime;
bool jumpToCurTime; //should we jump to current time in dayview?
int rowStyle;
DateBookDayWidget *selectedWidget; //actual selected widget (obviously)
DateBookDayTimeMarker *timeMarker; //marker for current time
};
#endif
diff --git a/core/pim/datebook/datebookdayallday.cpp b/core/pim/datebook/datebookdayallday.cpp
index 2294f3c..1244fd3 100644
--- a/core/pim/datebook/datebookdayallday.cpp
+++ b/core/pim/datebook/datebookdayallday.cpp
@@ -1,235 +1,236 @@
/****************************************************************************
** GPL by Rajko Albrecht
**
**
**
**
**
****************************************************************************/
#include "datebookdayallday.h"
#include <qpushbutton.h>
#include <qlayout.h>
#include <qvariant.h>
#include <qtooltip.h>
#include <qwhatsthis.h>
#include <qobjectlist.h>
#include <qpe/event.h>
#include <qpe/ir.h>
#include <qpe/datebookdb.h>
#include <qpe/resource.h>
#include <qpopupmenu.h>
#include <qtimer.h>
#include <qregexp.h>
#include <qdatetime.h>
#include "datebookday.h"
/*
* Constructs a DatebookdayAllday which is a child of 'parent', with the
* name 'name' and widget flags set to 'f'
*/
DatebookdayAllday::DatebookdayAllday(DateBookDB* db, QWidget* parent, const char* name, WFlags )
: QScrollView( parent, name ),item_count(0),dateBook(db)
{
if ( !name )
setName( "DatebookdayAllday" );
setMinimumSize( QSize( 0, 0 ) );
setMaximumHeight(3* (QFontMetrics(font()).height()+4) );
m_MainFrame = new QFrame(viewport());
m_MainFrame->setFrameStyle(QFrame::NoFrame|QFrame::Plain);
setFrameStyle(QFrame::NoFrame|QFrame::Plain);
setResizePolicy( QScrollView::Default );
setHScrollBarMode( AlwaysOff );
addChild(m_MainFrame);
datebookdayalldayLayout = new QVBoxLayout( m_MainFrame );
datebookdayalldayLayout->setSpacing( 0 );
datebookdayalldayLayout->setMargin( 0 );
lblDesc = new DatebookEventDesc(parent->parentWidget(),"");
lblDesc->setBackgroundColor(Qt::yellow);
lblDesc->hide();
subWidgets.setAutoDelete(true);
}
/*
* Destroys the object and frees any allocated resources
*/
DatebookdayAllday::~DatebookdayAllday()
{
// no need to delete child widgets, Qt does it all for us
}
DatebookAlldayDisp* DatebookdayAllday::addEvent(const EffectiveEvent&ev)
{
DatebookAlldayDisp * lb;
lb = new DatebookAlldayDisp(dateBook,ev,m_MainFrame,NULL);
lb->show();
datebookdayalldayLayout->addWidget(lb);
subWidgets.append(lb);
connect(lb,SIGNAL(displayMe(const Event &)),lblDesc,SLOT(disp_event(const Event&)));
++item_count;
return lb;
}
void DatebookdayAllday::removeAllEvents()
{
subWidgets.clear();
item_count = 0;
}
DatebookAlldayDisp::DatebookAlldayDisp(DateBookDB *db,const EffectiveEvent& ev,
QWidget* parent,const char* name,WFlags f)
: QLabel(parent,name,f),m_Ev(ev),dateBook(db)
{
QString strDesc = m_Ev.description();
strDesc = strDesc.replace(QRegExp("<"),"&#60;");
setBackgroundColor(yellow);
setText(strDesc);
setFrameStyle(QFrame::Raised|QFrame::Panel);
int s = QFontMetrics(font()).height()+4;
setMaximumHeight( s );
setMinimumSize( QSize( 0, s ) );
}
DatebookAlldayDisp::~DatebookAlldayDisp()
{
}
void DatebookAlldayDisp::beam_single_event()
{
// create an Event and beam it...
/*
* Start with the easy stuff. If start and end date is the same we can just use
* the values of effective m_Events
* If it is a multi day m_Event we need to find the real start and end date...
*/
if ( m_Ev.event().start().date() == m_Ev.event().end().date() ) {
Event m_Event( m_Ev.event() );
QDateTime dt( m_Ev.date(), m_Ev.start() );
m_Event.setStart( dt );
dt.setTime( m_Ev.end() );
m_Event.setEnd( dt );
emit beamMe( m_Event );
}else {
/*
* at least the the Times are right now
*/
QDateTime start( m_Ev.event().start() );
QDateTime end ( m_Ev.event().end () );
/*
* ok we know the start date or we need to find it
*/
if ( m_Ev.start() != QTime( 0, 0, 0 ) ) {
start.setDate( m_Ev.date() );
}else {
QDate dt = DateBookDay::findRealStart( m_Ev.event().uid(), m_Ev.date(), dateBook );
start.setDate( dt );
}
/*
* ok we know now the end date...
* else
* get to know the offset btw the real start and real end
* and then add it to the new start date...
*/
if ( m_Ev.end() != QTime(23, 59, 59 ) ) {
end.setDate( m_Ev.date() );
}else{
int days = m_Ev.event().start().date().daysTo( m_Ev.event().end().date() );
end.setDate( start.date().addDays( days ) );
}
Event m_Event( m_Ev.event() );
m_Event.setStart( start );
m_Event.setEnd ( end );
emit beamMe( m_Event );
}
}
void DatebookAlldayDisp::mousePressEvent(QMouseEvent*e)
{
+ Event ev = m_Ev.event();
QColor b = backgroundColor();
setBackgroundColor(green);
update();
QPopupMenu m;
m.insertItem( DateBookDayWidget::tr( "Edit" ), 1 );
m.insertItem( DateBookDayWidget::tr( "Duplicate" ), 4 );
m.insertItem( DateBookDayWidget::tr( "Delete" ), 2 );
if(Ir::supported()) m.insertItem( DateBookDayWidget::tr( "Beam" ), 3 );
if(Ir::supported() && m_Ev.event().doRepeat() ) m.insertItem( DateBookDayWidget::tr( "Beam this occurence"), 5 );
m.insertItem( tr( "Info"),6);
int r = m.exec( e->globalPos() );
setBackgroundColor(b);
update();
switch (r) {
case 1:
- emit editMe( m_Ev.event() );
+ emit editMe( ev );
break;
case 2:
- emit deleteMe( m_Ev.event() );
+ emit deleteMe( ev );
break;
case 3:
- emit beamMe( m_Ev.event() );
+ emit beamMe( ev );
break;
case 4:
- emit duplicateMe( m_Ev.event() );
+ emit duplicateMe( ev );
break;
case 5:
beam_single_event();
break;
case 6:
- emit displayMe( m_Ev.event() );
+ emit displayMe( ev );
break;
default:
break;
}
}
DatebookEventDesc::DatebookEventDesc(QWidget*parent,const char*name)
:QLabel(parent,name)
{
m_Timer=new QTimer(this);
connect(m_Timer,SIGNAL(timeout()),this,SLOT(hide()));
setFrameStyle(QFrame::Sunken|QFrame::Panel);
setTextFormat(RichText);
}
DatebookEventDesc::~DatebookEventDesc()
{
}
void DatebookEventDesc::mousePressEvent(QMouseEvent*)
{
hide();
if (m_Timer->isActive()) m_Timer->stop();
}
void DatebookEventDesc::disp_event(const Event&e)
{
if (m_Timer->isActive()) m_Timer->stop();
QString text;
text = "<b><i>"+e.description()+"</i></b><br>";
if (e.notes().length()>0) {
text+="<b>"+e.notes()+"</b><br>";
}
if (e.location().length()>0) {
text+="<i>"+e.location()+"</i><br>";
}
text = text.replace(QRegExp("\n"),"<br>");
setText(text);
QSize s = sizeHint();
s+=QSize(10,10);
resize(s);
move( QMAX(0,(parentWidget()->width()-width()) / 2),
(parentWidget()->height()-height())/2 );
show();
m_Timer->start(2000,true);
}
diff --git a/core/pim/datebook/datebookweek.cpp b/core/pim/datebook/datebookweek.cpp
index 8435132..933e191 100644
--- a/core/pim/datebook/datebookweek.cpp
+++ b/core/pim/datebook/datebookweek.cpp
@@ -1,679 +1,675 @@
/**********************************************************************
** 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/datebookdb.h>
#include <qpe/qpeapplication.h>
#include <qpe/calendar.h>
#include <qheader.h>
#include <qlabel.h>
#include <qlayout.h>
#include <qtimer.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()
{
-#warning Please review this ! (eilers)
-
- // Ok, I am Mr. Pedantic, but shouldn't we count until 6 instead of 7, if bOnMonday is false ? (eilers)
static bool bFirst = true;
if ( bFirst ) {
if ( bOnMonday ) {
for ( int i = 1; i<=7; i++ ) {
header->addLabel( Calendar::nameOfDay( i ) );
}
} else {
header->addLabel( Calendar::nameOfDay( 7 ) );
for ( int i = 1; i<7; i++ ) {
header->addLabel( Calendar::nameOfDay( i ) );
}
}
bFirst = false;
} else {
// we are change things...
if ( bOnMonday ) {
for ( int i = 1; i<=7; i++ ) {
header->setLabel( i, Calendar::nameOfDay( i ) );
}
} else {
header->setLabel( 1, Calendar::nameOfDay( 7 ) );
for ( int i = 1; i<7; i++ ) {
header->setLabel( i+1, Calendar::nameOfDay( i ) );
}
}
}
}
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 );
-#warning check the geometry i have choosen BRANCH_1_0 (waspe)
//HEAD
/*
int avail = visibleWidth();
header->setGeometry( leftMargin()+frameWidth()+frameRect().left() , frameWidth(),
visibleWidth(), header->sizeHint().height() );
setMargins( 0, header->sizeHint().height(), 0, 0 );
*/
//BRANCH_1_0
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( QDate &) ), this, SLOT( dateChanged( QDate &) ) );
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=bdate;
// Calculate offset to first day of week.
int dayoffset=d.dayOfWeek() % 7;
if(bStartOnMonday) dayoffset--;
day--;
d=d.addDays(day-dayoffset);
emit showDate( d.year(), d.month(), d.day() );
}
void DateBookWeek::setDate( int y, int m, int d )
{
setDate(QDate(y, m, d));
}
void DateBookWeek::setDate(QDate newdate)
{
bdate=newdate;
dow = newdate.dayOfWeek();
header->setDate( newdate );
}
void DateBookWeek::dateChanged( QDate &newdate )
{
bdate=newdate;
getEvents();
}
QDate DateBookWeek::date() const
{
return bdate;
}
void DateBookWeek::getEvents()
{
QDate startWeek = weekDate();
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>";
}
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, "&#60;" );
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, "&#60;" );
// where = strCat.find( "<", where );
// }
QString strLocation = ev.location();
while ( where != -1 ) {
strLocation.remove( where, 1 );
strLocation.insert( where, "&#60;" );
where = strLocation.find( "<", where );
}
QString strNote = ev.notes();
where = strNote.find( "<" );
while ( where != -1 ) {
strNote.remove( where, 1 );
strNote.insert( where, "&#60;" );
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 );
calcWeek( d, totWeek, throwAway, bStartOnMonday );
}
}
void DateBookWeek::slotWeekChanged( bool onMonday )
{
bStartOnMonday = onMonday;
view->setStartOfWeek( bStartOnMonday );
header->setStartOfWeek( bStartOnMonday );
redraw();
}
void DateBookWeek::slotClockChanged( bool ap )
{
ampm = ap;
}
// return the date at the beginning of the week...
QDate DateBookWeek::weekDate() const
{
QDate d=bdate;
// Calculate offset to first day of week.
int dayoffset=d.dayOfWeek();
if(bStartOnMonday) dayoffset--;
else if( dayoffset == 7 )
dayoffset = 0;
return d.addDays(-dayoffset);
}
// 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;
}