#include "MainWindow.h"
#include "ui_MainWindow.h"
#include "FindDialog.h"
#include "AddBookmarkDialog.h"
#include <QFile>
#include <QMessageBox>
#include <QFileDialog>
#include <QMouseEvent>
#include <QDebug>
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
{
ui->setupUi(this);
// ui->statusBar->resize(this->width(),20);
SBH = ui->statusBar->height();
MPH = ui->menuBar->height()+ui->mainToolBar->height();
MBH = ui->menuBar->height();
textEdit = new TextEdit(this);
// parser = new Parser(textEdit);
textEdit->setGeometry(0,MPH,this->width(),this->height()-MPH-SBH);
// textEdit->setFrameShape(QFrame::NoFrame);
// textEdit->setReadOnly(true);
// connect(ui->OpenAct, SIGNAL(triggered()), this, SLOT(Open()));
// connect(ui->QuitAct, SIGNAL(triggered()), this, SLOT(Quit()));
// connect(ui->FileInfoAct, SIGNAL(triggered()), this, SLOT(FileInfo()));
// connect(ui->BoobInfoAct, SIGNAL(triggered()), this, SLOT(BookInfo()));
// connect(ui->ZoomInAct, SIGNAL(triggered()), this, SLOT(zoomIn()));
// connect(ui->ZoomOutAct, SIGNAL(triggered()), this, SLOT(zoomOut()));
// connect(ui->FullScreenModeAct, SIGNAL(triggered()), this, SLOT(fullScreenMode()));
// connect(ui->NormalScreenModeAct, SIGNAL(triggered()), this, SLOT(normalScreenMode()));
// connect(ui->FindAct, SIGNAL(triggered()), this, SLOT(Find()));
// connect(ui->FirstPageAct, SIGNAL(triggered()), textEdit, SLOT(toBeginning()));
// connect(ui->LastPageAct, SIGNAL(triggered()), textEdit, SLOT(toEnd()));
// connect(ui->AddBookmarkAct, SIGNAL(triggered()), this, SLOT(AddBookmark()));
// connect(this, SIGNAL(dialogOpened(int)), parser, SLOT(getDialog(int)));
// connect(textEdit, SIGNAL(hideMenu()), this, SLOT(hideMenu()));
// connect(textEdit, SIGNAL(showMenu()), this, SLOT(showMenu()));
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::Open()
{
// QString fileName = QFileDialog::getOpenFileName(this, QString::fromLocal8Bit("Открыть книгу"), QDir::currentPath(), QString::fromLocal8Bit("Файлы FB2 *.fb2"));
// if (fileName.isEmpty()) return;
// QFile file(fileName);
// if (!file.open(QFile::ReadOnly | QFile::Text))
// {
// QMessageBox::warning(this, tr("fb2Reader"), QString::fromLocal8Bit("Невозможно прочесть файл %1:\n%2.").arg(fileName).arg(file.errorString()));
// return;
// }
// parser->Parse(&file);
}
void MainWindow::Quit()
{
// this->close();
}
void MainWindow::resizeEvent(QResizeEvent *e)
{
// textEdit->resize(this->width(), this->height()-ui->menuBar->height()-ui->mainToolBar->height()-SBH);
}
void MainWindow::FileInfo()
{
// emit dialogOpened(fileInfoDialog);
}
void MainWindow::BookInfo()
{
// emit dialogOpened(bookInfoDialog);
}
void MainWindow::fullScreenMode()
{
// hidden = true;
// // ui->menuBar->move(0,-ui->menuBar->height());
// // ui->mainToolBar->move(0, -ui->menuBar->height()-ui->mainToolBar->height());
// ui->NormalScreenModeAct->setEnabled(true);
// ui->FullScreenModeAct->setEnabled(false);
// ui->FullScreenModeAct->setVisible(false);
// ui->NormalScreenModeAct->setVisible(true);
// this->showFullScreen();
// textEdit->move(0,0);
// textEdit->resize(this->width(),this->height()-SBH);
// textEdit->setMouseTracking(true);
}
void MainWindow::normalScreenMode()
{
// hidden = false;
// ui->NormalScreenModeAct->setEnabled(false);
// ui->FullScreenModeAct->setEnabled(true);
// ui->FullScreenModeAct->setVisible(true);
// ui->NormalScreenModeAct->setVisible(false);
// // ui->menuBar->move(0,0);
// // ui->mainToolBar->move(0,ui->menuBar->height());
// textEdit->move(0,ui->menuBar->height()+ui->mainToolBar->height());
// this->showNormal();
// textEdit->setMouseTracking(false);
// textEdit->raise();
}
void MainWindow::Find()
{
// FindDialog *dialog = new FindDialog(this);
// connect(dialog, SIGNAL(searchParameters(bool,bool,int,QString&)), textEdit, SLOT(Find(bool,bool,int,QString&)));
// dialog->show();
}
void MainWindow::hideMenu()
{
// if(/*ui->menuBar->pos().y() != -MBH*/!hidden)
// {
// //ui->menuBar->move(0,-ui->menuBar->height());
// //ui->mainToolBar->move(0,-ui->menuBar->height()-ui->mainToolBar->height());
// hidden = true;
// ui->menuBar->lower();
// ui->mainToolBar->lower();
// }
}
void MainWindow::showMenu()
{
// if(/*ui->menuBar->pos().y() != 0*/hidden)
// {
// //ui->menuBar->move(0,0);
// //ui->mainToolBar->move(0,ui->menuBar->height());
// ui->menuBar->raise();
// ui->mainToolBar->raise();
// hidden = false;
// }
}
void MainWindow::mouseMoveEvent(QMouseEvent *e)
{
}
void MainWindow::AddBookmark()
{
// AddBookmarkDialog *dialog = new AddBookmarkDialog(this,textEdit);
// // connect(this, SIGNAL(selectedText(QString&,int)), dialog, SLOT(selectedText(QString&,int)));
// // emit selectedText(textEdit->textCursor().selectedText(), textEdit->textCursor().anchor());
// dialog->show();
}