~ubuntu-branches/ubuntu/precise/koffice/precise

« back to all changes in this revision

Viewing changes to kchart/kdchart/examples/Zoom/ScrollBars/mainwindow.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2010-09-21 15:36:35 UTC
  • mfrom: (1.4.1 upstream) (60.2.11 maverick)
  • Revision ID: james.westby@ubuntu.com-20100921153635-6tejqkiro2u21ydi
Tags: 1:2.2.2-0ubuntu3
Add kubuntu_03_fix-crash-on-closing-sqlite-connection-2.2.2.diff and
kubuntu_04_support-large-memo-values-for-msaccess-2.2.2.diff as
recommended by upstream http://kexi-
project.org/wiki/wikiview/index.php@Kexi2.2_Patches.html#sqlite_stab
ility

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/****************************************************************************
2
 
 ** Copyright (C) 2006 Klarälvdalens Datakonsult AB.  All rights reserved.
3
 
 **
4
 
 ** This file is part of the KD Chart library.
5
 
 **
6
 
 ** This file may be used under the terms of the GNU General Public
7
 
 ** License versions 2.0 or 3.0 as published by the Free Software
8
 
 ** Foundation and appearing in the files LICENSE.GPL2 and LICENSE.GPL3
9
 
 ** included in the packaging of this file.  Alternatively you may (at
10
 
 ** your option) use any later version of the GNU General Public
11
 
 ** License if such license has been publicly approved by
12
 
 ** Klarälvdalens Datakonsult AB (or its successors, if any).
13
 
 ** 
14
 
 ** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
15
 
 ** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
16
 
 ** A PARTICULAR PURPOSE. Klarälvdalens Datakonsult AB reserves all rights
17
 
 ** not expressly granted herein.
18
 
 ** 
19
 
 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
20
 
 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
21
 
 **
22
 
 **********************************************************************/
23
 
 
24
 
#include "mainwindow.h"
25
 
 
26
 
#include <KDChartChart>
27
 
#include <KDChartAbstractCoordinatePlane>
28
 
#include <KDChartLineDiagram>
29
 
#include <KDChartLegend>
30
 
 
31
 
#include <QDebug>
32
 
#include <QPainter>
33
 
 
34
 
using namespace KDChart;
35
 
 
36
 
MainWindow::MainWindow( QWidget* parent ) :
37
 
    QWidget( parent )
38
 
{
39
 
    setupUi( this );
40
 
 
41
 
    QHBoxLayout* chartLayout = new QHBoxLayout( chartFrame );
42
 
    m_chart = new Chart();
43
 
    m_chart->setGlobalLeadingTop( 10 );
44
 
    m_chart->setGlobalLeadingRight( 10 );
45
 
    chartLayout->addWidget( m_chart );
46
 
    hSBar->setVisible( false );
47
 
    vSBar->setVisible( false );
48
 
 
49
 
    m_model.loadFromCSV( ":/data" );
50
 
 
51
 
    // Set up the diagram
52
 
    m_lines = new LineDiagram();
53
 
    m_lines->setModel( &m_model );
54
 
 
55
 
    CartesianAxis *xAxis = new CartesianAxis( m_lines );
56
 
    CartesianAxis *yAxis = new CartesianAxis ( m_lines );
57
 
    xAxis->setPosition ( KDChart::CartesianAxis::Bottom );
58
 
    yAxis->setPosition ( KDChart::CartesianAxis::Left );
59
 
 
60
 
    xAxis->setTitleText ( "Abscissa axis at the bottom" );
61
 
    yAxis->setTitleText ( "Ordinate axis at the left side" );
62
 
 
63
 
    m_lines->addAxis( xAxis );
64
 
    m_lines->addAxis( yAxis );
65
 
    m_chart->coordinatePlane()->replaceDiagram( m_lines );
66
 
 
67
 
    // Set up the legend
68
 
    m_legend = new Legend( m_lines, m_chart );
69
 
    m_chart->addLegend( m_legend );
70
 
    m_legend->setPosition( KDChartEnums::PositionEast );
71
 
    m_legend->setAlignment( Qt::AlignTop );
72
 
}
73
 
 
74
 
 
75
 
void MainWindow::on_zoomFactorSB_valueChanged( double factor )
76
 
{
77
 
    if ( factor > 1 ) {
78
 
        hSBar->setVisible( true );
79
 
        vSBar->setVisible( true );
80
 
    } else {
81
 
        hSBar->setValue( 500 );
82
 
        vSBar->setValue( 500 );
83
 
        hSBar->setVisible( false );
84
 
        vSBar->setVisible( false );
85
 
    }
86
 
    m_chart->coordinatePlane()->setZoomFactorX( factor );
87
 
    m_chart->coordinatePlane()->setZoomFactorY( factor );
88
 
    m_chart->update();
89
 
}
90
 
 
91
 
void MainWindow::on_adjustGridCB_toggled( bool checked )
92
 
{
93
 
    static_cast <CartesianCoordinatePlane*>( m_chart->coordinatePlane() )
94
 
            ->setAutoAdjustGridToZoom( checked );
95
 
    m_chart->update();
96
 
}
97
 
 
98
 
void MainWindow::on_hSBar_valueChanged( int hPos )
99
 
{
100
 
    m_chart->coordinatePlane()->setZoomCenter( QPointF(hPos/1000.0, vSBar->value()/1000.0) );
101
 
    m_chart->update();
102
 
}
103
 
 
104
 
void MainWindow::on_vSBar_valueChanged( int vPos )
105
 
{
106
 
    m_chart->coordinatePlane()->setZoomCenter( QPointF( hSBar->value()/1000.0, vPos/1000.0) );
107
 
    m_chart->update();
108
 
}
109