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
36 int currentEventIndex;
44 :
QWidget(parent), d( new Private() )
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);
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*)) );
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 )
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() )
197 if ( !
event->additionalText().isEmpty() )
200 d->ui.lblInfo->setText( text );
204 d->ui.lblInfo->clear();
207 d->ui.lblActions->setVisible( !
event->actions().isEmpty() );
208 if ( !
event->actions().isEmpty() )
214 while ( it.hasNext() )
220 d->ui.lblActions->setText( linkCode );
225 if ( sizeHintHeight() >
height() )
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
285 #include "infoeventwidget.moc"
void setSizeConstraint(SizeConstraint)
bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *method)
int toInt(bool *ok, int base) const
QString escape(const QString &plain)
QString fromLatin1(const char *str, int size)
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const