@@ -1,141 +1,141 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "pentool.h" |
|
21 | #include "pentool.h" | |
22 | #include <QPushButton> |
|
22 | #include <QPushButton> | |
23 | #include <QDoubleSpinBox> |
|
23 | #include <QDoubleSpinBox> | |
24 | #include <QComboBox> |
|
24 | #include <QComboBox> | |
25 | #include <QFormLayout> |
|
25 | #include <QFormLayout> | |
26 | #include <QColorDialog> |
|
26 | #include <QColorDialog> | |
27 |
|
27 | |||
28 | PenTool::PenTool(QString title, QWidget *parent) |
|
28 | PenTool::PenTool(QString title, QWidget *parent) | |
29 | : QWidget(parent) |
|
29 | : QWidget(parent) | |
30 | { |
|
30 | { | |
31 | setWindowTitle(title); |
|
31 | setWindowTitle(title); | |
32 | setWindowFlags(Qt::Tool); |
|
32 | setWindowFlags(Qt::Tool); | |
33 |
|
33 | |||
34 | m_colorButton = new QPushButton(); |
|
34 | m_colorButton = new QPushButton(); | |
35 |
|
35 | |||
36 | m_widthSpinBox = new QDoubleSpinBox(); |
|
36 | m_widthSpinBox = new QDoubleSpinBox(); | |
37 |
|
37 | |||
38 | m_styleCombo = new QComboBox(); |
|
38 | m_styleCombo = new QComboBox(); | |
39 | m_styleCombo->addItem("NoPen"); |
|
39 | m_styleCombo->addItem("NoPen"); | |
40 | m_styleCombo->addItem("SolidLine"); |
|
40 | m_styleCombo->addItem("SolidLine"); | |
41 | m_styleCombo->addItem("DashLine"); |
|
41 | m_styleCombo->addItem("DashLine"); | |
42 | m_styleCombo->addItem("DotLine"); |
|
42 | m_styleCombo->addItem("DotLine"); | |
43 | m_styleCombo->addItem("DashDotLine"); |
|
43 | m_styleCombo->addItem("DashDotLine"); | |
44 | m_styleCombo->addItem("DashDotDotLine"); |
|
44 | m_styleCombo->addItem("DashDotDotLine"); | |
45 |
|
45 | |||
46 | m_capStyleCombo = new QComboBox(); |
|
46 | m_capStyleCombo = new QComboBox(); | |
47 | m_capStyleCombo->addItem("FlatCap", Qt::FlatCap); |
|
47 | m_capStyleCombo->addItem("FlatCap", Qt::FlatCap); | |
48 | m_capStyleCombo->addItem("SquareCap", Qt::SquareCap); |
|
48 | m_capStyleCombo->addItem("SquareCap", Qt::SquareCap); | |
49 | m_capStyleCombo->addItem("RoundCap", Qt::RoundCap); |
|
49 | m_capStyleCombo->addItem("RoundCap", Qt::RoundCap); | |
50 |
|
50 | |||
51 | m_joinStyleCombo = new QComboBox(); |
|
51 | m_joinStyleCombo = new QComboBox(); | |
52 | m_joinStyleCombo->addItem("MiterJoin", Qt::MiterJoin); |
|
52 | m_joinStyleCombo->addItem("MiterJoin", Qt::MiterJoin); | |
53 | m_joinStyleCombo->addItem("BevelJoin", Qt::BevelJoin); |
|
53 | m_joinStyleCombo->addItem("BevelJoin", Qt::BevelJoin); | |
54 | m_joinStyleCombo->addItem("RoundJoin", Qt::RoundJoin); |
|
54 | m_joinStyleCombo->addItem("RoundJoin", Qt::RoundJoin); | |
55 | m_joinStyleCombo->addItem("SvgMiterJoin", Qt::SvgMiterJoin); |
|
55 | m_joinStyleCombo->addItem("SvgMiterJoin", Qt::SvgMiterJoin); | |
56 |
|
56 | |||
57 | QFormLayout *layout = new QFormLayout(); |
|
57 | QFormLayout *layout = new QFormLayout(); | |
58 | layout->addRow("Color", m_colorButton); |
|
58 | layout->addRow("Color", m_colorButton); | |
59 | layout->addRow("Width", m_widthSpinBox); |
|
59 | layout->addRow("Width", m_widthSpinBox); | |
60 | layout->addRow("Style", m_styleCombo); |
|
60 | layout->addRow("Style", m_styleCombo); | |
61 | layout->addRow("Cap style", m_capStyleCombo); |
|
61 | layout->addRow("Cap style", m_capStyleCombo); | |
62 | layout->addRow("Join style", m_joinStyleCombo); |
|
62 | layout->addRow("Join style", m_joinStyleCombo); | |
63 | setLayout(layout); |
|
63 | setLayout(layout); | |
64 |
|
64 | |||
65 | connect(m_colorButton, SIGNAL(clicked()), this, SLOT(showColorDialog())); |
|
65 | connect(m_colorButton, SIGNAL(clicked()), this, SLOT(showColorDialog())); | |
66 | connect(m_widthSpinBox, SIGNAL(valueChanged(double)), this, SLOT(updateWidth(double))); |
|
66 | connect(m_widthSpinBox, SIGNAL(valueChanged(double)), this, SLOT(updateWidth(double))); | |
67 | connect(m_styleCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(updateStyle(int))); |
|
67 | connect(m_styleCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(updateStyle(int))); | |
68 | connect(m_capStyleCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(updateCapStyle(int))); |
|
68 | connect(m_capStyleCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(updateCapStyle(int))); | |
69 | connect(m_joinStyleCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(updateJoinStyle(int))); |
|
69 | connect(m_joinStyleCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(updateJoinStyle(int))); | |
70 | } |
|
70 | } | |
71 |
|
71 | |||
72 | void PenTool::setPen(const QPen &pen) |
|
72 | void PenTool::setPen(const QPen &pen) | |
73 | { |
|
73 | { | |
74 | m_pen = pen; |
|
74 | m_pen = pen; | |
75 | m_colorButton->setText(m_pen.color().name()); |
|
75 | m_colorButton->setText(m_pen.color().name()); | |
76 | m_widthSpinBox->setValue(m_pen.widthF()); |
|
76 | m_widthSpinBox->setValue(m_pen.widthF()); | |
77 | m_styleCombo->setCurrentIndex(m_pen.style()); // index matches the enum |
|
77 | m_styleCombo->setCurrentIndex(m_pen.style()); // index matches the enum | |
78 | m_capStyleCombo->setCurrentIndex(m_capStyleCombo->findData(m_pen.capStyle())); |
|
78 | m_capStyleCombo->setCurrentIndex(m_capStyleCombo->findData(m_pen.capStyle())); | |
79 | m_joinStyleCombo->setCurrentIndex(m_joinStyleCombo->findData(m_pen.joinStyle())); |
|
79 | m_joinStyleCombo->setCurrentIndex(m_joinStyleCombo->findData(m_pen.joinStyle())); | |
80 | } |
|
80 | } | |
81 |
|
81 | |||
82 | QPen PenTool::pen() const |
|
82 | QPen PenTool::pen() const | |
83 | { |
|
83 | { | |
84 | return m_pen; |
|
84 | return m_pen; | |
85 | } |
|
85 | } | |
86 |
|
86 | |||
87 | QString PenTool::name() |
|
87 | QString PenTool::name() | |
88 | { |
|
88 | { | |
89 | return name(m_pen); |
|
89 | return name(m_pen); | |
90 | } |
|
90 | } | |
91 |
|
91 | |||
92 | QString PenTool::name(const QPen &pen) |
|
92 | QString PenTool::name(const QPen &pen) | |
93 | { |
|
93 | { | |
94 | return pen.color().name() + ":" + QString::number(pen.widthF()); |
|
94 | return pen.color().name() + ":" + QString::number(pen.widthF()); | |
95 | } |
|
95 | } | |
96 |
|
96 | |||
97 | void PenTool::showColorDialog() |
|
97 | void PenTool::showColorDialog() | |
98 | { |
|
98 | { | |
99 | QColorDialog dialog(m_pen.color()); |
|
99 | QColorDialog dialog(m_pen.color()); | |
100 | dialog.show(); |
|
100 | dialog.show(); | |
101 | dialog.exec(); |
|
101 | dialog.exec(); | |
102 | m_pen.setColor(dialog.selectedColor()); |
|
102 | m_pen.setColor(dialog.selectedColor()); | |
103 | m_colorButton->setText(m_pen.color().name()); |
|
103 | m_colorButton->setText(m_pen.color().name()); | |
104 | emit changed(); |
|
104 | emit changed(); | |
105 | } |
|
105 | } | |
106 |
|
106 | |||
107 | void PenTool::updateWidth(double width) |
|
107 | void PenTool::updateWidth(double width) | |
108 | { |
|
108 | { | |
109 | if (!qFuzzyCompare(width, m_pen.widthF())) { |
|
109 | if (!qFuzzyCompare((qreal) width, m_pen.widthF())) { | |
110 | m_pen.setWidthF(width); |
|
110 | m_pen.setWidthF(width); | |
111 | emit changed(); |
|
111 | emit changed(); | |
112 | } |
|
112 | } | |
113 | } |
|
113 | } | |
114 |
|
114 | |||
115 | void PenTool::updateStyle(int style) |
|
115 | void PenTool::updateStyle(int style) | |
116 | { |
|
116 | { | |
117 | if (m_pen.style() != style) { |
|
117 | if (m_pen.style() != style) { | |
118 | m_pen.setStyle((Qt::PenStyle) style); |
|
118 | m_pen.setStyle((Qt::PenStyle) style); | |
119 | emit changed(); |
|
119 | emit changed(); | |
120 | } |
|
120 | } | |
121 | } |
|
121 | } | |
122 |
|
122 | |||
123 | void PenTool::updateCapStyle(int index) |
|
123 | void PenTool::updateCapStyle(int index) | |
124 | { |
|
124 | { | |
125 | Qt::PenCapStyle capStyle = (Qt::PenCapStyle) m_capStyleCombo->itemData(index).toInt(); |
|
125 | Qt::PenCapStyle capStyle = (Qt::PenCapStyle) m_capStyleCombo->itemData(index).toInt(); | |
126 | if (m_pen.capStyle() != capStyle) { |
|
126 | if (m_pen.capStyle() != capStyle) { | |
127 | m_pen.setCapStyle(capStyle); |
|
127 | m_pen.setCapStyle(capStyle); | |
128 | emit changed(); |
|
128 | emit changed(); | |
129 | } |
|
129 | } | |
130 | } |
|
130 | } | |
131 |
|
131 | |||
132 | void PenTool::updateJoinStyle(int index) |
|
132 | void PenTool::updateJoinStyle(int index) | |
133 | { |
|
133 | { | |
134 | Qt::PenJoinStyle joinStyle = (Qt::PenJoinStyle) m_joinStyleCombo->itemData(index).toInt(); |
|
134 | Qt::PenJoinStyle joinStyle = (Qt::PenJoinStyle) m_joinStyleCombo->itemData(index).toInt(); | |
135 | if (m_pen.joinStyle() != joinStyle) { |
|
135 | if (m_pen.joinStyle() != joinStyle) { | |
136 | m_pen.setJoinStyle(joinStyle); |
|
136 | m_pen.setJoinStyle(joinStyle); | |
137 | emit changed(); |
|
137 | emit changed(); | |
138 | } |
|
138 | } | |
139 | } |
|
139 | } | |
140 |
|
140 | |||
141 | #include "moc_pentool.cpp" |
|
141 | #include "moc_pentool.cpp" |
General Comments 0
You need to be logged in to leave comments.
Login now