Commit 8d33d2d7 authored by David Edmundson's avatar David Edmundson
Browse files

[kcms/activities] Port to QQuickWidget from nested QQuickWindows

Nested QQuickWindows are still somewhat problematic especially when used
in systemsettings which is already a very hybrid mix.

At some point this will all be fully ported to QtQuick anyway, there
isn't anything especially complex going on in the UI that isn't QtQuick
already. This is a small backportable patch to supress the bugs.

BUG: 394899
BUG: 423682
BUG: 416253
Fixed-in: 5.20.0
parent 64d0b10a
......@@ -35,26 +35,19 @@
#include "kactivities-kcm-features.h"
#include "utils.h"
class ActivitiesTab::Private {
public:
std::unique_ptr<QQuickView> viewActivities;
ExtraActivitiesInterface *extraActivitiesInterface;
};
ActivitiesTab::ActivitiesTab(QWidget *parent)
: QWidget(parent)
: QQuickWidget(parent)
, d()
{
new QVBoxLayout(this);
d->extraActivitiesInterface = new ExtraActivitiesInterface(this);
d->viewActivities = createView(this);
d->viewActivities->rootContext()->setContextProperty(
QStringLiteral("kactivitiesExtras"), d->extraActivitiesInterface);
setViewSource(d->viewActivities, QStringLiteral("/qml/activitiesTab/main.qml"));
setClearColor(QGuiApplication::palette().window().color());
setResizeMode(QQuickWidget::SizeRootObjectToView);
rootContext()->setContextProperty(QStringLiteral("kactivitiesExtras"), d->extraActivitiesInterface);
setSource(QUrl::fromLocalFile(KAMD_KCM_DATADIR + QStringLiteral("/qml/activitiesTab/main.qml")));
}
ActivitiesTab::~ActivitiesTab()
......
......@@ -21,14 +21,14 @@
#ifndef ACTIVITIES_TAB_H
#define ACTIVITIES_TAB_H
#include <QWidget>
#include <QQuickWidget>
#include <utils/d_ptr.h>
/**
* ActivitiesTab
*/
class ActivitiesTab : public QWidget {
class ActivitiesTab : public QQuickWidget {
Q_OBJECT
public:
explicit ActivitiesTab(QWidget *parent);
......
......@@ -56,6 +56,7 @@ add_library (kcm_activities MODULE ${KAMD_KCM_SRCS})
target_link_libraries (kcm_activities
Qt5::Quick
Qt5::QuickWidgets
Qt5::Core
Qt5::Sql
Qt5::Qml
......
......@@ -28,7 +28,7 @@
#include <QQmlComponent>
#include <QDBusPendingCall>
#include <QQuickView>
#include <QQuickWidget>
#include <KConfigGroup>
#include <KSharedConfig>
......@@ -43,22 +43,16 @@
#include "common/dbus/common.h"
#include "utils.h"
class PrivacyTab::Private : public Ui::PrivacyTabBase {
public:
KActivityManagerdSettings *mainConfig;
KActivityManagerdPluginsSettings *pluginConfig;
BlacklistedApplicationsModel *blacklistedApplicationsModel;
QObject *viewBlacklistedApplicationsRoot;
std::unique_ptr<QQuickView> viewBlacklistedApplications;
Private(QObject *parent)
: mainConfig(new KActivityManagerdSettings(parent))
, pluginConfig(new KActivityManagerdPluginsSettings(parent))
, viewBlacklistedApplicationsRoot(nullptr)
, viewBlacklistedApplications(nullptr)
{
}
};
......@@ -104,14 +98,10 @@ PrivacyTab::PrivacyTab(QWidget *parent)
connect(d->blacklistedApplicationsModel, &BlacklistedApplicationsModel::changed, this, &PrivacyTab::blackListModelChanged);
connect(d->blacklistedApplicationsModel, &BlacklistedApplicationsModel::defaulted, this, &PrivacyTab::blackListModelDefaulted);
new QGridLayout(d->viewBlacklistedApplicationsContainer);
d->viewBlacklistedApplications
= createView(d->viewBlacklistedApplicationsContainer);
d->viewBlacklistedApplications->setClearColor(QGuiApplication::palette().window().color());
d->viewBlacklistedApplications->rootContext()->setContextProperty(
QStringLiteral("applicationModel"), d->blacklistedApplicationsModel);
setViewSource(d->viewBlacklistedApplications,
QStringLiteral("/qml/privacyTab/BlacklistApplicationView.qml"));
d->viewBlacklistedApplications->setSource(QUrl::fromLocalFile(KAMD_KCM_DATADIR + QStringLiteral("/qml/privacyTab/BlacklistApplicationView.qml")));
// React to changes
......
......@@ -33,6 +33,7 @@
#include <QTabWidget>
#include <QTimer>
#include <QVBoxLayout>
#include <QGuiApplication>
#include <KLocalizedString>
#include <KGlobalAccel>
......@@ -47,7 +48,6 @@
#include "common/dbus/common.h"
#include "utils/continue_with.h"
#include "utils/d_ptr_implementation.h"
#include "../utils.h"
class Dialog::Private {
public:
......@@ -82,11 +82,14 @@ public:
view->rootContext()->setContextProperty(QStringLiteral("dialog"), q);
if (setViewSource(view, QStringLiteral("/qml/activityDialog/") + file)) {
const QString sourceFile = QStringLiteral(KAMD_KCM_DATADIR) +"qml/activityDialog/" + file;
if (QFile::exists(sourceFile)) {
view->setSource(QUrl::fromLocalFile(sourceFile));
tabs->addTab(view, title);
} else {
message->setText(i18n("Error loading the QML files. Check your installation.\nMissing %1",
QStringLiteral(KAMD_KCM_DATADIR) + QStringLiteral("/qml/activityDialog/") + file));
sourceFile));
message->setVisible(true);
}
......
......@@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>500</width>
<width>629</width>
<height>500</height>
</rect>
</property>
......@@ -101,13 +101,22 @@
</layout>
</item>
<item>
<widget class="QWidget" name="viewBlacklistedApplicationsContainer" native="true">
<widget class="QQuickWidget" name="viewBlacklistedApplications">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
<sizepolicy hsizetype="Preferred" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>200</height>
</size>
</property>
<property name="resizeMode">
<enum>QQuickWidget::SizeRootObjectToView</enum>
</property>
</widget>
</item>
<item>
......@@ -132,25 +141,14 @@
<extends>QFrame</extends>
<header>kmessagewidget.h</header>
</customwidget>
<customwidget>
<class>QQuickWidget</class>
<extends>QWidget</extends>
<header location="global">QtQuickWidgets/QQuickWidget</header>
</customwidget>
</customwidgets>
<resources/>
<connections>
<connection>
<sender>radioRememberSpecificApplications</sender>
<signal>toggled(bool)</signal>
<receiver>viewBlacklistedApplicationsContainer</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>352</x>
<y>167</y>
</hint>
<hint type="destinationlabel">
<x>249</x>
<y>363</y>
</hint>
</hints>
</connection>
<connection>
<sender>radioRememberSpecificApplications</sender>
<signal>toggled(bool)</signal>
......
/*
* Copyright (C) 2015 - 2016 by Ivan Cukic <ivan.cukic@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) version 3 or any later version
* accepted by the membership of KDE e.V. (or its successor approved
* by the membership of KDE e.V.), which shall act as a proxy
* defined in Section 14 of version 3 of the license.
*
* 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/>.
*/
#ifndef UTILS_H
#define UTILS_H
#include <QGuiApplication>
inline std::unique_ptr<QQuickView> createView(QWidget *parent)
{
auto view = new QQuickView();
view->setColor(QGuiApplication::palette().window().color());
view->setResizeMode(QQuickView::SizeRootObjectToView);
auto container = QWidget::createWindowContainer(view, parent);
container->setFocusPolicy(Qt::TabFocus);
parent->layout()->addWidget(container);
return std::unique_ptr<QQuickView>(view);
}
template <typename View>
inline bool setViewSource(View &view, const QString &file)
{
QString sourceFile = QStringLiteral(KAMD_KCM_DATADIR) + file;
if (QFile::exists(sourceFile)) {
view->setSource(QUrl::fromLocalFile(sourceFile));
return true;
} else {
return false;
}
}
#endif // UTILS_H
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment