From 346bdc4901d7a53bb4aeb818900a784f87496fe1 Mon Sep 17 00:00:00 2001
From: Roger Siddons <dizygotheca@ntlworld.com>
Date: Mon, 28 Sep 2015 19:20:00 +0100
Subject: [PATCH 11/15] MythUI: Signal when image loaded
Emit a signal when MythUIImage finishes loading an image in a background thread.
Required for Gallery slideshows, which won't display an image until it is loaded.
diff --git a/mythtv/libs/libmythui/mythuiimage.cpp b/mythtv/libs/libmythui/mythuiimage.cpp
index 28245d7..c7961a8 100644
a
|
b
|
bool MythUIImage::Load(bool allowLoadInBackground, bool forceStat) |
1036 | 1036 | if (isAnimation) |
1037 | 1037 | Clear(); |
1038 | 1038 | |
| 1039 | bool complete = true; |
| 1040 | |
1039 | 1041 | QString imagelabel; |
1040 | 1042 | |
1041 | 1043 | int j = 0; |
… |
… |
bool MythUIImage::Load(bool allowLoadInBackground, bool forceStat) |
1161 | 1163 | } |
1162 | 1164 | |
1163 | 1165 | ++j; |
| 1166 | |
| 1167 | // Load is complete if no image is loading in background |
| 1168 | complete &= !do_background_load; |
1164 | 1169 | } |
1165 | 1170 | |
| 1171 | if (complete) |
| 1172 | emit LoadComplete(); |
| 1173 | |
1166 | 1174 | return true; |
1167 | 1175 | } |
1168 | 1176 | |
… |
… |
void MythUIImage::customEvent(QEvent *event) |
1594 | 1602 | if (le->GetParent() != this) |
1595 | 1603 | return; |
1596 | 1604 | |
1597 | | image = le->GetImage(); |
1598 | | number = le->GetNumber(); |
1599 | | filename = le->GetFilename(); |
| 1605 | image = le->GetImage(); |
| 1606 | number = le->GetNumber(); |
| 1607 | filename = le->GetFilename(); |
1600 | 1608 | animationFrames = le->GetAnimationFrames(); |
1601 | | aborted = le->GetAbortState(); |
| 1609 | aborted = le->GetAbortState(); |
1602 | 1610 | |
1603 | 1611 | m_runningThreads--; |
1604 | 1612 | |
1605 | 1613 | d->m_UpdateLock.lockForRead(); |
| 1614 | QString propFilename = m_imageProperties.filename; |
| 1615 | d->m_UpdateLock.unlock(); |
1606 | 1616 | |
1607 | 1617 | // 1) We aborted loading the image for some reason (e.g. two requests |
1608 | 1618 | // for same image) |
1609 | 1619 | // 2) Filename changed since we started this image, so abort to avoid |
1610 | 1620 | // rendering two different images in quick succession which causes |
1611 | 1621 | // unsightly flickering |
1612 | | if (aborted || |
1613 | | (le->GetBasefile() != m_imageProperties.filename)) |
| 1622 | if (aborted || (le->GetBasefile() != propFilename)) |
1614 | 1623 | { |
1615 | | d->m_UpdateLock.unlock(); |
1616 | | |
1617 | 1624 | if (aborted) |
1618 | 1625 | LOG(VB_GUI, LOG_DEBUG, QString("Aborted loading image %1") |
1619 | 1626 | .arg(filename)); |
… |
… |
void MythUIImage::customEvent(QEvent *event) |
1635 | 1642 | |
1636 | 1643 | delete animationFrames; |
1637 | 1644 | } |
1638 | | |
1639 | | return; |
1640 | 1645 | } |
1641 | | |
1642 | | d->m_UpdateLock.unlock(); |
1643 | | |
1644 | | if (animationFrames) |
| 1646 | else if (animationFrames) |
1645 | 1647 | { |
1646 | 1648 | SetAnimationFrames(*animationFrames); |
1647 | 1649 | |
1648 | 1650 | delete animationFrames; |
1649 | | |
1650 | | return; |
1651 | 1651 | } |
1652 | | |
1653 | | if (image) |
| 1652 | else if (image) |
1654 | 1653 | { |
1655 | 1654 | // We don't clear until we have the new image ready to display to |
1656 | 1655 | // avoid unsightly flashing. This isn't currently supported for |
… |
… |
void MythUIImage::customEvent(QEvent *event) |
1687 | 1686 | d->m_UpdateLock.lockForWrite(); |
1688 | 1687 | m_LastDisplay = QTime::currentTime(); |
1689 | 1688 | d->m_UpdateLock.unlock(); |
1690 | | |
1691 | | return; |
| 1689 | } |
| 1690 | else |
| 1691 | { |
| 1692 | // No Images were loaded, so trigger Reset to default |
| 1693 | Reset(); |
1692 | 1694 | } |
1693 | 1695 | |
1694 | | // No Images were loaded, so trigger Reset to default |
1695 | | Reset(); |
| 1696 | emit LoadComplete(); |
1696 | 1697 | } |
1697 | 1698 | } |
1698 | 1699 | |
diff --git a/mythtv/libs/libmythui/mythuiimage.h b/mythtv/libs/libmythui/mythuiimage.h
index dbd7901..7847c4a 100644
a
|
b
|
typedef QVector<AnimationFrame> AnimationFrames; |
87 | 87 | */ |
88 | 88 | class MUI_PUBLIC MythUIImage : public MythUIType |
89 | 89 | { |
| 90 | Q_OBJECT |
| 91 | |
90 | 92 | public: |
91 | 93 | MythUIImage(const QString &filepattern, int low, int high, int delayms, |
92 | 94 | MythUIType *parent, const QString &name); |
… |
… |
class MUI_PUBLIC MythUIImage : public MythUIType |
126 | 128 | |
127 | 129 | void SetOrientation(int orientation); |
128 | 130 | |
| 131 | signals: |
| 132 | void LoadComplete(); |
| 133 | |
129 | 134 | protected: |
130 | 135 | virtual void DrawSelf(MythPainter *p, int xoffset, int yoffset, |
131 | 136 | int alphaMod, QRect clipRect); |