main.cpp
605 lines
| 20.1 KiB
| text/x-c
|
CppLexer
Jani Honkonen
|
r437 | #include <QtGui/QApplication> | ||
#include <QMainWindow> | ||||
#include <qchartglobal.h> | ||||
#include <qchartview.h> | ||||
#include <qpieseries.h> | ||||
#include <qpieslice.h> | ||||
#include <QGridLayout> | ||||
#include <QFormLayout> | ||||
#include <QComboBox> | ||||
#include <QSpinBox> | ||||
#include <QCheckBox> | ||||
#include <QGroupBox> | ||||
#include <QLabel> | ||||
Jani Honkonen
|
r511 | #include <QPushButton> | ||
#include <QColorDialog> | ||||
Jani Honkonen
|
r520 | #include <QFontDialog> | ||
Jani Honkonen
|
r437 | |||
QTCOMMERCIALCHART_USE_NAMESPACE | ||||
Jani Honkonen
|
r520 | class PenTool : public QWidget | ||
{ | ||||
Q_OBJECT | ||||
public: | ||||
explicit PenTool(QString title, QWidget *parent = 0) | ||||
:QWidget(parent) | ||||
{ | ||||
setWindowTitle(title); | ||||
setWindowFlags(Qt::Tool); | ||||
m_colorButton = new QPushButton(); | ||||
Jani Honkonen
|
r522 | |||
Jani Honkonen
|
r520 | m_widthSpinBox = new QDoubleSpinBox(); | ||
Jani Honkonen
|
r522 | m_styleCombo = new QComboBox(); | ||
m_styleCombo->addItem("NoPen"); | ||||
m_styleCombo->addItem("SolidLine"); | ||||
m_styleCombo->addItem("DashLine"); | ||||
m_styleCombo->addItem("DotLine"); | ||||
m_styleCombo->addItem("DashDotLine"); | ||||
m_styleCombo->addItem("DashDotDotLine"); | ||||
m_capStyleCombo = new QComboBox(); | ||||
m_capStyleCombo->addItem("FlatCap", Qt::FlatCap); | ||||
m_capStyleCombo->addItem("SquareCap", Qt::SquareCap); | ||||
m_capStyleCombo->addItem("RoundCap", Qt::RoundCap); | ||||
m_joinStyleCombo = new QComboBox(); | ||||
m_joinStyleCombo->addItem("MiterJoin", Qt::MiterJoin); | ||||
m_joinStyleCombo->addItem("BevelJoin", Qt::BevelJoin); | ||||
m_joinStyleCombo->addItem("RoundJoin", Qt::RoundJoin); | ||||
m_joinStyleCombo->addItem("SvgMiterJoin", Qt::SvgMiterJoin); | ||||
Jani Honkonen
|
r520 | QFormLayout *layout = new QFormLayout(); | ||
layout->addRow("Color", m_colorButton); | ||||
layout->addRow("Width", m_widthSpinBox); | ||||
Jani Honkonen
|
r522 | layout->addRow("Style", m_styleCombo); | ||
layout->addRow("Cap style", m_capStyleCombo); | ||||
layout->addRow("Join style", m_joinStyleCombo); | ||||
Jani Honkonen
|
r520 | setLayout(layout); | ||
connect(m_colorButton, SIGNAL(clicked()), this, SLOT(showColorDialog())); | ||||
connect(m_widthSpinBox, SIGNAL(valueChanged(double)), this, SLOT(updateWidth(double))); | ||||
Jani Honkonen
|
r522 | connect(m_styleCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(updateStyle(int))); | ||
connect(m_capStyleCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(updateCapStyle(int))); | ||||
connect(m_joinStyleCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(updateJoinStyle(int))); | ||||
Jani Honkonen
|
r520 | } | ||
void setPen(QPen pen) | ||||
{ | ||||
m_pen = pen; | ||||
m_colorButton->setText(m_pen.color().name()); | ||||
m_widthSpinBox->setValue(m_pen.widthF()); | ||||
Jani Honkonen
|
r522 | m_styleCombo->setCurrentIndex(m_pen.style()); // index matches the enum | ||
m_capStyleCombo->setCurrentIndex(m_capStyleCombo->findData(m_pen.capStyle())); | ||||
m_joinStyleCombo->setCurrentIndex(m_joinStyleCombo->findData(m_pen.joinStyle())); | ||||
Jani Honkonen
|
r520 | } | ||
QPen pen() const | ||||
{ | ||||
return m_pen; | ||||
} | ||||
QString name() | ||||
{ | ||||
return name(m_pen); | ||||
} | ||||
static QString name(const QPen &pen) | ||||
{ | ||||
return pen.color().name() + ":" + QString::number(pen.widthF()); | ||||
} | ||||
Q_SIGNALS: | ||||
void changed(); | ||||
public Q_SLOTS: | ||||
void showColorDialog() | ||||
{ | ||||
QColorDialog dialog(m_pen.color()); | ||||
dialog.show(); | ||||
dialog.exec(); | ||||
m_pen.setColor(dialog.selectedColor()); | ||||
m_colorButton->setText(m_pen.color().name()); | ||||
emit changed(); | ||||
} | ||||
void updateWidth(double width) | ||||
{ | ||||
if (width != m_pen.widthF()) { | ||||
m_pen.setWidthF(width); | ||||
emit changed(); | ||||
} | ||||
} | ||||
Jani Honkonen
|
r522 | void updateStyle(int style) | ||
{ | ||||
if (m_pen.style() != style) { | ||||
m_pen.setStyle((Qt::PenStyle) style); | ||||
emit changed(); | ||||
} | ||||
} | ||||
void updateCapStyle(int index) | ||||
{ | ||||
Qt::PenCapStyle capStyle = (Qt::PenCapStyle) m_capStyleCombo->itemData(index).toInt(); | ||||
if (m_pen.capStyle() != capStyle) { | ||||
m_pen.setCapStyle(capStyle); | ||||
emit changed(); | ||||
} | ||||
} | ||||
void updateJoinStyle(int index) | ||||
{ | ||||
Qt::PenJoinStyle joinStyle = (Qt::PenJoinStyle) m_joinStyleCombo->itemData(index).toInt(); | ||||
if (m_pen.joinStyle() != joinStyle) { | ||||
m_pen.setJoinStyle(joinStyle); | ||||
emit changed(); | ||||
} | ||||
} | ||||
Jani Honkonen
|
r520 | private: | ||
QPen m_pen; | ||||
QPushButton *m_colorButton; | ||||
QDoubleSpinBox *m_widthSpinBox; | ||||
Jani Honkonen
|
r522 | QComboBox *m_styleCombo; | ||
QComboBox *m_capStyleCombo; | ||||
QComboBox *m_joinStyleCombo; | ||||
Jani Honkonen
|
r520 | }; | ||
class BrushTool : public QWidget | ||||
{ | ||||
Q_OBJECT | ||||
public: | ||||
explicit BrushTool(QString title, QWidget *parent = 0) | ||||
:QWidget(parent) | ||||
{ | ||||
setWindowTitle(title); | ||||
setWindowFlags(Qt::Tool); | ||||
m_colorButton = new QPushButton(); | ||||
m_styleCombo = new QComboBox(); | ||||
m_styleCombo->addItem("Nobrush", Qt::NoBrush); | ||||
m_styleCombo->addItem("Solidpattern", Qt::SolidPattern); | ||||
m_styleCombo->addItem("Dense1pattern", Qt::Dense1Pattern); | ||||
m_styleCombo->addItem("Dense2attern", Qt::Dense2Pattern); | ||||
m_styleCombo->addItem("Dense3Pattern", Qt::Dense3Pattern); | ||||
m_styleCombo->addItem("Dense4Pattern", Qt::Dense4Pattern); | ||||
m_styleCombo->addItem("Dense5Pattern", Qt::Dense5Pattern); | ||||
m_styleCombo->addItem("Dense6Pattern", Qt::Dense6Pattern); | ||||
m_styleCombo->addItem("Dense7Pattern", Qt::Dense7Pattern); | ||||
m_styleCombo->addItem("HorPattern", Qt::HorPattern); | ||||
m_styleCombo->addItem("VerPattern", Qt::VerPattern); | ||||
m_styleCombo->addItem("CrossPattern", Qt::CrossPattern); | ||||
m_styleCombo->addItem("BDiagPattern", Qt::BDiagPattern); | ||||
m_styleCombo->addItem("FDiagPattern", Qt::FDiagPattern); | ||||
m_styleCombo->addItem("DiagCrossPattern", Qt::DiagCrossPattern); | ||||
QFormLayout *layout = new QFormLayout(); | ||||
layout->addRow("Color", m_colorButton); | ||||
layout->addRow("Style", m_styleCombo); | ||||
setLayout(layout); | ||||
connect(m_colorButton, SIGNAL(clicked()), this, SLOT(showColorDialog())); | ||||
connect(m_styleCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(updateStyle())); | ||||
} | ||||
void setBrush(QBrush brush) | ||||
{ | ||||
m_brush = brush; | ||||
m_colorButton->setText(m_brush.color().name()); | ||||
m_styleCombo->setCurrentIndex(m_brush.style()); // index matches the enum | ||||
} | ||||
QBrush brush() const | ||||
{ | ||||
return m_brush; | ||||
} | ||||
QString name() | ||||
{ | ||||
return name(m_brush); | ||||
} | ||||
static QString name(const QBrush &brush) | ||||
{ | ||||
return brush.color().name(); | ||||
} | ||||
Q_SIGNALS: | ||||
void changed(); | ||||
public Q_SLOTS: | ||||
void showColorDialog() | ||||
{ | ||||
QColorDialog dialog(m_brush.color()); | ||||
dialog.show(); | ||||
dialog.exec(); | ||||
m_brush.setColor(dialog.selectedColor()); | ||||
m_colorButton->setText(m_brush.color().name()); | ||||
emit changed(); | ||||
} | ||||
void updateStyle() | ||||
{ | ||||
Qt::BrushStyle style = (Qt::BrushStyle) m_styleCombo->itemData(m_styleCombo->currentIndex()).toInt(); | ||||
if (m_brush.style() != style) { | ||||
m_brush.setStyle(style); | ||||
emit changed(); | ||||
} | ||||
} | ||||
private: | ||||
QBrush m_brush; | ||||
QPushButton *m_colorButton; | ||||
QComboBox *m_styleCombo; | ||||
}; | ||||
Jani Honkonen
|
r437 | class CustomSlice : public QPieSlice | ||
{ | ||||
Q_OBJECT | ||||
public: | ||||
CustomSlice(qreal value, QString label) | ||||
:QPieSlice(value, label) | ||||
{ | ||||
connect(this, SIGNAL(hoverEnter()), this, SLOT(handleHoverEnter())); | ||||
connect(this, SIGNAL(hoverLeave()), this, SLOT(handleHoverLeave())); | ||||
} | ||||
Jani Honkonen
|
r511 | public: | ||
QBrush originalBrush() | ||||
{ | ||||
return m_originalBrush; | ||||
} | ||||
Jani Honkonen
|
r437 | public Q_SLOTS: | ||
void handleHoverEnter() | ||||
{ | ||||
Jani Honkonen
|
r469 | QBrush brush = this->sliceBrush(); | ||
Jani Honkonen
|
r437 | m_originalBrush = brush; | ||
brush.setColor(brush.color().lighter()); | ||||
Jani Honkonen
|
r469 | setSliceBrush(brush); | ||
Jani Honkonen
|
r437 | } | ||
void handleHoverLeave() | ||||
{ | ||||
Jani Honkonen
|
r469 | setSliceBrush(m_originalBrush); | ||
Jani Honkonen
|
r437 | } | ||
private: | ||||
QBrush m_originalBrush; | ||||
}; | ||||
class MainWidget : public QWidget | ||||
{ | ||||
Q_OBJECT | ||||
public: | ||||
explicit MainWidget(QWidget* parent = 0) | ||||
Jani Honkonen
|
r454 | :QWidget(parent), | ||
m_slice(0) | ||||
Jani Honkonen
|
r437 | { | ||
Jani Honkonen
|
r511 | // create chart | ||
Jani Honkonen
|
r437 | m_chartView = new QChartView(); | ||
m_chartView->setChartTitle("Piechart customization"); | ||||
Jani Honkonen
|
r618 | m_chartView->setAnimationOptions(QChart::AllAnimations); | ||
Jani Honkonen
|
r437 | |||
Jani Honkonen
|
r511 | // create series | ||
Jani Honkonen
|
r437 | m_series = new QPieSeries(); | ||
*m_series << new CustomSlice(10.0, "Slice 1"); | ||||
*m_series << new CustomSlice(20.0, "Slice 2"); | ||||
*m_series << new CustomSlice(30.0, "Slice 3"); | ||||
*m_series << new CustomSlice(40.0, "Slice 4"); | ||||
*m_series << new CustomSlice(50.0, "Slice 5"); | ||||
m_chartView->addSeries(m_series); | ||||
Jani Honkonen
|
r511 | connect(m_series, SIGNAL(clicked(QPieSlice*)), this, SLOT(handleSliceClicked(QPieSlice*))); | ||
// chart settings | ||||
m_themeComboBox = new QComboBox(); | ||||
m_themeComboBox->addItem("Default", QChart::ChartThemeDefault); | ||||
m_themeComboBox->addItem("Vanilla", QChart::ChartThemeVanilla); | ||||
m_themeComboBox->addItem("Icy", QChart::ChartThemeIcy); | ||||
m_themeComboBox->addItem("Grayscale", QChart::ChartThemeGrayscale); | ||||
m_themeComboBox->addItem("Scientific", QChart::ChartThemeScientific); | ||||
m_aaCheckBox = new QCheckBox(); | ||||
Jani Honkonen
|
r628 | m_animationsCheckBox = new QCheckBox(); | ||
m_animationsCheckBox->setCheckState(Qt::Checked); | ||||
Jani Honkonen
|
r511 | |||
QFormLayout* chartSettingsLayout = new QFormLayout(); | ||||
chartSettingsLayout->addRow("Theme", m_themeComboBox); | ||||
chartSettingsLayout->addRow("Antialiasing", m_aaCheckBox); | ||||
Jani Honkonen
|
r628 | chartSettingsLayout->addRow("Animations", m_animationsCheckBox); | ||
Jani Honkonen
|
r511 | QGroupBox* chartSettings = new QGroupBox("Chart"); | ||
chartSettings->setLayout(chartSettingsLayout); | ||||
connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this ,SLOT(updateChartSettings())); | ||||
connect(m_aaCheckBox, SIGNAL(toggled(bool)), this ,SLOT(updateChartSettings())); | ||||
Jani Honkonen
|
r628 | connect(m_animationsCheckBox, SIGNAL(toggled(bool)), this ,SLOT(updateChartSettings())); | ||
Jani Honkonen
|
r511 | |||
// series settings | ||||
Jani Honkonen
|
r454 | m_hPosition = new QDoubleSpinBox(); | ||
m_hPosition->setMinimum(0.0); | ||||
m_hPosition->setMaximum(1.0); | ||||
m_hPosition->setSingleStep(0.1); | ||||
Jani Honkonen
|
r498 | m_hPosition->setValue(m_series->pieHorizontalPosition()); | ||
Jani Honkonen
|
r437 | |||
Jani Honkonen
|
r454 | m_vPosition = new QDoubleSpinBox(); | ||
m_vPosition->setMinimum(0.0); | ||||
m_vPosition->setMaximum(1.0); | ||||
m_vPosition->setSingleStep(0.1); | ||||
Jani Honkonen
|
r498 | m_vPosition->setValue(m_series->pieVerticalPosition()); | ||
Jani Honkonen
|
r437 | |||
m_sizeFactor = new QDoubleSpinBox(); | ||||
m_sizeFactor->setMinimum(0.0); | ||||
m_sizeFactor->setMaximum(1.0); | ||||
m_sizeFactor->setSingleStep(0.1); | ||||
Jani Honkonen
|
r498 | m_sizeFactor->setValue(m_series->pieSize()); | ||
Jani Honkonen
|
r437 | |||
m_startAngle = new QDoubleSpinBox(); | ||||
m_startAngle->setMinimum(0.0); | ||||
m_startAngle->setMaximum(360); | ||||
Jani Honkonen
|
r498 | m_startAngle->setValue(m_series->pieStartAngle()); | ||
Jani Honkonen
|
r437 | m_startAngle->setSingleStep(1); | ||
m_endAngle = new QDoubleSpinBox(); | ||||
m_endAngle->setMinimum(0.0); | ||||
m_endAngle->setMaximum(360); | ||||
Jani Honkonen
|
r498 | m_endAngle->setValue(m_series->pieEndAngle()); | ||
Jani Honkonen
|
r437 | m_endAngle->setSingleStep(1); | ||
Jani Honkonen
|
r618 | QPushButton *addSlice = new QPushButton("Add slice"); | ||
Jani Honkonen
|
r621 | QPushButton *insertSlice = new QPushButton("Insert slice"); | ||
Jani Honkonen
|
r618 | |||
Jani Honkonen
|
r437 | QFormLayout* seriesSettingsLayout = new QFormLayout(); | ||
seriesSettingsLayout->addRow("Horizontal position", m_hPosition); | ||||
Jani Honkonen
|
r454 | seriesSettingsLayout->addRow("Vertical position", m_vPosition); | ||
Jani Honkonen
|
r437 | seriesSettingsLayout->addRow("Size factor", m_sizeFactor); | ||
seriesSettingsLayout->addRow("Start angle", m_startAngle); | ||||
seriesSettingsLayout->addRow("End angle", m_endAngle); | ||||
Jani Honkonen
|
r618 | seriesSettingsLayout->addRow(addSlice); | ||
Jani Honkonen
|
r621 | seriesSettingsLayout->addRow(insertSlice); | ||
Jani Honkonen
|
r437 | QGroupBox* seriesSettings = new QGroupBox("Series"); | ||
seriesSettings->setLayout(seriesSettingsLayout); | ||||
Jani Honkonen
|
r511 | connect(m_vPosition, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings())); | ||
connect(m_hPosition, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings())); | ||||
connect(m_sizeFactor, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings())); | ||||
connect(m_startAngle, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings())); | ||||
connect(m_endAngle, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings())); | ||||
Jani Honkonen
|
r618 | connect(addSlice, SIGNAL(clicked()), this, SLOT(addSlice())); | ||
Jani Honkonen
|
r621 | connect(insertSlice, SIGNAL(clicked()), this, SLOT(insertSlice())); | ||
Jani Honkonen
|
r511 | |||
// slice settings | ||||
Jani Honkonen
|
r437 | m_sliceName = new QLabel("<click a slice>"); | ||
m_sliceValue = new QDoubleSpinBox(); | ||||
m_sliceValue->setMaximum(1000); | ||||
m_sliceLabelVisible = new QCheckBox(); | ||||
Jani Honkonen
|
r454 | m_sliceLabelArmFactor = new QDoubleSpinBox(); | ||
m_sliceLabelArmFactor->setSingleStep(0.01); | ||||
Jani Honkonen
|
r437 | m_sliceExploded = new QCheckBox(); | ||
Jani Honkonen
|
r454 | m_sliceExplodedFactor = new QDoubleSpinBox(); | ||
m_sliceExplodedFactor->setSingleStep(0.01); | ||||
Jani Honkonen
|
r520 | m_pen = new QPushButton(); | ||
m_penTool = new PenTool("Slice pen", this); | ||||
m_brush = new QPushButton(); | ||||
m_brushTool = new BrushTool("Slice brush", this); | ||||
m_font = new QPushButton(); | ||||
m_labelArmPen = new QPushButton(); | ||||
m_labelArmPenTool = new PenTool("Label arm pen", this); | ||||
Jani Honkonen
|
r618 | QPushButton *removeSlice = new QPushButton("Remove slice"); | ||
Jani Honkonen
|
r437 | |||
QFormLayout* sliceSettingsLayout = new QFormLayout(); | ||||
sliceSettingsLayout->addRow("Selected", m_sliceName); | ||||
sliceSettingsLayout->addRow("Value", m_sliceValue); | ||||
Jani Honkonen
|
r520 | sliceSettingsLayout->addRow("Pen", m_pen); | ||
sliceSettingsLayout->addRow("Brush", m_brush); | ||||
Jani Honkonen
|
r437 | sliceSettingsLayout->addRow("Label visible", m_sliceLabelVisible); | ||
Jani Honkonen
|
r520 | sliceSettingsLayout->addRow("Label font", m_font); | ||
sliceSettingsLayout->addRow("Label arm pen", m_labelArmPen); | ||||
Jani Honkonen
|
r454 | sliceSettingsLayout->addRow("Label arm length", m_sliceLabelArmFactor); | ||
Jani Honkonen
|
r437 | sliceSettingsLayout->addRow("Exploded", m_sliceExploded); | ||
Jani Honkonen
|
r454 | sliceSettingsLayout->addRow("Explode distance", m_sliceExplodedFactor); | ||
Jani Honkonen
|
r618 | sliceSettingsLayout->addRow(removeSlice); | ||
Jani Honkonen
|
r437 | QGroupBox* sliceSettings = new QGroupBox("Slice"); | ||
sliceSettings->setLayout(sliceSettingsLayout); | ||||
connect(m_sliceValue, SIGNAL(valueChanged(double)), this, SLOT(updateSliceSettings())); | ||||
Jani Honkonen
|
r520 | connect(m_pen, SIGNAL(clicked()), m_penTool, SLOT(show())); | ||
connect(m_penTool, SIGNAL(changed()), this, SLOT(updateSliceSettings())); | ||||
connect(m_brush, SIGNAL(clicked()), m_brushTool, SLOT(show())); | ||||
connect(m_brushTool, SIGNAL(changed()), this, SLOT(updateSliceSettings())); | ||||
connect(m_font, SIGNAL(clicked()), this, SLOT(showFontDialog())); | ||||
connect(m_labelArmPen, SIGNAL(clicked()), m_labelArmPenTool, SLOT(show())); | ||||
connect(m_labelArmPenTool, SIGNAL(changed()), this, SLOT(updateSliceSettings())); | ||||
connect(m_sliceLabelVisible, SIGNAL(toggled(bool)), this, SLOT(updateSliceSettings())); | ||||
Jani Honkonen
|
r437 | connect(m_sliceLabelVisible, SIGNAL(toggled(bool)), this, SLOT(updateSliceSettings())); | ||
Jani Honkonen
|
r454 | connect(m_sliceLabelArmFactor, SIGNAL(valueChanged(double)), this, SLOT(updateSliceSettings())); | ||
Jani Honkonen
|
r437 | connect(m_sliceExploded, SIGNAL(toggled(bool)), this, SLOT(updateSliceSettings())); | ||
Jani Honkonen
|
r454 | connect(m_sliceExplodedFactor, SIGNAL(valueChanged(double)), this, SLOT(updateSliceSettings())); | ||
Jani Honkonen
|
r618 | connect(removeSlice, SIGNAL(clicked()), this, SLOT(removeSlice())); | ||
Jani Honkonen
|
r437 | |||
Jani Honkonen
|
r511 | // create main layout | ||
QVBoxLayout *settingsLayout = new QVBoxLayout(); | ||||
settingsLayout->addWidget(chartSettings); | ||||
settingsLayout->addWidget(seriesSettings); | ||||
settingsLayout->addWidget(sliceSettings); | ||||
settingsLayout->addStretch(); | ||||
QGridLayout* baseLayout = new QGridLayout(); | ||||
baseLayout->addLayout(settingsLayout, 0, 0); | ||||
baseLayout->addWidget(m_chartView, 0, 1); | ||||
setLayout(baseLayout); | ||||
Jani Honkonen
|
r437 | |||
updateSerieSettings(); | ||||
} | ||||
public Q_SLOTS: | ||||
Jani Honkonen
|
r511 | void updateChartSettings() | ||
{ | ||||
QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData(m_themeComboBox->currentIndex()).toInt(); | ||||
m_chartView->setChartTheme(theme); | ||||
m_chartView->setRenderHint(QPainter::Antialiasing, m_aaCheckBox->isChecked()); | ||||
Jani Honkonen
|
r628 | |||
if (m_animationsCheckBox->checkState() == Qt::Checked) | ||||
m_chartView->setAnimationOptions(QChart::AllAnimations); | ||||
else | ||||
m_chartView->setAnimationOptions(QChart::NoAnimation); | ||||
Jani Honkonen
|
r511 | } | ||
Jani Honkonen
|
r437 | void updateSerieSettings() | ||
{ | ||||
Jani Honkonen
|
r633 | m_series->setPiePosition(m_hPosition->value(), m_vPosition->value()); | ||
Jani Honkonen
|
r498 | m_series->setPieSize(m_sizeFactor->value()); | ||
m_series->setPieStartAngle(m_startAngle->value()); | ||||
m_series->setPieEndAngle(m_endAngle->value()); | ||||
Jani Honkonen
|
r437 | } | ||
void updateSliceSettings() | ||||
{ | ||||
Jani Honkonen
|
r454 | if (!m_slice) | ||
return; | ||||
Jani Honkonen
|
r437 | m_slice->setValue(m_sliceValue->value()); | ||
Jani Honkonen
|
r511 | |||
Jani Honkonen
|
r520 | m_slice->setSlicePen(m_penTool->pen()); | ||
m_slice->setSliceBrush(m_brushTool->brush()); | ||||
Jani Honkonen
|
r511 | |||
Jani Honkonen
|
r520 | m_slice->setLabelArmPen(m_labelArmPenTool->pen()); | ||
Jani Honkonen
|
r437 | m_slice->setLabelVisible(m_sliceLabelVisible->isChecked()); | ||
Jani Honkonen
|
r454 | m_slice->setLabelArmLengthFactor(m_sliceLabelArmFactor->value()); | ||
Jani Honkonen
|
r511 | |||
Jani Honkonen
|
r437 | m_slice->setExploded(m_sliceExploded->isChecked()); | ||
Jani Honkonen
|
r454 | m_slice->setExplodeDistanceFactor(m_sliceExplodedFactor->value()); | ||
Jani Honkonen
|
r437 | } | ||
void handleSliceClicked(QPieSlice* slice) | ||||
{ | ||||
Jani Honkonen
|
r511 | m_slice = static_cast<CustomSlice*>(slice); | ||
Jani Honkonen
|
r520 | // name | ||
Jani Honkonen
|
r437 | m_sliceName->setText(slice->label()); | ||
Jani Honkonen
|
r520 | // value | ||
Jani Honkonen
|
r437 | m_sliceValue->blockSignals(true); | ||
m_sliceValue->setValue(slice->value()); | ||||
m_sliceValue->blockSignals(false); | ||||
Jani Honkonen
|
r520 | // pen | ||
m_pen->setText(PenTool::name(m_slice->slicePen())); | ||||
m_penTool->setPen(m_slice->slicePen()); | ||||
Jani Honkonen
|
r511 | |||
Jani Honkonen
|
r520 | // brush | ||
m_brush->setText(m_slice->originalBrush().color().name()); | ||||
m_brushTool->setBrush(m_slice->originalBrush()); | ||||
Jani Honkonen
|
r511 | |||
Jani Honkonen
|
r520 | // label | ||
m_labelArmPen->setText(PenTool::name(m_slice->labelArmPen())); | ||||
m_labelArmPenTool->setPen(m_slice->labelArmPen()); | ||||
m_font->setText(slice->labelFont().toString()); | ||||
Jani Honkonen
|
r437 | m_sliceLabelVisible->blockSignals(true); | ||
m_sliceLabelVisible->setChecked(slice->isLabelVisible()); | ||||
m_sliceLabelVisible->blockSignals(false); | ||||
Jani Honkonen
|
r454 | m_sliceLabelArmFactor->blockSignals(true); | ||
m_sliceLabelArmFactor->setValue(slice->labelArmLengthFactor()); | ||||
m_sliceLabelArmFactor->blockSignals(false); | ||||
Jani Honkonen
|
r520 | // exploded | ||
Jani Honkonen
|
r437 | m_sliceExploded->blockSignals(true); | ||
m_sliceExploded->setChecked(slice->isExploded()); | ||||
m_sliceExploded->blockSignals(false); | ||||
Jani Honkonen
|
r454 | m_sliceExplodedFactor->blockSignals(true); | ||
m_sliceExplodedFactor->setValue(slice->explodeDistanceFactor()); | ||||
m_sliceExplodedFactor->blockSignals(false); | ||||
Jani Honkonen
|
r437 | } | ||
Jani Honkonen
|
r520 | void showFontDialog() | ||
Jani Honkonen
|
r511 | { | ||
if (!m_slice) | ||||
return; | ||||
Jani Honkonen
|
r520 | QFontDialog dialog(m_slice->labelFont()); | ||
Jani Honkonen
|
r511 | dialog.show(); | ||
dialog.exec(); | ||||
Jani Honkonen
|
r520 | m_slice->setLabelFont(dialog.currentFont()); | ||
m_font->setText(dialog.currentFont().toString()); | ||||
Jani Honkonen
|
r511 | } | ||
Jani Honkonen
|
r618 | void addSlice() | ||
{ | ||||
Jani Honkonen
|
r657 | *m_series << new CustomSlice(10.0, "Slice " + QString::number(m_series->count()+1)); | ||
Jani Honkonen
|
r618 | } | ||
Jani Honkonen
|
r621 | void insertSlice() | ||
{ | ||||
if (!m_slice) | ||||
return; | ||||
int i = m_series->slices().indexOf(m_slice); | ||||
Jani Honkonen
|
r657 | m_series->insert(i, new CustomSlice(10.0, "Slice " + QString::number(m_series->count()+1))); | ||
Jani Honkonen
|
r621 | } | ||
Jani Honkonen
|
r618 | void removeSlice() | ||
{ | ||||
if (!m_slice) | ||||
return; | ||||
m_series->remove(m_slice); | ||||
m_slice = 0; | ||||
} | ||||
Jani Honkonen
|
r437 | private: | ||
Jani Honkonen
|
r511 | QComboBox *m_themeComboBox; | ||
QCheckBox *m_aaCheckBox; | ||||
Jani Honkonen
|
r628 | QCheckBox *m_animationsCheckBox; | ||
Jani Honkonen
|
r511 | |||
Jani Honkonen
|
r437 | QChartView* m_chartView; | ||
QPieSeries* m_series; | ||||
Jani Honkonen
|
r511 | CustomSlice* m_slice; | ||
Jani Honkonen
|
r437 | |||
Jani Honkonen
|
r454 | QDoubleSpinBox* m_hPosition; | ||
QDoubleSpinBox* m_vPosition; | ||||
Jani Honkonen
|
r437 | QDoubleSpinBox* m_sizeFactor; | ||
QDoubleSpinBox* m_startAngle; | ||||
QDoubleSpinBox* m_endAngle; | ||||
QLabel* m_sliceName; | ||||
QDoubleSpinBox* m_sliceValue; | ||||
QCheckBox* m_sliceLabelVisible; | ||||
Jani Honkonen
|
r454 | QDoubleSpinBox* m_sliceLabelArmFactor; | ||
Jani Honkonen
|
r437 | QCheckBox* m_sliceExploded; | ||
Jani Honkonen
|
r454 | QDoubleSpinBox* m_sliceExplodedFactor; | ||
Jani Honkonen
|
r520 | QPushButton *m_brush; | ||
BrushTool *m_brushTool; | ||||
QPushButton *m_pen; | ||||
PenTool *m_penTool; | ||||
QPushButton *m_font; | ||||
QPushButton *m_labelArmPen; | ||||
PenTool *m_labelArmPenTool; | ||||
Jani Honkonen
|
r437 | }; | ||
int main(int argc, char *argv[]) | ||||
{ | ||||
QApplication a(argc, argv); | ||||
QMainWindow window; | ||||
MainWidget* widget = new MainWidget(); | ||||
window.setCentralWidget(widget); | ||||
window.resize(900, 600); | ||||
window.show(); | ||||
return a.exec(); | ||||
} | ||||
#include "main.moc" | ||||