Browse Source

added goal bars to the progress bars

1.0-fixes
Wes Hardaker 11 years ago
parent
commit
d7e45369c8
  1. 41
      GoalBar.cpp
  2. 21
      GoalBar.h
  3. 6
      cutecw.pro
  4. 11
      docs/TODO.org
  5. 1
      modes/LetterTrainingMode.cpp
  6. 2
      modes/SpeedTrainingMode.cpp
  7. 3
      modes/TrainingMode.cpp
  8. 3
      modes/TrainingMode.h

41
GoalBar.cpp

@ -0,0 +1,41 @@
#include "GoalBar.h"
#include <QtGui/QPainter>
#include <qdebug.h>
GoalBar::GoalBar(QWidget *parent)
: QProgressBar(parent), m_goalBarLevel(-1)
{
}
GoalBar::GoalBar(QWidget *parent, int goalBarLevel)
: QProgressBar(parent), m_goalBarLevel(goalBarLevel)
{
}
void GoalBar::paintEvent(QPaintEvent *event)
{
QProgressBar::paintEvent(event);
if (m_goalBarLevel < 0)
return;
QPainter painter(this);
int barWidth = width();
int barHeight = height();
int drawAtHeight = barHeight - int(float(barHeight) * float(m_goalBarLevel - minimum())/float(maximum() - minimum()));
qDebug() << "drawing: " << minimum() << " - " << maximum() << " - " << m_goalBarLevel << " = " << drawAtHeight << " (out of)" << height();
QColor markerColor(0,0,0);
painter.save();
painter.setPen(markerColor);
painter.drawLine(0,drawAtHeight,barWidth,drawAtHeight);
painter.restore();
}
void GoalBar::setGoalBarLevel(int newlevel)
{
m_goalBarLevel = newlevel;
}

21
GoalBar.h

@ -0,0 +1,21 @@
#ifndef GOALBAR_H
#define GOALBAR_H
#include <QProgressBar>
class GoalBar : public QProgressBar
{
public:
GoalBar(QWidget *parent = 0);
GoalBar(QWidget *parent = 0, int goalBarLevel = -1);
void setGoalBarLevel(int newlevel);
protected:
virtual void paintEvent ( QPaintEvent *event );
private:
int m_goalBarLevel;
};
#endif // GOALBAR_H

6
cutecw.pro

@ -35,7 +35,8 @@ SOURCES += main.cpp\
modes/games/HighScores.cpp \
modes/QModeStart.cpp \
AboutDialog.cpp \
modes/FrontPage.cpp
modes/FrontPage.cpp \
GoalBar.cpp
HEADERS += MainWindow.h \
Morse.h \
@ -66,7 +67,8 @@ HEADERS += MainWindow.h \
modes/games/HighScores.h \
modes/QModeStart.h \
AboutDialog.h \
modes/FrontPage.h
modes/FrontPage.h \
GoalBar.h
FORMS += MainWindow.ui \
Prefs.ui \

11
docs/TODO.org

@ -67,9 +67,14 @@
SCHEDULED: <2011-02-13 Sun>
*** TODO icons for the home page buttons
SCHEDULED: <2011-02-13 Sun>
*** TODO Make the progress bars draw a level indicator on top for:
- [ ] The needed training level
- [ ] the WPM goal when appropriate
*** DONE Make the progress bars draw a level indicator on top for:
:LOGBOOK:
- State "DONE" from "TODO" [2011-02-13 Sun 09:02]
:END:
- [X] The needed training level
- [X] the WPM goal when appropriate
SCHEDULED: <2011-02-13 Sun>
*** TODO saving in maemo on window close is broken?
SCHEDULED: <2011-02-13 Sun>
*** TODO make the home screen use QGroupBoxes
SCHEDULED: <2011-02-13 Sun>

1
modes/LetterTrainingMode.cpp

@ -178,6 +178,7 @@ void LetterTrainingMode::updateGraphs()
#ifndef SMALL_DEVICE
foreach(QChar theLetter, m_trainingSequence) {
m_progressBars[theLetter]->setRange(0, 100);
m_progressBars[theLetter]->setGoalBarLevel(m_percentGoal);
m_progressBars[theLetter]->setValue(getStat(theLetter)->getGoodPercentage(m_minimumTries));
}
// qDebug() << "max graph WPM: " << fastestWPM;

2
modes/SpeedTrainingMode.cpp

@ -194,6 +194,7 @@ void SpeedTrainingMode::updateGraphs()
{
#ifndef SMALL_DEVICE
int fastestWPM = MULTFACTOR * m_morse->currentWPMGoal();
int goalWPM = MULTFACTOR * m_morse->currentWPMAccept();
foreach(QChar theLetter, m_trainingSequence) {
float aveTime = getStat(theLetter)->getAverageTime();
if (aveTime > 0) {
@ -202,6 +203,7 @@ void SpeedTrainingMode::updateGraphs()
}
foreach(QChar theLetter, m_trainingSequence) {
m_progressBars[theLetter]->setRange(0,fastestWPM);
m_progressBars[theLetter]->setGoalBarLevel(goalWPM);
float aveTime = getStat(theLetter)->getAverageTime();
if (aveTime < 0)
aveTime = .5; // seconds is very slow

3
modes/TrainingMode.cpp

@ -1,7 +1,6 @@
#include "TrainingMode.h"
#include "Morse.h"
#include <qdebug.h>
#include <QtGui/QMenu>
#include <QtGui/QMenuBar>
@ -293,7 +292,7 @@ QGridLayout *TrainingMode::setupGraphs(QString barLabel)
label->setAlignment(Qt::AlignCenter);
gridLayout->addWidget(label, 1, column);
QProgressBar *bar = new QProgressBar();
GoalBar *bar = new GoalBar(0, 20);
bar->setRange(0,20);
bar->setValue(1);
bar->setOrientation(Qt::Vertical);

3
modes/TrainingMode.h

@ -16,6 +16,7 @@
#include "ChooseSequenceDialog.h"
#include "MorseMode.h"
#include "GoalBar.h"
#include "ui_MainWindow.h"
class TrainingMode : public MorseMode
@ -66,7 +67,7 @@ protected:
QChar m_lastKey;
QList<QChar> m_lastKeys;
QList<QTime> m_lastTimes;
QMap<QChar, QProgressBar *> m_progressBars;
QMap<QChar, GoalBar *> m_progressBars;
QMap<QChar, MorseStat *> m_stats;
QAction *m_doEntireSequenceButton;
int m_maxBadLetters;

Loading…
Cancel
Save