improve vastly user interaction with indicators uis

work/spdx
Michail Vourlakos 4 years ago
parent 810fd7e3cd
commit c777fca05a

@ -147,12 +147,32 @@ void Factory::reload(const QString &indicatorPath)
&& (metadata.pluginId() != "org.kde.latte.plasma") && (metadata.pluginId() != "org.kde.latte.plasma")
&& (metadata.pluginId() != "org.kde.latte.plasmatabstyle")) { && (metadata.pluginId() != "org.kde.latte.plasmatabstyle")) {
//! find correct alphabetical position
int newPos = -1;
if (!m_customPluginIds.contains(metadata.pluginId())) {
for (int i=0; i<m_customPluginNames.count(); ++i) {
if (QString::compare(metadata.name(), m_customPluginNames[i], Qt::CaseInsensitive)<=0) {
newPos = i;
break;
}
}
}
if (!m_customPluginIds.contains(metadata.pluginId())) { if (!m_customPluginIds.contains(metadata.pluginId())) {
if (newPos == -1) {
m_customPluginIds << metadata.pluginId(); m_customPluginIds << metadata.pluginId();
} else {
m_customPluginIds.insert(newPos, metadata.pluginId());
}
} }
if (!m_customPluginNames.contains(metadata.name())) { if (!m_customPluginNames.contains(metadata.name())) {
if (newPos == -1) {
m_customPluginNames << metadata.name(); m_customPluginNames << metadata.name();
} else {
m_customPluginNames.insert(newPos, metadata.name());
}
} }
} }

@ -151,6 +151,21 @@ void Indicator::setPluginIsReady(bool ready)
emit pluginIsReadyChanged(); emit pluginIsReadyChanged();
} }
int Indicator::index(const QString &type)
{
if (type == "org.kde.latte.default") {
return 0;
} else if (type == "org.kde.latte.plasma") {
return 1;
} else if (type == "org.kde.latte.plasmatabstyle") {
return 2;
} else if (customPluginIds().contains(type)){
return 3 + customPluginIds().indexOf(type);
}
return -1;
}
QString Indicator::type() const QString Indicator::type() const
{ {
return m_type; return m_type;

@ -101,6 +101,8 @@ public:
bool pluginIsReady(); bool pluginIsReady();
int index(const QString &type);
QString type() const; QString type() const;
void setType(QString type); void setType(QString type);

@ -22,6 +22,7 @@
// local // local
#include "primaryconfigview.h" #include "primaryconfigview.h"
#include "../view.h" #include "../view.h"
#include "../indicator/indicator.h"
#include "../../lattecorona.h" #include "../../lattecorona.h"
#include "../../indicator/factory.h" #include "../../indicator/factory.h"
@ -70,7 +71,6 @@ int IndicatorUiManager::index(const QString &type)
return -1; return -1;
} }
void IndicatorUiManager::setParentItem(QQuickItem *parentItem) void IndicatorUiManager::setParentItem(QQuickItem *parentItem)
{ {
m_parentItem = parentItem; m_parentItem = parentItem;
@ -89,13 +89,32 @@ void IndicatorUiManager::hideAllUi()
} }
} }
void IndicatorUiManager::showNextIndicator()
{
if (!m_parentItem) {
return;
}
if (auto *metaObject = m_parentItem->metaObject()) {
int methodIndex = metaObject->indexOfMethod("showNextIndicator()");
if (methodIndex == -1) {
qDebug() << "indicator parent page function showNextIndicator() was not found...";
return;
}
QMetaMethod method = metaObject->method(methodIndex);
method.invoke(m_parentItem);
}
}
void IndicatorUiManager::ui(const QString &type, Latte::View *view) void IndicatorUiManager::ui(const QString &type, Latte::View *view)
{ {
if (!m_parentItem) { if (!m_parentItem) {
return; return;
} }
hideAllUi(); // hideAllUi();
int typeIndex = index(type); int typeIndex = index(type);
@ -106,7 +125,9 @@ void IndicatorUiManager::ui(const QString &type, Latte::View *view)
//! config ui has already been created and can be provided again //! config ui has already been created and can be provided again
QQuickItem *qmlItem = qobject_cast<QQuickItem*>(m_uidata[typeIndex].ui->rootObject()); QQuickItem *qmlItem = qobject_cast<QQuickItem*>(m_uidata[typeIndex].ui->rootObject());
if (qmlItem) { if (qmlItem) {
qmlItem->setVisible(true); qmlItem->setParentItem(m_parentItem);
showNextIndicator();
//qmlItem->setVisible(true);
} }
return; return;
} }
@ -133,12 +154,29 @@ void IndicatorUiManager::ui(const QString &type, Latte::View *view)
uidata.ui->rootContext()->setContextProperty(QStringLiteral("indicator"), view->indicator()); uidata.ui->rootContext()->setContextProperty(QStringLiteral("indicator"), view->indicator());
uidata.ui->completeInitialization(); uidata.ui->completeInitialization();
int newTypeIndex = view->indicator()->index(type);
int newPos = -1;
for (int i=0; i<m_uidata.count(); ++i) {
int oldTypeIndex = view->indicator()->index(m_uidata[i].type);
if (oldTypeIndex > newTypeIndex) {
newPos = i;
break;
}
}
if (newPos == -1) {
m_uidata << uidata;
} else {
m_uidata.insert(newPos, uidata);
}
QQuickItem *qmlItem = qobject_cast<QQuickItem*>(uidata.ui->rootObject()); QQuickItem *qmlItem = qobject_cast<QQuickItem*>(uidata.ui->rootObject());
if (qmlItem) { if (qmlItem) {
qmlItem->setParentItem(m_parentItem); qmlItem->setParentItem(m_parentItem);
showNextIndicator();
} }
m_uidata << uidata;
} }
} }
} }

