graphpainter.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 #include "graphpainter.h"
15 #include "measure.h"
16 #include "graphwidget.h"
17 #include <QFont>
18 #include <QFontMetrics>
19 #include <QPainter>
20 
21 #define SELECT_WIDTH 0.02
22 #define SELECT_DEPTH 0.1
23 
24 using std::min;
25 using std::max;
26 
27 float
29  return 1.0f / max(m_pItem->width(), m_pItem->height());
30 }
31 
32 void
33 XQGraphPainter::repaintGraph(int x1, int y1, int x2, int y2) {
34  repaintBuffer(x1, y1, x2, y2);
35 }
36 
37 void
39  XGraph::ScrPoint *src, XGraph::SFloat offset) {
40  XGraph::ScrPoint scr, dir_proj;
41  windowToScreen(m_pItem->width() / 2, m_pItem->height() / 2, 0.0, &scr);
42  windowToScreen(m_pItem->width() / 2, m_pItem->height() / 2, 1.0, &dir_proj);
43  dir_proj -= scr;
44  dir_proj.normalize();
45  double x, y, z;
46  if(screenToWindow(*src, &x, &y, &z)) return;
47  x = x / m_pItem->width() - 0.5;
48  y = y / m_pItem->height() - 0.5;
49  double r1 = x*x + y*y;
50  XGraph::ScrPoint s1 = dir_proj;
51  s1.vectorProduct(dir);
52  s1.normalize();
53  s1 *= offset;
54  *src += s1;
55  int ret = screenToWindow(*src, &x, &y, &z);
56  x = x / m_pItem->width() - 0.5;
57  y = y / m_pItem->height() - 0.5;
58  double r2 = x*x + y*y;
59  if(ret || ((r2 - r1) * offset < 0) ) {
60  *src -= s1;
61  *src -= s1;
62  }
63 }
64 
65 shared_ptr<XAxis>
66 XQGraphPainter::findAxis(const Snapshot &shot, const XGraph::ScrPoint &s1) {
67  shared_ptr<XAxis> found_axis;
68  double zmin = 0.1;
69  if(shot.size(m_graph->axes())) {
70  const XNode::NodeList &axes_list( *shot.list(m_graph->axes()));
71  for(auto it = axes_list.begin(); it != axes_list.end(); it++) {
72  auto axis = dynamic_pointer_cast<XAxis>(*it);
73  XGraph::SFloat z1;
75  axis->axisToScreen(shot, axis->screenToAxis(shot, s1), &s2);
76  z1 = sqrtf(s1.distance2(s2));
77  if(zmin > z1) {
78  zmin = z1;
79  found_axis = axis;
80  }
81  }
82  }
83  return found_axis;
84 }
85 shared_ptr<XPlot>
86 XQGraphPainter::findPlane(const Snapshot &shot, const XGraph::ScrPoint &s1,
87  shared_ptr<XAxis> *axis1, shared_ptr<XAxis> *axis2) {
88  double zmin = 0.1;
89  shared_ptr<XPlot> plot_found;
90  if(shot.size(m_graph->plots())) {
91  const auto &plots_list( *shot.list(m_graph->plots()));
92  for(auto it = plots_list.begin(); it != plots_list.end(); it++) {
93  shared_ptr<XPlot> plot = dynamic_pointer_cast<XPlot>( *it);
94  XGraph::GPoint g1;
95  shared_ptr<XAxis> axisx = shot[ *plot->axisX()];
96  shared_ptr<XAxis> axisy = shot[ *plot->axisY()];
97  shared_ptr<XAxis> axisz = shot[ *plot->axisZ()];
98  if( !axisx || !axisy)
99  continue;
100  plot->screenToGraph(shot, s1, &g1);
101  if((fabs(g1.x) < zmin) && axisz) {
102  plot_found = plot;
103  zmin = fabs(g1.x);
104  *axis1 = axisy;
105  *axis2 = axisz;
106  }
107  if((fabs(g1.y) < zmin) && axisz) {
108  plot_found = plot;
109  zmin = fabs(g1.y);
110  *axis1 = axisx;
111  *axis2 = axisz;
112  }
113  if(fabs(g1.z) < zmin) {
114  plot_found = plot;
115  zmin = fabs(g1.z);
116  *axis1 = axisx;
117  *axis2 = axisy;
118  }
119  }
120  }
121  return plot_found;
122 }
123 
124 void
125 XQGraphPainter::selectObjs(int x, int y, SelectionState state, SelectionMode mode) {
126  m_pointerLastPos[0] = x;
127  m_pointerLastPos[1] = y;
128 
129  if(m_bReqHelp) {
130  if(state != SelStart) return;
131  m_bReqHelp = false;
132  return;
133  }
134  double z;
135 
136  m_selectionStateNow = state;
137  switch(state) {
138  case SelStart:
139  m_selectionModeNow = mode;
140  m_selStartPos[0] = x;
141  m_selStartPos[1] = y;
142  m_tiltLastPos[0] = x;
143  m_tiltLastPos[1] = y;
144  switch(mode) {
145  case SelPlane:
146  m_foundPlane.reset();
147  z = selectPlane(x, y,
148  (int)(SELECT_WIDTH * m_pItem->width()),
149  (int)(SELECT_WIDTH * m_pItem->height()),
150  &m_startScrPos, &m_startScrDX, &m_startScrDY);
151  if(z < 1.0)
152  m_foundPlane = findPlane(Snapshot( *m_graph), m_startScrPos, &m_foundPlaneAxis1, &m_foundPlaneAxis2);
153  m_finishScrPos = m_startScrPos;
154  break;
155  case SelAxis:
156  m_foundAxis.reset();
157  z = selectAxis(x, y,
158  (int)(SELECT_WIDTH * m_pItem->width()),
159  (int)(SELECT_WIDTH * m_pItem->height()),
160  &m_startScrPos, &m_startScrDX, &m_startScrDY);
161  if(z < 1.0) m_foundAxis = findAxis(Snapshot( *m_graph), m_startScrPos);
162  m_finishScrPos = m_startScrPos;
163  break;
164  default:
165  break;
166  }
167  break;
168  case Selecting:
169  //restore mode
170  mode = m_selectionModeNow;
171  break;
172  case SelFinish:
173  //restore mode
174  mode = m_selectionModeNow;
175  m_selectionModeNow = SelNone;
176  break;
177  }
178  switch(mode) {
179  case SelNone:
180  m_foundPlane.reset();
181  z = selectPlane(x, y,
182  (int)(SELECT_WIDTH * m_pItem->width()),
183  (int)(SELECT_WIDTH * m_pItem->height()),
184  &m_finishScrPos, &m_finishScrDX, &m_finishScrDY);
185  if(z < 1.0)
186  m_foundPlane = findPlane(Snapshot( *m_graph), m_finishScrPos, &m_foundPlaneAxis1, &m_foundPlaneAxis2);
187  break;
188  case SelPlane:
189  selectPlane(x, y,
190  (int)(SELECT_WIDTH * m_pItem->width()),
191  (int)(SELECT_WIDTH * m_pItem->height()),
192  &m_finishScrPos, &m_finishScrDX, &m_finishScrDY);
193  break;
194  case SelAxis:
195  selectAxis(x, y,
196  (int)(SELECT_WIDTH * m_pItem->width()),
197  (int)(SELECT_WIDTH * m_pItem->height()),
198  &m_finishScrPos, &m_finishScrDX, &m_finishScrDY);
199  break;
200  case TiltTracking:
201  {
202  float x0 = (float)m_tiltLastPos[0] / m_pItem->width() - 0.5;
203  float y0 = (1.0f - (float)m_tiltLastPos[1] / m_pItem->height()) - 0.5;
204  float z0 = 0.5;
205  float x1 = (float)x / m_pItem->width() - 0.5;
206  float y1 = (1.0f - (float)y / m_pItem->height()) - 0.5;
207  float z1 = z0;
208  float x2, y2, z2;
209  x2 = y0 * z1 - z0 * y1;
210  y2 = z0 * x1 - x0 * z1;
211  z2 = x0 * y1 - y0 * x1;
212  float k = sqrt(x2*x2 + y2*y2 + z2*z2);
213  x2 /= k; y2 /= k; z2 /= k;
214  viewRotate( -pow(k/(z0/4), 1.4f)*90, x2, y2, z2);
215  m_tiltLastPos[0] = x;
216  m_tiltLastPos[1] = y;
217  }
218  break;
219  default:
220  break;
221  }
222  if(state == SelFinish) {
223  if((abs(x - m_selStartPos[0]) < 3) && (abs(y - m_selStartPos[1]) < 3)) {
224  switch(mode) {
225  case SelPlane:
226  break;
227  case SelAxis:
228  m_graph->iterate_commit([=](Transaction &tr){
229  if( !m_foundAxis) {
230  //Autoscales all axes
231  if(tr.size(m_graph->axes())) {
232  const auto &axes_list( *tr.list(m_graph->axes()));
233  for(auto it = axes_list.begin(); it != axes_list.end(); it++) {
234  shared_ptr<XAxis> axis = static_pointer_cast<XAxis>(*it);
235  if(tr[ *axis->autoScale()].isUIEnabled())
236  tr[ *axis->autoScale()] = true;
237  }
238  }
239  }
240  else {
241  if(tr[ *m_foundAxis->autoScale()].isUIEnabled())
242  tr[ *m_foundAxis->autoScale()] = true;
243  }
244  });
245  break;
246  case TiltTracking:
247  viewRotate(0.0, 0.0, 0.0, 0.0, true);
248  break;
249  default:
250  break;
251  }
252  }
253  else {
254  m_graph->iterate_commit([=](Transaction &tr){
255  switch(mode) {
256  case SelPlane:
257  if(m_foundPlane && !(m_startScrPos == m_finishScrPos) ) {
258  XGraph::VFloat src1 = m_foundPlaneAxis1->screenToVal(tr, m_startScrPos);
259  XGraph::VFloat src2 = m_foundPlaneAxis2->screenToVal(tr, m_startScrPos);
260  XGraph::VFloat dst1 = m_foundPlaneAxis1->screenToVal(tr, m_finishScrPos);
261  XGraph::VFloat dst2 = m_foundPlaneAxis2->screenToVal(tr, m_finishScrPos);
262 
263  if(tr[ *m_foundPlaneAxis1->minValue()].isUIEnabled())
264  tr[ *m_foundPlaneAxis1->minValue()] = double(min(src1, dst1));
265  if(tr[ *m_foundPlaneAxis1->maxValue()].isUIEnabled())
266  tr[ *m_foundPlaneAxis1->maxValue()] = double(max(src1, dst1));
267  if(tr[ *m_foundPlaneAxis1->autoScale()].isUIEnabled())
268  tr[ *m_foundPlaneAxis1->autoScale()] = false;
269  if(tr[ *m_foundPlaneAxis2->minValue()].isUIEnabled())
270  tr[ *m_foundPlaneAxis2->minValue()] = double(min(src2, dst2));
271  if(tr[ *m_foundPlaneAxis2->maxValue()].isUIEnabled())
272  tr[ *m_foundPlaneAxis2->maxValue()] = double(max(src2, dst2));
273  if(tr[ *m_foundPlaneAxis2->autoScale()].isUIEnabled())
274  tr[ *m_foundPlaneAxis2->autoScale()] = false;
275 
276  }
277  break;
278  case SelAxis:
279  if(m_foundAxis && !(m_startScrPos == m_finishScrPos) ) {
280  XGraph::VFloat src = m_foundAxis->screenToVal(tr, m_startScrPos);
281  XGraph::VFloat dst = m_foundAxis->screenToVal(tr, m_finishScrPos);
282  double _min = std::min(src, dst);
283  double _max = std::max(src, dst);
284  if(tr[ *m_foundAxis->minValue()].isUIEnabled())
285  tr[ *m_foundAxis->minValue()] = _min;
286  if(tr[ *m_foundAxis->maxValue()].isUIEnabled())
287  tr[ *m_foundAxis->maxValue()] = _max;
288  if(tr[ *m_foundAxis->autoScale()].isUIEnabled())
289  tr[ *m_foundAxis->autoScale()] = false;
290  }
291  break;
292  default:
293  break;
294  }
295  });
296  }
297  }
298 
299  repaintGraph(0, 0, m_pItem->width(), m_pItem->height() );
300 }
301 
302 void
303 XQGraphPainter::wheel(int x, int y, double deg)
304 {
305  if(fabs(deg) < 1.0) return;
306  double a = ((double)x / m_pItem->width() - 0.5);
307  double b = ((double)y / m_pItem->height() - 0.5);
308  if( max(fabs(a), fabs(b)) < 0.35) {
309  zoom(min(1.15, max(0.85, exp(deg * 0.04))), x, y);
310  }
311  else {
312  if( (a - b) * (a + b) > 0 ) {
313  viewRotate(30.0 * deg / fabs(deg), -1.0, 0.0, 0.0, false);
314  }
315  else {
316  viewRotate(30.0 * deg / fabs(deg), 0.0, 1.0, 0.0, false);
317  }
318  repaintGraph(0, 0, m_pItem->width(), m_pItem->height() );
319  }
320 }
321 void
322 XQGraphPainter::zoom(double zoomscale, int , int ) {
323  XGraph::ScrPoint s1(0.5, 0.5, 0.5);
324 
325  m_graph->iterate_commit([=](Transaction &tr){
326  if(tr.size(m_graph->axes())) {
327  const auto &axes_list( *tr.list(m_graph->axes()));
328  for(auto it = axes_list.begin(); it != axes_list.end(); ++it) {
329  shared_ptr<XAxis> axis = static_pointer_cast<XAxis>( *it);
330  if(tr[ *axis->autoScale()].isUIEnabled())
331  tr[ *axis->autoScale()] = false;
332  }
333  }
334  m_graph->zoomAxes(tr, resScreen(), zoomscale, s1);
335  });
336 }
337 void
338 XQGraphPainter::onRedraw(const Snapshot &, XGraph *graph) {
339  redrawOffScreen();
340  repaintGraph(0, 0, m_pItem->width(), m_pItem->height() );
341 }
342 void
344  QString msg = "";
345 // if(SelectionStateNow != Selecting) return;
346  switch ( m_selectionModeNow ) {
347  case SelNone:
348  if(m_foundPlane) {
349  XGraph::VFloat dst1 = m_foundPlaneAxis1->screenToVal(shot, m_finishScrPos);
350  XGraph::VFloat dst1dx = m_foundPlaneAxis1->screenToVal(shot, m_finishScrDX) - dst1;
351  XGraph::VFloat dst1dy = m_foundPlaneAxis1->screenToVal(shot, m_finishScrDY) - dst1;
352  XGraph::VFloat dst2 = m_foundPlaneAxis2->screenToVal(shot, m_finishScrPos);
353  XGraph::VFloat dst2dx = m_foundPlaneAxis2->screenToVal(shot, m_finishScrDX) - dst2;
354  XGraph::VFloat dst2dy = m_foundPlaneAxis2->screenToVal(shot, m_finishScrDY) - dst2;
355 
356  dst1 = setprec(dst1, sqrt(dst1dx*dst1dx + dst1dy*dst1dy));
357  dst2 = setprec(dst2, sqrt(dst2dx*dst2dx + dst2dy*dst2dy));
358  msg += QString("(%1, %2)")
359  .arg(m_foundPlaneAxis1->valToString(dst1).c_str())
360  .arg(m_foundPlaneAxis2->valToString(dst2).c_str());
361  }
362  else {
363  msg = i18n("R-DBL-CLICK TO SHOW HELP");
364  }
365  break;
366  case SelPlane:
367  if(m_foundPlane && !(m_startScrPos == m_finishScrPos) ) {
368  XGraph::VFloat src1 = m_foundPlaneAxis1->screenToVal(shot, m_startScrPos);
369  XGraph::VFloat src1dx = m_foundPlaneAxis1->screenToVal(shot, m_startScrDX) - src1;
370  XGraph::VFloat src1dy = m_foundPlaneAxis1->screenToVal(shot, m_startScrDY) - src1;
371  XGraph::VFloat src2 = m_foundPlaneAxis2->screenToVal(shot, m_startScrPos);
372  XGraph::VFloat src2dx = m_foundPlaneAxis2->screenToVal(shot, m_startScrDX) - src2;
373  XGraph::VFloat src2dy = m_foundPlaneAxis2->screenToVal(shot, m_startScrDY) - src2;
374  XGraph::VFloat dst1 = m_foundPlaneAxis1->screenToVal(shot, m_finishScrPos);
375  XGraph::VFloat dst1dx = m_foundPlaneAxis1->screenToVal(shot, m_finishScrDX) - dst1;
376  XGraph::VFloat dst1dy = m_foundPlaneAxis1->screenToVal(shot, m_finishScrDY) - dst1;
377  XGraph::VFloat dst2 = m_foundPlaneAxis2->screenToVal(shot, m_finishScrPos);
378  XGraph::VFloat dst2dx = m_foundPlaneAxis2->screenToVal(shot, m_finishScrDX) - dst2;
379  XGraph::VFloat dst2dy = m_foundPlaneAxis2->screenToVal(shot, m_finishScrDY) - dst2;
380 
381  src1 = setprec(src1, sqrt(src1dx*src1dx + src1dy*src1dy));
382  src2 = setprec(src2, sqrt(src2dx*src2dx + src2dy*src2dy));
383  dst1 = setprec(dst1, sqrt(dst1dx*dst1dx + dst1dy*dst1dy));
384  dst2 = setprec(dst2, sqrt(dst2dx*dst2dx + dst2dy*dst2dy));
385  msg += QString("(%1, %2) - (%3, %4)")
386  .arg(m_foundPlaneAxis1->valToString(src1).c_str())
387  .arg(m_foundPlaneAxis2->valToString(src2).c_str())
388  .arg(m_foundPlaneAxis1->valToString(dst1).c_str())
389  .arg(m_foundPlaneAxis2->valToString(dst2).c_str());
390 
391  XGraph::ScrPoint sd1, sd2;
392  m_foundPlaneAxis1->valToScreen(shot, dst1, &sd1);
393  m_foundPlaneAxis1->valToScreen(shot, src1, &sd2);
394  sd1 -= sd2;
395  sd1 += m_startScrPos;
396  XGraph::ScrPoint ss1, ss2;
397  m_foundPlaneAxis2->valToScreen(shot, dst2, &ss1);
398  m_foundPlaneAxis2->valToScreen(shot, src2, &ss2);
399  ss1 -= ss2;
400  ss1 += m_startScrPos;
401 
402  beginQuad(true);
403  setColor(clBlue, 0.2);
404  setVertex(m_startScrPos);
405  setVertex(sd1);
406  setVertex(m_finishScrPos);
407  setVertex(ss1);
408  endQuad();
409  }
410  break;
411  case SelAxis:
412  if(m_foundAxis && !(m_startScrPos == m_finishScrPos) ) {
413  XGraph::VFloat src = m_foundAxis->screenToVal(shot, m_startScrPos);
414  XGraph::VFloat srcdx = m_foundAxis->screenToVal(shot, m_startScrDX) - src;
415  XGraph::VFloat srcdy = m_foundAxis->screenToVal(shot, m_startScrDY) - src;
416  XGraph::VFloat dst = m_foundAxis->screenToVal(shot, m_finishScrPos);
417  XGraph::VFloat dstdx = m_foundAxis->screenToVal(shot, m_finishScrDX) - dst;
418  XGraph::VFloat dstdy = m_foundAxis->screenToVal(shot, m_finishScrDY) - dst;
419 
420  src = setprec(src, sqrt(srcdx*srcdx + srcdy*srcdy));
421  dst = setprec(dst, sqrt(dstdx*dstdx + dstdy*dstdy));
422 
423  msg += QString("%1 - %2")
424  .arg(m_foundAxis->valToString(src).c_str())
425  .arg(m_foundAxis->valToString(dst).c_str());
426 
427  XGraph::GFloat src1 = m_foundAxis->valToAxis(src);
428  XGraph::GFloat dst1 = m_foundAxis->valToAxis(dst);
429  beginQuad(true);
430  setColor( clRed, 0.4 );
431  XGraph::ScrPoint s1, s2, s3, s4;
432  m_foundAxis->axisToScreen(shot, src1, &s1);
433  posOffAxis(m_foundAxis->dirVector(), &s1, -0.02);
434  m_foundAxis->axisToScreen(shot, src1, &s2);
435  posOffAxis(m_foundAxis->dirVector(), &s2, +0.02);
436  m_foundAxis->axisToScreen(shot, dst1, &s3);
437  posOffAxis(m_foundAxis->dirVector(), &s3, +0.02);
438  m_foundAxis->axisToScreen(shot, dst1, &s4);
439  posOffAxis(m_foundAxis->dirVector(), &s4, -0.02);
440  setVertex(s1);
441  setVertex(s2);
442  setVertex(s3);
443  setVertex(s4);
444  endQuad();
445  beginLine();
446  setColor( clBlue, 1.0 );
447  m_foundAxis->axisToScreen(shot, src1, &s1);
448  posOffAxis(m_foundAxis->dirVector(), &s1, -0.1);
449  m_foundAxis->axisToScreen(shot, src1, &s2);
450  posOffAxis(m_foundAxis->dirVector(), &s2, 0.05);
451  setVertex(s1);
452  setVertex(s2);
453  m_foundAxis->axisToScreen(shot, dst1, &s1);
454  posOffAxis(m_foundAxis->dirVector(), &s1, -0.1);
455  m_foundAxis->axisToScreen(shot, dst1, &s2);
456  posOffAxis(m_foundAxis->dirVector(), &s2, 0.05);
457  setVertex(s1);
458  setVertex(s2);
459  endLine();
460  }
461  break;
462  case TiltTracking:
463  break;
464  default:
465  break;
466  }
467  m_onScreenMsg = msg;
468 }
469 void
470 XQGraphPainter::showHelp() {
471  m_bReqHelp = true;
472  repaintGraph(0, 0, m_pItem->width(), m_pItem->height());
473 }
474 void
476  //Draw Title
477  setColor(shot[ *m_graph->titleColor()]);
478  defaultFont();
479  m_curAlign = Qt::AlignTop | Qt::AlignHCenter;
480  drawText(XGraph::ScrPoint(0.5, 0.99, 0.01), shot[ *m_graph->label()]);
481 
482  if(m_onScreenMsg.length() ) {
483  selectFont(m_onScreenMsg, XGraph::ScrPoint(0.6, 0.05, 0.01), XGraph::ScrPoint(1, 0, 0), XGraph::ScrPoint(0, 0.05, 0), 0);
484  setColor(shot[ *m_graph->titleColor()]);
485  m_curAlign = Qt::AlignBottom | Qt::AlignLeft;
486  drawText(XGraph::ScrPoint(0.01, 0.01, 0.01), m_onScreenMsg);
487  }
488  //Legends
489  if(shot[ *m_graph->drawLegends()] &&
490  (m_selectionModeNow == SelNone)) {
491  if(shot.size(m_graph->plots())) {
492  const XNode::NodeList &plots_list( *shot.list(m_graph->plots()));
493  float z = 0.97;
494  float dy = 0.04;
495  float x1 = 0.75;
496  float y1 = 0.81;
497  if(m_pointerLastPos[0] > m_pItem->width() / 2)
498  x1 = 1.06f - x1;
499  if(m_pointerLastPos[1] < m_pItem->height() / 2)
500  y1 = 1.0f - y1 + plots_list.size() * dy;
501  float x2 = x1 - 0.01;
502  float x3 = x1 + 0.08;
503  defaultFont();
504  m_curAlign = Qt::AlignVCenter | Qt::AlignRight;
505  float y2 = y1;
506  for(auto it = plots_list.begin(); it != plots_list.end(); it++) {
507  auto plot = static_pointer_cast<XPlot>( *it);
508  selectFont(shot[ *plot->label()], XGraph::ScrPoint(x2,y2,z), XGraph::ScrPoint(1, 0, 0), XGraph::ScrPoint(0, dy, 0), 0);
509  y2 -= dy;
510  }
511  setColor(shot[ *m_graph->backGround()], 0.7);
512  beginQuad(true);
513  setVertex(XGraph::ScrPoint(x1, y1 + dy/2, z));
514  setVertex(XGraph::ScrPoint(x1, y2 + dy/2, z));
515  setVertex(XGraph::ScrPoint(x3, y2 + dy/2, z));
516  setVertex(XGraph::ScrPoint(x3, y1 + dy/2, z));
517  endQuad();
518  setColor(shot[ *m_graph->titleColor()], 0.05);
519  z = 0.98;
520  beginQuad(true);
521  setVertex(XGraph::ScrPoint(x1, y1 + dy/2, z));
522  setVertex(XGraph::ScrPoint(x1, y2 + dy/2, z));
523  setVertex(XGraph::ScrPoint(x3, y2 + dy/2, z));
524  setVertex(XGraph::ScrPoint(x3, y1 + dy/2, z));
525  endQuad();
526  m_curAlign = Qt::AlignVCenter | Qt::AlignRight;
527  float y = y1;
528  z = 0.99;
529  for(auto it = plots_list.begin(); it != plots_list.end(); it++) {
530  setColor(shot[ *m_graph->titleColor()], 1.0);
531  auto plot = static_pointer_cast<XPlot>( *it);
532  drawText(XGraph::ScrPoint(x2,y,z), shot[ *plot->label()]);
533  plot->drawLegend(shot, this, XGraph::ScrPoint((x3 + x1)/2, y, z),
534  (x3 - x1)/1.5f, dy/1.2f);
535  y -= dy;
536  }
537  }
538  }
539 }
540 void
541 XQGraphPainter::drawOnScreenHelp(const Snapshot &shot, QPainter *qpainter) {
542  double y = 1.0;
543  float z = 0.99;
544 
545  QColor cl(QRgb((unsigned int)shot[ *m_graph->backGround()]));
546  cl.setAlpha(lrint(0.3 * 255));
547  qpainter->fillRect(QRect(0, 0, m_pItem->width(), m_pItem->height()), cl);
548  cl = QColor(QRgb((unsigned int)shot[ *m_graph->titleColor()]));
549  cl.setAlpha(lrint(0.55 * 255));
550  qpainter->fillRect(QRect(0, 0, m_pItem->width(), m_pItem->height()), cl);
551  m_curTextColor = QRgb(shot[ *m_graph->backGround()]);
552 
553  defaultFont();
554  m_curAlign = Qt::AlignTop | Qt::AlignHCenter;
555  drawText(XGraph::ScrPoint(0.5, y, z), i18n("QUICK HELP!"));
556  m_curAlign = Qt::AlignVCenter | Qt::AlignLeft;
557  y -= 0.1;
558  double x = 0.1;
559  double dy = -y/10;
560  selectFont(i18n("Single Click Right Button on Axis : Auto-scale"), XGraph::ScrPoint(x,y,z), XGraph::ScrPoint(1, 0, 0), XGraph::ScrPoint(0, dy, 0), 0);
561 
562  drawText(XGraph::ScrPoint(x, y, z), i18n("Press Left Button on Plot : Manual Scale"));
563  y += dy;
564  drawText(XGraph::ScrPoint(x, y, z), i18n("Press Right Button along Axis: Manual Scale"));
565  y += dy;
566  drawText(XGraph::ScrPoint(x, y, z), i18n("Single Click Right Button on Axis : Auto-scale"));
567  y += dy;
568  drawText(XGraph::ScrPoint(x, y, z), i18n("Single Click Right Button elsewhere : Auto-scale all"));
569  y += dy;
570  drawText(XGraph::ScrPoint(x, y, z), i18n("Press Middle Button : Tilt plots"));
571  y += dy;
572  drawText(XGraph::ScrPoint(x, y, z), i18n("Single Click Middle Button : Reset tilting"));
573  y += dy;
574  drawText(XGraph::ScrPoint(x, y, z), i18n("Wheel around Center : (Un)Zoom all Plots"));
575  y += dy;
576  drawText(XGraph::ScrPoint(x, y, z), i18n("Wheel at Side : Tilt by 30deg."));
577  y += dy;
578  drawText(XGraph::ScrPoint(x, y, z), i18n("Double Click Left Button : Show Dialog"));
579  y += dy;
580  drawText(XGraph::ScrPoint(x, y, z), i18n("Double Click Right Button : This Help"));
581 }
582 
583 Snapshot
585  return m_graph->iterate_commit([=](Transaction &tr){
586  m_graph->setupRedraw(tr, resScreen());
587  });
588 }
589 void
591  setColor((QRgb)shot[ *m_graph->backGround()], 0.3);
592  if(shot.size(m_graph->plots())) {
593  const auto &plots_list( *shot.list(m_graph->plots()));
594  for(auto it = plots_list.begin(); it != plots_list.end(); it++) {
595  auto plot = static_pointer_cast<XPlot>( *it);
596  XGraph::GPoint g1(0.0, 0.0, 0.0),
597  g2(1.0, 0.0, 0.0),
598  g3(0.0, 1.0, 0.0),
599  g4(1.0, 1.0, 0.0),
600  g5(0.0, 0.0, 1.0),
601  g6(0.0, 1.0, 1.0),
602  g7(1.0, 0.0, 1.0),
603  g8(1.0, 1.0, 1.0);
604  XGraph::ScrPoint s1, s2, s3, s4, s5, s6, s7, s8;
605  plot->graphToScreen(shot, g1, &s1);
606  plot->graphToScreen(shot, g2, &s2);
607  plot->graphToScreen(shot, g3, &s3);
608  plot->graphToScreen(shot, g4, &s4);
609  plot->graphToScreen(shot, g5, &s5);
610  plot->graphToScreen(shot, g6, &s6);
611  plot->graphToScreen(shot, g7, &s7);
612  plot->graphToScreen(shot, g8, &s8);
613  beginQuad(true);
614  setVertex(s1);
615  setVertex(s2);
616  setVertex(s4);
617  setVertex(s3);
618  shared_ptr<XAxis> axisz = shot[ *plot->axisZ()];
619  if(axisz) {
620  setVertex(s1);
621  setVertex(s2);
622  setVertex(s7);
623  setVertex(s5);
624  setVertex(s1);
625  setVertex(s3);
626  setVertex(s6);
627  setVertex(s5);
628  }
629  endQuad();
630  }
631  }
632 }
633 void
635  const double axistomarker = 0.05;
636  if(shot.size(m_graph->axes())) {
637  const auto &axes_list( *shot.list(m_graph->axes()));
638  for(auto it = axes_list.begin(); it != axes_list.end(); it++) {
639  auto axis = static_pointer_cast<XAxis>( *it);
640  setColor(shot[ *axis->ticColor()]);
641  if((axis->direction() != XAxis::DirAxisZ) || m_bTilted) {
642  XGraph::ScrPoint s10,s11,s20,s21,vdir;
643  axis->axisToScreen(shot, 0.0, &s10);
644  axis->axisToScreen(shot, 1.0, &s20);
645  s11 = s10;
646  s21 = s20;
647  vdir = s20;
648  vdir -= s10;
649  posOffAxis(vdir, &s10, axistomarker);
650  posOffAxis(vdir, &s11, -axistomarker);
651  posOffAxis(vdir, &s20, axistomarker);
652  posOffAxis(vdir, &s21, -axistomarker);
653  beginQuad(true);
654  setVertex(s10);
655  setVertex(s11);
656  setVertex(s21);
657  setVertex(s20);
658  endQuad();
659  }
660  }
661  }
662 }
663 void
664 XQGraphPainter::drawOffScreenGrids(const Snapshot &shot) {
665  if(shot.size(m_graph->plots())) {
666  const auto &plots_list( *shot.list(m_graph->plots()));
667  for(auto it = plots_list.begin(); it != plots_list.end(); it++) {
668  auto plot = dynamic_pointer_cast<XPlot>( *it);
669  plot->drawGrid(shot, this, m_bTilted);
670  }
671  }
672 }
673 void
674 XQGraphPainter::drawOffScreenPoints(const Snapshot &shot) {
675  if(shot.size(m_graph->plots())) {
676  const auto &plots_list( *shot.list(m_graph->plots()));
677  for(auto it = plots_list.begin(); it != plots_list.end(); it++) {
678  auto plot = static_pointer_cast<XPlot>( *it);
679  plot->drawPlot(shot, this);
680  }
681  }
682 }
683 void
684 XQGraphPainter::drawOffScreenAxes(const Snapshot &shot) {
685  if(shot.size(m_graph->axes())) {
686  const auto &axes_list( *shot.list(m_graph->axes()));
687  for(auto it = axes_list.begin(); it != axes_list.end(); it++) {
688  auto axis = static_pointer_cast<XAxis>( *it);
689  if((axis->direction() != XAxis::DirAxisZ) || m_bTilted)
690  axis->drawAxis(shot, this);
691  }
692  }
693 }

Generated for KAME4 by  doxygen 1.8.3