forked from openkylin/ukui-menu
1.使用Quickview替换Quickwindow,2.完成命令行接口功能
This commit is contained in:
parent
33a4a7d961
commit
db3c8c7601
|
@ -0,0 +1,41 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2023, KylinSoft Co., Ltd.
|
||||||
|
*
|
||||||
|
* 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 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* 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 <https://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
import QtQuick 2.12
|
||||||
|
import org.ukui.menu.core 1.0
|
||||||
|
|
||||||
|
import AppUI 1.0 as AppUI
|
||||||
|
|
||||||
|
MenuMainWindow {
|
||||||
|
id: mainWindow
|
||||||
|
visible: true
|
||||||
|
|
||||||
|
Component.onCompleted: {
|
||||||
|
console.log("MenuMainWindow Completed.");
|
||||||
|
}
|
||||||
|
|
||||||
|
onIsFullScreenChanged: {
|
||||||
|
console.log("full screen", isFullScreen)
|
||||||
|
//loader.source = isFullScreen ? "qrc:/qml/FullScreenUI.qml" : "qrc:/qml/NormalUI.qml";
|
||||||
|
}
|
||||||
|
|
||||||
|
AppUI.NormalUI {
|
||||||
|
parent: mainWindow.contentItem
|
||||||
|
anchors.fill: parent
|
||||||
|
}
|
||||||
|
}
|
18
qml/main.qml
18
qml/main.qml
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2022, KylinSoft Co., Ltd.
|
* Copyright (C) 2023, KylinSoft Co., Ltd.
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -17,25 +17,11 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import QtQuick 2.12
|
import QtQuick 2.12
|
||||||
import org.ukui.menu.core 1.0
|
|
||||||
|
|
||||||
import AppUI 1.0 as AppUI
|
import AppUI 1.0 as AppUI
|
||||||
|
|
||||||
MenuMainWindow {
|
Item {
|
||||||
id: mainWindow
|
|
||||||
visible: true
|
|
||||||
|
|
||||||
Component.onCompleted: {
|
|
||||||
console.log("MenuMainWindow Completed.");
|
|
||||||
}
|
|
||||||
|
|
||||||
onIsFullScreenChanged: {
|
|
||||||
console.log("full screen", isFullScreen)
|
|
||||||
//loader.source = isFullScreen ? "qrc:/qml/FullScreenUI.qml" : "qrc:/qml/NormalUI.qml";
|
|
||||||
}
|
|
||||||
|
|
||||||
AppUI.NormalUI {
|
AppUI.NormalUI {
|
||||||
parent: mainWindow.contentItem
|
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
<RCC>
|
<RCC>
|
||||||
<qresource prefix="/qml">
|
<qresource prefix="/qml">
|
||||||
<file>main.qml</file>
|
<file>main.qml</file>
|
||||||
|
<file>MenuMainWindow.qml</file>
|
||||||
<file>org/ukui/menu/extension/qmldir</file>
|
<file>org/ukui/menu/extension/qmldir</file>
|
||||||
<file>org/ukui/menu/extension/UkuiMenuExtension.qml</file>
|
<file>org/ukui/menu/extension/UkuiMenuExtension.qml</file>
|
||||||
<file>AppUI/qmldir</file>
|
<file>AppUI/qmldir</file>
|
||||||
|
|
|
@ -44,6 +44,7 @@ UkuiMenuApplication::UkuiMenuApplication(MenuMessageProcessor *processor) : QObj
|
||||||
void UkuiMenuApplication::startUkuiMenu()
|
void UkuiMenuApplication::startUkuiMenu()
|
||||||
{
|
{
|
||||||
initQmlEngine();
|
initQmlEngine();
|
||||||
|
loadMenuUI();
|
||||||
}
|
}
|
||||||
|
|
||||||
void UkuiMenuApplication::registerQmlTypes()
|
void UkuiMenuApplication::registerQmlTypes()
|
||||||
|
@ -65,28 +66,36 @@ void UkuiMenuApplication::registerQmlTypes()
|
||||||
}
|
}
|
||||||
|
|
||||||
void UkuiMenuApplication::initQmlEngine()
|
void UkuiMenuApplication::initQmlEngine()
|
||||||
|
{
|
||||||
|
m_engine = new QQmlEngine(this);
|
||||||
|
m_engine->addImportPath("qrc:/qml");
|
||||||
|
m_engine->addImageProvider("appicon", new AppIconProvider());
|
||||||
|
|
||||||
|
QQmlContext *context = m_engine->rootContext();
|
||||||
|
context->setContextProperty("colorHelper", ColorHelper::instance());
|
||||||
|
context->setContextProperty("themePalette", ThemePalette::getInstance());
|
||||||
|
context->setContextProperty("menuSetting", MenuSetting::instance());
|
||||||
|
context->setContextProperty("modelManager", new ModelManager(this));
|
||||||
|
context->setContextProperty("extensionManager", MenuExtension::instance());
|
||||||
|
|
||||||
|
// MenuMainWindow
|
||||||
|
// const QUrl url(QStringLiteral("qrc:/qml/MenuMainWindow.qml"));
|
||||||
|
// QQmlApplicationEngine *m_applicationEngine{nullptr};
|
||||||
|
// m_applicationEngine = new QQmlApplicationEngine(this);
|
||||||
|
// QObject::connect(m_applicationEngine, &QQmlApplicationEngine::objectCreated,
|
||||||
|
// this, [url](QObject *obj, const QUrl &objUrl) {
|
||||||
|
// if (!obj && url == objUrl)
|
||||||
|
// QCoreApplication::exit(-1);
|
||||||
|
// }, Qt::QueuedConnection);
|
||||||
|
//
|
||||||
|
// m_applicationEngine->load(url);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UkuiMenuApplication::loadMenuUI()
|
||||||
{
|
{
|
||||||
const QUrl url(QStringLiteral("qrc:/qml/main.qml"));
|
const QUrl url(QStringLiteral("qrc:/qml/main.qml"));
|
||||||
m_applicationEngine = new QQmlApplicationEngine(this);
|
m_mainWindow = new MenuWindow(m_engine, nullptr);
|
||||||
|
m_mainWindow->setSource(url);
|
||||||
m_applicationEngine->addImportPath("qrc:/qml");
|
|
||||||
|
|
||||||
// icon provider
|
|
||||||
m_applicationEngine->addImageProvider("appicon", new AppIconProvider());
|
|
||||||
|
|
||||||
m_applicationEngine->rootContext()->setContextProperty("colorHelper", ColorHelper::instance());
|
|
||||||
m_applicationEngine->rootContext()->setContextProperty("themePalette", ThemePalette::getInstance());
|
|
||||||
m_applicationEngine->rootContext()->setContextProperty("menuSetting", MenuSetting::instance());
|
|
||||||
m_applicationEngine->rootContext()->setContextProperty("modelManager", new ModelManager(this));
|
|
||||||
m_applicationEngine->rootContext()->setContextProperty("extensionManager", MenuExtension::instance());
|
|
||||||
|
|
||||||
QObject::connect(m_applicationEngine, &QQmlApplicationEngine::objectCreated,
|
|
||||||
this, [url](QObject *obj, const QUrl &objUrl) {
|
|
||||||
if (!obj && url == objUrl)
|
|
||||||
QCoreApplication::exit(-1);
|
|
||||||
}, Qt::QueuedConnection);
|
|
||||||
|
|
||||||
m_applicationEngine->load(url);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void UkuiMenuApplication::initDbusService()
|
void UkuiMenuApplication::initDbusService()
|
||||||
|
@ -105,22 +114,38 @@ void UkuiMenuApplication::initDbusService()
|
||||||
void UkuiMenuApplication::execCommand(Command command)
|
void UkuiMenuApplication::execCommand(Command command)
|
||||||
{
|
{
|
||||||
switch (command) {
|
switch (command) {
|
||||||
case Active:
|
case Active: {
|
||||||
qDebug() << "=Active=>>" << Active;
|
if (m_mainWindow) {
|
||||||
|
m_mainWindow->setVisible(!m_mainWindow->isVisible());
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case Show:
|
}
|
||||||
qDebug() << "=Show=>>" << Show;
|
case Show: {
|
||||||
|
if (m_mainWindow) {
|
||||||
|
m_mainWindow->setVisible(true);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case Quit:
|
}
|
||||||
qDebug() << "=Quit=>>" << Quit;
|
case Quit: {
|
||||||
m_applicationEngine->quit();
|
if (m_mainWindow) {
|
||||||
|
m_mainWindow->setVisible(false);
|
||||||
|
m_engine->quit();
|
||||||
|
}
|
||||||
QCoreApplication::quit();
|
QCoreApplication::quit();
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UkuiMenuApplication::~UkuiMenuApplication()
|
||||||
|
{
|
||||||
|
if (m_mainWindow) {
|
||||||
|
m_mainWindow->deleteLater();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// == MenuMessageProcessor == //
|
// == MenuMessageProcessor == //
|
||||||
MenuMessageProcessor::MenuMessageProcessor() : QObject(nullptr) {}
|
MenuMessageProcessor::MenuMessageProcessor() : QObject(nullptr) {}
|
||||||
|
|
||||||
|
|
|
@ -20,11 +20,12 @@
|
||||||
#define UKUI_MENU_UKUI_MENU_APPLICATION_H
|
#define UKUI_MENU_UKUI_MENU_APPLICATION_H
|
||||||
|
|
||||||
#include "menu-dbus-service.h"
|
#include "menu-dbus-service.h"
|
||||||
#include <QQmlApplicationEngine>
|
#include <QQmlEngine>
|
||||||
|
|
||||||
namespace UkuiMenu {
|
namespace UkuiMenu {
|
||||||
|
|
||||||
class MenuMessageProcessor;
|
class MenuMessageProcessor;
|
||||||
|
class MenuWindow;
|
||||||
|
|
||||||
class UkuiMenuApplication : public QObject
|
class UkuiMenuApplication : public QObject
|
||||||
{
|
{
|
||||||
|
@ -36,6 +37,7 @@ public:
|
||||||
Quit
|
Quit
|
||||||
};
|
};
|
||||||
explicit UkuiMenuApplication(MenuMessageProcessor *processor);
|
explicit UkuiMenuApplication(MenuMessageProcessor *processor);
|
||||||
|
~UkuiMenuApplication() override;
|
||||||
UkuiMenuApplication() = delete;
|
UkuiMenuApplication() = delete;
|
||||||
UkuiMenuApplication(const UkuiMenuApplication& obj) = delete;
|
UkuiMenuApplication(const UkuiMenuApplication& obj) = delete;
|
||||||
UkuiMenuApplication(const UkuiMenuApplication&& obj) = delete;
|
UkuiMenuApplication(const UkuiMenuApplication&& obj) = delete;
|
||||||
|
@ -47,13 +49,15 @@ private:
|
||||||
static void registerQmlTypes();
|
static void registerQmlTypes();
|
||||||
void startUkuiMenu();
|
void startUkuiMenu();
|
||||||
void initQmlEngine();
|
void initQmlEngine();
|
||||||
|
void loadMenuUI();
|
||||||
|
|
||||||
//注册dubs
|
//注册dubs
|
||||||
void initDbusService();
|
void initDbusService();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QQmlApplicationEngine *m_applicationEngine{nullptr};
|
QQmlEngine *m_engine{nullptr};
|
||||||
MenuDbusService *m_menuDbusService = nullptr;
|
MenuWindow *m_mainWindow{nullptr};
|
||||||
|
MenuDbusService *m_menuDbusService{nullptr};
|
||||||
};
|
};
|
||||||
|
|
||||||
class MenuMessageProcessor : public QObject
|
class MenuMessageProcessor : public QObject
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
#include <QQuickItem>
|
#include <QQuickItem>
|
||||||
#include <QGSettings>
|
#include <QGSettings>
|
||||||
#include <QX11Info>
|
#include <QX11Info>
|
||||||
|
#include <QQmlContext>
|
||||||
#include <QPoint>
|
#include <QPoint>
|
||||||
#include <KWindowSystem>
|
#include <KWindowSystem>
|
||||||
|
|
||||||
|
@ -89,6 +90,7 @@ void WindowHelper::setWindowAttribute(QWindow *window)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//======MenuMainWindow======//
|
||||||
MenuMainWindow::MenuMainWindow(QWindow *parent) : QQuickWindow(parent), m_geometryHelper(new WindowGeometryHelper(this))
|
MenuMainWindow::MenuMainWindow(QWindow *parent) : QQuickWindow(parent), m_geometryHelper(new WindowGeometryHelper(this))
|
||||||
{
|
{
|
||||||
init();
|
init();
|
||||||
|
@ -314,4 +316,99 @@ const QRect &WindowGeometryHelper::normalGeometry()
|
||||||
return m_normalGeometry;
|
return m_normalGeometry;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//======MenuWindow======//
|
||||||
|
MenuWindow::MenuWindow(QWindow *parent) : QQuickView(parent), m_geometryHelper(new WindowGeometryHelper(this))
|
||||||
|
{
|
||||||
|
init();
|
||||||
|
}
|
||||||
|
|
||||||
|
MenuWindow::MenuWindow(QQmlEngine *engine, QWindow *parent)
|
||||||
|
: QQuickView(engine, parent), m_geometryHelper(new WindowGeometryHelper(this))
|
||||||
|
{
|
||||||
|
init();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MenuWindow::init()
|
||||||
|
{
|
||||||
|
setTitle(QCoreApplication::applicationName());
|
||||||
|
setResizeMode(SizeRootObjectToView);
|
||||||
|
setColor("transparent");
|
||||||
|
|
||||||
|
// TODO 使用窗管接口设置无边框
|
||||||
|
setFlags(Qt::FramelessWindowHint);
|
||||||
|
WindowHelper::setWindowAttribute(this);
|
||||||
|
|
||||||
|
// 访问窗口api
|
||||||
|
rootContext()->setContextProperty("mainWindow", this);
|
||||||
|
connect(this, &QQuickView::activeFocusItemChanged, this, &MenuWindow::onActiveFocusItemChanged);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MenuWindow::updateGeometry()
|
||||||
|
{
|
||||||
|
QRect rect = m_isFullScreen ? m_geometryHelper->fullScreenGeometry() : m_geometryHelper->normalGeometry();
|
||||||
|
if (rect == geometry()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
WindowHelper::setWindowGeometry(this, rect);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MenuWindow::isFullScreen() const
|
||||||
|
{
|
||||||
|
return m_isFullScreen;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MenuWindow::setFullScreen(bool isFullScreen)
|
||||||
|
{
|
||||||
|
if (m_isFullScreen == isFullScreen) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_isFullScreen = isFullScreen;
|
||||||
|
QEvent event(QEvent::Resize);
|
||||||
|
QCoreApplication::sendEvent(this, &event);
|
||||||
|
|
||||||
|
Q_EMIT fullScreenChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MenuWindow::exposeEvent(QExposeEvent *event)
|
||||||
|
{
|
||||||
|
QQuickWindow::exposeEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MenuWindow::resizeEvent(QResizeEvent *event)
|
||||||
|
{
|
||||||
|
updateGeometry();
|
||||||
|
QQuickView::resizeEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MenuWindow::showEvent(QShowEvent *event)
|
||||||
|
{
|
||||||
|
QQuickWindow::showEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MenuWindow::focusOutEvent(QFocusEvent *event)
|
||||||
|
{
|
||||||
|
//setVisible(false);
|
||||||
|
QQuickWindow::focusOutEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MenuWindow::event(QEvent *event)
|
||||||
|
{
|
||||||
|
if (event->type() == QEvent::Move) {
|
||||||
|
updateGeometry();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return QQuickView::event(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MenuWindow::onActiveFocusItemChanged()
|
||||||
|
{
|
||||||
|
if (activeFocusItem()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setVisible(false);
|
||||||
|
}
|
||||||
|
|
||||||
} // UkuiMenu
|
} // UkuiMenu
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QRect>
|
#include <QRect>
|
||||||
#include <QScreen>
|
#include <QScreen>
|
||||||
|
#include <QQuickView>
|
||||||
#include <QQuickWindow>
|
#include <QQuickWindow>
|
||||||
|
|
||||||
namespace UkuiMenu {
|
namespace UkuiMenu {
|
||||||
|
@ -98,6 +99,40 @@ private:
|
||||||
WindowGeometryHelper *m_geometryHelper{nullptr};
|
WindowGeometryHelper *m_geometryHelper{nullptr};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class MenuWindow : public QQuickView
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(bool isFullScreen READ isFullScreen WRITE setFullScreen NOTIFY fullScreenChanged)
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit MenuWindow(QWindow *parent = nullptr);
|
||||||
|
MenuWindow(QQmlEngine* engine, QWindow *parent);
|
||||||
|
|
||||||
|
bool isFullScreen() const;
|
||||||
|
void setFullScreen(bool isFullScreen);
|
||||||
|
|
||||||
|
Q_SIGNALS:
|
||||||
|
void fullScreenChanged();
|
||||||
|
|
||||||
|
private Q_SLOTS:
|
||||||
|
void onActiveFocusItemChanged();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void exposeEvent(QExposeEvent *event) override;
|
||||||
|
void resizeEvent(QResizeEvent *event) override;
|
||||||
|
void showEvent(QShowEvent *event) override;
|
||||||
|
void focusOutEvent(QFocusEvent *event) override;
|
||||||
|
bool event(QEvent *event) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void init();
|
||||||
|
void updateGeometry();
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool m_isFullScreen{false};
|
||||||
|
WindowGeometryHelper *m_geometryHelper{nullptr};
|
||||||
|
};
|
||||||
|
|
||||||
} // UkuiMenu
|
} // UkuiMenu
|
||||||
|
|
||||||
#endif //UKUI_MENU_MENU_MAIN_WINDOW_H
|
#endif //UKUI_MENU_MENU_MAIN_WINDOW_H
|
||||||
|
|
Loading…
Reference in New Issue