~snwh/sudoku-app/new-icons

« back to all changes in this revision

Viewing changes to sudoku-app.qml

  • Committer: dinko.metalac at gmail
  • Date: 2013-07-09 09:54:46 UTC
  • mfrom: (62.2.4 profiles)
  • Revision ID: dinko.metalac@gmail.com-20130709095446-u9smezoot4td0kxd
MergedĀ lp:~fredoust/sudoku-app/profiles

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
import Ubuntu.Components 0.1
3
3
import Ubuntu.Components.ListItems 0.1 as ListItem
4
4
import QtQuick.LocalStorage 2.0
 
5
import Ubuntu.Components.Popups 0.1
5
6
import "js/localStorage.js" as Settings
6
7
import "components"
7
8
 
17
18
    property real blockDistance: pageWidth/200;
18
19
    property bool alreadyCreated: false;
19
20
    property bool gridLoaded: false;
20
 
    property int currentUserId: 1;
 
21
    property int currentUserId: -1;
21
22
    property string highscoresHeaderText: i18n.tr("<b>Best scores for all players</b>")
22
23
 
 
24
    property string alertTitle: ""
 
25
    property string alertText : ""
 
26
 
 
27
    property int editUserId : -1;
 
28
 
23
29
    width: pageWidth;
24
30
    height: pageHeight;
25
31
 
 
32
    onCurrentUserIdChanged: {
 
33
        Settings.setSetting("currentUserId", currentUserId)
 
34
    }
 
35
 
26
36
    function newSize(width, height) {
27
37
        pageWidth = width;
28
38
        pageHeight = height;
58
68
        //buttonsGridPublic.update();
59
69
    }
60
70
 
 
71
 
 
72
    Component {
 
73
        id: alertDialog
 
74
        Dialog {
 
75
            id: alertDialogue
 
76
            title: alertTitle
 
77
            text: alertText
 
78
 
 
79
            SudokuDialogButton{
 
80
                buttonText: i18n.tr("OK")
 
81
                width: parent.width/2;
 
82
                size: units.gu(5)
 
83
                onTriggered: {
 
84
                    PopupUtils.close(alertDialogue)
 
85
                }
 
86
            }
 
87
 
 
88
        }
 
89
    }
 
90
 
 
91
    function showAlert(title, text, caller)
 
92
    {
 
93
        alertTitle = title
 
94
        alertText = text
 
95
        PopupUtils.open(alertDialog, caller)
 
96
 
 
97
    }
 
98
 
 
99
 
 
100
 
61
101
    onHeightChanged: {
62
102
        if (!gridLoaded)
63
103
            return;
98
138
                                       'lastname':  lastName,
99
139
                                       'score': rowItem[1] });
100
140
        }
 
141
 
 
142
        if(Settings.getSetting("currentUserId")=="Unknown")
 
143
            currentUserId = -1;
 
144
        else
 
145
        {
 
146
            currentUserId = Settings.getSetting("currentUserId")
 
147
        }
 
148
 
101
149
    }
102
150
 
103
151
    Tabs {
259
307
                    SudokuBlocksGrid {
260
308
                        id: sudokuBlocksGrid;
261
309
                    }
 
310
 
262
311
                }
263
312
            }
264
313
 
364
413
            property alias difficultyIndex: difficultySelector.selectedIndex;
365
414
            property alias themeIndex: themeSelector.selectedIndex;
366
415
 
 
416
 
 
417
 
367
418
            title: i18n.tr("Settings")
368
 
            page: Page {
369
 
                /*
370
 
                tools: ToolbarActions {
371
 
 
372
 
                    Action {
373
 
                        iconSource: Qt.resolvedUrl("icons/close.svg")
374
 
                        text: i18n.tr("Close");
375
 
                        onTriggered: Qt.quit()
376
 
                    }
377
 
                }
378
 
                */
 
419
            page:
 
420
 
 
421
                Page {
 
422
 
379
423
                Column {
 
424
 
 
425
                    Component {
 
426
                        id: profileSelector
 
427
                        DefaultSheet {
 
428
                            title: i18n.tr("Select profile")
 
429
                            contentsHeight: mainView.height
 
430
 
 
431
                            /*
 
432
                            Column {
 
433
                                anchors {
 
434
                                    top: parent.top
 
435
                                    left: parent.left
 
436
                                    right: parent.right
 
437
                                }
 
438
                                height: mainColumnSettings.height
 
439
 
 
440
                                ListItem.Header {
 
441
                                    id: header
 
442
                                    text: i18n.tr("Select profile")
 
443
                                }
 
444
                                */
 
445
 
 
446
 
 
447
 
 
448
                            ListView {
 
449
                                height: mainColumnSettings.height
 
450
                                id: profileListView
 
451
                                clip: true
 
452
                                width: parent.width
 
453
                                // height: parent.height - header.height
 
454
                                model: profilesModel
 
455
 
 
456
                                delegate:
 
457
                                    ListItem.Standard {
 
458
 
 
459
                                    text: firstname + " " + lastname
 
460
                                    progression: true
 
461
                                    onTriggered: {
 
462
                                        console.log("clicked "+index)
 
463
                                        currentUserId = profileId;
 
464
                                        hide()
 
465
                                    }
 
466
                                }
 
467
 
 
468
                            }
 
469
                        }
 
470
                        // }
 
471
                    }
 
472
 
 
473
                    Component {
 
474
                        id: manageProfileSelector
 
475
                        DefaultSheet {
 
476
                            title: i18n.tr("Select profile")
 
477
                            contentsHeight: mainView.height
 
478
 
 
479
 
 
480
 
 
481
                                ListView {
 
482
                                    id: manageProfileListView
 
483
                                    clip: true
 
484
                                    width: parent.width
 
485
                                  height: mainColumnSettings.height
 
486
                                    model: profilesModel
 
487
 
 
488
                                    delegate:
 
489
 
 
490
                                        ListItem.Standard {
 
491
 
 
492
                                            text: firstname + " " + lastname
 
493
 
 
494
                                            progression: true
 
495
                                            onTriggered: {
 
496
                                                hide()
 
497
                                                editUserId = profileId
 
498
                                                PopupUtils.open(manageProfileDialog, selectorProfile)
 
499
                                            }
 
500
                                        }
 
501
 
 
502
 
 
503
 
 
504
                            }
 
505
                        }
 
506
                    }
 
507
 
 
508
                    ListModel{
 
509
                        id: profilesModel
 
510
                    }
 
511
 
380
512
                    id: mainColumnSettings;
381
513
                    //width: settingsTab.width;
382
514
                    //height: settingsTab.height;
460
592
                            }
461
593
                        }
462
594
                    }
 
