表示文字をvideo idから動画タイトルに変更
関連動画を得たときにすべての情報を保持するように変更
| @@ -29,10 +29,10 @@ | ||
| 29 | 29 | public: |
| 30 | 30 | virtual ~NicoNode(); |
| 31 | 31 | |
| 32 | - const NicoThumbInfo *getThumbInfo() const | |
| 33 | - { return thumbinfo; } | |
| 32 | + const NicoThumbInfo& getThumbInfo() const | |
| 33 | + { return *thumbinfo; } | |
| 34 | 34 | |
| 35 | - void setNicoThumbInfo(NicoThumbInfo *nico_thumbinfo); | |
| 35 | + void setNicoThumbInfo(const NicoThumbInfo& nico_thumbinfo); | |
| 36 | 36 | |
| 37 | 37 | protected: |
| 38 | 38 | NicoNode(GraphWidget *widget,QString video_id); |
| @@ -31,7 +31,7 @@ | ||
| 31 | 31 | setViewportUpdateMode(BoundingRectViewportUpdate); |
| 32 | 32 | setRenderHint(QPainter::Antialiasing); |
| 33 | 33 | |
| 34 | - timerId = startTimer(200); | |
| 34 | + timerId = startTimer(50); | |
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | void GraphWidget::nodeUpdate() |
| @@ -26,7 +26,7 @@ | ||
| 26 | 26 | #include <QStyleOption> |
| 27 | 27 | |
| 28 | 28 | Node::Node(GraphWidget *widget) : |
| 29 | - graphwidget(widget), node_factory(0), fixed(false) | |
| 29 | + graphwidget(widget), node_factory(0), paint_scale(1),fixed(false) | |
| 30 | 30 | { |
| 31 | 31 | setFlag(ItemIsMovable); |
| 32 | 32 | setCacheMode(DeviceCoordinateCache); |
| @@ -129,6 +129,13 @@ | ||
| 129 | 129 | node_factory = factory; |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | +void Node::setPaintScale(const float scale) | |
| 133 | +{ | |
| 134 | + this->scale(1.0/paint_scale,1.0/paint_scale); | |
| 135 | + paint_scale = scale; | |
| 136 | + this->scale(paint_scale,paint_scale); | |
| 137 | +} | |
| 138 | + | |
| 132 | 139 | QVariant Node::itemChange(GraphicsItemChange change, const QVariant &value) |
| 133 | 140 | { |
| 134 | 141 | if(change==ItemPositionHasChanged) |
| @@ -80,16 +80,54 @@ | ||
| 80 | 80 | |
| 81 | 81 | // related videoをXMLデータから抽出 |
| 82 | 82 | QList<QString> related_video_id; |
| 83 | - getRelatedVideo(related_video_id, xml); | |
| 83 | + QList<NicoThumbInfo> video_infos = getRelatedVideoInfo(xml); | |
| 84 | 84 | |
| 85 | 85 | // related videoのノードを新たに作る |
| 86 | - createRelatedNode(related_video_id); | |
| 86 | + createRelatedNode(video_infos); | |
| 87 | 87 | } |
| 88 | 88 | |
| 89 | -void NicoNodeFactory::getRelatedVideo(QList<QString>& related_video_id, QString& xml) | |
| 89 | + void NicoNodeFactory::getRelatedVideo(QList<QString>& related_video_id, QString& xml) | |
| 90 | + { | |
| 91 | + if(xml.isEmpty()) | |
| 92 | + return; | |
| 93 | + | |
| 94 | + QDomDocument document("related_video"); | |
| 95 | + QString errorMsg; | |
| 96 | + int errorLine, errorColumn; | |
| 97 | + if(!document.setContent(xml, &errorMsg, &errorLine, &errorColumn)) | |
| 98 | + { | |
| 99 | + qDebug() << errorMsg; | |
| 100 | + return; | |
| 101 | + } | |
| 102 | + | |
| 103 | + QDomElement related_video = document.elementsByTagName("related_video") | |
| 104 | + .item(0) | |
| 105 | + .toElement(); | |
| 106 | + if(related_video.attribute("status")!="ok") | |
| 107 | + { | |
| 108 | + qDebug() << tr("xml status error"); | |
| 109 | + return; | |
| 110 | + } | |
| 111 | + | |
| 112 | + QDomNodeList videos = related_video.elementsByTagName("video"); | |
| 113 | + if(videos.size()==0) | |
| 114 | + { | |
| 115 | + qDebug() << tr("ハズレ"); | |
| 116 | + } | |
| 117 | + | |
| 118 | + related_video_id.clear(); | |
| 119 | + for(int i=0;i<videos.size();++i) | |
| 120 | + { | |
| 121 | + const QDomNode& dom_node = videos.item(i); | |
| 122 | + QUrl url(dom_node.firstChildElement("url").text()); | |
| 123 | + QString video_id = UrlToId(url); | |
| 124 | + related_video_id.push_back(video_id); | |
| 125 | + } | |
| 126 | + } | |
| 127 | +QList<NicoThumbInfo> NicoNodeFactory::getRelatedVideoInfo(const QString& xml) | |
| 90 | 128 | { |
| 91 | 129 | if(xml.isEmpty()) |
| 92 | - return; | |
| 130 | + return QList<NicoThumbInfo>(); | |
| 93 | 131 | |
| 94 | 132 | QDomDocument document("related_video"); |
| 95 | 133 | QString errorMsg; |
| @@ -97,7 +135,7 @@ | ||
| 97 | 135 | if(!document.setContent(xml, &errorMsg, &errorLine, &errorColumn)) |
| 98 | 136 | { |
| 99 | 137 | qDebug() << errorMsg; |
| 100 | - return; | |
| 138 | + return QList<NicoThumbInfo>(); | |
| 101 | 139 | } |
| 102 | 140 | |
| 103 | 141 | QDomElement related_video = document.elementsByTagName("related_video") |
| @@ -106,7 +144,7 @@ | ||
| 106 | 144 | if(related_video.attribute("status")!="ok") |
| 107 | 145 | { |
| 108 | 146 | qDebug() << tr("xml status error"); |
| 109 | - return; | |
| 147 | + return QList<NicoThumbInfo>(); | |
| 110 | 148 | } |
| 111 | 149 | |
| 112 | 150 | QDomNodeList videos = related_video.elementsByTagName("video"); |
| @@ -115,28 +153,40 @@ | ||
| 115 | 153 | qDebug() << tr("ハズレ"); |
| 116 | 154 | } |
| 117 | 155 | |
| 118 | - related_video_id.clear(); | |
| 156 | + QList<NicoThumbInfo> infos; | |
| 119 | 157 | for(int i=0;i<videos.size();++i) |
| 120 | 158 | { |
| 159 | + NicoThumbInfo info; | |
| 121 | 160 | const QDomNode& dom_node = videos.item(i); |
| 122 | - QUrl url(dom_node.firstChildElement("url").text()); | |
| 123 | - QString video_id = UrlToId(url); | |
| 124 | - related_video_id.push_back(video_id); | |
| 161 | + info.video_id = UrlToId(QUrl(dom_node.firstChildElement("url").text())); | |
| 162 | + info.title = dom_node.firstChildElement("title").text(); | |
| 163 | + info.description = tr("untaken"); | |
| 164 | + info.thumbnail_url = QUrl(dom_node.firstChildElement("thumbnail").text()); | |
| 165 | + info.mylist_counter = dom_node.firstChildElement("time").text().toInt(); | |
| 166 | + info.length = dom_node.firstChildElement("length").text(); | |
| 167 | + info.view_counter = dom_node.firstChildElement("view").text().toInt(); | |
| 168 | + info.comment_num = dom_node.firstChildElement("comment").text().toInt(); | |
| 169 | + info.mylist_counter = dom_node.firstChildElement("mylist").text().toInt(); | |
| 170 | + info.watch_url = QUrl(dom_node.firstChildElement("url").text()); | |
| 171 | + info.thumb_type = tr("untaken"); | |
| 172 | + // info.tags = QList<QString>(); | |
| 173 | + infos.push_back(info); | |
| 125 | 174 | } |
| 175 | + return infos; | |
| 126 | 176 | } |
| 127 | 177 | |
| 128 | -void NicoNodeFactory::createRelatedNode(QList<QString>& related_video_id) | |
| 178 | +void NicoNodeFactory::createRelatedNode(QList<NicoThumbInfo>& infos) | |
| 129 | 179 | { |
| 130 | - if(related_video_id.isEmpty()) | |
| 180 | + if(infos.isEmpty()) | |
| 131 | 181 | return; |
| 132 | 182 | |
| 133 | 183 | const int append_max_node = 15; // 追加最大数 |
| 134 | 184 | |
| 135 | - int node_num = qMin(append_max_node, related_video_id.size()); | |
| 185 | + int node_num = qMin(append_max_node, infos.size()); | |
| 136 | 186 | |
| 137 | 187 | for(int i=0;i<node_num;++i) |
| 138 | 188 | { |
| 139 | - QString& video_id = related_video_id[i]; | |
| 189 | + QString& video_id = infos[i].video_id; | |
| 140 | 190 | |
| 141 | 191 | // このvideo_idがすでにNodeになっていないか調べる |
| 142 | 192 | // すでにNodeがあればEdgeを作る |
| @@ -155,6 +205,9 @@ | ||
| 155 | 205 | { |
| 156 | 206 | graph()->scene()->addItem(new Edge(source_node,dest)); |
| 157 | 207 | edge=true; |
| 208 | + | |
| 209 | + // Nodeの情報を更新する | |
| 210 | + dest->setNicoThumbInfo(infos[i]); | |
| 158 | 211 | break; |
| 159 | 212 | } |
| 160 | 213 | } |
| @@ -163,6 +216,7 @@ | ||
| 163 | 216 | |
| 164 | 217 | // 新しくNodeを作る |
| 165 | 218 | NicoNode *new_node = new NicoNode(graph(), video_id); |
| 219 | + new_node->setNicoThumbInfo(infos[i]); | |
| 166 | 220 | QPointF pos(source_node->pos().x()+rand()%50-100, |
| 167 | 221 | source_node->pos().y()+rand()%50-100); |
| 168 | 222 | new_node->setPos(pos); |
| @@ -19,6 +19,7 @@ | ||
| 19 | 19 | |
| 20 | 20 | #include "node_factory.h" |
| 21 | 21 | #include "nico_videoid.h" |
| 22 | +#include "nico_thumbinfo.h" | |
| 22 | 23 | #include <QNetworkAccessManager> |
| 23 | 24 | #include <QPointF> |
| 24 | 25 |
| @@ -37,7 +38,8 @@ | ||
| 37 | 38 | QNetworkAccessManager network_manager; |
| 38 | 39 | |
| 39 | 40 | void getRelatedVideo(QList<QString>& related, QString& xml); |
| 40 | - void createRelatedNode(QList<QString>& related); | |
| 41 | + QList<NicoThumbInfo> getRelatedVideoInfo(const QString& xml); | |
| 42 | + void createRelatedNode(QList<NicoThumbInfo>& infos); | |
| 41 | 43 | |
| 42 | 44 | public slots: |
| 43 | 45 | void downloadFinished(QNetworkReply *reply); |
| @@ -54,6 +54,8 @@ | ||
| 54 | 54 | |
| 55 | 55 | void setNodeFactory(NodeFactory *factory); |
| 56 | 56 | |
| 57 | + void setPaintScale(const float scale); | |
| 58 | + | |
| 57 | 59 | protected: |
| 58 | 60 | QVariant itemChange(GraphicsItemChange change, const QVariant &value); |
| 59 | 61 | void mousePressEvent(QGraphicsSceneMouseEvent *event); |
| @@ -74,6 +76,7 @@ | ||
| 74 | 76 | QList<Edge *> edgeList; |
| 75 | 77 | GraphWidget *graphwidget; |
| 76 | 78 | NodeFactory *node_factory; |
| 79 | + float paint_scale; | |
| 77 | 80 | bool fixed; |
| 78 | 81 | }; |
| 79 | 82 |
| @@ -20,6 +20,7 @@ | ||
| 20 | 20 | |
| 21 | 21 | #include <QDebug> |
| 22 | 22 | #include <QString> |
| 23 | +#include <cmath> | |
| 23 | 24 | |
| 24 | 25 | NicoNode::NicoNode(GraphWidget *widget, QString video_id) : |
| 25 | 26 | Node(widget) |
| @@ -41,22 +42,14 @@ | ||
| 41 | 42 | delete node_factory; |
| 42 | 43 | } |
| 43 | 44 | |
| 44 | -void NicoNode::setNicoThumbInfo(NicoThumbInfo *nico_thumbinfo) | |
| 45 | +void NicoNode::setNicoThumbInfo(const NicoThumbInfo& nico_thumbinfo) | |
| 45 | 46 | { |
| 46 | - if(nico_thumbinfo==0) | |
| 47 | - { | |
| 48 | - qDebug() << "NicoNode::setNicoThumbInfo warning #1"; | |
| 49 | - return; | |
| 50 | - } | |
| 47 | + *thumbinfo = nico_thumbinfo; | |
| 48 | + setName(thumbinfo->title); | |
| 51 | 49 | |
| 52 | - if(nico_thumbinfo==thumbinfo) | |
| 53 | - { | |
| 54 | - qDebug() << "NicoNode::setNicoThumbInfo warning #2"; | |
| 55 | - return; | |
| 56 | - } | |
| 57 | - | |
| 58 | - delete thumbinfo; | |
| 59 | - thumbinfo = nico_thumbinfo; | |
| 50 | + float scale = (2.0-3e5/(thumbinfo->comment_num+3e5)); | |
| 51 | + setPaintScale(scale); | |
| 52 | + qDebug() << "scale: " << scale ; | |
| 60 | 53 | } |
| 61 | 54 | |
| 62 | 55 | void NicoNode::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) |