From 848b8ac3dd8d9051392a9160be5d37d11c187c1e Mon Sep 17 00:00:00 2001 From: Pino Toscano Date: Fri, 16 Feb 2007 15:53:07 +0000 Subject: [PATCH] Start moving some of the KPlotWidget internal stuff to a Private class. svn path=/trunk/KDE/kdeedu/libkdeedu/; revision=634193 --- kdeeduplot/kplotwidget.cpp | 90 ++++++++++++++++++++++++++++++++------ kdeeduplot/kplotwidget.h | 26 ++++++----- 2 files changed, 91 insertions(+), 25 deletions(-) diff --git a/kdeeduplot/kplotwidget.cpp b/kdeeduplot/kplotwidget.cpp index fb6f5e7..03eed6e 100644 --- a/kdeeduplot/kplotwidget.cpp +++ b/kdeeduplot/kplotwidget.cpp @@ -38,8 +38,26 @@ #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 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( e ); QList 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 diff --git a/kdeeduplot/kplotwidget.h b/kdeeduplot/kplotwidget.h index 216889a..cd16b29 100644 --- a/kdeeduplot/kplotwidget.h +++ b/kdeeduplot/kplotwidget.h @@ -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 mAxes; - //Colors - QColor cBackground, cForeground, cGrid; - //draw options - bool ShowGrid, ShowObjectToolTips, UseAntialias; //padding int LeftPadding, RightPadding, TopPadding, BottomPadding; -- 2.47.3