]> Git trees. - libqmvoc.git/commitdiff
Start moving some of the KPlotWidget internal stuff to a Private class.
authorPino Toscano <pino@kde.org>
Fri, 16 Feb 2007 15:53:07 +0000 (15:53 +0000)
committerPino Toscano <pino@kde.org>
Fri, 16 Feb 2007 15:53:07 +0000 (15:53 +0000)
svn path=/trunk/KDE/kdeedu/libkdeedu/; revision=634193

kdeeduplot/kplotwidget.cpp
kdeeduplot/kplotwidget.h

index fb6f5e7ed330d0a0046118f1ea6894199a19dc53..03eed6e674fec6c75304cb0842742d5c61068e1c 100644 (file)
 #define SMALLTICKSIZE 4
 #define TICKOFFSET 0
 
+class KPlotWidget::Private
+{
+    public:
+        Private( KPlotWidget *qq )
+          : q( qq ),
+            cBackground( Qt::white ), cForeground( Qt::white ), cGrid( Qt::gray ),
+            showGrid( false ), showObjectToolTips( true ), useAntialias( false )
+        {
+        }
+
+        KPlotWidget *q;
+
+        //Colors
+        QColor cBackground, cForeground, cGrid;
+        //draw options
+        bool showGrid, showObjectToolTips, useAntialias;
+};
+
 KPlotWidget::KPlotWidget( QWidget *parent, double x1, double x2, double y1, double y2 )
: QFrame( parent ), ShowGrid( false ), ShowObjectToolTips( true ), UseAntialias( false )
   : QFrame( parent ), d( new Private( this ) )
 {
        setAttribute( Qt::WA_NoBackground, true );
 
@@ -59,11 +77,6 @@ KPlotWidget::KPlotWidget( QWidget *parent, double x1, double x2, double y1, doub
 
        setDefaultPaddings();
 
-       //default colors:
-       setBackgroundColor( Qt::black );
-       setForegroundColor( Qt::white );
-       setGridColor( Qt::gray );
-
        setMinimumSize( 150, 150 );
 }
 
@@ -73,6 +86,8 @@ KPlotWidget::~KPlotWidget()
        ObjectList.clear();
        qDeleteAll( mAxes );
        mAxes.clear();
+
+    delete d;
 }
 
 QSize KPlotWidget::minimumSizeHint() const
@@ -191,18 +206,67 @@ KPlotObject *KPlotWidget::object( int i ) {
        return ObjectList.at(i);
 }
 
+QColor KPlotWidget::backgroundColor() const
+{
+    return d->cBackground;
+}
+
+QColor KPlotWidget::foregroundColor() const
+{
+    return d->cForeground;
+}
+
+QColor KPlotWidget::gridColor() const
+{
+    return d->cGrid;
+}
+
 void KPlotWidget::setBackgroundColor( const QColor &bg ) {
-       cBackground = bg;
+    d->cBackground = bg;
        update();
 }
 
+void KPlotWidget::setForegroundColor( const QColor &fg )
+{
+    d->cForeground = fg;
+    update();
+}
+
+void KPlotWidget::setGridColor( const QColor &gc )
+{
+    d->cGrid = gc;
+    update();
+}
+
+bool KPlotWidget::isGridShown() const
+{
+    return d->showGrid;
+}
+
+bool KPlotWidget::areObjectToolTipsShown() const
+{
+    return d->showObjectToolTips;
+}
+
+bool KPlotWidget::antialias() const
+{
+    return d->useAntialias;
+}
+
+void KPlotWidget::setAntialias( bool b )
+{
+    d->useAntialias = b;
+    update();
+}
+
 void KPlotWidget::setShowGrid( bool show ) {
-       ShowGrid = show;
+    d->showGrid = show;
        update();
 }
 
-void KPlotWidget::setShowObjectToolTips( bool show ) {
-       ShowObjectToolTips = show;
+void KPlotWidget::setShowObjectToolTips( bool show )
+{
+    d->showObjectToolTips = show;
 }
 
 
@@ -225,7 +289,7 @@ QList<KPlotPoint*> KPlotWidget::pointsUnderPoint( const QPoint& p ) const {
 
 bool KPlotWidget::event( QEvent* e ) {
        if ( e->type() == QEvent::ToolTip ) {
-               if ( ShowObjectToolTips )
+               if ( d->showObjectToolTips )
                {
                        QHelpEvent *he = static_cast<QHelpEvent*>( e );
                        QList<KPlotPoint*> pts = pointsUnderPoint( he->pos() - QPoint( leftPadding(), topPadding() ) - contentsRect().topLeft() );
@@ -390,7 +454,7 @@ void KPlotWidget::paintEvent( QPaintEvent *e ) {
        QPainter p;
 
        p.begin( this );
-       p.setRenderHint( QPainter::Antialiasing, UseAntialias );
+       p.setRenderHint( QPainter::Antialiasing, d->useAntialias );
        p.fillRect( rect(), backgroundColor() );
        p.translate( leftPadding(), topPadding() );
 
@@ -426,7 +490,7 @@ void KPlotWidget::paintEvent( QPaintEvent *e ) {
 }
 
 void KPlotWidget::drawAxes( QPainter *p ) {
-       if ( ShowGrid ) {
+       if ( d->showGrid ) {
                p->setPen( gridColor() );
 
                //Grid lines are placed at locations of primary axes' major tickmarks
index 216889a37164b69dd87a7d91df9f4a2d9639a09a..cd16b299aa578176d2b59552cdd50c914aef9a3f 100644 (file)
@@ -214,18 +214,18 @@ public:
        /**
         * @return the background color of the plot
         */
-       QColor backgroundColor() const { return cBackground; }
+        QColor backgroundColor() const;
 
        /**
         * @return the foreground color, used for the axes, tickmarks
         * and associated labels.
         */
-       QColor foregroundColor() const { return cForeground; }
+        QColor foregroundColor() const;
 
        /**
         * @return the grid color
         */
-       QColor gridColor() const { return cGrid; }
+        QColor gridColor() const;
 
        /**
         * Set the background color
@@ -237,25 +237,27 @@ public:
         * Set the foreground color
         * @param fg the new foreground color
         */
-       void setForegroundColor( const QColor &fg ) { cForeground = fg; }
+        void setForegroundColor( const QColor &fg );
 
        /**
         * Set the grid color
         * @param gc the new grid color
         */
-       void setGridColor( const QColor &gc ) { cGrid = gc; }
+        void setGridColor( const QColor &gc );
 
        /**
         * @return whether the grid lines are shown
         */
-       bool isGridShown() const { return ShowGrid; }
+        bool isGridShown() const;
 
        /**
         * @return whether the tooltip for the point objects are shown
         */
-       bool areObjectToolTipsShown() const { return ShowObjectToolTips; }
+        bool areObjectToolTipsShown() const;
 
-       inline void setAntialias( bool b ) { UseAntialias = b; }
+        bool antialias() const;
+
+        void setAntialias( bool b );
 
        /**
         * @return the number of pixels to the left of the plot area.
@@ -377,6 +379,10 @@ public slots:
         */
        void setShowObjectToolTips( bool show );
 
+    private:
+        class Private;
+        Private * const d;
+
 protected:
        /**
         * Generic event handler.
@@ -442,10 +448,6 @@ protected:
         */
        QHash<Axis, KPlotAxis*> mAxes;
 
-       //Colors
-       QColor cBackground, cForeground, cGrid;
-       //draw options
-       bool ShowGrid, ShowObjectToolTips, UseAntialias;
        //padding
        int LeftPadding, RightPadding, TopPadding, BottomPadding;