6 #include <QDomDocument> 39 #define LOC QString("MythUIType: ") 48 m_Parent = dynamic_cast<MythUIType *>(parent);
93 static QObject *
qChildHelper(
const char *objName,
const char *inheritsClass,
94 bool recursiveSearch,
const QObjectList &children)
96 if (children.isEmpty())
99 bool onlyWidgets = (inheritsClass
100 && qstrcmp(inheritsClass,
"QWidget") == 0);
101 const QLatin1String oName(objName);
103 for (
int i = 0; i < children.size(); ++i)
105 QObject *obj = children.at(i);
109 if (obj->isWidgetType() && (!objName || obj->objectName() == oName))
112 else if ((!inheritsClass || obj->inherits(inheritsClass))
113 && (!objName || obj->objectName() == oName))
116 if (recursiveSearch && (dynamic_cast<MythUIGroup *>(obj) !=
nullptr)
134 QObject *ret =
qChildHelper(name.toLatin1().constData(),
nullptr,
true, children());
137 return dynamic_cast<MythUIType *>(ret);
156 if (
type->objectName() == name)
206 QList<MythUIType *>::iterator it;
224 bool focusable)
const 235 QList<MythUIType *>::const_iterator it;
245 if (!(*it)->GetArea().contains(
p -
GetArea().topLeft()))
289 QList<MythUIType *>::Iterator it;
292 (*it)->ResetNeedsRedraw();
315 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();
552 if (size ==
m_Area.size())
611 int delta_w,
int delta_h)
618 QRect bounded(
m_Area.x() - delta_x,
621 m_Area.height() + delta_h);
626 QPoint center = bounded.center();
628 if (bounded.isNull())
631 bounded.setSize(bounded.size().expandedTo(
GetMinSize()));
633 bounded.moveCenter(center);
636 if (bounded.x() + bounded.width() >
m_Area.x() +
m_Area.width())
638 if (bounded.y() + bounded.height() >
m_Area.y() +
m_Area.height())
640 if (bounded.x() <
m_Area.x())
642 bounded.moveLeft(
m_Area.x());
643 if (bounded.width() >
m_Area.width())
644 bounded.setWidth(
m_Area.width());
646 if (bounded.y() <
m_Area.y())
648 bounded.moveTop(
m_Area.y());
649 if (bounded.height() >
m_Area.height())
650 bounded.setHeight(
m_Area.height());
656 QList<MythUIType *>::iterator it;
660 if (!(*it)->m_Initiator)
661 (*it)->AdjustMinArea(delta_x, delta_y, delta_w, delta_h);
676 QList<MythUIType *>::iterator it;
680 if (!(*it)->m_Initiator)
681 (*it)->VanishSibling();
712 QList<MythUIType *>::iterator it;
719 if (!(*it)->m_Vanished)
722 area = (*it)->GetArea();
724 actual_area = actual_area.united(area);
726 area = (*it)->m_Area;
728 allowed_area = allowed_area.united(area);
733 actual_area = actual_area.intersected(
m_Area);
734 allowed_area = allowed_area.intersected(
m_Area);
736 if (
m_Vanish && actual_area.size().isNull())
744 delta_x =
m_Area.x() - actual_area.x();
745 delta_y =
m_Area.y() - actual_area.y();
746 delta_w = actual_area.width() -
m_Area.width();
747 delta_h = actual_area.height() -
m_Area.height();
751 delta_x = allowed_area.x() - actual_area.x();
752 delta_y = allowed_area.y() - actual_area.y();
753 delta_w = actual_area.width() - allowed_area.width();
754 delta_h = actual_area.height() - allowed_area.height();
762 if (*it == calling_child)
765 if (!(*it)->m_Initiator)
768 (*it)->VanishSibling();
770 (*it)->AdjustMinArea(delta_x, delta_y, delta_w, delta_h);
773 area = (*it)->GetArea();
775 actual_area = actual_area.united(area);
781 actual_area.
setRect(0, 0, 0, 0);
785 QSize bound(actual_area.width(), actual_area.height());
790 actual_area.x() + bound.width(),
791 actual_area.y() + bound.height());
808 bool vanish = (
m_Vanish && rect.isNull());
817 QPoint center = bounded.center();
819 if (bounded.isNull())
822 bounded.setSize(bounded.size().expandedTo(
GetMinSize()));
824 bounded.moveCenter(center);
825 if (bounded.x() + bounded.width() >
m_Area.x() +
m_Area.width())
827 if (bounded.y() + bounded.height() >
m_Area.y() +
m_Area.height())
829 if (bounded.x() <
m_Area.x())
831 bounded.moveLeft(
m_Area.x());
832 if (bounded.width() >
m_Area.width())
833 bounded.setWidth(
m_Area.width());
835 if (bounded.y() <
m_Area.y())
837 bounded.moveTop(
m_Area.y());
838 if (bounded.height() >
m_Area.height())
839 bounded.setHeight(
m_Area.height());
852 QSize childSize = rect.size();
853 QSize size =
m_Area.size();
855 if (childSize == size)
858 SetSize(size.expandedTo(childSize));
900 if (destXY.x() ==
m_Area.x() && destXY.y() ==
m_Area.y())
982 QObject::customEvent(event);
1035 bool visible =
false;
1040 visible = reverse ? !isDefault : isDefault;
1060 visible = visible && v;
1065 visible = visible || v;
1076 auto *dependee = static_cast<MythUIType*>(sender());
1129 QList<MythUIType *>::Iterator it;
1132 (*it)->AddFocusableChildrenToList(focusList);
1175 QList<MythUIAnimation*>::Iterator i;
1179 animation->CopyFrom(*i);
1183 QList<MythUIType *>::Iterator it;
1193 (*it)->CreateCopy(
this);
1215 const QString &
filename, QDomElement &element,
bool showWarnings)
1219 if (element.tagName() ==
"position")
1221 else if (element.tagName() ==
"area")
1225 else if (element.tagName() ==
"minsize")
1228 if (element.hasAttribute(
"initiator"))
1231 if (element.hasAttribute(
"vanish"))
1236 else if (element.tagName() ==
"alpha")
1241 else if (element.tagName() ==
"alphapulse")
1244 m_AlphaMin = element.attribute(
"min",
"0").toInt();
1255 else if (element.tagName() ==
"focusorder")
1260 else if (element.tagName() ==
"loadondemand")
1264 else if (element.tagName() ==
"helptext")
1268 else if (element.tagName() ==
"animation")
1275 QString(
"Unknown widget type '%1'").arg(element.tagName()));
1318 QList<MythUIType *>::iterator it;
1322 (*it)->RecalculateArea(recurse);
1379 QList<MythUIType *>::Iterator it;
1392 return m_Area.contains(point);
1424 QStringList dependees;
1425 QList<int> operators;
1426 QString name = it.value();
1427 QStringList tmp1 = name.split(
"&");
1428 for (
int i = 0; i < tmp1.size(); i++)
1430 QStringList tmp2 = tmp1[i].split(
"|");
1432 dependees.append(tmp2[0]);
1433 for (
int j = 1; j < tmp2.size(); j++)
1435 dependees.append(tmp2[j]);
1436 operators.append(1);
1438 operators.append(2);
1445 foreach (QString dependeeName, dependees)
1447 bool reverse =
false;
1448 if (dependeeName.startsWith(
'!'))
1451 dependeeName.remove(0,1);
1460 dependant->
m_dependsValue.append(QPair<MythUIType *, bool>(dependee,
false));
1465 dependant->
m_dependsValue.append(QPair<MythUIType *, bool>(dependee, !reverse));
1474 QList<MythUIType *>::iterator child;
1478 (*child)->ConnectDependants(recurse);
#define VERBOSE_XML(type, level, filename, element, msg)
QPoint toQPoint(void) const
QList< MythUIType * > * GetAllChildren(void)
Return a list of all child widgets.
void CalculateArea(const MythRect &parentArea)
QList< QPair< MythUIType *, bool > > m_dependsValue
void setHeight(const QString &sHeight)
static int NormX(const int width)
QMap< QString, QString > m_dependsMap
bool AddFont(const QString &text, MythFontProperties *fontProp)
virtual MythPainter * GetPainter(void)
void SetDependsMap(QMap< QString, QString > dependsMap)
virtual bool keyPressEvent(QKeyEvent *event)
Key event handler.
void SetVerticalZoom(float zoom)
void SetEnabled(bool enable)
void customEvent(QEvent *event) override
void ResetNeedsRedraw(void)
virtual void SetMinAreaParent(MythRect actual_area, MythRect allowed_area, MythUIType *child)
Adjust the size of sibling objects within the button.
void SetAlpha(int newalpha)
void DeleteChild(const QString &name)
Delete a named child of this UIType.
virtual bool gestureEvent(MythGestureEvent *event)
Mouse click/movement handler, receives mouse gesture events from the QCoreApplication event loop.
bool IsVisible(bool recurse=false) const
void HandleAlphaPulse()
Handle one frame of an alpha (transparency) change animation.
void SetHorizontalZoom(float zoom)
MythPainter * GetMythPainter(void)
void SetReverseDependence(MythUIType *dependee, bool reverse)
int CalcAlpha(int alphamod)
bool AddFont(const QString &text, MythFontProperties *fontProp)
QPointF GetCentre(const QRect &rect, int xoff, int yoff)
void SetColor(const QColor &color)
void DeleteAllChildren(void)
Delete all child widgets.
void UpdateDependState(bool isDefault)
void ConnectDependants(bool recurse=false)
The base class on which all widgets and screens are based.
MythUIType(QObject *parent, const QString &name)
void CalculatePoint(const MythRect &parentArea)
void SetPosition(int x, int y)
Convenience method, calls SetPosition(const MythPoint&) Override that instead to change functionality...
QList< MythUIAnimation * > m_animations
static MythPoint parsePoint(const QString &text, bool normalize=true)
void AddFocusableChildrenToList(QMap< int, MythUIType * > &focusList)
virtual void CreateCopy(MythUIType *parent)
Copy the state of this widget to the one given, it must be of the same type.
virtual QRegion GetDirtyArea(void) const
virtual void SetVisible(bool visible)
QRect toQRect(void) const
void setRect(const QString &sX, const QString &sY, const QString &sWidth, const QString &sHeight, const QString &baseRes=QString())
virtual void mediaEvent(MythMediaEvent *event)
Media/Device status event handler, received from MythMediaMonitor.
static void ParseElement(const QDomElement &element, MythUIType *parent)
A C++ ripoff of the stroke library for MythTV.
static int NormY(const int height)
virtual void VanishSibling(void)
virtual void SetMinArea(const MythRect &rect)
Set the minimum area based on the given size.
virtual MythRect GetArea(void) const
If the object has a minimum area defined, return it, other wise return the default area.
void DependChanged(bool isDefault)
static QString getFirstText(QDomElement &element)
virtual void SetSize(const QSize &size)
static QObject * qChildHelper(const char *objName, const char *inheritsClass, bool recursiveSearch, const QObjectList &children)
virtual void Pulse(void)
Pulse is called 70 times a second to trigger a single frame of an animation.
Wrapper around QRect allowing us to handle percentage and other relative values for areas in mythui.
void MoveTo(QPoint destXY, QPoint speedXY)
bool MoveChildToTop(MythUIType *child)
virtual void SetMinSize(const MythPoint &size)
Set the minimum size of this widget, for widgets which can be rescaled.
void moveLeft(const QString &sX)
MythUIType * GetChildAt(const QPoint &p, bool recursive=true, bool focusable=true) const
Return the first MythUIType at the given coordinates.
virtual void RecalculateArea(bool recurse=true)
void ExpandArea(const MythRect &rect)
virtual void AdjustMinArea(int delta_x, int delta_y, int delta_w, int delta_h)
Adjust the size of a sibling.
void setWidth(const QString &sWidth)
virtual void DrawSelf(MythPainter *p, int xoffset, int yoffset, int alphaMod, QRect clipRect)
A custom event that represents a mouse gesture.
virtual QSize GetMinSize(void) const
void AdjustAlpha(int mode, int alphachange, int minalpha=0, int maxalpha=255)
void HandleMovementPulse()
Handle one frame of a movement animation.
virtual void LoadNow(void)
Cause images in this and child widgets to be loaded.
MythMainWindow * GetMythMainWindow(void)
MythFontProperties * GetFont(const QString &text) const
virtual void SetArea(const MythRect &rect)
bool CanTakeFocus(void) const
Return if this widget can accept input focus.
virtual void Reset(void)
Reset the widget to it's original state, should not reset changes made by the theme.
void SetDeferLoad(bool defer)
bool IsDeferredLoading(bool recurse=false) const
void SetFace(const QFont &face)
virtual MythPoint GetPosition(void) const
MythFontProperties * GetFont(const QString &text)
virtual MythRect GetFullArea(void) const
QMap< MythUIType *, bool > m_ReverseDepend
MythPoint topLeft(void) const
void moveTopLeft(const MythPoint &point)
Trigger GetTrigger(void) const
virtual void CopyFrom(MythUIType *base)
Copy this widgets state from another.
bool NeedsRedraw(void) const
bool IsEnabled(void) const
static MythRect parseRect(const QString &text, bool normalize=true)
Wrapper around QPoint allowing us to handle percentage and other relative values for positioning in m...
void SetChildNeedsRedraw(MythUIType *child)
static long int random(void)
void SetDependIsDefault(bool isDefault)
void Draw(MythPainter *p, int xoffset, int yoffset, int alphaMod=255, QRect clipRect=QRect())
bool ContainsPoint(const QPoint &point) const
Check if the given point falls within this widgets area.
void ActivateAnimations(MythUIAnimation::Trigger trigger)
void moveTop(const QString &sY)
void SetAngle(float angle)
MythUIType * GetChild(const QString &name) const
Get a named child of this UIType.
QList< int > m_dependOperator
static bool parseBool(const QString &text)
void SetCanTakeFocus(bool set=true)
Set whether this widget can take focus.
QList< MythUIType * > m_ChildrenList
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 SetCentre(UIEffects::Centre centre)
void SetPointSize(uint points)
void AddChild(MythUIType *child)
Add a child UIType.
virtual void Finalize(void)
Perform any post-xml parsing initialisation tasks.