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>
46 #include <KLocalizedString>
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 ) );
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." ) );
99 if ( event->activated() && (
event->part() == this ) ) {
103 KParts::ReadOnlyPart::partActivateEvent( event );
110 for ( it = mSummaries.
constBegin(); it != end; ++it ) {
111 it.
value()->updateSummary(
false );
121 KPIMIdentities::IdentityManager idm(
true,
this );
122 const KPIMIdentities::Identity &
id = idm.defaultIdentity();
124 QString currentUser = i18n(
"Summary for %1",
id.fullName() );
130 connect( mFrame, SIGNAL(summaryWidgetDropped(
QWidget*,
QWidget*,
int)),
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() );
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() );
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 );
212 mLeftColumn->
setSpacing( KDialog::spacingHint() );
216 mRightColumn->
setSpacing( KDialog::spacingHint() );
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 ] );
234 QSizePolicy::MinimumExpanding,
235 QSizePolicy::MinimumExpanding );
237 QSizePolicy::MinimumExpanding,
238 QSizePolicy::MinimumExpanding );
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 ) ) {
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 ) {
279 mLeftColumnSummaries.
removeAll( widgetName( widget ) );
280 }
else if ( mRightColumn->
indexOf( widget ) != -1 ) {
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();
298 mLeftColumnSummaries.
insert( pos, widgetName( widget ) );
300 if ( alignment & Qt::AlignBottom ) {
301 pos = mRightColumnSummaries.
count();
305 mRightColumnSummaries.
insert( pos, widgetName( widget ) );
312 int targetPos = mLeftColumn->
indexOf( target );
313 if ( targetPos != -1 ) {
314 if ( alignment == Qt::AlignBottom ) {
319 mLeftColumnSummaries.
insert( targetPos, widgetName( widget ) );
321 targetPos = mRightColumn->
indexOf( target );
323 if ( alignment == Qt::AlignBottom ) {
328 mRightColumnSummaries.
insert( targetPos, widgetName( widget ) );
333 void SummaryViewPart::drawRtoL(
QWidget *target,
QWidget *widget,
int alignment )
335 if ( mRightColumn->
indexOf( widget ) != -1 ) {
337 mRightColumnSummaries.
removeAll( widgetName( widget ) );
338 }
else if ( mLeftColumn->
indexOf( widget ) != -1 ) {
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();
356 mRightColumnSummaries.
insert( pos, widgetName( widget ) );
358 if ( alignment & Qt::AlignBottom ) {
359 pos = mLeftColumnSummaries.
count();
363 mLeftColumnSummaries.
insert( pos, widgetName( widget ) );
370 int targetPos = mRightColumn->
indexOf( target );
371 if ( targetPos != -1 ) {
372 if ( alignment == Qt::AlignBottom ) {
377 mRightColumnSummaries.
insert( targetPos, widgetName( widget ) );
379 targetPos = mLeftColumn->
indexOf( target );
381 if ( alignment == Qt::AlignBottom ) {
386 mLeftColumnSummaries.
insert( targetPos, widgetName( widget ) );
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); }") );
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); }") );
428 date = date.
arg( KGlobal::locale()->formatDate( newDate ) );
434 KCMultiDialog dlg( mMainWidget );
436 dlg.setModal(
true );
440 connect( &dlg, SIGNAL(configCommitted()),
445 for ( strIt = modules.
constBegin(); strIt != end; ++strIt ) {
446 dlg.addModule( *strIt );
458 for ( it = mSummaries.
constBegin(); it != end; ++it ) {
462 for ( strIt = cm.
constBegin(); strIt != strEnd; ++strIt ) {
463 if ( !(*strIt).isEmpty() && !modules.
contains( *strIt ) ) {
472 void SummaryViewPart::initGUI( KontactInterface::Core *core )
486 connect( KGlobalSettings::self(), SIGNAL(kdisplayPaletteChanged()), SLOT(
slotAdjustPalette()) );
490 mMainLayout->
setSpacing( KDialog::spacingHint() );
491 mMainLayout->
setMargin( KDialog::marginHint() );
495 mUsernameLabel =
new QLabel( mMainWidget );
496 mDateLabel =
new QLabel( mMainWidget );
516 connect( mFrame, SIGNAL(summaryWidgetDropped(
QWidget*,
QWidget*,
int)),
522 void SummaryViewPart::loadLayout()
525 KConfigGroup grp( &config,
QString() );
527 if ( !grp.hasKey(
"LeftColumnSummaries" ) ) {
528 mLeftColumnSummaries <<
QLatin1String(
"kontact_korganizerplugin");
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()
546 KConfigGroup grp( &config,
QString() );
548 grp.writeEntry(
"LeftColumnSummaries", mLeftColumnSummaries );
549 grp.writeEntry(
"RightColumnSummaries", mRightColumnSummaries );
558 for ( it = mSummaries.
constBegin(); it != end; ++it ) {
559 if ( it.
value() == widget ) {
SummaryViewPart(KontactInterface::Core *core, const char *widgetName, const KAboutData *aboutData, QObject *parent=0)
void insertSpacing(int index, int size)
bool contains(const Key &key) const
void addSpacerItem(QSpacerItem *spacerItem)
void textChanged(const QString &)
const_iterator constBegin() const
bool contains(const QString &str, Qt::CaseSensitivity cs) const
void setAlignment(QFlags< Qt::AlignmentFlag >)
iterator erase(iterator pos)
void setFrameStyle(int style)
virtual int indexOf(QWidget *widget) const
int count(const T &value) const
void append(const T &value)
virtual void addItem(QLayoutItem *item)
void setObjectName(const QString &name)
int removeAll(const T &value)
const_iterator constEnd() const
void setText(const QString &)
void setDate(const QDate &newDate)
void setMargin(int margin)
const Key key(const T &value) const
void addStretch(int stretch)
void insert(int i, const T &value)
virtual void partActivateEvent(KParts::PartActivateEvent *event)
QString fromLatin1(const char *str, int size)
void prepend(const T &value)
iterator insert(const Key &key, const T &value)
const_iterator constEnd() const
const_iterator constBegin() const
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
void setSpacing(int spacing)
void summaryWidgetMoved(QWidget *target, QWidget *widget, int alignment)
void addLayout(QLayout *layout, int stretch)
const T value(const Key &key) const