Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
Posts: 84
Registered: ‎04-22-2013
My Device: BB 10 Dev
My Carrier: Simulator

Problems in updating the background image in main.qml

Hi all,

In main.qml, i have the below codes which updates the background whenever the user changes the wallpaper in page2.qml.

Unfortunately, it only updates the background of page2.qml while main.qml still remain the same even if I killed the app. (page2.qml 's background is the updated one even if I killed the app)

Any idea where goes wrong? 

Thanks in advance.

 

 

main.qml

background: recipeBackground.imagePaint

                    BackgroundManager {
                        id: bg_manager
                        onWallpaperChanged: {
                            recipeBackground.setImageSource(wallpaper);
                        }
                    }

                    attachedObjects: [
                        ImagePaintDefinition {
                            property alias bgi: bg_manager.backgroundImage
                            //bgi: "set ur background here"
                            id: recipeBackground
                            repeatPattern: RepeatPattern.XY
                            imageSource: bgi
                        }
                    ]

 

page2.qml

            ListView {
                layout: GridListLayout {
                    columnCount: 2
                    horizontalCellSpacing: 0.0
                    cellAspectRatio: 1.0
                    verticalCellSpacing: 3.0
                    spacingBeforeHeader: 0.0
                    spacingAfterHeader: 0.0
                }
                dataModel: XmlDataModel {
                    source: "wallpaper.xml"
                }

                listItemComponents: [
                    ListItemComponent {
                        type: "wallpaper"

                        Container {
                            horizontalAlignment: HorizontalAlignment.Center
                            layout: DockLayout {
                            }

                            Container {
                                leftPadding: 20.0
                                horizontalAlignment: HorizontalAlignment.Fill
                                layout: StackLayout {
                                    orientation: LayoutOrientation.LeftToRight
                                }
                                topPadding: 20.0
                                bottomPadding: 20.0
                                ImageView {
                                    preferredWidth: 270.0
                                    preferredHeight: 350.0
                                    verticalAlignment: VerticalAlignment.Center

                                    // The image is bound to the data in models/recipemodel.xml image attribute.
                                    imageSource: ListItemData.day
                                    horizontalAlignment: HorizontalAlignment.Center
                                }
                            }
                        }
                    }
                ]

                onTriggered: {
                    var selectedItem = dataModel.data(indexPath);
                    bg_manager.setBackground(selectedItem.day, BackgroundManager.Day);
                    bg_manager.setBackground(selectedItem.night, BackgroundManager.Night);

                }
                leadingVisualSnapThreshold: 0.2
                horizontalAlignment: HorizontalAlignment.Center
                verticalAlignment: VerticalAlignment.Top
            }

 

Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: Problems in updating the background image in main.qml

What does your log say, is it reporting any problems or unknown variables.

My guess would be a scoping problem on bm_manager and/or BackGroundManager in page2.


If you've been helped click on Like Button, if you've been saved buy the app. :smileyhappy:

Developer of stokLocker, Sympatico and Super Sentences.
Developer
Posts: 84
Registered: ‎04-22-2013
My Device: BB 10 Dev
My Carrier: Simulator

Re: Problems in updating the background image in main.qml

no problems appear in my log.

in my actual app i have main.qml, page1.qml pag2.qml, page 3.qml and lots more...

page2.qml is the page where user can choose their preferred wallpaper and set it as the app background for all pages.

It updates all the background for the other pages EXCEPT main.qml still remain the same.

 

Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: Problems in updating the background image in main.qml

I take it the signal is emitted by the setBackground function.

Have you tried putting a console.log in the OnWallpaperChanged slot and see if it gets called?


If you've been helped click on Like Button, if you've been saved buy the app. :smileyhappy:

Developer of stokLocker, Sympatico and Super Sentences.
Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: Problems in updating the background image in main.qml

The code also looks dangerously circular to me,

 

Aren't you recalling the emit signal when you update the ImagePaintDefinition?


If you've been helped click on Like Button, if you've been saved buy the app. :smileyhappy:

Developer of stokLocker, Sympatico and Super Sentences.
Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: Problems in updating the background image in main.qml

Or it may just be I need sleep, 5am here, I'll look this up when I awaken hopefully you'll have figured it out. :smileyhappy:


If you've been helped click on Like Button, if you've been saved buy the app. :smileyhappy:

Developer of stokLocker, Sympatico and Super Sentences.
Developer
Posts: 84
Registered: ‎04-22-2013
My Device: BB 10 Dev
My Carrier: Simulator

Re: Problems in updating the background image in main.qml

[ Edited ]

when the app starts, onWallpaperChanged doesn't called in main.qml same for other pages.

I tried console.debug bg_manager.backgroundImage and what printed out was the default image path for main.qml BUT when i tried to debug it on page1.qml and so on.... console printed out the updated image path.

all calling the same c++ code but it doesn't get into main.qml only, totaly got no idea where goes wrong:smileysad:

 

i call this in my main.cpp

qmlRegisterType<BackgroundManager>("manager.bg", 1, 0, "BackgroundManager");

 

below is my background_manager.cpp

#include "background_manager.h"
#include <QDebug>
#include <bb/cascades/ImagePaint>
#include <bb/cascades/RepeatPattern>
#include <QTime>

#define DEFAULT_WALL	"asset:///images/backGround.png"
#define DAY_WALL		"daywall"
#define NIGHT_WALL		"nightwall"

BackgroundManager* BackgroundManager::instance = NULL;

// This is a singleton class

BackgroundManager::BackgroundManager(Container* parent)
    : CustomControl(parent) {
	wallpaperSettings = new WallpaperSettings();
	dummyTime = NULL;
}

BackgroundManager* BackgroundManager::GetInstance() {
	if (instance == NULL) instance = new BackgroundManager();
	return instance;
}

BackgroundManager::~BackgroundManager() {
}

QString BackgroundManager::getBackground() {
	if (getCurrentWallpaperType() == BackgroundManager::Day)
		return wallpaperSettings->getValueFor(DAY_WALL, DEFAULT_WALL);
	return wallpaperSettings->getValueFor(NIGHT_WALL, DEFAULT_WALL);
}

void BackgroundManager::setBackground(const QString& backgroundImage, const BackgroundManager::WallpaperType& wallpaperType) {
	wallpaperImage = backgroundImage;
	if (wallpaperType == BackgroundManager::Day)
		wallpaperSettings->saveValueFor(DAY_WALL, backgroundImage);
	else wallpaperSettings->saveValueFor(NIGHT_WALL, backgroundImage);

	if (changedOnCurrentTime(wallpaperType))
		emit wallpaperChanged(backgroundImage);
}

BackgroundManager::WallpaperType BackgroundManager::getCurrentWallpaperType() {
	QTime currentTime = QTime::currentTime();
	if (dummyTime != NULL)
		currentTime = *dummyTime;
	if (currentTime >= QTime(8, 0, 0) && currentTime < QTime(20, 0, 0)) return BackgroundManager::Day;
	return BackgroundManager::Night;
}

bool BackgroundManager::changedOnCurrentTime(const BackgroundManager::WallpaperType& wallpaperType) {
	if (wallpaperType == getCurrentWallpaperType()) return true;
	return false;
}

void BackgroundManager::forceTime(const BackgroundManager::WallpaperType& wallpaperType) {
	if (wallpaperType == BackgroundManager::Day)
		dummyTime = new QTime(8, 0, 0);
	else
		dummyTime = new QTime(20, 0, 0);
}

void BackgroundManager::resetTime() {
	dummyTime = NULL;
}