#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 );
setDefaultPaddings();
- //default colors:
- setBackgroundColor( Qt::black );
- setForegroundColor( Qt::white );
- setGridColor( Qt::gray );
-
setMinimumSize( 150, 150 );
}
ObjectList.clear();
qDeleteAll( mAxes );
mAxes.clear();
+
+ delete d;
}
QSize KPlotWidget::minimumSizeHint() const
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;
}
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() );
QPainter p;
p.begin( this );
- p.setRenderHint( QPainter::Antialiasing, UseAntialias );
+ p.setRenderHint( QPainter::Antialiasing, d->useAntialias );
p.fillRect( rect(), backgroundColor() );
p.translate( leftPadding(), topPadding() );
}
void KPlotWidget::drawAxes( QPainter *p ) {
- if ( ShowGrid ) {
+ if ( d->showGrid ) {
p->setPen( gridColor() );
//Grid lines are placed at locations of primary axes' major tickmarks
/**
* @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
* 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.
*/
void setShowObjectToolTips( bool show );
+ private:
+ class Private;
+ Private * const d;
+
protected:
/**
* Generic event handler.
*/
QHash<Axis, KPlotAxis*> mAxes;
- //Colors
- QColor cBackground, cForeground, cGrid;
- //draw options
- bool ShowGrid, ShowObjectToolTips, UseAntialias;
//padding
int LeftPadding, RightPadding, TopPadding, BottomPadding;