Skip to content

Commit

Permalink
Implemented Main Window Title (and related window properties)
Browse files Browse the repository at this point in the history
  • Loading branch information
cbjeukendrup committed Jun 21, 2021
1 parent d8e834a commit cfe37dd
Show file tree
Hide file tree
Showing 14 changed files with 282 additions and 26 deletions.
2 changes: 2 additions & 0 deletions src/appshell/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ set(MODULE_SRC
${CMAKE_CURRENT_LIST_DIR}/view/devtools/settingslistmodel.h
${CMAKE_CURRENT_LIST_DIR}/view/appmenumodel.cpp
${CMAKE_CURRENT_LIST_DIR}/view/appmenumodel.h
${CMAKE_CURRENT_LIST_DIR}/view/mainwindowtitleprovider.cpp
${CMAKE_CURRENT_LIST_DIR}/view/mainwindowtitleprovider.h
${CMAKE_CURRENT_LIST_DIR}/view/notationpagemodel.cpp
${CMAKE_CURRENT_LIST_DIR}/view/notationpagemodel.h
${CMAKE_CURRENT_LIST_DIR}/view/notationstatusbarmodel.cpp
Expand Down
2 changes: 2 additions & 0 deletions src/appshell/appshellmodule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

#include "view/devtools/settingslistmodel.h"
#include "view/appmenumodel.h"
#include "view/mainwindowtitleprovider.h"
#include "view/notationpagemodel.h"
#include "view/notationstatusbarmodel.h"
#include "view/aboutmodel.h"
Expand Down Expand Up @@ -135,6 +136,7 @@ void AppShellModule::registerUiTypes()
qmlRegisterType<IOPreferencesModel>("MuseScore.Preferences", 1, 0, "IOPreferencesModel");
qmlRegisterType<CommonAudioApiConfigurationModel>("MuseScore.Preferences", 1, 0, "CommonAudioApiConfigurationModel");
qmlRegisterType<AppMenuModel>("MuseScore.AppShell", 1, 0, "AppMenuModel");
qmlRegisterType<MainWindowTitleProvider>("MuseScore.AppShell", 1, 0, "MainWindowTitleProvider");
qmlRegisterType<NotationPageModel>("MuseScore.AppShell", 1, 0, "NotationPageModel");
qmlRegisterType<NotationStatusBarModel>("MuseScore.AppShell", 1, 0, "NotationStatusBarModel");
qmlRegisterType<AboutModel>("MuseScore.AppShell", 1, 0, "AboutModel");
Expand Down
18 changes: 17 additions & 1 deletion src/appshell/qml/AppWindow.qml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import QtQuick.Controls 2.15

import MuseScore.Ui 1.0
import MuseScore.Shortcuts 1.0
import MuseScore.AppShell 1.0
import MuseScore.Dock 1.0

ApplicationWindow {
id: root
Expand All @@ -36,7 +38,20 @@ ApplicationWindow {

visible: true

title: qsTrc("appshell", "MuseScore 4")
MainWindowTitleProvider {
id: titleProvider
}

MainWindowProvider {
window: root

//! NOTE These properties of QWindow (of which ApplicationWindow is derived)
//! are not available in QML, so we access them via MainWindowProvider
filePath: titleProvider.filePath
fileModified: titleProvider.fileModified
}

title: titleProvider.title

ToolTipProvider { }

Expand All @@ -45,5 +60,6 @@ ApplicationWindow {

Component.onCompleted: {
ui.rootItem = root.contentItem
titleProvider.load()
}
}
5 changes: 0 additions & 5 deletions src/appshell/qml/Main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,12 @@ import QtQuick.Window 2.15

import MuseScore.UiComponents 1.0
import MuseScore.AppShell 1.0
import MuseScore.Dock 1.0

import "../.."

AppWindow {
id: root

MainWindowProvider {
window: root
}

function toggleMaximized() {
if (root.visibility === Window.Maximized) {
root.showNormal()
Expand Down
5 changes: 0 additions & 5 deletions src/appshell/qml/platform/linux/Main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import QtQuick 2.15
import QtQuick.Window 2.15

import MuseScore.UiComponents 1.0
import MuseScore.Dock 1.0

import "../../"

Expand All @@ -33,10 +32,6 @@ AppWindow {
flags: Qt.FramelessWindowHint | Qt.Window
color: "transparent"

MainWindowProvider {
window: root
}

property int sideMargin: root.visibility === Window.Windowed ? 8 : 0

function toggleMaximized() {
Expand Down
5 changes: 0 additions & 5 deletions src/appshell/qml/platform/mac/Main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,12 @@ import QtQuick 2.15
import Qt.labs.platform 1.1 as PLATFORM

import MuseScore.AppShell 1.0
import MuseScore.Dock 1.0

import "../../"

AppWindow {
id: root

MainWindowProvider {
window: root
}

PLATFORM.MenuBar {
id: menuBar
}
Expand Down
5 changes: 0 additions & 5 deletions src/appshell/qml/platform/win/Main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,12 @@ import QtQuick.Window 2.15

import MuseScore.UiComponents 1.0
import MuseScore.AppShell 1.0
import MuseScore.Dock 1.0

import "../../"

AppWindow {
id: root

MainWindowProvider {
window: root
}

function toggleMaximized() {
if (root.visibility === Window.Maximized) {
root.showNormal()
Expand Down
8 changes: 7 additions & 1 deletion src/appshell/view/dockwindow/dockwindow.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,15 @@ set (DOCK_LIBS

if (OS_IS_MAC)
set (DOCKWINDOW_PLATFORM_SRC
${CMAKE_CURRENT_LIST_DIR}/internal/platform/macos/macosmainwindowprovider.cpp
${CMAKE_CURRENT_LIST_DIR}/internal/platform/macos/macosmainwindowprovider.mm
${CMAKE_CURRENT_LIST_DIR}/internal/platform/macos/macosmainwindowprovider.h
)
# Don't mix C++ and Objective-C++ in Unity Build
set_source_files_properties(${CMAKE_CURRENT_LIST_DIR}/internal/platform/macos/macosmainwindowprovider.mm
PROPERTIES SKIP_UNITY_BUILD_INCLUSION ON)

set_source_files_properties(${CMAKE_CURRENT_LIST_DIR}/internal/platform/macos/macosmainwindowprovider.mm
PROPERTIES SKIP_PRECOMPILE_HEADERS ON)
else()
set (DOCKWINDOW_PLATFORM_SRC )
endif()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ class MacOSMainWindowProvider : public MainWindowProvider, public async::Asyncab
public:
explicit MacOSMainWindowProvider(QObject* parent = nullptr);

signals:
void targetWindowChanged();
bool fileModified() const override;

public slots:
void setFileModified(bool modified) override;

private:
void init() override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,22 @@
*/
#include "macosmainwindowprovider.h"

#include <Cocoa/Cocoa.h>
#include <QWindow>

using namespace mu::dock;

static NSWindow* nsWindowForQWindow(QWindow* qWindow)
{
if (!qWindow) {
return nullptr;
}

NSView* nsView = (__bridge NSView*)reinterpret_cast<void*>(qWindow->winId());
NSWindow* nsWindow = [nsView window];
return nsWindow;
}

MacOSMainWindowProvider::MacOSMainWindowProvider(QObject* parent)
: MainWindowProvider(parent)
{
Expand All @@ -40,3 +52,29 @@ void MacOSMainWindowProvider::init()
uiConfiguration()->applyPlatformStyle(m_window);
});
}

bool MacOSMainWindowProvider::fileModified() const
{
//! NOTE QWindow misses an API for this, so we'll do it ourselves.
NSWindow* nsWindow = nsWindowForQWindow(m_window);
if (!nsWindow) {
return false;
}

return [nsWindow isDocumentEdited];
}

void MacOSMainWindowProvider::setFileModified(bool modified)
{
NSWindow* nsWindow = nsWindowForQWindow(m_window);
if (!nsWindow) {
return;
}

if ([nsWindow isDocumentEdited] == modified) {
return;
}

[nsWindow setDocumentEdited:modified];
emit fileModifiedChanged();
}
28 changes: 28 additions & 0 deletions src/appshell/view/dockwindow/mainwindowprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,34 @@ void MainWindowProvider::init()
framework::ioc()->registerExport<ui::IMainWindow>("dock", this);
}

QString MainWindowProvider::filePath() const
{
return m_window ? m_window->filePath() : "";
}

void MainWindowProvider::setFilePath(const QString& filePath)
{
if (!m_window) {
return;
}

if (filePath == m_window->filePath()) {
return;
}

m_window->setFilePath(filePath);
emit filePathChanged();
}

bool MainWindowProvider::fileModified() const
{
return false;
}

void MainWindowProvider::setFileModified(bool /*modified*/)
{
}

void MainWindowProvider::requestShowOnBack()
{
m_window->lower();
Expand Down
14 changes: 12 additions & 2 deletions src/appshell/view/dockwindow/mainwindowprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,18 @@ class MainWindowProvider : public QObject, public ui::IMainWindow
Q_OBJECT

Q_PROPERTY(QWindow * window READ qWindow WRITE setWindow NOTIFY windowChanged)
Q_PROPERTY(QString filePath READ filePath WRITE setFilePath NOTIFY filePathChanged)
Q_PROPERTY(bool fileModified READ fileModified WRITE setFileModified NOTIFY fileModifiedChanged)

public:
explicit MainWindowProvider(QObject* parent = nullptr);

QMainWindow* qMainWindow() const override;
QWindow* qWindow() const override;

QString filePath() const;
virtual bool fileModified() const;

void requestShowOnBack() override;
void requestShowOnFront() override;

Expand All @@ -61,15 +66,20 @@ class MainWindowProvider : public QObject, public ui::IMainWindow

signals:
void windowChanged();
void filePathChanged();
void fileModifiedChanged();

protected:
virtual void init();

QWindow* m_window = nullptr;

private:
void setWindow(QWindow* window); // Should only be used from QML
private slots: // Should only be used from QML
void setWindow(QWindow* window);
void setFilePath(const QString& filePath);
virtual void setFileModified(bool modified);

private:
async::Channel<QString, framework::Orientation> m_dockOrientationChanged;
async::Channel<QPoint> m_showToolBarDockingHolderRequested;
async::Channel<QPoint> m_showPanelDockingHolderRequested;
Expand Down
Loading

0 comments on commit cfe37dd

Please sign in to comment.