File indexing completed on 2024-06-23 04:26:34
0001 /* 0002 * SPDX-FileCopyrightText: 2020 Saurabh Kumar <saurabhk660@gmail.com> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef __STORYBOARD_DELEGATE_H 0008 #define __STORYBOARD_DELEGATE_H 0009 0010 #include <QStyledItemDelegate> 0011 #include <QTextEdit> 0012 0013 #include "StoryboardView.h" 0014 #include <kis_types.h> 0015 #include <kis_debug.h> 0016 #include <kis_image.h> 0017 0018 class QListView; 0019 class StoryboardModel; 0020 class StoryboardView; 0021 0022 class StoryboardDelegate : public QStyledItemDelegate 0023 { 0024 Q_OBJECT 0025 public: 0026 StoryboardDelegate(QObject *parent); 0027 ~StoryboardDelegate() override; 0028 0029 void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override; 0030 QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override; 0031 bool editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index) override; 0032 QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, 0033 const QModelIndex &index) const override; 0034 void setEditorData(QWidget *editor, const QModelIndex &index) const override; 0035 void setModelData(QWidget *editor, QAbstractItemModel *model, 0036 const QModelIndex &index) const override; 0037 void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const override; 0038 0039 void setView(StoryboardView *view); 0040 0041 /** 0042 * @brief Draw the spin box. 0043 */ 0044 void drawSpinBox(QPainter *p, const QStyleOptionViewItem &option, QString data, QString suffix) const; 0045 0046 /** 0047 * @brief Draw the comment header. 0048 */ 0049 QStyleOptionSlider drawCommentHeader(QPainter *p, const QStyleOptionViewItem &option, const QModelIndex &index) const; 0050 0051 /** 0052 * @return rectangle for Spinbox Up button for spin box at @c option.rect 0053 */ 0054 QRect spinBoxUpButton(const QStyleOptionViewItem &option); 0055 0056 /** 0057 * @return rectangle for Spinbox down button for spin box at @c option.rect 0058 */ 0059 QRect spinBoxDownButton(const QStyleOptionViewItem &option); 0060 0061 /** 0062 * @return rectangle for Spinbox edit field for spin box at @c option.rect 0063 */ 0064 QRect spinBoxEditField(const QStyleOptionViewItem &option); 0065 0066 /** 0067 * @return rectangle for Scrollbar(the rectangular controller) for scroll bar at @c option.rect 0068 */ 0069 QRect scrollBar(const QStyleOptionViewItem &option, QStyleOptionSlider &scrollBarOption) const; 0070 0071 /** 0072 * @return rectangle for Scrollbar's down button for scroll bar at @c option.rect 0073 */ 0074 QRect scrollDownButton(const QStyleOptionViewItem &option, QStyleOptionSlider &scrollBarOption); 0075 0076 /** 0077 * @return rectangle for Scrollbar's up button for scroll bar at @c option.rect 0078 */ 0079 QRect scrollUpButton(const QStyleOptionViewItem &option, QStyleOptionSlider &scrollBarOption); 0080 void setImageSize(QSize imageSize); 0081 0082 bool isOverlappingActionIcons(const QRect& rect, const QMouseEvent *event); 0083 0084 protected: 0085 bool eventFilter(QObject* editor, QEvent* event) override; 0086 0087 private Q_SLOTS: 0088 0089 /** 0090 * @brief updates the scroll value of the @c CommentBox in @c StoryboardModel 0091 * This enables the model to keep track of the part of the comment that has to be drawn in delegate. 0092 */ 0093 void slotCommentScrolledTo(int value) const; 0094 0095 private: 0096 StoryboardView *m_view; 0097 QPoint m_lastDragPos = QPoint(0, 0); 0098 QSize m_imageSize; 0099 }; 0100 0101 class LimitedTextEditor : public QTextEdit { 0102 Q_OBJECT 0103 public: 0104 LimitedTextEditor(int limit, QWidget* parent = nullptr) 0105 : QTextEdit(parent) 0106 , m_charLimit(limit){ 0107 connect(this, SIGNAL(textChanged()), this, SLOT(restrictText())); 0108 } 0109 0110 ~LimitedTextEditor(){} 0111 0112 public Q_SLOTS: 0113 void restrictText() { 0114 if (toPlainText().length() > m_charLimit) { 0115 setText(toPlainText().left(m_charLimit)); 0116 QTextCursor c = textCursor(); 0117 c.setPosition(m_charLimit); 0118 setTextCursor(c); 0119 } 0120 } 0121 0122 private: 0123 const int m_charLimit; 0124 }; 0125 0126 #endif