Skip to content

Commit

Permalink
[Merge] Revert to the way of doing screen projections in v1.1
Browse files Browse the repository at this point in the history
This earlier way of doing things isn't incompatible with Qt 6.
Let's use it as means to have the feature until a better solution
is found.

Merges 4dc5b07
  • Loading branch information
Cuperino committed Dec 1, 2024
1 parent 04d01bd commit 8da5ef9
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 132 deletions.
14 changes: 7 additions & 7 deletions src/kirigami_ui/+android/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -302,13 +302,13 @@ Kirigami.ApplicationWindow {
}
Kirigami.Action {
text: i18nc("Main menu actions. Enters Performance tweaks submenu.", "Performance tweaks")
// Kirigami.Action {
// text: i18nc("Main menu actions", "Disable screen projections")
// enabled: !checked
// checkable: true
// checked: !projectionManager.isEnabled
// onTriggered: projectionManager.toggle()
// }
Kirigami.Action {
text: i18nc("Main menu actions", "Disable screen projections")
enabled: !checked
checkable: true
checked: !projectionManager.isEnabled
onTriggered: projectionManager.toggle()
}
Kirigami.Action {
text: i18nc("Main menu actions", "Disable timers")
enabled: !checked
Expand Down
29 changes: 13 additions & 16 deletions src/kirigami_ui/+windows/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -330,13 +330,13 @@ Kirigami.ApplicationWindow {
}
Kirigami.Action {
text: i18nc("Main menu actions. Enters Performance tweaks submenu.", "Performance tweaks")
// Kirigami.Action {
// text: i18nc("Main menu actions", "Disable screen projections")
// enabled: !checked
// checkable: true
// checked: !projectionManager.isEnabled
// onTriggered: projectionManager.toggle()
// }
Kirigami.Action {
text: i18nc("Main menu actions", "Disable screen projections")
enabled: !checked
checkable: true
checked: !projectionManager.isEnabled
onTriggered: projectionManager.toggle()
}
Kirigami.Action {
text: i18nc("Main menu actions", "Disable timers")
enabled: !checked
Expand Down Expand Up @@ -661,15 +661,12 @@ Kirigami.ApplicationWindow {
// Thus runs from here because there's no event that occurs on each bit of scroll, and this takes much less CPU than a timer, is more precise and scales better.
root.pageStack.currentItem.prompter.markerCompare();
// Update Projections
if (projectionManager.isEnabled/* && projectionManager.model.count*/)
// Recount projections on each for loop iteration to prevent value from going stale because a window was closed from a different thread.
for (var i=0; i<projectionManager.projections.count; i++) {
const w = projectionManager.projections.objectAt(i);
if (w!==null && root.visible)
w.update();
else
break;
}
if (projectionManager.isEnabled)
root.pageStack.currentItem.viewport.grabToImage(function(p) {
// Recount projections on each for loop iteration to prevent value from going stale because a window was closed from a different thread.
for (var i=0; i<projectionManager.projections.count; i++)
projectionManager.model.setProperty(i, "p", String(p.url));
});
}

ProjectionsManager {
Expand Down
3 changes: 1 addition & 2 deletions src/kirigami_ui/PrompterPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -614,8 +614,7 @@ Kirigami.Page {
},
Kirigami.Action {
id: displaySettings
visible: false
// visible: (!Kirigami.Settings.isMobile || Qt.platform.os==='linux') && Qt.platform.os!=='haiku'
visible: (!Kirigami.Settings.isMobile || Qt.platform.os==='linux') && Qt.platform.os!=='haiku'
text: i18nc("Screens refers to computer displays", "Screens")

Kirigami.Action {
Expand Down
29 changes: 13 additions & 16 deletions src/kirigami_ui/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -330,13 +330,13 @@ Kirigami.ApplicationWindow {
}
Kirigami.Action {
text: i18nc("Main menu actions. Enters Performance tweaks submenu.", "Performance tweaks")
// Kirigami.Action {
// text: i18nc("Main menu actions", "Disable screen projections")
// enabled: !checked
// checkable: true
// checked: !projectionManager.isEnabled
// onTriggered: projectionManager.toggle()
// }
Kirigami.Action {
text: i18nc("Main menu actions", "Disable screen projections")
enabled: !checked
checkable: true
checked: !projectionManager.isEnabled
onTriggered: projectionManager.toggle()
}
Kirigami.Action {
text: i18nc("Main menu actions", "Disable timers")
enabled: !checked
Expand Down Expand Up @@ -962,15 +962,12 @@ Kirigami.ApplicationWindow {
// Thus runs from here because there's no event that occurs on each bit of scroll, and this takes much less CPU than a timer, is more precise and scales better.
root.pageStack.currentItem.prompter.markerCompare();
// Update Projections
if (projectionManager.isEnabled/* && projectionManager.model.count*/)
// Recount projections on each for loop iteration to prevent value from going stale because a window was closed from a different thread.
for (var i=0; i<projectionManager.projections.count; i++) {
const w = projectionManager.projections.objectAt(i);
if (w!==null && root.visible)
w.update();
else
break;
}
if (projectionManager.isEnabled)
root.pageStack.currentItem.viewport.grabToImage(function(p) {
// Recount projections on each for loop iteration to prevent value from going stale because a window was closed from a different thread.
for (var i=0; i<projectionManager.projections.count; i++)
projectionManager.model.setProperty(i, "p", String(p.url));
});
}

ProjectionsManager {
Expand Down
112 changes: 47 additions & 65 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@
#include <QHotkey>
#endif

// #if defined(Q_OS_MACOS)
// #include <../3rdparty/KDMacTouchBar/src/kdmactouchbar.h>
// #endif
#if defined(Q_OS_MACOS)
#include <../3rdparty/KDMacTouchBar/src/kdmactouchbar.h>
#endif

#include "../qprompt_version.h"
#include "abstractunits.hpp"
Expand All @@ -72,25 +72,6 @@ Q_DECL_EXPORT int main(int argc, char *argv[])
qputenv("QT_QUICK_CONTROLS_STYLE", QByteArray("Material"));
qputenv("QT_QUICK_CONTROLS_MATERIAL_THEME", QByteArray("Dark"));
qputenv("QT_QUICK_CONTROLS_MATERIAL_ACCENT", QByteArray("#3daee9"));

// Initialize app metadata
QCoreApplication::setOrganizationName(QString::fromUtf8("Cuperino"));
QCoreApplication::setOrganizationDomain(QString::fromUtf8(QPROMPT_URI));
QCoreApplication::setApplicationName(QString::fromUtf8("QPrompt"));

// Acquire saved settings
QSettings settings(QCoreApplication::organizationName(), QCoreApplication::applicationName().toLower());

// The following code forces the use of a specific language.
QString language = settings.value("ui/language", "").toString();
if (!language.isEmpty()) {
auto langCode = language.append(".UTF-8").toStdString();
qDebug() << langCode;
qputenv("LANGUAGE", langCode);
qputenv("LC_ALL", langCode);
qputenv("LANG", langCode);
}

// Instantiate app
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
Expand All @@ -100,10 +81,11 @@ Q_DECL_EXPORT int main(int argc, char *argv[])
#else
QApplication app(argc, argv);
#endif

// Initialize i18n metadata
// Initialize app metadata
KLocalizedString::setApplicationDomain("qprompt");

QCoreApplication::setOrganizationName(QString::fromUtf8("Cuperino"));
QCoreApplication::setOrganizationDomain(QString::fromUtf8(QPROMPT_URI));
QCoreApplication::setApplicationName(QString::fromUtf8("QPrompt"));
// Parse command line arguments
QCommandLineParser parser;
parser.setApplicationDescription(
Expand All @@ -121,6 +103,9 @@ Q_DECL_EXPORT int main(int argc, char *argv[])
if (positionalArguments.length())
fileToOpen = parser.positionalArguments().at(0);

// Acquire saved settings
QSettings settings(QCoreApplication::organizationName(), QCoreApplication::applicationName().toLower());

// Substract from 2 because order in app is intentionally inverted from order in Qt
app.setLayoutDirection(static_cast<Qt::LayoutDirection>(2 - settings.value("ui/layout", 0).toInt()));

Expand Down Expand Up @@ -181,43 +166,43 @@ Q_DECL_EXPORT int main(int argc, char *argv[])
// KirigamiPlugin::getInstance().registerTypes();
// #endif

// #if defined(Q_OS_MACOS)
// // Enable automatic display of dialog prompts on the touchbar.
// KDMacTouchBar::setAutomaticallyCreateMessageBoxTouchBar(true);
// // // Create touchbar for use through all of QPrompt's execusion
// // KDMacTouchBar *touchBar = new KDMacTouchBar();
// // //QMainWindow *mainWindow = nullptr;
// // //foreach(QWidget *widget, app.topLevelWidgets())
// // // if(widget->inherits("QMainWindow")) {
// // // mainWindow = qobject_cast<QMainWindow *>(widget);
// // // break;
// // // };
// // //KDMacTouchBar *touchBar = new KDMacTouchBar(mainWindow);
// // // Toggle teleprompter state
// // QIcon qpromptIcon(QStringLiteral(":images/qprompt"));
// // QAction *action = new QAction(qpromptIcon, "Toggle");
// // touchBar->addAction(action);
// // // connect(action, &QAction::triggered, this, &MainWindow::activated);
// // touchBar->addSeparator();
// // // Velocity and placement toachbar controls
// // touchBar->setTouchButtonStyle(KDMacTouchBar::IconOnly);
// // // Up
// // QIcon upIcon(QStringLiteral(":icons/go-previous"));
// // QAction *reduceAction = new QAction(upIcon, "Reduce");
// // touchBar->addAction(reduceAction);
// // touchBar->setPrincipialAction(reduceAction);
// // // connect(reduceAction, &QAction::triggered, this, &MainWindow::activated);
// // // Down
// // QIcon downIcon(QStringLiteral(":icons/go-next"));
// // QAction *increaseAction = new QAction(downIcon, "Increase");
// // touchBar->addAction(increaseAction);
// // // connect(increaseAction, &QAction::triggered, this, &MainWindow::activated);
// //// touchBar->addSeparator();
// //// // Stop prompter
// //// QAction *stopAction = new QAction(upIcon, "Stop");
// //// touchBar->addAction(stopAction);
// //// // connect(stopAction, &QAction::triggered, this, &MainWindow::activated);
// #endif
#if defined(Q_OS_MACOS)
// Enable automatic display of dialog prompts on the touchbar.
KDMacTouchBar::setAutomaticallyCreateMessageBoxTouchBar(true);
// // Create touchbar for use through all of QPrompt's execusion
// KDMacTouchBar *touchBar = new KDMacTouchBar();
// //QMainWindow *mainWindow = nullptr;
// //foreach(QWidget *widget, app.topLevelWidgets())
// // if(widget->inherits("QMainWindow")) {
// // mainWindow = qobject_cast<QMainWindow *>(widget);
// // break;
// // };
// //KDMacTouchBar *touchBar = new KDMacTouchBar(mainWindow);
// // Toggle teleprompter state
// QIcon qpromptIcon(QStringLiteral(":images/qprompt"));
// QAction *action = new QAction(qpromptIcon, "Toggle");
// touchBar->addAction(action);
// // connect(action, &QAction::triggered, this, &MainWindow::activated);
// touchBar->addSeparator();
// // Velocity and placement toachbar controls
// touchBar->setTouchButtonStyle(KDMacTouchBar::IconOnly);
// // Up
// QIcon upIcon(QStringLiteral(":icons/go-previous"));
// QAction *reduceAction = new QAction(upIcon, "Reduce");
// touchBar->addAction(reduceAction);
// touchBar->setPrincipialAction(reduceAction);
// // connect(reduceAction, &QAction::triggered, this, &MainWindow::activated);
// // Down
// QIcon downIcon(QStringLiteral(":icons/go-next"));
// QAction *increaseAction = new QAction(downIcon, "Increase");
// touchBar->addAction(increaseAction);
// // connect(increaseAction, &QAction::triggered, this, &MainWindow::activated);
//// touchBar->addSeparator();
//// // Stop prompter
//// QAction *stopAction = new QAction(upIcon, "Stop");
//// touchBar->addAction(stopAction);
//// // connect(stopAction, &QAction::triggered, this, &MainWindow::activated);
#endif

#if defined(QHotkey_FOUND)
// Toggle transparency of all windows
Expand Down Expand Up @@ -252,9 +237,6 @@ Q_DECL_EXPORT int main(int argc, char *argv[])
engine.addImportPath(QStringLiteral("../../lib/qml/"));
engine.addImportPath(QStringLiteral("../lib/qml/"));
engine.addImportPath(QStringLiteral("./lib/qml/"));
engine.addImportPath(QStringLiteral("../../../install/lib/qml/"));
engine.addImportPath(QStringLiteral("../../install/lib/qml/"));
engine.addImportPath(QStringLiteral("./../install/lib/qml/"));
// MacOS paths
engine.addImportPath(QStringLiteral("../build/"));
engine.addImportPath(QStringLiteral("../Resources/qml/"));
Expand Down
42 changes: 25 additions & 17 deletions src/prompter/ProjectionsManager.qml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ Item {
property bool isEnabled: false
property string screensStringified: ""
required property var forwardTo // prompter
property bool projectionRestartPrompt: true
property bool projectionRestartPrompt: false
// property bool projectionRestartPrompt: true
property int projectionRestartModulus: 1

function toggle() {
Expand All @@ -50,17 +51,17 @@ Item {
closeAll();
projectionSettings.sync();

// If it was initially off, prompt to restart each time it's turned on.
// If initially on and turning off, don't prompt to restart more than once.
if (projectionRestartModulus % 2) {
if (projectionRestartPrompt)
restartDialog.visible = true;
if (!isEnabled && projectionRestartPrompt)
projectionRestartPrompt = false;
projectionRestartModulus = 0;
}
else
projectionRestartModulus++;
// // If it was initially off, prompt to restart each time it's turned on.
// // If initially on and turning off, don't prompt to restart more than once.
// if (projectionRestartModulus % 2) {
// if (projectionRestartPrompt)
// restartDialog.visible = true;
// if (!isEnabled && projectionRestartPrompt)
// projectionRestartPrompt = false;
// projectionRestartModulus = 0;
// }
// else
// projectionRestartModulus++;
}
function getDisplayFlip(screenName, flipSetting) {
const totalDisplays = displayModel.count;
Expand Down Expand Up @@ -274,19 +275,26 @@ Item {
opacity: 0.6
}
// The actual projection
ShaderEffect {
Image {
id: img
property variant source: projectionManager.forwardTo
// property variant source: projectionManager.forwardTo
source: model.flip ? model.p : false
// Keep loading asynchronous. Improve responsiveness of main thread.
asynchronous: true
// Cache image if it's not being re-scaled so it could be used on n projection without much additional cost.
cache: !reScale
// Mirror Horizontally: Save time by mirroring image on copy instead of flipping the result
mirror: model.flip===2 || model.flip===4
// Keep image vertically centered relative to the window's MouseArea, which fills the window.
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
width: reScale ? parent.width : projectionManager.forwardTo.width
height: reScale ? (parent.width / projectionManager.forwardTo.width) * projectionManager.forwardTo.height : projectionManager.forwardTo.height
blending: false
transform: Scale {
origin.y: img.height/2
yScale: model.flip===3 || model.flip===4 ? -1 : 1
origin.x: img.width/2
xScale: model.flip===2 || model.flip===4 ? -1 : 1
// origin.x: img.width/2
// xScale: model.flip===2 || model.flip===4 ? -1 : 1
}
Rectangle {
color: "#000000"
Expand Down
9 changes: 0 additions & 9 deletions src/prompter/PrompterView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,6 @@ Item {
property real __baseSpeed: editorToolbar.baseSpeedSlider.value
property real __curvature: editorToolbar.baseAccelerationSlider.value

//layer.enabled: true
// Undersample
//layer.mipmap: true
// Oversample
//layer.samples: 2
//layer.smooth: true
// Make texture the size of the largest destinations.
//layer.textureSize: Qt.size(projectionWindow.width, projectionWindow.height)

transform: Rotation {
origin.x: (forcedOrientation && forcedOrientation!==3 ? parent.height/2 : parent.width*0.15);
origin.y: (forcedOrientation && forcedOrientation!==3 ? parent.width/2 : parent.height);
Expand Down

0 comments on commit 8da5ef9

Please sign in to comment.