File indexing completed on 2024-11-24 03:43:19

0001 /*******************************************************************
0002 *
0003 * Copyright 2007  Aron Boström <c02ab@efd.lth.se>
0004 *
0005 * Bovo is free software; you can redistribute it and/or modify
0006 * it under the terms of the GNU General Public License as published by
0007 * the Free Software Foundation; either version 2, or (at your option)
0008 * any later version.
0009 *
0010 * Bovo is distributed in the hope that it will be useful,
0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0013 * GNU General Public License for more details.
0014 *
0015 * You should have received a copy of the GNU General Public License
0016 * along with Bovo; see the file COPYING.  If not, write to
0017 * the Free Software Foundation, 51 Franklin Street, Fifth Floor,
0018 * Boston, MA 02110-1301, USA.
0019 *
0020 ********************************************************************/
0021 
0022 // Declaration include
0023 #include "view.h"
0024 
0025 // Qt Includes
0026 #include <QColor>
0027 #include <QGraphicsScene>
0028 #include <QResizeEvent>
0029 
0030 // Bovo includes
0031 #include "scene.h"
0032 
0033 namespace gui {
0034 
0035 View::View(Scene* scene, const QColor& bgColor, QWidget *parent) : QGraphicsView(scene, parent),
0036            m_scene(scene) {
0037     Q_UNUSED(bgColor);
0038     setFrameStyle(QFrame::NoFrame);
0039 //    setCacheMode(QGraphicsView::CacheBackground);
0040     setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
0041     setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
0042     setMinimumSize(sizeHint());
0043     resize(sizeHint());
0044     setAlignment(Qt::AlignLeft | Qt::AlignTop);
0045 }
0046 
0047 void View::resizeEvent( QResizeEvent* ev ) {
0048     fitInView(sceneRect(), Qt::KeepAspectRatio);
0049     QGraphicsView::resizeEvent(ev);
0050 }
0051 
0052 QSize View::sizeHint() const {
0053     return {static_cast<int>(m_scene->width()),
0054                  static_cast<int>(m_scene->height())};
0055 }
0056 
0057 } /* namespace gui */