File r905628.diff of Package kdepim4
Subject: an attempt at fixing the dreaded crash in paintEvent().
From: wstephenson@suse.de
Bug:
Patch-upstream: 905628
--- korganizer/koagendaitem.h (revision 905627)
+++ korganizer/koagendaitem.h (revision 905628)
@@ -143,7 +143,7 @@ class KOAgendaItem : public QWidget, pub
bool dissociateFromMultiItem();
- bool setIncidence( Incidence *i );
+ void setIncidence( Incidence *incidence );
Incidence *incidence() const { return mIncidence; }
QDate itemDate() { return mDate; }
@@ -175,6 +175,7 @@ class KOAgendaItem : public QWidget, pub
void addAttendee( const QString & );
protected:
+ bool eventFilter( QObject *obj, QEvent *event );
bool event( QEvent *event );
void dragEnterEvent( QDragEnterEvent *e );
void dropEvent( QDropEvent *e );
@@ -221,6 +222,7 @@ class KOAgendaItem : public QWidget, pub
QColor mResourceColor;
private:
+ bool mValid;
bool mSelected;
QList<KOAgendaItem*> mConflictItems;
--- korganizer/koagenda.cpp (revision 905627)
+++ korganizer/koagenda.cpp (revision 905628)
@@ -1609,8 +1609,8 @@ void KOAgenda::setStartTime( const QTime
/*
Insert KOAgendaItem into agenda.
*/
-KOAgendaItem *KOAgenda::insertItem( Incidence *incidence, const QDate &qd, int X,
- int YTop, int YBottom )
+KOAgendaItem *KOAgenda::insertItem( Incidence *incidence, const QDate &qd,
+ int X, int YTop, int YBottom )
{
if ( mAllDayMode ) {
kDebug() << "using this in all-day mode is illegal.";
--- korganizer/koagendaitem.cpp (revision 905627)
+++ korganizer/koagendaitem.cpp (revision 905628)
@@ -76,13 +76,23 @@ QPixmap *KOAgendaItem::completedPxmp = 0
//-----------------------------------------------------------------------------
KOAgendaItem::KOAgendaItem( Incidence *incidence, const QDate &qd, QWidget *parent )
- : QWidget( parent ), mIncidence( incidence ), mDate( qd ),
- mLabelText( mIncidence->summary() ), mIconAlarm( false ),
- mIconRecur( false ), mIconReadonly( false ), mIconReply( false ),
- mIconGroup( false ), mIconGroupTent( false ), mIconOrganizer( false ),
- mMultiItemInfo( 0 ), mStartMoveInfo( 0 )
+ : QWidget( parent ), mIncidence( incidence ), mDate( qd ), mValid( true )
{
- kDebug() << "Incidence Type is " << mIncidence->type();
+ if ( !mIncidence ) {
+ mValid = false;
+ return;
+ }
+ mLabelText = mIncidence->summary();
+ mIconAlarm = false;
+ mIconRecur = false;
+ mIconReadonly = false;
+ mIconReply = false;
+ mIconGroup = false;
+ mIconGroupTent = false;
+ mIconOrganizer = false;
+ mMultiItemInfo = 0;
+ mStartMoveInfo = 0;
+
QPalette pal = palette();
pal.setColor( QPalette::Window, Qt::transparent );
setPalette( pal );
@@ -103,7 +113,7 @@ KOAgendaItem::KOAgendaItem( Incidence *i
void KOAgendaItem::updateIcons()
{
- if ( !mIncidence ) {
+ if ( !mValid ) {
return;
}
mIconReadonly = mIncidence->isReadOnly();
@@ -185,11 +195,14 @@ bool KOAgendaItem::dissociateFromMultiIt
return true;
}
-bool KOAgendaItem::setIncidence( Incidence *i )
+void KOAgendaItem::setIncidence( Incidence *incidence )
{
- mIncidence = i;
- updateIcons();
- return true;
+ mValid = false;
+ if ( incidence ) {
+ mValid = true;
+ mIncidence = incidence;
+ updateIcons();
+ }
}
/*
@@ -601,6 +614,10 @@ void KOAgendaItem::dragEnterEvent( QDrag
void KOAgendaItem::addAttendee( const QString &newAttendee )
{
+ if ( !mValid ) {
+ return;
+ }
+
QString name, email;
KPIMUtils::extractEmailAddressAndName( newAttendee, email, name );
if ( !( name.isEmpty() && email.isEmpty() ) ) {
@@ -620,11 +637,15 @@ void KOAgendaItem::dropEvent( QDropEvent
// otherwise check for attendees, then if the data is binary,
// add a binary attachment.
#ifndef KORG_NODND
+ if ( !mValid ) {
+ return;
+ }
+
const QMimeData *md = e->mimeData();
bool decoded = md->hasText();
QString text = md->text();
- if ( decoded && text.startsWith( "file:" ) ) {
+ if ( decoded && text.startsWith( QLatin1String( "file:" ) ) ) {
mIncidence->addAttachment( new Attachment( text ) );
return;
}
@@ -706,7 +727,7 @@ static void conditionalPaint( QPainter *
void KOAgendaItem::paintEventIcon( QPainter *p, int &x, int y, int ft )
{
- if ( !mIncidence ) {
+ if ( !mValid ) {
return;
}
conditionalPaint( p, mIncidence->type() == "Event", x, y, ft, *eventPxmp );
@@ -714,7 +735,7 @@ void KOAgendaItem::paintEventIcon( QPain
void KOAgendaItem::paintTodoIcon( QPainter *p, int &x, int y, int ft )
{
- if ( !mIncidence || mIncidence->type() != "Todo" ) {
+ if ( !mValid || mIncidence->type() != "Todo" ) {
return;
}
@@ -725,7 +746,7 @@ void KOAgendaItem::paintTodoIcon( QPaint
void KOAgendaItem::paintJournalIcon( QPainter *p, int &x, int y, int ft )
{
- if ( !mIncidence ) {
+ if ( !mValid ) {
return;
}
conditionalPaint( p, mIncidence->type() == "Journal", x, y, ft, *journalPxmp );
@@ -751,7 +772,7 @@ void KOAgendaItem::paintIcons( QPainter
void KOAgendaItem::paintEvent( QPaintEvent * )
{
- if ( !mIncidence ) {
+ if ( !mValid ) {
return;
}
@@ -1068,8 +1089,14 @@ void KOAgendaItem::paintEvent( QPaintEve
void KOAgendaItem::drawRoundedRect( QPainter *p, const QRect &rect,
bool selected, const QColor &bgColor,
- bool frame, int/*ft*/, bool roundTop, bool roundBottom )
+ bool frame, int ft, bool roundTop,
+ bool roundBottom )
{
+ Q_UNUSED( ft );
+ if ( !mValid ) {
+ return;
+ }
+
QRect r = rect;
r.adjust( 0, 0, 1, 1 );
@@ -1277,6 +1304,16 @@ void KOAgendaItem::drawRoundedRect( QPai
p->restore();
}
+bool KOAgendaItem::eventFilter( QObject *obj, QEvent *event )
+{
+ if ( event->type() == QEvent::Paint ) {
+ return mValid;
+ } else {
+ // standard event processing
+ return QObject::eventFilter( obj, event );
+ }
+}
+
bool KOAgendaItem::event( QEvent *event )
{
if ( event->type() == QEvent::ToolTip ) {
Index: korganizer/koagendaitem.h
===================================================================
Index: korganizer/koagenda.cpp
===================================================================
Index: korganizer/koagendaitem.cpp
===================================================================