SlideShare ist ein Scribd-Unternehmen logo
1 von 15
Platform and device-specific settings for your QML layouts Artem Marchenko October 8, 2011 After Easy Discount Calculator by Artem Marchenko, JarmoParkkinen, TuukkaLindroos and Ekaterina Kuts Technical solution by Artem Marchenko and TuukkaLindroos
Artem Marchenko Product Manager, Agile Coach, QML engineer for hire Was a Product Manager shipping multi-hundred MEur products Three times Forum Nokia Champion Private entrepreneur Available for hire for all things QML http://fi.linkedin.com/in/artemmarchenko
Same app running on Harmattan, Android and Symbian
Easy Discount Calculator Symbian, MeeGo/Harmattan - http://store.ovi.com/content/186742 Android - http://bit.ly/discountcalculator Free, but has font issues on some models due to porting technology bug. Well working proof of concept for now
All the parameters can be fine-tuned on desktop
Settings system // SettingsBase.QML import Qt 4.7 import "GlobalSettings.js" as Js QtObject {     id: settingsObject // logical switches/conditions     property boolexitButtonPresent: true     property boolclearButtonIsBetweenTheLines: true     // element sizes     property introllerHeight: 110     property intdigitRollerWidth: 56     property intpercentageRollerWidth: digitRollerWidth
Settings system // SettingsMaemo.qml import Qt 4.7 SettingsBase {     property string platformTitle: "Maemo"     property intscreenWidthInPortrait:  480 ...     property introllerHeight: 160     property introllerNumberLineInnerSpacing:  0     property int digitRollerWidth:69 statusLineHeight: 0
Tree of settings
Using platform settings in JS //GlobalSettings.js .pragma library   // - the only QML possibility for global variables varglobalSettings = null // Will fetch the settings object from the item. If the settings object doesn't // exists, will return the global one or generate one on the fly based on base settings.  function getSettings(item) { …  if(item.settings) {         if(!globalSettings) { globalSettings = item.settings         } if(!globalSettings) { var component = Qt.createComponent("SettingsBase.qml") globalSettings = component.createObject(item)     }     return globalSettings;
Using Settings in QML // SmallButton.qml import Qt 4.7 import "GlobalSettings.js" as Js Rectangle {     id: button     width: Js.getSettings(button).smallButtonWidth     height: Js.getSettings(button).smallButtonHeight     radius: 3
Injecting Settings from C++ QStringsettingsPath = "qml/discountcalcui/Settings" + platformTitle + ".qml"; // localAdjustPath cares about platform-specific file location details settingsUrl = QUrl::fromLocalFile(CrossPlatformUtils::localAdjustPath(settingsPath)); QDeclarativeComponent component(view.engine(), settingsUrl); settingsInstance = component.create(); if(!settingsInstance) {           // No settings found - no object to install qWarning() << "Settings not found for this platform!"; qWarning() << component.errorString(); } else { settingsInstance->setProperty("shouldInitializeGlobalSettingWithItself", true); view.engine()->rootContext()->setContextProperty("forcedSettings”, settingsInstance);     } // continue with normal QML initialization
JavaScript side of initialization //SettingsBase.qml import Qt 4.7 import "GlobalSettings.js" as Js QtObject {     id: settingsObject     property boolshouldInitializeGlobalSettingWithItself: false // Is executed way before main QML file is loaded onShouldInitializeGlobalSettingWithItselfChanged: {         if(shouldInitializeGlobalSettingWithItself) { console.log("SBase: initializing global settings with " + settingsObject) Js.globalSettings = settingsObject         }     }
Switching settings for desktop simulation // Simulator for different platforms DiscountCalcUi {         id: main     } ListModel {         id: platformsModel ListElement {title: "Symbian"; visualTitle: "S^3"} ListElement{title: "Android480x800"; visualTitle: "Andr 800" } ListElement{title: "Harmattan" }     } onButtonClicked: { var component = Qt.createComponent("Settings" + model.title + ".qml") main.settings = component.createObject(main) } // actually, maybe we should have changed the global JS reference :/
Summary Parameterizing code everywhere is possible and easy Use JavaScript libraries for storing global objects To initialize settings by the moment of QML instantiations, inject settings from C++ before the main QML object Care about ability to change settings object for the desktop simulation of different platforms
Thank you Q&As time You can find these and similar slides at http://agilesoftwaredevelopment.com/tags/qml

