From 49367b51e078193e90a2bde77ef53d877a860906 Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Tue, 5 Nov 2013 11:26:29 +0100 Subject: [PATCH] export alignment as a property --- tabbox/declarative.cpp | 32 +++++++++++++++++++++++++++++--- tabbox/qml/tabbox.qml | 1 + 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/tabbox/declarative.cpp b/tabbox/declarative.cpp index ae93d06427..19e237fa89 100644 --- a/tabbox/declarative.cpp +++ b/tabbox/declarative.cpp @@ -295,9 +295,35 @@ void DeclarativeView::slotUpdateGeometry() } else { const int width = rootObject()->property("width").toInt(); const int height = rootObject()->property("height").toInt(); - setGeometry(m_currentScreenGeometry.x() + static_cast(m_currentScreenGeometry.width()) * 0.5 - static_cast(width) * 0.5, - m_currentScreenGeometry.y() + static_cast(m_currentScreenGeometry.height()) * 0.5 - static_cast(height) * 0.5, - width, height); + + Qt::Alignment alignment = Qt::AlignCenter; + + if (rootObject()->property("alignment").canConvert()) { + alignment = (Qt::Alignment)rootObject()->property("alignment").toInt(); + } + + int x; + int y; + + if (alignment & Qt::AlignLeft) { + x = m_currentScreenGeometry.x(); + } else if (alignment & Qt::AlignLeft) { + x = m_currentScreenGeometry.right() - width; + //Center + } else { + x = m_currentScreenGeometry.x() + static_cast(m_currentScreenGeometry.width()) * 0.5 - static_cast(width) * 0.5; + } + + if (alignment & Qt::AlignTop) { + y = m_currentScreenGeometry.y(); + } else if (alignment & Qt::AlignBottom) { + y = m_currentScreenGeometry.bottom() - height; + //Center + } else { + y = m_currentScreenGeometry.y() + static_cast(m_currentScreenGeometry.height()) * 0.5 - static_cast(height) * 0.5; + } + + setGeometry(x, y, width, height); m_relativePos = position(); } } diff --git a/tabbox/qml/tabbox.qml b/tabbox/qml/tabbox.qml index d81e691030..04f5f7751b 100644 --- a/tabbox/qml/tabbox.qml +++ b/tabbox/qml/tabbox.qml @@ -25,6 +25,7 @@ Loader { property int screenWidth : 0 property int screenHeight : 0 property bool allDesktops: true + property int alignment: item && item.alignment ? item.alignment : Qt.AlignCenter property string longestCaption: "" property string maskImagePath: item && item.maskImagePath != undefined ? item.maskImagePath : "" property double maskWidth: item && item.maskWidth != undefined ? item.maskWidth : 0