12#include <QStyleFactory>
25 const QStyleOption *option,
27 const QWidget *widget)
const override
29 if (element == QStyle::PE_IndicatorItemViewItemDrop)
31 QColor color(widget->palette().color(QPalette::Highlight).lighter());
32 if (option->rect.width() == 0 && option->rect.height() == 0){
35 else if (option->rect.width() == 0) {
38 QRect r(option->rect);
39 r.setLeft(r.left() - 4);
40 r.setRight(r.right() + 4);
42 painter->fillRect(r, brush);
44 else if (option->rect.height() == 0) {
47 QRect r(option->rect);
48 r.setTop(r.top() - 4);
49 r.setBottom(r.bottom() + 4);
51 painter->fillRect(r, brush);
56 QProxyStyle::drawPrimitive(element, option, painter, widget);
69 , m_itemOrientation(Qt::Vertical)
70 , m_commentIsVisible(true)
71 , m_thumbnailIsVisible(true)
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);
82 viewport()->setAcceptDrops(
true);
83 setDropIndicatorShown(
true);
84 setDragDropMode(QAbstractItemView::InternalMove);
86 QStyle *newStyle = QStyleFactory::create(this->style()->objectName());
89 proxyStyle->setParent(
this);
92 connect(
this, SIGNAL(customContextMenuRequested(
const QPoint &)),
95 connect(
this, &StoryboardView::clicked,
105 QListView::paintEvent(event);
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++) {
115 QModelIndex childIndex = model()->index(childRow, 0, index);
117 QStyleOptionViewItem option;
118 if (selectionModel()->isSelected(childIndex)) {
119 option.state |= QStyle::State_Selected;
121 if (childIndex == selectionModel()->currentIndex()) {
122 option.state |= QStyle::State_HasFocus;
124 option.font = font();
125 option.fontMetrics = fontMetrics();
127 itemDelegate()->paint(&painter, option, childIndex);
149 if (!index.isValid() || !index.parent().isValid()) {
150 return QListView::visualRect(index);
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");
159 int parentWidth = parentRect.width();
160 int childRow = index.row();
162 int thumbnailWidth = parentWidth;
164 thumbnailWidth = 250;
172 parentRect.setSize(QSize(3*numericFontWidth + 2, fontHeight));
176 parentRect.setSize(QSize(thumbnailWidth, 120));
177 parentRect.translate(0, fontHeight);
182 QRect itemNameRect = parentRect;
183 itemNameRect.setSize(QSize(thumbnailWidth - (12 * numericFontWidth + 22), fontHeight));
184 itemNameRect.moveLeft(parentRect.left() + 3*numericFontWidth + 2);
189 QRect secondRect = parentRect;
190 secondRect.setSize(QSize(5 * numericFontWidth + 10, fontHeight));
191 secondRect.moveLeft(parentRect.left() + thumbnailWidth - 9*numericFontWidth -20);
196 QRect frameRect = parentRect;
197 frameRect.setSize(QSize(4 * numericFontWidth + 10, fontHeight));
198 frameRect.moveLeft(parentRect.left() + thumbnailWidth - 4*numericFontWidth - 10);
212 parentRect.setTop(parentRect.top() + thumbnailheight + fontHeight + Model->visibleCommentsUpto(index) * 100);
213 parentRect.setHeight(100);
221 int commentWidth = 200;
222 if (numVisibleComments) {
223 commentWidth = qMax(200, (viewport()->width() - 250) / numVisibleComments);
225 parentRect.setSize(QSize(commentWidth, thumbnailheight + fontHeight));
226 parentRect.moveLeft(parentRect.left() + thumbnailWidth + storyboardModel->
visibleCommentsUpto(index) * commentWidth);
236 QModelIndex index = QListView::indexAt(point);
237 if (index.isValid()) {
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);
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); });
288 else if (index.parent().isValid()) {
289 index = index.parent();
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); });
298 contextMenu.addAction(i18nc(
"Duplicate current scene from storyboard docker",
"Duplicate Scene"), [index, pModel] {
299 int row = index.row();
305 contextMenu.addAction(i18nc(
"Remove current scene from storyboards",
"Remove Scene"), [index, pModel] {
306 int row = index.row();
312 contextMenu.exec(viewport()->mapToGlobal(point));
320 sbModel->
visualizeScene(clicked.parent().isValid() ? clicked.parent() : clicked);
330 if (index.isValid()) {
331 selectionModel()->select(index, QItemSelectionModel::ClearAndSelect);
332 selectionModel()->setCurrentIndex(index, QItemSelectionModel::ClearAndSelect);
338 QModelIndex index =
indexAt(event->pos());
350 QListView::mouseReleaseEvent(event);
356 const bool hasContent = m_storyboardModel->hasIndex(0,0);
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);
367 return QSize(250, 128);
float value(const T *src, size_t ch)
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
bool isOverlappingActionIcons(const QRect &rect, const QMouseEvent *event)
@ DurationFrame
Store the duration in frame at index 3. Data type stored here should be int.
@ FrameNumber
Store the frame number at index 0. Data type stored here should be ThumbnailData.
@ 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.
The main storyboard model. This class manages a StoryboardItemList which is a list of StoryboardItem ...
void visualizeScene(const QModelIndex &index, bool useUndo=true)
StoryboardItemList getData()
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.
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
int visibleCommentCount() const
Used in StoryboardDelegate and StoryboardView to get size of one storyboard item.
int visibleCommentsUpto(QModelIndex index) const
Used in StoryboardView to design the layout of storyboard item.
void drawPrimitive(PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const override
StoryboardStyle(QStyle *baseStyle=0)
QRect visualRect(const QModelIndex &index) const override
QModelIndex indexAt(const QPoint &point) const override
bool m_thumbnailIsVisible
Qt::Orientation itemOrientation()
whether Comments are below or on the right of Thumbnail
bool thumbnailIsVisible() const
void setThumbnailVisibility(bool value)
Sets the visibility of thumbnails.
void setCurrentItem(int frame)
changes the currentIndex and selectedIndex to frame
void mouseReleaseEvent(QMouseEvent *event) override
Qt::Orientation m_itemOrientation
void setItemOrientation(Qt::Orientation orientation)
void setCommentVisibility(bool value)
Sets the visibility of comments.
void paintEvent(QPaintEvent *event) override
~StoryboardView() override
StoryboardView(QWidget *parent=0)
void slotItemClicked(const QModelIndex &clicked)
QSize sizeHint() const override
void slotContextMenuRequested(const QPoint &)
bool commentIsVisible() const
#define KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(cond, val)
#define KIS_SAFE_ASSERT_RECOVER_RETURN(cond)