Weitere ähnliche Inhalte

Andere mochten auch

Difference Between Open And Closed Cell Foam Insulation
Difference Between Open And Closed Cell Foam InsulationDifference Between Open And Closed Cell Foam Insulation
Difference Between Open And Closed Cell Foam InsulationBill Miller
 
Scrum não é suficiente - ultrapassando o básico
Scrum não é suficiente - ultrapassando o básicoScrum não é suficiente - ultrapassando o básico
Scrum não é suficiente - ultrapassando o básicoIgor Macaubas
 
Fun with QML and JavaScript: Embedded Linux Conference 11th April 2011, Hotel...
Fun with QML and JavaScript: Embedded Linux Conference 11th April 2011, Hotel...Fun with QML and JavaScript: Embedded Linux Conference 11th April 2011, Hotel...
Fun with QML and JavaScript: Embedded Linux Conference 11th April 2011, Hotel...Raj Lal
 
Vídeos - novos hábitos, grandes desafios
Vídeos - novos hábitos, grandes desafiosVídeos - novos hábitos, grandes desafios
Vídeos - novos hábitos, grandes desafiosIgor Macaubas
 
QML demo for makerpro (1)
QML demo for makerpro (1)QML demo for makerpro (1)
QML demo for makerpro (1)diro fan
 
Intro to QML / Declarative UI
Intro to QML / Declarative UIIntro to QML / Declarative UI
Intro to QML / Declarative UIOpenBossa
 
Terraforming organisations
Terraforming organisationsTerraforming organisations
Terraforming organisationsClaudio Perrone
 
Build Cutting edge Mobile Apps using QML and JavaScript for MeeGo N9: Linux F...
Build Cutting edge Mobile Apps using QML and JavaScript for MeeGo N9: Linux F...Build Cutting edge Mobile Apps using QML and JavaScript for MeeGo N9: Linux F...
Build Cutting edge Mobile Apps using QML and JavaScript for MeeGo N9: Linux F...Raj Lal
 
How to Make Your Qt App Look Native
How to Make Your Qt App Look NativeHow to Make Your Qt App Look Native
How to Make Your Qt App Look Nativeaccount inactive
 
Having the Correct Context for an Agile Transformation
Having the Correct Context for an Agile TransformationHaving the Correct Context for an Agile Transformation
Having the Correct Context for an Agile TransformationDerek Huether
 
Fases de RUP - PDF
Fases de RUP - PDFFases de RUP - PDF
Fases de RUP - PDFradoslawkb
 

Andere mochten auch (19)

Difference Between Open And Closed Cell Foam Insulation
Difference Between Open And Closed Cell Foam InsulationDifference Between Open And Closed Cell Foam Insulation
Difference Between Open And Closed Cell Foam Insulation
 
Scrum não é suficiente - ultrapassando o básico
Scrum não é suficiente - ultrapassando o básicoScrum não é suficiente - ultrapassando o básico
Scrum não é suficiente - ultrapassando o básico
 
Resumen RUP
Resumen RUPResumen RUP
Resumen RUP
 
Fun with QML and JavaScript: Embedded Linux Conference 11th April 2011, Hotel...
Fun with QML and JavaScript: Embedded Linux Conference 11th April 2011, Hotel...Fun with QML and JavaScript: Embedded Linux Conference 11th April 2011, Hotel...
Fun with QML and JavaScript: Embedded Linux Conference 11th April 2011, Hotel...
 
QtQuick Day 4
QtQuick Day 4QtQuick Day 4
QtQuick Day 4
 
Agile Contracts
Agile ContractsAgile Contracts
Agile Contracts
 
Vídeos - novos hábitos, grandes desafios
Vídeos - novos hábitos, grandes desafiosVídeos - novos hábitos, grandes desafios
Vídeos - novos hábitos, grandes desafios
 
QML demo for makerpro (1)
QML demo for makerpro (1)QML demo for makerpro (1)
QML demo for makerpro (1)
 
Hello, QML
Hello, QMLHello, QML
Hello, QML
 
QtQuick Day 2
QtQuick Day 2QtQuick Day 2
QtQuick Day 2
 
QtQuick Day 3
QtQuick Day 3QtQuick Day 3
QtQuick Day 3
 
