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.
icc-effect-5.14.5
Martin Gräßlin 2013-08-08 13:09:11 +02:00
parent 69b109b5b9
commit 8cf8f57966
17 changed files with 71 additions and 76 deletions

View File

@ -23,12 +23,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "clientmodel.h" #include "clientmodel.h"
// Qt // Qt
#include <QApplication> #include <QApplication>
#include <QtDeclarative/qdeclarative.h> #include <QtQml/QQmlContext>
#include <QtDeclarative/QDeclarativeContext> #include <QtQml/QQmlEngine>
#include <QtDeclarative/QDeclarativeEngine>
#include <QDesktopWidget> #include <QDesktopWidget>
#include <QGraphicsObject> #include <QPainter>
#include <QtGui/QResizeEvent> #include <QtGui/QResizeEvent>
#include <QQuickItem>
#include <QX11Info> #include <QX11Info>
// include KDE // include KDE
@ -55,7 +55,7 @@ namespace TabBox
{ {
ImageProvider::ImageProvider(QAbstractItemModel *model) ImageProvider::ImageProvider(QAbstractItemModel *model)
: QDeclarativeImageProvider(QDeclarativeImageProvider::Pixmap) : QQuickImageProvider(QQuickImageProvider::Pixmap)
, m_model(model) , 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) DeclarativeView::DeclarativeView(QAbstractItemModel *model, TabBoxConfig::TabBoxMode mode, QQuickWindow *parent)
: QDeclarativeView(parent) : QQuickView(parent)
, m_model(model) , m_model(model)
, m_mode(mode) , m_mode(mode)
, m_currentScreenGeometry() , m_currentScreenGeometry()
@ -124,16 +124,13 @@ DeclarativeView::DeclarativeView(QAbstractItemModel *model, TabBoxConfig::TabBox
, m_cachedWidth(0) , m_cachedWidth(0)
, m_cachedHeight(0) , m_cachedHeight(0)
{ {
setAttribute(Qt::WA_TranslucentBackground); setColor(Qt::transparent);
setWindowFlags(Qt::X11BypassWindowManagerHint); setFlags(Qt::X11BypassWindowManagerHint);
if (tabBox->embedded()) { if (tabBox->embedded()) {
setResizeMode(QDeclarativeView::SizeRootObjectToView); setResizeMode(QQuickView::SizeRootObjectToView);
} else { } else {
setResizeMode(QDeclarativeView::SizeViewToRootObject); setResizeMode(QQuickView::SizeViewToRootObject);
} }
QPalette pal = palette();
pal.setColor(backgroundRole(), Qt::transparent);
setPalette(pal);
engine()->addImageProvider(QLatin1String("client"), new ImageProvider(model)); engine()->addImageProvider(QLatin1String("client"), new ImageProvider(model));
#warning TabBox needs porting of KDeclarative #warning TabBox needs porting of KDeclarative
#if KWIN_QT5_PORTING #if KWIN_QT5_PORTING
@ -192,7 +189,7 @@ void DeclarativeView::showEvent(QShowEvent *event)
slotUpdateGeometry(); slotUpdateGeometry();
QResizeEvent re(size(), size()); // to set mask and blurring. QResizeEvent re(size(), size()); // to set mask and blurring.
resizeEvent(&re); resizeEvent(&re);
QGraphicsView::showEvent(event); QQuickView::showEvent(event);
} }
void DeclarativeView::resizeEvent(QResizeEvent *event) void DeclarativeView::resizeEvent(QResizeEvent *event)
@ -202,7 +199,6 @@ void DeclarativeView::resizeEvent(QResizeEvent *event)
} else { } else {
const QString maskImagePath = rootObject()->property("maskImagePath").toString(); const QString maskImagePath = rootObject()->property("maskImagePath").toString();
if (maskImagePath.isEmpty()) { if (maskImagePath.isEmpty()) {
clearMask();
KWindowEffects::enableBlurBehind(winId(), false); KWindowEffects::enableBlurBehind(winId(), false);
} else { } else {
const double maskWidth = rootObject()->property("maskWidth").toDouble(); const double maskWidth = rootObject()->property("maskWidth").toDouble();
@ -217,7 +213,6 @@ void DeclarativeView::resizeEvent(QResizeEvent *event)
if (Workspace::self()->compositing() && effects) { if (Workspace::self()->compositing() && effects) {
// blur background?! // blur background?!
KWindowEffects::enableBlurBehind(winId(), static_cast<EffectsHandlerImpl*>(effects)->provides(Effect::Blur), mask); KWindowEffects::enableBlurBehind(winId(), static_cast<EffectsHandlerImpl*>(effects)->provides(Effect::Blur), mask);
clearMask();
} else } else
#endif #endif
{ {
@ -226,12 +221,12 @@ void DeclarativeView::resizeEvent(QResizeEvent *event)
} }
} }
} }
QDeclarativeView::resizeEvent(event); QQuickView::resizeEvent(event);
} }
void DeclarativeView::hideEvent(QHideEvent *event) void DeclarativeView::hideEvent(QHideEvent *event)
{ {
QWidget::hideEvent(event); QQuickView::hideEvent(event);
#ifndef TABBOX_KCM #ifndef TABBOX_KCM
if (tabBox->embedded()) { if (tabBox->embedded()) {
Client *c = Workspace::self()->findClient(WindowMatchPredicate(tabBox->embedded())); Client *c = Workspace::self()->findClient(WindowMatchPredicate(tabBox->embedded()));
@ -304,7 +299,7 @@ void DeclarativeView::slotUpdateGeometry()
setGeometry(m_currentScreenGeometry.x() + static_cast<qreal>(m_currentScreenGeometry.width()) * 0.5 - static_cast<qreal>(width) * 0.5, setGeometry(m_currentScreenGeometry.x() + static_cast<qreal>(m_currentScreenGeometry.width()) * 0.5 - static_cast<qreal>(width) * 0.5,
m_currentScreenGeometry.y() + static_cast<qreal>(m_currentScreenGeometry.height()) * 0.5 - static_cast<qreal>(height) * 0.5, m_currentScreenGeometry.y() + static_cast<qreal>(m_currentScreenGeometry.height()) * 0.5 - static_cast<qreal>(height) * 0.5,
width, height); width, height);
m_relativePos = pos(); m_relativePos = position();
} }
} }
@ -410,11 +405,11 @@ void DeclarativeView::slotEmbeddedChanged(bool enabled)
{ {
if (enabled) { if (enabled) {
// cache the width // cache the width
setResizeMode(QDeclarativeView::SizeRootObjectToView); setResizeMode(QQuickView::SizeRootObjectToView);
m_cachedWidth = rootObject()->property("width").toInt(); m_cachedWidth = rootObject()->property("width").toInt();
m_cachedHeight = rootObject()->property("height").toInt(); m_cachedHeight = rootObject()->property("height").toInt();
} else { } else {
setResizeMode(QDeclarativeView::SizeViewToRootObject); setResizeMode(QQuickView::SizeViewToRootObject);
if (m_cachedWidth != 0 && m_cachedHeight != 0) { if (m_cachedWidth != 0 && m_cachedHeight != 0) {
rootObject()->setProperty("width", m_cachedWidth); rootObject()->setProperty("width", m_cachedWidth);
rootObject()->setProperty("height", m_cachedHeight); rootObject()->setProperty("height", m_cachedHeight);

View File

@ -20,8 +20,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef KWIN_TABBOX_DECLARATIVE_H #ifndef KWIN_TABBOX_DECLARATIVE_H
#define KWIN_TABBOX_DECLARATIVE_H #define KWIN_TABBOX_DECLARATIVE_H
// includes // includes
#include <QtDeclarative/QDeclarativeImageProvider> #include <QQuickImageProvider>
#include <QtDeclarative/QDeclarativeView> #include <QQuickView>
#include <KDE/KService> #include <KDE/KService>
#include "tabboxconfig.h" #include "tabboxconfig.h"
@ -40,7 +40,7 @@ namespace KWin
namespace TabBox namespace TabBox
{ {
class ImageProvider : public QDeclarativeImageProvider class ImageProvider : public QQuickImageProvider
{ {
public: public:
explicit ImageProvider(QAbstractItemModel *model); explicit ImageProvider(QAbstractItemModel *model);
@ -50,11 +50,11 @@ private:
QAbstractItemModel *m_model; QAbstractItemModel *m_model;
}; };
class DeclarativeView : public QDeclarativeView class DeclarativeView : public QQuickView
{ {
Q_OBJECT Q_OBJECT
public: 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 showEvent(QShowEvent *event);
virtual void resizeEvent(QResizeEvent *event); virtual void resizeEvent(QResizeEvent *event);
void setCurrentIndex(const QModelIndex &index, bool disableAnimation = false); void setCurrentIndex(const QModelIndex &index, bool disableAnimation = false);

View File

@ -17,9 +17,9 @@ GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/ *********************************************************************/
import QtQuick 1.0 import QtQuick 2.0
import org.kde.plasma.core 0.1 as PlasmaCore import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.qtextracomponents 0.1 import org.kde.qtextracomponents 2.0
Item { Item {
id: iconsTabBox id: iconsTabBox

View File

@ -18,8 +18,8 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/ *********************************************************************/
import QtQuick 1.0 import QtQuick 2.0
import org.kde.plasma.core 0.1 as PlasmaCore import org.kde.plasma.core 2.0 as PlasmaCore
Item { Item {
property double leftMargin: shadow.margins.left + background.margins.left property double leftMargin: shadow.margins.left + background.margins.left

View File

@ -17,9 +17,9 @@ GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/ *********************************************************************/
import QtQuick 1.0 import QtQuick 2.0
import org.kde.plasma.core 0.1 as PlasmaCore import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.qtextracomponents 0.1 import org.kde.qtextracomponents 2.0
Item { Item {
id: bigIconsTabBox id: bigIconsTabBox

View File

@ -17,9 +17,9 @@ GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/ *********************************************************************/
import QtQuick 1.0 import QtQuick 2.0
import org.kde.plasma.core 0.1 as PlasmaCore import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.qtextracomponents 0.1 import org.kde.qtextracomponents 2.0
Item { Item {
id: compactTabBox id: compactTabBox
@ -142,7 +142,7 @@ Item {
function calculateMaxRowWidth() { function calculateMaxRowWidth() {
var width = 0; var width = 0;
var textElement = Qt.createQmlObject( var textElement = Qt.createQmlObject(
'import QtQuick 1.0;' 'import QtQuick 2.0;'
+ 'Text {\n' + 'Text {\n'
+ ' text: "' + itemCaption(compactTabBox.longestCaption, true) + '"\n' + ' text: "' + itemCaption(compactTabBox.longestCaption, true) + '"\n'
+ ' font.bold: true\n' + ' font.bold: true\n'
@ -159,7 +159,7 @@ Item {
**/ **/
function calcRowHeight() { function calcRowHeight() {
var textElement = Qt.createQmlObject( var textElement = Qt.createQmlObject(
'import QtQuick 1.0;' 'import QtQuick 2.0;'
+ 'Text {\n' + 'Text {\n'
+ ' text: "Some Text"\n' + ' text: "Some Text"\n'
+ ' font.bold: true\n' + ' font.bold: true\n'

View File

@ -17,9 +17,9 @@ GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/ *********************************************************************/
import QtQuick 1.0 import QtQuick 2.0
import org.kde.plasma.core 0.1 as PlasmaCore import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.qtextracomponents 0.1 import org.kde.qtextracomponents 2.0
Item { Item {
id: informativeTabBox id: informativeTabBox
@ -158,7 +158,7 @@ Item {
function calculateMaxRowWidth() { function calculateMaxRowWidth() {
var width = 0; var width = 0;
var textElement = Qt.createQmlObject( var textElement = Qt.createQmlObject(
'import QtQuick 1.0;' 'import QtQuick 2.0;'
+ 'Text {\n' + 'Text {\n'
+ ' text: "' + itemCaption(informativeTabBox.longestCaption, true) + '"\n' + ' text: "' + itemCaption(informativeTabBox.longestCaption, true) + '"\n'
+ ' font.bold: true\n' + ' font.bold: true\n'
@ -175,7 +175,7 @@ Item {
**/ **/
function calcRowHeight() { function calcRowHeight() {
var textElement = Qt.createQmlObject( var textElement = Qt.createQmlObject(
'import QtQuick 1.0;' 'import QtQuick 2.0;'
+ 'Text {\n' + 'Text {\n'
+ ' text: "Some Text"\n' + ' text: "Some Text"\n'
+ ' font.bold: true\n' + ' font.bold: true\n'

View File

@ -17,9 +17,9 @@ GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/ *********************************************************************/
import QtQuick 1.1 import QtQuick 2.0
import org.kde.plasma.core 0.1 as PlasmaCore import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.qtextracomponents 0.1 import org.kde.qtextracomponents 2.0
import org.kde.kwin 0.1 as KWin import org.kde.kwin 0.1 as KWin
Item { Item {

View File

@ -17,9 +17,9 @@ GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/ *********************************************************************/
import QtQuick 1.0 import QtQuick 2.0
import org.kde.plasma.core 0.1 as PlasmaCore import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.qtextracomponents 0.1 import org.kde.qtextracomponents 2.0
Item { Item {
id: smallIconsTabBox id: smallIconsTabBox

View File

@ -17,9 +17,9 @@ GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/ *********************************************************************/
import QtQuick 1.0 import QtQuick 2.0
import org.kde.plasma.core 0.1 as PlasmaCore import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.qtextracomponents 0.1 import org.kde.qtextracomponents 2.0
Item { Item {
id: textTabBox id: textTabBox
@ -109,7 +109,7 @@ Item {
function calculateMaxRowWidth() { function calculateMaxRowWidth() {
var width = 0; var width = 0;
var textElement = Qt.createQmlObject( var textElement = Qt.createQmlObject(
'import QtQuick 1.0;' 'import QtQuick 2.0;'
+ 'Text {\n' + 'Text {\n'
+ ' text: "' + textTabBox.longestCaption + '"\n' + ' text: "' + textTabBox.longestCaption + '"\n'
+ ' visible: false\n' + ' visible: false\n'
@ -125,7 +125,7 @@ Item {
**/ **/
function calcRowHeight() { function calcRowHeight() {
var textElement = Qt.createQmlObject( var textElement = Qt.createQmlObject(
'import QtQuick 1.0;' 'import QtQuick 2.0;'
+ 'Text {\n' + 'Text {\n'
+ ' text: "Some Text"\n' + ' text: "Some Text"\n'
+ ' visible: false\n' + ' visible: false\n'

View File

@ -17,9 +17,9 @@ GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/ *********************************************************************/
import QtQuick 1.0 import QtQuick 2.0
import org.kde.plasma.core 0.1 as PlasmaCore import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.qtextracomponents 0.1 import org.kde.qtextracomponents 2.0
import org.kde.kwin 0.1 as KWin import org.kde.kwin 0.1 as KWin
Item { Item {

View File

@ -18,11 +18,11 @@ GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/ *********************************************************************/
import QtQuick 1.0 import QtQuick 2.0
import org.kde.plasma.core 0.1 as PlasmaCore import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 0.1 as PlasmaComponents import org.kde.plasma.components 2.0 as PlasmaComponents
import org.kde.plasma.mobilecomponents 0.1 as MobileComponents 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 import org.kde.kwin 0.1 as KWin
Item { Item {

View File

@ -17,9 +17,9 @@ GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/ *********************************************************************/
import QtQuick 1.0 import QtQuick 2.0
import org.kde.plasma.core 0.1 as PlasmaCore import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.qtextracomponents 0.1 import org.kde.qtextracomponents 2.0
Item { Item {
id: desktopTabBox id: desktopTabBox
@ -122,7 +122,7 @@ Item {
function calculateMaxRowWidth() { function calculateMaxRowWidth() {
var width = 0; var width = 0;
var textElement = Qt.createQmlObject( var textElement = Qt.createQmlObject(
'import QtQuick 1.0;' 'import QtQuick 2.0;'
+ 'Text {\n' + 'Text {\n'
+ ' text: "' + desktopTabBox.longestCaption + '"\n' + ' text: "' + desktopTabBox.longestCaption + '"\n'
+ ' font.bold: true\n' + ' font.bold: true\n'
@ -139,7 +139,7 @@ Item {
**/ **/
function calcRowHeight() { function calcRowHeight() {
var textElement = Qt.createQmlObject( var textElement = Qt.createQmlObject(
'import QtQuick 1.0;' 'import QtQuick 2.0;'
+ 'Text {\n' + 'Text {\n'
+ ' text: "Some Text"\n' + ' text: "Some Text"\n'
+ ' font.bold: true\n' + ' font.bold: true\n'

View File

@ -17,9 +17,9 @@ GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/ *********************************************************************/
import QtQuick 1.0 import QtQuick 2.0
import org.kde.plasma.core 0.1 as PlasmaCore import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.qtextracomponents 0.1 import org.kde.qtextracomponents 2.0
import org.kde.kwin 0.1 as KWin import org.kde.kwin 0.1 as KWin
Item { Item {

View File

@ -17,7 +17,7 @@ GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/ *********************************************************************/
import QtQuick 1.0 import QtQuick 2.0
Loader { Loader {
id: loader id: loader

View File

@ -118,7 +118,7 @@ void TabBoxHandlerPrivate::updateHighlightWindows()
Display *dpy = QX11Info::display(); Display *dpy = QX11Info::display();
TabBoxClient *currentClient = q->client(index); TabBoxClient *currentClient = q->client(index);
QWidget *w = NULL; QWindow *w = NULL;
if (m_declarativeView && m_declarativeView->isVisible()) { if (m_declarativeView && m_declarativeView->isVisible()) {
w = m_declarativeView; w = m_declarativeView;
} }
@ -230,7 +230,7 @@ void TabBoxHandler::show()
} }
dv = d->m_declarativeDesktopView; dv = d->m_declarativeDesktopView;
} }
if (dv->status() == QDeclarativeView::Ready && dv->rootObject()) { if (dv->status() == QQuickView::Ready && dv->rootObject()) {
dv->show(); dv->show();
dv->setCurrentIndex(d->index, d->config.tabBoxMode() == TabBoxConfig::ClientTabBox); dv->setCurrentIndex(d->index, d->config.tabBoxMode() == TabBoxConfig::ClientTabBox);
} else { } else {
@ -386,7 +386,7 @@ void TabBoxHandler::grabbedKeyEvent(QKeyEvent* event) const
bool TabBoxHandler::containsPos(const QPoint& pos) const bool TabBoxHandler::containsPos(const QPoint& pos) const
{ {
QWidget *w = NULL; QWindow *w = NULL;
if (d->m_declarativeView && d->m_declarativeView->isVisible()) { if (d->m_declarativeView && d->m_declarativeView->isVisible()) {
w = d->m_declarativeView; w = d->m_declarativeView;
} else if (d->m_declarativeDesktopView && d->m_declarativeDesktopView->isVisible()) { } else if (d->m_declarativeDesktopView && d->m_declarativeDesktopView->isVisible()) {

View File

@ -24,7 +24,7 @@ namespace KWin
namespace TabBox namespace TabBox
{ {
DeclarativeView::DeclarativeView(QAbstractItemModel *model, TabBoxConfig::TabBoxMode mode, QWidget *parent) DeclarativeView::DeclarativeView(QAbstractItemModel *model, TabBoxConfig::TabBoxMode mode, QWidget *parent)
: QDeclarativeView(parent) : QQuickView(parent)
{ {
Q_UNUSED(model) Q_UNUSED(model)
Q_UNUSED(mode) Q_UNUSED(mode)