// Copyright: See COPYING file that comes with this distribution
//
//
+
#include "leitnersystemview.h"
#include "leitnersystem.h"
-//#include "kwordquiz.h"
-#include <stdlib.h>
-#include <kiconloader.h>
#include <QPainter>
-//Added by qt3to4:
#include <QMouseEvent>
#include <kdebug.h>
-LeitnerSystemView::LeitnerSystemView( QWidget* parent ) : QWidget( parent )
+class LeitnerSystemView::Private
+{
+public:
+ Private( LeitnerSystemView* qq )
+ : q( qq ), m_highlightedBox( -1 )
+ {
+ }
+
+ LeitnerSystemView *q;
+
+ LeitnerSystem* m_leitnerSystem; //the system which is shown
+
+ void drawSystem(QPainter*); //paints the boxes
+ void drawConnections(QPainter*); //paints the arrows between the boxes
+ void calculateSize();
+
+ int m_imageY; //high border of the images
+ int m_distPixmap;
+ int m_highlightedBox; //the box which is currently highlighted
+};
+
+
+LeitnerSystemView::LeitnerSystemView( QWidget* parent )
+ : QWidget( parent ), d( new Private( this ) )
{
- m_highlightedBox = -1;
}
LeitnerSystemView::~LeitnerSystemView()
{
+ delete d;
}
-void LeitnerSystemView::drawSystem( QPainter* p )
+void LeitnerSystemView::Private::drawSystem( QPainter* p )
{
- m_imageY = height() / 2 - 32;
+ m_imageY = q->height() / 2 - 32;
//draw the boxes' icons
for(int i = 0; i < m_leitnerSystem->getNumberOfBoxes(); i++)
}
}
-void LeitnerSystemView::drawConnections(QPainter* p)
+void LeitnerSystemView::Private::drawConnections(QPainter* p)
{
//dist = number of boxes that are in between the two boxes
//width = width of the rect for the arc
void LeitnerSystemView::setSystem( LeitnerSystem* leitnersystem )
{
- m_leitnerSystem = leitnersystem;
+ d->m_leitnerSystem = leitnersystem;
//calculate the new sizes
- calculateSize();
+ d->calculateSize();
update();
}
void LeitnerSystemView::highlightBox(int box)
{
- m_highlightedBox = box;
+ d->m_highlightedBox = box;
update();
}
QPainter p( this );
p.eraseRect( 0, 0, width(), height() );
- drawSystem( &p );
+ d->drawSystem( &p );
- drawConnections( &p );
+ d->drawConnections( &p );
}
-void LeitnerSystemView::calculateSize()
+void LeitnerSystemView::Private::calculateSize()
{
//margin = 12
//distance between boxes = 10
height += 24+64;
// resizeContents( numberOfBoxes * 64 + (numberOfBoxes - 1)*10 + 2 * 12, height );
- setMinimumSize( numberOfBoxes * 64 + (numberOfBoxes - 1)*10 + 2 * 12, height );
+ q->setMinimumSize( numberOfBoxes * 64 + (numberOfBoxes - 1)*10 + 2 * 12, height );
}
void LeitnerSystemView::mousePressEvent(QMouseEvent* e)
{
kDebug() << "mouseClick" << endl;
//if the user has clicked into a box
- if( e->y() > m_imageY && e->y() < m_imageY + 64 && e->x() < width() )
+ if( e->y() > d->m_imageY && e->y() < d->m_imageY + 64 && e->x() < width() )
{
- int d = (e->x()-12)/74;
+ int dd = (e->x()-12)/74;
- if((e->x()-12-74*d) <= 64)
+ if((e->x()-12-74*dd) <= 64)
{
//signal for prefLeitner to set the comboboxes to the clicked box
- emit boxClicked( d );
- m_highlightedBox = d;
+ emit boxClicked( dd );
+ d->m_highlightedBox = dd;
update();
}
#include <libkdeedu_core_export.h>
-#include <QWidget>
-#include <QPixmap>
-#include <QMouseEvent>
+#include <QtGui/QWidget>
class LeitnerSystem;
-
/**
* This class displays a given LeitnerSystem on a QWidget
* It is used to configurate a LeitnerSystem and easily remove
* and add boxes within a GUI.
* @author Martin Pfeiffer
*/
-
class KDEEDUCORE_EXPORT LeitnerSystemView : public QWidget
{
Q_OBJECT
* The public constructor
* @param parent the QWidget that is the parent widget
*/
- LeitnerSystemView( QWidget* parent = 0 );
+ explicit LeitnerSystemView( QWidget* parent = 0 );
~LeitnerSystemView();
*/
void highlightBox( int box );
-signals:
+Q_SIGNALS:
void boxClicked(int box); //is emited if the user clicks on a box
protected:
virtual void mousePressEvent(QMouseEvent* e);
private:
- LeitnerSystem* m_leitnerSystem; //the system which is shown
-
- void drawSystem(QPainter*); //paints the boxes
- void drawConnections(QPainter*); //paints the arrows between the boxes
- void calculateSize();
+ class Private;
+ Private* const d;
- int m_imageY; //high border of the images
- int m_distPixmap;
- int m_highlightedBox; //the box which is currently highlighted
+ Q_DISABLE_COPY( LeitnerSystemView )
};
#endif