mirror of
https://github.com/KDE/latte-dock.git
synced 2025-03-09 00:58:15 +03:00
improve vastly user interaction with indicators uis
This commit is contained in:
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.plasmatabstyle")) {
|
||||
|
||||
//! find correct alphabetical position
|
||||
int newPos = -1;
|
||||
|
||||
if (!m_customPluginIds.contains(metadata.pluginId())) {
|
||||
m_customPluginIds << 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 (newPos == -1) {
|
||||
m_customPluginIds << metadata.pluginId();
|
||||
} else {
|
||||
m_customPluginIds.insert(newPos, metadata.pluginId());
|
||||
}
|
||||
}
|
||||
|
||||
if (!m_customPluginNames.contains(metadata.name())) {
|
||||
m_customPluginNames << metadata.name();
|
||||
if (newPos == -1) {
|
||||
m_customPluginNames << metadata.name();
|
||||
} else {
|
||||
m_customPluginNames.insert(newPos, metadata.name());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -151,6 +151,21 @@ void Indicator::setPluginIsReady(bool ready)
|
||||
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
|
||||
{
|
||||
return m_type;
|
||||
|
@ -101,6 +101,8 @@ public:
|
||||
|
||||
bool pluginIsReady();
|
||||
|
||||
int index(const QString &type);
|
||||
|
||||
QString type() const;
|
||||
void setType(QString type);
|
||||
|
||||
|
@ -22,6 +22,7 @@
|
||||
// local
|
||||
#include "primaryconfigview.h"
|
||||
#include "../view.h"
|
||||
#include "../indicator/indicator.h"
|
||||
#include "../../lattecorona.h"
|
||||
#include "../../indicator/factory.h"
|
||||
|
||||
@ -70,7 +71,6 @@ int IndicatorUiManager::index(const QString &type)
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
void IndicatorUiManager::setParentItem(QQuickItem *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)
|
||||
{
|
||||
if (!m_parentItem) {
|
||||
return;
|
||||
}
|
||||
|
||||
hideAllUi();
|
||||
// hideAllUi();
|
||||
|
||||
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
|
||||
QQuickItem *qmlItem = qobject_cast<QQuickItem*>(m_uidata[typeIndex].ui->rootObject());
|
||||
if (qmlItem) {
|
||||
qmlItem->setVisible(true);
|
||||
qmlItem->setParentItem(m_parentItem);
|
||||
showNextIndicator();
|
||||
//qmlItem->setVisible(true);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@ -133,12 +154,29 @@ void IndicatorUiManager::ui(const QString &type, Latte::View *view)
|
||||
uidata.ui->rootContext()->setContextProperty(QStringLiteral("indicator"), view->indicator());
|
||||
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());
|
||||
if (qmlItem) {
|
||||
qmlItem->setParentItem(m_parentItem);
|
||||
showNextIndicator();
|
||||
}
|
||||
|
||||
m_uidata << uidata;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -49,6 +49,7 @@ struct IndicatorUiData
|
||||
{
|
||||
QString type;
|
||||
QString pluginPath;
|
||||
QString name;
|
||||
QPointer<Latte::View> view;
|
||||
QPointer<KDeclarative::QmlObjectSharedEngine> ui;
|
||||
};
|
||||
@ -68,11 +69,12 @@ public slots:
|
||||
Q_INVOKABLE void setParentItem(QQuickItem *parentItem);
|
||||
Q_INVOKABLE void ui(const QString &type, Latte::View *view);
|
||||
|
||||
Q_INVOKABLE int index(const QString &type);
|
||||
private:
|
||||
bool contains(const QString &type);
|
||||
int index(const QString &type);
|
||||
|
||||
void hideAllUi();
|
||||
void showNextIndicator();
|
||||
|
||||
private:
|
||||
QQuickItem *m_parentItem{nullptr};
|
||||
|
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user