595
                    ListItem.Header {
 
596
                        text: i18n.tr("<b>Profiles settings</b>")
 
597
                    }
 
598
                    ListItem.SingleValue {
 
599
                        text: "Current profile"
 
600
                        id: selectorProfile
 
601
                        value: {
 
602
                            if(currentUserId==-1)
 
603
                                return i18n.tr("None")
 
604
                            else
 
605
                                return Settings.getUserFirstName(currentUserId)+" "+Settings.getUserLastName(currentUserId);
 
606
 
 
607
                        }
 
608
 
 
609
                        onClicked: {
 
610
 
 
611
                            var allProfiles = new Array();
 
612
                            allProfiles = Settings.getAllProfiles()
 
613
 
 
614
                            profilesModel.clear()
 
615
 
 
616
                            for(var i = 0; i < allProfiles.length; i++)
 
617
                            {
 
618
                                profilesModel.append({"profileId":allProfiles[i].id,"lastname":allProfiles[i].lastname, "firstname":allProfiles[i].firstname})
 
619
                            }
 
620
                            PopupUtils.open(profileSelector, selectorProfile)
 
621
                        }
 
622
                    }
 
623
 
 
624
                    AddProfileDialog{
 
625
                        id:addProfileDialog
 
626
                    }
 
627
 
 
628
                    ManageProfileDialog{
 
629
                        id:manageProfileDialog
 
630
                    }
 
631
 
 
632
 
 
633
                    ListItem.SingleValue {
 
634
                        id:addSingleValue
 
635
                        text: i18n.tr("Add profile")
 
636
                        onClicked: {
 
637
                            PopupUtils.open(addProfileDialog, addSingleValue);
 
638
                        }
 
639
                    }
 
640
 
 
641
                    ListItem.SingleValue {
 
642
                        id:manageProfileSingleValue
 
643
                        text: i18n.tr("Manage profiles")
 
644
                        onClicked: {
 
645
 
 
646
                            var allProfiles = new Array();
 
647
                            allProfiles = Settings.getAllProfiles()
 
648
 
 
649
                            profilesModel.clear()
 
650
 
 
651
                            for(var i = 0; i < allProfiles.length; i++)
 
652
                            {
 
653
                                profilesModel.append({"profileId":allProfiles[i].id,"lastname":allProfiles[i].lastname, "firstname":allProfiles[i].firstname})
 
654
                            }
 
655
 
 
656
                            PopupUtils.open(manageProfileSelector, manageProfileSingleValue)
 
657
                        }
 
658
                    }
 
659
 
 
660
 
463
661
                }
464
662
            }
465
663
 
 
664
 
466
665
        }
467
666
 
468
667
        Tab {
470
669
            objectName: "aboutTab"
471
670
            title: i18n.tr("About")
472
671
            page: Page {
473
 
                /*
474
 
                tools: ToolbarActions {
475
 
 
476
 
 
477
 
                    Action {
478
 
                        iconSource: Qt.resolvedUrl("icons/close.svg");
479
 
                        text: i18n.tr("Close");
480
 
                        onTriggered: Qt.quit()
481
 
                    }
482
 
 
483
 
                }
484
 
                */
 
672
 
485
673
                Column {
486
674
                    id: aboutColumn;
487
675
                    spacing: 5;
489
677
                    anchors.horizontalCenter: parent.horizontalCenter;
490
678
                    y: units.gu(8);
491
679
                    Image {
492
 
                            property real maxWidth: units.gu(100)
493
 
                            anchors.horizontalCenter: parent.horizontalCenter
494
 
                            width: Math.min(mainView.width, maxWidth)/1.75
495
 
                            //height: width
496
 
                            source: "icons/sudoko-vector-about.svg"
497
 
                            smooth: true
498
 
                            fillMode: Image.PreserveAspectFit
 
680
                        property real maxWidth: units.gu(100)
 
681
                        anchors.horizontalCenter: parent.horizontalCenter
 
682
                        width: Math.min(mainView.width, maxWidth)/1.75
 
683
                        //height: width
 
684
                        source: "icons/sudoko-vector-about.svg"
 
685
                        smooth: true
 
686
                        fillMode: Image.PreserveAspectFit
499
687
 
500
 
                        }
 
688
                    }
501
689
                    Row {
502
690
                        //anchors.horizontalCenter: parent.horizontalCenter;
503
691
                        anchors.left: aboutColumn.left