#include "SpeedReader/speedreader.h" #include "SpeedReader/txtreader.h" // TextFormatReader
TxtReader *pTxtReader = new TxtReader("path_to_file", "UTF-8"); // : , SpeedReader *pSpeedReader = new SpeedReader(pTxtReader);
pSpeedReader->setReadingSpeed(300); // pSpeedReader->setCommaPauseTime(150); // ( ) pSpeedReader->setDotPauseTime(200); // ( ) pSpeedReader->setCurrentPosition(0); //
ui->speedReaderLabel->setSymbolColor("red");
connect(pSpeedReader, SIGNAL(nextWordAvailable(QString, int)), ui->speedReaderLabel, SLOT(processNextWordAvailable(QString, int))); connect(pSpeedReader, SIGNAL(wordOffset(int)), ui->speedReaderLabel, SLOT(processWordOffset(int)));
pSpeedReader->startReading(); pSpeedReader->stopReading();
SIGNAL(error(SpeedReaderError)) // SIGNAL(endOfBook()) // SIGNAL(readingProgress(double)) // ( 0 1)
class SpeedReader : public QObject { ... void setCurrentPosition(const int ¤tPosition); // void setCommaPauseTime(const int &comaPauseTime); // ( ) void setDotPauseTime(const int &dotPauseTime); // ( ) void setReadingSpeed(int wordPerMinute); // ( ) void setEnableShifting(const bool &enableShifting); // ( ) // get QStringList getWordsToRead() const; // int getCurrentPosition() const; int getComaPauseTime() const; int getDotPauseTime() const; int getReadingSpeed() const; int getWordsCount() const; // , bool isEnableShifting() const; void startReading(); // void stopReading(); // ... }
signals: // ( . , ) void nextWordAvailable(QString, int); // , - void wordOffset(int); // , // void readingProgress(double); // , ( 0 1) void error(SpeedReaderError); // , void endOfBook(); // ,
virtual QStringList getWords() = 0;
which needs to be redefined in classes by successors. This method just parses the contents of the text format. For example, in the TxtReader class, the simplest parsing occurs in this method, namely, replacing two spaces with one space and deleting line-break characters. class TextFormatReader: public QObject { ... public: TextFormatReader(const QString &fileName, const QString &textCodecName); virtual QStringList getWords() = 0; // void openBook(const QString &filePath); ... };
class SpeedReaderLabel : public QLabel { ... public slots: void processWordOffset(const int &verticalPointerOffset); // nextWordAvailable SpeedReader? . (. ) void processNextWordAvailable(QString w, int shift); // . shift * ... };
#ifndef SOMEREADER_H #define SOMEREADER_H #include "textformatreader.h" class SomeReader : public TextFormatReader { public: SomeReader(const QString &fileName, const QString &textCodecName) : TextFormatReader(fileName, textCodecName) {} // QStringList getWords(); // }; #endif // SOMEREADER_H
QStringList SomeReader::getWords() { QString textToParse = this->text; // this->text - "" // ( ) textToParse = textToParse.replace("someTag", ""); return countWords(textToParse); // countWords(QString text) , }
SomeReader *pSomeReader = new SomeReader("path_to_file", "UTF-8"); SpeedReader *pSpeedReader = new SpeedReader(pSomeReader); ...
Source: https://habr.com/ru/post/216003/
All Articles