23 #include <QDataStream>
28 using namespace MessageList::Core;
63 : mType( type ), mFlags( 0 )
71 mCustomColor( src.mCustomColor )
80 return i18nc(
"Description of Type Subject",
"Subject" );
83 return i18nc(
"Description of Type Date",
"Date" );
85 case SenderOrReceiver:
86 return i18n(
"Sender/Receiver" );
89 return i18nc(
"Description of Type Sender",
"Sender" );
92 return i18nc(
"Description of Type Receiver",
"Receiver" );
95 return i18nc(
"Description of Type Size",
"Size" );
98 return i18n(
"Unread/Read Icon" );
100 case AttachmentStateIcon:
101 return i18n(
"Attachment Icon" );
103 case RepliedStateIcon:
104 return i18n(
"Replied/Forwarded Icon" );
106 case CombinedReadRepliedStateIcon:
107 return i18n(
"Combined New/Unread/Read/Replied/Forwarded Icon" );
109 case ActionItemStateIcon:
110 return i18n(
"Action Item Icon" );
112 case ImportantStateIcon:
113 return i18n(
"Important Icon" );
115 case GroupHeaderLabel:
116 return i18n(
"Group Header Label" );
118 case SpamHamStateIcon:
119 return i18n(
"Spam/Ham Icon" );
121 case WatchedIgnoredStateIcon:
122 return i18n(
"Watched/Ignored Icon" );
124 case ExpandedStateIcon:
125 return i18n(
"Group Header Expand/Collapse Icon" );
127 case EncryptionStateIcon:
128 return i18n(
"Encryption State Icon" );
130 case SignatureStateIcon:
131 return i18n(
"Signature State Icon" );
134 return i18n(
"Vertical Separation Line" );
136 case HorizontalSpacer:
137 return i18n(
"Horizontal Spacer" );
140 return i18n(
"Max Date" );
143 return i18n(
"Message Tags" );
146 return i18n(
"Note Icon" );
148 return i18n(
"Invitation Icon" );
150 return i18nc(
"Description for an Unknown Type",
"Unknown" );
158 return ( static_cast< int >( type ) & ApplicableToMessageItems );
163 return ( static_cast< int >( type ) & ApplicableToGroupHeaderItems );
169 mFontKey = font.key();
174 stream << (int)mType;
177 stream << mCustomColor;
185 mType =
static_cast< Type >( val );
190 case SenderOrReceiver:
195 case AttachmentStateIcon:
196 case RepliedStateIcon:
197 case GroupHeaderLabel:
198 case ActionItemStateIcon:
199 case ImportantStateIcon:
200 case SpamHamStateIcon:
201 case WatchedIgnoredStateIcon:
202 case ExpandedStateIcon:
203 case EncryptionStateIcon:
204 case SignatureStateIcon:
206 case HorizontalSpacer:
208 case CombinedReadRepliedStateIcon:
215 kDebug() <<
"Invalid content item type";
222 stream >> mCustomColor;
223 if ( mFlags & UseCustomColor )
225 if ( !mCustomColor.isValid() )
226 mFlags &= ~UseCustomColor;
240 QList< ContentItem * >::ConstIterator end( src.mLeftItems.constEnd() );
241 for ( QList< ContentItem * >::ConstIterator it = src.mLeftItems.constBegin(); it != end ; ++it )
244 end= src.mRightItems.constEnd();
245 for ( QList< ContentItem * >::ConstIterator it = src.mRightItems.constBegin(); it != end ; ++it )
252 removeAllLeftItems();
253 removeAllRightItems();
258 while( !mLeftItems.isEmpty() )
259 delete mLeftItems.takeFirst();
264 while( !mRightItems.isEmpty() )
265 delete mRightItems.takeFirst();
270 if ( idx >= mLeftItems.count() )
272 mLeftItems.append( item );
275 mLeftItems.insert( idx, item );
280 if ( idx >= mRightItems.count() )
282 mRightItems.append( item );
285 mRightItems.insert( idx, item );
290 QList< ContentItem * >::ConstIterator end( mLeftItems.constEnd() );
291 for ( QList< ContentItem * >::ConstIterator it = mLeftItems.constBegin(); it != end ; ++it )
293 if ( ( *it )->displaysText() )
296 end = mRightItems.constEnd();
297 for ( QList< ContentItem * >::ConstIterator it = mRightItems.constBegin(); it != end ; ++it )
299 if ( ( *it )->displaysText() )
307 stream << (int)mLeftItems.count();
309 int cnt = mLeftItems.count();
311 for (
int i = 0; i < cnt ; ++i )
317 stream << (int)mRightItems.count();
319 cnt = mRightItems.count();
321 for (
int i = 0; i < cnt ; ++i )
330 removeAllLeftItems();
331 removeAllRightItems();
339 if ( ( val < 0 ) || ( val > 50 ) )
344 for (
int i = 0; i < val ; ++i )
347 if ( !ci->
load( stream, themeVersion ) )
349 kDebug() <<
"Left content item loading failed";
361 kDebug() <<
"Old theme version detected, adding annotation item next to attachment icon.";
364 addLeftItem( annotationItem );
371 kDebug() <<
"Old theme version detected, adding invitation item next to attachment icon.";
374 addLeftItem( invitationItem );
382 if ( ( val < 0 ) || ( val > 50 ) )
385 for (
int i = 0; i < val ; ++i )
388 if ( !ci->
load( stream, themeVersion ) )
390 kDebug() <<
"Right content item loading failed";
398 kDebug() <<
"Old theme version detected, adding annotation item next to attachment icon.";
401 addRightItem( annotationItem );
406 kDebug() <<
"Old theme version detected, adding invitation item next to attachment icon.";
409 addRightItem( invitationItem );
418 : mReferences( 0 ), mCurrentlyVisible( currentlyVisible ), mCurrentWidth( currentWidth )
434 Q_ASSERT( mReferences >= 0 );
435 return mReferences > 0;
440 stream << mCurrentlyVisible;
441 stream << mCurrentWidth;
446 stream >> mCurrentlyVisible;
447 stream >> mCurrentWidth;
448 if ( mCurrentWidth > 10000 )
450 kDebug() <<
"Theme has insane column width " << mCurrentWidth <<
" chopping to 100";
453 return (mCurrentWidth >= -1);
458 : mVisibleByDefault( true ),
459 mIsSenderOrReceiver( false ),
460 mMessageSorting(
SortOrder::NoMessageSorting )
469 mPixmapName = src.mPixmapName;
470 mVisibleByDefault = src.mVisibleByDefault;
471 mIsSenderOrReceiver = src.mIsSenderOrReceiver;
472 mMessageSorting = src.mMessageSorting;
474 mSharedRuntimeData = src.mSharedRuntimeData;
476 QList< Row * >::ConstIterator end( src.mMessageRows.constEnd() );
477 for ( QList< Row * >::ConstIterator it = src.mMessageRows.constBegin(); it != end ; ++it )
478 addMessageRow(
new Row( *( *it ) ) );
480 end = src.mGroupHeaderRows.constEnd();
481 for ( QList< Row * >::ConstIterator it = src.mGroupHeaderRows.constBegin(); it != end ; ++it )
482 addGroupHeaderRow(
new Row( *( *it ) ) );
487 removeAllMessageRows();
488 removeAllGroupHeaderRows();
489 if( !( mSharedRuntimeData->deleteReference() ) )
490 delete mSharedRuntimeData;
495 if( mSharedRuntimeData->referenceCount() < 2 )
497 mSharedRuntimeData->deleteReference();
500 mSharedRuntimeData->addReference();
506 while ( !mMessageRows.isEmpty() )
507 delete mMessageRows.takeFirst();
512 while ( !mGroupHeaderRows.isEmpty() )
513 delete mGroupHeaderRows.takeFirst();
518 if ( idx >= mMessageRows.count() )
520 mMessageRows.append( row );
523 mMessageRows.insert( idx, row );
528 if ( idx >= mGroupHeaderRows.count() )
530 mGroupHeaderRows.append( row );
533 mGroupHeaderRows.insert( idx, row );
538 QList< Row * >::ConstIterator end( mMessageRows.constEnd() );
539 for ( QList< Row * >::ConstIterator it = mMessageRows.constBegin(); it != end ; ++it )
541 if ( ( *it )->containsTextItems() )
544 end = mGroupHeaderRows.constEnd();
545 for ( QList< Row * >::ConstIterator it = mGroupHeaderRows.constBegin(); it != end ; ++it )
547 if ( ( *it )->containsTextItems() )
556 stream << mPixmapName;
557 stream << mVisibleByDefault;
558 stream << mIsSenderOrReceiver;
559 stream << (int)mMessageSorting;
561 stream << (int)mGroupHeaderRows.count();
563 int cnt = mGroupHeaderRows.count();
565 for (
int i = 0; i < cnt ; ++i )
567 Row * row = mGroupHeaderRows.at( i );
571 cnt = mMessageRows.count();
574 for (
int i = 0; i < cnt ; ++i )
576 Row * row = mMessageRows.at( i );
581 mSharedRuntimeData->save( stream );
587 removeAllGroupHeaderRows();
588 removeAllMessageRows();
593 stream >> mPixmapName;
595 stream >> mVisibleByDefault;
596 stream >> mIsSenderOrReceiver;
604 kDebug() <<
"Invalid message sorting";
622 if ( ( val < 0 ) || ( val > 50 ) )
624 kDebug() <<
"Invalid group header row count";
628 for (
int i = 0; i < val ; ++i )
631 if ( !row->
load( stream, themeVersion ) )
633 kDebug() <<
"Group header row loading failed";
637 addGroupHeaderRow( row );
643 if ( ( val < 0 ) || ( val > 50 ) )
645 kDebug() <<
"Invalid message row count";
649 for (
int i = 0; i < val ; ++i )
652 if ( !row->
load( stream, themeVersion ) )
654 kDebug() <<
"Message row loading failed";
658 addMessageRow( row );
664 if( !mSharedRuntimeData->load( stream, themeVersion ) )
666 kDebug() <<
"Shared runtime data loading failed";
671 mSharedRuntimeData->setCurrentlyVisible( mVisibleByDefault );
672 mSharedRuntimeData->setCurrentWidth( -1 );
690 Theme::Theme(
const QString &name,
const QString &description,
bool readOnly )
691 :
OptionSet( name, description, readOnly )
703 mGroupHeaderBackgroundMode = src.mGroupHeaderBackgroundMode;
704 mGroupHeaderBackgroundColor = src.mGroupHeaderBackgroundColor;
705 mGroupHeaderBackgroundStyle = src.mGroupHeaderBackgroundStyle;
706 mViewHeaderPolicy = src.mViewHeaderPolicy;
707 mIconSize = src.mIconSize;
708 QList< Column * >::ConstIterator end( src.mColumns.constEnd() );
709 for ( QList< Column * >::ConstIterator it = src.mColumns.constBegin(); it != end ; ++it )
720 QList< Column * >::ConstIterator end( mColumns.constEnd() );
721 for ( QList< Column * >::ConstIterator it = mColumns.constBegin(); it != end ; ++it )
727 QList< Column * >::ConstIterator end( mColumns.constEnd() );
728 for ( QList< Column * >::ConstIterator it = mColumns.constBegin(); it != end ; ++it )
730 ( *it )->setCurrentlyVisible( ( *it )->visibleByDefault() );
731 ( *it )->setCurrentWidth( -1 );
737 QList< Column * >::ConstIterator end( mColumns.constEnd() );
738 for ( QList< Column * >::ConstIterator it = mColumns.constBegin(); it != end; ++it )
739 ( *it )->setCurrentWidth( -1 );
745 while ( !mColumns.isEmpty() )
746 delete mColumns.takeFirst();
751 if ( idx >= mColumns.count() )
753 mColumns.append( column );
756 mColumns.insert( idx, column );
761 if ( (newPosition >= mColumns.count()) || newPosition < 0 )
763 mColumns.move( idx, newPosition );
768 mGroupHeaderBackgroundMode = bm;
769 if ( ( bm ==
CustomColor ) && !mGroupHeaderBackgroundColor.isValid() )
770 mGroupHeaderBackgroundColor = QColor( 127, 127, 127 );
775 QList< QPair< QString, int > > ret;
776 ret.append( QPair< QString, int >( i18n(
"Never Show" ),
NeverShowHeader ) );
777 ret.append( QPair< QString, int >( i18n(
"Always Show" ),
ShowHeaderAlways ) );
783 QList< QPair< QString, int > > ret;
784 ret.append( QPair< QString, int >( i18n(
"Plain Rectangles" ),
PlainRect ) );
785 ret.append( QPair< QString, int >( i18n(
"Plain Joined Rectangle" ),
PlainJoinedRect ) );
786 ret.append( QPair< QString, int >( i18n(
"Rounded Rectangles" ),
RoundedRect ) );
787 ret.append( QPair< QString, int >( i18n(
"Rounded Joined Rectangle" ),
RoundedJoinedRect ) );
788 ret.append( QPair< QString, int >( i18n(
"Gradient Rectangles" ),
GradientRect ) );
789 ret.append( QPair< QString, int >( i18n(
"Gradient Joined Rectangle" ),
GradientJoinedRect ) );
790 ret.append( QPair< QString, int >( i18n(
"Styled Rectangles" ),
StyledRect ) );
791 ret.append( QPair< QString, int >( i18n(
"Styled Joined Rectangles" ),
StyledJoinedRect ) );
799 if ( ( mIconSize < 8 ) || ( mIconSize > 64 ) )
809 stream >> themeVersion;
818 kDebug() <<
"Invalid theme version";
826 switch(mGroupHeaderBackgroundMode)
834 kDebug() <<
"Invalid theme group header background mode";
839 stream >> mGroupHeaderBackgroundColor;
843 switch(mGroupHeaderBackgroundStyle)
856 kDebug() <<
"Invalid theme group header background style";
863 switch(mViewHeaderPolicy)
870 kDebug() <<
"Invalid theme view header policy";
879 if ( ( mIconSize < 8 ) || ( mIconSize > 64 ) )
887 if ( val < 1 || val > 50 )
890 for (
int i = 0; i < val ; ++i )
893 if ( !col->
load( stream, themeVersion ) )
895 kDebug() <<
"Column loading failed";
909 stream << (int)mGroupHeaderBackgroundMode;
910 stream << mGroupHeaderBackgroundColor;
911 stream << (int)mGroupHeaderBackgroundStyle;
912 stream << (int)mViewHeaderPolicy;
915 const int cnt = mColumns.count();
919 for (
int i = 0; i < cnt ; ++i )
921 Column * col = mColumns.at( i );
The ContentItem class defines a content item inside a Row.
bool load(QDataStream &stream, int themeVersion)
Handles row loading (used by Theme::Column::load())
Whether the message is an invitation.
static bool applicableToMessageItems(Type type)
Static test that returns true if an instance of ContentItem with the specified type makes sense in a ...
void removeAllColumns()
Removes all columns from this theme.
A class which holds information about sorting, e.g.
bool containsTextItems() const
Returns true if this column contains text items.
void removeAllLeftItems()
Removes all the left items from this row: the items are deleted.
A set of options that can be applied to the MessageList in one shot.
static bool isValidMessageSorting(SortOrder::MessageSorting ms)
Returns true if the ms parameter specifies a valid MessageSorting option.
static const int gThemeMinimumVersionWithColumnRuntimeData
void addReference()
Increments the reference count for this shared runtime data object.
static QString description(Type type)
Returns a descriptive name for the specified content item type.
void insertMessageRow(int idx, Row *row)
Inserts a message row to this theme column in the specified position.
void insertColumn(int idx, Column *column)
Inserts a column to this theme at the specified position.
The Row class defines a row of items inside a Column.
void moveColumn(int idx, int newPosition)
The icon that displays the atachment state (may be disabled)
bool load(QDataStream &stream, int themeVersion)
Handles column loading (used by Theme::load())
void removeAllMessageRows()
Removes all the message rows from this column.
static const int gThemeDefaultIconSize
void setGroupHeaderBackgroundMode(GroupHeaderBackgroundMode bm)
Sets the group header background mode for this theme.
static bool applicableToGroupHeaderItems(Type type)
Static test that returns true if an instance of ContentItem with the specified type makes sense in a ...
bool load(QDataStream &stream, int themeVersion)
Handles content item loading (used by Theme::Row::load())
Whether the message has a annotation/note.
void save(QDataStream &stream) const
Handles row saving (used by Theme::Column::save())
The Column class defines a view column available inside this theme.
One big styled rect per column.
int iconSize() const
Returns the currently set icon size.
void setFont(const QFont &font)
Sets the custom font to be used with this item.
static QList< QPair< QString, int > > enumerateGroupHeaderBackgroundStyles()
Enumerates the available group header background styles.
No background at all: use style default.
One plain rect per column.
One big rounded gradient rect for all the columns.
void removeAllRightItems()
Removes all the right items from this row.
Type type() const
Returns the type of this content item.
void save(QDataStream &stream) const
Handles content item saving (used by Theme::Row::save())
Display the subject of the message item.
void save(QDataStream &stream) const
Handles column saving (used by Theme::save())
bool deleteReference()
Decrements the reference count for this shared runtime data object.
MessageSorting
The available message sorting options.
static const int gThemeMinimumVersionWithColumnIcon
GroupHeaderBackgroundMode
Which color do we use to paint group header background ?
static const int gThemeMinimumVersionWithInvitationIcon
void resetColumnState()
Resets the column state (visibility and width) to their default values (the "visible by default" ones...
Column()
Create an empty column with default settings.
Type
The available ContentItem types.
bool containsTextItems() const
Returns true if this row contains text items.
static const int gThemeMinimumVersionWithSortingByUnreadStatusAllowed
static const int gThemeMinimumSupportedVersion
void resetColumnSizes()
Resets the column sizes to "default" (subset of resetColumnState() above).
Theme()
Creates a totally uninitialized theme object.
Don't sort the messages at all.
~Column()
Kill a column object.
void save(QDataStream &stream) const
Saves this runtime data to the specified stream.
One big rounded rect for all the columns.
One big plain rect for all the columns.
void setIconSize(int iconSize)
Sets the icon size for this theme.
static QList< QPair< QString, int > > enumerateViewHeaderPolicyOptions()
Enumerates the available view header policy options.
void insertGroupHeaderRow(int idx, Row *row)
Inserts a group header row to this theme column in the specified position.
GroupHeaderBackgroundStyle
How do we paint group header background ?
void detach()
Detaches the shared runtime data object and makes this object totally independent.
static const int gThemeCurrentVersion
static const int gThemeMinimumVersionWithIconSizeField
ContentItem(Type type)
Creates a ContentItem with the specified type.
Sort the messages by the "Unread" flags of status.
void insertLeftItem(int idx, ContentItem *item)
Adds a left aligned item at the specified position in this row.
void detach()
Detaches this object from the shared runtime data for columns.
The Theme class defines the visual appearance of the MessageList.
bool load(QDataStream &stream, int themeVersion)
Loads the shared runtime data from the specified stream assuming that it uses the specified theme ver...
virtual bool load(QDataStream &stream)
Pure virtual reimplemented from OptionSet.
SharedRuntimeData(bool currentlyVisible, int currentWidth)
Create a shared runtime data object.
virtual void save(QDataStream &stream) const
Pure virtual reimplemented from OptionSet.
void addColumn(Column *column)
Appends a column to this theme.
static const int gThemeMinimumVersionWithAnnotationIcon
Automatically determine the color (somewhere in the middle between background and text) ...
void removeAllGroupHeaderRows()
Removes all the group header rows from this column.
~Theme()
Destroys this theme object.
One rounded gradient filled rect per column.
~SharedRuntimeData()
Destroy a shared runtime data object.
void insertRightItem(int idx, ContentItem *item)
Adds a right aligned item at the specified position in this row.
void setHideWhenDisabled(bool hideWhenDisabled)
Sets the flag that causes this item to be hidden when disabled.
One styled rect per column.
A set of shared runtime data.
One rounded rect per column.
ViewHeaderPolicy
How do we manage the QHeaderView attacched to our View ?