summaryrefslogtreecommitdiffabout
path: root/korganizer/kodaymatrix.cpp
Side-by-side diff
Diffstat (limited to 'korganizer/kodaymatrix.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/kodaymatrix.cpp47
1 files changed, 28 insertions, 19 deletions
diff --git a/korganizer/kodaymatrix.cpp b/korganizer/kodaymatrix.cpp
index 52fd1e8..4f681b3 100644
--- a/korganizer/kodaymatrix.cpp
+++ b/korganizer/kodaymatrix.cpp
@@ -3,176 +3,185 @@
Copyright (c) 2001 Eitzenberger Thomas <thomas.eitzenberger@siemens.at>
Parts of the source code have been copied from kdpdatebutton.cpp
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
As a special exception, permission is given to link this program
with any edition of Qt, and distribute the resulting executable,
without including the source ode for Qt in the source distribution.
*/
#include <qevent.h>
#include <qpainter.h>
-#include <qptrlist.h>
+#include <q3ptrlist.h>
#include <qtimer.h>
-#include <qwhatsthis.h>
+#include <q3whatsthis.h>
+//Added by qt3to4:
+#include <QDragLeaveEvent>
+#include <Q3Frame>
+#include <QDragEnterEvent>
+#include <QDragMoveEvent>
+#include <QDropEvent>
+#include <QResizeEvent>
+#include <QMouseEvent>
+#include <QPaintEvent>
#include <kglobal.h>
#include <kdebug.h>
#include <klocale.h>
#include <libkcal/vcaldrag.h>
#include <libkcal/icaldrag.h>
#include <libkcal/dndfactory.h>
#include <libkcal/calendarresources.h>
#include <libkcal/resourcecalendar.h>
#include <kresources/resourceselectdialog.h>
#include <kcalendarsystem.h>
#ifndef KORG_NOPLUGINS
#include "kocore.h"
#endif
#include "koprefs.h"
#include "koglobals.h"
#include "kodaymatrix.h"
// ============================================================================
// D Y N A M I C T I P
// ============================================================================
DynamicTip::DynamicTip( QWidget * parent )
- : QToolTip( parent )
+ /* TODO:hacker: : QToolTip( parent ) */
{
matrix = (KODayMatrix*)parent;
}
-class KODaymatrixWhatsThis :public QWhatsThis
+class KODaymatrixWhatsThis :public Q3WhatsThis
{
public:
- KODaymatrixWhatsThis( KODayMatrix* view ) : QWhatsThis( view ),_view (view) { ;};
+ KODaymatrixWhatsThis( KODayMatrix* view ) : Q3WhatsThis( view ),_view (view) { ;};
~KODaymatrixWhatsThis() { ; };
protected:
virtual QString text( const QPoint& p )
{
return _view->getWhatsThisText( p ) ;
}
private:
KODayMatrix * _view;
};
void DynamicTip::maybeTip( const QPoint &pos )
{
//calculate which cell of the matrix the mouse is in
QRect sz = matrix->frameRect();
int dheight = sz.height()*7 / 42;
int dwidth = sz.width() / 7;
int row = pos.y()/dheight;
int col = pos.x()/dwidth;
QRect rct(col*dwidth, row*dheight, dwidth, dheight);
// kdDebug() << "DynamicTip::maybeTip matrix cell index [" <<
// col << "][" << row << "] => " <<(col+row*7) << endl;
//show holiday names only
QString str = matrix->getHolidayLabel(col+row*7);
if (str.isEmpty()) return;
- tip(rct, str);
+ /* TODO:hacker: tip(rct, str);*/
}
// ============================================================================
// K O D A Y M A T R I X
// ============================================================================
const int KODayMatrix::NOSELECTION = -1000;
const int KODayMatrix::NUMDAYS = 42;
KODayMatrix::KODayMatrix( QWidget *parent, const char *name )
- : QFrame( parent, name , Qt::WRepaintNoErase ), mCalendar( 0 )
+ : Q3Frame( parent, name , Qt::WNoAutoErase ), mCalendar( 0 )
{
mLastView = -1;
oldW = 0;
oldH = 0;
myPix.resize( 150, 120 );
mRedrawNeeded = true;
mKODaymatrixWhatsThis = new KODaymatrixWhatsThis(this);
mPendingUpdateBeforeRepaint = false;
mouseDown = false;
// initialize dynamic arrays
bDays.resize ( NUMDAYS );
pDays.resize ( NUMDAYS );
hDays.resize ( NUMDAYS );
eDays.resize ( NUMDAYS );
days = new QDate[NUMDAYS];
daylbls = new QString[NUMDAYS];
//events = new int[NUMDAYS];
mToolTip = new DynamicTip(this);
// set default values used for drawing the matrix
mDefaultBackColor = palette().active().base();
mDefaultTextColor = palette().active().foreground();
mDefaultTextColorShaded = getShadedColor(mDefaultTextColor);
mHolidayColorShaded = getShadedColor(KOPrefs::instance()->mHolidayColor);
mSelectedDaysColor = QColor("white");
mTodayMarginWidth = 2;
mSelEnd = mSelStart = NOSELECTION;
setAcceptDrops(true);
//setFont( QFont("Arial", 10) );
mUpdateTimer = new QTimer( this );
connect (mUpdateTimer ,SIGNAL(timeout()), this, SLOT ( updateViewTimed() ));
mRepaintTimer = new QTimer( this );
connect (mRepaintTimer ,SIGNAL(timeout()), this, SLOT ( repaintViewTimed() ));
mDayChanged = false;
updateView();
}
QString KODayMatrix::getWhatsThisText( QPoint p )
{
int tmp = getDayIndexFrom(p.x(), p.y());
if ( tmp < 0 || tmp > NUMDAYS-1 || !mCalendar )
return QString();
QDate mDate = days[tmp];
- QPtrList<Event> eventlist = mCalendar->events(mDate);
+ Q3PtrList<Event> eventlist = mCalendar->events(mDate);
Event *event;
QStringList mToolTip;
for(event=eventlist.first();event != 0;event=eventlist.next()) {
QString mToolTipText;
QString text;
int multiday = 0;// 1 = start, 2 = midddle, 3 = end day
if (event->isMultiDay()) {
QString prefix = "<->";multiday = 2;
QString time;
if ( event->doesRecur() ) {
if ( event->recursOn( mDate) ) {
prefix ="->" ;multiday = 1;
}
else {
int days = event->dtStart().date().daysTo ( event->dtEnd().date() );
if ( event->recursOn( mDate.addDays( -days)) ) {
prefix ="<-" ;multiday = 3;
}
}
} else {
if (mDate == event->dtStart().date()) {
prefix ="->" ;multiday = 1;
} else if (mDate == event->dtEnd().date()) {
prefix ="<-" ;multiday = 3;
@@ -184,64 +193,64 @@ QString KODayMatrix::getWhatsThisText( QPoint p )
else if ( mDate == event->dtEnd().date () )
time = KGlobal::locale()->formatTime(event->dtEnd().time())+" ";
}
text = time + event->summary();
mToolTipText += prefix + text;
} else {
if (event->doesFloat()) {
text = event->summary();
mToolTipText += text;
}
else {
text = KGlobal::locale()->formatTime(event->dtStart().time());
text += " " + event->summary();
mToolTipText += KGlobal::locale()->formatTime(event->dtStart().time()) +"-"+KGlobal::locale()->formatTime(event->dtEnd().time())+" " + event->summary();
}
}
if ( !event->location().isEmpty() )
mToolTipText += " (" + event->location() + ")";
//qDebug("TTT: %s ", mToolTipText.latin1());
mToolTip.append( deTag( mToolTipText ) );
}
mToolTip.sort();
if ( KOPrefs::instance()->mCurrentDisplayedView == VIEW_T_VIEW ) {
- QPtrList<Todo> todolist = mCalendar->todos(mDate);
+ Q3PtrList<Todo> todolist = mCalendar->todos(mDate);
Todo *todo;
for(todo=todolist.first();todo != 0;todo=todolist.next()) {
QString mToolTipText;
if ( !todo->doesFloat() )
mToolTipText += KGlobal::locale()->formatTime(todo->dtDue().time())+" ";
mToolTipText += todo->summary();
if ( !todo->location().isEmpty() )
mToolTipText += " (" + todo->location() + ")";
mToolTipText = deTag( mToolTipText);
mToolTipText = "<b>" + i18n("Todo: ") + "</b>"+ mToolTipText;
mToolTip.append( mToolTipText );
}
}
if (KOPrefs::instance()->mCurrentDisplayedView == VIEW_J_VIEW ) {
- QPtrList<Journal> j_list = mCalendar->journals4Date( mDate );
+ Q3PtrList<Journal> j_list = mCalendar->journals4Date( mDate );
Journal *j = j_list.first();
while ( j ) {
QString mToolTipText;
if ( !j->summary().isEmpty() ) {
mToolTipText = j->summary().left(30);
if ( j->summary().length() > 30 )
mToolTipText += " ...";
} else {
mToolTipText = j->description().left(25);
if ( j->description().length() > 25 )
mToolTipText += " ...";
mToolTipText = deTag( mToolTipText);
}
mToolTipText = "<b>" + i18n("Journal: ") + "</b>"+ mToolTipText;
mToolTip.append( mToolTipText );
j = j_list.next();
}
}
return "<b>"+KGlobal::locale()->formatDate(days[tmp]) + "</b><br>" + mToolTip.join("<br>");
}
QString KODayMatrix::deTag( QString mToolTipText )
{
@@ -420,49 +429,49 @@ void KODayMatrix::computeEvent(Event *event, int i )
if ( !holiStr.isEmpty() )
holiStr += "\n";
holiStr += i18n("Birthday") + ": "+event->summary();
if ( !event->location().isEmpty() )
holiStr += " (" + event->location() + ")";
bDays.setBit(i);
mHolidays[i] =holiStr ;
}
}
if ( KOPrefs::instance()->mCurrentDisplayedView != VIEW_J_VIEW )
eDays.setBit(i);
}
void KODayMatrix::updateViewTimed()
{
mUpdateTimer->stop();
if ( !mCalendar ) {
qDebug("NOT CAL ");
return;
}
#if 1
int i;
int timeSpan = NUMDAYS-1;
- QPtrList<Event> events = mCalendar->events();
+ Q3PtrList<Event> events = mCalendar->events();
Event *event;
QDateTime dt;
bool ok;
bDays.fill( false);
pDays.fill( false);
hDays.fill( false);
eDays.fill( false);
mHolidays.clear();
QDate mStartDate = days[0];
QDate endDate = mStartDate.addDays( timeSpan );
for( event = events.first(); event; event = events.next() ) { // for event
ushort recurType = event->doesRecur();
if ((recurType == Recurrence::rDaily && !KOPrefs::instance()->mDailyRecur) ||
(recurType == Recurrence::rWeekly && !KOPrefs::instance()->mWeeklyRecur)) {
continue;
}
if ( !KOPrefs::instance()->mLongAllday && event->doesFloat()&& event->isMultiDay() ) {
continue;
}
if ( event->doesRecur() ) {
bool last;
QDateTime incidenceStart = event->recurrence()->getPreviousDateTime( QDateTime( mStartDate ) , &last );
QDateTime incidenceEnd;
int eventlen = event->dtStart().date().daysTo ( event->dtEnd().date() );
@@ -505,98 +514,98 @@ void KODayMatrix::updateViewTimed()
int st = event->dtStart().date().daysTo( endDate );
if ( st >= 0 ) { // start before timeend
int end = mStartDate.daysTo( event->dtEnd().date() );
if ( end >= 0 ) { // end after timestart --- got one!
//normalize
st = timeSpan - st;
if ( st < 0 ) st = 0;
if ( end > timeSpan ) end = timeSpan;
int iii;
for ( iii = st;iii<= end;++iii)
computeEvent( event, iii );
}
}
}
}
int startDay = days[0].dayOfWeek(); // 1...7 7 = sunday
for(i = 0; i < NUMDAYS; i++) {
if ( ( (i+startDay) % 7 == 0 ) ) {
pDays.setBit(i);
}
}
if ( KOPrefs::instance()->mCurrentDisplayedView == VIEW_T_VIEW ) {
bDays.fill( false);
// insert due todos
- QPtrList<Todo> todos = mCalendar->todos( );
+ Q3PtrList<Todo> todos = mCalendar->todos( );
Todo *todo;
for(todo = todos.first(); todo; todo = todos.next()) {
//insertTodo( todo );
if ( todo->hasDueDate() ) {
int day = mStartDate.daysTo( todo->dtDue().date() );
if ( day >= 0 && day < timeSpan + 1) {
int i = day;
QString holiStr = mHolidays[i];
pDays.setBit(i);
if ( !holiStr.isEmpty() )
holiStr += "\n";
holiStr += i18n("Todo") + ": "+todo->summary();
if ( !todo->location().isEmpty() )
holiStr += " (" + todo->location() + ")";
bDays.setBit(i);
mHolidays[i] =holiStr ;
eDays.setBit(i);
}
}
}
}
if ( KOPrefs::instance()->mCurrentDisplayedView == VIEW_J_VIEW ) {
bDays.fill( false);
// insert due todos
- QPtrList<Journal> todos = mCalendar->journals( );
+ Q3PtrList<Journal> todos = mCalendar->journals( );
Journal *todo;
for(todo = todos.first(); todo; todo = todos.next()) {
int day = mStartDate.daysTo( todo->dtStart().date() );
if ( day >= 0 && day < timeSpan + 1) {
int i = day;
QString holiStr = mHolidays[i];
pDays.setBit(i);
if ( !holiStr.isEmpty() )
holiStr += "\n";
holiStr += i18n("Journal: ")+todo->summary().left(25);
if ( todo->summary().length() > 25 )
holiStr +="...";
bDays.setBit(i);
mHolidays[i] =holiStr ;
eDays.setBit(i);
}
}
}
#else
//qDebug("KODayMatrix::updateViewTimed ");
for(int i = 0; i < NUMDAYS; i++) {
// if events are set for the day then remember to draw it bold
- QPtrList<Event> eventlist = mCalendar->events(days[i]);
+ Q3PtrList<Event> eventlist = mCalendar->events(days[i]);
Event *event;
int numEvents = eventlist.count();
QString holiStr = "";
bDays.clearBit(i);
hDays.clearBit(i);
eDays.clearBit(i);
for(event=eventlist.first();event != 0;event=eventlist.next()) {
ushort recurType = event->recurrence()->doesRecur();
if ((recurType == Recurrence::rDaily && !KOPrefs::instance()->mDailyRecur) ||
(recurType == Recurrence::rWeekly && !KOPrefs::instance()->mWeeklyRecur)) {
numEvents--;
}
if ( event->isHoliday()) {
hDays.setBit(i);
if ( !holiStr.isEmpty() )
holiStr += "\n";
holiStr += event->summary();
if ( !event->location().isEmpty() )
holiStr += " (" + event->location() + ")";
}
if ( event->isBirthday()) {
if ( !holiStr.isEmpty() )
holiStr += "\n";
holiStr += i18n("Birthday") + ": "+event->summary();
@@ -654,49 +663,49 @@ void KODayMatrix::updateView(QDate actdate)
mDayChanged = true;
recalculateToday();
mRedrawNeeded = true;
}
//qDebug("restart Timer %d vis: %d", mDayChanged, isVisible() );
if ( !isVisible() ) {
mPendingUpdateBeforeRepaint = true;
} else {
#ifdef DESKTOP_VERSION
//mRepaintTimer->start( 100 );
//updateViewTimed();
mUpdateTimer->start( 50 );
#else
mRepaintTimer->start( 250 );
mUpdateTimer->start( 500 );
#endif
}
}
void KODayMatrix::updateEvents()
{
if ( !mCalendar ) return;
for( int i = 0; i < NUMDAYS; i++ ) {
// if events are set for the day then remember to draw it bold
- QPtrList<Event> eventlist = mCalendar->events( days[ i ] );
+ Q3PtrList<Event> eventlist = mCalendar->events( days[ i ] );
int numEvents = eventlist.count();
Event *event;
for( event = eventlist.first(); event != 0;event=eventlist.next()) {
ushort recurType = event->doesRecur();
if ( ( recurType == Recurrence::rDaily &&
!KOPrefs::instance()->mDailyRecur ) ||
( recurType == Recurrence::rWeekly &&
!KOPrefs::instance()->mWeeklyRecur ) ) {
numEvents--;
}
if ( !KOPrefs::instance()->mLongAllday && event->doesFloat()&& event->isMultiDay() ) {
numEvents--;
}
}
if ( numEvents )
eDays.setBit(i);
else
eDays.clearBit(i);
}
}
const QDate& KODayMatrix::getDate(int offset)
{
@@ -718,62 +727,62 @@ QString KODayMatrix::getHolidayLabel(int offset)
int KODayMatrix::getDayIndexFrom(int x, int y)
{
int colModulo = (width()-2) % 7;
int rowModulo = (height()-2) % 6;
#if 0
return 7*(y/daysize.height()) + (KOGlobals::self()->reverseLayout() ?
6 - x/daysize.width() : x/daysize.width());
#endif
int xVal = (x-colModulo/2-2)/daysize.width();
int yVal = (y-rowModulo/2-2)/daysize.height();
return 7*(yVal) + xVal;
}
// ----------------------------------------------------------------------------
// M O U S E E V E N T H A N D L I N G
// ----------------------------------------------------------------------------
void KODayMatrix::mousePressEvent (QMouseEvent* e)
{
- if ( e->button() == LeftButton )
+ if ( e->button() == Qt::LeftButton )
mouseDown = true;
mSelStart = getDayIndexFrom(e->x(), e->y());
if (mSelStart > NUMDAYS-1) mSelStart=NUMDAYS-1;
mSelInit = mSelStart;
mSelEnd = mSelStart;
mRedrawNeeded = true;
repaint(false);
}
void KODayMatrix::mouseReleaseEvent (QMouseEvent* e)
{
mRedrawNeeded = true;
- if ( e->button() == LeftButton )
+ if ( e->button() == Qt::LeftButton )
if ( ! mouseDown ) {
return;
}
else
mouseDown = false;
int tmp = getDayIndexFrom(e->x(), e->y());
if (tmp > NUMDAYS-1) tmp=NUMDAYS-1;
if (mSelInit > tmp) {
mSelEnd = mSelInit;
if (tmp != mSelStart) {
mSelStart = tmp;
repaint(false);
}
} else {
mSelStart = mSelInit;
//repaint only if selection has changed
if (tmp != mSelEnd) {
mSelEnd = tmp;
repaint(false);
}
}
@@ -1174,50 +1183,50 @@ void KODayMatrix::paintEvent(QPaintEvent * pevent)
//qDebug("add %d %d -- %d %d ", col, addCol, row, addRow);
++addCol;//++addCol;
if ( row == 0)
addRow = 1;
p.drawText(col*dwidth+addCol, row*dheight+addRow, dwidth, dheight,
Qt::AlignHCenter | Qt::AlignVCenter, daylbls[i]);
// reset color to actual color
if (pDays.testBit(i)) {
p.setPen(actcol);
}
// reset bold font to plain font
if ( eDays.testBit(i)) {
QFont myFont = font();
myFont.setBold(false);
p.setFont(myFont);
}
}
p.setPen(mDefaultTextColor);
p.drawRect(0, 0, width(), height());
} else {
//qDebug("NO redraw ");
}
- bitBlt (this, pevent->rect().topLeft(), &myPix , pevent->rect() ,CopyROP);
+ bitBlt (this, pevent->rect().topLeft(), &myPix , pevent->rect() ,QPainter::CompositionMode_Source);
mRedrawNeeded = false;
}
// ----------------------------------------------------------------------------
// R E SI Z E E V E N T H A N D L I N G
// ----------------------------------------------------------------------------
void KODayMatrix::resizeEvent(QResizeEvent * e)
{
QRect sz = frameRect();
daysize.setHeight(sz.height()*7 / NUMDAYS);
daysize.setWidth(sz.width() / 7);
- QFrame::resizeEvent( e );
+ Q3Frame::resizeEvent( e );
}
QSize KODayMatrix::sizeHint() const
{
QFontMetrics fm ( font() );
int wid = fm.width( "30") *7+3;
int hei = fm.height() * 6+3;
//qDebug("KODayMatrix::sizeHint()********************* %d %d", wid , hei);
return QSize ( wid, hei );
}