diff --git a/messagelist/src/core/themedelegate.h b/messagelist/src/core/themedelegate.h index 829cb458..4a65f985 100644 --- a/messagelist/src/core/themedelegate.h +++ b/messagelist/src/core/themedelegate.h @@ -1,206 +1,206 @@ /****************************************************************************** * * Copyright 2008 Szymon Tomasz Stefanek * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * *******************************************************************************/ #ifndef MESSAGELIST_CORE_THEMEDELEGATE_H #define MESSAGELIST_CORE_THEMEDELEGATE_H #include #include #include -#include -#include +#include "core/theme.h" +#include "core/item.h" class QAbstractItemView; namespace MessageList { namespace Core { class Item; /** * The ThemeDelegate paints the message list view message and group items by * using the supplied Theme. */ class ThemeDelegate : public QStyledItemDelegate { Q_OBJECT public: explicit ThemeDelegate(QAbstractItemView *parent); ~ThemeDelegate() override; /** * Called when the global fonts change (from systemsettings) */ void generalFontChanged(); private: const Theme *mTheme; ///< Shallow pointer to the current theme QAbstractItemView *mItemView; QColor mGroupHeaderBackgroundColor; // cache // hitTest results QModelIndex mHitIndex; Item *mHitItem; QRect mHitItemRect; const Theme::Column *mHitColumn; const Theme::Row *mHitRow; int mHitRowIndex; bool mHitRowIsMessageRow; QRect mHitRowRect; bool mHitContentItemRight; const Theme::ContentItem *mHitContentItem; QRect mHitContentItemRect; mutable QSize mCachedMessageItemSizeHint; mutable QSize mCachedGroupHeaderItemSizeHint; public: const Theme *theme() const; void setTheme(const Theme *theme); /** * Returns a heuristic sizeHint() for the specified item type and column. * The hint is based on the contents of the theme (and not of any message or group header). */ QSize sizeHintForItemTypeAndColumn(Item::Type type, int column, const Item *item = nullptr) const; /** * Performs a hit test on the specified viewport point. * Returns true if the point hit something and false otherwise. * When the hit test is succesfull then the hitIndex(), hitItem(), hitColumn(), hitRow(), and hitContentItem() * function will return information about the item that was effectively hit. * If exact is set to true then hitTest() will return true only if the viewportPoint * is exactly over an item. If exact is set to false then the hitTest() function * will do its best to find the closest object to be actually "hit": this is useful, * for example, in drag and drop operations. */ bool hitTest(const QPoint &viewportPoint, bool exact = true); /** * Returns the model index that was reported as hit by the previous call to hitTest(). * The result of this function is valid only if hitTest() returned true and only * within the same calling function. */ const QModelIndex &hitIndex() const; /** * Returns the Item that was reported as hit by the previous call to hitTest(). * The result of this function is valid only if hitTest() returned true and only * within the same calling function. */ Item *hitItem() const; /** * Returns the visual rectangle of the item that was reported as hit by the previous call to hitTest(). * The result of this function is valid only if hitTest() returned true and only * within the same calling function. Please note that this rectangle refers * to a specific item column (and not all of the columns). */ QRect hitItemRect() const; /** * Returns the theme column that was reported as hit by the previous call to hitTest(). * The result of this function is valid only if hitTest() returned true and only * within the same calling function. */ const Theme::Column *hitColumn() const; /** * Returns the index of the theme column that was reported as hit by the previous call to hitTest(). * The result of this function is valid only if hitTest() returned true and only * within the same calling function. * This is the same as hitIndex().column(). */ int hitColumnIndex() const; /** * Returns the theme row that was reported as hit by the previous call to hitTest(). * The result of this function is valid only if hitTest() returned true and only * within the same calling function. This function may also return a null row * when hitTest() returned true. This means that the item was globally hit * but no row was exactly hit (the user probably hit the margin instead). */ const Theme::Row *hitRow() const; /** * Returns the index of the theme row that was reported as hit by the previous call to hitTest(). * The result of this function is valid only if hitRow() returns a non null value. */ int hitRowIndex() const; /** * Returns the rectangle of the row that was reported as hit by the previous call to hitTest(). * The result of this function is valid only if hitTest() returned true and only * within the same calling function. The result of this function is also invalid * if hitRow() returns 0. */ QRect hitRowRect() const; /** * Returns true if the hitRow() is a message row, false otherwise. * The result of this function has a meaning only if hitRow() returns a non zero result. */ bool hitRowIsMessageRow() const; /** * Returns the theme content item that was reported as hit by the previous call to hitTest(). * The result of this function is valid only if hitTest() returned true and only * within the same calling function. This function may also return a null content item * when hitTest() returned true. This means that the item was globally hit * but no content item was exactly hit (the user might have clicked inside a blank unused space instead). */ const Theme::ContentItem *hitContentItem() const; /** * Returns true if the hit theme content item was a right item and false otherwise. * The result of this function is valid only if hitContentItem() returns true. */ bool hitContentItemRight() const; /** * Returns the bounding rect of the content item that was reported as hit by the previous call to hitTest(). * The result of this function is valid only if hitTest() returned true and only * within the same calling function. The result of this function is to be considered * invalid also when hitContentItem() returns 0. */ QRect hitContentItemRect() const; protected: /** * Returns the Item for the specified model index. Pure virtual: must be reimplemented * by derived classes. */ virtual Item *itemFromIndex(const QModelIndex &index) const = 0; /** * Reimplemented from QStyledItemDelegate */ void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override; /** * Reimplemented from QStyledItemDelegate */ QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override; }; } // namespace Core } // namespace MessageList #endif //!__MESSAGELIST_CORE_SKINDELEGATE_H diff --git a/messagelist/src/utils/themeeditor.h b/messagelist/src/utils/themeeditor.h index ab9688e3..66dc0e96 100644 --- a/messagelist/src/utils/themeeditor.h +++ b/messagelist/src/utils/themeeditor.h @@ -1,234 +1,234 @@ /****************************************************************************** * * Copyright 2008 Szymon Tomasz Stefanek * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * *******************************************************************************/ #ifndef MESSAGELIST_UTILS_THEMEEDITOR_H #define MESSAGELIST_UTILS_THEMEEDITOR_H -#include -#include -#include +#include "utils/optionseteditor.h" +#include "core/themedelegate.h" +#include "core/theme.h" #include #include #include #include class QCheckBox; class KComboBox; class KPluralHandlingSpinBox; class KLineEdit; namespace MessageList { namespace Core { class Item; class GroupHeaderItem; class MessageItem; class FakeItem; class ModelInvariantRowMapper; } // namespace Core namespace Utils { class ThemeColumnPropertiesDialog : public QDialog { Q_OBJECT public: explicit ThemeColumnPropertiesDialog(QWidget *parent, Core::Theme::Column *column, const QString &title); protected: Core::Theme::Column *mColumn = nullptr; KLineEdit *mNameEdit = nullptr; QCheckBox *mVisibleByDefaultCheck = nullptr; QCheckBox *mIsSenderOrReceiverCheck = nullptr; KComboBox *mMessageSortingCombo = nullptr; protected Q_SLOTS: void slotOkButtonClicked(); }; class ThemePreviewDelegate : public Core::ThemeDelegate { Q_OBJECT public: explicit ThemePreviewDelegate(QAbstractItemView *parent); ~ThemePreviewDelegate(); private: Core::GroupHeaderItem *mSampleGroupHeaderItem = nullptr; Core::FakeItem *mSampleMessageItem = nullptr; Core::ModelInvariantRowMapper *mRowMapper = nullptr; // needed for the MessageItem above to be valid public: Core::Item *itemFromIndex(const QModelIndex &index) const override; }; class ThemePreviewWidget : public QTreeWidget { Q_OBJECT public: explicit ThemePreviewWidget(QWidget *parent); ~ThemePreviewWidget(); void setReadOnly(bool readOnly); private: // DnD insert position stuff /** * The row we'll be inserting the dragged item into */ enum RowInsertPosition { AboveRow, ///< We'll insert above the currently hit row in mDelegate InsideRow, ///< We'll insert inside the currently hit row in mDelegate BelowRow ///< We'll insert below the currently hit row in mDelegate }; /** * The position in row that we'll be inserting the dragged item */ enum ItemInsertPosition { OnLeftOfItem, ///< We'll insert on the left of the selected item OnRightOfItem, ///< We'll insert on the right of the selected item AsLastLeftItem, ///< We'll insert as last left item of the row (rightmost left item) AsLastRightItem, ///< We'll insert as last right item of the row (leftmost right item) AsFirstLeftItem, ///< We'll insert as first left item of the row (leftmost) AsFirstRightItem ///< We'll insert as first right item of the row (rightmost) }; private: ThemePreviewDelegate *mDelegate = nullptr; QTreeWidgetItem *mGroupHeaderSampleItem = nullptr; QRect mThemeSelectedContentItemRect; Core::Theme::ContentItem *mSelectedThemeContentItem = nullptr; Core::Theme::Column *mSelectedThemeColumn = nullptr; QPoint mMouseDownPoint; Core::Theme *mTheme; RowInsertPosition mRowInsertPosition; ItemInsertPosition mItemInsertPosition; QPoint mDropIndicatorPoint1; QPoint mDropIndicatorPoint2; bool mFirstShow; bool mReadOnly; public: QSize sizeHint() const override; void setTheme(Core::Theme *theme); protected: void dragMoveEvent(QDragMoveEvent *e) override; void dragEnterEvent(QDragEnterEvent *e) override; void dropEvent(QDropEvent *e) override; void mouseMoveEvent(QMouseEvent *e) override; void mousePressEvent(QMouseEvent *e) override; void paintEvent(QPaintEvent *e) override; void showEvent(QShowEvent *e) override; void changeEvent(QEvent *event) override; private: void internalHandleDragMoveEvent(QDragMoveEvent *e); void internalHandleDragEnterEvent(QDragEnterEvent *e); /** * Computes the drop insert position for the dragged item at position pos. * Returns true if the dragged item can be inserted somewhere and * false otherwise. Sets mRowInsertPosition, mItemInsertPosition, * mDropIndicatorPoint1 ,mDropIndicatorPoint2. */ bool computeContentItemInsertPosition(const QPoint &pos, Core::Theme::ContentItem::Type type); void applyThemeColumnWidths(); protected Q_SLOTS: void slotHeaderContextMenuRequested(const QPoint &pos); void slotAddColumn(); void slotColumnProperties(); void slotDeleteColumn(); void slotDisabledFlagsMenuTriggered(QAction *act); void slotForegroundColorMenuTriggered(QAction *act); void slotFontMenuTriggered(QAction *act); void slotSoftenActionTriggered(bool); void slotGroupHeaderBackgroundModeMenuTriggered(QAction *act); void slotGroupHeaderBackgroundStyleMenuTriggered(QAction *act); void slotMoveColumnToLeft(); void slotMoveColumnToRight(); }; class ThemeContentItemSourceLabel : public QLabel { Q_OBJECT public: ThemeContentItemSourceLabel(QWidget *parent, Core::Theme::ContentItem::Type type); ~ThemeContentItemSourceLabel(); public: Core::Theme::ContentItem::Type type() const; void startDrag(); protected: void mousePressEvent(QMouseEvent *e) override; void mouseMoveEvent(QMouseEvent *e) override; private: QPoint mMousePressPoint; Core::Theme::ContentItem::Type mType; }; class ThemeEditor : public OptionSetEditor { Q_OBJECT public: explicit ThemeEditor(QWidget *parent); ~ThemeEditor(); public: /** * Sets the option set to be edited. * Saves and forgets any previously option set that was being edited. * The set parameter may be 0: in this case the editor is simply disabled. */ void editTheme(Core::Theme *set); Core::Theme *editedTheme() const; void commit(); Q_SIGNALS: void themeNameChanged(); private: void fillViewHeaderPolicyCombo(); protected Q_SLOTS: void slotNameEditTextEdited(const QString &newName) override; void slotIconSizeSpinBoxValueChanged(int val); private: void setReadOnly(bool readOnly); Core::Theme *mCurrentTheme = nullptr; // shallow, may be null! // Appearance tab ThemePreviewWidget *mPreviewWidget = nullptr; // Advanced tab KComboBox *mViewHeaderPolicyCombo = nullptr; KPluralHandlingSpinBox *mIconSizeSpinBox = nullptr; }; } // namespace Utils } // namespace MessageList #endif //!__MESSAGELIST_UTILS_SKINEDITOR_H