Krita Source Code Documentation
Loading...
Searching...
No Matches
StoryboardView Class Reference

#include <StoryboardView.h>

+ Inheritance diagram for StoryboardView:

Public Member Functions

bool commentIsVisible () const
 
QModelIndex indexAt (const QPoint &point) const override
 
Qt::Orientation itemOrientation ()
 whether Comments are below or on the right of Thumbnail
 
void mouseReleaseEvent (QMouseEvent *event) override
 
void paintEvent (QPaintEvent *event) override
 
void setCommentVisibility (bool value)
 Sets the visibility of comments.
 
void setCurrentItem (int frame)
 changes the currentIndex and selectedIndex to frame
 
void setItemOrientation (Qt::Orientation orientation)
 
void setThumbnailVisibility (bool value)
 Sets the visibility of thumbnails.
 
QSize sizeHint () const override
 
 StoryboardView (QWidget *parent=0)
 
bool thumbnailIsVisible () const
 
QRect visualRect (const QModelIndex &index) const override
 
 ~StoryboardView () override
 

Private Slots

void slotContextMenuRequested (const QPoint &)
 
void slotItemClicked (const QModelIndex &clicked)
 

Private Attributes

bool m_commentIsVisible
 
Qt::Orientation m_itemOrientation
 
bool m_thumbnailIsVisible
 

Detailed Description

This view draws the children of every index in the first column of the model inside the parent index

Definition at line 23 of file StoryboardView.h.

Constructor & Destructor Documentation

◆ StoryboardView()

StoryboardView::StoryboardView ( QWidget * parent = 0)
explicit

This view draws the children of every index in the first column of the model inside the parent

Definition at line 67 of file StoryboardView.cpp.

68 : QListView(parent)
69 , m_itemOrientation(Qt::Vertical)
70 , m_commentIsVisible(true)
72{
73 setSelectionBehavior(SelectRows);
74 setDefaultDropAction(Qt::MoveAction);
75 setResizeMode(QListView::Adjust);
76 setUniformItemSizes(true);
77 setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
78 setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel);
79 QWidget::setMouseTracking(true);
80 setContextMenuPolicy(Qt::CustomContextMenu);
81 setDragEnabled(true);
82 viewport()->setAcceptDrops(true);
83 setDropIndicatorShown(true);
84 setDragDropMode(QAbstractItemView::InternalMove);
85
86 QStyle *newStyle = QStyleFactory::create(this->style()->objectName());
87 // proxy style steals the ownership of the style and deletes it later
88 StoryboardStyle *proxyStyle = new StoryboardStyle(newStyle);
89 proxyStyle->setParent(this);
90 setStyle(proxyStyle);
91
92 connect(this, SIGNAL(customContextMenuRequested(const QPoint &)),
93 this, SLOT(slotContextMenuRequested(const QPoint &)));
94
95 connect(this, &StoryboardView::clicked,
97}
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
Qt::Orientation m_itemOrientation
void slotItemClicked(const QModelIndex &clicked)
void slotContextMenuRequested(const QPoint &)

References connect(), slotContextMenuRequested(), and slotItemClicked().

◆ ~StoryboardView()

StoryboardView::~StoryboardView ( )
override

Definition at line 99 of file StoryboardView.cpp.

100{}

Member Function Documentation

◆ commentIsVisible()

bool StoryboardView::commentIsVisible ( ) const
Returns
True if comments are visible, otherwise False.

Definition at line 260 of file StoryboardView.cpp.

261{
262 return m_commentIsVisible;
263}

References m_commentIsVisible.

◆ indexAt()

QModelIndex StoryboardView::indexAt ( const QPoint & point) const
override

Definition at line 234 of file StoryboardView.cpp.

235{
236 QModelIndex index = QListView::indexAt(point);
237 if (index.isValid()) {
238 //look for the index in children of the current index
239 int numChild = model()->rowCount(index);
240 for (int row = 0; row < numChild; row++) {
241 QRect childRect = visualRect(model()->index(row, 0, index));
242 if (childRect.contains(point)) {
243 return model()->index(row, 0, index);
244 }
245 }
246 }
247 return index;
248}
QRect visualRect(const QModelIndex &index) const override

References visualRect().

◆ itemOrientation()

Qt::Orientation StoryboardView::itemOrientation ( )

whether Comments are below or on the right of Thumbnail

Returns
The orientation of each Storyboard Item

Definition at line 255 of file StoryboardView.cpp.

256{
257 return m_itemOrientation;
258}

References m_itemOrientation.

