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 @@ ...@@ -35,26 +35,19 @@
#include "kactivities-kcm-features.h" #include "kactivities-kcm-features.h"
#include "utils.h"
class ActivitiesTab::Private { class ActivitiesTab::Private {
public: public:
std::unique_ptr<QQuickView> viewActivities;
ExtraActivitiesInterface *extraActivitiesInterface; ExtraActivitiesInterface *extraActivitiesInterface;
}; };
ActivitiesTab::ActivitiesTab(QWidget *parent) ActivitiesTab::ActivitiesTab(QWidget *parent)
: QWidget(parent) : QQuickWidget(parent)
, d() , d()
{ {
new QVBoxLayout(this); setClearColor(QGuiApplication::palette().window().color());
setResizeMode(QQuickWidget::SizeRootObjectToView);
d->extraActivitiesInterface = new ExtraActivitiesInterface(this); rootContext()->setContextProperty(QStringLiteral("kactivitiesExtras"), d->extraActivitiesInterface);
setSource(QUrl::fromLocalFile(KAMD_KCM_DATADIR + QStringLiteral("/qml/activitiesTab/main.qml")));
d->viewActivities = createView(this);
d->viewActivities->rootContext()->setContextProperty(
QStringLiteral("kactivitiesExtras"), d->extraActivitiesInterface);
setViewSource(d->viewActivities, QStringLiteral("/qml/activitiesTab/main.qml"));
} }
ActivitiesTab::~ActivitiesTab() ActivitiesTab::~ActivitiesTab()
......
...@@ -21,14 +21,14 @@ ...@@ -21,14 +21,14 @@
#ifndef ACTIVITIES_TAB_H #ifndef ACTIVITIES_TAB_H
#define ACTIVITIES_TAB_H #define ACTIVITIES_TAB_H
#include <QWidget> #include <QQuickWidget>
#include <utils/d_ptr.h> #include <utils/d_ptr.h>
/** /**
* ActivitiesTab * ActivitiesTab
*/ */
class ActivitiesTab : public QWidget { class ActivitiesTab : public QQuickWidget {
Q_OBJECT Q_OBJECT
public: public:
explicit ActivitiesTab(QWidget *parent); explicit ActivitiesTab(QWidget *parent);
......
...@@ -56,6 +56,7 @@ add_library (kcm_activities MODULE ${KAMD_KCM_SRCS}) ...@@ -56,6 +56,7 @@ add_library (kcm_activities MODULE ${KAMD_KCM_SRCS})
target_link_libraries (kcm_activities target_link_libraries (kcm_activities
Qt5::Quick Qt5::Quick
Qt5::QuickWidgets
Qt5::Core Qt5::Core
Qt5::Sql Qt5::Sql
Qt5::Qml Qt5::Qml
......
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
#include <QQmlComponent> #include <QQmlComponent>
#include <QDBusPendingCall> #include <QDBusPendingCall>
#include <QQuickView> #include <QQuickWidget>
#include <KConfigGroup> #include <KConfigGroup>
#include <KSharedConfig> #include <KSharedConfig>
...@@ -43,22 +43,16 @@ ...@@ -43,22 +43,16 @@
#include "common/dbus/common.h" #include "common/dbus/common.h"
#include "utils.h"
class PrivacyTab::Private : public Ui::PrivacyTabBase { class PrivacyTab::Private : public Ui::PrivacyTabBase {
public: public:
KActivityManagerdSettings *mainConfig; KActivityManagerdSettings *mainConfig;
KActivityManagerdPluginsSettings *pluginConfig; KActivityManagerdPluginsSettings *pluginConfig;
BlacklistedApplicationsModel *blacklistedApplicationsModel; BlacklistedApplicationsModel *blacklistedApplicationsModel;
QObject *viewBlacklistedApplicationsRoot;
std::unique_ptr<QQuickView> viewBlacklistedApplications;
Private(QObject *parent) Private(QObject *parent)
: mainConfig(new KActivityManagerdSettings(parent)) : mainConfig(new KActivityManagerdSettings(parent))
, pluginConfig(new KActivityManagerdPluginsSettings(parent)) , pluginConfig(new KActivityManagerdPluginsSettings(parent))
, viewBlacklistedApplicationsRoot(nullptr)
, viewBlacklistedApplications(nullptr)
{ {
} }
}; };
...@@ -104,14 +98,10 @@ PrivacyTab::PrivacyTab(QWidget *parent) ...@@ -104,14 +98,10 @@ PrivacyTab::PrivacyTab(QWidget *parent)
connect(d->blacklistedApplicationsModel, &BlacklistedApplicationsModel::changed, this, &PrivacyTab::blackListModelChanged); connect(d->blacklistedApplicationsModel, &BlacklistedApplicationsModel::changed, this, &PrivacyTab::blackListModelChanged);
connect(d->blacklistedApplicationsModel, &BlacklistedApplicationsModel::defaulted, this, &PrivacyTab::blackListModelDefaulted); connect(d->blacklistedApplicationsModel, &BlacklistedApplicationsModel::defaulted, this, &PrivacyTab::blackListModelDefaulted);
new QGridLayout(d->viewBlacklistedApplicationsContainer); d->viewBlacklistedApplications->setClearColor(QGuiApplication::palette().window().color());
d->viewBlacklistedApplications
= createView(d->viewBlacklistedApplicationsContainer);
d->viewBlacklistedApplications->rootContext()->setContextProperty( d->viewBlacklistedApplications->rootContext()->setContextProperty(
QStringLiteral("applicationModel"), d->blacklistedApplicationsModel); QStringLiteral("applicationModel"), d->blacklistedApplicationsModel);
setViewSource(d->viewBlacklistedApplications, d->viewBlacklistedApplications->setSource(QUrl::fromLocalFile(KAMD_KCM_DATADIR + QStringLiteral("/qml/privacyTab/BlacklistApplicationView.qml")));
QStringLiteral("/qml/privacyTab/BlacklistApplicationView.qml"));
// React to changes // React to changes
......
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include <QTabWidget> #include <QTabWidget>
#include <QTimer> #include <QTimer>
#include <QVBoxLayout> #include <QVBoxLayout>
#include <QGuiApplication>
#include <KLocalizedString> #include <KLocalizedString>
#include <KGlobalAccel> #include <KGlobalAccel>
...@@ -47,7 +48,6 @@ ...@@ -47,7 +48,6 @@
#include "common/dbus/common.h" #include "common/dbus/common.h"
#include "utils/continue_with.h" #include "utils/continue_with.h"
#include "utils/d_ptr_implementation.h" #include "utils/d_ptr_implementation.h"
#include "../utils.h"
class Dialog::Private { class Dialog::Private {
public: public:
...@@ -82,11 +82,14 @@ public: ...@@ -82,11 +82,14 @@ public:
view->rootContext()->setContextProperty(QStringLiteral("dialog"), q); 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); tabs->addTab(view, title);
} else { } else {
message->setText(i18n("Error loading the QML files. Check your installation.\nMissing %1", 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); message->setVisible(true);
} }
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>500</width> <width>629</width>
<height>500</height> <height>500</height>
</rect> </rect>
</property> </property>
...@@ -63,33 +63,33 @@ ...@@ -63,33 +63,33 @@
<property name="flat"> <property name="flat">
<bool>true</bool> <bool>true</bool>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_2"> <layout class="QVBoxLayout" name="verticalLayout_2">
<item> <item>
<widget class="QRadioButton" name="radioRememberAllApplications"> <widget class="QRadioButton" name="radioRememberAllApplications">
<property name="text"> <property name="text">
<string>For a&amp;ll applications</string> <string>For a&amp;ll applications</string>
</property> </property>
<property name="checked"> <property name="checked">
<bool>true</bool> <bool>true</bool>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QRadioButton" name="radioDontRememberApplications"> <widget class="QRadioButton" name="radioDontRememberApplications">
<property name="text"> <property name="text">
<string>&amp;Do not remember</string> <string>&amp;Do not remember</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QRadioButton" name="radioRememberSpecificApplications"> <widget class="QRadioButton" name="radioRememberSpecificApplications">
<property name="text"> <property name="text">
<string>O&amp;nly for specific applications:</string> <string>O&amp;nly for specific applications:</string>
</property> </property>
</widget> </widget>
</item> </item>
</layout> </layout>
</widget> </widget>
</item> </item>
<item row="1" column="0"> <item row="1" column="0">
<widget class="QLabel" name="labelRememberDocuments"> <widget class="QLabel" name="labelRememberDocuments">
...@@ -101,13 +101,22 @@ ...@@ -101,13 +101,22 @@
</layout> </layout>
</item> </item>
<item> <item>
<widget class="QWidget" name="viewBlacklistedApplicationsContainer" native="true"> <widget class="QQuickWidget" name="viewBlacklistedApplications">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Expanding"> <sizepolicy hsizetype="Preferred" vsizetype="MinimumExpanding">
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<property name="minimumSize">
<size>
<width>0</width>
<height>200</height>
</size>
</property>
<property name="resizeMode">
<enum>QQuickWidget::SizeRootObjectToView</enum>
</property>
</widget> </widget>
</item> </item>
<item> <item>
...@@ -132,25 +141,14 @@ ...@@ -132,25 +141,14 @@
<extends>QFrame</extends> <extends>QFrame</extends>
<header>kmessagewidget.h</header> <header>kmessagewidget.h</header>
</customwidget> </customwidget>
<customwidget>
<class>QQuickWidget</class>
<extends>QWidget</extends>
<header location="global">QtQuickWidgets/QQuickWidget</header>
</customwidget>
</customwidgets> </customwidgets>
<resources/> <resources/>
<connections> <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> <connection>
<sender>radioRememberSpecificApplications</sender> <sender>radioRememberSpecificApplications</sender>
<signal>toggled(bool)</signal> <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