Commit f0ddd628 authored by kaniini's avatar kaniini

timeline widget: add action visibility button

parent 39bfbff2
<svg width="1800" height="1750" xmlns="http://www.w3.org/2000/svg">
<path d="M1664 960c-95-147-225-273-381-353 40 68 61 146 61 225 0 247-201 448-448 448s-448-201-448-448c0-79 21-157 61-225-156 80-286 206-381 353 171 264 447 448 768 448s597-184 768-448zM944 576c0-26-22-48-48-48-167 0-304 137-304 304 0 26 22 48 48 48s48-22 48-48c0-114 94-208 208-208 26 0 48-22 48-48zm848 384c0 25-8 48-20 69-184 303-521 507-876 507s-692-205-876-507c-12-21-20-44-20-69s8-48 20-69c184-302 521-507 876-507s692 205 876 507c12 21 20 44 20 69z"/>
</svg>
......@@ -8,5 +8,6 @@
<file>icons/action-reply.svg</file>
<file>icons/action-repeat.svg</file>
<file>icons/action-favorite.svg</file>
<file>icons/action-visibility.svg</file>
</qresource>
</RCC>
......@@ -308,7 +308,8 @@ void HTMLDelegate::paint(QPainter* painter, const QStyleOptionViewItem & option_
auto p = static_cast<const TimelineModel*>(index.model())->internalData(index);
bool favorited = p->m_is_favorited,
repeated = p->m_is_repeated;
repeated = p->m_is_repeated,
attachments_visible = p->m_attachments_visible;
// translate cursor position to actionbar position
cursor -= abRect.topLeft();
......@@ -351,7 +352,16 @@ void HTMLDelegate::paint(QPainter* painter, const QStyleOptionViewItem & option_
":/embedded-assets/icons/action-repeat.svg",
proper_icon_state (repeatIconRect, cursor, repeated)));
QRect menuIconRect = QRect (repeatIconRect.topRight() + spacingPoint, iconSize);
QRect visIconRect = QRect (repeatIconRect.topRight() + spacingPoint, iconSize);
#ifdef SHOW_ACTION_BAR_HITBOXES
painter->fillRect (visIconRect, Qt::green);
#endif
painter->drawPixmap(visIconRect, pixmap_from_theme (option.widget->palette(),
"michabo-action-visibility",
":/embedded-assets/icons/action-visibility.svg",
proper_icon_state (visIconRect, cursor, attachments_visible)));
QRect menuIconRect = QRect (visIconRect.topRight() + spacingPoint, iconSize);
#ifdef SHOW_ACTION_BAR_HITBOXES
painter->fillRect (menuIconRect, Qt::green);
#endif
......@@ -381,7 +391,15 @@ void HTMLDelegate::paint(QPainter* painter, const QStyleOptionViewItem & option_
painter->save ();
painter->setRenderHints (QPainter::Antialiasing | QPainter::SmoothPixmapTransform, true);
painter->drawImage (attachmentRect, attachment->m_preview);
if (p->m_attachments_visible)
painter->drawImage (attachmentRect, attachment->m_preview);
else
{
auto col = widget->palette ().text ();
painter->fillRect (attachmentRect, col);
}
painter->restore ();
}
else if (strategy == GridLayout)
......@@ -535,7 +553,8 @@ bool HTMLDelegate::editorEvent(QEvent *event, QAbstractItemModel *model, const Q
QRect replyIconRect = QRect (abRect.topLeft () + marginPoint, iconSize);
QRect favIconRect = QRect (replyIconRect.topRight () + spacingPoint, iconSize);
QRect repeatIconRect = QRect (favIconRect.topRight () + spacingPoint, iconSize);
QRect menuIconRect = QRect (repeatIconRect.topRight () + spacingPoint, iconSize);
QRect visIconRect = QRect (repeatIconRect.topRight () + spacingPoint, iconSize);
QRect menuIconRect = QRect (visIconRect.topRight () + spacingPoint, iconSize);
if (replyIconRect.contains (pos))
{
......@@ -555,6 +574,12 @@ bool HTMLDelegate::editorEvent(QEvent *event, QAbstractItemModel *model, const Q
return true;
}
if (visIconRect.contains (pos))
{
timeline_model->actionVis (index);
return true;
}
if (menuIconRect.contains (pos))
{
timeline_model->actionMenu (index);
......@@ -835,6 +860,16 @@ void TimelineModel::actionRepeat(const QModelIndex &index)
emit dataChanged(index, index);
}
void TimelineModel::actionVis(const QModelIndex &index)
{
int row = index.row ();
auto p = m_timeline[row];
p->m_attachments_visible ^= true;
emit dataChanged(index, index);
}
void TimelineModel::handleMouseOver(const QModelIndex &index)
{
emit dataChanged(index, index);
......
......@@ -66,6 +66,7 @@ public:
void actionFavorite(const QModelIndex &index);
void actionRepeat(const QModelIndex &index);
void actionMenu(const QModelIndex &index);
void actionVis(const QModelIndex &index);
void handleMouseOver(const QModelIndex &index);
void disallowUpdates() { m_last_fetch = time(nullptr) + 3; }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment