##// END OF EJS Templates
Add styles to pen in piechartcustomization demo
Jani Honkonen -
r522:49c80e862047
parent child
Show More
@@ -29,15 +29,41 public:
29 setWindowFlags(Qt::Tool);
29 setWindowFlags(Qt::Tool);
30
30
31 m_colorButton = new QPushButton();
31 m_colorButton = new QPushButton();
32
32 m_widthSpinBox = new QDoubleSpinBox();
33 m_widthSpinBox = new QDoubleSpinBox();
33
34
35 m_styleCombo = new QComboBox();
36 m_styleCombo->addItem("NoPen");
37 m_styleCombo->addItem("SolidLine");
38 m_styleCombo->addItem("DashLine");
39 m_styleCombo->addItem("DotLine");
40 m_styleCombo->addItem("DashDotLine");
41 m_styleCombo->addItem("DashDotDotLine");
42
43 m_capStyleCombo = new QComboBox();
44 m_capStyleCombo->addItem("FlatCap", Qt::FlatCap);
45 m_capStyleCombo->addItem("SquareCap", Qt::SquareCap);
46 m_capStyleCombo->addItem("RoundCap", Qt::RoundCap);
47
48 m_joinStyleCombo = new QComboBox();
49 m_joinStyleCombo->addItem("MiterJoin", Qt::MiterJoin);
50 m_joinStyleCombo->addItem("BevelJoin", Qt::BevelJoin);
51 m_joinStyleCombo->addItem("RoundJoin", Qt::RoundJoin);
52 m_joinStyleCombo->addItem("SvgMiterJoin", Qt::SvgMiterJoin);
53
34 QFormLayout *layout = new QFormLayout();
54 QFormLayout *layout = new QFormLayout();
35 layout->addRow("Color", m_colorButton);
55 layout->addRow("Color", m_colorButton);
36 layout->addRow("Width", m_widthSpinBox);
56 layout->addRow("Width", m_widthSpinBox);
57 layout->addRow("Style", m_styleCombo);
58 layout->addRow("Cap style", m_capStyleCombo);
59 layout->addRow("Join style", m_joinStyleCombo);
37 setLayout(layout);
60 setLayout(layout);
38
61
39 connect(m_colorButton, SIGNAL(clicked()), this, SLOT(showColorDialog()));
62 connect(m_colorButton, SIGNAL(clicked()), this, SLOT(showColorDialog()));
40 connect(m_widthSpinBox, SIGNAL(valueChanged(double)), this, SLOT(updateWidth(double)));
63 connect(m_widthSpinBox, SIGNAL(valueChanged(double)), this, SLOT(updateWidth(double)));
64 connect(m_styleCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(updateStyle(int)));
65 connect(m_capStyleCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(updateCapStyle(int)));
66 connect(m_joinStyleCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(updateJoinStyle(int)));
41 }
67 }
42
68
43 void setPen(QPen pen)
69 void setPen(QPen pen)
@@ -45,6 +71,9 public:
45 m_pen = pen;
71 m_pen = pen;
46 m_colorButton->setText(m_pen.color().name());
72 m_colorButton->setText(m_pen.color().name());
47 m_widthSpinBox->setValue(m_pen.widthF());
73 m_widthSpinBox->setValue(m_pen.widthF());
74 m_styleCombo->setCurrentIndex(m_pen.style()); // index matches the enum
75 m_capStyleCombo->setCurrentIndex(m_capStyleCombo->findData(m_pen.capStyle()));
76 m_joinStyleCombo->setCurrentIndex(m_joinStyleCombo->findData(m_pen.joinStyle()));
48 }
77 }
49
78
50 QPen pen() const
79 QPen pen() const
@@ -85,10 +114,39 public Q_SLOTS:
85 }
114 }
86 }
115 }
87
116
117 void updateStyle(int style)
118 {
119 if (m_pen.style() != style) {
120 m_pen.setStyle((Qt::PenStyle) style);
121 emit changed();
122 }
123 }
124
125 void updateCapStyle(int index)
126 {
127 Qt::PenCapStyle capStyle = (Qt::PenCapStyle) m_capStyleCombo->itemData(index).toInt();
128 if (m_pen.capStyle() != capStyle) {
129 m_pen.setCapStyle(capStyle);
130 emit changed();
131 }
132 }
133
134 void updateJoinStyle(int index)
135 {
136 Qt::PenJoinStyle joinStyle = (Qt::PenJoinStyle) m_joinStyleCombo->itemData(index).toInt();
137 if (m_pen.joinStyle() != joinStyle) {
138 m_pen.setJoinStyle(joinStyle);
139 emit changed();
140 }
141 }
142
88 private:
143 private:
89 QPen m_pen;
144 QPen m_pen;
90 QPushButton *m_colorButton;
145 QPushButton *m_colorButton;
91 QDoubleSpinBox *m_widthSpinBox;
146 QDoubleSpinBox *m_widthSpinBox;
147 QComboBox *m_styleCombo;
148 QComboBox *m_capStyleCombo;
149 QComboBox *m_joinStyleCombo;
92 };
150 };
93
151
94 class BrushTool : public QWidget
152 class BrushTool : public QWidget
General Comments 0
You need to be logged in to leave comments. Login now