From e4b140b5b9b38113761be11dbca18a6a1f39ab09 Mon Sep 17 00:00:00 2001 From: Martin Pfeiffer Date: Thu, 7 Jul 2005 16:27:14 +0000 Subject: [PATCH] the leitnersystem's base classes, not fully intergrated yet, no saving/loading svn path=/branches/work/kwordquiz/src/leitnersystemview.cpp; revision=432508 --- kwordquiz/leitnerbox.cpp | 69 +++++++++ kwordquiz/leitnerbox.h | 49 +++++++ kwordquiz/leitnersystem.cpp | 191 ++++++++++++++++++++++++ kwordquiz/leitnersystem.h | 67 +++++++++ kwordquiz/leitnersystemview.cpp | 217 ++++++++++++++++++++++++++++ kwordquiz/leitnersystemview.h | 57 ++++++++ kwordquiz/prefleitner.h | 56 ++++++++ kwordquiz/prefleitnerbase.ui | 247 ++++++++++++++++++++++++++++++++ 8 files changed, 953 insertions(+) create mode 100644 kwordquiz/leitnerbox.cpp create mode 100644 kwordquiz/leitnerbox.h create mode 100644 kwordquiz/leitnersystem.cpp create mode 100644 kwordquiz/leitnersystem.h create mode 100644 kwordquiz/leitnersystemview.cpp create mode 100644 kwordquiz/leitnersystemview.h create mode 100644 kwordquiz/prefleitner.h create mode 100644 kwordquiz/prefleitnerbase.ui diff --git a/kwordquiz/leitnerbox.cpp b/kwordquiz/leitnerbox.cpp new file mode 100644 index 0000000..aab7fff --- /dev/null +++ b/kwordquiz/leitnerbox.cpp @@ -0,0 +1,69 @@ +// +// C++ Implementation: leitnerbox +// +// Description: +// +// +// Author: Martin Pfeiffer , (C) 2005 +// +// Copyright: See COPYING file that comes with this distribution +// +// +#include "leitnerbox.h" + +LeitnerBox::LeitnerBox() +{ +} + + +LeitnerBox::~LeitnerBox() +{ +} + +int LeitnerBox::getVocabCount() +{ + return m_vocabCount; +} + +void LeitnerBox::setVocabCount( int count ) +{ + m_vocabCount = count; +} + +const QString& LeitnerBox::getBoxName() const +{ + return m_name; +} + +LeitnerBox* LeitnerBox::getCorrectWordBox() +{ + return m_correctWordBox; +} + +LeitnerBox* LeitnerBox::getWrongWordBox() +{ + return m_wrongWordBox; +} + +void LeitnerBox::setBoxName( const QString& name ) +{ + m_name = name; +} + +void LeitnerBox::setCorrectWordBox( LeitnerBox* correctWordBox ) +{ + m_correctWordBox = correctWordBox; +} + +void LeitnerBox::setWrongWordBox( LeitnerBox* wrongWordBox ) +{ + m_wrongWordBox = wrongWordBox; +} + +bool LeitnerBox::operator ==( const LeitnerBox& a ) const +{ + if( a.getBoxName() == getBoxName() ) + return true; + else + return false; +} diff --git a/kwordquiz/leitnerbox.h b/kwordquiz/leitnerbox.h new file mode 100644 index 0000000..bf20d6a --- /dev/null +++ b/kwordquiz/leitnerbox.h @@ -0,0 +1,49 @@ +// +// C++ Interface: leitnerbox +// +// Description: +// +// +// Author: Martin Pfeiffer , (C) 2005 +// +// Copyright: See COPYING file that comes with this distribution +// +// +#ifndef LEITNERBOX_H +#define LEITNERBOX_H + +#include + +/** +@author Martin Pfeiffer +*/ +class LeitnerBox +{ +public: + LeitnerBox(); + + ~LeitnerBox(); + + void setCorrectWordBox( LeitnerBox* ); //sets the correct word box + void setWrongWordBox( LeitnerBox* ); //sets the wrong word box + void setBoxName( const QString& ); //sets the boxes name + + void setVocabCount( int count ); + int getVocabCount(); + + LeitnerBox* getCorrectWordBox(); + LeitnerBox* getWrongWordBox(); + const QString& getBoxName() const; + + bool operator == ( const LeitnerBox& a ) const; + +private: + QString m_name; + + int m_vocabCount; + + LeitnerBox* m_wrongWordBox; + LeitnerBox* m_correctWordBox; +}; + +#endif diff --git a/kwordquiz/leitnersystem.cpp b/kwordquiz/leitnersystem.cpp new file mode 100644 index 0000000..178b8b9 --- /dev/null +++ b/kwordquiz/leitnersystem.cpp @@ -0,0 +1,191 @@ +// +// C++ Implementation: leitnersystem +// +// Description: +// +// +// Author: Martin Pfeiffer , (C) 2005 +// +// Copyright: See COPYING file that comes with this distribution +// +// +#include "leitnersystem.h" +#include + +LeitnerSystem::LeitnerSystem(QValueList& boxes, QString name) +{ + if( !boxes.empty() ) + m_boxes = boxes; + + if( name.isNull() ) + m_systemName = name; +} + +LeitnerSystem::LeitnerSystem() +{ +} + +LeitnerSystem::~LeitnerSystem() +{ +} + +QStringList LeitnerSystem::getBoxNameList() +{ + QStringList boxNameList; + QValueList::iterator it; + + + for(it = m_boxes.begin(); it != m_boxes.end(); ++it) + { + boxNameList.append((*it).getBoxName()); + } + + return boxNameList; +} + +int LeitnerSystem::getNumberOfBoxes() +{ + return m_boxes.count(); +} + +LeitnerBox* LeitnerSystem::getBoxWithNumber( int number ) +{ + return &m_boxes[ number ]; +} + +LeitnerBox* LeitnerSystem::getBoxWithName( const QString& name ) +{ + QValueList::iterator it; + + for(it = m_boxes.begin(); it != m_boxes.end(); ++it) + { + if((*it).getBoxName() == name) + return &(*it); + } + + return 0; +} + +QString& LeitnerSystem::getSystemName() +{ + return m_systemName; +} + +const QString& LeitnerSystem::getNextBox( QString& previousBox ) +{ + for( int i = 0; i < m_boxes.count(); i++ ) + { + if( m_boxes[i].getVocabCount() > 0 ) + return getBox( i ); + } + + return QString::null; +} + +const QString& LeitnerSystem::getCorrectBox( int box ) +{ + return m_boxes[ box ].getCorrectWordBox()->getBoxName(); +} + +const QString& LeitnerSystem::getWrongBox( int box ) +{ + return m_boxes[ box ].getWrongWordBox()->getBoxName(); +} + +int LeitnerSystem::getWrongBoxNumber( int box ) +{ + return getNumber( m_boxes[ box ].getWrongWordBox() ); +} + +int LeitnerSystem::getCorrectBoxNumber( int box ) +{ + return getNumber( m_boxes[ box ].getCorrectWordBox() ); +} + +void LeitnerSystem::deleteBox( int box ) +{ + m_boxes.remove( m_boxes.at( box ) ); +} + +void LeitnerSystem::deleteBox( LeitnerBox* box ) +{ + m_boxes.remove( *box ); +} + +bool LeitnerSystem::insertBox( const QString& name, int correctWordBox, int wrongWordBox ) +{ + if( getBoxNameList().contains( name ) != 0 ) + return false; + + LeitnerBox tmpBox; + tmpBox.setBoxName( name ); + tmpBox.setCorrectWordBox( getBoxWithNumber( correctWordBox ) ); + tmpBox.setWrongWordBox( getBoxWithNumber( wrongWordBox ) ); + + m_boxes.append( tmpBox ); + return true; +} + +void LeitnerSystem::setSystemName( const QString& name ) +{ + m_systemName = name; +} + +int LeitnerSystem::getNumber( LeitnerBox* box ) +{ + if( m_boxes.findIndex( *box ) == -1 ) + kdDebug() << "muhaha" << endl; + return m_boxes.findIndex( *box ); +} + +bool LeitnerSystem::setBoxName( int box, const QString& name ) +{ + if( getBoxWithName( name ) == 0 || getBoxWithName( name ) == getBoxWithNumber( box ) ) + { + getBoxWithNumber( box )->setBoxName( name ); + + return true; + } + else + return false; +} + +bool LeitnerSystem::setBoxName( LeitnerBox* box, const QString& name ) +{ + if( getBoxWithName( name ) == 0 || getBoxWithName( name ) == box ) + { + box->setBoxName( name ); + + return true; + } + else + return false; +} + +bool LeitnerSystem::insertBox( const QString& name ) +{ + if( getBoxNameList().contains( name ) != 0 ) + return false; + + LeitnerBox tmpBox; + tmpBox.setBoxName( name ); + //tmpBox.setVocabCount( count ); + + m_boxes.append( tmpBox ); + return true; +} + +void LeitnerSystem::setCorrectBox( const QString& box, const QString& correctWordBox ) +{ + getBoxWithName( box )->setCorrectWordBox( getBoxWithName( correctWordBox ) ); +} + +void LeitnerSystem::setWrongBox( const QString& box, const QString& wrongWordBox ) +{ + getBoxWithName( box )->setWrongWordBox( getBoxWithName( wrongWordBox ) ); +} + +const QString& LeitnerSystem::getBox( int i ) +{ + return getBoxWithNumber( i )->getBoxName(); +} diff --git a/kwordquiz/leitnersystem.h b/kwordquiz/leitnersystem.h new file mode 100644 index 0000000..87e583d --- /dev/null +++ b/kwordquiz/leitnersystem.h @@ -0,0 +1,67 @@ +// +// C++ Interface: leitnersystem +// +// Description: +// +// +// Author: Martin Pfeiffer , (C) 2005 +// +// Copyright: See COPYING file that comes with this distribution +// +// + +#include +#include +#include +#include "leitnerbox.h" + +#ifndef LEITNERSYSTEM_H +#define LEITNERSYSTEM_H + + +/** +@author Martin Pfeiffer +*/ +class LeitnerSystem +{ +public: + LeitnerSystem(); + LeitnerSystem( QValueList& boxes, QString name ); + + ~LeitnerSystem(); + + int getNumberOfBoxes(); //returns the number of boxes in the system + QStringList getBoxNameList(); //returns a list with the boxes names + + QString& getSystemName(); //returns the systems name + void setSystemName( const QString& name ); //sets the systems name + + LeitnerBox* getBoxWithNumber( int number ); //returns box by number + LeitnerBox* getBoxWithName( const QString& name );//returns box by name + int getNumber( LeitnerBox* box ); + const QString& getBox( int i ); + + const QString& getNextBox( QString& previousBox ); //returns the next box for the next question + + const QString& getCorrectBox( int box ); //returns the correct word box of "int box" + const QString& getWrongBox( int box ); //returns the wrong word box of "int box" + int getWrongBoxNumber( int box ); + int getCorrectBoxNumber( int box ); + void setCorrectBox( const QString& box, const QString& correctWordBox ); + void setWrongBox( const QString& box, const QString& wrongWordBox ); + bool setBoxName( int box, const QString& name ); + bool setBoxName( LeitnerBox* box, const QString& name ); + + //inserts a box with number, name, correct and wrong word box + bool insertBox( const QString& name, int correctWordBox, int wrongWordBox ); + bool insertBox( const QString& name ); + void deleteBox( int box ); + void deleteBox( LeitnerBox* box ); + +private: + QString m_systemName; //the systems name + + QValueList m_boxes; +}; + +#endif diff --git a/kwordquiz/leitnersystemview.cpp b/kwordquiz/leitnersystemview.cpp new file mode 100644 index 0000000..3dcd5b0 --- /dev/null +++ b/kwordquiz/leitnersystemview.cpp @@ -0,0 +1,217 @@ +// +// C++ Implementation: leitnersystemview +// +// Description: +// +// +// Author: Martin Pfeiffer , (C) 2005 +// +// Copyright: See COPYING file that comes with this distribution +// +// +#include "leitnersystemview.h" + +#include "leitnersystem.h" +#include "kwordquiz.h" + +#include +#include +#include + +#include + +LeitnerSystemView::LeitnerSystemView(QWidget * parent, const char* name, WFlags f) + : QScrollView(parent, name, f) +{ + m_highlightedBox = -1; +} + + +LeitnerSystemView::~LeitnerSystemView() +{ +} + +void LeitnerSystemView::drawSystem(QPainter* p) +{ + kdDebug() << "drawSystem( )" << endl; + + + //einarbeiten von m_selectedBox... aus prefLeitner + + m_imageY = height() / 2 - 32; + + //draw the boxes' icons + for(int i = 0; i < m_leitnerSystem->getNumberOfBoxes(); i++) + { + if(i == m_highlightedBox) + { + //p->drawPixmap(12 + i * 64 + i*10, m_imageY, KGlobal::iconLoader()->loadIcon("leitnerbox", KIcon::Panel)); + p->drawRect(12 + i * 64 + i*10, m_imageY,64,64); + p->fillRect(12 + i * 64 + i*10, m_imageY,64,64, QBrush(red)); + } + else + { //for each box 74 = 64(pixmap) + 10(distance between two boxes) + //p->drawPixmap(12 + i * 74, m_imageY, KGlobal::iconLoader()->loadIcon("leitnerbox", KIcon::Panel)); + p->drawRect(12 + i * 64 + i*10, m_imageY,64,64); + } + } +} + +void LeitnerSystemView::drawConnections(QPainter* p) +{ + //dist = number of boxes that are in between the two boxes + //width = width of the rect for the arc + int dist, width = 0; + int numberOfBoxes = m_leitnerSystem->getNumberOfBoxes(); + + p->setPen( QPen(green, 2) ); + + //paint the connections for the correct word boxes, above the boxes + for(int i = 0; i < numberOfBoxes; i++) + { + dist = m_leitnerSystem->getCorrectBoxNumber( i ) - i; + + if(dist <= 0) + { + // (dist*(-1) -1)*64 == for each box in between take 64 + // dist*(-1)*10 == the gaps in between + // 2*22; 2*21 == the distances of the endings on the picture + width = (dist*(-1) -1)*64 + dist*(-1)*10 + 2*22 + 2*21; + + p->drawArc( 12 + (dist+i)*74 + 21, m_imageY-(width/3), width, /*(height()/2 - 12-32) *2*/ width/3*2, 0, 180*16); + } + else + { + width = (dist-1)*64 + dist*10 + 2*21; + p->drawArc(12 + i*74 + 21+22 ,m_imageY-(width/3) , width, /*(height()/2 - 12-32) *2*/width/3*2, 0, 180*16); + } + + } + + //paint the connections for the wrong word boxes, below the boxes + p->setPen(QPen(red, 2)); + + for(int i = 0; i < numberOfBoxes; i++) + { + dist = m_leitnerSystem->getWrongBoxNumber( i ) - i; + + if(dist <= 0) + { + width = (dist*(-1) -1)*64 + dist*(-1)*10 + 2*22 + 2*21; + p->drawArc(12+ (dist+i)*74 + 21 ,m_imageY+64-width/3 , width, width/3*2 , 180*16, 180*16); + } + else + { + width = (dist-1)*64 + dist*10 + 2*21; + p->drawArc(12 + i*74 + 21+22 ,m_imageY+64-width/3 , width, width/3*2, 180*16, 180*16); + } + } + +} + +void LeitnerSystemView::setSystem(LeitnerSystem* leitnersystem) +{ + m_leitnerSystem = leitnersystem; + + //calculate the new sizes + calculateSize(); + updateContents(); + //repaint + //update(); + //QPainter* p = new QPainter(this); + //drawContents( p, 0, 0, 0, 0 ); +} + +void LeitnerSystemView::highlightBox(int box) +{ + m_highlightedBox = box; + updateContents(); +} + +void LeitnerSystemView::drawContents(QPainter* p, int clipx, int clipy, int clipw, int cliph) +{ + kdDebug() << "drawContents" << endl; + p->eraseRect(0,0,width(),height()); + + drawSystem( p ); + + drawConnections( p ); +} + +void LeitnerSystemView::calculateSize() +{ + //margin = 12 + //distance between boxes = 10 + //boxes = 64*64 + + int numberOfBoxes = m_leitnerSystem->getNumberOfBoxes(); + QString x; + int height, dist, tmpMaxC, tmpMaxW; + tmpMaxC = 0; + tmpMaxW = 0; + height = 0; + + for(int i = 0; i < numberOfBoxes; i++) + { + dist = m_leitnerSystem->getCorrectBoxNumber( i ) - i; + + if( abs(dist) >= abs(tmpMaxC) ) + tmpMaxC = dist; + + dist = m_leitnerSystem->getWrongBoxNumber( i ) - i; + + if( abs(dist) >= abs(tmpMaxW) ) + tmpMaxW = dist; + } + + if( tmpMaxC <= 0 ) + height += (( abs(tmpMaxC) -1)*64 + abs(tmpMaxC)*10 + 2*22 + 2*21)/3; + else + height += (( tmpMaxC-1)*64 + tmpMaxC*10 + 2*21)/3; + + if( tmpMaxW <= 0 ) + height += (( abs(tmpMaxW) -1)*64 + abs(tmpMaxW)*10 + 2*22 + 2*21)/3; + else + height += (( tmpMaxW-1)*64 + tmpMaxW*10 + 2*21)/3; + + height += 24+64; + + resizeContents( numberOfBoxes * 64 + (numberOfBoxes - 1)*10 + 2 * 12, height ); + setMinimumSize( numberOfBoxes * 64 + (numberOfBoxes - 1)*10 + 2 * 12, height ); +} + +void LeitnerSystemView::mousePressEvent(QMouseEvent* e) +{ + kdDebug() << "mouseClick" << endl; + //if the user has clicked into a box + if(e->y() > m_imageY && e->y() < m_imageY + 64 && e->x() < width()-13) + { + int d = (e->x()-12)/74; + + if((e->x()-12-74*d) <= 64) + { + //signal for prefLeitner to set the comboboxes to the clicked box + emit boxClicked( d ); + m_highlightedBox = d; + + updateContents(); + } + else + { + emit boxClicked( -1 ); + m_highlightedBox = -1; + + updateContents(); + } + } + else + { + emit boxClicked( -1 ); + m_highlightedBox = -1; + + updateContents(); + } +} + +#include "leitnersystemview.moc" + diff --git a/kwordquiz/leitnersystemview.h b/kwordquiz/leitnersystemview.h new file mode 100644 index 0000000..be52bc0 --- /dev/null +++ b/kwordquiz/leitnersystemview.h @@ -0,0 +1,57 @@ +// +// C++ Interface: leitnersystemview +// +// Description: +// +// +// Author: Martin Pfeiffer , (C) 2005 +// +// Copyright: See COPYING file that comes with this distribution +// +// +#ifndef LEITNERSYSTEMVIEW_H +#define LEITNERSYSTEMVIEW_H + +#include +#include + +class LeitnerSystem; + + +/** +@author Martin Pfeiffer +*/ + +class LeitnerSystemView : public QScrollView +{ + Q_OBJECT + +public: + LeitnerSystemView(QWidget* parent = 0, const char* name = 0, WFlags f = 0); + + ~LeitnerSystemView(); + + void setSystem(LeitnerSystem* system); //set a new system to view on + void highlightBox(int box); //highlight a box + +signals: + void boxClicked(int box); //is emited if the user clicks on a box + +protected: + virtual void drawContents(QPainter* p, int clipx, int clipy, int clipw, int cliph); + 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(); + + //QRect m_viewArea; + int m_imageY; //high border of the images + int m_distPixmap; + int m_highlightedBox; //the box which is currently highlighted +}; + +#endif diff --git a/kwordquiz/prefleitner.h b/kwordquiz/prefleitner.h new file mode 100644 index 0000000..09ecae1 --- /dev/null +++ b/kwordquiz/prefleitner.h @@ -0,0 +1,56 @@ +// +// C++ Interface: prefleitner +// +// Description: the part of the preferences to change the settings for the LeitnerSystem +// +// +// Author: Martin Pfeiffer , (C) 2005 +// +// Copyright: See COPYING file that comes with this distribution +// +// +#ifndef PREFLEITNER_H +#define PREFLEITNER_H + +#include + +class LeitnerSystemView; +class LeitnerSystem; +class LeitnerBox; + +/** +@author Martin Pfeiffer +*/ +class PrefLeitner : public PrefLeitnerBase +{ + Q_OBJECT + +public: + PrefLeitner(QWidget * parent, const char* name, WFlags f, LeitnerSystem* system); + + ~PrefLeitner(); + + LeitnerSystem* getSystem(); + +public slots: + void slotCorrectWord( const QString& newBox ); + void slotWrongWord( const QString& newBox ); + void slotBoxName( const QString& newName ); + void slotAddBox(); + void slotDeleteBox(); + void slotDiscard(); + void slotApply(); + +private slots: + void slotBoxClicked(int); //catches the signal from the view if user clicks on box + +private: + LeitnerSystemView* m_leitnerSystemView; //the LeitnerSystemView which shows the selected system + LeitnerSystem* m_selectedSystem; //the currently selected system to be changed + LeitnerBox* m_selectedBox; //the currently selected box + + void refreshSystemView(); //refresh the LeitnerSystemView + void newSystem(); +}; + +#endif diff --git a/kwordquiz/prefleitnerbase.ui b/kwordquiz/prefleitnerbase.ui new file mode 100644 index 0000000..1a154c1 --- /dev/null +++ b/kwordquiz/prefleitnerbase.ui @@ -0,0 +1,247 @@ + +PrefLeitnerBase + + + PrefLeitnerBase + + + + 0 + 0 + 770 + 458 + + + + Leitner System + + + + unnamed + + + + layout5 + + + + unnamed + + + + btnApply + + + Appl&y Changes + + + Alt+Y + + + + + spacer2 + + + Horizontal + + + Expanding + + + + 421 + 20 + + + + + + lytBoxName + + + + unnamed + + + + lndBoxName + + + + + lblBoxName + + + Edit box name: + + + + + + + btnDiscard + + + Disc&ard Changes + + + Alt+A + + + + + btnAddBox + + + Add a bo&x + + + Alt+X + + + + + btnDeleteBox + + + Delete selected &box + + + Alt+B + + + + + lytWrongCorrect + + + + unnamed + + + + lblCorrect + + + + 0 + 255 + 0 + + + + Correct words to: + + + + + cmbCorrect + + + + + lblWrong + + + + 255 + 0 + 0 + + + + Wrong words to: + + + + + cmbWrong + + + + 253 + 253 + 253 + + + + + + + + spacer1 + + + Horizontal + + + Expanding + + + + 252 + 20 + + + + + + + + + + cmbCorrect + activated(const QString&) + PrefLeitnerBase + slotCorrectWord(const QString&) + + + cmbWrong + activated(const QString&) + PrefLeitnerBase + slotWrongWord(const QString&) + + + lndBoxName + textChanged(const QString&) + PrefLeitnerBase + slotBoxName(const QString&) + + + btnAddBox + clicked() + PrefLeitnerBase + slotAddBox() + + + btnDeleteBox + clicked() + PrefLeitnerBase + slotDeleteBox() + + + btnApply + clicked() + PrefLeitnerBase + slotDiscard() + + + btnDiscard + clicked() + PrefLeitnerBase + slotApply() + + + + slotBoxName(const QString&) + slotSystem(const QString&) + slotWrongWord(const QString&) + slotCorrectWord(const QString&) + slotAddBox() + slotDeleteBox() + slotDiscard() + slotApply() + + + -- 2.47.3