Go to the documentation of this file.
9 #include <QDomDocument>
12 #include <QInputMethodEvent>
41 #define LOC QString("MythUIType: ")
50 m_parent = qobject_cast<MythUIType *>(parent);
96 static QObject *
qChildHelper(
const char *objName,
const char *inheritsClass,
97 bool recursiveSearch,
const QObjectList &children)
99 if (children.isEmpty())
102 bool onlyWidgets = (inheritsClass
103 && qstrcmp(inheritsClass,
"QWidget") == 0);
104 const QLatin1String oName(objName);
106 for (
auto *obj : qAsConst(children))
110 if (obj->isWidgetType() && (!objName || obj->objectName() == oName))
113 else if ((!inheritsClass || obj->inherits(inheritsClass))
114 && (!objName || obj->objectName() == oName))
117 if (recursiveSearch && (qobject_cast<MythUIGroup *>(obj) !=
nullptr)
135 QObject *ret =
qChildHelper(name.toLatin1().constData(),
nullptr,
true, children());
138 return qobject_cast<MythUIType *>(ret);
157 if (
type->objectName() == name)
204 QList<MythUIType *> descendants {};
209 descendants += item->GetAllDescendants();
219 QList<MythUIType *>::iterator it;
237 bool focusable)
const
248 QList<MythUIType *>::const_reverse_iterator it;
258 if (!(*it)->GetArea().contains(
p -
GetArea().topLeft()))
286 if (animation->GetTrigger() == trigger)
287 animation->Activate();
290 uiType->ActivateAnimations(trigger);
302 QList<MythUIType *>::Iterator it;
305 (*it)->ResetNeedsRedraw();
328 if (childRegion.isEmpty())
463 QList<MythUIAnimation*>::Iterator i;
465 (*i)->IncrementCurrentTime();
467 QList<MythUIType *>::Iterator it;
495 realArea.translate(xoffset, yoffset);
497 if (!realArea.intersects(clipRect))
502 DrawSelf(
p, xoffset, yoffset, alphaMod, clipRect);
504 QList<MythUIType *>::Iterator it;
512 if (
p->ShowBorders())
514 static const QBrush kNullBrush(Qt::NoBrush);
517 p->DrawRect(realArea, kNullBrush, pen, 255);
519 if (
p->ShowTypeNames())
522 font.
SetFace(QFont(
"Droid Sans"));
525 p->DrawText(realArea, objectName(), 0, font, 255, realArea);
529 p->PopTransformation();
570 if (size ==
m_area.size())
629 int delta_w,
int delta_h)
636 QRect bounded(
m_area.x() - delta_x,
639 m_area.height() + delta_h);
644 QPoint center = bounded.center();
646 if (bounded.isNull())
649 bounded.setSize(bounded.size().expandedTo(
GetMinSize()));
651 bounded.moveCenter(center);
654 if (bounded.x() + bounded.width() >
m_area.x() +
m_area.width())
656 if (bounded.y() + bounded.height() >
m_area.y() +
m_area.height())
658 if (bounded.x() <
m_area.x())
660 bounded.moveLeft(
m_area.x());
661 if (bounded.width() >
m_area.width())
662 bounded.setWidth(
m_area.width());
664 if (bounded.y() <
m_area.y())
666 bounded.moveTop(
m_area.y());
667 if (bounded.height() >
m_area.height())
668 bounded.setHeight(
m_area.height());
674 QList<MythUIType *>::iterator it;
678 if (!(*it)->m_initiator)
679 (*it)->AdjustMinArea(delta_x, delta_y, delta_w, delta_h);
694 QList<MythUIType *>::iterator it;
698 if (!(*it)->m_initiator)
699 (*it)->VanishSibling();
730 QList<MythUIType *>::iterator it;
737 if (!(*it)->m_vanished)
740 area = (*it)->GetArea();
742 actual_area = actual_area.united(area);
744 area = (*it)->m_area;
746 allowed_area = allowed_area.united(area);
751 actual_area = actual_area.intersected(
m_area);
752 allowed_area = allowed_area.intersected(
m_area);
754 if (
m_vanish && actual_area.size().isNull())
762 delta_x =
m_area.x() - actual_area.x();
763 delta_y =
m_area.y() - actual_area.y();
764 delta_w = actual_area.width() -
m_area.width();
765 delta_h = actual_area.height() -
m_area.height();
769 delta_x = allowed_area.x() - actual_area.x();
770 delta_y = allowed_area.y() - actual_area.y();
771 delta_w = actual_area.width() - allowed_area.width();
772 delta_h = actual_area.height() - allowed_area.height();
780 if (*it == calling_child)
783 if (!(*it)->m_initiator)
786 (*it)->VanishSibling();
788 (*it)->AdjustMinArea(delta_x, delta_y, delta_w, delta_h);
791 area = (*it)->GetArea();
793 actual_area = actual_area.united(area);
799 actual_area.
setRect(0, 0, 0, 0);
803 QSize bound(actual_area.width(), actual_area.height());
808 actual_area.x() + bound.width(),
809 actual_area.y() + bound.height());
826 bool vanish = (
m_vanish && rect.isNull());
835 QPoint center = bounded.center();
837 if (bounded.isNull())
840 bounded.setSize(bounded.size().expandedTo(
GetMinSize()));
842 bounded.moveCenter(center);
843 if (bounded.x() + bounded.width() >
m_area.x() +
m_area.width())
845 if (bounded.y() + bounded.height() >
m_area.y() +
m_area.height())
847 if (bounded.x() <
m_area.x())
849 bounded.moveLeft(
m_area.x());
850 if (bounded.width() >
m_area.width())
851 bounded.setWidth(
m_area.width());
853 if (bounded.y() <
m_area.y())
855 bounded.moveTop(
m_area.y());
856 if (bounded.height() >
m_area.height())
857 bounded.setHeight(
m_area.height());
870 QSize childSize = rect.size();
871 QSize size =
m_area.size();
873 if (childSize == size)
876 SetSize(size.expandedTo(childSize));
918 if (destXY.x() ==
m_area.x() && destXY.y() ==
m_area.y())
1008 QObject::customEvent(event);
1061 bool visible =
false;
1066 visible = reverse ? !isDefault : isDefault;
1087 visible = visible && v;
1092 visible = visible || v;
1103 auto *dependee = qobject_cast<MythUIType*>(sender());
1158 (*it)->AddFocusableChildrenToList(focusList);
1201 QList<MythUIAnimation*>::Iterator i;
1205 animation->CopyFrom(*i);
1209 QList<MythUIType *>::Iterator it;
1219 (*it)->CreateCopy(
this);
1241 const QString &
filename, QDomElement &element,
bool showWarnings)
1245 if (element.tagName() ==
"position")
1247 else if (element.tagName() ==
"area")
1251 else if (element.tagName() ==
"minsize")
1254 if (element.hasAttribute(
"initiator"))
1257 if (element.hasAttribute(
"vanish"))
1262 else if (element.tagName() ==
"alpha")
1267 else if (element.tagName() ==
"alphapulse")
1270 m_alphaMin = element.attribute(
"min",
"0").toInt();
1281 else if (element.tagName() ==
"focusorder")
1286 else if (element.tagName() ==
"loadondemand")
1290 else if (element.tagName() ==
"helptext")
1294 else if (element.tagName() ==
"animation")
1301 QString(
"Unknown widget type '%1'").arg(element.tagName()));
1344 QList<MythUIType *>::iterator it;
1348 (*it)->RecalculateArea(recurse);
1405 QList<MythUIType *>::Iterator it;
1418 return m_area.contains(point);
1445 QStringList dependees;
1446 QList<int> operators;
1454 QString name = it.value();
1455 QStringList tmp1 = name.split(
"&");
1456 for (
const QString& t1 : qAsConst(tmp1))
1458 QStringList tmp2 = t1.split(
"|");
1460 dependees.append(tmp2[0]);
1461 for (
int j = 1; j < tmp2.size(); j++)
1463 dependees.append(tmp2[j]);
1464 operators.append(1);
1466 operators.append(2);
1473 for (QString dependeeName : qAsConst(dependees))
1475 bool reverse =
false;
1476 if (dependeeName.startsWith(
'!'))
1479 dependeeName.remove(0,1);
1488 dependant->
m_dependsValue.append(QPair<MythUIType *, bool>(dependee,
false));
1493 dependant->
m_dependsValue.append(QPair<MythUIType *, bool>(dependee, !reverse));
1502 QList<MythUIType *>::iterator child;
1506 (*child)->ConnectDependants(recurse);
virtual bool keyPressEvent(QKeyEvent *event)
Key event handler.
void SetReverseDependence(MythUIType *dependee, bool reverse)
bool CanTakeFocus(void) const
Return if this widget can accept input focus.
void AddFocusableChildrenToList(FocusInfoType &focusList)
virtual bool inputMethodEvent(QInputMethodEvent *event)
Input Method event handler.
static MythPoint parsePoint(const QString &text, bool normalize=true)
virtual void mediaEvent(MythMediaEvent *event)
Media/Device status event handler, received from MythMediaMonitor.
void DeleteChild(const QString &name)
Delete a named child of this UIType.
void ConnectDependants(bool recurse=false)
void SetDependIsDefault(bool isDefault)
MythUIType * GetChildAt(QPoint p, bool recursive=true, bool focusable=true) const
Return the first MythUIType at the given coordinates.
virtual QRegion GetDirtyArea(void) const
virtual MythRect GetFullArea(void) const
int CalcAlpha(int alphamod) const
void setRect(const QString &sX, const QString &sY, const QString &sWidth, const QString &sHeight, const QString &baseRes=QString())
QRect toQRect(void) const
void UpdateDependState(bool isDefault)
MythUIType * GetChild(const QString &name) const
Get a named child of this UIType.
void SetFace(const QFont &face)
QList< MythUIAnimation * > m_animations
QPoint toQPoint(void) const
virtual MythPainter * GetPainter(void)
void SetCanTakeFocus(bool set=true)
Set whether this widget can take focus.
void customEvent(QEvent *event) override
bool AddFont(const QString &text, MythFontProperties *fontProp)
virtual void SetArea(const MythRect &rect)
static void ParseElement(const QDomElement &element, MythUIType *parent)
QList< MythUIType * > * GetAllChildren(void)
Return a list of all child widgets.
void SetColor(const QColor &color)
MythUIType(QObject *parent, const QString &name)
void ResetNeedsRedraw(void)
void CalculatePoint(QRect parentArea)
Wrapper around QRect allowing us to handle percentage and other relative values for areas in mythui.
virtual void Pulse(void)
Pulse is called 70 times a second to trigger a single frame of an animation.
virtual void CreateCopy(MythUIType *parent)
Copy the state of this widget to the one given, it must be of the same type.
virtual void DrawSelf(MythPainter *p, int xoffset, int yoffset, int alphaMod, QRect clipRect)
void DeleteAllChildren(void)
Delete all child widgets.
virtual void VanishSibling(void)
virtual void AdjustMinArea(int delta_x, int delta_y, int delta_w, int delta_h)
Adjust the size of a sibling.
void ExpandArea(QRect rect)
void moveLeft(const QString &sX)
virtual MythRect GetArea(void) const
If the object has a minimum area defined, return it, other wise return the default area.
static QObject * qChildHelper(const char *objName, const char *inheritsClass, bool recursiveSearch, const QObjectList &children)
void AddChild(MythUIType *child)
Add a child UIType.
void ActivateAnimations(MythUIAnimation::Trigger trigger)
void SetAlpha(int newalpha)
virtual void SetMinArea(const MythRect &rect)
Set the minimum area based on the given size.
void DependChanged(bool isDefault)
void SetPosition(int x, int y)
Convenience method, calls SetPosition(const MythPoint&) Override that instead to change functionality...
bool IsEnabled(void) const
#define VERBOSE_XML(type, level, filename, element, msg)
void moveTop(const QString &sY)
void AdjustAlpha(int mode, int alphachange, int minalpha=0, int maxalpha=255)
static QString getFirstText(QDomElement &element)
virtual QSize GetMinSize(void) const
virtual MythPoint GetPosition(void) const
void setHeight(const QString &sHeight)
static int NormY(int height)
QPointF GetCentre(const QRect rect, int xoff, int yoff) const
void CalculateArea(QRect parentArea)
QList< MythUIType * > m_childrenList
virtual void CopyFrom(MythUIType *base)
Copy this widgets state from another.
void SetEnabled(bool enable)
static MythRect parseRect(const QString &text, bool normalize=true)
A C++ ripoff of the stroke library for MythTV.
virtual void Reset(void)
Reset the widget to it's original state, should not reset changes made by the theme.
MythFontProperties * GetFont(const QString &text)
virtual void RecalculateArea(bool recurse=true)
The base class on which all widgets and screens are based.
bool IsDeferredLoading(bool recurse=false) const
void SetDependsMap(QMap< QString, QString > dependsMap)
QList< int > m_dependOperator
virtual void SetMinAreaParent(MythRect actual_area, MythRect allowed_area, MythUIType *child)
Adjust the size of sibling objects within the button.
QMap< QString, QString > m_dependsMap
MythPoint topLeft(void) const
void setWidth(const QString &sWidth)
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.
QMultiMap< int, MythUIType * > FocusInfoType
virtual void SetSize(QSize size)
void SetDeferLoad(bool defer)
void HandleAlphaPulse()
Handle one frame of an alpha (transparency) change animation.
virtual void SetVisible(bool visible)
void SetChildNeedsRedraw(MythUIType *child)
QList< QPair< MythUIType *, bool > > m_dependsValue
MythMainWindow * GetMythMainWindow(void)
QMap< MythUIType *, bool > m_reverseDepend
bool ContainsPoint(QPoint point) const
Check if the given point falls within this widgets area.
virtual void SetMinSize(const MythPoint &size)
Set the minimum size of this widget, for widgets which can be rescaled.
void SetHorizontalZoom(float zoom)
MythFontProperties * GetFont(const QString &text) const
void SetCentre(UIEffects::Centre centre)
A custom event that represents a mouse gesture.
void Draw(MythPainter *p, int xoffset, int yoffset, int alphaMod=255, QRect clipRect=QRect())
void SetAngle(float angle)
static int NormX(int width)
void moveTopLeft(QPoint point)
MythPainter * GetMythPainter(void)
void SetVerticalZoom(float zoom)
void SetFocusOrder(int order)
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 VisibilityChanged(bool Visible)
void SetPointSize(uint points)
bool MoveChildToTop(MythUIType *child)
bool NeedsRedraw(void) const
QList< MythUIType * > GetAllDescendants(void)
bool AddFont(const QString &text, MythFontProperties *fontProp)
static bool parseBool(const QString &text)
bool IsVisible(bool recurse=false) const
uint32_t MythRandom()
generate 32 random bits
virtual void Finalize(void)
Perform any post-xml parsing initialisation tasks.
void HandleMovementPulse()
Handle one frame of a movement animation.
Wrapper around QPoint allowing us to handle percentage and other relative values for positioning in m...
void MoveTo(QPoint destXY, QPoint speedXY)