Use a QDeclarativeView for button views in Present Windows and Desktop Grid
Declarative UI++ REVIEW: 109409
This commit is contained in:
parent
fbc11aad13
commit
fb65c07bf7
9 changed files with 146 additions and 143 deletions
|
@ -8,6 +8,11 @@ set(kwin_effect_OWN_LIBS
|
|||
set(kwin_effect_KDE_LIBS
|
||||
${KDE4_KDEUI_LIBS}
|
||||
${KDE4_PLASMA_LIBS}
|
||||
${KDECLARATIVE_LIBRARIES}
|
||||
)
|
||||
|
||||
set(kwin_effect_QT_LIBS
|
||||
${QT_QTDECLARATIVE_LIBRARY}
|
||||
)
|
||||
|
||||
set(kwin_effect_XLIB_LIBS
|
||||
|
@ -34,7 +39,7 @@ endif()
|
|||
|
||||
macro( KWIN4_ADD_EFFECT_BACKEND name )
|
||||
kde4_add_plugin( ${name} ${ARGN} )
|
||||
target_link_libraries( ${name} ${kwin_effect_OWN_LIBS} ${kwin_effect_KDE_LIBS} ${kwin_effect_XLIB_LIBS} ${kwin_effect_XCB_LIBS})
|
||||
target_link_libraries( ${name} ${kwin_effect_OWN_LIBS} ${kwin_effect_KDE_LIBS} ${kwin_effect_QT_LIBS} ${kwin_effect_XLIB_LIBS} ${kwin_effect_XCB_LIBS})
|
||||
endmacro()
|
||||
|
||||
# Adds effect plugin with given name. Sources are given after the name
|
||||
|
|
|
@ -12,6 +12,10 @@ kde4_add_kcfg_files(kwin4_effect_builtins_sources desktopgrid/desktopgridconfig.
|
|||
install( FILES
|
||||
desktopgrid/desktopgrid.desktop
|
||||
DESTINATION ${SERVICES_INSTALL_DIR}/kwin )
|
||||
install( FILES
|
||||
desktopgrid/main.qml
|
||||
DESTINATION ${DATA_INSTALL_DIR}/kwin/effects/desktopgrid/
|
||||
)
|
||||
|
||||
#######################################
|
||||
# Config
|
||||
|
|
|
@ -32,17 +32,16 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
#include <kactioncollection.h>
|
||||
#include <kdebug.h>
|
||||
#include <KDE/KLocalizedString>
|
||||
#include <KDE/KStandardDirs>
|
||||
#include <kdeclarative.h>
|
||||
#include <netwm_def.h>
|
||||
#include <QEvent>
|
||||
#include <QMouseEvent>
|
||||
#include <kglobalsettings.h>
|
||||
#include <QtGui/QPainter>
|
||||
#include <QGraphicsLinearLayout>
|
||||
#include <QtGui/QVector2D>
|
||||
#include <Plasma/FrameSvg>
|
||||
#include <Plasma/PushButton>
|
||||
#include <Plasma/Theme>
|
||||
#include <Plasma/WindowEffects>
|
||||
#include <QDeclarativeEngine>
|
||||
#include <QDeclarativeContext>
|
||||
#include <QGraphicsObject>
|
||||
|
||||
namespace KWin
|
||||
{
|
||||
|
@ -1383,58 +1382,34 @@ bool DesktopGridEffect::isRelevantWithPresentWindows(EffectWindow *w) const
|
|||
/************************************************
|
||||
* DesktopButtonView
|
||||
************************************************/
|
||||
DesktopButtonsView::DesktopButtonsView(QWidget* parent)
|
||||
: QGraphicsView(parent)
|
||||
DesktopButtonsView::DesktopButtonsView(QWidget *parent)
|
||||
: QDeclarativeView(parent)
|
||||
{
|
||||
setWindowFlags(Qt::X11BypassWindowManagerHint);
|
||||
setAttribute(Qt::WA_TranslucentBackground);
|
||||
setFrameShape(QFrame::NoFrame);
|
||||
QPalette pal = palette();
|
||||
pal.setColor(backgroundRole(), Qt::transparent);
|
||||
setPalette(pal);
|
||||
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
|
||||
// setup the scene
|
||||
QGraphicsScene* scene = new QGraphicsScene(this);
|
||||
m_addDesktopButton = new Plasma::PushButton();
|
||||
m_addDesktopButton->setIcon(KIcon("list-add"));
|
||||
m_removeDesktopButton = new Plasma::PushButton();
|
||||
m_removeDesktopButton->setIcon(KIcon("list-remove"));
|
||||
scene->addItem(m_addDesktopButton);
|
||||
scene->addItem(m_removeDesktopButton);
|
||||
connect(m_addDesktopButton, SIGNAL(clicked()), SIGNAL(addDesktop()));
|
||||
connect(m_removeDesktopButton, SIGNAL(clicked()), SIGNAL(removeDesktop()));
|
||||
|
||||
QGraphicsLinearLayout *layout = new QGraphicsLinearLayout;
|
||||
layout->addItem(m_addDesktopButton);
|
||||
layout->addItem(m_removeDesktopButton);
|
||||
|
||||
QGraphicsWidget *form = new QGraphicsWidget;
|
||||
form->setLayout(layout);
|
||||
form->setGeometry(0, 0, 64 * 2, 64);
|
||||
scene->addItem(form);
|
||||
|
||||
m_frame = new Plasma::FrameSvg(this);
|
||||
if (Plasma::Theme::defaultTheme()->currentThemeHasImage("translucent/dialogs/background")) {
|
||||
m_frame->setImagePath("translucent/dialogs/background");
|
||||
} else {
|
||||
m_frame->setImagePath("dialogs/background");
|
||||
foreach (const QString &importPath, KGlobal::dirs()->findDirs("module", "imports")) {
|
||||
engine()->addImportPath(importPath);
|
||||
}
|
||||
KDeclarative kdeclarative;
|
||||
kdeclarative.setDeclarativeEngine(engine());
|
||||
kdeclarative.initialize();
|
||||
kdeclarative.setupBindings();
|
||||
|
||||
rootContext()->setContextProperty("add", QVariant(true));
|
||||
rootContext()->setContextProperty("remove", QVariant(true));
|
||||
setSource(QUrl(KStandardDirs::locate("data", QLatin1String("kwin/effects/desktopgrid/main.qml"))));
|
||||
if (QObject *item = rootObject()->findChild<QObject*>("addButton")) {
|
||||
connect(item, SIGNAL(clicked()), SIGNAL(addDesktop()));
|
||||
}
|
||||
if (QObject *item = rootObject()->findChild<QObject*>("removeButton")) {
|
||||
connect(item, SIGNAL(clicked()), SIGNAL(removeDesktop()));
|
||||
}
|
||||
m_frame->setCacheAllRenderedFrames(true);
|
||||
m_frame->setEnabledBorders(Plasma::FrameSvg::AllBorders);
|
||||
qreal left, top, right, bottom;
|
||||
m_frame->getMargins(left, top, right, bottom);
|
||||
qreal width = form->size().width() + left + right;
|
||||
qreal height = form->size().height() + top + bottom;
|
||||
m_frame->resizeFrame(QSizeF(width, height));
|
||||
Plasma::WindowEffects::enableBlurBehind(winId(), true, m_frame->mask());
|
||||
form->setPos(left, top);
|
||||
scene->setSceneRect(QRectF(QPointF(0, 0), QSizeF(width, height)));
|
||||
setScene(scene);
|
||||
}
|
||||
|
||||
void DesktopButtonsView::windowInputMouseEvent(QMouseEvent* e)
|
||||
void DesktopButtonsView::windowInputMouseEvent(QMouseEvent *e)
|
||||
{
|
||||
if (e->type() == QEvent::MouseMove) {
|
||||
mouseMoveEvent(e);
|
||||
|
@ -1449,19 +1424,12 @@ void DesktopButtonsView::windowInputMouseEvent(QMouseEvent* e)
|
|||
|
||||
void DesktopButtonsView::setAddDesktopEnabled(bool enable)
|
||||
{
|
||||
m_addDesktopButton->setEnabled(enable);
|
||||
rootContext()->setContextProperty("add", QVariant(enable));
|
||||
}
|
||||
|
||||
void DesktopButtonsView::setRemoveDesktopEnabled(bool enable)
|
||||
{
|
||||
m_removeDesktopButton->setEnabled(enable);
|
||||
}
|
||||
|
||||
void DesktopButtonsView::drawBackground(QPainter* painter, const QRectF& rect)
|
||||
{
|
||||
Q_UNUSED(rect)
|
||||
painter->setRenderHint(QPainter::Antialiasing);
|
||||
m_frame->paintFrame(painter);
|
||||
rootContext()->setContextProperty("remove", QVariant(enable));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
|
|
@ -25,38 +25,25 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
#include <kwineffects.h>
|
||||
#include <kshortcut.h>
|
||||
#include <QObject>
|
||||
#include <QDeclarativeView>
|
||||
#include <QTimeLine>
|
||||
#include <QGraphicsView>
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
class PushButton;
|
||||
class FrameSvg;
|
||||
}
|
||||
|
||||
namespace KWin
|
||||
{
|
||||
|
||||
class PresentWindowsEffectProxy;
|
||||
|
||||
class DesktopButtonsView : public QGraphicsView
|
||||
class DesktopButtonsView : public QDeclarativeView
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit DesktopButtonsView(QWidget* parent = 0);
|
||||
explicit DesktopButtonsView(QWidget *parent = 0);
|
||||
void windowInputMouseEvent(QMouseEvent* e);
|
||||
void setAddDesktopEnabled(bool enable);
|
||||
void setRemoveDesktopEnabled(bool enable);
|
||||
virtual void drawBackground(QPainter* painter, const QRectF& rect);
|
||||
|
||||
Q_SIGNALS:
|
||||
void addDesktop();
|
||||
void removeDesktop();
|
||||
|
||||
private:
|
||||
Plasma::PushButton* m_addDesktopButton;
|
||||
Plasma::PushButton* m_removeDesktopButton;
|
||||
Plasma::FrameSvg* m_frame;
|
||||
};
|
||||
|
||||
class DesktopGridEffect
|
||||
|
|
44
effects/desktopgrid/main.qml
Normal file
44
effects/desktopgrid/main.qml
Normal file
|
@ -0,0 +1,44 @@
|
|||
/********************************************************************
|
||||
KWin - the KDE window manager
|
||||
This file is part of the KDE project.
|
||||
|
||||
Copyright (C) 2013 Martin Gräßlin <mgraesslin@kde.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*********************************************************************/
|
||||
import QtQuick 1.1
|
||||
import org.kde.plasma.components 0.1 as Plasma
|
||||
|
||||
Item {
|
||||
Plasma.ButtonRow {
|
||||
anchors.fill: parent
|
||||
exclusive: false
|
||||
Plasma.Button {
|
||||
id: removeButton
|
||||
objectName: "removeButton"
|
||||
enabled: remove
|
||||
width: 64
|
||||
height: 64
|
||||
iconSource: "list-remove"
|
||||
}
|
||||
Plasma.Button {
|
||||
id: addButton
|
||||
objectName: "addButton"
|
||||
enabled: add
|
||||
width: 64
|
||||
height: 64
|
||||
iconSource: "list-add"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -13,6 +13,10 @@ kde4_add_kcfg_files(kwin4_effect_builtins_sources presentwindows/presentwindowsc
|
|||
install( FILES
|
||||
presentwindows/presentwindows.desktop
|
||||
DESTINATION ${SERVICES_INSTALL_DIR}/kwin )
|
||||
install( FILES
|
||||
presentwindows/main.qml
|
||||
DESTINATION ${DATA_INSTALL_DIR}/kwin/effects/presentwindows/
|
||||
)
|
||||
|
||||
#######################################
|
||||
# Config
|
||||
|
|
32
effects/presentwindows/main.qml
Normal file
32
effects/presentwindows/main.qml
Normal file
|
@ -0,0 +1,32 @@
|
|||
/********************************************************************
|
||||
KWin - the KDE window manager
|
||||
This file is part of the KDE project.
|
||||
|
||||
Copyright (C) 2013 Martin Gräßlin <mgraesslin@kde.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*********************************************************************/
|
||||
import QtQuick 1.1
|
||||
import org.kde.plasma.components 0.1 as Plasma
|
||||
|
||||
Item {
|
||||
Plasma.Button {
|
||||
id: closeButton
|
||||
objectName: "closeButton"
|
||||
enabled: armed
|
||||
width: 32
|
||||
height: 32
|
||||
iconSource: "window-close"
|
||||
}
|
||||
}
|
|
@ -26,25 +26,24 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
#include <kaction.h>
|
||||
#include <KDE/KIcon>
|
||||
#include <KDE/KLocalizedString>
|
||||
#include <KDE/KStandardDirs>
|
||||
#include <kdebug.h>
|
||||
#include <kglobalsettings.h>
|
||||
#include <kdeclarative.h>
|
||||
|
||||
#include <kwinglutils.h>
|
||||
|
||||
#include <QMouseEvent>
|
||||
#include <QtGui/QPainter>
|
||||
#include <QGraphicsLinearLayout>
|
||||
#include <Plasma/FrameSvg>
|
||||
#include <Plasma/PushButton>
|
||||
#include <Plasma/Theme>
|
||||
#include <Plasma/WindowEffects>
|
||||
#include <netwm_def.h>
|
||||
|
||||
#include <math.h>
|
||||
#include <assert.h>
|
||||
#include <limits.h>
|
||||
#include <QApplication>
|
||||
#include <QDeclarativeContext>
|
||||
#include <QDeclarativeEngine>
|
||||
#include <QDesktopWidget>
|
||||
#include <QGraphicsObject>
|
||||
#include <QTimer>
|
||||
#include <QVector2D>
|
||||
#include <QVector4D>
|
||||
|
@ -1927,51 +1926,29 @@ void PresentWindowsEffect::screenCountChanged()
|
|||
/************************************************
|
||||
* CloseWindowView
|
||||
************************************************/
|
||||
CloseWindowView::CloseWindowView(QWidget* parent)
|
||||
: QGraphicsView(parent)
|
||||
CloseWindowView::CloseWindowView(QWidget *parent)
|
||||
: QDeclarativeView(parent)
|
||||
, m_armTimer(new QTimer(this))
|
||||
{
|
||||
setWindowFlags(Qt::X11BypassWindowManagerHint);
|
||||
setAttribute(Qt::WA_TranslucentBackground);
|
||||
setFrameShape(QFrame::NoFrame);
|
||||
QPalette pal = palette();
|
||||
pal.setColor(backgroundRole(), Qt::transparent);
|
||||
setPalette(pal);
|
||||
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
|
||||
// setup the scene
|
||||
QGraphicsScene* scene = new QGraphicsScene(this);
|
||||
m_closeButton = new Plasma::PushButton();
|
||||
m_closeButton->setIcon(KIcon("window-close"));
|
||||
scene->addItem(m_closeButton);
|
||||
connect(m_closeButton, SIGNAL(clicked()), SIGNAL(close()));
|
||||
|
||||
QGraphicsLinearLayout *layout = new QGraphicsLinearLayout;
|
||||
layout->addItem(m_closeButton);
|
||||
|
||||
QGraphicsWidget *form = new QGraphicsWidget;
|
||||
form->setLayout(layout);
|
||||
form->setGeometry(0, 0, 32, 32);
|
||||
scene->addItem(form);
|
||||
|
||||
m_frame = new Plasma::FrameSvg(this);
|
||||
if (Plasma::Theme::defaultTheme()->currentThemeHasImage("translucent/dialogs/background")) {
|
||||
m_frame->setImagePath("translucent/dialogs/background");
|
||||
} else {
|
||||
m_frame->setImagePath("dialogs/background");
|
||||
foreach (const QString &importPath, KGlobal::dirs()->findDirs("module", "imports")) {
|
||||
engine()->addImportPath(importPath);
|
||||
}
|
||||
KDeclarative kdeclarative;
|
||||
kdeclarative.setDeclarativeEngine(engine());
|
||||
kdeclarative.initialize();
|
||||
kdeclarative.setupBindings();
|
||||
|
||||
rootContext()->setContextProperty("armed", QVariant(false));
|
||||
|
||||
setSource(QUrl(KStandardDirs::locate("data", QLatin1String("kwin/effects/presentwindows/main.qml"))));
|
||||
if (QObject *item = rootObject()->findChild<QObject*>("closeButton")) {
|
||||
connect(item, SIGNAL(clicked()), SIGNAL(close()));
|
||||
}
|
||||
m_frame->setCacheAllRenderedFrames(true);
|
||||
m_frame->setEnabledBorders(Plasma::FrameSvg::AllBorders);
|
||||
qreal left, top, right, bottom;
|
||||
m_frame->getMargins(left, top, right, bottom);
|
||||
qreal width = form->size().width() + left + right;
|
||||
qreal height = form->size().height() + top + bottom;
|
||||
m_frame->resizeFrame(QSizeF(width, height));
|
||||
Plasma::WindowEffects::enableBlurBehind(winId(), true, m_frame->mask());
|
||||
form->setPos(left, top);
|
||||
scene->setSceneRect(QRectF(QPointF(0, 0), QSizeF(width, height)));
|
||||
setScene(scene);
|
||||
|
||||
// setup the timer - attempt to prevent accidental clicks
|
||||
m_armTimer->setSingleShot(true);
|
||||
|
@ -1979,9 +1956,9 @@ CloseWindowView::CloseWindowView(QWidget* parent)
|
|||
connect(m_armTimer, SIGNAL(timeout()), SLOT(arm()));
|
||||
}
|
||||
|
||||
void CloseWindowView::windowInputMouseEvent(QMouseEvent* e)
|
||||
void CloseWindowView::windowInputMouseEvent(QMouseEvent *e)
|
||||
{
|
||||
if (!isEnabled())
|
||||
if (m_armTimer->isActive())
|
||||
return;
|
||||
if (e->type() == QEvent::MouseMove) {
|
||||
mouseMoveEvent(e);
|
||||
|
@ -1994,25 +1971,17 @@ void CloseWindowView::windowInputMouseEvent(QMouseEvent* e)
|
|||
}
|
||||
}
|
||||
|
||||
void CloseWindowView::drawBackground(QPainter* painter, const QRectF& rect)
|
||||
{
|
||||
Q_UNUSED(rect)
|
||||
painter->setRenderHint(QPainter::Antialiasing);
|
||||
m_frame->paintFrame(painter);
|
||||
}
|
||||
|
||||
void CloseWindowView::arm()
|
||||
{
|
||||
setEnabled(true);
|
||||
rootContext()->setContextProperty("armed", QVariant(true));
|
||||
}
|
||||
|
||||
void CloseWindowView::disarm()
|
||||
{
|
||||
setEnabled(false);
|
||||
rootContext()->setContextProperty("armed", QVariant(false));
|
||||
m_armTimer->start();
|
||||
}
|
||||
|
||||
|
||||
} // namespace
|
||||
|
||||
#include "presentwindows.moc"
|
||||
|
|
|
@ -26,26 +26,18 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
|
||||
#include <kwineffects.h>
|
||||
#include <kshortcut.h>
|
||||
#include <QGraphicsView>
|
||||
#include <QDeclarativeView>
|
||||
|
||||
class QTimer;
|
||||
namespace Plasma
|
||||
{
|
||||
class PushButton;
|
||||
class FrameSvg;
|
||||
}
|
||||
|
||||
namespace KWin
|
||||
{
|
||||
|
||||
class CloseWindowView : public QGraphicsView
|
||||
class CloseWindowView : public QDeclarativeView
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit CloseWindowView(QWidget* parent = 0);
|
||||
explicit CloseWindowView(QWidget *parent = 0);
|
||||
void windowInputMouseEvent(QMouseEvent* e);
|
||||
virtual void drawBackground(QPainter* painter, const QRectF& rect);
|
||||
|
||||
void disarm();
|
||||
public slots:
|
||||
void arm();
|
||||
|
@ -54,8 +46,6 @@ Q_SIGNALS:
|
|||
void close();
|
||||
|
||||
private:
|
||||
Plasma::PushButton* m_closeButton;
|
||||
Plasma::FrameSvg* m_frame;
|
||||
QTimer* m_armTimer;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue