31 #include <KPIMIdentities/Identity>
32 #include <KPIMIdentities/IdentityManager>
34 #include <KontactInterface/Core>
35 #include <KontactInterface/Plugin>
36 #include <KontactInterface/Summary>
39 #include <KActionCollection>
40 #include <KCMultiDialog>
41 #include <KComponentData>
42 #include <KConfigGroup>
44 #include <KGlobalSettings>
47 #include <KParts/PartActivateEvent>
49 #include <QApplication>
51 #include <QHBoxLayout>
53 #include <QScrollArea>
55 #include <QVBoxLayout>
58 const KAboutData *aboutData,
QObject *parent )
59 : KParts::ReadOnlyPart( parent ), mCore( core ), mFrame( 0 ), mConfigAction( 0 )
61 setComponentData( KComponentData( aboutData ) );
67 setDate( QDate::currentDate() );
68 connect( mCore, SIGNAL(dayChanged(QDate)), SLOT(
setDate(QDate)) );
70 mConfigAction =
new KAction( KIcon( QLatin1String(
"configure") ), i18n(
"&Configure Summary View..." ),
this );
71 actionCollection()->addAction( QLatin1String(
"summaryview_configure"), mConfigAction );
72 connect( mConfigAction, SIGNAL(triggered(
bool)), SLOT(
slotConfigure()) );
73 mConfigAction->setHelpText( i18n(
"Configure the summary view" ) );
74 mConfigAction->setWhatsThis(
75 i18nc(
"@info:whatsthis",
76 "Choosing this will show a dialog where you can select which "
77 "summaries you want to see and also allow you to configure "
78 "the summaries to your liking." ) );
80 setXMLFile( QLatin1String(
"kontactsummary_part.rc") );
99 if ( event->activated() && (
event->part() == this ) ) {
103 KParts::ReadOnlyPart::partActivateEvent( event );
108 QMap<QString, KontactInterface::Summary*>::ConstIterator it;
109 QMap<QString, KontactInterface::Summary*>::ConstIterator end(mSummaries.constEnd());
110 for ( it = mSummaries.constBegin(); it != end; ++it ) {
111 it.value()->updateSummary(
false );
117 mMainWidget->setUpdatesEnabled(
false );
121 KPIMIdentities::IdentityManager idm(
true,
this );
122 const KPIMIdentities::Identity &
id = idm.defaultIdentity();
124 QString currentUser = i18n(
"Summary for %1",
id.fullName() );
125 mUsernameLabel->setText( QString::fromLatin1(
"<b>%1</b>" ).arg( currentUser ) );
130 connect( mFrame, SIGNAL(summaryWidgetDropped(
QWidget*,
QWidget*,
int)),
133 mMainLayout->insertWidget( 2, mFrame );
135 QStringList activeSummaries;
137 KConfig config( QLatin1String(
"kontact_summaryrc") );
138 KConfigGroup grp( &config, QString() );
139 if ( !grp.hasKey(
"ActiveSummaries" ) ) {
140 activeSummaries << QLatin1String(
"kontact_korganizerplugin");
141 activeSummaries << QLatin1String(
"kontact_todoplugin");
142 activeSummaries << QLatin1String(
"kontact_specialdatesplugin");
143 activeSummaries << QLatin1String(
"kontact_kmailplugin");
144 activeSummaries << QLatin1String(
"kontact_knotesplugin");
146 activeSummaries = grp.readEntry(
"ActiveSummaries", QStringList() );
150 QStringList loadedSummaries;
155 for ( ; it != end; ++it ) {
156 KontactInterface::Plugin *plugin = *it;
157 if ( !activeSummaries.contains( plugin->identifier() ) ) {
161 KontactInterface::Summary *summary = plugin->createSummaryWidget( mFrame );
163 if ( summary->summaryHeight() > 0 ) {
164 mSummaries.insert( plugin->identifier(), summary );
166 connect( summary, SIGNAL(message(QString)),
167 BroadcastStatus::instance(), SLOT(setStatusMsg(QString)) );
168 connect( summary, SIGNAL(summaryWidgetDropped(
QWidget*,
QWidget*,
int)),
171 if ( !mLeftColumnSummaries.contains( plugin->identifier() ) &&
172 !mRightColumnSummaries.contains( plugin->identifier() ) ) {
173 mLeftColumnSummaries.append( plugin->identifier() );
176 loadedSummaries.append( plugin->identifier() );
185 QStringList::Iterator strIt;
186 for ( strIt = mLeftColumnSummaries.begin(); strIt != mLeftColumnSummaries.end(); ++strIt ) {
187 if ( !loadedSummaries.contains( *strIt ) ) {
188 strIt = mLeftColumnSummaries.erase( strIt );
192 for ( strIt = mRightColumnSummaries.begin(); strIt != mRightColumnSummaries.end(); ++strIt ) {
193 if ( !loadedSummaries.contains( *strIt ) ) {
194 strIt = mRightColumnSummaries.erase( strIt );
202 vline->setFrameStyle( QFrame::VLine | QFrame::Plain );
204 QHBoxLayout *layout =
new QHBoxLayout( mFrame );
209 layout->insertSpacing( 0, margin );
210 mLeftColumn =
new QVBoxLayout();
211 layout->addLayout( mLeftColumn );
212 mLeftColumn->setSpacing( KDialog::spacingHint() );
213 layout->addWidget( vline );
214 mRightColumn =
new QVBoxLayout();
215 layout->addLayout( mRightColumn );
216 mRightColumn->setSpacing( KDialog::spacingHint() );
217 layout->insertSpacing( -1, margin );
219 QStringList::ConstIterator strIt;
220 QStringList::ConstIterator strEnd(mLeftColumnSummaries.constEnd());
221 for ( strIt = mLeftColumnSummaries.constBegin(); strIt != strEnd; ++strIt ) {
222 if ( mSummaries.contains( *strIt ) ) {
223 mLeftColumn->addWidget( mSummaries[ *strIt ] );
226 strEnd = mRightColumnSummaries.constEnd();
227 for ( strIt = mRightColumnSummaries.constBegin(); strIt != strEnd; ++strIt ) {
228 if ( mSummaries.contains( *strIt ) ) {
229 mRightColumn->addWidget( mSummaries[ *strIt ] );
233 QSpacerItem *lspacer =
new QSpacerItem( 1, 10,
234 QSizePolicy::MinimumExpanding,
235 QSizePolicy::MinimumExpanding );
236 QSpacerItem *rspacer =
new QSpacerItem( 1, 10,
237 QSizePolicy::MinimumExpanding,
238 QSizePolicy::MinimumExpanding );
239 mLeftColumn->addSpacerItem( lspacer );
240 mRightColumn->addSpacerItem( rspacer );
244 mMainWidget->setUpdatesEnabled(
true );
245 mMainWidget->update();
247 mLeftColumn->addStretch();
248 mRightColumn->addStretch();
253 if ( target == widget ) {
257 if ( target == mFrame ) {
258 if ( mLeftColumn->indexOf( widget ) == -1 && mRightColumn->indexOf( widget ) == -1 ) {
262 if ( ( mLeftColumn->indexOf( target ) == -1 && mRightColumn->indexOf( target ) == -1 ) ||
263 ( mLeftColumn->indexOf( widget ) == -1 && mRightColumn->indexOf( widget ) == -1 ) ) {
268 if ( !QApplication::isRightToLeft() ) {
269 drawLtoR( target, widget, alignment );
271 drawRtoL( target, widget, alignment );
275 void SummaryViewPart::drawLtoR(
QWidget *target,
QWidget *widget,
int alignment )
277 if ( mLeftColumn->indexOf( widget ) != -1 ) {
278 mLeftColumn->removeWidget( widget );
279 mLeftColumnSummaries.removeAll( widgetName( widget ) );
280 }
else if ( mRightColumn->indexOf( widget ) != -1 ) {
281 mRightColumn->removeWidget( widget );
282 mRightColumnSummaries.removeAll( widgetName( widget ) );
285 if ( target == mFrame ) {
288 if ( alignment & Qt::AlignTop ) {
292 if ( alignment & Qt::AlignLeft ) {
293 if ( alignment & Qt::AlignBottom ) {
294 pos = mLeftColumnSummaries.count();
297 mLeftColumn->insertWidget( pos, widget );
298 mLeftColumnSummaries.insert( pos, widgetName( widget ) );
300 if ( alignment & Qt::AlignBottom ) {
301 pos = mRightColumnSummaries.count();
304 mRightColumn->insertWidget( pos, widget );
305 mRightColumnSummaries.insert( pos, widgetName( widget ) );
308 mFrame->updateGeometry();
312 int targetPos = mLeftColumn->indexOf( target );
313 if ( targetPos != -1 ) {
314 if ( alignment == Qt::AlignBottom ) {
318 mLeftColumn->insertWidget( targetPos, widget );
319 mLeftColumnSummaries.insert( targetPos, widgetName( widget ) );
321 targetPos = mRightColumn->indexOf( target );
323 if ( alignment == Qt::AlignBottom ) {
327 mRightColumn->insertWidget( targetPos, widget );
328 mRightColumnSummaries.insert( targetPos, widgetName( widget ) );
330 mFrame->updateGeometry();
333 void SummaryViewPart::drawRtoL(
QWidget *target,
QWidget *widget,
int alignment )
335 if ( mRightColumn->indexOf( widget ) != -1 ) {
336 mRightColumn->removeWidget( widget );
337 mRightColumnSummaries.removeAll( widgetName( widget ) );
338 }
else if ( mLeftColumn->indexOf( widget ) != -1 ) {
339 mLeftColumn->removeWidget( widget );
340 mLeftColumnSummaries.removeAll( widgetName( widget ) );
343 if ( target == mFrame ) {
346 if ( alignment & Qt::AlignTop ) {
350 if ( alignment & Qt::AlignLeft ) {
351 if ( alignment & Qt::AlignBottom ) {
352 pos = mRightColumnSummaries.count();
355 mRightColumn->insertWidget( pos, widget );
356 mRightColumnSummaries.insert( pos, widgetName( widget ) );
358 if ( alignment & Qt::AlignBottom ) {
359 pos = mLeftColumnSummaries.count();
362 mLeftColumn->insertWidget( pos, widget );
363 mLeftColumnSummaries.insert( pos, widgetName( widget ) );
366 mFrame->updateGeometry();
370 int targetPos = mRightColumn->indexOf( target );
371 if ( targetPos != -1 ) {
372 if ( alignment == Qt::AlignBottom ) {
376 mRightColumn->insertWidget( targetPos, widget );
377 mRightColumnSummaries.insert( targetPos, widgetName( widget ) );
379 targetPos = mLeftColumn->indexOf( target );
381 if ( alignment == Qt::AlignBottom ) {
385 mLeftColumn->insertWidget( targetPos, widget );
386 mLeftColumnSummaries.insert( targetPos, widgetName( widget ) );
388 mFrame->updateGeometry();
398 if ( !QApplication::isRightToLeft() ) {
399 mMainWidget->setStyleSheet(
400 QLatin1String(
"#mMainWidget { "
401 " background: palette(base);"
402 " color: palette(text);"
403 " background-image: url(:/summaryview/kontact_bg.png);"
404 " background-position: bottom right;"
405 " background-repeat: no-repeat; }"
407 " color: palette(text); }"
409 " color: palette(link); }") );
411 mMainWidget->setStyleSheet(
412 QLatin1String(
"#mMainWidget { "
413 " background: palette(base);"
414 " color: palette(text);"
415 " background-image: url(:/summaryview/kontact_bg.png);"
416 " background-position: bottom left;"
417 " background-repeat: no-repeat; }"
419 " color: palette(text); }"
421 " color: palette(link); }") );
427 QString
date( QLatin1String(
"<b>%1</b>") );
428 date = date.arg( KGlobal::locale()->formatDate( newDate ) );
429 mDateLabel->setText( date );
434 KCMultiDialog dlg( mMainWidget );
435 dlg.setObjectName( QLatin1String(
"ConfigDialog") );
436 dlg.setModal(
true );
438 QStringList modules = configModules();
439 modules.prepend( QLatin1String(
"kcmkontactsummary.desktop") );
440 connect( &dlg, SIGNAL(configCommitted()),
443 QStringList::ConstIterator strIt;
444 QStringList::ConstIterator end(modules.constEnd());
445 for ( strIt = modules.constBegin(); strIt != end; ++strIt ) {
446 dlg.addModule( *strIt );
452 QStringList SummaryViewPart::configModules()
const
456 QMap<QString, KontactInterface::Summary*>::ConstIterator it;
457 QMap<QString, KontactInterface::Summary*>::ConstIterator end(mSummaries.constEnd());
458 for ( it = mSummaries.constBegin(); it != end; ++it ) {
459 QStringList cm = it.value()->configModules();
460 QStringList::ConstIterator strIt;
461 QStringList::ConstIterator strEnd(cm.constEnd());
462 for ( strIt = cm.constBegin(); strIt != strEnd; ++strIt ) {
463 if ( !(*strIt).isEmpty() && !modules.contains( *strIt ) ) {
464 modules.append( *strIt );
472 void SummaryViewPart::initGUI( KontactInterface::Core *core )
476 sa->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
477 sa->setFrameStyle( QFrame::StyledPanel | QFrame::Sunken );
478 sa->setWidgetResizable(
true );
481 mMainWidget->setObjectName( QLatin1String(
"mMainWidget") );
482 sa->setWidget( mMainWidget );
483 mMainWidget->setFocusPolicy( Qt::StrongFocus );
486 connect( KGlobalSettings::self(), SIGNAL(kdisplayPaletteChanged()), SLOT(
slotAdjustPalette()) );
489 mMainLayout =
new QVBoxLayout( mMainWidget );
490 mMainLayout->setSpacing( KDialog::spacingHint() );
491 mMainLayout->setMargin( KDialog::marginHint() );
493 QHBoxLayout *hbl =
new QHBoxLayout();
494 mMainLayout->addItem( hbl );
495 mUsernameLabel =
new QLabel( mMainWidget );
496 mDateLabel =
new QLabel( mMainWidget );
497 if ( !QApplication::isRightToLeft() ) {
498 mUsernameLabel->setAlignment( Qt::AlignLeft );
499 hbl->addWidget( mUsernameLabel );
500 mDateLabel->setAlignment( Qt::AlignRight );
501 hbl->addWidget( mDateLabel );
503 mDateLabel->setAlignment( Qt::AlignRight );
504 hbl->addWidget( mDateLabel );
505 mUsernameLabel->setAlignment( Qt::AlignLeft );
506 hbl->addWidget( mUsernameLabel );
510 hline->setFrameStyle( QFrame::HLine | QFrame::Plain );
511 mMainLayout->insertWidget( 1, hline );
514 mMainLayout->insertWidget( 2, mFrame );
516 connect( mFrame, SIGNAL(summaryWidgetDropped(
QWidget*,
QWidget*,
int)),
522 void SummaryViewPart::loadLayout()
524 KConfig config( QLatin1String(
"kontact_summaryrc") );
525 KConfigGroup grp( &config, QString() );
527 if ( !grp.hasKey(
"LeftColumnSummaries" ) ) {
528 mLeftColumnSummaries << QLatin1String(
"kontact_korganizerplugin");
529 mLeftColumnSummaries << QLatin1String(
"kontact_todoplugin");
530 mLeftColumnSummaries << QLatin1String(
"kontact_specialdatesplugin");
532 mLeftColumnSummaries = grp.readEntry(
"LeftColumnSummaries", QStringList() );
535 if ( !grp.hasKey(
"RightColumnSummaries" ) ) {
536 mRightColumnSummaries << QLatin1String(
"kontact_kmailplugin");
537 mRightColumnSummaries << QLatin1String(
"kontact_knotesplugin");
539 mRightColumnSummaries = grp.readEntry(
"RightColumnSummaries", QStringList() );
543 void SummaryViewPart::saveLayout()
545 KConfig config( QLatin1String(
"kontact_summaryrc") );
546 KConfigGroup grp( &config, QString() );
548 grp.writeEntry(
"LeftColumnSummaries", mLeftColumnSummaries );
549 grp.writeEntry(
"RightColumnSummaries", mRightColumnSummaries );
554 QString SummaryViewPart::widgetName(
QWidget *widget )
const
556 QMap<QString, KontactInterface::Summary*>::ConstIterator it;
557 QMap<QString, KontactInterface::Summary*>::ConstIterator end(mSummaries.constEnd());
558 for ( it = mSummaries.constBegin(); it != end; ++it ) {
559 if ( it.value() == widget ) {
567 #include "summaryview_part.moc"
SummaryViewPart(KontactInterface::Core *core, const char *widgetName, const KAboutData *aboutData, QObject *parent=0)
void textChanged(const QString &)
void setDate(const QDate &newDate)
virtual void partActivateEvent(KParts::PartActivateEvent *event)
void summaryWidgetMoved(QWidget *target, QWidget *widget, int alignment)