File: previewwidget.cpp

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 (225 lines) | stat: -rw-r--r-- 7,559 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
#include <qpixmap.h>

#include "previewwidget.h"
#include "defs.h"

// arrows
#include "arrows.h"
#include "cw90.xpm"
#include "ccw90.xpm"
#include "cw180.xpm"
#include "ccw180.xpm"
#include "cw270.xpm"
#include "ccw270.xpm"

// brackets
#include "brackets.h"

// bonds
/* XPM */
static const char *upline_xpm[] = {
/* width height num_colors chars_per_pixel */
"    64    24        2            1",
/* colors */
". c #000000",
"# c #ffffff",
/* pixels */
"################################################################",
"################################################################",
"################################################################",
"################################################################",
"################################################################",
"################################################################",
"################################################################",
"##################################################.........#####",
"##################################.........................#####",
"##################.........................................#####",
"#########..................................................#####",
"######################.....................................#####",
"##############################################.............#####",
"################################################################",
"################################################################",
"################################################################",
"################################################################",
"################################################################",
"################################################################",
"################################################################",
"################################################################",
"################################################################",
"################################################################",
"################################################################"
};
/* XPM */
static const char *downline_xpm[] = {
/* width height num_colors chars_per_pixel */
"    64    24        2            1",
/* colors */
". c #000000",
"# c #ffffff",
/* pixels */
"################################################################",
"################################################################",
"################################################################",
"################################################################",
"################################################################",
"################################################################",
"################################################################",
"################################################################",
"################################################################",
"################################################################",
"#############################################.###.###.###.######",
"#########################.###.###.###.###.###.###.###.###.######",
"#########.###.###.###.###.###.###.###.###.###.###.###.###.######",
"#########################.###.###.###.###.###.###.###.###.######",
"#############################################.###.###.###.######",
"################################################################",
"################################################################",
"################################################################",
"################################################################",
"################################################################",
"################################################################",
"################################################################",
"################################################################",
"################################################################",
};

// symbols
#include "symbol_xpm.h"

PreviewWidget::PreviewWidget(QWidget *parent, const char *name)
  : QWidget(parent, name)
{
  resize(50,50);
}

void PreviewWidget::paintEvent(QPaintEvent *qp1) {
  int ofs = 2;
  QPainter p(this);

  if (type == TYPE_ARROW) {
    switch(style) {
    case ARROW_REGULAR:
      p.drawPixmap(10, 10, QPixmap(arrow_regular_xpm));
      break;
    case ARROW_DASH:
      p.drawPixmap(10, 10, QPixmap(arrow_dash_xpm));
      break;
    case ARROW_BI1:
      p.drawPixmap(10, 10, QPixmap(arrow_bi1_xpm));
      break;
    case ARROW_BI2:
      p.drawPixmap(10, 10, QPixmap(arrow_bi2_xpm));
      break;
    case ARROW_RETRO:
      p.drawPixmap(10, 10, QPixmap(arrow_retro_xpm));
      break;
    }
    return;
  }
  if (type == TYPE_BOND) {
    switch (_or) {
    case 1:
      if (da == 1) {
	p.setPen(QPen(QColor(0,0,0),th,DotLine));
	p.drawLine( QPoint(10,30), QPoint(60,30) );
      } else {
	p.setPen(QPen(QColor(0,0,0),th));
	p.drawLine( QPoint(10,30), QPoint(60,30) );
      }
      break;
    case 2:
      if (da == 1) {
	p.setPen(QPen(QColor(0,0,0),th,DotLine));
	p.drawLine( QPoint(10,30), QPoint(60,30) );
	p.setPen(QPen(QColor(0,0,0),th));
	p.drawLine( QPoint(10,30 + th + ofs), QPoint(60,30 + th + ofs) );
      } else {
	p.setPen(QPen(QColor(0,0,0),th));
	p.drawLine( QPoint(10,30), QPoint(60,30) );
	p.drawLine( QPoint(10,30 + th + ofs), QPoint(60,30 + th + ofs) );
      }
      break;	
    case 3:
      if (da == 1) {
	p.setPen(QPen(QColor(0,0,0),th,DotLine));
	p.drawLine( QPoint(10,30 - th - ofs), QPoint(60,30 - th - ofs) );
	p.setPen(QPen(QColor(0,0,0),th));
	p.drawLine( QPoint(10,30), QPoint(60,30) );
	p.drawLine( QPoint(10,30 + th + ofs), QPoint(60,30 + th + ofs) );
      } else {
	p.setPen(QPen(QColor(0,0,0),th));
	p.drawLine( QPoint(10,30 - th - ofs), QPoint(60,30 - th - ofs) );
	p.drawLine( QPoint(10,30), QPoint(60,30) );
	p.drawLine( QPoint(10,30 + th + ofs), QPoint(60,30 + th + ofs) );
      }
      break;
    case 5:
      p.drawPixmap(10, 10, QPixmap(upline_xpm));
      break;
    case 7:
      p.drawPixmap(10, 10, QPixmap(downline_xpm));
      break;
    }
    return;
  }
  if (type == TYPE_BRACKET) {
    switch(style) {
    case BRACKET_SQUARE:
      p.drawPixmap(10, 10, QPixmap(squarebracket_xpm));
      break;
    case BRACKET_CURVE:
      p.drawPixmap(10, 10, QPixmap(curvebracket_xpm));
      break;
    case BRACKET_BRACE:
      p.drawPixmap(10, 10, QPixmap(bracebracket_xpm));
      break;
    }
    return;
  }
  if (type == TYPE_CURVEARROW) {
    switch(style) {
    case CA_CW90:
      p.drawPixmap(10, 10, QPixmap(cw90_xpm));
      break;
    case CA_CW180:
      p.drawPixmap(10, 10, QPixmap(cw180_xpm));
      break;
    case CA_CW270:
      p.drawPixmap(10, 10, QPixmap(cw270_xpm));
      break;
    case CA_CCW90:
      p.drawPixmap(10, 10, QPixmap(ccw90_xpm));
      break;
    case CA_CCW180:
      p.drawPixmap(10, 10, QPixmap(ccw180_xpm));
      break;
    case CA_CCW270:
      p.drawPixmap(10, 10, QPixmap(ccw270_xpm));
      break;
    }
    return;
  }
  if (type == TYPE_SYMBOL) {
    switch (style) {
    case SYM_PLUS:
      p.drawPixmap(10, 10, QPixmap(sym_plus_xpm));
      break;
    case SYM_MINUS:
      p.drawPixmap(10, 10, QPixmap(sym_minus_xpm));
      break;
    case SYM_DELTA_PLUS:
      p.drawPixmap(10, 10, QPixmap(sym_delta_plus_xpm));
      break;
    case SYM_DELTA_MINUS:
      p.drawPixmap(10, 10, QPixmap(sym_delta_minus_xpm));
      break;
    case SYM_1E:
      p.drawPixmap(10, 10, QPixmap(sym_1e_xpm));
      break;
    case SYM_2E:
      p.drawPixmap(10, 10, QPixmap(sym_2e_xpm));
      break;
    }
    return;
  }
}