Main.qml Example File
declarative-sfw-notes/content-sfw-notes/Main.qml
import Qt 4.7
import QtMobility.serviceframework 1.1
Rectangle {
id: mainWindow
property int size: 0
property int curr: 0
property double screenScale: 1
property string searchText: ""
property bool validService: false
property alias screenWidth: mainWindow.width
property alias screenHeight: mainWindow.height
property alias screenColor: mainWindow.color
property variant notesManager: 0
SystemPalette { id: activePalette; colorGroup: SystemPalette.Active }
Text {
id: title
text: "ToDoTool"
font.pointSize: 24 * screenScale; font.family: "Nimbus Roman No9 L"; font.bold: true; font.italic:true
color: "blue"
y: 5;
anchors.horizontalCenter: mainWindow.horizontalCenter
}
Button {
id: addButton
image: "icons/addIcon.png"
width: mainWindow.width * 3/11
height: mainWindow.height * 6/53
anchors.right: deleteButton.left;
anchors.top: title.bottom; anchors.topMargin: 10
onClicked: {
if (validService) {
addDialog.opacity = 1;
enableScreen(false);
}
}
}
Button {
id: deleteButton
image: "icons/deleteIcon.png"
width: mainWindow.width * 3/11
height: mainWindow.height * 6/53
anchors.horizontalCenter: mainWindow.horizontalCenter
anchors.top: title.bottom; anchors.topMargin: 10
onClicked: {
if (validService && size > 0) {
deleteDialog.opacity = 1;
enableScreen(false);
}
}
}
Button {
id: searchButton
image: "icons/searchIcon.png"
width: mainWindow.width * 3/11
height: mainWindow.height * 6/53
anchors.left: deleteButton.right;
anchors.top: title.bottom; anchors.topMargin: 10
onClicked: {
if (validService) {
searchDialog.opacity = 1;
enableScreen(false);
}
}
}
Button {
id: nextButton
image: "icons/nextIcon.png"
width: mainWindow.width * 2/11;
height: mainWindow.height * 6/53
anchors.left: countLabel.right;
anchors.top: deleteButton.bottom; anchors.topMargin: 10
onClicked: {
if (validService && curr < size) {
curr++;
refreshNotes();
}
}
}
Button {
id: prevButton
image: "icons/prevIcon.png"
width: mainWindow.width * 2/11;
height: mainWindow.height * 6/53
anchors.right: countLabel.left;
anchors.top: deleteButton.bottom; anchors.topMargin: 10
onClicked: {
if (validService && curr > 1) {
curr--;
refreshNotes();
}
}
}
Text {
id: countLabel
text: curr + "/" + size
font.pointSize: 10 * screenScale
color: activePalette.text
width: mainWindow.width * 2/11;
horizontalAlignment: Text.AlignHCenter
anchors.horizontalCenter: mainWindow.horizontalCenter
anchors.verticalCenter: prevButton.verticalCenter
}
Rectangle {
id: datetimeArea
width: mainWindow.width * 8/11
height: mainWindow.height * 4/53
color: "#FFFF7F"
anchors.horizontalCenter: mainWindow.horizontalCenter
anchors.top: prevButton.bottom; anchors.topMargin: 10
}
Rectangle {
id: noteArea
width: mainWindow.width * 8/11
height: mainWindow.height * 22/53
color: "#FFFF7F"
anchors.horizontalCenter: mainWindow.horizontalCenter
anchors.top: datetimeArea.bottom;
}
Text {
id: datetimeLabel
text: ""
font.pointSize: 10 * screenScale
anchors.right: datetimeArea.right
anchors.top: datetimeArea.top
}
Text {
id: noteLabel
text: ""
font.pointSize: 18 * screenScale; font.family: "Comic Sans MS"; font.italic:true
horizontalAlignment: Text.AlignHCenter
wrapMode: Text.Wrap
width: noteArea.width
anchors.verticalCenter: noteArea.verticalCenter
anchors.horizontalCenter: title.horizontalCenter
}
InputDialog {
id: interfaceDialog
text: "Specify Notes Manager Interface"
defaultText: "com.nokia.qt.examples.NotesManager"
cancelable: false
opacity: 1
onConfirmed: {
interfaceDialog.defaultText = input;
notesService.interfaceName = input;
if (notesService.valid) {
notesManager = notesService.serviceObject;
notesManager.init();
var list = notesManager.noteSet;
if (list.length > 0) {curr = 1;}
refreshNotes();
validService = true;
enableScreen(true);
} else {
invalidDialog.opacity = 1;
noteLabel.text = "Notes Manager service not found";
addButton.color = "gray";
deleteButton.color = "gray";
searchButton.color = "gray";
nextButton.color = "gray";
prevButton.color = "gray";
}
}
Component.onCompleted: { enableScreen(false); }
}
InputDialog {
id: addDialog
text: "Add a new note + alarm of format:\nnote#yyyy-mm-dd#hh:mm"
onConfirmed: {
var note = input.split("#");
if (note.length == 3) {
var date = note[1].split("-");
var time = note[2].split(":");
if (date.length == 3 && time.length ==2) {
notesManager.addNote(note[0], note[1] + " " + note[2] + ":00");
}
} else {
notesManager.addNote(note[0], currentDateTime() + ":00");
}
refreshNotes();
}
}
InputDialog {
id: searchDialog
text: "Find a note:"
size: 100
onConfirmed: {
searchText = input;
curr = 1;
refreshNotes()
}
}
Dialog {
id: deleteDialog
text: "Confirm removing this note item?"
onConfirmed: {
var list = notesManager.noteSet;
notesManager.removeNote(list[curr-1].index);
if (curr > 1) { curr--; }
refreshNotes();
}
}
Dialog {
id: alarmDialog
text: "ALERT SOUNDED!!!"
cancelable: false
}
Dialog {
id: invalidDialog
text: "No valid default interface for:\n\n\"" + interfaceDialog.defaultText + "\""
cancelable: false
}
Dialog {
id: unconnectedDialog
text: "Unable to connect to notes manager database\n in current or home directory"
cancelable: false
}
function refreshNotes()
{
notesManager.setSearch(searchText);
var list = notesManager.noteSet;
size = list.length;
if (size < 1) curr = 0;
else if (size > 0 && curr == 0) curr = 1;
if (size > 0) {
noteLabel.text = list[curr-1].message;
datetimeLabel.text = formatDateTime(list[curr-1].alarm);
}
else {
noteLabel.text = "Click + to add a new note";
datetimeLabel.text = "";
}
}
function formatDateTime(datetime)
{
var dt = new Date(datetime);
var month = (dt.getMonth() + 1) + "";
if (month.length == 1) month = "0" + month;
var date = dt.getDate() + "";
if (date.length == 1) date= "0" + date;
var hour = dt.getHours() + "";
if (hour.length == 1) hour = "0" + hour;
var mins = dt.getMinutes() + "";
if (mins.length == 1) mins = "0" + mins;
return (dt.getFullYear() + "-" + month + "-" + date + " " + hour + ":" + mins);
}
function currentDateTime()
{
var dt = new Date();
return formatDateTime(dt);
}
function enableScreen(enable)
{
addButton.enableButton = enable;
deleteButton.enableButton = enable;
searchButton.enableButton = enable;
nextButton.enableButton = enable;
prevButton.enableButton = enable;
}
Service {
id: notesService
interfaceName: "com.nokia.qt.examples.NotesManager"
Component.onCompleted: {
notesManager = notesService.serviceObject;
}
}
Connections {
target: notesManager
ignoreUnknownSignals: true
onSoundAlarm: {
alarmDialog.text = "ALERT SOUNDED!!!" + "\n\n" +
formatDateTime(alarm) + "\n\n" + notesManager.alarmMessage;
alarmDialog.opacity = 1;
}
}
}
[+] Documentation Feedback