use a framesvgitem as background

This commit is contained in:
Marco Martin 2013-02-21 14:32:48 +01:00
parent de81cdada3
commit efc725acec
3 changed files with 31 additions and 17 deletions

View File

@ -19,7 +19,7 @@
***************************************************************************/
#include "dialog.h"
//#include "declarativeitemcontainer_p.h"
#include "framesvgitem.h"
#include <QApplication>
#include <QQuickItem>
@ -112,6 +112,12 @@ DialogProxy::DialogProxy(QQuickItem *parent)
m_syncTimer->setSingleShot(true);
m_syncTimer->setInterval(250);
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
property("data");
//Create the FrameSvg background.
m_frameSvgItem = new Plasma::FrameSvgItem(contentItem());
m_frameSvgItem->setImagePath("dialogs/background");
}
DialogProxy::~DialogProxy()
@ -131,8 +137,6 @@ void DialogProxy::setMainItem(QQuickItem *mainItem)
if (m_mainItem) {
m_mainItem.data()->setParent(parent());
}
//HACK: this property is invoked due to the initialization that gets done to contentItem() in the getter
property("data");
m_mainItem = mainItem;
@ -309,17 +313,25 @@ QObject *DialogProxy::margins() const
void DialogProxy::resizeEvent(QResizeEvent *re)
{
contentItem()->setX(0);
contentItem()->setY(0);
if (m_mainItem) {
m_mainItem.data()->setX(0);
m_mainItem.data()->setY(0);
m_mainItem.data()->setWidth(re->size().width());
m_mainItem.data()->setHeight(re->size().height());
}
syncMainItemToSize();
QQuickWindow::resizeEvent(re);
}
void DialogProxy::syncMainItemToSize()
{
m_frameSvgItem->setX(0);
m_frameSvgItem->setY(0);
m_frameSvgItem->setWidth(width());
m_frameSvgItem->setHeight(height());
if (m_mainItem) {
m_mainItem.data()->setX(m_frameSvgItem->margins()->left());
m_mainItem.data()->setY(m_frameSvgItem->margins()->top());
m_mainItem.data()->setWidth(width() - m_frameSvgItem->margins()->left() - m_frameSvgItem->margins()->right());
m_mainItem.data()->setHeight(height() - m_frameSvgItem->margins()->top() - m_frameSvgItem->margins()->bottom());
}
}
void DialogProxy::syncToMainItemSize()
{
if (!m_mainItem) {
@ -327,7 +339,9 @@ void DialogProxy::syncToMainItemSize()
}
//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()) +
QSize(m_frameSvgItem->margins()->left() + m_frameSvgItem->margins()->right(),
m_frameSvgItem->margins()->top() + m_frameSvgItem->margins()->bottom());
//resize(0,0);
resize(s);
emit widthChanged(s.width());

View File

@ -31,10 +31,9 @@ class QQuickItem;
namespace Plasma
{
class Dialog;
class FrameSvgItem;
}
class DeclarativeItemContainer;
class DialogMargins : public QObject
{
@ -219,6 +218,7 @@ private:
DialogMargins *m_margins;
bool m_activeWindow;
Plasma::Location m_location;
Plasma::FrameSvgItem *m_frameSvgItem;
};
#endif

View File

@ -45,9 +45,9 @@ Item {
color: Qt.rgba(0,0,0,0)
visible: plasmoid.expanded
visualParent: root
mainItem: Rectangle {
mainItem: Item {
id: appletParent
radius: 5
width: applet && applet.implicitWidth > 0 ? applet.implicitWidth : theme.defaultFont.mSize.width * 35
height: applet && applet.implicitHeight > 0 ? applet.implicitHeight : theme.defaultFont.mSize.height * 25
onWidthChanged: applet.width = width
@ -56,7 +56,7 @@ Item {
onActiveWindowChanged: {
if (!activeWindow) {
plasmoid.expanded = false
// plasmoid.expanded = false
}
}
onVisibleChanged: {