Skip to content

Commit

Permalink
Add a modrana context property, fix theme errors at startup
Browse files Browse the repository at this point in the history
The modrana context property exposes core modRana functionality to QML. Currently, it has mode and theme properties that can be used for bindings and also to set the mode and theme in the modRana core. also all rWin.theme calls were replaced by modrana.theme, which fixes quite a few errors reported in the startup log.
  • Loading branch information
M4rtinK committed Mar 24, 2013
1 parent b9e117c commit a76dcf7
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 16 deletions.
47 changes: 47 additions & 0 deletions modules/gui_modules/gui_qml/gui_qml.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ def closeEvent(self, event):
self.view.engine().addImageProvider("tiles", self.tilesProvider)

rc = self.view.rootContext()
# make core modRana functionality accessible from QML
modRanaCore = ModRana(self.modrana)
rc.setContextProperty("modrana", modRanaCore)
# make options accessible from QML
options = Options(self.modrana)
rc.setContextProperty("options", options)
Expand Down Expand Up @@ -697,6 +700,50 @@ def _gps_mode(self):
mode = QtCore.Property(str, _gps_mode, notify=changed)


class ModRana(QtCore.QObject):
"""
core modRana functionality
"""

def __init__(self, modrana):
QtCore.QObject.__init__(self)
self.modrana = modrana
self.modrana.watch("mode", self._modeChangedCB)
self.modrana.watch("theme", self._themeChangedCB)

# mode

def _getMode(self):
return self.modrana.get('mode', "car")

def _setMode(self, mode):
self.modrana.set('mode', mode)

modeChanged = Signal()

def _modeChangedCB(self, *args):
"""notify when the mode key changes in options"""
self.modeChanged.emit()

# theme

def _getTheme(self):
return self.modrana.get('theme', "default")

def _setTheme(self, newTheme):
return self.modrana.set('theme', newTheme)

themeChanged = Signal()

def _themeChangedCB(self, *args):
"""notify when the mode key changes in options"""
self.themeChanged.emit()

# properties

mode = QtCore.Property(str, _getMode, _setMode, notify=modeChanged)
theme = QtCore.Property(str, _getTheme, _setTheme, notify=themeChanged)

class Options(QtCore.QObject):
"""make options available to QML and integrable as a property"""

Expand Down
2 changes: 1 addition & 1 deletion modules/gui_modules/gui_qml/ic/BasePage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ Page {
anchors.topMargin : 8
anchors.leftMargin : 16
iconName : "left_thin.png"
//iconSource : "image://icons/"+ rWin.mTheme +"/back_small.png"
//iconSource : "image://icons/"+ modrana.theme +"/back_small.png"
opacity : pageFlickable.atYBeginning ? 1.0 : 0.55
onClicked : {
rWin.pageStack.pop()
Expand Down
2 changes: 1 addition & 1 deletion modules/gui_modules/gui_qml/ic/BitcoinButton.qml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ Rectangle {
anchors.top : dialogContent.top
anchors.topMargin : 8
anchors.horizontalCenter : parent.horizontalCenter
source : "image://icons/" + rWin.mTheme + "/qrcode_bitcoin.png"
source : "image://icons/" + modrana.theme + "/qrcode_bitcoin.png"
}
TextInput {
id : urlField
Expand Down
2 changes: 1 addition & 1 deletion modules/gui_modules/gui_qml/ic/InfoAboutPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ BasePage {
anchors.horizontalCenter : parent.horizontalCenter
anchors.topMargin : 16
anchors.top : aboutTitle.bottom
source : "image://icons/"+ rWin.mTheme +"/modrana.svg"
source : "image://icons/"+ modrana.theme +"/modrana.svg"
}

Label {
Expand Down
14 changes: 7 additions & 7 deletions modules/gui_modules/gui_qml/ic/MapPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ Item {
/* TODO: investigate how to replace this by an image loader
what about rendered size ?
*/
source: "../../../../themes/"+ rWin.mTheme +"/windrose-simple.svg"
source: "../../../../themes/"+ modrana.theme +"/windrose-simple.svg"
transform: [Rotation {
id: azCompass
origin.x: compassImage.width/2
Expand All @@ -123,7 +123,7 @@ Item {
/* TODO: investigate how to replace this by an image loader
what about rendered size ?
*/
source: "../../../../themes/"+ rWin.mTheme +"/arrow_target.svg"
source: "../../../../themes/"+ modrana.theme +"/arrow_target.svg"
width: (compassImage.paintedWidth / compassImage.sourceSize.width)*sourceSize.width
fillMode: Image.PreserveAspectFit
x: compassImage.width/2 - width/2
Expand All @@ -145,15 +145,15 @@ Item {
anchors.rightMargin: 16
spacing: 16
Button {
iconSource: "image://icons/" + rWin.mTheme + "/" + "plus_small.png"
iconSource: "image://icons/" + modrana.theme + "/" + "plus_small.png"
onClicked: {pinchmap.zoomIn() }
width: parent.parent.buttonSize
height: parent.parent.buttonSize
enabled : pinchmap.zoomLevel != pinchmap.maxZoomLevel
//text : "<h1>+</h1>"
}
Button {
iconSource: "image://icons/" + rWin.mTheme + "/" + "minus_small.png"
iconSource: "image://icons/" + modrana.theme + "/" + "minus_small.png"
onClicked: {pinchmap.zoomOut() }
width: parent.parent.buttonSize
height: parent.parent.buttonSize
Expand All @@ -170,7 +170,7 @@ Item {
anchors.leftMargin: 16
spacing: 16
Button {
iconSource: "image://icons/" + rWin.mTheme + "/" + "minimize_small.png"
iconSource: "image://icons/" + modrana.theme + "/" + "minimize_small.png"
checkable : true
visible: !platform.fullscreenOnly()
onClicked: {
Expand All @@ -181,7 +181,7 @@ Item {
}
Button {
id: followPositionButton
iconSource: "image://icons/" + rWin.mTheme + "/" + "center_small.png"
iconSource: "image://icons/" + modrana.theme + "/" + "center_small.png"
width: parent.parent.buttonSize
height: parent.parent.buttonSize
checked : tabMap.center
Expand All @@ -204,7 +204,7 @@ Item {
}
Button {
id: mainMenuButton
iconSource: "image://icons/" + rWin.mTheme + "/" + "menu_small.png"
iconSource: "image://icons/" + modrana.theme + "/" + "menu_small.png"
width: parent.parent.buttonSize
height: parent.parent.buttonSize
onClicked: {
Expand Down
2 changes: 1 addition & 1 deletion modules/gui_modules/gui_qml/ic/ModeMenuPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ IconGridPage {
isMockup : false

function getPage(menu){
options.set('mode', menu)
modrana.mode = menu
rWin.push(null)
}

Expand Down
8 changes: 4 additions & 4 deletions modules/gui_modules/gui_qml/ic/PinchMap.qml
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ Rectangle {
function tileUrl(layerID, tx, ty) {
//console.log("tileUrl" + tx + "/" + ty)
if (ty < 0 || ty > maxTileNo) {
return "image://icons/"+ rWin.mTheme +"/noimage.png"
return "image://icons/"+ modrana.theme +"/noimage.png"
} else {
if (tileserverPort != 0) {
return "http://127.0.0.1:"+tileserverPort+"/"+layerID+"/"+zoomLevel+"/"+tx+"/"+ty+".png"
Expand Down Expand Up @@ -413,7 +413,7 @@ Rectangle {
}
Image {
id: targetIndicator
source: "image://icons/"+ rWin.mTheme +"/target-indicator-cross.png"
source: "image://icons/"+ modrana.theme +"/target-indicator-cross.png"
property variant t: getMappointFromCoord(showTargetAtLat, showTargetAtLon)
x: map.x + t[0] - width/2
y: map.y + t[1] - height/2
Expand Down Expand Up @@ -444,8 +444,8 @@ Rectangle {
id: positionIndicator

source: currentPositionValid ?
"image://icons/"+ rWin.mTheme +"/position-indicator.png" :
"image://icons/"+ rWin.mTheme +"/position-indicator-red.png"
"image://icons/"+ modrana.theme +"/position-indicator.png" :
"image://icons/"+ modrana.theme +"/position-indicator-red.png"
property variant t: getMappointFromCoord(currentPositionLat, currentPositionLon)
x: map.x + t[0] - width/2
y: map.y + t[1] - height + positionIndicator.width/2
Expand Down
2 changes: 1 addition & 1 deletion modules/gui_modules/gui_qml/ic/TIcon.qml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Image {
// TODO: proper slash,backslash,qUrl handling ?

// handle place-holders
source : iconName == "" ? "" : "image://icons/" + rWin.mTheme + "/" + iconName
source : iconName == "" ? "" : "image://icons/" + modrana.theme + "/" + iconName
fillMode : Image.PreserveAspectFit
smooth : true
}

0 comments on commit a76dcf7

Please sign in to comment.