Intro to QML / Declarative UI
Intro to QML / Declarative UIIntro to QML / Declarative UI
Intro to QML / Declarative UI
 
Terraforming organisations
Terraforming organisationsTerraforming organisations
Terraforming organisations
 
Qt Qml
Qt QmlQt Qml
Qt Qml
 
Build Cutting edge Mobile Apps using QML and JavaScript for MeeGo N9: Linux F...
Build Cutting edge Mobile Apps using QML and JavaScript for MeeGo N9: Linux F...Build Cutting edge Mobile Apps using QML and JavaScript for MeeGo N9: Linux F...
Build Cutting edge Mobile Apps using QML and JavaScript for MeeGo N9: Linux F...
 
QtQuick Day 1
QtQuick Day 1QtQuick Day 1
QtQuick Day 1
 
How to Make Your Qt App Look Native
How to Make Your Qt App Look NativeHow to Make Your Qt App Look Native
How to Make Your Qt App Look Native
 
Having the Correct Context for an Agile Transformation
Having the Correct Context for an Agile TransformationHaving the Correct Context for an Agile Transformation
Having the Correct Context for an Agile Transformation
 
Fases de RUP - PDF
Fases de RUP - PDFFases de RUP - PDF
Fases de RUP - PDF
 

Mehr von Artem Marchenko

One code Web, iOS, Android
One code Web, iOS, AndroidOne code Web, iOS, Android
One code Web, iOS, AndroidArtem Marchenko
 
Getting started with coding for Jolla Sailfish OS. 29 Mar 2014, Tampere, Finland
Getting started with coding for Jolla Sailfish OS. 29 Mar 2014, Tampere, FinlandGetting started with coding for Jolla Sailfish OS. 29 Mar 2014, Tampere, Finland
Getting started with coding for Jolla Sailfish OS. 29 Mar 2014, Tampere, FinlandArtem Marchenko
 
Getting started with coding for Jolla Sailfish OS. 22 Feb 2014, Tampere, Finland
Getting started with coding for Jolla Sailfish OS. 22 Feb 2014, Tampere, FinlandGetting started with coding for Jolla Sailfish OS. 22 Feb 2014, Tampere, Finland
Getting started with coding for Jolla Sailfish OS. 22 Feb 2014, Tampere, FinlandArtem Marchenko
 
Misapplied Scrum pattern
Misapplied Scrum patternMisapplied Scrum pattern
Misapplied Scrum patternArtem Marchenko
 
Effective Software Development for the 21st century
Effective Software Development for the 21st centuryEffective Software Development for the 21st century
Effective Software Development for the 21st centuryArtem Marchenko
 

Mehr von Artem Marchenko (7)

One code Web, iOS, Android
One code Web, iOS, AndroidOne code Web, iOS, Android
One code Web, iOS, Android
 
Getting started with coding for Jolla Sailfish OS. 29 Mar 2014, Tampere, Finland
Getting started with coding for Jolla Sailfish OS. 29 Mar 2014, Tampere, FinlandGetting started with coding for Jolla Sailfish OS. 29 Mar 2014, Tampere, Finland
Getting started with coding for Jolla Sailfish OS. 29 Mar 2014, Tampere, Finland
 
Getting started with coding for Jolla Sailfish OS. 22 Feb 2014, Tampere, Finland
Getting started with coding for Jolla Sailfish OS. 22 Feb 2014, Tampere, FinlandGetting started with coding for Jolla Sailfish OS. 22 Feb 2014, Tampere, Finland
Getting started with coding for Jolla Sailfish OS. 22 Feb 2014, Tampere, Finland
 
Test driving-qml
Test driving-qmlTest driving-qml
Test driving-qml
 
Test driving QML
Test driving QMLTest driving QML
Test driving QML
 
Misapplied Scrum pattern
Misapplied Scrum patternMisapplied Scrum pattern
Misapplied Scrum pattern
 
Effective Software Development for the 21st century
Effective Software Development for the 21st centuryEffective Software Development for the 21st century
Effective Software Development for the 21st century
 

Kürzlich hochgeladen

The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGSujit Pal
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 

Kürzlich hochgeladen (20)

The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAG
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 

