显示标签为“Qml”的博文。显示所有博文
显示标签为“Qml”的博文。显示所有博文

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年1月17日星期一

A Simple Qml Game - Thumder

Yeah,I've not updated my blog entry for a long time.Last blog entry was five months ago. one reason is I am basically a lazy guy,the other is busy work Frankly.Look back upon the past three months(First Workday on 10.18 2010),many things happend to me: a good job looks like,great changes in my routine life,work on project I am good at,making some innovative work with one or two talent guys.totally, a new journey for me has come to the beginning and I am on my way.

  screenshot of  Thumder
Btw,I spend free time writing  a small pure qml game(Thumder) instead of complex qt-apps integrated with qml like qDou.I am sure someone has played it in their childhood.:-) this simple one is just a part of a another interesting project(What's it ? secret).And when that interesting project is done.It will be going to wonderful,people will barely be able to comprehend it.But actually it's very easy.Maybe in the next post, I will give some details on It.

get the source code
git clone git://gitorious.org/thumder/thumder.git

Be good all.

2010年8月16日星期一

The stronger lineedit

I haven't update my blog for a long time.One reason is I am waiting impatiently for the time when Qt 4.7 release to rewrite qDou(qDou is programmed with Qt 4.6,at that time Qml is on the way.In the latter days,it changes a lot. here,QML on the Road to Release).Meanwhile I finished my under graduation last month.It's days of fun and good feelings and memories.There are the days when I stay up for the world cup and so amazing about spanish team work and Paul (The Octopus )'performance.The other Reason is looking forward to doing something useful software on the desktop,Just like Krunner or omnibox. 

                                   

Give all you need to the LineEdit,let it give you answers.
such as what's the weather like in chengdu?



but the first things I need to consider in programming is the result ranking
two factors for the result ranking
1.DateTime.the later the Matching words putted in the historyList,the more frontly will be it shows.
2.Frequence.the More times that you queryed for a same word ,The more frontly ........

btw,I really indebted to Arora(is opensource webkit based browser)'writer for his work.With his clear contributed code, it makes me benefit from it,especially how to re-construct QCompleter supporting filter and sorting with matching algorithm in post-facto.Actually what attracted me most in Arora's feature is Adblock.Althought it's not perfect,it's a really interesting way to block ads.

2010年3月8日星期一

qDou 0.1.2 Released

after one week ,I update qDou'source and Released qDou 0.1.2.
qDou 0.1.2 provide some bug fixes,optimization and new features which you can view comments about
movie,music or book and even publish your comments about your favourite.
More info about qDou 0.1.2.

2010年3月3日星期三

qDou 0.1.0 Released

I can't wait to say that qDou 0.1.0 is Released.You can download here. With powerful GraphicsView and smooth, beauty of Qml,qDou would't let you down.Before first time you play with qDou,you need to register douban's accout and apply for an APIKEY.More Information,you can find here.Please test and give feedback to me in the gruop.
By the way,I will talk about Deploying an application on Windows,especially your app with plugins.
First of all,you can follow the step By the document.Two easy ways to make plugins work out.you can choose anyone of them below .
1.put document named plugins which contains all you need plugins for you app in your applicationDirPath and In main.cpp you add a custom path using QApplication::addLibraryPath like this:
qApp->addLibraryPath(qApp->applicationDirPath()+"./plugins");
2.Using qt.conf
After you deploy your app on Windows with these methods above and your app still failed with loading plugins,It's not your fault.What you need is vcredist_x86.exe.Install it and the problems would be solved.In fact,Qt document refer to the point.
here is the video about qDou ,enjoy.

2010年2月18日星期四

QDou is not far away

Happy chinese new year.For my part,There is one more important thing I can tell you: what tedious days of study ,thought ,practice,experience ,went to the equipment of I who was able to impose upon all of you that QDou is not far away.
Meanwhile,I decided to buy N900 for testing.I can't wait to release QDou,But there is some small problems to consider them.Just give me sometime. :-)
                                          photoview of QDou

2010年1月23日星期六

QDou is on the way

I am home for about 1 month, after home, I am going to finish my graduate design: Qdou(Douban client on Symbian).This time I will use Declarative UI to finish it.With this Computer language,you can build the animation rich, fluid user interfaces,such as iphone.But........I am familiar with Qt rather than ECMAScript(QML is an extension to ECMAScript,So is javascript).at the beginning,It's a little difficult for me.Fortunately, there is a document about QML provided by Qt.after viewing document,you will find gradually that it's more convenient in some respects,like automatic property bindings and network transparency.This is what I need.Just like qt engineer says,even if you do not know how to use Qt, you can also program a pretty apps with Qml.Of course,qt would not let us down on extending.Because QML is fully extensible from C++.It's absolutely fantastic property for me. I have completed coding parts of qDou on the pc.From now on,maybe I will speed up.
                 seach ATB's album                                                                             Trilogy(detail)