mirror of
https://codeberg.org/vyn/mirai.git
synced 2025-07-03 01:33:19 +00:00
Add basic responsive layout for Phone
This commit is contained in:
parent
1416b5db58
commit
375a1bfb2d
7 changed files with 360 additions and 293 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -5,3 +5,4 @@ todo.md
|
||||||
.clangd
|
.clangd
|
||||||
.cache
|
.cache
|
||||||
.nvimrc
|
.nvimrc
|
||||||
|
CMakeLists.txt.user
|
||||||
|
|
|
@ -39,6 +39,7 @@ qt_add_qml_module(mirai
|
||||||
#RESOURCE_PREFIX /qt/qml
|
#RESOURCE_PREFIX /qt/qml
|
||||||
QML_FILES
|
QML_FILES
|
||||||
src/qml/Main.qml
|
src/qml/Main.qml
|
||||||
|
src/qml/MainPanel.qml
|
||||||
src/qml/SideMenu.qml
|
src/qml/SideMenu.qml
|
||||||
src/qml/DatePicker.qml
|
src/qml/DatePicker.qml
|
||||||
src/qml/DateField.qml
|
src/qml/DateField.qml
|
||||||
|
|
|
@ -19,19 +19,19 @@ namespace cpputils::debug
|
||||||
class Timer
|
class Timer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Timer() : startTime(std::chrono::high_resolution_clock::now())
|
Timer() : startTime(std::chrono::steady_clock::now())
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void start()
|
void start()
|
||||||
{
|
{
|
||||||
startTime = std::chrono::high_resolution_clock::now();
|
startTime = std::chrono::steady_clock::now();
|
||||||
isRunning = true;
|
isRunning = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void stop()
|
void stop()
|
||||||
{
|
{
|
||||||
const auto now = std::chrono::high_resolution_clock::now();
|
const auto now = std::chrono::steady_clock::now();
|
||||||
duration += std::chrono::duration_cast<std::chrono::microseconds>(now - startTime).count();
|
duration += std::chrono::duration_cast<std::chrono::microseconds>(now - startTime).count();
|
||||||
isRunning = false;
|
isRunning = false;
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,7 @@ class Timer
|
||||||
{
|
{
|
||||||
long durationToShow = duration;
|
long durationToShow = duration;
|
||||||
if (isRunning) {
|
if (isRunning) {
|
||||||
const auto now = std::chrono::high_resolution_clock::now();
|
const auto now = std::chrono::steady_clock::now();
|
||||||
durationToShow +=
|
durationToShow +=
|
||||||
std::chrono::duration_cast<std::chrono::microseconds>(now - startTime).count();
|
std::chrono::duration_cast<std::chrono::microseconds>(now - startTime).count();
|
||||||
}
|
}
|
||||||
|
@ -55,7 +55,7 @@ class Timer
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::chrono::time_point<std::chrono::system_clock> startTime;
|
std::chrono::time_point<std::chrono::steady_clock, std::chrono::nanoseconds> startTime;
|
||||||
|
|
||||||
// Timer are always running when created. You can use .reset() after creation.
|
// Timer are always running when created. You can use .reset() after creation.
|
||||||
bool isRunning = true;
|
bool isRunning = true;
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
#include "core/TodoMd.h"
|
#include "core/TodoMd.h"
|
||||||
#include "cpp-utils/debug.h"
|
#include "cpp-utils/debug.h"
|
||||||
#include <exception>
|
#include <exception>
|
||||||
|
#include <sstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
#include <qjsonarray.h>
|
#include <qjsonarray.h>
|
||||||
|
@ -28,11 +29,7 @@ Backend::Backend() : todoView(&mirai)
|
||||||
QFile loadFile(QDir::homePath() + "/.config/mirai/config.json");
|
QFile loadFile(QDir::homePath() + "/.config/mirai/config.json");
|
||||||
readConfigDuration.printTimeElapsed("Read config duration");
|
readConfigDuration.printTimeElapsed("Read config duration");
|
||||||
|
|
||||||
if (!loadFile.open(QIODevice::ReadOnly)) {
|
if (loadFile.open(QIODevice::ReadOnly)) {
|
||||||
qWarning() << "Couldn't find existing config file";
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
QByteArray loadData = loadFile.readAll();
|
QByteArray loadData = loadFile.readAll();
|
||||||
QJsonDocument json = QJsonDocument::fromJson(loadData);
|
QJsonDocument json = QJsonDocument::fromJson(loadData);
|
||||||
loadFile.close();
|
loadFile.close();
|
||||||
|
@ -62,6 +59,11 @@ Backend::Backend() : todoView(&mirai)
|
||||||
jsonTagsConfig.toObject()[jsonTagConfigKey].toObject()["color"].toString();
|
jsonTagsConfig.toObject()[jsonTagConfigKey].toObject()["color"].toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
qWarning() << "Couldn't find existing config file";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
cpputils::debug::Timer updatingViewDuration;
|
cpputils::debug::Timer updatingViewDuration;
|
||||||
todoView.update();
|
todoView.update();
|
||||||
|
|
146
src/qml/Main.qml
146
src/qml/Main.qml
|
@ -51,123 +51,65 @@ Window {
|
||||||
taskFormPopup.open()
|
taskFormPopup.open()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Component {
|
||||||
|
id: sideMenuComponent
|
||||||
|
SideMenu {
|
||||||
|
id: sideMenu
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Component {
|
||||||
|
id: mainPanelComponent
|
||||||
|
MainPanel {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
RowLayout {
|
RowLayout {
|
||||||
|
id: desktopLayout
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
spacing: 0
|
spacing: 0
|
||||||
|
|
||||||
Rectangle {
|
Loader {
|
||||||
color: MiraiColorPalette.pane
|
sourceComponent: sideMenuComponent
|
||||||
Layout.preferredWidth: childrenRect.width + 20
|
Layout.preferredWidth: item.width
|
||||||
Layout.fillHeight: true
|
Layout.fillHeight: true
|
||||||
|
|
||||||
SideMenu {
|
|
||||||
anchors.top: parent.top
|
|
||||||
anchors.bottom: parent.bottom
|
|
||||||
anchors.left: parent.left
|
|
||||||
anchors.margins: 10
|
|
||||||
}
|
}
|
||||||
}
|
Loader {
|
||||||
|
sourceComponent: mainPanelComponent
|
||||||
Rectangle {
|
|
||||||
color: colorPalette.selected.background
|
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
Layout.fillHeight: true
|
Layout.fillHeight: true
|
||||||
ColumnLayout {
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
SwipeView {
|
||||||
|
id: phoneLayout
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
anchors.margins: 10
|
spacing: 0
|
||||||
spacing: 16
|
|
||||||
|
|
||||||
TabSelector {
|
|
||||||
Layout.fillWidth: true
|
|
||||||
Layout.preferredHeight: childrenRect.height
|
|
||||||
|
|
||||||
tabs: [
|
|
||||||
{
|
|
||||||
label: "Todo",
|
|
||||||
onClick: () => {
|
|
||||||
backend.hideCompletedTasks(true) // Little workaround for now.
|
|
||||||
root.selectedView = "list"
|
|
||||||
},
|
|
||||||
selected: root.selectedView === "list"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: "Calendar",
|
|
||||||
onClick: () => {
|
|
||||||
backend.hideCompletedTasks(false) // Little workaround for now.
|
|
||||||
root.selectedView = "calendar"
|
|
||||||
},
|
|
||||||
selected: root.selectedView === "calendar"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
AppButton {
|
|
||||||
icon.source: "qrc:/qt/qml/Mirai/src/images/add.png"
|
|
||||||
icon.color: colorPalette.selected.palette.green
|
|
||||||
text: "Add task"
|
|
||||||
onClicked: {
|
|
||||||
root.newTask()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Component {
|
|
||||||
id: listViewComponent
|
|
||||||
ListView {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Component {
|
|
||||||
id: calendarViewComponent
|
|
||||||
CalendarView {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Component {
|
|
||||||
id: gettingStartedComponent
|
|
||||||
AppText {
|
|
||||||
text: "You currently have no files loaded, you can add them by clicking on the cog icon on the left pane"
|
|
||||||
anchors.centerIn: parent
|
|
||||||
horizontalAlignment: Text.AlignHCenter
|
|
||||||
verticalAlignment: Text.AlignVCenter
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Loader {
|
Loader {
|
||||||
sourceComponent: backend.tasks.length === 0 ? gettingStartedComponent
|
sourceComponent: sideMenuComponent
|
||||||
: selectedView === "list" ? listViewComponent
|
Layout.preferredWidth: item.width
|
||||||
: selectedView === "calendar" ? calendarViewComponent
|
Layout.fillHeight: true
|
||||||
: undefined
|
}
|
||||||
|
Loader {
|
||||||
|
sourceComponent: mainPanelComponent
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
Layout.fillHeight: true
|
Layout.fillHeight: true
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function setFittingLayout() {
|
||||||
|
if (width > height) {
|
||||||
Popup {
|
desktopLayout.visible = true
|
||||||
id: taskFormPopup
|
phoneLayout.visible = false
|
||||||
width: parent.width * 0.75
|
} else {
|
||||||
implicitHeight: taskForm.height + padding * 2
|
desktopLayout.visible = false
|
||||||
x: Math.round((parent.width - width) / 2)
|
phoneLayout.visible = true
|
||||||
y: Math.round((parent.height * 0.4) / 2)
|
phoneLayout.setCurrentIndex(1)
|
||||||
padding: 8
|
|
||||||
background: Rectangle {
|
|
||||||
border.color: colorPalette.selected.modalBorder
|
|
||||||
border.width: 2
|
|
||||||
color: colorPalette.selected.pane
|
|
||||||
radius: 4
|
|
||||||
}
|
|
||||||
TaskForm {
|
|
||||||
id: taskForm
|
|
||||||
width: parent.width
|
|
||||||
onConfirmed: {
|
|
||||||
taskFormPopup.close()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
onWidthChanged: setFittingLayout()
|
||||||
|
Component.onCompleted: setFittingLayout()
|
||||||
}
|
}
|
||||||
|
|
112
src/qml/MainPanel.qml
Normal file
112
src/qml/MainPanel.qml
Normal file
|
@ -0,0 +1,112 @@
|
||||||
|
/*
|
||||||
|
* Mirai. Copyright (C) 2024 Vyn
|
||||||
|
* This file is licensed under version 3 of the GNU General Public License (GPL-3.0-only)
|
||||||
|
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
||||||
|
*/
|
||||||
|
|
||||||
|
import QtQuick
|
||||||
|
import QtQuick.Window
|
||||||
|
import QtQuick.Controls
|
||||||
|
import QtQuick.Layouts
|
||||||
|
import Mirai
|
||||||
|
|
||||||
|
Rectangle {
|
||||||
|
color: colorPalette.selected.background
|
||||||
|
|
||||||
|
ColumnLayout {
|
||||||
|
anchors.fill: parent
|
||||||
|
anchors.margins: 10
|
||||||
|
spacing: 16
|
||||||
|
|
||||||
|
TabSelector {
|
||||||
|
Layout.fillWidth: true
|
||||||
|
Layout.preferredHeight: childrenRect.height
|
||||||
|
|
||||||
|
tabs: [
|
||||||
|
{
|
||||||
|
label: "Todo",
|
||||||
|
onClick: () => {
|
||||||
|
backend.hideCompletedTasks(true) // Little workaround for now.
|
||||||
|
root.selectedView = "list"
|
||||||
|
},
|
||||||
|
selected: root.selectedView === "list"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: "Calendar",
|
||||||
|
onClick: () => {
|
||||||
|
backend.hideCompletedTasks(false) // Little workaround for now.
|
||||||
|
root.selectedView = "calendar"
|
||||||
|
},
|
||||||
|
selected: root.selectedView === "calendar"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
AppButton {
|
||||||
|
icon.source: "qrc:/qt/qml/Mirai/src/images/add.png"
|
||||||
|
icon.color: colorPalette.selected.palette.green
|
||||||
|
text: "Add task"
|
||||||
|
onClicked: {
|
||||||
|
root.newTask()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Component {
|
||||||
|
id: listViewComponent
|
||||||
|
ListView {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Component {
|
||||||
|
id: calendarViewComponent
|
||||||
|
CalendarView {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Component {
|
||||||
|
id: gettingStartedComponent
|
||||||
|
AppText {
|
||||||
|
text: "You currently have no files loaded, you can add them by clicking on the cog icon on the left pane"
|
||||||
|
anchors.centerIn: parent
|
||||||
|
horizontalAlignment: Text.AlignHCenter
|
||||||
|
verticalAlignment: Text.AlignVCenter
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Loader {
|
||||||
|
sourceComponent: backend.tasks.length === 0 ? gettingStartedComponent
|
||||||
|
: selectedView === "list" ? listViewComponent
|
||||||
|
: selectedView === "calendar" ? calendarViewComponent
|
||||||
|
: undefined
|
||||||
|
Layout.fillWidth: true
|
||||||
|
Layout.fillHeight: true
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Popup {
|
||||||
|
id: taskFormPopup
|
||||||
|
width: parent.width * 0.75
|
||||||
|
implicitHeight: taskForm.height + padding * 2
|
||||||
|
x: Math.round((parent.width - width) / 2)
|
||||||
|
y: Math.round((parent.height * 0.4) / 2)
|
||||||
|
padding: 8
|
||||||
|
background: Rectangle {
|
||||||
|
border.color: colorPalette.selected.modalBorder
|
||||||
|
border.width: 2
|
||||||
|
color: colorPalette.selected.pane
|
||||||
|
radius: 4
|
||||||
|
}
|
||||||
|
TaskForm {
|
||||||
|
id: taskForm
|
||||||
|
width: parent.width
|
||||||
|
onConfirmed: {
|
||||||
|
taskFormPopup.close()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -10,8 +10,16 @@ import QtQuick.Layouts
|
||||||
import QtQuick.Controls
|
import QtQuick.Controls
|
||||||
import Mirai
|
import Mirai
|
||||||
|
|
||||||
ColumnLayout {
|
Rectangle {
|
||||||
|
|
||||||
|
color: MiraiColorPalette.pane
|
||||||
|
implicitWidth: childrenRect.width + 20
|
||||||
|
|
||||||
|
ColumnLayout {
|
||||||
|
anchors.top: parent.top
|
||||||
|
anchors.bottom: parent.bottom
|
||||||
|
anchors.left: parent.left
|
||||||
|
anchors.margins: 10
|
||||||
RowLayout {
|
RowLayout {
|
||||||
AppText {
|
AppText {
|
||||||
text: "Files"
|
text: "Files"
|
||||||
|
@ -176,4 +184,5 @@ ColumnLayout {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue