nodebrowser.cpp
1 /***************************************************************************
2  Copyright (C) 2002-2015 Kentaro Kitagawa
3  kitagawa@phys.s.u-tokyo.ac.jp
4 
5  This program is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Library General Public
7  License as published by the Free Software Foundation; either
8  version 2 of the License, or (at your option) any later version.
9 
10  You should have received a copy of the GNU Library General
11  Public License and a list of authors along with this program;
12  see the files COPYING and AUTHORS.
13  ***************************************************************************/
14 //---------------------------------------------------------------------------
15 #include "nodebrowser.h"
16 #include "measure.h"
17 #include <QLineEdit>
18 #include <QCursor>
19 #include <QTimer>
20 #include <QTextBrowser>
21 #include <QApplication>
22 
23 #include "ui_nodebrowserform.h"
24 
25 XNodeBrowser::XNodeBrowser
26 (const shared_ptr<XNode> &root, FrmNodeBrowser *form)
27  : XQConnector(root, form),
28  m_root(root),
29  m_pForm(form),
30  m_desc(XNode::createOrphan<XStringNode>("Desc", true)),
31  m_conDesc(xqcon_create<XQTextBrowserConnector>(m_desc, form->m_txtDesc)) {
32 
33  m_pTimer = new QTimer(this);
34  connect(m_pTimer, SIGNAL (timeout() ), this, SLOT(process()));
35  m_pTimer->start(500);
36  form->m_txtDesc->setAcceptRichText(true);
37 }
38 
39 XNodeBrowser::~XNodeBrowser() {
40  m_pTimer->stop();
41 }
42 shared_ptr<XNode>
43 XNodeBrowser::connectedNode(QWidget *widget) {
44  if( !widget || (widget == m_pForm->m_txtDesc) ||
45  (widget == m_pForm->m_edValue) || (widget == m_pForm)) {
46  return shared_ptr<XNode>();
47  }
48  return XQConnector::connectedNode(widget);
49 }
50 
51 void
52 XNodeBrowser::process() {
53  QWidget *widget;
54  shared_ptr<XNode> node;
55  // widget = KApplication::kApplication()->focusWidget();
56  // node = connectedNode(widget);
57  if( !node) {
58  widget = QApplication::widgetAt(QCursor::pos());
59  node = connectedNode(widget);
60  if( !node && widget) {
61  widget = widget->parentWidget();
62  node = connectedNode(widget);
63  if( !node && widget) {
64  widget = widget->parentWidget();
65  node = connectedNode(widget);
66  }
67  }
68  }
69 
70  if( !node)
71  node = m_lastPointed;
72  if((node != m_lastPointed) && node) {
73  Snapshot shot( *node);
74  auto valuenode(dynamic_pointer_cast<XValueNodeBase>(node));
75  auto listnode(dynamic_pointer_cast<XListNodeBase>(node));
76 
77  m_conValue.reset();
78  if(valuenode)
79  m_conValue = xqcon_create<XQLineEditConnector>(valuenode, m_pForm->m_edValue);
80  else
81  m_pForm->m_edValue->setText("");
82  QString str;
83  str += "<font color=#005500>Label:</font> ";
84  str += node->getLabel().c_str();
85  // str += "\nName: ";
86  // str += node->getName();
87  str += "<br>";
88  if( !shot[ *node].isUIEnabled()) str+= "UI/scripting disabled.<br>";
89  if(shot[ *node].isRuntime()) str+= "For run-time only.<br>";
90  str += "<font color=#005500>Type:</font> ";
91  str += node->getTypename().c_str();
92  str += "<br>";
93  XString rbpath;
94  XNode *cnode = node.get();
95  shared_ptr<XNode> rootnode(m_root);
96  Snapshot rootshot( *rootnode);
97  while(cnode) {
98  if((rbpath.length() > 64) ||
99  (cnode == m_root.lock().get())) {
100  str += "<font color=#550000>Ruby object:</font><br> Measurement";
101  str += rbpath.c_str();
102  str += "<br><font color=#550000>Supported Ruby methods:</font>"
103  " name() touch() child(<font color=#000088><i>name/idx</i></font>)"
104  " [](<font color=#000088><i>name/idx</i></font>) count() each() to_ary()";
105  if(valuenode)
106  str += " set(<font color=#000088><i>x</i></font>)"
107  " value=<font color=#000088><i>x</i></font> load(<font color=#000088><i>x</i></font>)"
108  " &lt;&lt;<font color=#000088><i>x</i></font> get() value() to_str()";
109  if(listnode)
110  str += " create(<font color=#000088><i>type</i></font>, <font color=#000088><i>name</i></font>)"
111  " release()";
112  str += "<br>";
113  break;
114  }
115  rbpath = formatString("[\"%s\"]%s", cnode->getName().c_str(), rbpath.c_str());
116  cnode = cnode->upperNode(rootshot);
117  }
118  if( !cnode) {
119  // str += rbpath;
120  str += "Inaccessible from the root.<br>";
121  }
122  if(shot.size()) {
123  str += formatString("<font color=#005500>%u Child(ren):</font> <br>", (unsigned int)shot.list()->size()).c_str();
124  for(auto it = shot.list()->begin(); it != shot.list()->end(); ++it) {
125  str += " ";
126  str += ( *it)->getName().c_str();
127  }
128  str += "<br>";
129  }
130  trans( *m_desc).str(str);
131  }
132  m_lastPointed = node;
133 }

Generated for KAME4 by  doxygen 1.8.3