17 #include "ui_infoeventbase.h"
23 #include <QTextDocument>
25 #include <knotification.h>
27 #include <kopeteinfoeventmanager.h>
28 #include <kopeteinfoevent.h>
29 #include <kopetestatusmanager.h>
30 #include <kopeteonlinestatusmanager.h>
32 class InfoEventWidget::Private
35 QPointer<Kopete::InfoEvent> currentEvent;
36 int currentEventIndex;
40 QHash<KNotification*, QPointer<Kopete::InfoEvent> > notifyEventHash;
44 :
QWidget(parent), d( new Private() )
46 d->timeline =
new QTimeLine( 150,
this );
47 d->timeline->setCurveShape( QTimeLine::EaseInOutCurve );
48 connect( d->timeline, SIGNAL(valueChanged(qreal)),
49 this, SLOT(slotAnimate(qreal)) );
52 static_cast<KSqueezedTextLabel*
>(d->ui.lblTitle)->setTextElideMode( Qt::ElideRight );
53 d->ui.buttonPrev->setIcon( KIcon(
"arrow-left" ) );
54 d->ui.buttonNext->setIcon( KIcon(
"arrow-right" ) );
55 d->ui.buttonClose->setIcon( KIcon(
"window-close" ) );
56 d->ui.lblInfo->setTextInteractionFlags(Qt::TextSelectableByMouse);
57 QWidget::setVisible(
false );
59 d->currentEventIndex = 0;
60 d->enableUpdates =
false;
61 connect( Kopete::InfoEventManager::self(), SIGNAL(changed()),
this, SLOT(updateInfo()) );
62 connect( Kopete::InfoEventManager::self(), SIGNAL(eventAdded(Kopete::InfoEvent*)),
this, SLOT(eventAdded(Kopete::InfoEvent*)) );
63 connect( d->ui.lblActions, SIGNAL(linkActivated(QString)),
this, SLOT(linkClicked(QString)) );
64 connect( d->ui.buttonPrev, SIGNAL(clicked(
bool)),
this, SLOT(
prevInfoEvent()) );
65 connect( d->ui.buttonNext, SIGNAL(clicked(
bool)),
this, SLOT(
nextInfoEvent()) );
66 connect( d->ui.buttonClose, SIGNAL(clicked(
bool)),
this, SLOT(
closeInfoEvent()) );
77 if ( visible == isVisible() )
80 d->enableUpdates = visible;
85 d->timeline->setDirection( visible ? QTimeLine::Forward
86 : QTimeLine::Backward );
92 if ( d->currentEventIndex > 0 )
94 d->currentEventIndex--;
101 if ( d->currentEventIndex + 1 < Kopete::InfoEventManager::self()->eventCount() )
103 d->currentEventIndex++;
110 Kopete::InfoEventManager* ie = Kopete::InfoEventManager::self();
111 if ( ie->eventCount() > 0 )
113 Kopete::InfoEvent*
event = ie->event( d->currentEventIndex );
119 if ( ie->eventCount() == 0 )
123 void InfoEventWidget::slotAnimate( qreal amount )
127 QWidget::setVisible(
false );
133 layout()->setSizeConstraint( QLayout::SetDefaultConstraint );
134 setFixedHeight( sizeHintHeight() );
138 setFixedHeight( sizeHintHeight() * amount );
141 QWidget::setVisible(
true );
144 void InfoEventWidget::linkClicked(
const QString& link )
146 Kopete::InfoEvent*
event = Kopete::InfoEventManager::self()->event( d->currentEventIndex );
149 event->activate( link.toInt() );
152 void InfoEventWidget::updateInfo()
154 if ( !d->enableUpdates )
157 Kopete::InfoEventManager* ie = Kopete::InfoEventManager::self();
159 if ( ie->eventCount() == 0 )
161 d->currentEventIndex = 0;
162 d->ui.lblInfo->clear();
163 d->ui.lblActions->clear();
165 static_cast<KSqueezedTextLabel*
>(d->ui.lblTitle)->setText(QString());
166 d->ui.lblEvent->setText(
"0/0" );
167 d->ui.buttonPrev->setEnabled(
false );
168 d->ui.buttonNext->setEnabled(
false );
172 if ( d->currentEventIndex >= ie->eventCount() )
173 d->currentEventIndex = ie->eventCount() - 1;
175 d->ui.buttonPrev->setEnabled( (d->currentEventIndex > 0) );
176 d->ui.buttonNext->setEnabled( (d->currentEventIndex + 1 < ie->eventCount()) );
178 Kopete::InfoEvent*
event = ie->event( d->currentEventIndex );
181 if ( d->currentEvent != event )
183 if ( !d->currentEvent )
184 disconnect( d->currentEvent, SIGNAL(changed()),
this , SLOT(updateInfo()) );
186 d->currentEvent = event;
187 connect( d->currentEvent, SIGNAL(changed()),
this , SLOT(updateInfo()) );
190 static_cast<KSqueezedTextLabel*
>(d->ui.lblTitle)->setText( Qt::escape( event->title() ) );
191 d->ui.lblEvent->setText( QString(
"%1/%2").arg( d->currentEventIndex + 1 ).arg( ie->eventCount() ) );
193 d->ui.lblInfo->setVisible( !event->text().isEmpty() );
194 if ( !event->text().isEmpty() )
196 QString text = QString(
"<p>%1</p>" ).arg( event->text() );
197 if ( !event->additionalText().isEmpty() )
198 text += QString(
"<p>%1</p>" ).arg( event->additionalText() );
200 d->ui.lblInfo->setText( text );
204 d->ui.lblInfo->clear();
207 d->ui.lblActions->setVisible( !event->actions().isEmpty() );
208 if ( !event->actions().isEmpty() )
210 QString linkCode = QString::fromLatin1(
"<p align=\"right\">" );
212 QMap<uint, QString> actions =
event->actions();
213 QMapIterator<uint, QString> it(actions);
214 while ( it.hasNext() )
217 linkCode += QString::fromLatin1(
"<a href=\"%1\">%2</a> " ).arg( it.key() ).arg( Qt::escape(it.value()) );
220 d->ui.lblActions->setText( linkCode );
224 layout()->activate();
225 if ( sizeHintHeight() > height() )
226 setFixedHeight( sizeHintHeight() );
229 void InfoEventWidget::eventAdded( Kopete::InfoEvent* event )
231 if ( Kopete::StatusManager::self()->globalStatusCategory() != Kopete::OnlineStatusManager::Busy )
233 KNotification *notify =
new KNotification( QString(
"kopete_info_event") , 0l );
234 notify->setActions( QStringList( i18n(
"View" ) ) );
235 notify->setText( event->text() );
237 d->notifyEventHash.insert( notify, event );
239 connect( notify, SIGNAL(activated(uint)),
this, SLOT(notificationActivated()) );
240 connect( notify, SIGNAL(closed()),
this, SLOT(notificationClosed()) );
245 if ( event->showOnSend() )
247 int index = Kopete::InfoEventManager::self()->events().indexOf( event );
250 d->currentEventIndex = index;
257 void InfoEventWidget::notificationActivated()
259 KNotification *notify =
dynamic_cast<KNotification *
>(sender());
261 Kopete::InfoEvent*
event = d->notifyEventHash.value( notify, 0 );
265 int index = Kopete::InfoEventManager::self()->events().indexOf( event );
268 d->currentEventIndex = index;
274 void InfoEventWidget::notificationClosed()
276 KNotification *notify =
dynamic_cast<KNotification *
>(sender());
277 d->notifyEventHash.remove( notify );
280 int InfoEventWidget::sizeHintHeight()
const
282 return qMin( sizeHint().height(), 250 );
285 #include "infoeventwidget.moc"