From b415824b890e057cc2cad0b6ae0983d29ebc74b6 Mon Sep 17 00:00:00 2001 From: Martin Pfeiffer Date: Mon, 11 Jul 2005 17:14:39 +0000 Subject: [PATCH] some bugs fixed svn path=/branches/work/kwordquiz/src/leitnersystemview.cpp; revision=433742 --- kwordquiz/leitnersystem.h | 9 +++ kwordquiz/leitnersystemview.cpp | 108 ++++++++++++++------------------ kwordquiz/prefleitner.cpp | 37 +++-------- 3 files changed, 66 insertions(+), 88 deletions(-) diff --git a/kwordquiz/leitnersystem.h b/kwordquiz/leitnersystem.h index 87e583d..50b9f2d 100644 --- a/kwordquiz/leitnersystem.h +++ b/kwordquiz/leitnersystem.h @@ -45,13 +45,22 @@ public: 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 ); + void setBoxVocabCount( QString& box, int vocabCount ); + int getBoxVocabCount( QString& box ); + + void incrementBoxVocabCount( QString& box ); + void decrementBoxVocabCount( QString& box ); + //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 ); diff --git a/kwordquiz/leitnersystemview.cpp b/kwordquiz/leitnersystemview.cpp index 3dcd5b0..a7ddaf2 100644 --- a/kwordquiz/leitnersystemview.cpp +++ b/kwordquiz/leitnersystemview.cpp @@ -33,11 +33,6 @@ 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 @@ -69,23 +64,25 @@ void LeitnerSystemView::drawConnections(QPainter* p) //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) + if( m_leitnerSystem->getCorrectBoxNumber( i ) != -1 ) { - // (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; + 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); - } - + 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 @@ -93,20 +90,22 @@ void LeitnerSystemView::drawConnections(QPainter* p) 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 + if( m_leitnerSystem->getWrongBoxNumber( i ) != -1 ) { - 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); + 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) @@ -116,10 +115,6 @@ void LeitnerSystemView::setSystem(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) @@ -130,7 +125,6 @@ void LeitnerSystemView::highlightBox(int box) void LeitnerSystemView::drawContents(QPainter* p, int clipx, int clipy, int clipw, int cliph) { - kdDebug() << "drawContents" << endl; p->eraseRect(0,0,width(),height()); drawSystem( p ); @@ -153,21 +147,27 @@ void LeitnerSystemView::calculateSize() for(int i = 0; i < numberOfBoxes; i++) { - dist = m_leitnerSystem->getCorrectBoxNumber( i ) - i; + if( m_leitnerSystem->getCorrectBoxNumber( i ) != -1 ) + { + dist = m_leitnerSystem->getCorrectBoxNumber( i ) - i; - if( abs(dist) >= abs(tmpMaxC) ) - tmpMaxC = dist; - - dist = m_leitnerSystem->getWrongBoxNumber( i ) - i; + if( abs(dist) >= abs(tmpMaxC) ) + tmpMaxC = dist; + } + + if( m_leitnerSystem->getWrongBoxNumber( i ) != -1 ) + { + dist = m_leitnerSystem->getWrongBoxNumber( i ) - i; - if( abs(dist) >= abs(tmpMaxW) ) - tmpMaxW = dist; + 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; + 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; @@ -175,7 +175,7 @@ void LeitnerSystemView::calculateSize() 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 ); } @@ -184,7 +184,7 @@ 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) + if( e->y() > m_imageY && e->y() < m_imageY + 64 && e->x() < contentsWidth() ) { int d = (e->x()-12)/74; @@ -196,20 +196,6 @@ void LeitnerSystemView::mousePressEvent(QMouseEvent* e) updateContents(); } - else - { - emit boxClicked( -1 ); - m_highlightedBox = -1; - - updateContents(); - } - } - else - { - emit boxClicked( -1 ); - m_highlightedBox = -1; - - updateContents(); } } diff --git a/kwordquiz/prefleitner.cpp b/kwordquiz/prefleitner.cpp index 6efd7a9..de264ab 100644 --- a/kwordquiz/prefleitner.cpp +++ b/kwordquiz/prefleitner.cpp @@ -33,15 +33,7 @@ PrefLeitner::PrefLeitner(QWidget * parent, const char* name, WFlags f, LeitnerSy PrefLeitnerBaseLayout->setOrigin( QGridLayout::BottomLeft ); connect( m_leitnerSystemView, SIGNAL( boxClicked( int ) ), this, SLOT( slotBoxClicked( int ) ) ); - /* - connect( cmbCorrect, SIGNAL( activated(const QString&) ), this, SLOT( slotCorrectWord(const QString&) ) ); - connect( cmbWrong, SIGNAL( activated(const QString&) ), this, SLOT( slotWrongWord(const QString&) ) ); - connect( lndBoxName, SIGNAL( textChanged(const QString&) ), this, SLOT( slotBoxName(const QString&) ) ); - connect( btnAddBox, SIGNAL( clicked() ), this, SLOT( slotAddBox() ) ); - connect( btnDeleteBox, SIGNAL( clicked() ), this, SLOT( slotDeleteBox() ) );*/ -// connect( btnApply, SIGNAL( clicked() ), this, SLOT( slotApply() ) ); -// connect( btnDiscard, SIGNAL( clicked() ), this, SLOT( slotDiscard() ) ); - + //insert the list of box' names in the comboboxes cmbWrong->insertStringList( m_selectedSystem->getBoxNameList() ); cmbCorrect->insertStringList( m_selectedSystem->getBoxNameList() ); @@ -77,6 +69,9 @@ void PrefLeitner::slotWrongWord( const QString& newBox ) void PrefLeitner::slotBoxName( const QString& newName ) { + if( m_selectedBox == 0 ) + return; + //when the boxes name was changed m_selectedSystem->setBoxName( m_selectedBox, newName ); } @@ -96,21 +91,11 @@ void PrefLeitner::refreshSystemView() void PrefLeitner::slotBoxClicked( int box ) { - if( box == -1 ) - { - kdDebug() << "outside" << endl; - m_selectedBox = 0; - lndBoxName->setText( "" ); - } - else - { - kdDebug() << "inside" << endl; - m_selectedBox = m_selectedSystem->getBoxWithNumber( box ); + m_selectedBox = m_selectedSystem->getBoxWithNumber( box ); - cmbCorrect->setCurrentItem( m_selectedSystem->getCorrectBoxNumber( box ) ); - cmbWrong->setCurrentItem( m_selectedSystem->getWrongBoxNumber( box ) ); - lndBoxName->setText( m_selectedBox->getBoxName() ); - } + cmbCorrect->setCurrentItem( m_selectedSystem->getCorrectBoxNumber( box ) ); + cmbWrong->setCurrentItem( m_selectedSystem->getWrongBoxNumber( box ) ); + lndBoxName->setText( m_selectedBox->getBoxName() ); } void PrefLeitner::slotAddBox() @@ -122,20 +107,19 @@ void PrefLeitner::slotAddBox() void PrefLeitner::slotDeleteBox() { m_selectedSystem->deleteBox( m_selectedBox ); - + m_selectedBox = 0; + refreshSystemView(); } void PrefLeitner::slotApply() { - kdDebug() << "apply" << endl; setResult( QDialog::Accepted ); close(); } void PrefLeitner::slotDiscard() { - kdDebug() << "discard" << endl; setResult( QDialog::Rejected ); close(); } @@ -145,4 +129,3 @@ LeitnerSystem* PrefLeitner::getSystem() return m_selectedSystem; } -//#include "prefleitner.moc" -- 2.47.3