]> Git trees. - libqmvoc.git/commitdiff
move all the private stuff of LeitnerSystemView in an own Private class; general...
authorPino Toscano <pino@kde.org>
Sat, 3 Mar 2007 00:39:50 +0000 (00:39 +0000)
committerPino Toscano <pino@kde.org>
Sat, 3 Mar 2007 00:39:50 +0000 (00:39 +0000)
svn path=/trunk/KDE/kdeedu/libkdeedu/; revision=638706

kdeeducore/leitnersystemview.cpp
kdeeducore/leitnersystemview.h

index c4ee3c3d12fedbae5e6e570602a4794914d66ea0..8463855faa9068d5ef77d1afb9703f4f018d0b76 100644 (file)
@@ -9,32 +9,52 @@
 // 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++)
@@ -53,7 +73,7 @@ void LeitnerSystemView::drawSystem( QPainter* p )
        }
 }
 
-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
@@ -111,16 +131,16 @@ void LeitnerSystemView::drawConnections(QPainter* p)
 
 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();
 }
 
@@ -129,12 +149,12 @@ void LeitnerSystemView::paintEvent( QPaintEvent* )
        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
@@ -179,22 +199,22 @@ void LeitnerSystemView::calculateSize()
        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();
                }
index 5c3c28cc1a630c72efe2051d10212ab256e2fe69..4d197e7f9de5cf4d212ea3ee23e2a4af6d883177 100644 (file)
 
 #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
@@ -37,7 +33,7 @@ public:
         * The public constructor
         * @param parent the QWidget that is the parent widget
         */
-       LeitnerSystemView( QWidget* parent = 0 );
+       explicit LeitnerSystemView( QWidget* parent = 0 );
 
        ~LeitnerSystemView();
 
@@ -53,7 +49,7 @@ public:
         */
        void highlightBox( int box );
        
-signals:
+Q_SIGNALS:
        void boxClicked(int box);               //is emited if the user clicks on a box 
 
 protected:
@@ -62,15 +58,10 @@ 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