/**
  * mapview.cpp
  * Widget, ktery zobrazuje mapu CR.
  *
  * @author Michala Capkova
  */

#include "mapview.h"

#include "iostream"

#include <QWheelEvent>

/**
  * konstruktor
  */
MapView::MapView(QGraphicsScene *scene, QWidget *parent) : QGraphicsView(scene, parent)
{
}

void MapView::wheelEvent(QWheelEvent* event) {
    //rychlost zoomovani
    double scaleFactor = 1.03;

    //priblizovani
    if(event->delta() > 0)
        this->scale(scaleFactor, scaleFactor);
    //oddalovani
    else
        this->scale(1.0 / scaleFactor, 1.0 / scaleFactor);
}

void MapView::setZoom(int value)
{
    double newScale = value / 100.0;
    QMatrix oldMatrix = this->matrix();
    this->resetMatrix();
    this->translate(oldMatrix.dx(), oldMatrix.dy());
    this->scale(newScale, newScale);
}

void MapView::enable()
{
    this->setEnabled(true);
    this->scene()->clearSelection();
}
