simplify
This commit is contained in:
parent
1f2f706c10
commit
b233c6e735
@ -118,7 +118,7 @@ void DialogProxy::setVisualParent(QQuickItem *visualParent)
|
|||||||
m_visualParent = visualParent;
|
m_visualParent = visualParent;
|
||||||
emit visualParentChanged();
|
emit visualParentChanged();
|
||||||
if (visualParent && isVisible()) {
|
if (visualParent && isVisible()) {
|
||||||
adjustPosition(popupPosition(visualParent, Qt::AlignCenter));
|
adjustGeometry(QRect(popupPosition(visualParent, Qt::AlignCenter), size()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -142,9 +142,7 @@ void DialogProxy::onVisibleChanged()
|
|||||||
syncMainItemToSize();
|
syncMainItemToSize();
|
||||||
m_cachedGeometry = QRect();
|
m_cachedGeometry = QRect();
|
||||||
}
|
}
|
||||||
if (m_visualParent) {
|
|
||||||
adjustPosition(popupPosition(m_visualParent.data(), Qt::AlignCenter));
|
|
||||||
}
|
|
||||||
syncToMainItemSize();
|
syncToMainItemSize();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -317,9 +315,9 @@ QObject *DialogProxy::margins() const
|
|||||||
return m_frameSvgItem->margins();
|
return m_frameSvgItem->margins();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DialogProxy::adjustPosition(const QPoint &point)
|
void DialogProxy::adjustGeometry(const QRect &geom)
|
||||||
{
|
{
|
||||||
setPosition(point);
|
setGeometry(geom);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DialogProxy::resizeEvent(QResizeEvent *re)
|
void DialogProxy::resizeEvent(QResizeEvent *re)
|
||||||
@ -353,9 +351,11 @@ void DialogProxy::syncToMainItemSize()
|
|||||||
const QSize s = QSize(m_mainItem.data()->width(), m_mainItem.data()->height()) +
|
const QSize s = QSize(m_mainItem.data()->width(), m_mainItem.data()->height()) +
|
||||||
QSize(m_frameSvgItem->margins()->left() + m_frameSvgItem->margins()->right(),
|
QSize(m_frameSvgItem->margins()->left() + m_frameSvgItem->margins()->right(),
|
||||||
m_frameSvgItem->margins()->top() + m_frameSvgItem->margins()->bottom());
|
m_frameSvgItem->margins()->top() + m_frameSvgItem->margins()->bottom());
|
||||||
resize(s);
|
|
||||||
if (visualParent()) {
|
if (visualParent()) {
|
||||||
adjustPosition(popupPosition(visualParent(), Qt::AlignCenter));
|
adjustGeometry(QRect(popupPosition(visualParent(), Qt::AlignCenter), s));
|
||||||
|
} else {
|
||||||
|
resize(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
emit widthChanged(s.width());
|
emit widthChanged(s.width());
|
||||||
|
@ -108,7 +108,7 @@ public:
|
|||||||
/*
|
/*
|
||||||
* set the dialog position. subclasses may change it. ToolTipDialog adjusts the position in an animated way
|
* set the dialog position. subclasses may change it. ToolTipDialog adjusts the position in an animated way
|
||||||
*/
|
*/
|
||||||
virtual void adjustPosition(const QPoint &point);
|
virtual void adjustGeometry(const QRect &geom);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @returns The suggested screen position for the popup
|
* @returns The suggested screen position for the popup
|
||||||
|
@ -100,38 +100,22 @@ void ToolTipDialog::hideEvent(QHideEvent *event)
|
|||||||
|
|
||||||
void ToolTipDialog::resizeEvent(QResizeEvent *re)
|
void ToolTipDialog::resizeEvent(QResizeEvent *re)
|
||||||
{
|
{
|
||||||
//TODO: less duplication
|
DialogProxy::resizeEvent(re);
|
||||||
if (!m_animation) {
|
}
|
||||||
m_animation = new QPropertyAnimation(this);
|
|
||||||
connect(m_animation, SIGNAL(valueChanged(QVariant)),
|
|
||||||
this, SLOT(valueChanged(QVariant)));
|
|
||||||
m_animation->setTargetObject(this);
|
|
||||||
m_animation->setEasingCurve(QEasingCurve::InOutQuad);
|
|
||||||
m_animation->setDuration(250);
|
|
||||||
}
|
|
||||||
m_animation->stop();
|
|
||||||
|
|
||||||
|
void ToolTipDialog::adjustGeometry(const QRect &geom)
|
||||||
|
{
|
||||||
switch (m_direction) {
|
switch (m_direction) {
|
||||||
case Plasma::Types::Right:
|
case Plasma::Types::Right:
|
||||||
setX(x() + (re->oldSize().width() - re->size().width()));
|
setX(x() + (size().width() - geom.size().width()));
|
||||||
break;
|
break;
|
||||||
case Plasma::Types::Up:
|
case Plasma::Types::Up:
|
||||||
setY(y() + (re->oldSize().height() - re->size().height()));
|
setY(y() + (size().height() - geom.size().height()));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isVisible()) {
|
|
||||||
m_animation->setStartValue(position());
|
|
||||||
m_animation->setEndValue(popupPosition(visualParent(), Qt::AlignCenter));
|
|
||||||
m_animation->start();
|
|
||||||
}
|
|
||||||
DialogProxy::resizeEvent(re);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ToolTipDialog::adjustPosition(const QPoint &point)
|
|
||||||
{
|
|
||||||
if (isVisible()) {
|
if (isVisible()) {
|
||||||
if (!m_animation) {
|
if (!m_animation) {
|
||||||
m_animation = new QPropertyAnimation(this);
|
m_animation = new QPropertyAnimation(this);
|
||||||
@ -142,11 +126,14 @@ void ToolTipDialog::adjustPosition(const QPoint &point)
|
|||||||
m_animation->setDuration(250);
|
m_animation->setDuration(250);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
resize(geom.size());
|
||||||
|
|
||||||
m_animation->setStartValue(position());
|
m_animation->setStartValue(position());
|
||||||
m_animation->setEndValue(point);
|
m_animation->setEndValue(geom.topLeft());
|
||||||
m_animation->start();
|
m_animation->start();
|
||||||
} else {
|
} else {
|
||||||
setPosition(point);
|
setGeometry(geom);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ public:
|
|||||||
/**
|
/**
|
||||||
* animate the position change if visible
|
* animate the position change if visible
|
||||||
*/
|
*/
|
||||||
virtual void adjustPosition(const QPoint &point);
|
virtual void adjustGeometry(const QRect &geom);
|
||||||
|
|
||||||
static ToolTipDialog* instance();
|
static ToolTipDialog* instance();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user