QML settings

  • 1. Platform and device-specific settings for your QML layouts Artem Marchenko October 8, 2011 After Easy Discount Calculator by Artem Marchenko, JarmoParkkinen, TuukkaLindroos and Ekaterina Kuts Technical solution by Artem Marchenko and TuukkaLindroos
  • 2. Artem Marchenko Product Manager, Agile Coach, QML engineer for hire Was a Product Manager shipping multi-hundred MEur products Three times Forum Nokia Champion Private entrepreneur Available for hire for all things QML http://fi.linkedin.com/in/artemmarchenko
  • 3. Same app running on Harmattan, Android and Symbian
  • 4. Easy Discount Calculator Symbian, MeeGo/Harmattan - http://store.ovi.com/content/186742 Android - http://bit.ly/discountcalculator Free, but has font issues on some models due to porting technology bug. Well working proof of concept for now
  • 5. All the parameters can be fine-tuned on desktop
  • 6. Settings system // SettingsBase.QML import Qt 4.7 import "GlobalSettings.js" as Js QtObject { id: settingsObject // logical switches/conditions property boolexitButtonPresent: true property boolclearButtonIsBetweenTheLines: true // element sizes property introllerHeight: 110 property intdigitRollerWidth: 56 property intpercentageRollerWidth: digitRollerWidth
  • 7. Settings system // SettingsMaemo.qml import Qt 4.7 SettingsBase { property string platformTitle: "Maemo" property intscreenWidthInPortrait: 480 ... property introllerHeight: 160 property introllerNumberLineInnerSpacing: 0 property int digitRollerWidth:69 statusLineHeight: 0
  • 9. Using platform settings in JS //GlobalSettings.js .pragma library // - the only QML possibility for global variables varglobalSettings = null // Will fetch the settings object from the item. If the settings object doesn't // exists, will return the global one or generate one on the fly based on base settings. function getSettings(item) { … if(item.settings) { if(!globalSettings) { globalSettings = item.settings } if(!globalSettings) { var component = Qt.createComponent("SettingsBase.qml") globalSettings = component.createObject(item) } return globalSettings;
  • 10. Using Settings in QML // SmallButton.qml import Qt 4.7 import "GlobalSettings.js" as Js Rectangle { id: button width: Js.getSettings(button).smallButtonWidth height: Js.getSettings(button).smallButtonHeight radius: 3
  • 11. Injecting Settings from C++ QStringsettingsPath = "qml/discountcalcui/Settings" + platformTitle + ".qml"; // localAdjustPath cares about platform-specific file location details settingsUrl = QUrl::fromLocalFile(CrossPlatformUtils::localAdjustPath(settingsPath)); QDeclarativeComponent component(view.engine(), settingsUrl); settingsInstance = component.create(); if(!settingsInstance) { // No settings found - no object to install qWarning() << "Settings not found for this platform!"; qWarning() << component.errorString(); } else { settingsInstance->setProperty("shouldInitializeGlobalSettingWithItself", true); view.engine()->rootContext()->setContextProperty("forcedSettings”, settingsInstance); } // continue with normal QML initialization
  • 12. JavaScript side of initialization //SettingsBase.qml import Qt 4.7 import "GlobalSettings.js" as Js QtObject { id: settingsObject property boolshouldInitializeGlobalSettingWithItself: false // Is executed way before main QML file is loaded onShouldInitializeGlobalSettingWithItselfChanged: { if(shouldInitializeGlobalSettingWithItself) { console.log("SBase: initializing global settings with " + settingsObject) Js.globalSettings = settingsObject } }
  • 13. Switching settings for desktop simulation // Simulator for different platforms DiscountCalcUi { id: main } ListModel { id: platformsModel ListElement {title: "Symbian"; visualTitle: "S^3"} ListElement{title: "Android480x800"; visualTitle: "Andr 800" } ListElement{title: "Harmattan" } } onButtonClicked: { var component = Qt.createComponent("Settings" + model.title + ".qml") main.settings = component.createObject(main) } // actually, maybe we should have changed the global JS reference :/
  • 14. Summary Parameterizing code everywhere is possible and easy Use JavaScript libraries for storing global objects To initialize settings by the moment of QML instantiations, inject settings from C++ before the main QML object Care about ability to change settings object for the desktop simulation of different platforms
  • 15. Thank you Q&As time You can find these and similar slides at http://agilesoftwaredevelopment.com/tags/qml