@ -49,6 +49,7 @@ struct IndicatorUiData
{ {
QString type; QString type;
QString pluginPath; QString pluginPath;
QString name;
QPointer<Latte::View> view; QPointer<Latte::View> view;
QPointer<KDeclarative::QmlObjectSharedEngine> ui; QPointer<KDeclarative::QmlObjectSharedEngine> ui;
}; };
@ -68,11 +69,12 @@ public slots:
Q_INVOKABLE void setParentItem(QQuickItem *parentItem); Q_INVOKABLE void setParentItem(QQuickItem *parentItem);
Q_INVOKABLE void ui(const QString &type, Latte::View *view); Q_INVOKABLE void ui(const QString &type, Latte::View *view);
Q_INVOKABLE int index(const QString &type);
private: private:
bool contains(const QString &type); bool contains(const QString &type);
int index(const QString &type);
void hideAllUi(); void hideAllUi();
void showNextIndicator();
private: private:
QQuickItem *m_parentItem{nullptr}; QQuickItem *m_parentItem{nullptr};

@ -22,10 +22,12 @@ import QtQuick.Controls 1.4
import QtQuick.Layouts 1.3 import QtQuick.Layouts 1.3
import QtGraphicalEffects 1.0 import QtGraphicalEffects 1.0
import QtQuick.Dialogs 1.2 import QtQuick.Dialogs 1.2
import QtQuick.Controls 2.12 as QtQuickControls212
import org.kde.plasma.core 2.0 as PlasmaCore import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 2.0 as PlasmaComponents import org.kde.plasma.components 2.0 as PlasmaComponents
import org.kde.plasma.components 3.0 as PlasmaComponents3 import org.kde.plasma.components 3.0 as PlasmaComponents3
import org.kde.plasma.extras 2.0 as PlasmaExtras
import org.kde.latte.core 0.2 as LatteCore import org.kde.latte.core 0.2 as LatteCore
import org.kde.latte.components 1.0 as LatteComponents import org.kde.latte.components 1.0 as LatteComponents
@ -35,16 +37,19 @@ import "../../controls" as LatteExtraControls
PlasmaComponents.Page { PlasmaComponents.Page {
Layout.maximumWidth: content.width + content.Layout.leftMargin * 2 Layout.maximumWidth: content.width + content.Layout.leftMargin * 2
Layout.maximumHeight: content.height + units.smallSpacing * 2 Layout.maximumHeight: content.height + units.smallSpacing
ColumnLayout { ColumnLayout {
id: content id: content
width: (dialog.appliedWidth - units.smallSpacing * 2) - Layout.leftMargin * 2 width: (dialog.appliedWidth - units.smallSpacing * 2) - Layout.leftMargin * 2
spacing: dialog.subGroupSpacing
anchors.horizontalCenter: parent.horizontalCenter anchors.horizontalCenter: parent.horizontalCenter
Layout.leftMargin: units.smallSpacing * 2 Layout.leftMargin: units.smallSpacing * 2
ColumnLayout {
id: contentStatic
Layout.fillWidth: true
spacing: dialog.subGroupSpacing
//! BEGIN: Shadows //! BEGIN: Shadows
ColumnLayout { ColumnLayout {
Layout.fillWidth: true Layout.fillWidth: true
@ -496,7 +501,7 @@ PlasmaComponents.Page {
} }
//! BEGIN: Indicator specific sub-options //! BEGIN: Indicator specific sub-options
ColumnLayout { /* ColumnLayout {
id: indicatorSpecificOptions id: indicatorSpecificOptions
Layout.fillWidth: true Layout.fillWidth: true
Layout.topMargin: units.smallSpacing * 2 Layout.topMargin: units.smallSpacing * 2
@ -526,10 +531,185 @@ PlasmaComponents.Page {
} }
} }
} }
} }*/
//! END: Indicator specific sub-options //! END: Indicator specific sub-options
} }
} }
//! END: Active Indicator General Settings //! END: Active Indicator General Settings
} //Static properties column
ColumnLayout {
id: contentDynamic
Layout.fillWidth: true
height: pagesBackground.height - contentStatic.height - 3*units.smallSpacing
spacing: dialog.subGroupSpacing
Rectangle {
id: indicatorsBackground
Layout.fillWidth: true
Layout.minimumHeight: parent.height
Layout.leftMargin: units.smallSpacing * 2
Layout.rightMargin: units.smallSpacing * 2
color: "transparent"
PlasmaExtras.ScrollArea {
id: scrollArea
anchors.fill: parent
verticalScrollBarPolicy: Qt.ScrollBarAsNeeded
horizontalScrollBarPolicy: Qt.ScrollBarAlwaysOff
flickableItem.flickableDirection: Flickable.VerticalFlick
QtQuickControls212.StackView {
id: indicatorsStackView
width: Math.max(currentItem.Layout.maximumWidth, currentItem.width)
height: Math.max(currentItem.Layout.maximumHeight, currentItem.height)
enabled: latteView.indicator.enabled
property bool forwardSliding: true
readonly property int optionsWidth: dialog.optionsWidth
readonly property bool deprecatedOptionsAreHidden: true // @since 0.10.0
replaceEnter: Transition {
ParallelAnimation {
PropertyAnimation {
property: "x"
from: indicatorsStackView.forwardSliding ? -indicatorsBackground.width : indicatorsBackground.width
to: 0
duration: 350
}
PropertyAnimation {
property: "opacity"
from: 0
to: 1
duration: 350
}
}
}
replaceExit: Transition {
ParallelAnimation {
PropertyAnimation {
property: "x"
from: 0
to: indicatorsStackView.forwardSliding ? indicatorsBackground.width : -indicatorsBackground.width
duration: 350
}
PropertyAnimation {
property: "opacity"
from: 1
to: 0
duration: 350
}
}
}
}
}
Item {
id: hiddenIndicatorPage
anchors.fill: parent
visible: false
readonly property int optionsWidth: dialog.optionsWidth
readonly property bool deprecatedOptionsAreHidden: true // @since 0.10.0
readonly property Item nextPage: indicatorsStackView.currentItem === page1 ? page2 : page1
readonly property Item previousPage: nextPage === page1 ? page2 : page1
function showNextIndicator() {
console.log("show next indicator in qml called, children:: " + children.length);
if (children.length===1) {
var nextIndicator = children[0];
if (nextIndicator && (!indicatorsStackView.currentItem || !indicatorsStackView.currentItem.isCurrent)) {
//!empty nextPage by moving its pages into hiddenPages
var childrenCount = nextPage.children.length;
for (var i=0; i<childrenCount; ++i) {
var previousIndicator = nextPage.children[0];
previousIndicator.visible = false;
previousIndicator.parent = hiddenPages;
} }
nextIndicator.parent = nextPage;
nextIndicator.visible = true;
nextPage.type = latteView.indicator.type;
var currentIndex = -1;
if (indicatorsStackView.currentItem) {
currentIndex = viewConfig.indicatorUiManager.index(indicatorsStackView.currentItem.type);
}
var nextIndex = viewConfig.indicatorUiManager.index(latteView.indicator.type);
indicatorsStackView.forwardSliding = (nextIndex<currentIndex);
indicatorsStackView.replace(indicatorsStackView.currentItem, nextPage);
}
}
}
Component.onCompleted: {
viewConfig.indicatorUiManager.setParentItem(hiddenIndicatorPage);
viewConfig.indicatorUiManager.ui(latteView.indicator.type, latteView);
}
Connections {
target: latteView.indicator
onPluginChanged: viewConfig.indicatorUiManager.ui(latteView.indicator.type, latteView);
}
Connections {
target: viewConfig
onIsReadyChanged: {
if (viewConfig.isReady) {
viewConfig.indicatorUiManager.ui(latteView.indicator.type, latteView);
}
}
}
}
Item {
id: hidden
visible: false
ColumnLayout {
id: page1
width: indicatorsBackground.width
height: childrenRect.height
readonly property bool isCurrent: latteView.indicator.type === type
readonly property bool deprecatedOptionsAreHidden: true // @since 0.10.0
readonly property int optionsWidth: dialog.optionsWidth
property string type: ""
}
ColumnLayout {
id: page2
width: indicatorsBackground.width
height: childrenRect.height
readonly property bool isCurrent: latteView.indicator.type === type
readonly property bool deprecatedOptionsAreHidden: true // @since 0.10.0
readonly property int optionsWidth: dialog.optionsWidth
property string type: ""
}
ColumnLayout {
id: hiddenPages
width: indicatorsBackground.width
height: childrenRect.height
readonly property bool isCurrent: latteView.indicator.type === type
readonly property bool deprecatedOptionsAreHidden: true // @since 0.10.0
readonly property int optionsWidth: dialog.optionsWidth
property string type: ""
}
}
}
}//! END of Dynamic content
} //! END of ALL content
} }

Loading…
Cancel
Save