use a window for dismiss area
animation done by kwin
This commit is contained in:
parent
ce2547c833
commit
7c3d1883c6
@ -21,6 +21,7 @@
|
|||||||
#include "../core/declarativeitemcontainer_p.h"
|
#include "../core/declarativeitemcontainer_p.h"
|
||||||
#include "plasmacomponentsplugin.h"
|
#include "plasmacomponentsplugin.h"
|
||||||
|
|
||||||
|
#include <QApplication>
|
||||||
#include <QDeclarativeItem>
|
#include <QDeclarativeItem>
|
||||||
#include <QDeclarativeContext>
|
#include <QDeclarativeContext>
|
||||||
#include <QGraphicsObject>
|
#include <QGraphicsObject>
|
||||||
@ -29,16 +30,57 @@
|
|||||||
#include <QGraphicsWidget>
|
#include <QGraphicsWidget>
|
||||||
#include <QLayout>
|
#include <QLayout>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QFile>
|
#include <QDesktopWidget>
|
||||||
|
|
||||||
#include <KWindowSystem>
|
#include <KWindowSystem>
|
||||||
#include <KStandardDirs>
|
#include <KStandardDirs>
|
||||||
|
|
||||||
#include <Plasma/Corona>
|
#include <Plasma/Corona>
|
||||||
|
#include <Plasma/WindowEffects>
|
||||||
|
|
||||||
|
|
||||||
uint FullScreenDialog::s_numItems = 0;
|
uint FullScreenDialog::s_numItems = 0;
|
||||||
|
|
||||||
|
class Background : public QWidget
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Background(FullScreenDialog *dialog)
|
||||||
|
: QWidget( 0L ),
|
||||||
|
m_dialog(dialog)
|
||||||
|
{
|
||||||
|
setAttribute( Qt::WA_NoSystemBackground );
|
||||||
|
setAttribute( Qt::WA_TranslucentBackground );
|
||||||
|
|
||||||
|
setWindowFlags(Qt::FramelessWindowHint | Qt::CustomizeWindowHint);
|
||||||
|
KWindowSystem::setOnAllDesktops(winId(), true);
|
||||||
|
unsigned long state = NET::Sticky | NET::StaysOnTop | NET::KeepAbove | NET::SkipTaskbar | NET::SkipPager | NET::MaxVert | NET::MaxHoriz;
|
||||||
|
KWindowSystem::setState(effectiveWinId(), state);
|
||||||
|
}
|
||||||
|
|
||||||
|
~Background()
|
||||||
|
{}
|
||||||
|
|
||||||
|
void paintEvent( QPaintEvent *e )
|
||||||
|
{
|
||||||
|
QPainter painter( this );
|
||||||
|
painter.setCompositionMode(QPainter::CompositionMode_Source);
|
||||||
|
painter.fillRect(e->rect(), QColor(0, 0, 0, 80));
|
||||||
|
}
|
||||||
|
|
||||||
|
void mousePressEvent(QMouseEvent *event)
|
||||||
|
{
|
||||||
|
event->accept();
|
||||||
|
}
|
||||||
|
|
||||||
|
void mouseReleaseEvent(QMouseEvent *event)
|
||||||
|
{
|
||||||
|
m_dialog->close();
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
FullScreenDialog *m_dialog;
|
||||||
|
};
|
||||||
|
|
||||||
FullScreenDialog::FullScreenDialog(QDeclarativeItem *parent)
|
FullScreenDialog::FullScreenDialog(QDeclarativeItem *parent)
|
||||||
: QDeclarativeItem(parent),
|
: QDeclarativeItem(parent),
|
||||||
m_declarativeItemContainer(0)
|
m_declarativeItemContainer(0)
|
||||||
@ -53,10 +95,10 @@ FullScreenDialog::FullScreenDialog(QDeclarativeItem *parent)
|
|||||||
m_view->setAttribute(Qt::WA_NoSystemBackground);
|
m_view->setAttribute(Qt::WA_NoSystemBackground);
|
||||||
m_view->viewport()->setAttribute(Qt::WA_NoSystemBackground);
|
m_view->viewport()->setAttribute(Qt::WA_NoSystemBackground);
|
||||||
m_view->setCacheMode(QGraphicsView::CacheNone);
|
m_view->setCacheMode(QGraphicsView::CacheNone);
|
||||||
m_view->setWindowFlags(m_view->windowFlags() | Qt::FramelessWindowHint | Qt::CustomizeWindowHint);
|
m_view->setWindowFlags(Qt::FramelessWindowHint | Qt::CustomizeWindowHint);
|
||||||
m_view->setFrameShape(QFrame::NoFrame);
|
m_view->setFrameShape(QFrame::NoFrame);
|
||||||
KWindowSystem::setOnAllDesktops(m_view->winId(), true);
|
KWindowSystem::setOnAllDesktops(m_view->winId(), true);
|
||||||
unsigned long state = NET::Sticky | NET::StaysOnTop | NET::KeepAbove | NET::SkipTaskbar | NET::SkipPager | NET::MaxVert | NET::MaxHoriz;
|
unsigned long state = NET::Sticky | NET::StaysOnTop | NET::KeepAbove | NET::SkipTaskbar | NET::SkipPager;
|
||||||
KWindowSystem::setState(m_view->effectiveWinId(), state);
|
KWindowSystem::setState(m_view->effectiveWinId(), state);
|
||||||
|
|
||||||
//Try to figure out the path of the dialog component
|
//Try to figure out the path of the dialog component
|
||||||
@ -102,6 +144,8 @@ FullScreenDialog::FullScreenDialog(QDeclarativeItem *parent)
|
|||||||
connect(m_rootObject.data(), SIGNAL(rejected()), this, SIGNAL(rejected()));
|
connect(m_rootObject.data(), SIGNAL(rejected()), this, SIGNAL(rejected()));
|
||||||
connect(m_rootObject.data(), SIGNAL(clickedOutside()), this, SIGNAL(clickedOutside()));
|
connect(m_rootObject.data(), SIGNAL(clickedOutside()), this, SIGNAL(clickedOutside()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_background = new Background(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
FullScreenDialog::~FullScreenDialog()
|
FullScreenDialog::~FullScreenDialog()
|
||||||
@ -183,15 +227,16 @@ void FullScreenDialog::syncMainItem()
|
|||||||
|
|
||||||
|
|
||||||
if (m_declarativeItemContainer) {
|
if (m_declarativeItemContainer) {
|
||||||
m_declarativeItemContainer->resize(m_view->size());
|
m_view->resize(m_declarativeItemContainer->size().toSize());
|
||||||
m_view->setSceneRect(m_declarativeItemContainer->geometry());
|
m_view->setSceneRect(m_declarativeItemContainer->geometry());
|
||||||
} else {
|
} else {
|
||||||
m_mainItem.data()->setProperty("width", m_view->size().width());
|
|
||||||
m_mainItem.data()->setProperty("height", m_view->size().height());
|
|
||||||
QRectF itemGeometry(QPointF(m_mainItem.data()->x(), m_mainItem.data()->y()),
|
QRectF itemGeometry(QPointF(m_mainItem.data()->x(), m_mainItem.data()->y()),
|
||||||
QSizeF(m_mainItem.data()->boundingRect().size()));
|
QSizeF(m_mainItem.data()->boundingRect().size()));
|
||||||
|
m_view->resize(itemGeometry.size().toSize());
|
||||||
m_view->setSceneRect(itemGeometry);
|
m_view->setSceneRect(itemGeometry);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_view->move(QApplication::desktop()->availableGeometry().center() - QPoint(m_view->width()/2, m_view->height()/2));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FullScreenDialog::isVisible() const
|
bool FullScreenDialog::isVisible() const
|
||||||
@ -202,11 +247,9 @@ bool FullScreenDialog::isVisible() const
|
|||||||
void FullScreenDialog::setVisible(const bool visible)
|
void FullScreenDialog::setVisible(const bool visible)
|
||||||
{
|
{
|
||||||
if (m_view->isVisible() != visible) {
|
if (m_view->isVisible() != visible) {
|
||||||
|
m_background->setVisible(visible);
|
||||||
m_view->setVisible(visible);
|
m_view->setVisible(visible);
|
||||||
if (visible) {
|
if (visible) {
|
||||||
unsigned long state = NET::Sticky | NET::StaysOnTop | NET::KeepAbove | NET::SkipTaskbar | NET::SkipPager | NET::MaxVert | NET::MaxHoriz;
|
|
||||||
m_view->setVisible(visible);
|
|
||||||
KWindowSystem::setState(m_view->effectiveWinId(), state);
|
|
||||||
m_view->raise();
|
m_view->raise();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -292,9 +335,13 @@ void FullScreenDialog::close()
|
|||||||
|
|
||||||
bool FullScreenDialog::eventFilter(QObject *watched, QEvent *event)
|
bool FullScreenDialog::eventFilter(QObject *watched, QEvent *event)
|
||||||
{
|
{
|
||||||
if (watched == m_view &&
|
if (watched == m_mainItem.data() &&
|
||||||
(event->type() == QEvent::Resize || event->type() == QEvent::Move)) {
|
(event->type() == QEvent::GraphicsSceneResize)) {
|
||||||
syncMainItem();
|
syncMainItem();
|
||||||
|
} else if (watched == m_view && event->type() == QEvent::Show) {
|
||||||
|
Plasma::WindowEffects::slideWindow(m_view->winId(), Plasma::BottomEdge, 0);
|
||||||
|
} else if (watched == m_view && event->type() == QEvent::Hide) {
|
||||||
|
Plasma::WindowEffects::slideWindow(m_view->winId(), Plasma::BottomEdge, 0);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -32,6 +32,7 @@ class QGraphicsObject;
|
|||||||
class QGraphicsView;
|
class QGraphicsView;
|
||||||
class QGraphicsScene;
|
class QGraphicsScene;
|
||||||
class DeclarativeItemContainer;
|
class DeclarativeItemContainer;
|
||||||
|
class Background;
|
||||||
|
|
||||||
class FullScreenDialog : public QDeclarativeItem
|
class FullScreenDialog : public QDeclarativeItem
|
||||||
{
|
{
|
||||||
@ -86,6 +87,7 @@ private:
|
|||||||
QGraphicsScene *m_scene;
|
QGraphicsScene *m_scene;
|
||||||
QWeakPointer<QObject> m_rootObject;
|
QWeakPointer<QObject> m_rootObject;
|
||||||
static uint s_numItems;
|
static uint s_numItems;
|
||||||
|
Background *m_background;
|
||||||
|
|
||||||
//those only used in case of error, to not make plasma crash
|
//those only used in case of error, to not make plasma crash
|
||||||
QList<QGraphicsObject *> m_dummyTitleElements;
|
QList<QGraphicsObject *> m_dummyTitleElements;
|
||||||
|
@ -47,6 +47,8 @@ import "." 0.1
|
|||||||
|
|
||||||
Item {
|
Item {
|
||||||
id: root
|
id: root
|
||||||
|
width: dialog.width
|
||||||
|
height: dialog.height
|
||||||
|
|
||||||
property alias title: titleBar.children
|
property alias title: titleBar.children
|
||||||
property alias content: contentItem.children
|
property alias content: contentItem.children
|
||||||
@ -91,12 +93,7 @@ Item {
|
|||||||
dialog.state = "closed"
|
dialog.state = "closed"
|
||||||
}
|
}
|
||||||
|
|
||||||
Rectangle {
|
|
||||||
id: fader
|
|
||||||
property double alpha: 0
|
|
||||||
color: Qt.rgba(0.0, 0.0, 0.0, alpha)
|
|
||||||
anchors.fill: parent
|
|
||||||
}
|
|
||||||
MouseArea {
|
MouseArea {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
onClicked: {
|
onClicked: {
|
||||||
@ -120,10 +117,6 @@ Item {
|
|||||||
|
|
||||||
state: "closed"
|
state: "closed"
|
||||||
|
|
||||||
transform: Translate {
|
|
||||||
id: dialogTransform
|
|
||||||
y: root.height - dialog.y
|
|
||||||
}
|
|
||||||
//state: "Hidden"
|
//state: "Hidden"
|
||||||
|
|
||||||
Item {
|
Item {
|
||||||
@ -183,65 +176,18 @@ Item {
|
|||||||
State {
|
State {
|
||||||
name: "closed"
|
name: "closed"
|
||||||
PropertyChanges {
|
PropertyChanges {
|
||||||
target: dialogTransform
|
target: root
|
||||||
y: root.height - dialog.y
|
status: DialogStatus.Closed
|
||||||
}
|
|
||||||
PropertyChanges {
|
|
||||||
target: fader
|
|
||||||
alpha: 0
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
State {
|
State {
|
||||||
name: ""
|
name: ""
|
||||||
PropertyChanges {
|
PropertyChanges {
|
||||||
target: dialogTransform
|
target: root
|
||||||
y: 0
|
status: DialogStatus.Open
|
||||||
}
|
|
||||||
PropertyChanges {
|
|
||||||
target: fader
|
|
||||||
alpha: 0.6
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
transitions: [
|
|
||||||
// Transition between open and closed states.
|
|
||||||
Transition {
|
|
||||||
from: ""
|
|
||||||
to: "closed"
|
|
||||||
reversible: false
|
|
||||||
SequentialAnimation {
|
|
||||||
ScriptAction {
|
|
||||||
script: root.status = DialogStatus.Closing
|
|
||||||
}
|
|
||||||
PropertyAnimation {
|
|
||||||
properties: "y, alpha"
|
|
||||||
easing.type: Easing.InOutQuad
|
|
||||||
duration: 250
|
|
||||||
}
|
|
||||||
ScriptAction {
|
|
||||||
script: root.status = DialogStatus.Closed
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
Transition {
|
|
||||||
from: "closed"
|
|
||||||
to: ""
|
|
||||||
reversible: false
|
|
||||||
SequentialAnimation {
|
|
||||||
ScriptAction {
|
|
||||||
script: root.status = DialogStatus.Opening
|
|
||||||
}
|
|
||||||
PropertyAnimation {
|
|
||||||
properties: "y, alpha"
|
|
||||||
easing.type: Easing.InOutQuad
|
|
||||||
duration: 250
|
|
||||||
}
|
|
||||||
ScriptAction {
|
|
||||||
script: root.status = DialogStatus.Open
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user