Disable borders when we're hitting the screen's edge
This commit is contained in:
parent
d6b66ecb96
commit
2032816118
@ -63,7 +63,7 @@ QString locString(const Plasma::Location l) {
|
|||||||
DialogProxy::DialogProxy(QQuickItem *parent)
|
DialogProxy::DialogProxy(QQuickItem *parent)
|
||||||
: QQuickWindow(),
|
: QQuickWindow(),
|
||||||
m_activeWindow(false),
|
m_activeWindow(false),
|
||||||
m_location(Plasma::LeftEdge)
|
m_location(Plasma::TopEdge)
|
||||||
{
|
{
|
||||||
QSurfaceFormat format;
|
QSurfaceFormat format;
|
||||||
format.setAlphaBufferSize(8);
|
format.setAlphaBufferSize(8);
|
||||||
@ -76,16 +76,15 @@ DialogProxy::DialogProxy(QQuickItem *parent)
|
|||||||
|
|
||||||
m_syncTimer = new QTimer(this);
|
m_syncTimer = new QTimer(this);
|
||||||
m_syncTimer->setSingleShot(true);
|
m_syncTimer->setSingleShot(true);
|
||||||
m_syncTimer->setInterval(2500);
|
m_syncTimer->setInterval(250);
|
||||||
connect(m_syncTimer, &QTimer::timeout, this, &DialogProxy::syncToMainItemSize);
|
connect(m_syncTimer, &QTimer::timeout, this, &DialogProxy::syncToMainItemSize);
|
||||||
|
|
||||||
//HACK: this property is invoked due to the initialization that gets done to contentItem() in the getter
|
//HACK: this property is invoked due to the initialization that gets done to contentItem() in the getter
|
||||||
property("data");
|
property("data");
|
||||||
//Create the FrameSvg background.
|
//Create the FrameSvg background.
|
||||||
m_frameSvgItem = new Plasma::FrameSvgItem(contentItem());
|
m_frameSvgItem = new Plasma::FrameSvgItem(contentItem());
|
||||||
//m_frameSvgItem->setImagePath("dialogs/background");
|
m_frameSvgItem->setImagePath("dialogs/background");
|
||||||
m_frameSvgItem->setImagePath("widgets/background");
|
//m_frameSvgItem->setImagePath("widgets/background"); // larger borders, for testing those
|
||||||
setVisualParent(parent);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DialogProxy::~DialogProxy()
|
DialogProxy::~DialogProxy()
|
||||||
@ -99,14 +98,11 @@ QQuickItem *DialogProxy::mainItem() const
|
|||||||
|
|
||||||
void DialogProxy::setMainItem(QQuickItem *mainItem)
|
void DialogProxy::setMainItem(QQuickItem *mainItem)
|
||||||
{
|
{
|
||||||
qDebug() << "XXXXX Main ITem: " << mainItem->width() << mainItem->height();
|
|
||||||
if (m_mainItem.data() != mainItem) {
|
if (m_mainItem.data() != mainItem) {
|
||||||
qDebug() << "YYYYY Main ITem: " << mainItem->width() << mainItem->height();
|
|
||||||
if (m_mainItem) {
|
if (m_mainItem) {
|
||||||
m_mainItem.data()->setParent(parent());
|
m_mainItem.data()->setParent(parent());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
m_mainItem = mainItem;
|
m_mainItem = mainItem;
|
||||||
|
|
||||||
if (mainItem) {
|
if (mainItem) {
|
||||||
@ -146,7 +142,6 @@ QQuickItem *DialogProxy::visualParent() const
|
|||||||
|
|
||||||
void DialogProxy::setVisualParent(QQuickItem *visualParent)
|
void DialogProxy::setVisualParent(QQuickItem *visualParent)
|
||||||
{
|
{
|
||||||
qDebug() << "Settting Parent.....";
|
|
||||||
if (m_visualParent.data() == visualParent) {
|
if (m_visualParent.data() == visualParent) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -167,47 +162,39 @@ bool DialogProxy::isVisible() const
|
|||||||
void DialogProxy::setVisible(const bool visible)
|
void DialogProxy::setVisible(const bool visible)
|
||||||
{
|
{
|
||||||
qDebug() << visible;
|
qDebug() << visible;
|
||||||
|
QRect avail = QRect(400, 300, 1200, 800);
|
||||||
if (visible) {
|
if (visible) {
|
||||||
m_frameSvgItem->setEnabledBorders(Plasma::FrameSvg::AllBorders);
|
if (!m_visualParent.isNull()) {
|
||||||
syncToMainItemSize();
|
avail = m_visualParent.data()->window()->screen()->availableGeometry();
|
||||||
QPoint p = popupPosition(m_visualParent.data(), Qt::AlignCenter);
|
if (location() == Plasma::FullScreen) {
|
||||||
|
m_frameSvgItem->setEnabledBorders(Plasma::FrameSvg::NoBorder);
|
||||||
|
setGeometry(avail);
|
||||||
|
|
||||||
const QRect avail = m_visualParent.data()->window()->screen()->availableGeometry();
|
} else {
|
||||||
int borders = Plasma::FrameSvg::AllBorders;
|
m_frameSvgItem->setEnabledBorders(Plasma::FrameSvg::AllBorders);
|
||||||
if (p.x() <= 0) {
|
syncToMainItemSize();
|
||||||
//m_frameSvgItem->setEnabledBorders(Plasma::FrameSvg::TopBorder | Plasma::FrameSvg::RightBorder | Plasma::FrameSvg::BottomBorder);
|
QPoint p = popupPosition(m_visualParent.data(), Qt::AlignCenter);
|
||||||
//m_frameSvgItem->setEnabledBorders(Plasma::FrameSvg::AllBorders & ~Plasma::FrameSvg::LeftBorder);
|
|
||||||
borders = borders & ~Plasma::FrameSvg::LeftBorder;
|
|
||||||
}
|
|
||||||
if (p.y() <= 0) {
|
|
||||||
//m_frameSvgItem->setEnabledBorders(Plasma::FrameSvg::LeftBorder | Plasma::FrameSvg::RightBorder | Plasma::FrameSvg::BottomBorder);
|
|
||||||
//m_frameSvgItem->setEnabledBorders(Plasma::FrameSvg::AllBorders & ~Plasma::FrameSvg::TopBorder);
|
|
||||||
borders = borders & ~Plasma::FrameSvg::TopBorder;
|
|
||||||
|
|
||||||
}
|
int borders = Plasma::FrameSvg::AllBorders;
|
||||||
if (avail.width() <= p.x() + m_visualParent.data()->width()) {
|
if (p.x() <= 0) {
|
||||||
//m_frameSvgItem->setEnabledBorders(Plasma::FrameSvg::LeftBorder | Plasma::FrameSvg::TopBorder | Plasma::FrameSvg::BottomBorder);
|
borders = borders & ~Plasma::FrameSvg::LeftBorder;
|
||||||
borders = borders & ~Plasma::FrameSvg::RightBorder;
|
}
|
||||||
|
if (p.y() <= 0) {
|
||||||
}
|
borders = borders & ~Plasma::FrameSvg::TopBorder;
|
||||||
if (avail.height() <= p.y() + m_visualParent.data()->height()) {
|
}
|
||||||
borders = borders & ~Plasma::FrameSvg::BottomBorder;
|
if (avail.width() <= p.x() + m_visualParent.data()->width()) {
|
||||||
|
borders = borders & ~Plasma::FrameSvg::RightBorder;
|
||||||
//m_frameSvgItem->setEnabledBorders(Plasma::FrameSvg::LeftBorder | Plasma::FrameSvg::RightBorder | Plasma::FrameSvg::TopBorder);
|
}
|
||||||
}
|
if (avail.height() <= p.y() + m_visualParent.data()->height()) {
|
||||||
m_frameSvgItem->setEnabledBorders((Plasma::FrameSvg::EnabledBorder)borders);
|
borders = borders & ~Plasma::FrameSvg::BottomBorder;
|
||||||
syncToMainItemSize();
|
}
|
||||||
// enum EnabledBorder {
|
m_frameSvgItem->setEnabledBorders((Plasma::FrameSvg::EnabledBorder)borders);
|
||||||
// NoBorder = 0,
|
syncToMainItemSize();
|
||||||
// TopBorder = 1,
|
setPosition(popupPosition(m_visualParent.data(), Qt::AlignCenter));
|
||||||
// BottomBorder = 2,
|
}
|
||||||
// LeftBorder = 4,
|
} else {
|
||||||
// RightBorder = 8,
|
// no visual parent -> center on screen
|
||||||
// AllBorders = TopBorder | BottomBorder | LeftBorder | RightBorder
|
setPosition((avail.width() - width()) / 2, (avail.height() - height()) / 2);
|
||||||
// };
|
|
||||||
|
|
||||||
if (m_visualParent) {
|
|
||||||
setPosition(popupPosition(m_visualParent.data(), Qt::AlignCenter));
|
|
||||||
}
|
}
|
||||||
raise();
|
raise();
|
||||||
}
|
}
|
||||||
@ -220,21 +207,16 @@ QPoint DialogProxy::popupPosition(QQuickItem *item, Qt::AlignmentFlag alignment)
|
|||||||
//If no item was specified try to align at the center of the parent view
|
//If no item was specified try to align at the center of the parent view
|
||||||
QQuickItem *parentItem = qobject_cast<QQuickItem *>(parent());
|
QQuickItem *parentItem = qobject_cast<QQuickItem *>(parent());
|
||||||
if (parentItem && parentItem->window()) {
|
if (parentItem && parentItem->window()) {
|
||||||
qDebug() << "no item, popping up at " << parentItem->window()->geometry().center() - QPoint(width()/2, height()/2);
|
|
||||||
return parentItem->window()->geometry().center() - QPoint(width()/2, height()/2);
|
return parentItem->window()->geometry().center() - QPoint(width()/2, height()/2);
|
||||||
} else {
|
} else {
|
||||||
qDebug() << "no item, zero-zero";
|
|
||||||
return QPoint();
|
return QPoint();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QPointF pos = item->mapToScene(QPointF(0, 0));
|
QPointF pos = item->mapToScene(QPointF(0, 0));
|
||||||
qDebug() << " we have an item at " << pos;
|
|
||||||
if (item->window() && item->window()->screen()) {
|
if (item->window() && item->window()->screen()) {
|
||||||
pos = item->window()->mapToGlobal(pos.toPoint());
|
pos = item->window()->mapToGlobal(pos.toPoint());
|
||||||
qDebug() << " ========= Item Screenposition " << pos << "Screen" << item->window()->screen();
|
|
||||||
} else {
|
} else {
|
||||||
qDebug() << " ========= popping up at zerozero";
|
|
||||||
return QPoint();
|
return QPoint();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -247,19 +229,6 @@ QPoint DialogProxy::popupPosition(QQuickItem *item, Qt::AlignmentFlag alignment)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QPoint offset(0, 0);
|
|
||||||
// * enum Location {
|
|
||||||
// Floating = 0, /**< Free floating. Neither geometry or z-ordering
|
|
||||||
// is described precisely by this value. */
|
|
||||||
// Desktop, /**< On the planar desktop layer, extending across
|
|
||||||
// the full screen from edge to edge */
|
|
||||||
// FullScreen, /**< Full screen */
|
|
||||||
// TopEdge, /**< Along the top of the screen*/
|
|
||||||
// BottomEdge, /**< Along the bottom of the screen*/
|
|
||||||
// LeftEdge, /**< Along the left side of the screen */
|
|
||||||
// RightEdge /**< Along the right side of the screen */
|
|
||||||
// };
|
|
||||||
//
|
|
||||||
Plasma::Location l = (Plasma::Location)location();
|
Plasma::Location l = (Plasma::Location)location();
|
||||||
|
|
||||||
QPoint topPoint((item->boundingRect().width() - width())/2,
|
QPoint topPoint((item->boundingRect().width() - width())/2,
|
||||||
@ -272,6 +241,7 @@ QPoint DialogProxy::popupPosition(QQuickItem *item, Qt::AlignmentFlag alignment)
|
|||||||
QPoint rightPoint(item->boundingRect().width(),
|
QPoint rightPoint(item->boundingRect().width(),
|
||||||
(item->boundingRect().height() - height())/2);
|
(item->boundingRect().height() - height())/2);
|
||||||
|
|
||||||
|
QPoint offset(0, 0);
|
||||||
if (l == Plasma::BottomEdge) {
|
if (l == Plasma::BottomEdge) {
|
||||||
offset = bottomPoint;
|
offset = bottomPoint;
|
||||||
} else if (l == Plasma::LeftEdge) {
|
} else if (l == Plasma::LeftEdge) {
|
||||||
@ -285,14 +255,6 @@ QPoint DialogProxy::popupPosition(QQuickItem *item, Qt::AlignmentFlag alignment)
|
|||||||
const QRect avail = item->window()->screen()->availableGeometry();
|
const QRect avail = item->window()->screen()->availableGeometry();
|
||||||
QPoint menuPos = pos.toPoint() + offset;
|
QPoint menuPos = pos.toPoint() + offset;
|
||||||
|
|
||||||
qDebug() << "ITem geom/boundingRect" << item->position() << item->width() << item->boundingRect();
|
|
||||||
qDebug() << "Before correction pos = " << pos << " menuPos = " << menuPos << " offset" << offset;
|
|
||||||
if (menuPos.y() + height() > avail.bottom()) {
|
|
||||||
//menuPos = pos.toPoint() + QPoint(offset.x(), -height());
|
|
||||||
//menuPos = pos.toPoint() + bottomPoint;
|
|
||||||
//qDebug() << "COrrected to BottomEdge" << menuPos;
|
|
||||||
}
|
|
||||||
//const int _m = 8;
|
|
||||||
const int leftMargin = m_frameSvgItem->margins()->left();
|
const int leftMargin = m_frameSvgItem->margins()->left();
|
||||||
const int rightMargin = m_frameSvgItem->margins()->right();
|
const int rightMargin = m_frameSvgItem->margins()->right();
|
||||||
const int topMargin = m_frameSvgItem->margins()->top();
|
const int topMargin = m_frameSvgItem->margins()->top();
|
||||||
@ -300,7 +262,6 @@ QPoint DialogProxy::popupPosition(QQuickItem *item, Qt::AlignmentFlag alignment)
|
|||||||
|
|
||||||
if (menuPos.x() < leftMargin) {
|
if (menuPos.x() < leftMargin) {
|
||||||
// popup hits lhs
|
// popup hits lhs
|
||||||
qDebug() << "hitting lhs";
|
|
||||||
if (l == Plasma::TopEdge || l == Plasma::BottomEdge) {
|
if (l == Plasma::TopEdge || l == Plasma::BottomEdge) {
|
||||||
// move it
|
// move it
|
||||||
menuPos.setX(0-leftMargin);
|
menuPos.setX(0-leftMargin);
|
||||||
@ -311,7 +272,6 @@ QPoint DialogProxy::popupPosition(QQuickItem *item, Qt::AlignmentFlag alignment)
|
|||||||
}
|
}
|
||||||
if (menuPos.x() + width() > avail.width() - rightMargin) {
|
if (menuPos.x() + width() > avail.width() - rightMargin) {
|
||||||
// popup hits rhs
|
// popup hits rhs
|
||||||
qDebug() << "hitting rhs";
|
|
||||||
if (l == Plasma::TopEdge || l == Plasma::BottomEdge) {
|
if (l == Plasma::TopEdge || l == Plasma::BottomEdge) {
|
||||||
menuPos.setX(avail.width() - item->boundingRect().width() + rightMargin);
|
menuPos.setX(avail.width() - item->boundingRect().width() + rightMargin);
|
||||||
} else {
|
} else {
|
||||||
@ -320,7 +280,6 @@ QPoint DialogProxy::popupPosition(QQuickItem *item, Qt::AlignmentFlag alignment)
|
|||||||
}
|
}
|
||||||
if (menuPos.y() < topMargin) {
|
if (menuPos.y() < topMargin) {
|
||||||
// hitting top
|
// hitting top
|
||||||
qDebug() << "hitting top";
|
|
||||||
if (l == Plasma::LeftEdge || l == Plasma::RightEdge) {
|
if (l == Plasma::LeftEdge || l == Plasma::RightEdge) {
|
||||||
menuPos.setY(0);
|
menuPos.setY(0);
|
||||||
} else {
|
} else {
|
||||||
@ -328,7 +287,6 @@ QPoint DialogProxy::popupPosition(QQuickItem *item, Qt::AlignmentFlag alignment)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (menuPos.y() + height() > avail.height() - bottomMargin) {
|
if (menuPos.y() + height() > avail.height() - bottomMargin) {
|
||||||
qDebug() << "Hitting bottom" << menuPos;
|
|
||||||
// hitting bottom
|
// hitting bottom
|
||||||
if (l == Plasma::TopEdge || l == Plasma::BottomEdge) {
|
if (l == Plasma::TopEdge || l == Plasma::BottomEdge) {
|
||||||
menuPos.setY(pos.y() + topPoint.y());
|
menuPos.setY(pos.y() + topPoint.y());
|
||||||
@ -338,8 +296,7 @@ QPoint DialogProxy::popupPosition(QQuickItem *item, Qt::AlignmentFlag alignment)
|
|||||||
qDebug() << menuPos;
|
qDebug() << menuPos;
|
||||||
}
|
}
|
||||||
|
|
||||||
qDebug() << "--> After correction pos = " << pos << " menuPos = " << menuPos << " offset" << offset;
|
qDebug() << "Popup position" << menuPos << " Location: Plasma::" <<locString(l);
|
||||||
qDebug() << "PUP" << menuPos << " Location: Plasma::" <<locString(l) << topPoint;
|
|
||||||
return menuPos;
|
return menuPos;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -352,7 +309,6 @@ void DialogProxy::activateWindow()
|
|||||||
{
|
{
|
||||||
qDebug();
|
qDebug();
|
||||||
setWindowState(Qt::WindowActive);
|
setWindowState(Qt::WindowActive);
|
||||||
//m_dialog->activateWindow();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int DialogProxy::windowFlags() const
|
int DialogProxy::windowFlags() const
|
||||||
@ -420,10 +376,6 @@ void DialogProxy::syncToMainItemSize()
|
|||||||
if (!m_mainItem) {
|
if (!m_mainItem) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (m_visualParent.isNull()) {
|
|
||||||
qDebug() << "booom: " << qobject_cast<QQuickItem*>(parent());
|
|
||||||
setVisualParent(qobject_cast<QQuickItem*>(parent()));
|
|
||||||
}
|
|
||||||
|
|
||||||
//FIXME: workaround to prevent dialogs of Popup type disappearing on the second show
|
//FIXME: workaround to prevent dialogs of Popup type disappearing on the second show
|
||||||
const QSize s = QSize(m_mainItem.data()->width(), m_mainItem.data()->height()) +
|
const QSize s = QSize(m_mainItem.data()->width(), m_mainItem.data()->height()) +
|
||||||
|
@ -169,6 +169,7 @@ private:
|
|||||||
bool m_activeWindow;
|
bool m_activeWindow;
|
||||||
Plasma::Location m_location;
|
Plasma::Location m_location;
|
||||||
Plasma::FrameSvgItem *m_frameSvgItem;
|
Plasma::FrameSvgItem *m_frameSvgItem;
|
||||||
|
QRect m_cachedGeometry;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user