~valavanisalex/ubuntu/maverick/scidavis/fix-604811

« back to all changes in this revision

Viewing changes to scidavis/src/SymbolBox.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Ruben Molina
  • Date: 2009-09-06 11:34:04 UTC
  • Revision ID: james.westby@ubuntu.com-20090906113404-4awaey82l3686w4q
Tags: upstream-0.2.3
ImportĀ upstreamĀ versionĀ 0.2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
    File                 : SymbolBox.cpp
 
3
    Project              : SciDAVis
 
4
    --------------------------------------------------------------------
 
5
    Copyright            : (C) 2006 by Ion Vasilief, Tilman Benkert
 
6
    Email (use @ for *)  : ion_vasilief*yahoo.fr, thzs*gmx.net
 
7
    Description          : Plot symbol combo box
 
8
                           
 
9
 ***************************************************************************/
 
10
 
 
11
/***************************************************************************
 
12
 *                                                                         *
 
13
 *  This program is free software; you can redistribute it and/or modify   *
 
14
 *  it under the terms of the GNU General Public License as published by   *
 
15
 *  the Free Software Foundation; either version 2 of the License, or      *
 
16
 *  (at your option) any later version.                                    *
 
17
 *                                                                         *
 
18
 *  This program is distributed in the hope that it will be useful,        *
 
19
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
 
20
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
 
21
 *  GNU General Public License for more details.                           *
 
22
 *                                                                         *
 
23
 *   You should have received a copy of the GNU General Public License     *
 
24
 *   along with this program; if not, write to the Free Software           *
 
25
 *   Foundation, Inc., 51 Franklin Street, Fifth Floor,                    *
 
26
 *   Boston, MA  02110-1301  USA                                           *
 
27
 *                                                                         *
 
28
 ***************************************************************************/
 
29
#include "SymbolBox.h"
 
30
#include <algorithm>
 
31
 
 
32
#include <qpixmap.h>
 
33
#include <qpainter.h>
 
34
 
 
35
const QwtSymbol::Style SymbolBox::symbols[] = {
 
36
  QwtSymbol::NoSymbol,
 
37
  QwtSymbol::Ellipse,
 
38
  QwtSymbol::Rect,
 
39
  QwtSymbol::Diamond,
 
40
  QwtSymbol::Triangle,
 
41
  QwtSymbol::DTriangle,
 
42
  QwtSymbol::UTriangle,
 
43
  QwtSymbol::LTriangle,
 
44
  QwtSymbol::RTriangle, 
 
45
  QwtSymbol::Cross, 
 
46
  QwtSymbol::XCross, 
 
47
  QwtSymbol::HLine,
 
48
  QwtSymbol::VLine,
 
49
  QwtSymbol::Star1, 
 
50
  QwtSymbol::Star2, 
 
51
  QwtSymbol::Hexagon
 
52
};
 
53
 
 
54
SymbolBox::SymbolBox(bool rw, QWidget *parent) : QComboBox(rw, parent)
 
55
{
 
56
  init();
 
57
}
 
58
 
 
59
SymbolBox::SymbolBox(QWidget *parent) : QComboBox(parent)
 
60
{
 
61
  init();
 
62
}
 
63
 
 
64
void SymbolBox::init()
 
