6#include <QtCore/QTimer>
7#include <QtWidgets/QGraphicsOpacityEffect>
8#include <QtWidgets/QWidget>
9#include <QtCore/QParallelAnimationGroup>
10#include <QtCore/QPropertyAnimation>
11#include <QtCore/QVariantAnimation>
14#include <icomp/CComponentBase.h>
17#include <imtbase/TModelUpdateBinder.h>
18#include <imtgui/IClientAreaProvider.h>
19#include <imtgui/IPopupController.h>
20#include <imtgui/IPopupEventHandler.h>
21#include <imtgui/IPopupWidget.h>
28class CPopupControllerComp:
30 public icomp::CComponentBase,
31 virtual public IPopupController
35 typedef icomp::CComponentBase BaseClass;
37 I_BEGIN_COMPONENT(CPopupControllerComp);
38 I_REGISTER_INTERFACE(IPopupController);
39 I_REGISTER_INTERFACE(ilog::IMessageConsumer);
40 I_ASSIGN(m_clientAreaProviderCompPtr,
"ClientArea",
"Desktop area for organizing popups",
false,
"ClientAreaProvider");
41 I_ASSIGN(m_popupWidgetFactoryCompPtr,
"PopupWidgetFactory",
"Widget factory for popup messages and content widgets",
false,
"StandardPopupWidgetFactory");
42 I_ASSIGN_MULTI_0(m_popupEventHandlerCompPtr,
"PopupEventHandler",
"Popup event handlers",
false);
43 I_ASSIGN(m_anchorAttrPtr,
"AnchorCorner",
"0 - TopLeft\n1 - TopRight\n2 - BottomLeft\n3 - BottomRight",
true, 3);
44 I_ASSIGN(m_xRatioAttrPtr,
"HorizontalRatio",
"Horizontal ratio",
true, 0.25);
45 I_ASSIGN(m_yRatioAttrPtr,
"VerticalRatio",
"Vertical ratio",
true, 1);
46 I_ASSIGN(m_spacingAttrPtr,
"Spacing",
"Spacing between adjacent popups",
true, 5);
47 I_ASSIGN(m_defaultTimeoutAttrPtr,
"DefaultTimeout",
"Timeout value in msecs before the popup closes, a zero or negative value requires user action to close",
true, 3000);
50 CPopupControllerComp();
53 virtual QByteArray AddPopup(
const MessagePtr& messagePtr,
int timeout = -1,
bool isClosingOnMouseClickAllowed =
true, QWidget* contentWidgetPtr =
nullptr)
override;
54 virtual void ClosePopup(
const QByteArray& popupId)
override;
55 virtual void RegisterEventHandler(IPopupEventHandler* handlerPtr)
override;
56 virtual void UnRegisterEventHandler(IPopupEventHandler* handlerPtr)
override;
59 virtual bool IsMessageSupported(
60 int messageCategory = -1,
62 const istd::IInformationProvider* messagePtr = NULL)
const override;
63 virtual void AddMessage(
const MessagePtr& messagePtr)
override;
66 virtual void OnComponentCreated()
override;
67 virtual void OnComponentDestroyed()
override;
70 void OnPrimaryScreenChanged();
71 void OnScreenGeometryChanged(
const QRect& geometry);
72 void OnClientAreaUpdated(
const istd::IChangeable::ChangeSet& changeSet,
const IClientAreaProvider* objectPtr);
74 void OnHoverEnter(QEvent* event);
75 void OnHoverLeave(QEvent* event);
76 void OnCloseRequest();
77 void OnPopupTimeout();
78 void OnFadeFinished();
83 void CalculatePopupAreaFromScreen();
84 QByteArray CreatePopupItem(
const MessagePtr& messagePtr,
int timeout,
bool isClosingOnMouseClickAllowed, QWidget* contentWidgetPtr);
85 void RemovePopupItem(
int index);
86 int GetVisibleItemIndex(
const QByteArray&
id);
87 int GetVisibleItemIndex(
const QObject* memberPtr);
89 void ValidateVisibleItems();
90 void ArrangeVisibleItems();
100 fadeAnimation.setTargetObject(&effect);
101 fadeAnimation.setPropertyName(
"opacity");
102 fadeAnimation.setDuration(500);
103 fadeAnimation.setStartValue(0);
104 fadeAnimation.setEndValue(1);
110 fadeAnimation.stop();
112 widgetPtr->deleteLater();
119 QGraphicsOpacityEffect effect;
120 QPropertyAnimation fadeAnimation;
122 typedef istd::TSmartPtr<PopupItem> PopupItemPtr;
125 I_REF(IClientAreaProvider, m_clientAreaProviderCompPtr);
126 I_REF(IPopupWidgetFactory, m_popupWidgetFactoryCompPtr);
127 I_MULTIREF(IPopupEventHandler, m_popupEventHandlerCompPtr);
128 I_ATTR(
int, m_anchorAttrPtr);
129 I_ATTR(
double, m_xRatioAttrPtr);
130 I_ATTR(
double, m_yRatioAttrPtr);
131 I_ATTR(
int, m_spacingAttrPtr);
132 I_ATTR(
int, m_defaultTimeoutAttrPtr);
139 QList<PopupItemPtr> m_items;
140 QList<PopupItemPtr> m_visibleItems;