Present Window's close button ported to QtQuick 2

This commit is contained in:
Martin Gräßlin 2013-08-05 14:08:23 +02:00
parent 35bb48df2c
commit 47cf35720f
4 changed files with 21 additions and 31 deletions

View file

@ -13,6 +13,7 @@ set(kwin_effect_KDE_LIBS
set(kwin_effect_QT_LIBS
${Qt5Declarative_LIBRARIES}
${Qt5Quick_LIBRARIES}
${Qt5X11Extras_LIBRARIES}
${Qt5DBus_LIBRARIES}
)

View file

@ -17,16 +17,17 @@ 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
import QtQuick 2.0
import org.kde.plasma.components 2.0 as Plasma
Item {
width: 32
height: 32
Plasma.Button {
id: closeButton
objectName: "closeButton"
enabled: armed
width: 32
height: 32
iconSource: "window-close"
anchors.fill: parent
}
}

View file

@ -41,8 +41,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <assert.h>
#include <limits.h>
#include <QApplication>
#include <QDeclarativeContext>
#include <QDeclarativeEngine>
#include <QQmlContext>
#include <QQmlEngine>
#include <QQuickItem>
#include <QDesktopWidget>
#include <QGraphicsObject>
#include <QTimer>
@ -1478,7 +1479,7 @@ void PresentWindowsEffect::setActive(bool active)
if (!m_doNotCloseWindows) {
m_closeView = new CloseWindowView();
connect(m_closeView, SIGNAL(close()), SLOT(closeWindow()));
connect(m_closeView, &CloseWindowView::requestClose, this, &PresentWindowsEffect::closeWindow);
}
// Add every single window to m_windowData (Just calling [w] creates it)
@ -1690,12 +1691,12 @@ void PresentWindowsEffect::updateCloseWindow()
return;
const QRectF rect(m_motionManager.targetGeometry(m_highlightedWindow));
if (2*m_closeView->sceneRect().width() > rect.width() && 2*m_closeView->sceneRect().height() > rect.height()) {
if (2*m_closeView->width() > rect.width() && 2*m_closeView->height() > rect.height()) {
// not for tiny windows (eg. with many windows) - they might become unselectable
m_closeView->hide();
return;
}
QRect cvr(QPoint(0,0), m_closeView->sceneRect().size().toSize());
QRect cvr(QPoint(0,0), m_closeView->size());
switch (m_closeButtonCorner)
{
case Qt::TopLeftCorner:
@ -1938,31 +1939,18 @@ void PresentWindowsEffect::screenCountChanged()
/************************************************
* CloseWindowView
************************************************/
CloseWindowView::CloseWindowView(QWidget *parent)
: QDeclarativeView(parent)
CloseWindowView::CloseWindowView(QWindow *parent)
: QQuickView(parent)
, m_armTimer(new QTimer(this))
{
setWindowFlags(Qt::X11BypassWindowManagerHint);
setAttribute(Qt::WA_TranslucentBackground);
QPalette pal = palette();
pal.setColor(backgroundRole(), Qt::transparent);
setPalette(pal);
for (const QString &importPath : KGlobal::dirs()->findDirs("module", QStringLiteral("imports"))) {
engine()->addImportPath(importPath);
}
#warning Port declarative code to QtQuick2
#if KWIN_QT5_PORTING
KDeclarative kdeclarative;
kdeclarative.setDeclarativeEngine(engine());
kdeclarative.initialize();
kdeclarative.setupBindings();
#endif
setFlags(Qt::X11BypassWindowManagerHint);
setColor(Qt::transparent);
rootContext()->setContextProperty(QStringLiteral("armed"), QVariant(false));
setSource(QUrl(KStandardDirs::locate("data", QStringLiteral("kwin/effects/presentwindows/main.qml"))));
if (QObject *item = rootObject()->findChild<QObject*>(QStringLiteral("closeButton"))) {
connect(item, SIGNAL(clicked()), SIGNAL(close()));
connect(item, SIGNAL(clicked()), SIGNAL(requestClose()));
}
// setup the timer - attempt to prevent accidental clicks

View file

@ -26,24 +26,24 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <kwineffects.h>
#include <kshortcut.h>
#include <QDeclarativeView>
#include <QQuickView>
class QTimer;
namespace KWin
{
class CloseWindowView : public QDeclarativeView
class CloseWindowView : public QQuickView
{
Q_OBJECT
public:
explicit CloseWindowView(QWidget *parent = 0);
explicit CloseWindowView(QWindow *parent = 0);
void windowInputMouseEvent(QMouseEvent* e);
void disarm();
public Q_SLOTS:
void arm();
Q_SIGNALS:
void close();
void requestClose();
private:
QTimer* m_armTimer;