◆ mouseReleaseEvent()

void StoryboardView::mouseReleaseEvent ( QMouseEvent * event)
override

Definition at line 337 of file StoryboardView.cpp.

337 {
338 QModelIndex index = indexAt(event->pos());
339
340 // To prevent selection changes from occurring when hitting the "plus" button,
341 // we want to filter out these inputs before passing it up to QListView / QAbstractItemView
342 if (index.isValid() && index.parent().isValid() && index.row() == StoryboardItem::FrameNumber) {
343 StoryboardDelegate* sbDelegate = dynamic_cast<StoryboardDelegate*>(itemDelegate(index));
344 QRect itemRect = visualRect(index);
345 if (sbDelegate && sbDelegate->isOverlappingActionIcons(itemRect, event)) {
346 return;
347 }
348 }
349
350 QListView::mouseReleaseEvent(event);
351}
bool isOverlappingActionIcons(const QRect &rect, const QMouseEvent *event)
@ FrameNumber
Store the frame number at index 0. Data type stored here should be ThumbnailData.
QModelIndex indexAt(const QPoint &point) const override

References StoryboardItem::FrameNumber, indexAt(), StoryboardDelegate::isOverlappingActionIcons(), and visualRect().

◆ paintEvent()

void StoryboardView::paintEvent ( QPaintEvent * event)
override

Definition at line 102 of file StoryboardView.cpp.

103{
104 event->accept();
105 QListView::paintEvent(event);
106
107 //ask delegate to draw the child nodes too
108 QPainter painter(viewport());
109 int itemNum = model()->rowCount();
110 for (int row = 0; row < itemNum; row++) {
111 QModelIndex index = model()->index(row, 0);
112 int childNum = model()->rowCount(index);
113 for (int childRow = 0; childRow < childNum; childRow++) {
114
115 QModelIndex childIndex = model()->index(childRow, 0, index);
116
117 QStyleOptionViewItem option;
118 if (selectionModel()->isSelected(childIndex)) {
119 option.state |= QStyle::State_Selected;
120 }
121 if (childIndex == selectionModel()->currentIndex()) {
122 option.state |= QStyle::State_HasFocus;
123 }
124 option.font = font();
125 option.fontMetrics = fontMetrics();
126 option.rect = visualRect(childIndex);
127 itemDelegate()->paint(&painter, option, childIndex);
128 }
129 }
130}

References visualRect().

◆ setCommentVisibility()

void StoryboardView::setCommentVisibility ( bool value)

Sets the visibility of comments.

Parameters
valueThe new visibility value

Definition at line 270 of file StoryboardView.cpp.

271{
273}
float value(const T *src, size_t ch)

References m_commentIsVisible, and value().

◆ setCurrentItem()

void StoryboardView::setCurrentItem ( int frame)

changes the currentIndex and selectedIndex to frame

Parameters
frameThe new current frame

Definition at line 324 of file StoryboardView.cpp.

325{
327 const StoryboardModel* sbModel = dynamic_cast<const StoryboardModel*>(model());
329 QModelIndex index = sbModel->indexFromFrame(frame);
330 if (index.isValid()) {
331 selectionModel()->select(index, QItemSelectionModel::ClearAndSelect);
332 selectionModel()->setCurrentIndex(index, QItemSelectionModel::ClearAndSelect);
333 scrollTo(index);
334 }
335}
The main storyboard model. This class manages a StoryboardItemList which is a list of StoryboardItem ...
QModelIndex indexFromFrame(int frame, bool framePerfect=true) const
Returns the index of the item corresponding the frame, if there is an item with that frame.
#define KIS_SAFE_ASSERT_RECOVER_RETURN(cond)
Definition kis_assert.h:128

References StoryboardModel::indexFromFrame(), and KIS_SAFE_ASSERT_RECOVER_RETURN.

◆ setItemOrientation()

void StoryboardView::setItemOrientation ( Qt::Orientation orientation)

Definition at line 250 of file StoryboardView.cpp.

251{
252 m_itemOrientation = orientation;
253}

References m_itemOrientation.

◆ setThumbnailVisibility()

void StoryboardView::setThumbnailVisibility ( bool value)

Sets the visibility of thumbnails.

Parameters
valueThe new visibility value

Definition at line 275 of file StoryboardView.cpp.

276{
278}

References m_thumbnailIsVisible, and value().

◆ sizeHint()

QSize StoryboardView::sizeHint ( ) const
override

Definition at line 353 of file StoryboardView.cpp.

353 {
354 if (model()) {
355 StoryboardModel* m_storyboardModel = static_cast<StoryboardModel*>(model());
356 const bool hasContent = m_storyboardModel->hasIndex(0,0);
357 if (hasContent) {
358 const bool hasComments = m_storyboardModel->visibleCommentCount() > 0;
359 const bool hasMoreThanOneComment = m_storyboardModel->visibleCommentCount() > 1;
360 const float commentPadding = hasComments ? 1.0f + (0.1f * hasMoreThanOneComment) : 0.0f;
361 const int thumbnailWidth = 286;
362 const int commentWidth = 200 * commentPadding;
363 return QSize(thumbnailWidth + commentWidth, 128);
364 }
365 }
366
367 return QSize(250, 128);
368}
int visibleCommentCount() const
Used in StoryboardDelegate and StoryboardView to get size of one storyboard item.

References StoryboardModel::visibleCommentCount().

◆ slotContextMenuRequested

void StoryboardView::slotContextMenuRequested ( const QPoint & point)
privateslot

Definition at line 280 of file StoryboardView.cpp.

281{
282 StoryboardModel* pModel = dynamic_cast<StoryboardModel*>(model());
283 QMenu contextMenu;
284 QModelIndex index = indexAt(point);
285 if (!index.isValid()) {
286 contextMenu.addAction(i18nc("Add new scene as the last storyboard", "Add Scene"), [index, pModel] {pModel->insertItem(index, false); });
287 }
288 else if (index.parent().isValid()) {
289 index = index.parent();
290 }
291
292 if (index.isValid()) {
293 contextMenu.addAction(i18nc("Add scene after active scene", "Add Scene After"), [index, pModel] {pModel->insertItem(index, true); });
294 if (index.row() > 0) {
295 contextMenu.addAction(i18nc("Add scene before active scene", "Add Scene Before"), [index, pModel] {pModel->insertItem(index, false); });
296 }
297
298 contextMenu.addAction(i18nc("Duplicate current scene from storyboard docker", "Duplicate Scene"), [index, pModel] {
299 int row = index.row();
301 command->redo();
302 pModel->pushUndoCommand(command);
303 });
304
305 contextMenu.addAction(i18nc("Remove current scene from storyboards", "Remove Scene"), [index, pModel] {
306 int row = index.row();
307 KisRemoveStoryboardCommand *command = new KisRemoveStoryboardCommand(row, pModel->getData().at(row), pModel);
308 pModel->removeItem(index, command);
309 pModel->pushUndoCommand(command);
310 });
311 }
312 contextMenu.exec(viewport()->mapToGlobal(point));
313}
StoryboardItemList getData()
bool insertItem(QModelIndex index, bool after)
inserts item after or before index based on after parameter
void pushUndoCommand(KUndo2Command *command)
bool removeItem(QModelIndex index, KUndo2Command *command=nullptr)
removes item, deletes keyframes within and shifts keyframe after the scene to fill in the gap

References StoryboardModel::getData(), indexAt(), StoryboardModel::insertItem(), StoryboardModel::pushUndoCommand(), KisDuplicateStoryboardCommand::redo(), and StoryboardModel::removeItem().

◆ slotItemClicked

void StoryboardView::slotItemClicked ( const QModelIndex & clicked)
privateslot

Definition at line 315 of file StoryboardView.cpp.

316{
317 StoryboardModel* sbModel = dynamic_cast<StoryboardModel*>(model());
318
319 if(sbModel) {
320 sbModel->visualizeScene(clicked.parent().isValid() ? clicked.parent() : clicked);
321 }
322}
void visualizeScene(const QModelIndex &index, bool useUndo=true)

References StoryboardModel::visualizeScene().

◆ thumbnailIsVisible()

bool StoryboardView::thumbnailIsVisible ( ) const
Returns
True if thumbnails are visible, otherwise False.

Definition at line 265 of file StoryboardView.cpp.

266{
268}

References m_thumbnailIsVisible.

◆ visualRect()

QRect StoryboardView::visualRect ( const QModelIndex & index) const
override

Definition at line 132 of file StoryboardView.cpp.

