11#include <QDomDocument>
14#include <QInputMethodEvent>
40#define LOC QString("MythUIType: ")
49 m_parent = qobject_cast<MythUIType *>(parent);
89static QObject *
qChildHelper(
const char *objName,
const char *inheritsClass,
90 bool recursiveSearch,
const QObjectList &children)
92 if (children.isEmpty())
95 bool onlyWidgets = (inheritsClass
96 && qstrcmp(inheritsClass,
"QWidget") == 0);
97 const QLatin1String oName(objName);
99 for (
auto *obj : std::as_const(children))
103 if (obj->isWidgetType() && (!objName || obj->objectName() == oName))
106 else if ((!inheritsClass || obj->inherits(inheritsClass))
107 && (!objName || obj->objectName() == oName))
112 if (recursiveSearch && (qobject_cast<MythUIGroup *>(obj) !=
nullptr))
114 obj =
qChildHelper(objName, inheritsClass, recursiveSearch,
132 QObject *ret =
qChildHelper(name.toLatin1().constData(),
nullptr,
true, children());
135 return qobject_cast<MythUIType *>(ret);
150 if (
type->objectName() == name)
195 QList<MythUIType *> descendants {};
200 descendants += item->GetAllDescendants();
210 QList<MythUIType *>::iterator it;
228 bool focusable)
const
239 QList<MythUIType *>::const_reverse_iterator it;
249 if (!(*it)->GetArea().contains(
p -
GetArea().topLeft()))
277 if (animation->GetTrigger() == trigger)
278 animation->Activate();
281 uiType->ActivateAnimations(trigger);
293 QList<MythUIType *>::Iterator it;
296 (*it)->ResetNeedsRedraw();
319 if (childRegion.isEmpty())
450 QList<MythUIAnimation*>::Iterator i;
452 (*i)->IncrementCurrentTime();
454 QList<MythUIType *>::Iterator it;
482 realArea.translate(xoffset, yoffset);
484 if (!realArea.intersects(clipRect))
489 DrawSelf(
p, xoffset, yoffset, alphaMod, clipRect);
491 QList<MythUIType *>::Iterator it;
499 if (
p->ShowBorders())
501 static const QBrush kNullBrush(Qt::NoBrush);
504 p->DrawRect(realArea, kNullBrush, pen, 255);
506 if (
p->ShowTypeNames())
509 font.
SetFace(QFont(
"Droid Sans"));
512 p->DrawText(realArea, objectName(), 0, font, 255, realArea);
516 p->PopTransformation();
557 if (size ==
m_area.size())
616 int delta_w,
int delta_h)
623 QRect bounded(
m_area.x() - delta_x,
626 m_area.height() + delta_h);
631 QPoint center = bounded.center();
633 if (bounded.isNull())
636 bounded.setSize(bounded.size().expandedTo(
GetMinSize()));
638 bounded.moveCenter(center);
641 if (bounded.x() + bounded.width() >
m_area.x() +
m_area.width())
643 if (bounded.y() + bounded.height() >
m_area.y() +
m_area.height())
645 if (bounded.x() <
m_area.x())
647 bounded.moveLeft(
m_area.x());
648 if (bounded.width() >
m_area.width())
649 bounded.setWidth(
m_area.width());
651 if (bounded.y() <
m_area.y())
653 bounded.moveTop(
m_area.y());
654 if (bounded.height() >
m_area.height())
655 bounded.setHeight(
m_area.height());
661 QList<MythUIType *>::iterator it;
665 if (!(*it)->m_initiator)
666 (*it)->AdjustMinArea(delta_x, delta_y, delta_w, delta_h);
681 QList<MythUIType *>::iterator it;
685 if (!(*it)->m_initiator)
686 (*it)->VanishSibling();
717 QList<MythUIType *>::iterator it;
724 if (!(*it)->m_vanished)
727 area = (*it)->GetArea();
729 actual_area = actual_area.united(area);
731 area = (*it)->m_area;
733 allowed_area = allowed_area.united(area);
738 actual_area = actual_area.intersected(
m_area);
739 allowed_area = allowed_area.intersected(
m_area);
741 if (
m_vanish && actual_area.size().isNull())
749 delta_x =
m_area.x() - actual_area.x();
750 delta_y =
m_area.y() - actual_area.y();
751 delta_w = actual_area.width() -
m_area.width();
752 delta_h = actual_area.height() -
m_area.height();
756 delta_x = allowed_area.x() - actual_area.x();
757 delta_y = allowed_area.y() - actual_area.y();
758 delta_w = actual_area.width() - allowed_area.width();
759 delta_h = actual_area.height() - allowed_area.height();
767 if (*it == calling_child)
770 if (!(*it)->m_initiator)
773 (*it)->VanishSibling();
775 (*it)->AdjustMinArea(delta_x, delta_y, delta_w, delta_h);
778 area = (*it)->GetArea();
780 actual_area = actual_area.united(area);
786 actual_area.
setRect(0, 0, 0, 0);
790 QSize bound(actual_area.width(), actual_area.height());
795 actual_area.x() + bound.width(),
796 actual_area.y() + bound.height());
813 bool vanish = (
m_vanish && rect.isNull());
822 QPoint center = bounded.center();
824 if (bounded.isNull())
827 bounded.setSize(bounded.size().expandedTo(
GetMinSize()));
829 bounded.moveCenter(center);
830 if (bounded.x() + bounded.width() >
m_area.x() +
m_area.width())
832 if (bounded.y() + bounded.height() >
m_area.y() +
m_area.height())
834 if (bounded.x() <
m_area.x())
836 bounded.moveLeft(
m_area.x());
837 if (bounded.width() >
m_area.width())
838 bounded.setWidth(
m_area.width());
840 if (bounded.y() <
m_area.y())
842 bounded.moveTop(
m_area.y());
843 if (bounded.height() >
m_area.height())
844 bounded.setHeight(
m_area.height());
857 QSize childSize = rect.size();
858 QSize size =
m_area.size();
860 if (childSize == size)
863 SetSize(size.expandedTo(childSize));
905 if (destXY.x() ==
m_area.x() && destXY.y() ==
m_area.y())
991 QObject::customEvent(event);
1050 bool visible =
false;
1055 visible = reverse ? !isDefault : isDefault;
1076 visible = visible && v;
1081 visible = visible || v;
1092 auto *dependee = qobject_cast<MythUIType*>(sender());
1147 child->AddFocusableChildrenToList(focusList);
1190 QList<MythUIAnimation*>::Iterator i;
1194 animation->CopyFrom(*i);
1198 QList<MythUIType *>::Iterator it;
1208 (*it)->CreateCopy(
this);
1230 const QString &
filename, QDomElement &element,
bool showWarnings)
1234 if (element.tagName() ==
"position")
1236 else if (element.tagName() ==
"area")
1240 else if (element.tagName() ==
"minsize")
1243 if (element.hasAttribute(
"initiator"))
1246 if (element.hasAttribute(
"vanish"))
1251 else if (element.tagName() ==
"alpha")
1256 else if (element.tagName() ==
"alphapulse")
1259 m_alphaMin = element.attribute(
"min",
"0").toInt();
1269 else if (element.tagName() ==
"focusorder")
1274 else if (element.tagName() ==
"loadondemand")
1278 else if (element.tagName() ==
"helptext")
1282 else if (element.tagName() ==
"animation")
1289 QString(
"Unknown widget type '%1'").arg(element.tagName()));
1332 QList<MythUIType *>::iterator it;
1336 (*it)->RecalculateArea(recurse);
1393 QList<MythUIType *>::Iterator it;
1406 return m_area.contains(point);
1432 QStringList dependees;
1433 QList<int> operators;
1439 QString& name = it.value();
1440 QStringList tmp1 = name.split(
"&");
1441 for (
const QString& t1 : std::as_const(tmp1))
1443 QStringList tmp2 = t1.split(
"|");
1445 dependees.append(tmp2[0]);
1446 for (
int j = 1; j < tmp2.size(); j++)
1448 dependees.append(tmp2[j]);
1449 operators.append(1);
1451 operators.append(2);
1458 for (QString dependeeName : std::as_const(dependees))
1460 bool reverse =
false;
1461 if (dependeeName.startsWith(
'!'))
1464 dependeeName.remove(0,1);
1473 dependant->
m_dependsValue.append(QPair<MythUIType *, bool>(dependee,
false));
1478 dependant->
m_dependsValue.append(QPair<MythUIType *, bool>(dependee, !reverse));
1487 QList<MythUIType *>::iterator child;
1491 (*child)->ConnectDependants(recurse);
bool AddFont(const QString &text, MythFontProperties *fontProp)
MythFontProperties * GetFont(const QString &text)
void SetFace(const QFont &face)
void SetColor(const QColor &color)
void SetPointSize(uint points)
A custom event that represents a mouse gesture.
Wrapper around QPoint allowing us to handle percentage and other relative values for positioning in m...
void CalculatePoint(QRect parentArea)
QPoint toQPoint(void) const
Wrapper around QRect allowing us to handle percentage and other relative values for areas in mythui.
void setRect(const QString &sX, const QString &sY, const QString &sWidth, const QString &sHeight, const QString &baseRes=QString())
MythPoint topLeft(void) const
void moveTop(const QString &sY)
void moveLeft(const QString &sX)
void setWidth(const QString &sWidth)
void setHeight(const QString &sHeight)
void CalculateArea(QRect parentArea)
void moveTopLeft(QPoint point)
QRect toQRect(void) const
static void ParseElement(const QDomElement &element, MythUIType *parent)
The base class on which all widgets and screens are based.
bool IsEnabled(void) const
void AddFocusableChildrenToList(FocusInfoType &focusList)
bool AddFont(const QString &text, MythFontProperties *fontProp)
QList< MythUIType * > * GetAllChildren(void)
Return a list of all child widgets.
bool ContainsPoint(QPoint point) const
Check if the given point falls within this widgets area.
virtual void RecalculateArea(bool recurse=true)
void SetCanTakeFocus(bool set=true)
Set whether this widget can take focus.
void SetDependsMap(QMap< QString, QString > dependsMap)
virtual QRegion GetDirtyArea(void) const
bool IsVisible(bool recurse=false) const
virtual void SetSize(QSize size)
void VisibilityChanged(bool Visible)
void HandleMovementPulse()
Handle one frame of a movement animation.
void AddChild(MythUIType *child)
Add a child UIType.
void ActivateAnimations(MythUIAnimation::Trigger trigger)
void SetFocusOrder(int order)
virtual void mediaEvent(MythMediaEvent *event)
Media/Device status event handler, received from MythMediaMonitor.
void customEvent(QEvent *event) override
virtual void DrawSelf(MythPainter *p, int xoffset, int yoffset, int alphaMod, QRect clipRect)
virtual void VanishSibling(void)
void Draw(MythPainter *p, int xoffset, int yoffset, int alphaMod=255, QRect clipRect=QRect())
bool CanTakeFocus(void) const
Return if this widget can accept input focus.
virtual void SetVisible(bool visible)
virtual MythPainter * GetPainter(void)
void AdjustAlpha(int mode, int alphachange, int minalpha=0, int maxalpha=255)
virtual void SetArea(const MythRect &rect)
virtual void LoadNow(void)
Cause images in this and child widgets to be loaded.
virtual bool gestureEvent(MythGestureEvent *event)
Mouse click/movement handler, receives mouse gesture events from the QCoreApplication event loop.
void ExpandArea(QRect rect)
virtual QSize GetMinSize(void) const
MythUIType(QObject *parent, const QString &name)
virtual void AdjustMinArea(int delta_x, int delta_y, int delta_w, int delta_h)
Adjust the size of a sibling.
QList< int > m_dependOperator
QMap< MythUIType *, bool > m_reverseDepend
void SetEnabled(bool enable)
void SetAngle(float angle)
virtual void CopyFrom(MythUIType *base)
Copy this widgets state from another.
virtual void Finalize(void)
Perform any post-xml parsing initialisation tasks.
bool NeedsRedraw(void) const
MythUIType * GetChildAt(QPoint p, bool recursive=true, bool focusable=true) const
Return the first MythUIType at the given coordinates.
void ResetNeedsRedraw(void)
void SetFocusedName(const QString &widgetname)
void ConnectDependants(bool recurse=false)
void SetVerticalZoom(float zoom)
virtual void SetMinArea(const MythRect &rect)
Set the minimum area based on the given size.
virtual void Pulse(void)
Pulse is called 70 times a second to trigger a single frame of an animation.
void SetChildNeedsRedraw(MythUIType *child)
static int NormY(int height)
MythFontProperties * GetFont(const QString &text) const
void SetReverseDependence(MythUIType *dependee, bool reverse)
virtual MythRect GetArea(void) const
If the object has a minimum area defined, return it, other wise return the default area.
bool IsDeferredLoading(bool recurse=false) const
virtual void CreateCopy(MythUIType *parent)
Copy the state of this widget to the one given, it must be of the same type.
void SetDependIsDefault(bool isDefault)
QMap< QString, QString > m_dependsMap
virtual MythRect GetFullArea(void) const
void DeleteAllChildren(void)
Delete all child widgets.
int CalcAlpha(int alphamod) const
virtual void SetMinAreaParent(MythRect actual_area, MythRect allowed_area, MythUIType *child)
Adjust the size of sibling objects within the button.
void SetPosition(int x, int y)
Convenience method, calls SetPosition(const MythPoint&) Override that instead to change functionality...
QList< MythUIAnimation * > m_animations
void UpdateDependState(bool isDefault)
void HandleAlphaPulse()
Handle one frame of an alpha (transparency) change animation.
MythUIType * GetChild(const QString &name) const
Get a named child of this UIType.
void SetAlpha(int newalpha)
void SetCentre(UIEffects::Centre centre)
void MoveTo(QPoint destXY, QPoint speedXY)
virtual bool inputMethodEvent(QInputMethodEvent *event)
Input Method event handler.
void DeleteChild(const QString &name)
Delete a named child of this UIType.
void SetHorizontalZoom(float zoom)
void DependChanged(bool isDefault)
virtual void Reset(void)
Reset the widget to it's original state, should not reset changes made by the theme.
virtual bool ParseElement(const QString &filename, QDomElement &element, bool showWarnings)
Parse the xml definition of this widget setting the state of the object accordingly.
void FinishedMoving(void)
QList< MythUIType * > m_childrenList
void FinishedFading(void)
static int NormX(int width)
void SetDeferLoad(bool defer)
virtual void SetMinSize(const MythPoint &size)
Set the minimum size of this widget, for widgets which can be rescaled.
virtual bool keyPressEvent(QKeyEvent *event)
Key event handler.
QList< MythUIType * > GetAllDescendants(void)
virtual MythPoint GetPosition(void) const
QList< QPair< MythUIType *, bool > > m_dependsValue
bool MoveChildToTop(MythUIType *child)
QPointF GetCentre(const QRect rect, int xoff, int yoff) const
static MythRect parseRect(const QString &text, bool normalize=true)
static MythPoint parsePoint(const QString &text, bool normalize=true)
static QString getFirstText(QDomElement &element)
static bool parseBool(const QString &text)
A C++ ripoff of the stroke library for MythTV.
MythPainter * GetMythPainter(void)
MythMainWindow * GetMythMainWindow(void)
Convenience inline random number generator functions.
static QObject * qChildHelper(const char *objName, const char *inheritsClass, bool recursiveSearch, const QObjectList &children)
QMultiMap< int, MythUIType * > FocusInfoType
uint32_t MythRandom()
generate 32 random bits
static eu8 clamp(eu8 value, eu8 low, eu8 high)
#define VERBOSE_XML(type, level, filename, element, msg)