forked from root-project/root
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TQtPen.cxx
185 lines (167 loc) · 5.88 KB
/
TQtPen.cxx
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
// Author: Valeri Fine 21/01/2002
/****************************************************************************
** $Id$
**
** Copyright (C) 2002 by Valeri Fine. Brookhaven National Laboratory.
** All rights reserved.
**
**
*****************************************************************************/
/////////////////////////////////////////////////////////////////////////////////
//
// TQtPen class is Qt QPen with ROOT TAttLine interface
//
/////////////////////////////////////////////////////////////////////////////////
#include "TQtPen.h"
#include "TGQt.h"
#include "TSystem.h"
#include "TMath.h"
#include "TStyle.h"
#include "TObjString.h"
#include "TObjArray.h"
#include "TAttLine.h"
#include <QtGui/QFontMetrics>
#include <QDebug>
////////////////////////////////////////////////////////////////////////////////
/// TQtPen default ctor
TQtPen::TQtPen(): QPen(),TAttLine()
{
}
////////////////////////////////////////////////////////////////////////////////
/// Copy ctor to copy ROOT TAttLine object
TQtPen::TQtPen(const TAttLine &line) : QPen()
{
SetLineAttributes(line);
}
////////////////////////////////////////////////////////////////////////////////
/// Assigns the Qt pen attributes from ROOT TAttLine object
TQtPen &TQtPen::operator=(const TAttLine &line)
{
SetLineAttributes(line);
return *this;
}
////////////////////////////////////////////////////////////////////////////////
/// Maps the ROOT TAttLine attributes to QPen attributes
void TQtPen::SetLineAttributes(const TAttLine &lineAttributes)
{
SetLineColor(lineAttributes.GetLineColor());
SetLineStyle(lineAttributes.GetLineStyle());
SetLineWidth(lineAttributes.GetLineWidth());
}
////////////////////////////////////////////////////////////////////////////////
///*-*-*-*-*-*-*-*-*-*-*Set color index for lines*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
///*-* =========================
///*-* cindex : color index
///*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
void TQtPen::SetLineColor(Color_t cindex)
{
if (fLineColor != cindex) {
fLineColor = cindex;
if (fLineColor >= 0) setColor(gQt->ColorIndex(gQt->UpdateColor(fLineColor)));
}
}
////////////////////////////////////////////////////////////////////////////////
///*-*-*-*-*-*-*-*-*-*-*Set line style-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
///*-* ==============
///*-* Set line style:
///*-* if n < 0 use pre-defined Windows style:
///*-* 0 - solid lines
///*-* -1 - solid lines
///*-* -2 - dash line
///*-* -3 - dot line
///*-* -4 - dash-dot line
///*-* -5 - dash-dot-dot line
///*-* < -6 - solid line
///*-*
///*-* if n > 0 use dashed lines described by DASH(N)
///*-* e.g. n=4,DASH=(6,3,1,3) gives a dashed-dotted line with dash length 6
///*-* and a gap of 7 between dashes
///*-*
void TQtPen::SetLineType(int n, int*dash)
{
/*
SetLineStyleString(1," ");
SetLineStyleString(2,"12 12");
SetLineStyleString(3,"4 8");
SetLineStyleString(4,"12 16 4 16");
SetLineStyleString(5,"20 12 4 12");
SetLineStyleString(6,"20 12 4 12 4 12 4 12");
SetLineStyleString(7,"20 20");
SetLineStyleString(8,"20 12 4 12 4 12");
SetLineStyleString(9,"80 20");
SetLineStyleString(10,"80 40 4 40");
*/
static Qt::PenStyle styles[] = {
Qt::NoPen // - no line at all.
,Qt::SolidLine // - a simple line.
,Qt::DashLine // - dashes separated by a few pixels.
,Qt::DotLine // - dots separated by a few pixels.
,Qt::DashDotLine // - alternate dots and dashes.
,Qt::DashDotDotLine // - one dash, two dots, one dash, two dotsQt::NoPen
};
if (n == 0 ) n = -1; // solid lines
if (n < 0) {
int l = -n;
if (l >= int(sizeof(styles)/sizeof(Qt::PenStyle)) ) l = 1; // Solid line "by default"
setStyle(styles[l]);
}
else if (dash) {
// - A custom pattern defined using QPainterPathStroker::setDashPattern().
QVector<qreal> dashes;
int i;
for (i=0;i<n;i++) dashes << dash[i];
setDashPattern(dashes);
}
}
////////////////////////////////////////////////////////////////////////////////
///*-*-*-*-*-*-*-*-*-*-*Set line style-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
///*-* ==============
///*-* Use pre-defined Windows style:
///*-* linestyle =
///*-* 0 - solid lines
///*-* -1 - solid lines
///*-* -2 - dash line
///*-* -3 - dot line
///*-* -4 - dash-dot line
///*-* -5 - dash-dot-dot line
///*-* < -6 - solid line
///*-*
///*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
/// Copy/Paste from TGX11::SetLineStyle (it is called "subclassing" ;-)
/// Set line style.
void TQtPen::SetLineStyle(Style_t linestyle)
{
if (fLineStyle != linestyle) { //set style index only if different
fLineStyle = linestyle;
if (linestyle > 0 && linestyle <= 5 ) {
SetLineType(-linestyle,NULL);
} else {
TString st = (TString)gStyle->GetLineStyleString(linestyle);
TObjArray *tokens = st.Tokenize(" ");
Int_t nt;
nt = tokens->GetEntries();
Int_t *lstyle = new Int_t[nt];
for (Int_t j = 0; j<nt; j++) {
Int_t it;
sscanf(((TObjString*)tokens->At(j))->GetName(), "%d", &it);
lstyle[j] = (Int_t)(it/4);
}
SetLineType(nt,lstyle);
delete [] lstyle;
delete tokens;
}
}
}
////////////////////////////////////////////////////////////////////////////////
///*-*-*-*-*-*-*-*-*-*-*Set line width*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
///*-* ==============
///*-* w : line width in pixels
///*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
void TQtPen::SetLineWidth(Width_t w)
{
if (w==1) w =0;
if (fLineWidth != w) {
fLineWidth = w;
if (fLineWidth >= 0 ) setWidth(fLineWidth);
}
}