133{
134 /*
135 * fw = fontWidth
136 *
137 * (3*fw+2), (5*fw+10) _____ (4*fw+10)
138 * | | /
139 * | | /
140 * ,_________________________,
141 * |__|_____________|____|___| ---------->(fontHeight)
142 * | |
143 * | |
144 * | |
145 * | |
146 * |_________________________|
147 */
148
149 if (!index.isValid() || !index.parent().isValid()) {
150 return QListView::visualRect(index);
151 }
152 else {
153 QRect parentRect = visualRect(index.parent());
154 parentRect.setTopLeft(parentRect.topLeft() + QPoint(5, 5));
155 parentRect.setBottomRight(parentRect.bottomRight() - QPoint(5, 5));
156 int fontHeight = fontMetrics().height() + 3;
157 int numericFontWidth = fontMetrics().horizontalAdvance("0");
158
159 int parentWidth = parentRect.width();
160 int childRow = index.row();
161
162 int thumbnailWidth = parentWidth;
163 if (m_itemOrientation == Qt::Horizontal) {
164 thumbnailWidth = 250;
165 }
166 switch (childRow)
167 {
169 {
170 //the frame thumbnail rect
171 if (!thumbnailIsVisible()) {
172 parentRect.setSize(QSize(3*numericFontWidth + 2, fontHeight));
173 return parentRect;
174 }
175
176 parentRect.setSize(QSize(thumbnailWidth, 120));
177 parentRect.translate(0, fontHeight);
178 return parentRect;
179 }
181 {
182 QRect itemNameRect = parentRect;
183 itemNameRect.setSize(QSize(thumbnailWidth - (12 * numericFontWidth + 22), fontHeight));
184 itemNameRect.moveLeft(parentRect.left() + 3*numericFontWidth + 2);
185 return itemNameRect;
186 }
188 {
189 QRect secondRect = parentRect;
190 secondRect.setSize(QSize(5 * numericFontWidth + 10, fontHeight));
191 secondRect.moveLeft(parentRect.left() + thumbnailWidth - 9*numericFontWidth -20);
192 return secondRect;
193 }
195 {
196 QRect frameRect = parentRect;
197 frameRect.setSize(QSize(4 * numericFontWidth + 10, fontHeight));
198 frameRect.moveLeft(parentRect.left() + thumbnailWidth - 4*numericFontWidth - 10);
199 return frameRect;
200 }
201 default:
202 {
203 //comment rect
204 if (!commentIsVisible()) {
205 return QRect();
206 }
207
208 int thumbnailheight = thumbnailIsVisible() ? 120 : 0;
209 if (m_itemOrientation == Qt::Vertical) {
210 const StoryboardModel* Model = dynamic_cast<const StoryboardModel*>(model());
212 parentRect.setTop(parentRect.top() + thumbnailheight + fontHeight + Model->visibleCommentsUpto(index) * 100);
213 parentRect.setHeight(100);
214 return parentRect;
215 }
216 else {
217 KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(model(), QRect());
218 const StoryboardModel* storyboardModel = dynamic_cast<const StoryboardModel*>(model());
219 KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(storyboardModel, QRect());
220 int numVisibleComments = storyboardModel->visibleCommentCount();
221 int commentWidth = 200;
222 if (numVisibleComments) {
223 commentWidth = qMax(200, (viewport()->width() - 250) / numVisibleComments);
224 }
225 parentRect.setSize(QSize(commentWidth, thumbnailheight + fontHeight));
226 parentRect.moveLeft(parentRect.left() + thumbnailWidth + storyboardModel->visibleCommentsUpto(index) * commentWidth);
227 return parentRect;
228 }
229 }
230 }
231 }
232}
@ DurationFrame
Store the duration in frame at index 3. Data type stored here should be int.
@ DurationSecond
Store the duration in second at index 2. Data type stored here should be int.
@ ItemName
Store the item name at index 1. Data type stored here should be string.
int visibleCommentsUpto(QModelIndex index) const
Used in StoryboardView to design the layout of storyboard item.
bool thumbnailIsVisible() const
bool commentIsVisible() const
#define KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(cond, val)
Definition kis_assert.h:129
const uint16_t Model

References commentIsVisible(), StoryboardItem::DurationFrame, StoryboardItem::DurationSecond, StoryboardItem::FrameNumber, StoryboardItem::ItemName, KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE, m_itemOrientation, thumbnailIsVisible(), StoryboardModel::visibleCommentCount(), StoryboardModel::visibleCommentsUpto(), and visualRect().

Member Data Documentation

◆ m_commentIsVisible

bool StoryboardView::m_commentIsVisible
private

Definition at line 81 of file StoryboardView.h.

◆ m_itemOrientation

Qt::Orientation StoryboardView::m_itemOrientation
private

Definition at line 80 of file StoryboardView.h.

◆ m_thumbnailIsVisible

bool StoryboardView::m_thumbnailIsVisible
private

Definition at line 82 of file StoryboardView.h.


The documentation for this class was generated from the following files: