Messagelib

theme.h
1/******************************************************************************
2 *
3 * SPDX-FileCopyrightText: 2008 Szymon Tomasz Stefanek <pragma@kvirc.net>
4 *
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 *
7 *******************************************************************************/
8
9#pragma once
10
11#include <QColor>
12#include <QList>
13#include <QPair>
14#include <QString>
15
16#include "core/optionset.h"
17#include "core/sortorder.h"
18
19class QPixmap;
20
21namespace MessageList
22{
23namespace Core
24{
25/**
26 * The Theme class defines the visual appearance of the MessageList.
27 *
28 * The core structure of the theme is made up of Column objects which
29 * are mapped to View (QTreeView) columns. Each theme must provide at least one column.
30 *
31 * Each column contains a set of Row objects dedicated to message items
32 * and a set of Row objects dedicated to group header items. There must be at least
33 * one message row and one group header row in each column. Rows are visually
34 * ordered from top to bottom.
35 *
36 * Each Row contains a set of left aligned and a set of right aligned ContentItem objects.
37 * The right aligned items are painted from right to left while the left aligned
38 * ones are painted from left to right. In Right-To-Left mode the ThemeDelegate
39 * follows the exact opposite convention.
40 *
41 * Each ContentItem object specifies a visual element to be displayed in a View
42 * row. The visual elements may be pieces of text (Subject, Date) or icons.
43 *
44 * The Theme is designed to strictly interoperate with the ThemeDelegate class
45 * which takes care of rendering the contents when attached to an QAbstractItemView.
46 */
47class Theme : public OptionSet
48{
49public:
50 /**
51 * The ContentItem class defines a content item inside a Row.
52 * Content items are data items extracted from a message or a group header:
53 * they can be text, spacers, separators or icons.
54 */
56 {
57 private:
58 /**
59 * Bits for composing the Type enumeration members.
60 * We'll be able to test these bits to quickly figure out item properties.
61 */
62 enum TypePropertyBits {
63 /**
64 * Item can use the custom color property
65 */
66 CanUseCustomColor = (1 << 16),
67 /**
68 * Item can be in a disabled state (for example the attachment icon when there is no attachment)
69 */
70 CanBeDisabled = (1 << 17),
71 /**
72 * Item displays some sort of text
73 */
74 DisplaysText = (1 << 18),
75 /**
76 * Item makes sense (and can be applied) for messages
77 */
78 ApplicableToMessageItems = (1 << 19),
79 /**
80 * Item makes sense (and can be applied) for group headers
81 */
82 ApplicableToGroupHeaderItems = (1 << 20),
83 /**
84 * The item takes more horizontal space than the other text items (at the time of writing it's only the subject)
85 */
86 LongText = (1 << 21),
87 /**
88 * The item displays an icon
89 */
90 IsIcon = (1 << 22),
91 /**
92 * The item is a small spacer
93 */
94 IsSpacer = (1 << 23),
95 /**
96 * The item is clickable
97 */
98 IsClickable = (1 << 24)
99 };
100
101 public:
102 /**
103 * The available ContentItem types.
104 * Note that the values in this enum are unique values or'ed with the TypePropertyBits above.
105 */
106 enum Type {
107 /**
108 * Display the subject of the message item. This is a long text.
109 */
110 Subject = 1 | DisplaysText | CanUseCustomColor | ApplicableToMessageItems | LongText,
111 /**
112 * Formatted date time of the message/group
113 */
114 Date = 2 | DisplaysText | CanUseCustomColor | ApplicableToMessageItems | ApplicableToGroupHeaderItems,
115 /**
116 * From: or To: strip, depending on the folder settings
117 */
118 SenderOrReceiver = 3 | DisplaysText | CanUseCustomColor | ApplicableToMessageItems,
119 /**
120 * From: strip, always
121 */
122 Sender = 4 | DisplaysText | CanUseCustomColor | ApplicableToMessageItems,
123 /**
124 * To: strip, always
125 */
126 Receiver = 5 | DisplaysText | CanUseCustomColor | ApplicableToMessageItems,
127 /**
128 * Formatted size of the message
129 */
130 Size = 6 | DisplaysText | CanUseCustomColor | ApplicableToMessageItems,
131 /**
132 * The icon that displays the unread/read state (never disabled)
133 */
134 ReadStateIcon = 7 | ApplicableToMessageItems | IsIcon,
135 /**
136 * The icon that displays the attachment state (may be disabled)
137 */
138 AttachmentStateIcon = 8 | CanBeDisabled | ApplicableToMessageItems | IsIcon,
139 /**
140 * The icon that displays the replied/forwarded state (may be disabled)
141 */
142 RepliedStateIcon = 9 | CanBeDisabled | ApplicableToMessageItems | IsIcon,
143 /**
144 * The group header label
145 */
146 GroupHeaderLabel = 10 | DisplaysText | CanUseCustomColor | ApplicableToGroupHeaderItems,
147 /**
148 * The ActionItem state icon. May be disabled. Clickable (cycles todo->nothing)
149 */
150 ActionItemStateIcon = 11 | CanBeDisabled | ApplicableToMessageItems | IsIcon | IsClickable,
151 /**
152 * The Important tag icon. May be disabled. Clickable (cycles important->nothing)
153 */
154 ImportantStateIcon = 12 | CanBeDisabled | ApplicableToMessageItems | IsIcon | IsClickable,
155 /**
156 * The Spam/Ham state icon. May be disabled. Clickable (cycles spam->ham->nothing)
157 */
158 SpamHamStateIcon = 13 | CanBeDisabled | ApplicableToMessageItems | IsIcon | IsClickable,
159 /**
160 * The Watched/Ignored state icon. May be disabled. Clickable (cycles watched->ignored->nothing)
161 */
162 WatchedIgnoredStateIcon = 14 | CanBeDisabled | ApplicableToMessageItems | IsIcon | IsClickable,
163 /**
164 * The Expanded state icon for group headers. May be disabled. Clickable (expands/collapses the group)
165 */
166 ExpandedStateIcon = 15 | CanBeDisabled | ApplicableToGroupHeaderItems | IsIcon | IsClickable,
167 /**
168 * The Encryption state icon for messages. May be disabled (no encryption).
169 */
170 EncryptionStateIcon = 16 | CanBeDisabled | ApplicableToMessageItems | IsIcon,
171 /**
172 * The Signature state icon for messages. May be disabled (no signature)
173 */
174 SignatureStateIcon = 17 | CanBeDisabled | ApplicableToMessageItems | IsIcon,
175 /**
176 * A vertical separation line.
177 */
178 VerticalLine = 18 | CanUseCustomColor | ApplicableToMessageItems | ApplicableToGroupHeaderItems | IsSpacer,
179 /**
180 * A small empty spacer usable as separator.
181 */
182 HorizontalSpacer = 19 | ApplicableToMessageItems | ApplicableToGroupHeaderItems | IsSpacer,
183 /**
184 * The date of the most recent message in subtree
185 */
186 MostRecentDate = 20 | DisplaysText | CanUseCustomColor | ApplicableToMessageItems | ApplicableToGroupHeaderItems,
187 /**
188 * The combined icon that displays the unread/read/replied/forwarded state (never disabled)
189 */
190 CombinedReadRepliedStateIcon = 21 | ApplicableToMessageItems | IsIcon,
191 /**
192 * The list of MessageItem::Tag entries
193 */
194 TagList = 22 | ApplicableToMessageItems | IsIcon,
195 /**
196 * Whether the message is an invitation
197 */
198 InvitationIcon = 24 | ApplicableToMessageItems | IsIcon,
199 /**
200 * Folder of the message
201 */
202 Folder = 25 | DisplaysText | CanUseCustomColor | ApplicableToMessageItems
203#if 0
204 TotalMessageCount
205 UnreadMessageCount
206 NewMessageCount
207#endif
208 };
209
210 enum Flags {
211 HideWhenDisabled = 1, ///< In disabled state the icon should take no space (overrides SoftenByBlendingWhenDisabled)
212 SoftenByBlendingWhenDisabled = (1 << 1), ///< In disabled state the icon should be still shown, but made very soft by alpha blending
213 UseCustomColor = (1 << 2), ///< For text and vertical line. If set then always use a custom color, otherwise use default text color
214 IsBold = (1 << 3), ///< For text items. If set then always show as bold, otherwise use the default font weight
215 IsItalic = (1 << 4), ///< Fot text items. If set then always show as italic, otherwise use the default font style
216 SoftenByBlending = (1 << 5) ///< For text items: use 60% opacity.
217 };
218
219 private:
220 Type mType; ///< The type of item
221 unsigned int mFlags; ///< The flags of the item
222
223 QColor mCustomColor; ///< The color to use with this content item, meaningful only if canUseCustomColor() return true.
224
225 public:
226 /**
227 * Creates a ContentItem with the specified type.
228 * A content item must be added to a theme Row.
229 */
230 explicit ContentItem(Type type);
231 /**
232 * Creates a ContentItem that is a copy of the content item src.
233 * A content item must be added to a theme Row.
234 */
235 explicit ContentItem(const ContentItem &src);
236
237 public:
238 /**
239 * Returns the type of this content item
240 */
241 [[nodiscard]] Type type() const;
242
243 /**
244 * Returns true if this ContentItem can be in a "disabled" state.
245 * The attachment state icon, for example, can be disabled when the related
246 * message has no attachments. For such items the HideWhenDisabled
247 * and SoftenByBlendingWhenDisabled flags are meaningful.
248 */
249 [[nodiscard]] bool canBeDisabled() const;
250
251 /**
252 * Returns true if this ContentItem can make use of a custom color.
253 */
254 [[nodiscard]] bool canUseCustomColor() const;
255
256 /**
257 * Returns true if this item displays some kind of text.
258 * Items that display text make use of the customFont() setting.
259 */
260 [[nodiscard]] bool displaysText() const;
261
262 /**
263 * Returns true if this item displays a long text.
264 * The returned value makes sense only if displaysText() returned true.
265 */
266 [[nodiscard]] bool displaysLongText() const;
267
268 /**
269 * Returns true if this item displays an icon.
270 */
271 [[nodiscard]] bool isIcon() const;
272 /**
273 * Returns true if clicking on this kind of item can perform an action
274 */
275 [[nodiscard]] bool isClickable() const;
276
277 /**
278 * Returns true if this item is a small spacer
279 */
280 [[nodiscard]] bool isSpacer() const;
281
282 /**
283 * Static test that returns true if an instance of ContentItem with the
284 * specified type makes sense in a Row for message items.
285 */
286 [[nodiscard]] static bool applicableToMessageItems(Type type);
287
288 /**
289 * Static test that returns true if an instance of ContentItem with the
290 * specified type makes sense in a Row for group header items.
291 */
292 [[nodiscard]] static bool applicableToGroupHeaderItems(Type type);
293
294 /**
295 * Returns a descriptive name for the specified content item type
296 */
297 [[nodiscard]] static QString description(Type type);
298
299 /**
300 * Returns true if this item uses a custom color.
301 * The return value of this function is valid only if canUseCustomColor() returns true.
302 */
303 [[nodiscard]] bool useCustomColor() const;
304
305 /**
306 * Makes this item use the custom color that can be set by setCustomColor().
307 * The custom color is meaningful only if canUseCustomColor() returns true.
308 */
310
311 /**
312 * Returns true if this item uses a bold text.
313 * The return value of this function is valid only if displaysText() returns true.
314 */
315 [[nodiscard]] bool isBold() const;
316
317 /**
318 * Makes this item use a bold font.
319 */
320 void setBold(bool isBold);
321
322 /**
323 * Returns true if this item uses an italic text.
324 * The return value of this function is valid only if displaysText() returns true.
325 */
326 [[nodiscard]] bool isItalic() const;
327
328 /**
329 * Makes this item use italic font.
330 */
331 void setItalic(bool isItalic);
332
333 /**
334 * Returns true if this item should be hidden when in disabled state.
335 * Hidden content items simply aren't painted and take no space.
336 * This flag has meaning only on items for that canBeDisabled() returns true.
337 */
338 [[nodiscard]] bool hideWhenDisabled() const;
339
340 /**
341 * Sets the flag that causes this item to be hidden when disabled.
342 * Hidden content items simply aren't painted and take no space.
343 * This flag overrides the setSoftenByBlendingWhenDisabled() setting.
344 * This flag has meaning only on items for that canBeDisabled() returns true.
345 */
347
348 /**
349 * Returns true if this item should be painted in a "soft" fashion when
350 * in disabled state. Soft icons are painted with very low opacity.
351 * This flag has meaning only on items for that canBeDisabled() returns true.
352 */
353 [[nodiscard]] bool softenByBlendingWhenDisabled() const;
354
355 /**
356 * Sets the flag that causes this item to be painted "softly" when disabled.
357 * Soft icons are painted with very low opacity.
358 * This flag may be overridden by the setHideWhenDisabled() setting.
359 * This flag has meaning only on items for that canBeDisabled() returns true.
360 */
362
363 /**
364 * Returns true if this item should be always painted in a "soft" fashion.
365 * Meaningful only for text items.
366 */
367 [[nodiscard]] bool softenByBlending() const;
368
369 /**
370 * Sets the flag that causes this item to be painted "softly".
371 * Meaningful only for text items.
372 */
374
375 /**
376 * Returns the custom color set for this item.
377 * The return value is meaningful only if canUseCustomColor() returns true
378 * returns true and setUseCustomColor( true ) has been called.
379 */
380 [[nodiscard]] const QColor &customColor() const;
381
382 /**
383 * Sets the custom color for this item. Meaningful only if canUseCustomColor()
384 * returns true and you call setUseCustomColor( true )
385 */
386 void setCustomColor(const QColor &clr);
387
388 // Stuff used by ThemeDelegate. This section should be protected but some gcc
389 // versions seem to get confused with nested class and friend declarations
390 // so for portability we're using a public interface also here.
391
392 /**
393 * Handles content item saving (used by Theme::Row::save())
394 */
395 void save(QDataStream &stream) const;
396
397 /**
398 * Handles content item loading (used by Theme::Row::load())
399 */
400 bool load(QDataStream &stream, int themeVersion);
401 };
402
403 /**
404 * The Row class defines a row of items inside a Column.
405 * The Row has a list of left aligned and a list of right aligned ContentItems.
406 */
407 class Row
408 {
409 public:
410 explicit Row();
411 explicit Row(const Row &src);
412 ~Row();
413
414 private:
415 QList<ContentItem *> mLeftItems; ///< The list of left aligned items
416 QList<ContentItem *> mRightItems; ///< The list of right aligned items
417
418 bool LoadContentItem(int val, QDataStream &stream, int themeVersion, bool leftItem);
419
420 public:
421 /**
422 * Returns the list of left aligned items for this row
423 */
424 const QList<ContentItem *> &leftItems() const;
425
426 /**
427 * Removes all the left items from this row: the items are deleted.
428 */
429 void removeAllLeftItems();
430
431 /**
432 * Adds a left aligned item to this row. The row takes the ownership
433 * of the ContentItem pointer.
434 */
435 void addLeftItem(ContentItem *item);
436
437 /**
438 * Adds a left aligned item at the specified position in this row. The row takes the ownership
439 * of the ContentItem pointer.
440 */
441 void insertLeftItem(int idx, ContentItem *item);
442
443 /**
444 * Removes the specified left aligned content item from this row.
445 * The item is NOT deleted.
446 */
447 void removeLeftItem(ContentItem *item);
448
449 /**
450 * Returns the list of right aligned items for this row
451 */
452 const QList<ContentItem *> &rightItems() const;
453
454 /**
455 * Removes all the right items from this row. The items are deleted.
456 */
457 void removeAllRightItems();
458
459 /**
460 * Adds a right aligned item to this row. The row takes the ownership
461 * of the ContentItem pointer. Please note that the first right aligned item
462 * will start at the right edge, the second right aligned item will come after it etc...
463 */
464 void addRightItem(ContentItem *item);
465
466 /**
467 * Adds a right aligned item at the specified position in this row. The row takes the ownership
468 * of the ContentItem pointer. Remember that right item positions go from right to left.
469 */
470 void insertRightItem(int idx, ContentItem *item);
471
472 /**
473 * Removes the specified right aligned content item from this row.
474 * The item is NOT deleted.
475 */
476 void removeRightItem(ContentItem *item);
477
478 /**
479 * Returns true if this row contains text items.
480 * This is useful if you want to know if the column should just get
481 * its minimum allowable space or it should get more.
482 */
483 [[nodiscard]] bool containsTextItems() const;
484
485 /**
486 * Handles row saving (used by Theme::Column::save())
487 */
488 void save(QDataStream &stream) const;
489
490 /**
491 * Handles row loading (used by Theme::Column::load())
492 */
493 bool load(QDataStream &stream, int themeVersion);
494 };
495
496 /**
497 * The Column class defines a view column available inside this theme.
498 * Each Column has a list of Row items that define the visible rows.
499 */
500 class Column
501 {
502 public:
503 /**
504 * A set of shared runtime data. This is used to store a set of "override" settings
505 * at runtime. For instance, the width of the visible columns of a skin are stored here.
506 */
508 {
509 private:
510 int mReferences; ///< The number of external references to this shared data object
511
512 int mCurrentlyVisible; ///< Is this column currently visible ? always valid (eventually set from default)
513 double mCurrentWidth; ///< The current width of this column, -1 if not valid (never set)
514 public:
515 /**
516 * Create a shared runtime data object
517 */
518 explicit SharedRuntimeData(bool currentlyVisible, double currentWidth);
519
520 /**
521 * Destroy a shared runtime data object
522 */
524
525 public:
526 /**
527 * Increments the reference count for this shared runtime data object.
528 */
529 void addReference();
530
531 /**
532 * Decrements the reference count for this shared runtime data object.
533 * Returns true if there are other references and false otherwise (so the data can be safely deleted)
534 */
535 [[nodiscard]] bool deleteReference();
536
537 /**
538 * Returns the current number of reference counts, that is, the number of
539 * Theme::Column objects that use this SharedRuntimeData instance.
540 */
541 [[nodiscard]] int referenceCount() const;
542
543 /**
544 * Returns the current visibility state
545 */
546 [[nodiscard]] bool currentlyVisible() const;
547
548 /**
549 * Sets the current visibility state
550 */
551 void setCurrentlyVisible(bool visible);
552
553 /**
554 * Returns the current width or -1 if the width is unspecified/invalid
555 */
556 [[nodiscard]] double currentWidth() const;
557
558 /**
559 * Sets the current width of the column
560 */
561 void setCurrentWidth(double currentWidth);
562
563 /**
564 * Saves this runtime data to the specified stream
565 */
566 void save(QDataStream &stream) const;
567
568 /**
569 * Loads the shared runtime data from the specified stream
570 * assuming that it uses the specified theme version.
571 * Returns true on success and false if the data can't be loaded.
572 */
573 bool load(QDataStream &stream, int themeVersion);
574 };
575
576 public:
577 /**
578 * Create an empty column with default settings
579 */
580 explicit Column();
581 /**
582 * Create an exact copy of the column src.
583 * The shared runtime data is not copied (only a reference is added).
584 * If you need to create an independent clone then please use detach()
585 * after the construction.
586 */
587 explicit Column(const Column &src);
588 /**
589 * Kill a column object
590 */
591 ~Column();
592
593 private:
594 QString mLabel; ///< The label visible in the column header
595 QString mPixmapName; ///< The icon's name visible in the column header if it was set
596 bool mVisibleByDefault; ///< Is this column visible by default ?
597 bool mIsSenderOrReceiver; ///< If this column displays the sender/receiver field then we will update its label on the fly
598 SortOrder::MessageSorting mMessageSorting; ///< The message sort order we switch to when clicking on this column
599 QList<Row *> mGroupHeaderRows; ///< The list of rows we display in this column for a GroupHeaderItem
600 QList<Row *> mMessageRows; ///< The list of rows we display in this column for a MessageItem
601
602 SharedRuntimeData *mSharedRuntimeData = nullptr; ///< A pointer to the shared runtime data: shared between all instances of a theme with the same id
603 public:
604 /**
605 * Returns the label set for this column
606 */
607 [[nodiscard]] const QString &label() const;
608
609 /**
610 * Sets the label for this column
611 */
612 void setLabel(const QString &label);
613
614 /**
615 * Returns the icon's name (used in SmallIcon) set for this column
616 */
617 [[nodiscard]] const QString &pixmapName() const;
618
619 /**
620 * Sets the icon's name (used in SmallIcon) for this column
621 */
622 void setPixmapName(const QString &pixmapName);
623
624 /**
625 * Returns true if this column is marked as "sender/receiver" and we should
626 * update its label on-the-fly.
627 */
628 [[nodiscard]] bool isSenderOrReceiver() const;
629
630 /**
631 * Marks this column as containing the "sender/receiver" field.
632 * Such columns will have the label automatically updated.
633 */
634 void setIsSenderOrReceiver(bool sor);
635
636 /**
637 * Returns true if this column has to be shown by default
638 */
639 [[nodiscard]] bool visibleByDefault() const;
640
641 /**
642 * Sets the "visible by default" tag for this column.
643 */
644 void setVisibleByDefault(bool vbd);
645
646 /**
647 * Detaches the shared runtime data object and makes this object
648 * totally independent. The shared runtime data is initialized to default values.
649 */
650 void detach();
651
652 /**
653 * Returns the sort order for messages that we should switch to
654 * when clicking on this column's header (if visible at all).
655 */
656 [[nodiscard]] SortOrder::MessageSorting messageSorting() const;
657
658 /**
659 * Sets the sort order for messages that we should switch to
660 * when clicking on this column's header (if visible at all).
661 */
663
664 /**
665 * Returns the current shared visibility state for this column.
666 * This state is shared between all the instances of this theme.
667 */
668 [[nodiscard]] bool currentlyVisible() const;
669
670 /**
671 * Sets the current shared visibility state for this column.
672 * This state is shared between all the instances of this theme.
673 */
675
676 /**
677 * Returns the current shared width setting for this column
678 * or -1 if the width is not specified and should be auto-determined.
679 * This state is shared between all the instances of this theme.
680 */
681 [[nodiscard]] double currentWidth() const;
682
683 /**
684 * Sets the current shared width setting for this column.
685 * This state is shared between all the instances of this theme.
686 */
687 void setCurrentWidth(double currentWidth);
688
689 /**
690 * Returns the list of rows visible in this column for a MessageItem
691 */
692 [[nodiscard]] const QList<Row *> &messageRows() const;
693
694 /**
695 * Removes all the message rows from this column.
696 */
698
699 /**
700 * Appends a message row to this theme column. The Theme takes
701 * the ownership of the Row pointer.
702 */
703 void addMessageRow(Row *row);
704
705 /**
706 * Inserts a message row to this theme column in the specified position. The Theme takes
707 * the ownership of the Row pointer.
708 */
709 void insertMessageRow(int idx, Row *row);
710
711 /**
712 * Removes the specified message row. The row is NOT deleted.
713 */
714 void removeMessageRow(Row *row);
715
716 /**
717 * Returns the list of rows visible in this column for a GroupHeaderItem
718 */
719 [[nodiscard]] const QList<Row *> &groupHeaderRows() const;
720
721 /**
722 * Removes all the group header rows from this column.
723 */
725
726 /**
727 * Appends a group header row to this theme. The Theme takes
728 * the ownership of the Row pointer.
729 */
730 void addGroupHeaderRow(Row *row);
731
732 /**
733 * Inserts a group header row to this theme column in the specified position. The Theme takes
734 * the ownership of the Row pointer.
735 */
736 void insertGroupHeaderRow(int idx, Row *row);
737
738 /**
739 * Removes the specified group header row. The row is NOT deleted.
740 */
741 void removeGroupHeaderRow(Row *row);
742
743 /**
744 * Returns true if this column contains text items.
745 * This is useful if you want to know if the column should just get
746 * its minimum allowable space or it should get more.
747 */
748 [[nodiscard]] bool containsTextItems() const;
749
750 /**
751 * Handles column saving (used by Theme::save())
752 */
753 void save(QDataStream &stream) const;
754
755 /**
756 * Handles column loading (used by Theme::load())
757 */
758 bool load(QDataStream &stream, int themeVersion);
759 };
760
761public:
762 /**
763 * Creates a totally uninitialized theme object.
764 */
765 explicit Theme();
766
767 /**
768 * Creates a theme object with the specified name and description.
769 */
770 explicit Theme(const QString &name, const QString &description, bool readOnly = false);
771
772 /**
773 * Creates an exact copy of the theme sharing the same runtime data.
774 * If you need an exact clone please use detach() and generateUniqueId() just
775 * after creation.
776 */
777 explicit Theme(const Theme &src);
778
779 /**
780 * Destroys this theme object.
781 */
782 ~Theme() override;
783
784 static bool compareName(Theme *theme1, Theme *theme2)
785 {
786 return theme1->name() < theme2->name();
787 }
788
789public:
790 /**
791 * Which color do we use to paint group header background ?
792 */
794 Transparent, ///< No background at all: use style default
795 AutoColor, ///< Automatically determine the color (somewhere in the middle between background and text)
796 CustomColor, ///< Use a custom color
797 };
798
799 /**
800 * How do we paint group header background ?
801 */
803 PlainRect, ///< One plain rect per column
804 PlainJoinedRect, ///< One big plain rect for all the columns
805 RoundedRect, ///< One rounded rect per column
806 RoundedJoinedRect, ///< One big rounded rect for all the columns
807 GradientRect, ///< One rounded gradient filled rect per column
808 GradientJoinedRect, ///< One big rounded gradient rect for all the columns
809 StyledRect, ///< One styled rect per column
810 StyledJoinedRect, ///< One big styled rect per column
811 };
812
813 /**
814 * How do we manage the QHeaderView attached to our View ?
815 */
817 ShowHeaderAlways,
818 NeverShowHeader,
819 // ShowWhenMoreThanOneColumn, ///< This doesn't work at the moment (since without header we don't have means for showing columns back)
820 };
821
822 enum ThemeIcon {
823 IconNew,
824 IconUnread,
825 IconRead,
826 IconDeleted,
827 IconReplied,
828 IconRepliedAndForwarded,
829 IconQueued,
830 IconActionItem,
831 IconSent,
832 IconForwarded,
833 IconImportant,
834 IconWatched,
835 IconIgnored,
836 IconSpam,
837 IconHam,
838 IconFullySigned,
839 IconPartiallySigned,
840 IconUndefinedSigned,
841 IconNotSigned,
842 IconFullyEncrypted,
843 IconPartiallyEncrypted,
844 IconUndefinedEncrypted,
845 IconNotEncrypted,
846 IconAttachment,
847 IconAnnotation,
848 IconInvitation,
849 IconShowMore,
850 IconShowLess,
851 IconVerticalLine,
852 IconHorizontalSpacer,
853
854 _IconCount
855 };
856
857private:
858 QList<Column *> mColumns; ///< The list of columns available in this theme
859
860 // pixmaps cache. Mutable, so it can be lazily populated from const methods
861 mutable QList<QPixmap *> mPixmaps;
862
863 GroupHeaderBackgroundMode mGroupHeaderBackgroundMode; ///< How do we paint group header background ?
864 QColor mGroupHeaderBackgroundColor; ///< The background color of the message group, used only if CustomColor
865 GroupHeaderBackgroundStyle mGroupHeaderBackgroundStyle; ///< How do we paint group header background ?
866 ViewHeaderPolicy mViewHeaderPolicy; ///< Do we show the header or not ?
867 int mIconSize; ///< The icon size for this theme, 16 is the default
868public:
869 /**
870 * Detaches this object from the shared runtime data for columns.
871 */
872 void detach();
873
874 /**
875 * Resets the column state (visibility and width) to their default values (the "visible by default" ones).
876 */
877 void resetColumnState();
878
879 /**
880 * Resets the column sizes to "default" (subset of resetColumnState() above).
881 */
882 void resetColumnSizes();
883
884 /**
885 * Returns the list of columns available in this theme
886 */
887 [[nodiscard]] const QList<Column *> &columns() const;
888
889 /**
890 * Returns a pointer to the column at the specified index or 0 if there is no such column
891 */
892 Column *column(int idx) const;
893
894 void moveColumn(int idx, int newPosition);
895
896 /**
897 * Removes all columns from this theme
898 */
899 void removeAllColumns();
900
901 /**
902 * Appends a column to this theme
903 */
904 void addColumn(Column *column);
905
906 /**
907 * Inserts a column to this theme at the specified position.
908 */
909 void insertColumn(int idx, Column *column);
910
911 /**
912 * Removes the specified message row. The row is NOT deleted.
913 */
914 void removeColumn(Column *col);
915
916 /**
917 * Returns the group header background mode for this theme.
918 */
919 [[nodiscard]] GroupHeaderBackgroundMode groupHeaderBackgroundMode() const;
920
921 /**
922 * Sets the group header background mode for this theme.
923 * If you set it to CustomColor then please also setGroupHeaderBackgroundColor()
924 */
925 void setGroupHeaderBackgroundMode(GroupHeaderBackgroundMode bm);
926
927 /**
928 * Returns the group header background color for this theme.
929 * This color is used only if groupHeaderBackgroundMode() is set to CustomColor.
930 */
931 const QColor &groupHeaderBackgroundColor() const;
932
933 /**
934 * Sets the group header background color for this theme.
935 * This color is used only if groupHeaderBackgroundMode() is set to CustomColor.
936 */
937 void setGroupHeaderBackgroundColor(const QColor &clr);
938
939 /**
940 * Returns the group header background style for this theme.
941 * The group header background style makes sense only if groupHeaderBackgroundMode() is
942 * set to something different than Transparent.
943 */
944 [[nodiscard]] GroupHeaderBackgroundStyle groupHeaderBackgroundStyle() const;
945
946 /**
947 * Sets the group header background style for this theme.
948 * The group header background style makes sense only if groupHeaderBackgroundMode() is
949 * set to something different than Transparent.
950 */
951 void setGroupHeaderBackgroundStyle(GroupHeaderBackgroundStyle groupHeaderBackgroundStyle);
952
953 /**
954 * Enumerates the available group header background styles.
955 * The returned descriptors are pairs in that the first item is the localized description
956 * of the option value and the second item is the integer option value itself.
957 */
959
960 /**
961 * Returns the currently set ViewHeaderPolicy
962 */
963 [[nodiscard]] ViewHeaderPolicy viewHeaderPolicy() const;
964
965 /**
966 * Sets the ViewHeaderPolicy for this theme
967 */
968 void setViewHeaderPolicy(ViewHeaderPolicy vhp);
969
970 /**
971 * Returns the currently set icon size
972 */
973 [[nodiscard]] int iconSize() const;
974
975 /**
976 * Sets the icon size for this theme.
977 * Please note that the function will not let you set insane values.
978 * The allowable range is [8,64]
979 */
980 void setIconSize(int iconSize);
981
982 /**
983 * Enumerates the available view header policy options.
984 * The returned descriptors are pairs in that the first item is the localized description
985 * of the option value and the second item is the integer option value itself.
986 */
988
989 inline const QPixmap *pixmap(ThemeIcon icon) const
990 {
991 if (Q_UNLIKELY(mPixmaps.isEmpty())) {
992 populatePixmapCache();
993 }
994 return mPixmaps[icon];
995 }
996
997protected:
998 /**
999 * Pure virtual reimplemented from OptionSet.
1000 */
1001 void save(QDataStream &stream) const override;
1002
1003 /**
1004 * Pure virtual reimplemented from OptionSet.
1005 */
1006 bool load(QDataStream &stream) override;
1007
1008 void clearPixmapCache() const;
1009 void populatePixmapCache() const;
1010};
1011} // namespace Core
1012} // namespace MessageList
A set of options that can be applied to the MessageList in one shot.
Definition optionset.h:33
const QString & description() const
Returns a description of this option set.
Definition optionset.h:79
const QString & name() const
Returns the name of this OptionSet.
Definition optionset.h:59
MessageSorting
The available message sorting options.
Definition sortorder.h:60
double currentWidth() const
Returns the current width or -1 if the width is unspecified/invalid.
Definition theme.cpp:555
void setCurrentlyVisible(bool visible)
Sets the current visibility state.
Definition theme.cpp:550
void addReference()
Increments the reference count for this shared runtime data object.
Definition theme.cpp:528
int referenceCount() const
Returns the current number of reference counts, that is, the number of Theme::Column objects that use...
Definition theme.cpp:540
bool deleteReference()
Decrements the reference count for this shared runtime data object.
Definition theme.cpp:533
~SharedRuntimeData()
Destroy a shared runtime data object.
bool currentlyVisible() const
Returns the current visibility state.
Definition theme.cpp:545
void setCurrentWidth(double currentWidth)
Sets the current width of the column.
Definition theme.cpp:560
SharedRuntimeData(bool currentlyVisible, double currentWidth)
Create a shared runtime data object.
Definition theme.cpp:519
void save(QDataStream &stream) const
Saves this runtime data to the specified stream.
Definition theme.cpp:565
bool load(QDataStream &stream, int themeVersion)
Loads the shared runtime data from the specified stream assuming that it uses the specified theme ver...
Definition theme.cpp:571
The Column class defines a view column available inside this theme.
Definition theme.h:501
bool isSenderOrReceiver() const
Returns true if this column is marked as "sender/receiver" and we should update its label on-the-fly.
Definition theme.cpp:639
void removeGroupHeaderRow(Row *row)
Removes the specified group header row.
Definition theme.cpp:757
void removeMessageRow(Row *row)
Removes the specified message row.
Definition theme.cpp:738
void setPixmapName(const QString &pixmapName)
Sets the icon's name (used in SmallIcon) for this column.
Definition theme.cpp:634
double currentWidth() const
Returns the current shared width setting for this column or -1 if the width is not specified and shou...
Definition theme.cpp:690
const QList< Row * > & groupHeaderRows() const
Returns the list of rows visible in this column for a GroupHeaderItem.
Definition theme.cpp:743
void save(QDataStream &stream) const
Handles column saving (used by Theme::save())
Definition theme.cpp:777
void detach()
Detaches the shared runtime data object and makes this object totally independent.
Definition theme.cpp:659
void insertMessageRow(int idx, Row *row)
Inserts a message row to this theme column in the specified position.
Definition theme.cpp:729
SortOrder::MessageSorting messageSorting() const
Returns the sort order for messages that we should switch to when clicking on this column's header (i...
Definition theme.cpp:670
bool visibleByDefault() const
Returns true if this column has to be shown by default.
Definition theme.cpp:649
void setMessageSorting(SortOrder::MessageSorting ms)
Sets the sort order for messages that we should switch to when clicking on this column's header (if v...
Definition theme.cpp:675
void setVisibleByDefault(bool vbd)
Sets the "visible by default" tag for this column.
Definition theme.cpp:654
void setIsSenderOrReceiver(bool sor)
Marks this column as containing the "sender/receiver" field.
Definition theme.cpp:644
void addGroupHeaderRow(Row *row)
Appends a group header row to this theme.
Definition theme.cpp:724
void setCurrentWidth(double currentWidth)
Sets the current shared width setting for this column.
Definition theme.cpp:695
Column()
Create an empty column with default settings.
Definition theme.cpp:582
const QList< Row * > & messageRows() const
Returns the list of rows visible in this column for a MessageItem.
Definition theme.cpp:700
bool currentlyVisible() const
Returns the current shared visibility state for this column.
Definition theme.cpp:680
const QString & pixmapName() const
Returns the icon's name (used in SmallIcon) set for this column.
Definition theme.cpp:629
void setLabel(const QString &label)
Sets the label for this column.
Definition theme.cpp:624
void setCurrentlyVisible(bool currentlyVisible)
Sets the current shared visibility state for this column.
Definition theme.cpp:685
void insertGroupHeaderRow(int idx, Row *row)
Inserts a group header row to this theme column in the specified position.
Definition theme.cpp:748
const QString & label() const
Returns the label set for this column.
Definition theme.cpp:619
void removeAllGroupHeaderRows()
Removes all the group header rows from this column.
Definition theme.cpp:717
bool containsTextItems() const
Returns true if this column contains text items.
Definition theme.cpp:762
void removeAllMessageRows()
Removes all the message rows from this column.
Definition theme.cpp:705
~Column()
Kill a column object.
Definition theme.cpp:610
bool load(QDataStream &stream, int themeVersion)
Handles column loading (used by Theme::load())
Definition theme.cpp:806
void addMessageRow(Row *row)
Appends a message row to this theme column.
Definition theme.cpp:712
The ContentItem class defines a content item inside a Row.
Definition theme.h:56
bool displaysText() const
Returns true if this item displays some kind of text.
Definition theme.cpp:77
bool canBeDisabled() const
Returns true if this ContentItem can be in a "disabled" state.
Definition theme.cpp:67
void setSoftenByBlending(bool softenByBlending)
Sets the flag that causes this item to be painted "softly".
Definition theme.cpp:256
bool hideWhenDisabled() const
Returns true if this item should be hidden when in disabled state.
Definition theme.cpp:223
void setBold(bool isBold)
Makes this item use a bold font.
Definition theme.cpp:200
void setUseCustomColor(bool useCustomColor)
Makes this item use the custom color that can be set by setCustomColor().
Definition theme.cpp:186
static bool applicableToMessageItems(Type type)
Static test that returns true if an instance of ContentItem with the specified type makes sense in a ...
Definition theme.cpp:275
bool isSpacer() const
Returns true if this item is a small spacer.
Definition theme.cpp:97
void setSoftenByBlendingWhenDisabled(bool softenByBlendingWhenDisabled)
Sets the flag that causes this item to be painted "softly" when disabled.
Definition theme.cpp:242
bool isBold() const
Returns true if this item uses a bold text.
Definition theme.cpp:195
void setItalic(bool isItalic)
Makes this item use italic font.
Definition theme.cpp:214
void setCustomColor(const QColor &clr)
Sets the custom color for this item.
Definition theme.cpp:270
@ SoftenByBlending
For text items: use 60% opacity.
Definition theme.h:216
@ HideWhenDisabled
In disabled state the icon should take no space (overrides SoftenByBlendingWhenDisabled)
Definition theme.h:211
@ SoftenByBlendingWhenDisabled
In disabled state the icon should be still shown, but made very soft by alpha blending.
Definition theme.h:212
@ UseCustomColor
For text and vertical line. If set then always use a custom color, otherwise use default text color.
Definition theme.h:213
@ IsItalic
Fot text items. If set then always show as italic, otherwise use the default font style.
Definition theme.h:215
@ IsBold
For text items. If set then always show as bold, otherwise use the default font weight.
Definition theme.h:214
Type type() const
Returns the type of this content item.
Definition theme.cpp:62
bool canUseCustomColor() const
Returns true if this ContentItem can make use of a custom color.
Definition theme.cpp:72
bool useCustomColor() const
Returns true if this item uses a custom color.
Definition theme.cpp:181
void save(QDataStream &stream) const
Handles content item saving (used by Theme::Row::save())
Definition theme.cpp:285
bool isIcon() const
Returns true if this item displays an icon.
Definition theme.cpp:87
bool softenByBlending() const
Returns true if this item should be always painted in a "soft" fashion.
Definition theme.cpp:251
bool softenByBlendingWhenDisabled() const
Returns true if this item should be painted in a "soft" fashion when in disabled state.
Definition theme.cpp:237
bool load(QDataStream &stream, int themeVersion)
Handles content item loading (used by Theme::Row::load())
Definition theme.cpp:292
bool isClickable() const
Returns true if clicking on this kind of item can perform an action.
Definition theme.cpp:92
Type
The available ContentItem types.
Definition theme.h:106
@ InvitationIcon
Whether the message is an invitation.
Definition theme.h:198
@ CombinedReadRepliedStateIcon
The combined icon that displays the unread/read/replied/forwarded state (never disabled)
Definition theme.h:190
@ SignatureStateIcon
The Signature state icon for messages.
Definition theme.h:174
@ Date
Formatted date time of the message/group.
Definition theme.h:114
@ MostRecentDate
The date of the most recent message in subtree.
Definition theme.h:186
@ ReadStateIcon
The icon that displays the unread/read state (never disabled)
Definition theme.h:134
@ RepliedStateIcon
The icon that displays the replied/forwarded state (may be disabled)
Definition theme.h:142
@ WatchedIgnoredStateIcon
The Watched/Ignored state icon.
Definition theme.h:162
@ ImportantStateIcon
The Important tag icon.
Definition theme.h:154
@ Folder
Folder of the message.
Definition theme.h:202
@ AttachmentStateIcon
The icon that displays the attachment state (may be disabled)
Definition theme.h:138
@ ExpandedStateIcon
The Expanded state icon for group headers.
Definition theme.h:166
@ SenderOrReceiver
From: or To: strip, depending on the folder settings.
Definition theme.h:118
@ GroupHeaderLabel
The group header label.
Definition theme.h:146
@ Subject
Display the subject of the message item.
Definition theme.h:110
@ VerticalLine
A vertical separation line.
Definition theme.h:178
@ HorizontalSpacer
A small empty spacer usable as separator.
Definition theme.h:182
@ EncryptionStateIcon
The Encryption state icon for messages.
Definition theme.h:170
@ Size
Formatted size of the message.
Definition theme.h:130
@ Receiver
To: strip, always.
Definition theme.h:126
@ ActionItemStateIcon
The ActionItem state icon.
Definition theme.h:150
@ Sender
From: strip, always.
Definition theme.h:122
@ SpamHamStateIcon
The Spam/Ham state icon.
Definition theme.h:158
ContentItem(const ContentItem &src)
Creates a ContentItem that is a copy of the content item src.
void setHideWhenDisabled(bool hideWhenDisabled)
Sets the flag that causes this item to be hidden when disabled.
Definition theme.cpp:228
const QColor & customColor() const
Returns the custom color set for this item.
Definition theme.cpp:265
bool displaysLongText() const
Returns true if this item displays a long text.
Definition theme.cpp:82
ContentItem(Type type)
Creates a ContentItem with the specified type.
Definition theme.cpp:52
static bool applicableToGroupHeaderItems(Type type)
Static test that returns true if an instance of ContentItem with the specified type makes sense in a ...
Definition theme.cpp:280
bool isItalic() const
Returns true if this item uses an italic text.
Definition theme.cpp:209
The Row class defines a row of items inside a Column.
Definition theme.h:408
void removeLeftItem(ContentItem *item)
Removes the specified left aligned content item from this row.
Definition theme.cpp:393
void addRightItem(ContentItem *item)
Adds a right aligned item to this row.
Definition theme.cpp:379
void insertRightItem(int idx, ContentItem *item)
Adds a right aligned item at the specified position in this row.
Definition theme.cpp:403
bool containsTextItems() const
Returns true if this row contains text items.
Definition theme.cpp:417
void removeAllLeftItems()
Removes all the left items from this row: the items are deleted.
Definition theme.cpp:360
bool load(QDataStream &stream, int themeVersion)
Handles row loading (used by Theme::Column::load())
Definition theme.cpp:494
void insertLeftItem(int idx, ContentItem *item)
Adds a left aligned item at the specified position in this row.
Definition theme.cpp:384
void removeAllRightItems()
Removes all the right items from this row.
Definition theme.cpp:372
void removeRightItem(ContentItem *item)
Removes the specified right aligned content item from this row.
Definition theme.cpp:412
void save(QDataStream &stream) const
Handles row saving (used by Theme::Column::save())
Definition theme.cpp:432
void addLeftItem(ContentItem *item)
Adds a left aligned item to this row.
Definition theme.cpp:367
const QList< ContentItem * > & rightItems() const
Returns the list of right aligned items for this row.
Definition theme.cpp:398
const QList< ContentItem * > & leftItems() const
Returns the list of left aligned items for this row.
Definition theme.cpp:489
The Theme class defines the visual appearance of the MessageList.
Definition theme.h:48
GroupHeaderBackgroundMode
Which color do we use to paint group header background ?
Definition theme.h:793
@ Transparent
No background at all: use style default.
Definition theme.h:794
@ CustomColor
Use a custom color.
Definition theme.h:796
@ AutoColor
Automatically determine the color (somewhere in the middle between background and text)
Definition theme.h:795
void setGroupHeaderBackgroundStyle(GroupHeaderBackgroundStyle groupHeaderBackgroundStyle)
Sets the group header background style for this theme.
Definition theme.cpp:1022
void setGroupHeaderBackgroundColor(const QColor &clr)
Sets the group header background color for this theme.
Definition theme.cpp:1012
void setViewHeaderPolicy(ViewHeaderPolicy vhp)
Sets the ViewHeaderPolicy for this theme.
Definition theme.cpp:1049
ViewHeaderPolicy
How do we manage the QHeaderView attached to our View ?
Definition theme.h:816
void removeColumn(Column *col)
Removes the specified message row.
Definition theme.cpp:981
void setGroupHeaderBackgroundMode(GroupHeaderBackgroundMode bm)
Sets the group header background mode for this theme.
Definition theme.cpp:999
void setIconSize(int iconSize)
Sets the icon size for this theme.
Definition theme.cpp:1059
void detach()
Detaches this object from the shared runtime data for columns.
Definition theme.cpp:928
const QColor & groupHeaderBackgroundColor() const
Returns the group header background color for this theme.
Definition theme.cpp:1007
static QList< QPair< QString, int > > enumerateGroupHeaderBackgroundStyles()
Enumerates the available group header background styles.
Definition theme.cpp:1032
~Theme() override
Destroys this theme object.
Definition theme.cpp:922
Theme()
Creates a totally uninitialized theme object.
Definition theme.cpp:891
GroupHeaderBackgroundMode groupHeaderBackgroundMode() const
Returns the group header background mode for this theme.
Definition theme.cpp:986
void addColumn(Column *column)
Appends a column to this theme.
Definition theme.cpp:967
void insertColumn(int idx, Column *column)
Inserts a column to this theme at the specified position.
Definition theme.cpp:972
ViewHeaderPolicy viewHeaderPolicy() const
Returns the currently set ViewHeaderPolicy.
Definition theme.cpp:1044
void resetColumnSizes()
Resets the column sizes to "default" (subset of resetColumnState() above).
Definition theme.cpp:943
GroupHeaderBackgroundStyle groupHeaderBackgroundStyle() const
Returns the group header background style for this theme.
Definition theme.cpp:1017
static QList< QPair< QString, int > > enumerateViewHeaderPolicyOptions()
Enumerates the available view header policy options.
Definition theme.cpp:1027
bool load(QDataStream &stream) override
Pure virtual reimplemented from OptionSet.
Definition theme.cpp:1071
int iconSize() const
Returns the currently set icon size.
Definition theme.cpp:1054
const QList< Column * > & columns() const
Returns the list of columns available in this theme.
Definition theme.cpp:950
void save(QDataStream &stream) const override
Pure virtual reimplemented from OptionSet.
Definition theme.cpp:1162
void removeAllColumns()
Removes all columns from this theme.
Definition theme.cpp:960
Column * column(int idx) const
Returns a pointer to the column at the specified index or 0 if there is no such column.
Definition theme.cpp:955
void resetColumnState()
Resets the column state (visibility and width) to their default values (the "visible by default" ones...
Definition theme.cpp:935
GroupHeaderBackgroundStyle
How do we paint group header background ?
Definition theme.h:802
@ RoundedJoinedRect
One big rounded rect for all the columns.
Definition theme.h:806
@ PlainRect
One plain rect per column.
Definition theme.h:803
@ GradientRect
One rounded gradient filled rect per column.
Definition theme.h:807
@ StyledRect
One styled rect per column.
Definition theme.h:809
@ RoundedRect
One rounded rect per column.
Definition theme.h:805
@ StyledJoinedRect
One big styled rect per column.
Definition theme.h:810
@ PlainJoinedRect
One big plain rect for all the columns.
Definition theme.h:804
@ GradientJoinedRect
One big rounded gradient rect for all the columns.
Definition theme.h:808
bool isEmpty() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Oct 4 2024 11:53:54 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.