65
{
 
66
        QPixmap icon = QPixmap(14, 14);
 
67
        icon.fill ( QColor (Qt::gray) );
 
68
        const QRect r= QRect(0, 0, 14, 14);
 
69
        QPainter p(&icon);
 
70
        p.setBackgroundColor(QColor(Qt::gray));
 
71
        QwtSymbol symb;
 
72
        p.setBrush(QBrush(QColor(Qt::white)));
 
73
 
 
74
        this->insertItem(tr("No Symbol" ));
 
75
 
 
76
        symb.setStyle (QwtSymbol::Ellipse);
 
77
        symb.draw(&p, r);
 
78
        this->insertItem(icon, tr("Ellipse" ));
 
79
 
 
80
        symb.setStyle (QwtSymbol::Rect);
 
81
        p.eraseRect ( r );
 
82
        symb.draw(&p, r);
 
83
    this->insertItem(icon,tr("Rectangle"));
 
84
 
 
85
        symb.setStyle (QwtSymbol::Diamond);
 
86
        p.eraseRect ( r );
 
87
        symb.draw(&p, r);
 
88
    this->insertItem(icon,tr("Diamond"));
 
89
 
 
90
        symb.setStyle (QwtSymbol::Triangle);
 
91
        p.eraseRect ( r );
 
92
        symb.draw(&p, r);
 
93
    this->insertItem(icon,tr("Triangle"));
 
94
 
 
95
        symb.setStyle (QwtSymbol::DTriangle);
 
96
        p.eraseRect ( r );
 
97
        symb.draw(&p, r);
 
98
    this->insertItem(icon,tr("Down Triangle"));
 
99
 
 
100
        symb.setStyle (QwtSymbol::UTriangle);
 
101
        p.eraseRect ( r );
 
102
        symb.draw(&p, r);
 
103
    this->insertItem(icon,tr("Up Triangle"));
 
104
 
 
105
        symb.setStyle (QwtSymbol::LTriangle);
 
106
        p.eraseRect ( r );
 
107
        symb.draw(&p, r);
 
108
    this->insertItem(icon,tr("Left Triangle"));
 
109
 
 
110
        symb.setStyle (QwtSymbol::RTriangle);
 
111
        p.eraseRect ( r );
 
112
        symb.draw(&p, r);
 
113
    this->insertItem(icon,tr("Right Triangle"));
 
114
 
 
115
        symb.setStyle (QwtSymbol::Cross);
 
116
        p.eraseRect ( r );
 
117
        symb.draw(&p, r);
 
118
    this->insertItem(icon,tr("Cross"));
 
119
 
 
120
        symb.setStyle (QwtSymbol::XCross);
 
121
        p.eraseRect ( r );
 
122
        symb.draw(&p, r);
 
123
    this->insertItem(icon,tr("Diagonal Cross"));
 
124
 
 
125
        symb.setStyle (QwtSymbol::HLine);
 
126
        p.eraseRect ( r );
 
127
        symb.draw(&p, r);
 
128
    this->insertItem(icon,tr("Horizontal Line"));
 
129
 
 
130
        symb.setStyle (QwtSymbol::VLine);
 
131
        p.eraseRect ( r );
 
132
        symb.draw(&p, r);
 
133
    this->insertItem(icon,tr("Vertical Line"));
 
134
 
 
135
        symb.setStyle (QwtSymbol::Star1);
 
136
        p.eraseRect ( r );
 
137
        symb.draw(&p, r);
 
138
    this->insertItem(icon,tr("Star 1"));
 
139
 
 
140
        symb.setStyle (QwtSymbol::Star2);
 
141
        p.eraseRect ( r );
 
142
        symb.draw(&p, r);
 
143
    this->insertItem(icon,tr("Star 2"));
 
144
 
 
145
        symb.setStyle (QwtSymbol::Hexagon);
 
146
        p.eraseRect ( r );
 
147
        symb.draw(&p, r);
 
148
    this->insertItem(icon,tr("Hexagon"));
 
149
 
 
150
        p.end();
 
151
}
 
152
 
 
153
void SymbolBox::setStyle(const QwtSymbol::Style& style)
 
154
{
 
155
  const QwtSymbol::Style*ite = std::find(symbols, symbols + sizeof(symbols), style);
 
156
  if (ite == symbols + sizeof(symbols))
 
157
    this->setCurrentIndex(0);
 
158
  else 
 
159
    this->setCurrentIndex(ite - symbols);
 
160
}
 
161
 
 
162
QwtSymbol::Style SymbolBox::selectedSymbol() const
 
163
{
 
164
  size_t i = this->currentItem();
 
165
  if (i < sizeof(symbols))
 
166
    return symbols[this->currentItem()];
 
167
  else
 
168
    return QwtSymbol::NoSymbol;
 
169
}
 
170
 
 
171
int SymbolBox::symbolIndex(const QwtSymbol::Style& style)
 
172
{
 
173
  const QwtSymbol::Style*ite = std::find(symbols, symbols + sizeof(symbols), style);
 
174
  if (ite == symbols + sizeof(symbols))
 
175
    return 0; 
 
176
  else
 
177
    return (ite - symbols);
 
178
}
 
179
 
 
180
QwtSymbol::Style SymbolBox::style(int index)
 
181
{
 
182
  if (index < (int)sizeof(symbols))
 
183
    return symbols[index];
 
184
  else
 
185
    return QwtSymbol::NoSymbol;
 
186
}