Preview task-group selections until Meta is released
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "windowpreview.h"
|
||||
#include "previewplacement.h"
|
||||
|
||||
#include <QGuiApplication>
|
||||
#include <QQmlComponent>
|
||||
#include <QScreen>
|
||||
#include <abstracttasksmodel.h>
|
||||
|
||||
WindowPreview::WindowPreview()
|
||||
{
|
||||
QQmlComponent component(&m_engine, QUrl(QStringLiteral("qrc:/Preview.qml")));
|
||||
m_window.reset(qobject_cast<QQuickWindow *>(component.create()));
|
||||
if (!m_window) {
|
||||
qFatal("Cannot create window preview: %s", qPrintable(component.errorString()));
|
||||
}
|
||||
}
|
||||
|
||||
void WindowPreview::show(const QModelIndex &task, int panelLocation)
|
||||
{
|
||||
const QVariantList ids = task.data(TaskManager::AbstractTasksModel::WinIdList).toList();
|
||||
m_window->setProperty("windowId", ids.isEmpty() ? QString() : ids.first().toString());
|
||||
m_window->setProperty("windowTitle", task.data(Qt::DisplayRole).toString());
|
||||
m_window->setProperty("position", task.parent().isValid() ? task.row() + 1 : 1);
|
||||
m_window->setProperty("count", task.parent().isValid() ? task.model()->rowCount(task.parent()) : 1);
|
||||
m_panelLocation = panelLocation;
|
||||
// Plasma sizes the dialog from mainItem when it becomes visible.
|
||||
m_window->show();
|
||||
|
||||
setAnchor({});
|
||||
}
|
||||
|
||||
void WindowPreview::setAnchor(const QRect &button)
|
||||
{
|
||||
if (!m_window->isVisible()) {
|
||||
return;
|
||||
}
|
||||
QScreen *screen = button.isValid() ? QGuiApplication::screenAt(button.center()) : nullptr;
|
||||
if (!screen) {
|
||||
screen = QGuiApplication::primaryScreen();
|
||||
}
|
||||
if (screen) {
|
||||
m_window->setScreen(screen);
|
||||
m_window->setPosition(previewPosition(button, screen->availableGeometry(), m_window->size(), m_panelLocation));
|
||||
}
|
||||
}
|
||||
|
||||
void WindowPreview::hide()
|
||||
{
|
||||
m_window->hide();
|
||||
m_window->setProperty("windowId", QString());
|
||||
}
|
||||
Reference in New Issue
Block a user