Warning, file /graphics/kdiagram/examples/Background/main.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /** 0002 * Copyright (C) 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved. 0003 * 0004 * This file is part of the KD Chart library. 0005 * 0006 * This program is free software; you can redistribute it and/or 0007 * modify it under the terms of the GNU General Public License as 0008 * published by the Free Software Foundation; either version 2 of 0009 * the License, or (at your option) any later version. 0010 * 0011 * This program is distributed in the hope that it will be useful, 0012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0014 * GNU General Public License for more details. 0015 * 0016 * You should have received a copy of the GNU General Public License 0017 * along with this program. If not, see <https://www.gnu.org/licenses/>. 0018 */ 0019 0020 #include <QApplication> 0021 #include <QStandardItemModel> 0022 #include <QWidget> 0023 #include <KChartChart> 0024 #include <KChartBarDiagram> 0025 #include <KChartHeaderFooter> 0026 #include <KChartPosition> 0027 #include <KChartBackgroundAttributes> 0028 #include <KChartFrameAttributes> 0029 0030 #include <QPixmap> 0031 0032 using namespace KChart; 0033 0034 class ChartWidget : public QWidget { 0035 Q_OBJECT 0036 public: 0037 explicit ChartWidget(QWidget* parent = nullptr) 0038 : QWidget(parent) 0039 { 0040 0041 m_model.insertRows( 0, 2, QModelIndex() ); 0042 m_model.insertColumns( 0, 3, QModelIndex() ); 0043 for (int row = 0; row < 3; ++row) { 0044 for (int column = 0; column < 3; ++column) { 0045 QModelIndex index = m_model.index(row, column, QModelIndex()); 0046 m_model.setData(index, QVariant(row+1 * column) ); 0047 } 0048 } 0049 0050 QPixmap* pixmap = new QPixmap ( "background.png" ); 0051 BarDiagram* diagram = new BarDiagram; 0052 diagram->setModel(&m_model); 0053 0054 m_chart.coordinatePlane()->replaceDiagram(diagram); 0055 0056 // Add at one Header and set it up 0057 HeaderFooter* header = new HeaderFooter( &m_chart ); 0058 header->setPosition( Position::North ); 0059 header->setText( "A Simple Bar Chart" ); 0060 m_chart.addHeaderFooter( header ); 0061 0062 // Configure the Header text attributes 0063 TextAttributes hta; 0064 hta.setPen( QPen( Qt::blue ) ); 0065 0066 // let the header resize itself 0067 // together with the widget. 0068 // so-called relative size 0069 Measure m( 35.0 ); 0070 m.setRelativeMode( header->autoReferenceArea(), 0071 KChartEnums::MeasureOrientationMinimum ); 0072 hta.setFontSize( m ); 0073 // min font size 0074 m.setValue( 3.0 ); 0075 m.setCalculationMode( KChartEnums::MeasureCalculationModeAbsolute ); 0076 hta.setMinimalFontSize( m ); 0077 header->setTextAttributes( hta ); 0078 0079 // Configure the plane's Background 0080 BackgroundAttributes pba; 0081 pba.setPixmap( *pixmap ); 0082 pba.setPixmapMode( BackgroundAttributes::BackgroundPixmapModeStretched ); 0083 pba.setVisible( true ); 0084 diagram->coordinatePlane()->setBackgroundAttributes( pba ); 0085 0086 // Configure the Header's Background 0087 BackgroundAttributes hba; 0088 hba.setBrush( Qt::white ); 0089 hba.setVisible( true ); 0090 header->setBackgroundAttributes( hba ); 0091 0092 // Configure the plane Frame attributes 0093 FrameAttributes pfa; 0094 pfa.setPen( QPen ( QBrush( Qt::blue ), 2 ) ); 0095 pfa.setVisible( true ); 0096 diagram->coordinatePlane()->setFrameAttributes( pfa ); 0097 0098 // Configure the header Frame attributes 0099 FrameAttributes hfa; 0100 hfa.setPen( QPen ( QBrush( Qt::darkGray ), 2 ) ); 0101 hfa.setPadding( 2 ); 0102 hfa.setVisible( true ); 0103 header->setFrameAttributes( hfa ); 0104 0105 QVBoxLayout* l = new QVBoxLayout(this); 0106 l->addWidget(&m_chart); 0107 setLayout(l); 0108 } 0109 0110 private: 0111 Chart m_chart; 0112 QStandardItemModel m_model; 0113 QPixmap pixmap; 0114 }; 0115 0116 int main( int argc, char** argv ) { 0117 QApplication app( argc, argv ); 0118 0119 ChartWidget w; 0120 w.show(); 0121 0122 return app.exec(); 0123 } 0124 0125 #include "main.moc"