2011年3月21日星期一

HappyFrog........just for fun

In the wake of angry bird become more and more popular,so I just wonder how to implement it with Qt.Below are some hint.
1.GraphicsView Framework(or Declarative UI) interagted with Box2D physics engine.
2.Explosion effect can be done with function drawPixmapFragment(which is introduced in Qt 4.7,make an optimize on state changes for QPainter,so it's faster than multiple calls to drawPixmap())
3.In order to boost my development,I wanna use some Element from Qml,such as flickAble or ListView,etc..


The first two are not difficult to implement it.
basically,lots of people want to know how to integrated qml with c++ in this demo,in particularly how to add item in the flickAble element (you konw,I am a lazy and humble guy and on the flip side,I guest not everyone konws that how to make kinetic animation,In fact it's not difficult).
(more detaileds watch the video Below).
In order to dynamically add item in the flickable,we can write some code in qml
Flickable {
     id: myFlickable
     ......
     function addItem(file) {
         var component = Qt.createComponent(file)
         component.createObject(myFlickable.contentItem);
     }
 }
Maybe someone just figure out an "easier" way

Flickable{
  id: myFlickable
  ......
  Loader { id: itemLoader }
  ......
  MouseArea {
          anchors.fill: parent
          onClicked: itemLoader.source = "items.qml"
     }
  }    
}
In case code you wrote like above,unfortunately,item inserted dynamiclly can not be "flicked",so it didn't work out if you forget passing Flickable.contentItem for the item created,even thought it seems like itemLoader is a "child" of myFlickable.
In C++
consider about foregoing problem we met.There are two little things we need to care about.
1.How to get the pointer of "Flickable"
2.How to get the pointer of "myFlickable.contentItem"(a property of Flickable)
;) some related apis have been prepared by Qt,easy and convinient.
   1.create QtObject Element for Flickable element,as the qt document mentioned "It can also be useful for C++ integration, as it is just a plain QObject.This allows a C++ application to locate an item within a QML component using the QObject::findChild() method". 
   2.with QObject'property to fetch the pointer of Flickable.contentItem.
   main.qml
Flikable {
      id:flickable;
      objectName: "flickArea"
      .......
      .......
  }
   
  main.cpp
 QDeclarativeComponent component(&engine,QUrl("main.qml"));
 if(component.status() != QDeclarativeComponent::Ready){
     foreach(const QDeclarativeError &error,component.errors()){
         qFatal(error.toString().toStdString().c_str());
     }
 } 
 QDeclarativeItem *mainView = qobject_cast< QDeclarativeItem *>(component.create());
 QDeclarativeItem *flickArea = mainView->findChild< QDeclarativeItem * >("flickArea");
 QDeclarativeItem *contentItem = qvariant_cast< QDeclarativeItem * >(flickArea->property("contentItem"));

//pass contenItem as item's parent.
ItemInserted   *item = new (contentItem);

That's all.Btw.
If you are a qml enthusiast,qml-Box2d(http://gitorious.org/qml-box2d) plugins is on the
way,here,Maybe it's useful for you to write fantastic game or something related stuff.
of course,HappyFrog is an opensource project,you can find here
http://code.google.com/p/happyfrog/
you can also checkout the latest source which is hosted on the my gitorious page.
git clone git://gitorious.org/happyfrog/happyfrog.git

2011年3月14日星期一

Sth From Norway

This morning,I got sth which is sent from Norway,meanwhile I have been accepted as a Qt Ambassador.Maybe It's good news for me during these times(seems like the T-shirt isn't fit me,small size would be fine),
Btw,I am working on a qt-apps integrated with Box2d and Declarative UI,I call it "Happy Frog" and about to prepare to release these days,stay tuned.

 

2011年3月6日星期日

Recent thoughts:my future

I suppose that everyone who gets involved with qt or focuses on Symbian, Maemo(Meego in the future) has been aware of the collaboration between Nokia and Microsoft.First time I heard of this, I feel shocked and then a lot of disappointment.You know,I am looking forward to the Meego platform for a long time.I am eager to get n900 mobile device still now.I stick to suppose that the Meego platform is still the first option for Nokia as mobile device operation system before this happened.But finally Nokia choose the Microsoft as parter and select window phone 7 as new platform.For my part,I have no idea if this is huge mistake for Nokia.For my part,I have no right to judge or criticize the collaboration or anyone involved with this,which should be on the agenda of those "Big man",not for nobody like me.Indeed,It's none of my business.I think I just an recent-undergraduate who get falling in love with qt programming from second year of college life and also a little "kid" in programming area.........
On the flip side,I really hope qt has a brilliant future,as well for nokia(without question,Qt never let us down).also hope Lots of people who love free and open (software) can continue concentrating on qt or any other (open source) related stuff instead of turning more attention on the wp7.I will guarantee that I will not get involved with wp7,so don't count me in.
............
Yeah,It's really tough time.at this point it reminds me of a famous blog post The fightback starts now.Comparision with burning platform,it's so obvious that "angry bird" is not the right person for that position.hum.Just let it go and see what happen next.Good luck to nokia.hope I am on the right way.