/*
Tiptop
Copyright (C) 2011 Leonid Nekin: nekin@narod.ru

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, version 3.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef MYTEXTEDIT_H
#define MYTEXTEDIT_H

#include <QMainWindow>
#include <QtGui>
#include <iostream>
#include <unistd.h>
#ifdef Q_WS_WIN
/*
#include <QtMultimedia>
*/
#else
#include <Phonon>
#endif

class QTextEdit;
 
class MyTextEdit: public QTextEdit
{
  Q_OBJECT

signals:
  void entered(const QString & s = "");

#ifdef Q_WS_WIN
/*
private slots:
  void finishedPlaying(QAudio::State state);
*/
#endif

public:  
  MyTextEdit(QWidget * parent = 0);
  ~MyTextEdit();

  bool getMode() const {return mode;}
  void setMode(bool mode_ini);
  int getNTotal() const {return n_total;}
  int getNTyped() const {return n_typed;}
  int getNAdded() const {return n_added;}
  int getNAddedTyped() const {return n_added_typed;}
  void setEditColor(QColor col) {editColor = col;}
  QColor getEditColor() {return editColor;}
  void setEraserColor(QColor col) {eraserColor = col;}
  QColor getEraserColor() {return eraserColor;}
  void setSound(bool s) {sound = s;}
  bool getSound() {return sound;}

private:
  void mouseDoubleClickEvent(QMouseEvent *e) {
    if (!mode) QTextEdit::mouseDoubleClickEvent(e);
  }
  void mouseMoveEvent(QMouseEvent *e) {
    if (!mode) QTextEdit::mouseMoveEvent(e);
  }
  void mousePressEvent(QMouseEvent *e) {
    if (!mode) QTextEdit::mousePressEvent(e);
  }
  void mouseReleaseEvent(QMouseEvent *e) {
    if (!mode) QTextEdit::mouseReleaseEvent(e);
  }
  void keyPressEvent(QKeyEvent *e);
  void inputMethodEvent(QInputMethodEvent *e);
  void RightOrWrong(const QString & s, int k);
  //void keyReleaseEvent(QKeyEvent *e);
  void Replace(const QString & ini, const QString & fin);
  void DoReplacements();
  void playSound();

  bool mode;
  int penalty;
  bool wasSpace;
  int n_total, n_typed, n_added, n_added_typed;
  int count_added;
  int count_para;
  QColor editColor;
  QColor eraserColor;
  bool sound;
  QFile soundFile;
#ifdef Q_WS_WIN
/*
  QAudioOutput* audio;
  QAudioFormat format;
*/
#else
  Phonon::AudioOutput *auOut;
  Phonon::MediaObject *player;
#endif
};  
 
#endif
