Commit 66d30f21 authored by Akarsh Simha's avatar Akarsh Simha
Browse files

SkyPainters should really take the dimensions of the widget that they are drawing on. Fixing this.

+ A pointer to the SkyMap need not be passed to the children.

+ A pointer to the QWidget / QGLWidget that drawing is being done in
  is passed instead, to obtain the dimensions.

svn path=/branches/KDE/4.6/kdeedu/kstars/; revision=1210816
parent 202f4885
......@@ -25,6 +25,7 @@ USING_PART_OF_NAMESPACE_EIGEN
using Eigen::Rotation2Df;
#include <GL/gl.h>
#include <QGLWidget>
#include "skymap.h"
#include "kstarsdata.h"
......@@ -48,9 +49,9 @@ Vector3f SkyGLPainter::m_color[NUMTYPES][6*BUFSIZE];
int SkyGLPainter::m_idx[NUMTYPES];
bool SkyGLPainter::m_init = false;
SkyGLPainter::SkyGLPainter(SkyMap* sm)
: SkyPainter(sm)
SkyGLPainter::SkyGLPainter( const QGLWidget *widget ) : SkyPainter()
{
m_widget = widget;
if( !m_init ) {
printf("Initializing texcoord arrays...\n");
for(int i = 0; i < NUMTYPES; ++i) {
......@@ -366,9 +367,9 @@ void SkyGLPainter::drawPolygon(const QVector<Vector2f>& polygon, bool convex)
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
glBegin(GL_QUADS);
glVertex2f(0,0);
glVertex2f(0,m_sm->height());
glVertex2f(m_sm->width(),m_sm->height());
glVertex2f(m_sm->width(),0);
glVertex2f(0,m_widget->height());
glVertex2f(m_widget->width(),m_widget->height());
glVertex2f(m_widget->width(),0);
glEnd();
glDisable(GL_STENCIL_TEST);
} else {
......@@ -523,10 +524,10 @@ void SkyGLPainter::begin()
m_proj = m_sm->projector();
//Load ortho projection
glViewport(0,0,m_sm->width(),m_sm->height());
glViewport(0,0,m_widget->width(),m_widget->height());
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0,m_sm->width(), m_sm->height(),0, -1,1);
glOrtho(0,m_widget->width(), m_widget->height(),0, -1,1);
//reset modelview matrix
glMatrixMode(GL_MODELVIEW);
......
......@@ -27,10 +27,12 @@ USING_PART_OF_NAMESPACE_EIGEN
#include "skyobjects/skyobject.h"
#include "projections/projector.h"
class QGLWidget;
class SkyGLPainter : public SkyPainter
{
public:
SkyGLPainter(SkyMap* sm);
SkyGLPainter( const QGLWidget *widget );
virtual bool drawPlanet(KSPlanetBase* planet);
virtual bool drawDeepSkyObject(DeepSkyObject* obj, bool drawImage = false);
virtual bool drawPointSource(SkyPoint* loc, float mag, char sp = 'A');
......@@ -60,6 +62,7 @@ private:
static Vector3f m_color[NUMTYPES][6*BUFSIZE];
static int m_idx[NUMTYPES];
static bool m_init; ///< keep track of whether we have filled the texcoord array
const QGLWidget* m_widget; // Pointer to (GL) widget on which we are painting
};
#endif // SKYGLPAINTER_H
......@@ -55,7 +55,7 @@ void SkyMapGLDraw::paintEvent( QPaintEvent *event )
makeCurrent();
SkyGLPainter psky( m_SkyMap );
SkyGLPainter psky( this );
//FIXME: we may want to move this into the components.
psky.begin();
......
......@@ -58,7 +58,7 @@ void SkyMapQDraw::paintEvent( QPaintEvent *event ) {
m_SkyMap->showFocusCoords();
m_SkyMap->setupProjector();
SkyQPainter psky(m_SkyMap, m_SkyPixmap); // FIXME: Again, we shouldn't be passing m_SkyMap, but rather, we should pass this widget instead.
SkyQPainter psky(this, m_SkyPixmap);
//FIXME: we may want to move this into the components.
psky.begin();
......
......@@ -31,11 +31,10 @@
#include "skyobjects/ksplanetbase.h"
#include "skyobjects/trailobject.h"
SkyPainter::SkyPainter(SkyMap* sm)
: m_sm(sm),
m_sizeMagLim(10.)
SkyPainter::SkyPainter()
: m_sizeMagLim(10.)
{
m_sm = SkyMap::Instance();
}
SkyPainter::~SkyPainter()
......
......@@ -46,9 +46,12 @@ class SkyPainter
{
public:
/** @short Constructor.
@param sm A pointer to SkyMap object on which to paint.
*/
SkyPainter(SkyMap *sm);
SkyPainter();
/**
*@short Destructor
*/
virtual ~SkyPainter();
/** @short Get the SkyMap on which the painter operates */
......
......@@ -19,6 +19,7 @@
#include "skyqpainter.h"
#include <QMap>
#include <QWidget>
#include "kstarsdata.h"
#include "Options.h"
......@@ -67,11 +68,12 @@ namespace {
QPixmap* imageCache[nSPclasses][nStarSizes] = {{0}};
}
SkyQPainter::SkyQPainter(SkyMap* sm, QPaintDevice *pd)
: SkyPainter(sm), QPainter()
SkyQPainter::SkyQPainter( QWidget *widget, QPaintDevice *pd )
: SkyPainter(), QPainter()
{
//Set paint device pointer to pd or sm if pd = 0
m_pd = (pd ? pd : sm);
// Set paint device pointer to pd or to the widget if pd = 0
m_pd = ( pd ? pd : widget );
m_widget = widget;
}
SkyQPainter::~SkyQPainter()
......@@ -94,8 +96,8 @@ void SkyQPainter::end()
void SkyQPainter::drawSkyBackground()
{
//FIXME use projctor
fillRect( 0, 0, m_sm->width(), m_sm->height(), KStarsData::Instance()->colorScheme()->colorNamed( "SkyColor" ) );
//FIXME use projector
fillRect( 0, 0, m_widget->width(), m_widget->height(), KStarsData::Instance()->colorScheme()->colorNamed( "SkyColor" ) );
}
void SkyQPainter::setPen(const QPen& pen)
......
......@@ -23,6 +23,7 @@
#include "skypainter.h"
class Projector;
class QWidget;
/** @short The QPainter-based painting backend.
This class implements the SkyPainter interface using a QPainter.
......@@ -31,10 +32,10 @@ class SkyQPainter : public SkyPainter, public QPainter
{
public:
/** Constructor.
@param sm the SkyMap pointer
@param widget the QWidget that provides the paint device (used to query height, width etc)
@param pd the painting device. If 0, then @p sm will be used.
*/
SkyQPainter(SkyMap *sm, QPaintDevice *pd = 0);
SkyQPainter( QWidget *widget, QPaintDevice *pd = 0 );
virtual ~SkyQPainter();
virtual void setPen(const QPen& pen);
virtual void setBrush(const QBrush& brush);
......@@ -65,6 +66,7 @@ private:
float positionAngle);
QPaintDevice *m_pd;
const Projector* m_proj;
const QWidget *m_widget;
};
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment