Go to the documentation of this file.
6 #include <QDomDocument>
40 #define LOC QString("MythUIType: ")
49 m_parent = qobject_cast<MythUIType *>(parent);
94 static QObject *
qChildHelper(
const char *objName,
const char *inheritsClass,
95 bool recursiveSearch,
const QObjectList &children)
97 if (children.isEmpty())
100 bool onlyWidgets = (inheritsClass
101 && qstrcmp(inheritsClass,
"QWidget") == 0);
102 const QLatin1String oName(objName);
104 for (
auto *obj : qAsConst(children))
108 if (obj->isWidgetType() && (!objName || obj->objectName() == oName))
111 else if ((!inheritsClass || obj->inherits(inheritsClass))
112 && (!objName || obj->objectName() == oName))
115 if (recursiveSearch && (qobject_cast<MythUIGroup *>(obj) !=
nullptr)
133 QObject *ret =
qChildHelper(name.toLatin1().constData(),
nullptr,
true, children());
136 return qobject_cast<MythUIType *>(ret);
155 if (
type->objectName() == name)
205 QList<MythUIType *>::iterator it;
223 bool focusable)
const
234 QList<MythUIType *>::const_iterator it;
244 if (!(*it)->GetArea().contains(
p -
GetArea().topLeft()))
272 if (animation->GetTrigger() == trigger)
273 animation->Activate();
276 uiType->ActivateAnimations(trigger);
288 QList<MythUIType *>::Iterator it;
291 (*it)->ResetNeedsRedraw();
314 if (childRegion.isEmpty())
449 QList<MythUIAnimation*>::Iterator i;
451 (*i)->IncrementCurrentTime();
453 QList<MythUIType *>::Iterator it;
481 realArea.translate(xoffset, yoffset);
483 if (!realArea.intersects(clipRect))
488 DrawSelf(
p, xoffset, yoffset, alphaMod, clipRect);
490 QList<MythUIType *>::Iterator it;
498 if (
p->ShowBorders())
500 static const QBrush kNullBrush(Qt::NoBrush);
503 p->DrawRect(realArea, kNullBrush, pen, 255);
505 if (
p->ShowTypeNames())
508 font.
SetFace(QFont(
"Droid Sans"));
511 p->DrawText(realArea, objectName(), 0, font, 255, realArea);
515 p->PopTransformation();
556 if (size ==
m_area.size())
615 int delta_w,
int delta_h)
622 QRect bounded(
m_area.x() - delta_x,
625 m_area.height() + delta_h);
630 QPoint center = bounded.center();
632 if (bounded.isNull())
635 bounded.setSize(bounded.size().expandedTo(
GetMinSize()));
637 bounded.moveCenter(center);
640 if (bounded.x() + bounded.width() >
m_area.x() +
m_area.width())
642 if (bounded.y() + bounded.height() >
m_area.y() +
m_area.height())
644 if (bounded.x() <
m_area.x())
646 bounded.moveLeft(
m_area.x());
647 if (bounded.width() >
m_area.width())
648 bounded.setWidth(
m_area.width());
650 if (bounded.y() <
m_area.y())
652 bounded.moveTop(
m_area.y());
653 if (bounded.height() >
m_area.height())
654 bounded.setHeight(
m_area.height());
660 QList<MythUIType *>::iterator it;
664 if (!(*it)->m_initiator)
665 (*it)->AdjustMinArea(delta_x, delta_y, delta_w, delta_h);
680 QList<MythUIType *>::iterator it;
684 if (!(*it)->m_initiator)
685 (*it)->VanishSibling();
716 QList<MythUIType *>::iterator it;
723 if (!(*it)->m_vanished)
726 area = (*it)->GetArea();
728 actual_area = actual_area.united(area);
730 area = (*it)->m_area;
732 allowed_area = allowed_area.united(area);
737 actual_area = actual_area.intersected(
m_area);
738 allowed_area = allowed_area.intersected(
m_area);
740 if (
m_vanish && actual_area.size().isNull())
748 delta_x =
m_area.x() - actual_area.x();
749 delta_y =
m_area.y() - actual_area.y();
750 delta_w = actual_area.width() -
m_area.width();
751 delta_h = actual_area.height() -
m_area.height();
755 delta_x = allowed_area.x() - actual_area.x();
756 delta_y = allowed_area.y() - actual_area.y();
757 delta_w = actual_area.width() - allowed_area.width();
758 delta_h = actual_area.height() - allowed_area.height();
766 if (*it == calling_child)
769 if (!(*it)->m_initiator)
772 (*it)->VanishSibling();
774 (*it)->AdjustMinArea(delta_x, delta_y, delta_w, delta_h);
777 area = (*it)->GetArea();
779 actual_area = actual_area.united(area);
785 actual_area.
setRect(0, 0, 0, 0);
789 QSize bound(actual_area.width(), actual_area.height());
794 actual_area.x() + bound.width(),
795 actual_area.y() + bound.height());
812 bool vanish = (
m_vanish && rect.isNull());
821 QPoint center = bounded.center();
823 if (bounded.isNull())
826 bounded.setSize(bounded.size().expandedTo(
GetMinSize()));
828 bounded.moveCenter(center);
829 if (bounded.x() + bounded.width() >
m_area.x() +
m_area.width())
831 if (bounded.y() + bounded.height() >
m_area.y() +
m_area.height())
833 if (bounded.x() <
m_area.x())
835 bounded.moveLeft(
m_area.x());
836 if (bounded.width() >
m_area.width())
837 bounded.setWidth(
m_area.width());
839 if (bounded.y() <
m_area.y())
841 bounded.moveTop(
m_area.y());
842 if (bounded.height() >
m_area.height())
843 bounded.setHeight(
m_area.height());
856 QSize childSize = rect.size();
857 QSize size =
m_area.size();
859 if (childSize == size)
862 SetSize(size.expandedTo(childSize));
904 if (destXY.x() ==
m_area.x() && destXY.y() ==
m_area.y())
986 QObject::customEvent(event);
1039 bool visible =
false;
1044 visible = reverse ? !isDefault : isDefault;
1065 visible = visible && v;
1070 visible = visible || v;
1081 auto *dependee = qobject_cast<MythUIType*>(sender());
1136 (*it)->AddFocusableChildrenToList(focusList);
1179 QList<MythUIAnimation*>::Iterator i;
1183 animation->CopyFrom(*i);
1187 QList<MythUIType *>::Iterator it;
1197 (*it)->CreateCopy(
this);
1219 const QString &
filename, QDomElement &element,
bool showWarnings)
1223 if (element.tagName() ==
"position")
1225 else if (element.tagName() ==
"area")
1229 else if (element.tagName() ==
"minsize")
1232 if (element.hasAttribute(
"initiator"))
1235 if (element.hasAttribute(
"vanish"))
1240 else if (element.tagName() ==
"alpha")
1245 else if (element.tagName() ==
"alphapulse")
1248 m_alphaMin = element.attribute(
"min",
"0").toInt();
1259 else if (element.tagName() ==
"focusorder")
1264 else if (element.tagName() ==
"loadondemand")
1268 else if (element.tagName() ==
"helptext")
1272 else if (element.tagName() ==
"animation")
1279 QString(
"Unknown widget type '%1'").
arg(element.tagName()));
1322 QList<MythUIType *>::iterator it;
1326 (*it)->RecalculateArea(recurse);
1383 QList<MythUIType *>::Iterator it;
1396 return m_area.contains(point);
1423 QStringList dependees;
1424 QList<int> operators;
1432 QString name = it.value();
1433 QStringList tmp1 = name.split(
"&");
1434 for (
int i = 0; i < tmp1.size(); i++)
1436 QStringList tmp2 = tmp1[i].split(
"|");
1438 dependees.append(tmp2[0]);
1439 for (
int j = 1; j < tmp2.size(); j++)
1441 dependees.append(tmp2[j]);
1442 operators.append(1);
1444 operators.append(2);
1451 for (QString dependeeName : qAsConst(dependees))
1453 bool reverse =
false;
1454 if (dependeeName.startsWith(
'!'))
1457 dependeeName.remove(0,1);
1466 dependant->
m_dependsValue.append(QPair<MythUIType *, bool>(dependee,
false));
1471 dependant->
m_dependsValue.append(QPair<MythUIType *, bool>(dependee, !reverse));
1480 QList<MythUIType *>::iterator child;
1484 (*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)
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
arg(title).arg(filename).arg(doDelete))
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)
MBASE_PUBLIC uint32_t MythRandom()
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
bool AddFont(const QString &text, MythFontProperties *fontProp)
static bool parseBool(const QString &text)
bool IsVisible(bool recurse=false) const
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)