fix enabled borders management

* never enable all the borders just to take margins, there is fixedMargins for that
* redo ResizeOrigin: Dialog needs to sync from both sides: when the mainItem gets resized, *and* when the window gets resized (syncing mainItem)
* don't crash when there is no Layout: not all mainItems export one
* fix availableScreenGeometryForPosition()

Change-Id: I09370e33a3e8d03675b60f14c6c5754f8491d52c
This commit is contained in:
Marco Martin 2014-09-16 16:04:35 +02:00
parent d59e005da3
commit aaa1a6315e

View File

@ -63,10 +63,17 @@ public:
hideOnWindowDeactivate(false), hideOnWindowDeactivate(false),
outputOnly(false), outputOnly(false),
componentComplete(dialog->parent() == 0), componentComplete(dialog->parent() == 0),
resizeOrigin(Undefined),
backgroundHints(Dialog::StandardBackground) backgroundHints(Dialog::StandardBackground)
{ {
} }
enum ResizeOrigin {
Undefined,
MainItem,
Window
};
void updateInputShape(); void updateInputShape();
//SLOTS //SLOTS
@ -114,7 +121,6 @@ public:
void syncToMainItemSize(); void syncToMainItemSize();
Dialog *q; Dialog *q;
QTimer *syncTimer;
Plasma::Types::Location location; Plasma::Types::Location location;
Plasma::FrameSvgItem *frameSvgItem; Plasma::FrameSvgItem *frameSvgItem;
QPointer<QQuickItem> mainItem; QPointer<QQuickItem> mainItem;
@ -126,6 +132,7 @@ public:
bool outputOnly; bool outputOnly;
Plasma::Theme theme; Plasma::Theme theme;
bool componentComplete; bool componentComplete;
ResizeOrigin resizeOrigin;
Dialog::BackgroundHints backgroundHints; Dialog::BackgroundHints backgroundHints;
//Attached Layout property of mainItem, if any //Attached Layout property of mainItem, if any
@ -142,7 +149,10 @@ QRect DialogPrivate::availableScreenGeometryForPosition(const QPoint& pos) const
// says it's at. // says it's at.
QRect avail; QRect avail;
Q_FOREACH (QScreen *screen, q->screen()->virtualSiblings()) { Q_FOREACH (QScreen *screen, q->screen()->virtualSiblings()) {
if (screen->availableGeometry().contains(pos)) { //we check geometry() but then take availableGeometry()
//to reliably check in what screen a position is, we need the full
//geometry, included areas for panels
if (screen->geometry().contains(pos)) {
avail = screen->availableGeometry(); avail = screen->availableGeometry();
break; break;
} }
@ -431,16 +441,17 @@ void DialogPrivate::updateLayoutParameters()
return; return;
} }
Q_ASSERT(mainItem); Q_ASSERT(mainItem);
Q_ASSERT(mainItemLayout); //Not all main items define a Layout internally, this depends from the QML
//Q_ASSERT(mainItemLayout);
mainItem->disconnect(q); mainItem->disconnect(q);
int minimumHeight = mainItemLayout->property("minimumHeight").toInt(); int minimumHeight = mainItemLayout ? mainItemLayout->property("minimumHeight").toInt() : 0;
int maximumHeight = mainItemLayout->property("maximumHeight").toInt(); int maximumHeight = mainItemLayout ? mainItemLayout->property("maximumHeight").toInt() : 0;
maximumHeight = maximumHeight ? maximumHeight : DIALOGSIZE_MAX; maximumHeight = maximumHeight ? maximumHeight : DIALOGSIZE_MAX;
int minimumWidth = mainItemLayout->property("minimumWidth").toInt(); int minimumWidth = mainItemLayout ? mainItemLayout->property("minimumWidth").toInt() : 0;
int maximumWidth = mainItemLayout->property("maximumWidth").toInt(); int maximumWidth = mainItemLayout ? mainItemLayout->property("maximumWidth").toInt() : 0;
maximumWidth = maximumWidth ? maximumWidth : DIALOGSIZE_MAX; maximumWidth = maximumWidth ? maximumWidth : DIALOGSIZE_MAX;
auto margin = frameSvgItem->margins(); auto margin = frameSvgItem->margins();
@ -540,14 +551,15 @@ void DialogPrivate::updateInputShape()
void DialogPrivate::syncToMainItemSize() void DialogPrivate::syncToMainItemSize()
{ {
if (!componentComplete || !mainItem || !q->isVisible()) { if (resizeOrigin == Window || !componentComplete || !mainItem || !q->isVisible()) {
return; return;
} }
resizeOrigin = MainItem;
if (visualParent) { if (visualParent) {
// Get the full size with ALL the borders // fixedMargins will get all the borders, no matter if they are enabled
frameSvgItem->setEnabledBorders(Plasma::FrameSvg::AllBorders); auto margins = frameSvgItem->fixedMargins();
auto margins = frameSvgItem->margins();
const QSize fullSize = QSize(mainItem->width(), mainItem->height()) + const QSize fullSize = QSize(mainItem->width(), mainItem->height()) +
QSize(margins->left() + margins->right(), QSize(margins->left() + margins->right(),
@ -594,6 +606,8 @@ void DialogPrivate::syncToMainItemSize()
mainItem->setY(frameSvgItem->margins()->top()); mainItem->setY(frameSvgItem->margins()->top());
updateTheme(); updateTheme();
resizeOrigin = Undefined;
} }
void DialogPrivate::slotWindowPositionChanged() void DialogPrivate::slotWindowPositionChanged()
@ -903,6 +917,14 @@ void Dialog::adjustGeometry(const QRect &geom)
void Dialog::resizeEvent(QResizeEvent* re) void Dialog::resizeEvent(QResizeEvent* re)
{ {
QQuickWindow::resizeEvent(re); QQuickWindow::resizeEvent(re);
if (d->resizeOrigin == DialogPrivate::MainItem) {
return;
}
d->resizeOrigin = DialogPrivate::Window;
d->updateLayoutParameters();
d->resizeOrigin = DialogPrivate::Undefined;
} }
void Dialog::setType(WindowType type) void Dialog::setType(WindowType type)