From 8cf8f57966a8db2deae040ce06574bd370be9ac2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Thu, 8 Aug 2013 13:09:11 +0200 Subject: [PATCH] Port tabbox to QtQuick 2 Straight forward port. Note: this is currently crashing deep down in QtQuick. To circumvent the crashes it helps to disable the property highlightFollowsCurrentItem in the listviews. This solves the problem that QtQuick crashes on first loading. Unfortunately it still crashes if one tries to invoke TabBox for the second time. --- tabbox/declarative.cpp | 39 ++++++++----------- tabbox/declarative.h | 10 ++--- tabbox/qml/IconTabBox.qml | 6 +-- tabbox/qml/ShadowedSvgItem.qml | 4 +- .../clients/big_icons/contents/ui/main.qml | 6 +-- .../qml/clients/compact/contents/ui/main.qml | 10 ++--- .../clients/informative/contents/ui/main.qml | 10 ++--- .../present_windows/contents/ui/main.qml | 6 +-- .../clients/small_icons/contents/ui/main.qml | 6 +-- tabbox/qml/clients/text/contents/ui/main.qml | 10 ++--- .../clients/thumbnails/contents/ui/main.qml | 6 +-- .../clients/window_strip/contents/ui/main.qml | 8 ++-- .../desktops/informative/contents/ui/main.qml | 10 ++--- .../desktops/previews/contents/ui/main.qml | 6 +-- tabbox/qml/tabbox.qml | 2 +- tabbox/tabboxhandler.cpp | 6 +-- tabbox/tests/mock_declarative.cpp | 2 +- 17 files changed, 71 insertions(+), 76 deletions(-) diff --git a/tabbox/declarative.cpp b/tabbox/declarative.cpp index fc7f824a24..b3bb21b86b 100644 --- a/tabbox/declarative.cpp +++ b/tabbox/declarative.cpp @@ -23,12 +23,12 @@ along with this program. If not, see . #include "clientmodel.h" // Qt #include -#include -#include -#include +#include +#include #include -#include +#include #include +#include #include // include KDE @@ -55,7 +55,7 @@ namespace TabBox { ImageProvider::ImageProvider(QAbstractItemModel *model) - : QDeclarativeImageProvider(QDeclarativeImageProvider::Pixmap) + : QQuickImageProvider(QQuickImageProvider::Pixmap) , m_model(model) { } @@ -114,8 +114,8 @@ QPixmap ImageProvider::requestPixmap(const QString &id, QSize *size, const QSize } -DeclarativeView::DeclarativeView(QAbstractItemModel *model, TabBoxConfig::TabBoxMode mode, QWidget *parent) - : QDeclarativeView(parent) +DeclarativeView::DeclarativeView(QAbstractItemModel *model, TabBoxConfig::TabBoxMode mode, QQuickWindow *parent) + : QQuickView(parent) , m_model(model) , m_mode(mode) , m_currentScreenGeometry() @@ -124,16 +124,13 @@ DeclarativeView::DeclarativeView(QAbstractItemModel *model, TabBoxConfig::TabBox , m_cachedWidth(0) , m_cachedHeight(0) { - setAttribute(Qt::WA_TranslucentBackground); - setWindowFlags(Qt::X11BypassWindowManagerHint); + setColor(Qt::transparent); + setFlags(Qt::X11BypassWindowManagerHint); if (tabBox->embedded()) { - setResizeMode(QDeclarativeView::SizeRootObjectToView); + setResizeMode(QQuickView::SizeRootObjectToView); } else { - setResizeMode(QDeclarativeView::SizeViewToRootObject); + setResizeMode(QQuickView::SizeViewToRootObject); } - QPalette pal = palette(); - pal.setColor(backgroundRole(), Qt::transparent); - setPalette(pal); engine()->addImageProvider(QLatin1String("client"), new ImageProvider(model)); #warning TabBox needs porting of KDeclarative #if KWIN_QT5_PORTING @@ -192,7 +189,7 @@ void DeclarativeView::showEvent(QShowEvent *event) slotUpdateGeometry(); QResizeEvent re(size(), size()); // to set mask and blurring. resizeEvent(&re); - QGraphicsView::showEvent(event); + QQuickView::showEvent(event); } void DeclarativeView::resizeEvent(QResizeEvent *event) @@ -202,7 +199,6 @@ void DeclarativeView::resizeEvent(QResizeEvent *event) } else { const QString maskImagePath = rootObject()->property("maskImagePath").toString(); if (maskImagePath.isEmpty()) { - clearMask(); KWindowEffects::enableBlurBehind(winId(), false); } else { const double maskWidth = rootObject()->property("maskWidth").toDouble(); @@ -217,7 +213,6 @@ void DeclarativeView::resizeEvent(QResizeEvent *event) if (Workspace::self()->compositing() && effects) { // blur background?! KWindowEffects::enableBlurBehind(winId(), static_cast(effects)->provides(Effect::Blur), mask); - clearMask(); } else #endif { @@ -226,12 +221,12 @@ void DeclarativeView::resizeEvent(QResizeEvent *event) } } } - QDeclarativeView::resizeEvent(event); + QQuickView::resizeEvent(event); } void DeclarativeView::hideEvent(QHideEvent *event) { - QWidget::hideEvent(event); + QQuickView::hideEvent(event); #ifndef TABBOX_KCM if (tabBox->embedded()) { Client *c = Workspace::self()->findClient(WindowMatchPredicate(tabBox->embedded())); @@ -304,7 +299,7 @@ void DeclarativeView::slotUpdateGeometry() 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); - m_relativePos = pos(); + m_relativePos = position(); } } @@ -410,11 +405,11 @@ void DeclarativeView::slotEmbeddedChanged(bool enabled) { if (enabled) { // cache the width - setResizeMode(QDeclarativeView::SizeRootObjectToView); + setResizeMode(QQuickView::SizeRootObjectToView); m_cachedWidth = rootObject()->property("width").toInt(); m_cachedHeight = rootObject()->property("height").toInt(); } else { - setResizeMode(QDeclarativeView::SizeViewToRootObject); + setResizeMode(QQuickView::SizeViewToRootObject); if (m_cachedWidth != 0 && m_cachedHeight != 0) { rootObject()->setProperty("width", m_cachedWidth); rootObject()->setProperty("height", m_cachedHeight); diff --git a/tabbox/declarative.h b/tabbox/declarative.h index 99b83601ff..bfcdd18588 100644 --- a/tabbox/declarative.h +++ b/tabbox/declarative.h @@ -20,8 +20,8 @@ along with this program. If not, see . #ifndef KWIN_TABBOX_DECLARATIVE_H #define KWIN_TABBOX_DECLARATIVE_H // includes -#include -#include +#include +#include #include #include "tabboxconfig.h" @@ -40,7 +40,7 @@ namespace KWin namespace TabBox { -class ImageProvider : public QDeclarativeImageProvider +class ImageProvider : public QQuickImageProvider { public: explicit ImageProvider(QAbstractItemModel *model); @@ -50,11 +50,11 @@ private: QAbstractItemModel *m_model; }; -class DeclarativeView : public QDeclarativeView +class DeclarativeView : public QQuickView { Q_OBJECT public: - DeclarativeView(QAbstractItemModel *model, TabBoxConfig::TabBoxMode mode, QWidget *parent = NULL); + DeclarativeView(QAbstractItemModel *model, TabBoxConfig::TabBoxMode mode, QQuickWindow *parent = NULL); virtual void showEvent(QShowEvent *event); virtual void resizeEvent(QResizeEvent *event); void setCurrentIndex(const QModelIndex &index, bool disableAnimation = false); diff --git a/tabbox/qml/IconTabBox.qml b/tabbox/qml/IconTabBox.qml index c59526183c..090fc1292f 100644 --- a/tabbox/qml/IconTabBox.qml +++ b/tabbox/qml/IconTabBox.qml @@ -17,9 +17,9 @@ 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 . *********************************************************************/ -import QtQuick 1.0 -import org.kde.plasma.core 0.1 as PlasmaCore -import org.kde.qtextracomponents 0.1 +import QtQuick 2.0 +import org.kde.plasma.core 2.0 as PlasmaCore +import org.kde.qtextracomponents 2.0 Item { id: iconsTabBox diff --git a/tabbox/qml/ShadowedSvgItem.qml b/tabbox/qml/ShadowedSvgItem.qml index 76d59221e6..dd39ac20c7 100644 --- a/tabbox/qml/ShadowedSvgItem.qml +++ b/tabbox/qml/ShadowedSvgItem.qml @@ -18,8 +18,8 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . *********************************************************************/ -import QtQuick 1.0 -import org.kde.plasma.core 0.1 as PlasmaCore +import QtQuick 2.0 +import org.kde.plasma.core 2.0 as PlasmaCore Item { property double leftMargin: shadow.margins.left + background.margins.left diff --git a/tabbox/qml/clients/big_icons/contents/ui/main.qml b/tabbox/qml/clients/big_icons/contents/ui/main.qml index 30e3b20bf8..fe3cb8ca92 100644 --- a/tabbox/qml/clients/big_icons/contents/ui/main.qml +++ b/tabbox/qml/clients/big_icons/contents/ui/main.qml @@ -17,9 +17,9 @@ 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 . *********************************************************************/ -import QtQuick 1.0 -import org.kde.plasma.core 0.1 as PlasmaCore -import org.kde.qtextracomponents 0.1 +import QtQuick 2.0 +import org.kde.plasma.core 2.0 as PlasmaCore +import org.kde.qtextracomponents 2.0 Item { id: bigIconsTabBox diff --git a/tabbox/qml/clients/compact/contents/ui/main.qml b/tabbox/qml/clients/compact/contents/ui/main.qml index 19cf79f6ed..6dddfa6614 100644 --- a/tabbox/qml/clients/compact/contents/ui/main.qml +++ b/tabbox/qml/clients/compact/contents/ui/main.qml @@ -17,9 +17,9 @@ 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 . *********************************************************************/ -import QtQuick 1.0 -import org.kde.plasma.core 0.1 as PlasmaCore -import org.kde.qtextracomponents 0.1 +import QtQuick 2.0 +import org.kde.plasma.core 2.0 as PlasmaCore +import org.kde.qtextracomponents 2.0 Item { id: compactTabBox @@ -142,7 +142,7 @@ Item { function calculateMaxRowWidth() { var width = 0; var textElement = Qt.createQmlObject( - 'import QtQuick 1.0;' + 'import QtQuick 2.0;' + 'Text {\n' + ' text: "' + itemCaption(compactTabBox.longestCaption, true) + '"\n' + ' font.bold: true\n' @@ -159,7 +159,7 @@ Item { **/ function calcRowHeight() { var textElement = Qt.createQmlObject( - 'import QtQuick 1.0;' + 'import QtQuick 2.0;' + 'Text {\n' + ' text: "Some Text"\n' + ' font.bold: true\n' diff --git a/tabbox/qml/clients/informative/contents/ui/main.qml b/tabbox/qml/clients/informative/contents/ui/main.qml index c52186950a..94bf50f025 100644 --- a/tabbox/qml/clients/informative/contents/ui/main.qml +++ b/tabbox/qml/clients/informative/contents/ui/main.qml @@ -17,9 +17,9 @@ 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 . *********************************************************************/ -import QtQuick 1.0 -import org.kde.plasma.core 0.1 as PlasmaCore -import org.kde.qtextracomponents 0.1 +import QtQuick 2.0 +import org.kde.plasma.core 2.0 as PlasmaCore +import org.kde.qtextracomponents 2.0 Item { id: informativeTabBox @@ -158,7 +158,7 @@ Item { function calculateMaxRowWidth() { var width = 0; var textElement = Qt.createQmlObject( - 'import QtQuick 1.0;' + 'import QtQuick 2.0;' + 'Text {\n' + ' text: "' + itemCaption(informativeTabBox.longestCaption, true) + '"\n' + ' font.bold: true\n' @@ -175,7 +175,7 @@ Item { **/ function calcRowHeight() { var textElement = Qt.createQmlObject( - 'import QtQuick 1.0;' + 'import QtQuick 2.0;' + 'Text {\n' + ' text: "Some Text"\n' + ' font.bold: true\n' diff --git a/tabbox/qml/clients/present_windows/contents/ui/main.qml b/tabbox/qml/clients/present_windows/contents/ui/main.qml index 17531d8c43..ae54594685 100644 --- a/tabbox/qml/clients/present_windows/contents/ui/main.qml +++ b/tabbox/qml/clients/present_windows/contents/ui/main.qml @@ -17,9 +17,9 @@ 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 . *********************************************************************/ -import QtQuick 1.1 -import org.kde.plasma.core 0.1 as PlasmaCore -import org.kde.qtextracomponents 0.1 +import QtQuick 2.0 +import org.kde.plasma.core 2.0 as PlasmaCore +import org.kde.qtextracomponents 2.0 import org.kde.kwin 0.1 as KWin Item { diff --git a/tabbox/qml/clients/small_icons/contents/ui/main.qml b/tabbox/qml/clients/small_icons/contents/ui/main.qml index a3e862fbe5..f0b055d1d6 100644 --- a/tabbox/qml/clients/small_icons/contents/ui/main.qml +++ b/tabbox/qml/clients/small_icons/contents/ui/main.qml @@ -17,9 +17,9 @@ 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 . *********************************************************************/ -import QtQuick 1.0 -import org.kde.plasma.core 0.1 as PlasmaCore -import org.kde.qtextracomponents 0.1 +import QtQuick 2.0 +import org.kde.plasma.core 2.0 as PlasmaCore +import org.kde.qtextracomponents 2.0 Item { id: smallIconsTabBox diff --git a/tabbox/qml/clients/text/contents/ui/main.qml b/tabbox/qml/clients/text/contents/ui/main.qml index aac7387c72..8bb7fce6fb 100644 --- a/tabbox/qml/clients/text/contents/ui/main.qml +++ b/tabbox/qml/clients/text/contents/ui/main.qml @@ -17,9 +17,9 @@ 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 . *********************************************************************/ -import QtQuick 1.0 -import org.kde.plasma.core 0.1 as PlasmaCore -import org.kde.qtextracomponents 0.1 +import QtQuick 2.0 +import org.kde.plasma.core 2.0 as PlasmaCore +import org.kde.qtextracomponents 2.0 Item { id: textTabBox @@ -109,7 +109,7 @@ Item { function calculateMaxRowWidth() { var width = 0; var textElement = Qt.createQmlObject( - 'import QtQuick 1.0;' + 'import QtQuick 2.0;' + 'Text {\n' + ' text: "' + textTabBox.longestCaption + '"\n' + ' visible: false\n' @@ -125,7 +125,7 @@ Item { **/ function calcRowHeight() { var textElement = Qt.createQmlObject( - 'import QtQuick 1.0;' + 'import QtQuick 2.0;' + 'Text {\n' + ' text: "Some Text"\n' + ' visible: false\n' diff --git a/tabbox/qml/clients/thumbnails/contents/ui/main.qml b/tabbox/qml/clients/thumbnails/contents/ui/main.qml index dda3b00009..b24fd1c877 100644 --- a/tabbox/qml/clients/thumbnails/contents/ui/main.qml +++ b/tabbox/qml/clients/thumbnails/contents/ui/main.qml @@ -17,9 +17,9 @@ 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 . *********************************************************************/ -import QtQuick 1.0 -import org.kde.plasma.core 0.1 as PlasmaCore -import org.kde.qtextracomponents 0.1 +import QtQuick 2.0 +import org.kde.plasma.core 2.0 as PlasmaCore +import org.kde.qtextracomponents 2.0 import org.kde.kwin 0.1 as KWin Item { diff --git a/tabbox/qml/clients/window_strip/contents/ui/main.qml b/tabbox/qml/clients/window_strip/contents/ui/main.qml index d242f68a7e..bd2d40eee1 100644 --- a/tabbox/qml/clients/window_strip/contents/ui/main.qml +++ b/tabbox/qml/clients/window_strip/contents/ui/main.qml @@ -18,11 +18,11 @@ 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 . *********************************************************************/ -import QtQuick 1.0 -import org.kde.plasma.core 0.1 as PlasmaCore -import org.kde.plasma.components 0.1 as PlasmaComponents +import QtQuick 2.0 +import org.kde.plasma.core 2.0 as PlasmaCore +import org.kde.plasma.components 2.0 as PlasmaComponents import org.kde.plasma.mobilecomponents 0.1 as MobileComponents -import org.kde.qtextracomponents 0.1 +import org.kde.qtextracomponents 2.0 import org.kde.kwin 0.1 as KWin Item { diff --git a/tabbox/qml/desktops/informative/contents/ui/main.qml b/tabbox/qml/desktops/informative/contents/ui/main.qml index 0f43e37e23..35547a8a26 100644 --- a/tabbox/qml/desktops/informative/contents/ui/main.qml +++ b/tabbox/qml/desktops/informative/contents/ui/main.qml @@ -17,9 +17,9 @@ 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 . *********************************************************************/ -import QtQuick 1.0 -import org.kde.plasma.core 0.1 as PlasmaCore -import org.kde.qtextracomponents 0.1 +import QtQuick 2.0 +import org.kde.plasma.core 2.0 as PlasmaCore +import org.kde.qtextracomponents 2.0 Item { id: desktopTabBox @@ -122,7 +122,7 @@ Item { function calculateMaxRowWidth() { var width = 0; var textElement = Qt.createQmlObject( - 'import QtQuick 1.0;' + 'import QtQuick 2.0;' + 'Text {\n' + ' text: "' + desktopTabBox.longestCaption + '"\n' + ' font.bold: true\n' @@ -139,7 +139,7 @@ Item { **/ function calcRowHeight() { var textElement = Qt.createQmlObject( - 'import QtQuick 1.0;' + 'import QtQuick 2.0;' + 'Text {\n' + ' text: "Some Text"\n' + ' font.bold: true\n' diff --git a/tabbox/qml/desktops/previews/contents/ui/main.qml b/tabbox/qml/desktops/previews/contents/ui/main.qml index 38a02dd1e8..3442a76cb9 100644 --- a/tabbox/qml/desktops/previews/contents/ui/main.qml +++ b/tabbox/qml/desktops/previews/contents/ui/main.qml @@ -17,9 +17,9 @@ 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 . *********************************************************************/ -import QtQuick 1.0 -import org.kde.plasma.core 0.1 as PlasmaCore -import org.kde.qtextracomponents 0.1 +import QtQuick 2.0 +import org.kde.plasma.core 2.0 as PlasmaCore +import org.kde.qtextracomponents 2.0 import org.kde.kwin 0.1 as KWin Item { diff --git a/tabbox/qml/tabbox.qml b/tabbox/qml/tabbox.qml index 9fccc0bdff..d81e691030 100644 --- a/tabbox/qml/tabbox.qml +++ b/tabbox/qml/tabbox.qml @@ -17,7 +17,7 @@ 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 . *********************************************************************/ -import QtQuick 1.0 +import QtQuick 2.0 Loader { id: loader diff --git a/tabbox/tabboxhandler.cpp b/tabbox/tabboxhandler.cpp index f99bd27e1e..80ab5349a3 100644 --- a/tabbox/tabboxhandler.cpp +++ b/tabbox/tabboxhandler.cpp @@ -118,7 +118,7 @@ void TabBoxHandlerPrivate::updateHighlightWindows() Display *dpy = QX11Info::display(); TabBoxClient *currentClient = q->client(index); - QWidget *w = NULL; + QWindow *w = NULL; if (m_declarativeView && m_declarativeView->isVisible()) { w = m_declarativeView; } @@ -230,7 +230,7 @@ void TabBoxHandler::show() } dv = d->m_declarativeDesktopView; } - if (dv->status() == QDeclarativeView::Ready && dv->rootObject()) { + if (dv->status() == QQuickView::Ready && dv->rootObject()) { dv->show(); dv->setCurrentIndex(d->index, d->config.tabBoxMode() == TabBoxConfig::ClientTabBox); } else { @@ -386,7 +386,7 @@ void TabBoxHandler::grabbedKeyEvent(QKeyEvent* event) const bool TabBoxHandler::containsPos(const QPoint& pos) const { - QWidget *w = NULL; + QWindow *w = NULL; if (d->m_declarativeView && d->m_declarativeView->isVisible()) { w = d->m_declarativeView; } else if (d->m_declarativeDesktopView && d->m_declarativeDesktopView->isVisible()) { diff --git a/tabbox/tests/mock_declarative.cpp b/tabbox/tests/mock_declarative.cpp index 67ac56a9be..4065acb6d9 100644 --- a/tabbox/tests/mock_declarative.cpp +++ b/tabbox/tests/mock_declarative.cpp @@ -24,7 +24,7 @@ namespace KWin namespace TabBox { DeclarativeView::DeclarativeView(QAbstractItemModel *model, TabBoxConfig::TabBoxMode mode, QWidget *parent) - : QDeclarativeView(parent) + : QQuickView(parent) { Q_UNUSED(model) Q_UNUSED(mode)