diff --git a/qml/pages/MainPage.qml b/qml/pages/MainPage.qml index 619a11a..bcff413 100644 --- a/qml/pages/MainPage.qml +++ b/qml/pages/MainPage.qml @@ -23,8 +23,8 @@ Page { readonly property real defaultStrokeSize: 5 readonly property real defaultRubberSize: 20 - readonly property string defaultStrokeColor: "#000000" - readonly property string defaultFillColor: "#ffffff" + readonly property color defaultStrokeColor: Qt.rgba(0, 0, 0, 1) + readonly property color defaultFillColor: Qt.rgba(1, 1, 1, 1) Column { anchors.fill: parent @@ -49,7 +49,7 @@ Page { property real prevLineWidth: defaultRubberSize; onCheckedChanged: { - if (canvas.strokeStyle === defaultStrokeColor) { + if (canvas.strokeStyle == defaultStrokeColor) { icon.source = "image://theme/icon-camera-focus" canvas.strokeStyle = defaultFillColor; } else { @@ -71,7 +71,7 @@ Page { stepSize: 1 value: defaultStrokeSize valueText: value - width: 300 + width: 240 anchors.verticalCenter: parent.verticalCenter @@ -84,16 +84,38 @@ Page { } } + IconButton { + icon.source: "image://theme/icon-m-image" + anchors.verticalCenter: parent.verticalCenter + + function pictureName() { + var dateTime = new Date(); + return Qt.formatDateTime(dateTime, "yyyy-MM-dd-hh-mm-ss") + ".jpeg"; + } + + onClicked: { + remorseSave.execute(menu, qsTr("Saving the canvas..."), function() { + canvas.save(papocchioDir + pictureName()); + }, 3000); + } + + RemorseItem { + id: remorseSave + } + } + IconButton { icon.source: "image://theme/icon-m-clear" anchors.verticalCenter: parent.verticalCenter onClicked: { - clear.execute(menu, qsTr("Clearing the canvas..."), function() { canvas.clear() }); + remorseClear.execute(menu, qsTr("Clearing the canvas..."), function() { + canvas.clear(); + }); } RemorseItem { - id: clear + id: remorseClear } } } @@ -112,21 +134,31 @@ Page { property int finishX property int finishY + property bool initialize: true + property real lineWidth: defaultStrokeSize property string strokeStyle: defaultStrokeColor onLineWidthChanged: requestPaint() - function clear() - { + function clear() { var ctx = getContext("2d"); + ctx.fillStyle = defaultFillColor; ctx.fillRect(0, 0, width, height); requestPaint(); } onPaint: { var ctx = getContext("2d"); - ctx.fillStyle = defaultFillColor; + + // The context is not available in Component.onCompleted + // then we have to use a "exec-once workaround" to init + // the canvas background + if (initialize) { + clear(); + initialize = false; + } + ctx.lineCap = "round"; ctx.lineJoin = "round"; ctx.lineWidth = lineWidth; diff --git a/src/main.cpp b/src/main.cpp index 9483eca..6cc733f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -20,6 +20,8 @@ #include +QString papocchioDir(); + int main(int argc, char *argv[]) { QGuiApplication *app = SailfishApp::application(argc, argv); @@ -31,8 +33,26 @@ int main(int argc, char *argv[]) view->setSource(SailfishApp::pathTo("qml/Papocchio.qml")); view->setPersistentOpenGLContext(true); view->setPersistentSceneGraph(true); + + view->rootContext()->setContextProperty("papocchioDir", papocchioDir()); + view->show(); return app->exec(); } +/** + * @brief papocchioDir just to be sure the directory where to save pictures + * exists. + * @return the path to the directory where to save pictures. + */ +QString papocchioDir() +{ + QDir papocchioDir(QDir::homePath() + "/Pictures/Papocchio"); + + if (!papocchioDir.exists()) { + papocchioDir.mkpath(papocchioDir.absolutePath()); + } + + return QString(papocchioDir.absolutePath() + "/"); +} diff --git a/translations/harbour-papocchio.ts b/translations/harbour-papocchio.ts index a9478ea..83252a6 100644 --- a/translations/harbour-papocchio.ts +++ b/translations/harbour-papocchio.ts @@ -12,7 +12,12 @@ MainPage - + + Saving the canvas... + + + + Clearing the canvas...