File: graphwidget.cpp.orig

package info (click to toggle)
xdrawchem 1.0-0.1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 2,820 kB
  • ctags: 2,389
  • sloc: cpp: 17,801; makefile: 263; ansic: 168
file content (113 lines) | stat: -rw-r--r-- 3,099 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
// graphwidget.cpp - definitions for functions of class GraphWidget

#include <iostream.h>
#include <qwidget.h>
#include <qpixmap.h>
#include <qpaintdevicemetrics.h>

#include "defs.h"
#include "render2d.h"
#include "graphwidget.h"
#include "graphdata.h"

GraphWidget::GraphWidget(QWidget *parent, const char *name)
  : QWidget(parent, name)
{
  datatype = 0;
  output = 0;
  PrintSetup();
}

void GraphWidget::paintEvent(QPaintEvent *pe) {
  QPainter p;
  QString s, ft;
  int cx = 10, cy = 10;

  if (output == 0)
    p.begin(this);
  else
    p.begin(printer);

  if (p1.width() > 0) {
    p.drawPixmap(QPoint(10,10), p1);
    cy = cy + p1.height() + 5;
  }
  if (datatype == 1) { // 13C-NMR
    cy = cy + 90;
    // draw baseline
    p.drawLine( QPoint(50,cy), QPoint(550,cy) );
    p.drawLine( QPoint(500,cy), QPoint(500,cy+3) );
    p.drawText( QPoint(500,cy+15), "0 ppm");
    p.drawLine( QPoint(440,cy), QPoint(440,cy+3) );
    p.drawText( QPoint(440,cy+15), "20");
    p.drawLine( QPoint(380,cy), QPoint(380,cy+3) );
    p.drawText( QPoint(380,cy+15), "40");
    p.drawLine( QPoint(320,cy), QPoint(320,cy+3) );
    p.drawText( QPoint(320,cy+15), "60");
    p.drawLine( QPoint(260,cy), QPoint(260,cy+3) );
    p.drawText( QPoint(260,cy+15), "80");
    p.drawLine( QPoint(200,cy), QPoint(200,cy+3) );
    p.drawText( QPoint(200,cy+15), "100");
    p.drawLine( QPoint(140,cy), QPoint(140,cy+3) );
    p.drawText( QPoint(140,cy+15), "120");
    p.drawLine( QPoint(80,cy), QPoint(80,cy+3) );
    p.drawText( QPoint(80,cy+15), "140");
    for (GraphData *tg = peaks.first(); tg != 0; tg = peaks.next()) {
      int cx = 500 - (int)(tg->value * 3.0);
      int intense = tg->intensity * 30;
      if (intense > 90) intense = 90;
      p.drawLine( QPoint(cx, cy), QPoint(cx, cy - intense) );
    }
    cy = cy + 45;
  }
  if (datatype == 2) // IR
    cy = cy + 20;
  for (GraphData *tg = peaks.first(); tg != 0; tg = peaks.next()) {
    s.setNum(tg->intensity);
    ft = tg->fulltext;
    if (datatype == 1) { // 13C-NMR
      ft.append(", intensity ");
      ft.append(s);
    }
    p.drawText(QPoint(cx, cy), ft);
    cy = cy + 15;
  }
  p.end();
}

void GraphWidget::PrintSetup() {
  printer = new QPrinter;
  printer->setFullPage(true);
  printer->setPageSize(QPrinter::Letter);
  printer->setOrientation(QPrinter::Portrait);
  printer->setColorMode(QPrinter::GrayScale);
}

void GraphWidget::Print() {
  cout << "Graph::Print" << endl;
  if (!printer->setup(this)) {
    return;
  }

  //QPaintDeviceMetrics pm(printer);

  output = 1;
  repaint();
  output = 0;
  repaint();
}

void GraphWidget::AddPeak(double v1, QString l1, QString t1) {
  GraphData *g1 = new GraphData;
  g1->value = v1;
  g1->fulltext = t1;
  if (l1.isEmpty() == false) { g1->label = l1; g1->drawlabel = true; }
  // check for duplicate peaks
  for (GraphData *tg = peaks.first(); tg != 0; tg = peaks.next()) {
    if (tg->value == v1) {
      tg->intensity++;
      return;
    }
  }
  peaks.append(g1);
}