SlideShare ist ein Scribd-Unternehmen logo
1 von 28
Downloaden Sie, um offline zu lesen
QML を用いた
YouTube クライアントの作成


小川 純平 (Jumpei Ogawa / @phanect)
     日本 KDE ユーザー会
Qt とは
●   C++ のフレームワーク
●   最近 QML という UI 記述言語と、JavaScript
    を用いる方法が導入された
●   デスクトップ (Windows / Mac / Linux) や
     モバイル系 OS (MeeGo / Android /
    Symbian)、組み込み Linux などで動作
      ●   Qt for Android は現在 alpha 版
QML で
YouTube クライアントを作成
作るもの
●   YouTube の動画を検索して結果を一覧表示
●   選択した動画を再生する
テキストボックスを配置
●   ウィンドウサイズを変更
     ●   左上の[ナビゲータ] で Rectangle を選択し、
          右の [プロパティ] > [ジオメトリ] > [サイ
          ズ] の値を変更
●   デザイナでテキストとテキストボックスを配
    置
     ●   左下の [ライブラリ] > [アイテム] タブ から
          [Text] と [Text Input] をドラッグアンドド
          ロップ
           –   [Text Edit] は複数行用
     ●   右上の ID を編集
     ●   右下の [テキスト] を編集
ここまでのコード
Rectangle {
    width: 600
    height: 400

   Text {
       id: text1
       x: 14
       y: 15
       text: "検索キーワード:"
       font.pixelSize: 12
   }

   TextInput {
       id: in_keyword
       x: 124
       y: 13
       width: 137
       height: 20
       text: "キーワードをここに入力"
       font.pixelSize: 12
QML のボタンコンポーネント
●   モバイル (Symbian/MeeGo) では Qt Quick
    Components が既に利用可能
●   PC で利用したい場合は
    git://gitorious.org/qt-
    components/desktop.git から落とす
QML のボタンコンポーネント
●   面倒なので今回は自前で作成
ボタンを作成
●   Rectangle を新たに作成
●   その中に Text を入れる
      ●   ナビゲータで Rectangle の下位に Text がき
           ていることを確認
            –   来ていなければ、ナビゲータで Rectangle に
                 Text をドラッグアンドドロップ
      ●   コードエディタで anchor.centerIn: parent
           を追加
ここまでのコード
Rectangle {
    ...
    Text {...}
    TextInput {...}

    Rectangle {
        id: button
        x: 286
        y: 13
        width: 72
        height: 20
        color: "#ffffff"

        Text {
            id: buttontext
            anchors.centerIn: parent
            text: "検索"
            font.pixelSize: 12
        }
anchor の設定
●   anchors で他のコンポーネントに対しての位
    置を指定
      ●   anchors.top / bottom / left / right
      ●   anchors.verticalCenter: 縦方向の中心点
      ●   anchors.fill: 上下左右の端
      ●   anchors.centerIn: 中心点

●   詳細 > Qt Quick 入門 第7回: レイアウト
      ●   http://labs.qt.nokia.co.jp/2011/01/06/qml-lay
anchor で TextInput の
              位置指定
●   TextInput で、
      ●   x: 286 → anchors.left: text1.right
      ●   y: 13 → anchors.verticalCenter:
            text1.verticalCenter
    と変更
●   anchors.margins: 10 を TextInput に追加
      ●   周囲からの間隔を指定

●   ボタンに対しても同様に行う
YouTube API
●   動画の検索 API
●   http://gdata.youtube.com/feeds/api/vide
    os?v=2&q=キーワード
    で XML が返ってくる
       ●   v=2 は API のバージョン番号
<feed ...>
   ...
   <entry>
       <title type="text">My walk with Mr. Darcy</title>

      <media:group>
        <media:thumbnail
           url="http://img.youtube.com/.../2.jpg" />

         <yt:videoid>EXS0BFS6QT4</yt:videoid>

       </media:group>
   </entry>
   ...
</feed>
YouTube タイトル・サムネイル
<feed ...>
   <entry>

     <title type="text">My walk with Mr. Darcy</title>

  </entry>

   <entry>
      ...
   </entry>
</feed>

XPath は “/feed/entry/title”
XmlListModel で XML を解析
XmlListModel {
  id: ytlist

 source:
    "http://gdata.youtube.com/feeds/api/videos?v=2&q=キー
ワード"
 query: "/feed/entry" // XPath で <entry> タグを繰り返し読込

   namespaceDeclarations:"declare default element namespace
'http://www.w3.org/2005/Atom';"

    XmlRole { name: "title"; query: "title/string()" }
}
ListView で解析結果を表示
ListView {
   id: videolist

    model: ytlist
    delegate: Text {text: title}

    anchors.top: in_keyword.bottom
    anchors.margins: 10
    width: parent.width / 2
    height: parent.height
}
YouTube タイトル・サムネイル
<feed>
   <entry>
      <media:group>
        <media:thumbnail url='http://i.ytimg.com/.../0.jpg' .../>
        <media:thumbnail url='http://i.ytimg.com/.../1.jpg' .../>
        <media:thumbnail url='http://i.ytimg.com/.../2.jpg' .../>
        <media:thumbnail url='http://i.ytimg.com/.../3.jpg' .../>
      </media:group>
   </entry>
</feed>

XPath は “/feed/entry/media:group/media:thumbnail[1]/@url”
       0ではなく1から始まることに注意↑
XmlListModel で XML を解析
XmlListModel {
  id: ytlist

  source: "http://gdata.youtube.com/feeds/api/videos?
v=2&q=キーワード"
  query: "/feed/entry"

   namespaceDeclarations:"declare default element namespace
'http://www.w3.org/2005/Atom';
declare namespace media='http://search.yahoo.com/mrss/';"

  XmlRole { name: "title"; query: "title/string()" }
  XmlRole {
    name: "thumbnail"
    query: "media:group/media:thumbnail[1]/@url/string()"
ListView で解析結果を表示
ListView {
   id: videolist

   model: ytlist
   delegate: Column{
         Image {
            source: thumbnail
         }
         Text {text: title}
   }

   anchors.top: in_keyword.bottom
   anchors.margins: 10
   width: parent.width / 2
   height: parent.height
動画プレイヤー部分の作成
●   ブラウザコンポーネント (WebView) 上に
    YouTube の Embedded player を貼り付け
●   http://www.youtube.com/embed/VIDEO_I
    D // ?html5=1
      ●   ?html5=1 は Flash 版ではなく HTML5
           Player を使いたい場合に付ける
本当はよくない方法ですが...
●   本来は Video を用いるべきだが、デスクトッ
    プでの利用が面倒くさそうなので...
     ●   モバイルならこちらの方が早いかも...
WebView を追加
WebView {
   url: "http://www.youtube.com/embed/"
         + videoId"
   // Flash Player を有効化
   settings.pluginsEnabled:true

    anchors.top: in_keyword.bottom
    anchors.left: videolist.right
    anchors.right: parent.right
    anchors.bottom: parent.bottom
    anchors.margins: 10
}
YouTube 動画 ID
<feed ...>
   <entry>
      <media:group>
          <yt:videoid>CL-vIg4Ivqw</yt:videoid>
      </media:group>
   </entry>
</feed>

XPath は “/feed/entry/media:group/yt:videoid”
XmlListModel で XML を解析
XmlListModel {
  id: ytlist

  source: "http://gdata.youtube.com/feeds/api/videos?
v=2&q=キーワード"
  query: "/feed/entry"

   NamespaceDeclarations:"... declare namespace
yt='http://gdata.youtube.com/schemas/2007';"

  XmlRole { … } // 前の XmlRole は省略
  XmlRole {
    name: "videoId"
    query: "media:group/yt:videoid/string()"
  }
ListView にクリックイベントを
ListView {
            追加
    id: videolist

    model: ytlist
    delegate: Column{
        Image {
            source: thumbnail
        }
        Text {text: title}
        MouseArea {
            anchors.fill: parent
            onClicked: {
                videoplayer.url =
                    "http://www.youtube.com/embed/" + videoId
            }
        }
    }
    ...
}
検索ボタンにクリックイベントを
 Rectangle {
             追加
       id: rectangle1
       ...

       Text {
           id: text2
           text: "Search"
       }

        MouseArea {
            anchors.fill: parent
            onClicked: {
                ytlist.source =
"http://gdata.youtube.com/feeds/api/videos?v=2&q=" + text_input1.text
            }
        }
    }
End of Slides
●   本日のスライド
     ●   http://slidesha.re/obeI9k
●   本日のコード
     ●   http://bit.ly/oeuejD
     ●   zip: http://bit.ly/oJHauZ

Weitere ähnliche Inhalte

Was ist angesagt?

Djangoフレームワークの紹介
Djangoフレームワークの紹介Djangoフレームワークの紹介
Djangoフレームワークの紹介Shinya Okano
 
jQuery Performance Tips – jQueryにおける高速化 -
jQuery Performance Tips – jQueryにおける高速化 -jQuery Performance Tips – jQueryにおける高速化 -
jQuery Performance Tips – jQueryにおける高速化 -Hayato Mizuno
 
WordPressプラグイン作成入門
WordPressプラグイン作成入門WordPressプラグイン作成入門
WordPressプラグイン作成入門Yuji Nojima
 
TDC20111031_Groovy_Geb
TDC20111031_Groovy_GebTDC20111031_Groovy_Geb
TDC20111031_Groovy_GebNobuhiro Sue
 
.htaccessによるリダイレクト徹底解説
.htaccessによるリダイレクト徹底解説.htaccessによるリダイレクト徹底解説
.htaccessによるリダイレクト徹底解説Cherry Pie Web
 
Dgeni with AngularJS Application
Dgeni with AngularJS ApplicationDgeni with AngularJS Application
Dgeni with AngularJS ApplicationK Kinzal
 
2005 07 30_xwj_customizinig
2005 07 30_xwj_customizinig2005 07 30_xwj_customizinig
2005 07 30_xwj_customizinigTom Hayakawa
 
Ginとbindataで作るシングルバイナリWebApp
Ginとbindataで作るシングルバイナリWebAppGinとbindataで作るシングルバイナリWebApp
Ginとbindataで作るシングルバイナリWebAppAkihiko Horiuchi
 
EC-CUBEプラグイン講義
EC-CUBEプラグイン講義EC-CUBEプラグイン講義
EC-CUBEプラグイン講義ria1201
 
Pythonで電卓アプリ(デスクトップ)を作成する
Pythonで電卓アプリ(デスクトップ)を作成するPythonで電卓アプリ(デスクトップ)を作成する
Pythonで電卓アプリ(デスクトップ)を作成するJun Okazaki
 
Google App Engine for Java
Google App Engine for JavaGoogle App Engine for Java
Google App Engine for JavaTakuya Tsuchida
 
仕事で使うちょっとしたコードをOSSとして開発メンテしていく - Django Redshift Backend の開発 - PyCon JP 2016
仕事で使うちょっとしたコードをOSSとして開発メンテしていく- Django Redshift Backend の開発 - PyCon JP 2016仕事で使うちょっとしたコードをOSSとして開発メンテしていく- Django Redshift Backend の開発 - PyCon JP 2016
仕事で使うちょっとしたコードをOSSとして開発メンテしていく - Django Redshift Backend の開発 - PyCon JP 2016Takayuki Shimizukawa
 
Nuxt なしで Vue App 作る時に乗り越えるべき5つの壁
Nuxt なしで Vue App 作る時に乗り越えるべき5つの壁Nuxt なしで Vue App 作る時に乗り越えるべき5つの壁
Nuxt なしで Vue App 作る時に乗り越えるべき5つの壁Yutaro Miyazaki
 
Chrome Extensionsの基本とデザインパターン
Chrome Extensionsの基本とデザインパターンChrome Extensionsの基本とデザインパターン
Chrome Extensionsの基本とデザインパターンYoichiro Tanaka
 
翻訳から始めるVue.js 入門
翻訳から始めるVue.js 入門翻訳から始めるVue.js 入門
翻訳から始めるVue.js 入門Makoto Chiba
 
プロダクトに 1 から Vue.js を導入した話
プロダクトに 1 から Vue.js を導入した話プロダクトに 1 から Vue.js を導入した話
プロダクトに 1 から Vue.js を導入した話Shohei Okada
 
JJUG CCC 2011 Fall / Web test automation with Geb and Spock
JJUG CCC 2011 Fall / Web test automation with Geb and SpockJJUG CCC 2011 Fall / Web test automation with Geb and Spock
JJUG CCC 2011 Fall / Web test automation with Geb and SpockNobuhiro Sue
 
getAllEntriesByKey vs createViewNavFromKey
getAllEntriesByKey vs createViewNavFromKeygetAllEntriesByKey vs createViewNavFromKey
getAllEntriesByKey vs createViewNavFromKeyHaruyuki Nakano
 

Was ist angesagt? (20)

Djangoフレームワークの紹介
Djangoフレームワークの紹介Djangoフレームワークの紹介
Djangoフレームワークの紹介
 
jQuery Performance Tips – jQueryにおける高速化 -
jQuery Performance Tips – jQueryにおける高速化 -jQuery Performance Tips – jQueryにおける高速化 -
jQuery Performance Tips – jQueryにおける高速化 -
 
WordPressとjQuery
WordPressとjQueryWordPressとjQuery
WordPressとjQuery
 
WordPressプラグイン作成入門
WordPressプラグイン作成入門WordPressプラグイン作成入門
WordPressプラグイン作成入門
 
TDC20111031_Groovy_Geb
TDC20111031_Groovy_GebTDC20111031_Groovy_Geb
TDC20111031_Groovy_Geb
 
.htaccessによるリダイレクト徹底解説
.htaccessによるリダイレクト徹底解説.htaccessによるリダイレクト徹底解説
.htaccessによるリダイレクト徹底解説
 
Dgeni with AngularJS Application
Dgeni with AngularJS ApplicationDgeni with AngularJS Application
Dgeni with AngularJS Application
 
2005 07 30_xwj_customizinig
2005 07 30_xwj_customizinig2005 07 30_xwj_customizinig
2005 07 30_xwj_customizinig
 
Ginとbindataで作るシングルバイナリWebApp
Ginとbindataで作るシングルバイナリWebAppGinとbindataで作るシングルバイナリWebApp
Ginとbindataで作るシングルバイナリWebApp
 
EC-CUBEプラグイン講義
EC-CUBEプラグイン講義EC-CUBEプラグイン講義
EC-CUBEプラグイン講義
 
20120118 titanium
20120118 titanium20120118 titanium
20120118 titanium
 
Pythonで電卓アプリ(デスクトップ)を作成する
Pythonで電卓アプリ(デスクトップ)を作成するPythonで電卓アプリ(デスクトップ)を作成する
Pythonで電卓アプリ(デスクトップ)を作成する
 
Google App Engine for Java
Google App Engine for JavaGoogle App Engine for Java
Google App Engine for Java
 
仕事で使うちょっとしたコードをOSSとして開発メンテしていく - Django Redshift Backend の開発 - PyCon JP 2016
仕事で使うちょっとしたコードをOSSとして開発メンテしていく- Django Redshift Backend の開発 - PyCon JP 2016仕事で使うちょっとしたコードをOSSとして開発メンテしていく- Django Redshift Backend の開発 - PyCon JP 2016
仕事で使うちょっとしたコードをOSSとして開発メンテしていく - Django Redshift Backend の開発 - PyCon JP 2016
 
Nuxt なしで Vue App 作る時に乗り越えるべき5つの壁
Nuxt なしで Vue App 作る時に乗り越えるべき5つの壁Nuxt なしで Vue App 作る時に乗り越えるべき5つの壁
Nuxt なしで Vue App 作る時に乗り越えるべき5つの壁
 
Chrome Extensionsの基本とデザインパターン
Chrome Extensionsの基本とデザインパターンChrome Extensionsの基本とデザインパターン
Chrome Extensionsの基本とデザインパターン
 
翻訳から始めるVue.js 入門
翻訳から始めるVue.js 入門翻訳から始めるVue.js 入門
翻訳から始めるVue.js 入門
 
プロダクトに 1 から Vue.js を導入した話
プロダクトに 1 から Vue.js を導入した話プロダクトに 1 から Vue.js を導入した話
プロダクトに 1 から Vue.js を導入した話
 
JJUG CCC 2011 Fall / Web test automation with Geb and Spock
JJUG CCC 2011 Fall / Web test automation with Geb and SpockJJUG CCC 2011 Fall / Web test automation with Geb and Spock
JJUG CCC 2011 Fall / Web test automation with Geb and Spock
 
getAllEntriesByKey vs createViewNavFromKey
getAllEntriesByKey vs createViewNavFromKeygetAllEntriesByKey vs createViewNavFromKey
getAllEntriesByKey vs createViewNavFromKey
 

Ähnlich wie QML を用いた YouTube クライアントの作成 - 関東 Qt 勉強会

Azure IoT Edge で Custom Vision
Azure IoT Edge で Custom VisionAzure IoT Edge で Custom Vision
Azure IoT Edge で Custom VisionYoshitaka Seo
 
13016 n分で作るtype scriptでnodejs
13016 n分で作るtype scriptでnodejs13016 n分で作るtype scriptでnodejs
13016 n分で作るtype scriptでnodejsTakayoshi Tanaka
 
Tide - SmalltalkでSPA
Tide - SmalltalkでSPATide - SmalltalkでSPA
Tide - SmalltalkでSPAMasashi Umezawa
 
Android Lecture #04 @PRO&BSC Inc.
Android Lecture #04 @PRO&BSC Inc.Android Lecture #04 @PRO&BSC Inc.
Android Lecture #04 @PRO&BSC Inc.Yuki Higuchi
 
Firefox DevTools
Firefox DevToolsFirefox DevTools
Firefox DevToolsdynamis
 
SpringMVCとmixer2で作るWebアプリのキホン 2013-01-24 Spring勉強会 #jsug
SpringMVCとmixer2で作るWebアプリのキホン 2013-01-24 Spring勉強会 #jsugSpringMVCとmixer2で作るWebアプリのキホン 2013-01-24 Spring勉強会 #jsug
SpringMVCとmixer2で作るWebアプリのキホン 2013-01-24 Spring勉強会 #jsugY Watanabe
 
Grafana Dashboards as Code
Grafana Dashboards as CodeGrafana Dashboards as Code
Grafana Dashboards as CodeTakuhiro Yoshida
 
Twitter sphere of #twitter4j #twtr_hack
Twitter sphere of #twitter4j #twtr_hackTwitter sphere of #twitter4j #twtr_hack
Twitter sphere of #twitter4j #twtr_hackkimukou_26 Kimukou
 
Chrome Developer Toolsを使いこなそう!
Chrome Developer Toolsを使いこなそう!Chrome Developer Toolsを使いこなそう!
Chrome Developer Toolsを使いこなそう!yoshikawa_t
 
Jetpack Library 事始め
Jetpack Library 事始めJetpack Library 事始め
Jetpack Library 事始めTomohiro Kaizu
 
CodeIgniterによるPhwittr
CodeIgniterによるPhwittrCodeIgniterによるPhwittr
CodeIgniterによるPhwittrkenjis
 
VSCodeで始めるAzure Static Web Apps開発
VSCodeで始めるAzure Static Web Apps開発VSCodeで始めるAzure Static Web Apps開発
VSCodeで始めるAzure Static Web Apps開発Yuta Matsumura
 
Html5 Web Applications
Html5  Web ApplicationsHtml5  Web Applications
Html5 Web Applicationstotty jp
 
Jqm20120210
Jqm20120210Jqm20120210
Jqm20120210cmtomoda
 
Recap: Modern CI/CD with Tekton and Prow Automated via Jenkins X - Kubernetes...
Recap: Modern CI/CD with Tekton and Prow Automated via Jenkins X - Kubernetes...Recap: Modern CI/CD with Tekton and Prow Automated via Jenkins X - Kubernetes...
Recap: Modern CI/CD with Tekton and Prow Automated via Jenkins X - Kubernetes...JUNICHI YOSHISE
 
Cast SDK for Flutter
Cast SDK for FlutterCast SDK for Flutter
Cast SDK for FlutterKojiYamada22
 
Internet Explorer 9 の新機能「固定サイト」 (Pinned sites)
Internet Explorer 9 の新機能「固定サイト」 (Pinned sites)Internet Explorer 9 の新機能「固定サイト」 (Pinned sites)
Internet Explorer 9 の新機能「固定サイト」 (Pinned sites)shigeya
 
OpenGLプログラミング
OpenGLプログラミングOpenGLプログラミング
OpenGLプログラミング幸雄 村上
 

Ähnlich wie QML を用いた YouTube クライアントの作成 - 関東 Qt 勉強会 (20)

Azure IoT Edge で Custom Vision
Azure IoT Edge で Custom VisionAzure IoT Edge で Custom Vision
Azure IoT Edge で Custom Vision
 
13016 n分で作るtype scriptでnodejs
13016 n分で作るtype scriptでnodejs13016 n分で作るtype scriptでnodejs
13016 n分で作るtype scriptでnodejs
 
Tide - SmalltalkでSPA
Tide - SmalltalkでSPATide - SmalltalkでSPA
Tide - SmalltalkでSPA
 
Android Lecture #04 @PRO&BSC Inc.
Android Lecture #04 @PRO&BSC Inc.Android Lecture #04 @PRO&BSC Inc.
Android Lecture #04 @PRO&BSC Inc.
 
Firefox DevTools
Firefox DevToolsFirefox DevTools
Firefox DevTools
 
SpringMVCとmixer2で作るWebアプリのキホン 2013-01-24 Spring勉強会 #jsug
SpringMVCとmixer2で作るWebアプリのキホン 2013-01-24 Spring勉強会 #jsugSpringMVCとmixer2で作るWebアプリのキホン 2013-01-24 Spring勉強会 #jsug
SpringMVCとmixer2で作るWebアプリのキホン 2013-01-24 Spring勉強会 #jsug
 
Grafana Dashboards as Code
Grafana Dashboards as CodeGrafana Dashboards as Code
Grafana Dashboards as Code
 
Twitter sphere of #twitter4j #twtr_hack
Twitter sphere of #twitter4j #twtr_hackTwitter sphere of #twitter4j #twtr_hack
Twitter sphere of #twitter4j #twtr_hack
 
Titanium勉強会
Titanium勉強会Titanium勉強会
Titanium勉強会
 
Chrome Developer Toolsを使いこなそう!
Chrome Developer Toolsを使いこなそう!Chrome Developer Toolsを使いこなそう!
Chrome Developer Toolsを使いこなそう!
 
Jetpack Library 事始め
Jetpack Library 事始めJetpack Library 事始め
Jetpack Library 事始め
 
CodeIgniterによるPhwittr
CodeIgniterによるPhwittrCodeIgniterによるPhwittr
CodeIgniterによるPhwittr
 
VSCodeで始めるAzure Static Web Apps開発
VSCodeで始めるAzure Static Web Apps開発VSCodeで始めるAzure Static Web Apps開発
VSCodeで始めるAzure Static Web Apps開発
 
jQuery超入門編
jQuery超入門編jQuery超入門編
jQuery超入門編
 
Html5 Web Applications
Html5  Web ApplicationsHtml5  Web Applications
Html5 Web Applications
 
Jqm20120210
Jqm20120210Jqm20120210
Jqm20120210
 
Recap: Modern CI/CD with Tekton and Prow Automated via Jenkins X - Kubernetes...
Recap: Modern CI/CD with Tekton and Prow Automated via Jenkins X - Kubernetes...Recap: Modern CI/CD with Tekton and Prow Automated via Jenkins X - Kubernetes...
Recap: Modern CI/CD with Tekton and Prow Automated via Jenkins X - Kubernetes...
 
Cast SDK for Flutter
Cast SDK for FlutterCast SDK for Flutter
Cast SDK for Flutter
 
Internet Explorer 9 の新機能「固定サイト」 (Pinned sites)
Internet Explorer 9 の新機能「固定サイト」 (Pinned sites)Internet Explorer 9 の新機能「固定サイト」 (Pinned sites)
Internet Explorer 9 の新機能「固定サイト」 (Pinned sites)
 
OpenGLプログラミング
OpenGLプログラミングOpenGLプログラミング
OpenGLプログラミング
 

QML を用いた YouTube クライアントの作成 - 関東 Qt 勉強会

  • 1. QML を用いた YouTube クライアントの作成 小川 純平 (Jumpei Ogawa / @phanect) 日本 KDE ユーザー会
  • 2. Qt とは ● C++ のフレームワーク ● 最近 QML という UI 記述言語と、JavaScript を用いる方法が導入された ● デスクトップ (Windows / Mac / Linux) や モバイル系 OS (MeeGo / Android / Symbian)、組み込み Linux などで動作 ● Qt for Android は現在 alpha 版
  • 4. 作るもの ● YouTube の動画を検索して結果を一覧表示 ● 選択した動画を再生する
  • 5. テキストボックスを配置 ● ウィンドウサイズを変更 ● 左上の[ナビゲータ] で Rectangle を選択し、 右の [プロパティ] > [ジオメトリ] > [サイ ズ] の値を変更 ● デザイナでテキストとテキストボックスを配 置 ● 左下の [ライブラリ] > [アイテム] タブ から [Text] と [Text Input] をドラッグアンドド ロップ – [Text Edit] は複数行用 ● 右上の ID を編集 ● 右下の [テキスト] を編集
  • 6. ここまでのコード Rectangle { width: 600 height: 400 Text { id: text1 x: 14 y: 15 text: "検索キーワード:" font.pixelSize: 12 } TextInput { id: in_keyword x: 124 y: 13 width: 137 height: 20 text: "キーワードをここに入力" font.pixelSize: 12
  • 7. QML のボタンコンポーネント ● モバイル (Symbian/MeeGo) では Qt Quick Components が既に利用可能 ● PC で利用したい場合は git://gitorious.org/qt- components/desktop.git から落とす
  • 8. QML のボタンコンポーネント ● 面倒なので今回は自前で作成
  • 9. ボタンを作成 ● Rectangle を新たに作成 ● その中に Text を入れる ● ナビゲータで Rectangle の下位に Text がき ていることを確認 – 来ていなければ、ナビゲータで Rectangle に Text をドラッグアンドドロップ ● コードエディタで anchor.centerIn: parent を追加
  • 10. ここまでのコード Rectangle { ... Text {...} TextInput {...} Rectangle { id: button x: 286 y: 13 width: 72 height: 20 color: "#ffffff" Text { id: buttontext anchors.centerIn: parent text: "検索" font.pixelSize: 12 }
  • 11. anchor の設定 ● anchors で他のコンポーネントに対しての位 置を指定 ● anchors.top / bottom / left / right ● anchors.verticalCenter: 縦方向の中心点 ● anchors.fill: 上下左右の端 ● anchors.centerIn: 中心点 ● 詳細 > Qt Quick 入門 第7回: レイアウト ● http://labs.qt.nokia.co.jp/2011/01/06/qml-lay
  • 12. anchor で TextInput の 位置指定 ● TextInput で、 ● x: 286 → anchors.left: text1.right ● y: 13 → anchors.verticalCenter: text1.verticalCenter と変更 ● anchors.margins: 10 を TextInput に追加 ● 周囲からの間隔を指定 ● ボタンに対しても同様に行う
  • 13. YouTube API ● 動画の検索 API ● http://gdata.youtube.com/feeds/api/vide os?v=2&q=キーワード で XML が返ってくる ● v=2 は API のバージョン番号
  • 14. <feed ...> ... <entry> <title type="text">My walk with Mr. Darcy</title> <media:group> <media:thumbnail url="http://img.youtube.com/.../2.jpg" /> <yt:videoid>EXS0BFS6QT4</yt:videoid> </media:group> </entry> ... </feed>
  • 15. YouTube タイトル・サムネイル <feed ...> <entry> <title type="text">My walk with Mr. Darcy</title> </entry> <entry> ... </entry> </feed> XPath は “/feed/entry/title”
  • 16. XmlListModel で XML を解析 XmlListModel { id: ytlist source: "http://gdata.youtube.com/feeds/api/videos?v=2&q=キー ワード" query: "/feed/entry" // XPath で <entry> タグを繰り返し読込 namespaceDeclarations:"declare default element namespace 'http://www.w3.org/2005/Atom';" XmlRole { name: "title"; query: "title/string()" } }
  • 17. ListView で解析結果を表示 ListView { id: videolist model: ytlist delegate: Text {text: title} anchors.top: in_keyword.bottom anchors.margins: 10 width: parent.width / 2 height: parent.height }
  • 18. YouTube タイトル・サムネイル <feed> <entry> <media:group> <media:thumbnail url='http://i.ytimg.com/.../0.jpg' .../> <media:thumbnail url='http://i.ytimg.com/.../1.jpg' .../> <media:thumbnail url='http://i.ytimg.com/.../2.jpg' .../> <media:thumbnail url='http://i.ytimg.com/.../3.jpg' .../> </media:group> </entry> </feed> XPath は “/feed/entry/media:group/media:thumbnail[1]/@url” 0ではなく1から始まることに注意↑
  • 19. XmlListModel で XML を解析 XmlListModel { id: ytlist source: "http://gdata.youtube.com/feeds/api/videos? v=2&q=キーワード" query: "/feed/entry" namespaceDeclarations:"declare default element namespace 'http://www.w3.org/2005/Atom'; declare namespace media='http://search.yahoo.com/mrss/';" XmlRole { name: "title"; query: "title/string()" } XmlRole { name: "thumbnail" query: "media:group/media:thumbnail[1]/@url/string()"
  • 20. ListView で解析結果を表示 ListView { id: videolist model: ytlist delegate: Column{ Image { source: thumbnail } Text {text: title} } anchors.top: in_keyword.bottom anchors.margins: 10 width: parent.width / 2 height: parent.height
  • 21. 動画プレイヤー部分の作成 ● ブラウザコンポーネント (WebView) 上に YouTube の Embedded player を貼り付け ● http://www.youtube.com/embed/VIDEO_I D // ?html5=1 ● ?html5=1 は Flash 版ではなく HTML5 Player を使いたい場合に付ける
  • 22. 本当はよくない方法ですが... ● 本来は Video を用いるべきだが、デスクトッ プでの利用が面倒くさそうなので... ● モバイルならこちらの方が早いかも...
  • 23. WebView を追加 WebView { url: "http://www.youtube.com/embed/" + videoId" // Flash Player を有効化 settings.pluginsEnabled:true anchors.top: in_keyword.bottom anchors.left: videolist.right anchors.right: parent.right anchors.bottom: parent.bottom anchors.margins: 10 }
  • 24. YouTube 動画 ID <feed ...> <entry> <media:group> <yt:videoid>CL-vIg4Ivqw</yt:videoid> </media:group> </entry> </feed> XPath は “/feed/entry/media:group/yt:videoid”
  • 25. XmlListModel で XML を解析 XmlListModel { id: ytlist source: "http://gdata.youtube.com/feeds/api/videos? v=2&q=キーワード" query: "/feed/entry" NamespaceDeclarations:"... declare namespace yt='http://gdata.youtube.com/schemas/2007';" XmlRole { … } // 前の XmlRole は省略 XmlRole { name: "videoId" query: "media:group/yt:videoid/string()" }
  • 26. ListView にクリックイベントを ListView { 追加 id: videolist model: ytlist delegate: Column{ Image { source: thumbnail } Text {text: title} MouseArea { anchors.fill: parent onClicked: { videoplayer.url = "http://www.youtube.com/embed/" + videoId } } } ... }
  • 27. 検索ボタンにクリックイベントを Rectangle { 追加 id: rectangle1 ... Text { id: text2 text: "Search" } MouseArea { anchors.fill: parent onClicked: { ytlist.source = "http://gdata.youtube.com/feeds/api/videos?v=2&q=" + text_input1.text } } }
  • 28. End of Slides ● 本日のスライド ● http://slidesha.re/obeI9k ● 本日のコード ● http://bit.ly/oeuejD ● zip: http://bit.ly/oJHauZ

Hinweis der Redaktion

  1. Web 系の開発で言うと、QML が HTML に対応して、C++ が PHP や Java などに対応。(JS は JS) .NET で言うと、QML は XAML、C++ は VC++ とか C# とか VB とか。
  2. &lt;entry&gt;...&lt;/entry&gt; の部分がビデオ一個分