00001 /* 00002 This file is part of geometria. 00003 00004 geometria is free software; you can redistribute it and/or modify 00005 it under the terms of the GNU General Public License as published 00006 by the Free Software Foundation; either version 2 of the License, 00007 or (at your option) any later version. 00008 00009 geometria is distributed in the hope that it will be useful, but 00010 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 00011 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 00012 License for more details. 00013 00014 You should have received a copy of the GNU General Public 00015 License along with geometria; if not, write to the Free Software 00016 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 00017 00018 (c) Philipp Moritz, 2006 00019 */ 00020 00021 #include "render_area.hpp" 00022 00023 #include <QtGui/QtGui> 00024 00025 #include "drawing_context.hpp" 00026 #include "qt_drawing_context.hpp" 00027 #include <boost/shared_ptr.hpp> 00028 #include "../kernel/kernel_fassade.hpp" 00029 00030 #include "../kernel/free_point_algorithm.hpp" 00031 00032 render_area::render_area(QWidget *parent) 00033 : QWidget(parent), m_dragging_point() 00034 { 00035 setBackgroundRole(QPalette::Base); 00036 } 00037 00038 render_area::~render_area(void) 00039 { 00040 } 00041 00042 00043 QSize render_area::minimumSizeHint() const 00044 { 00045 return QSize(0, 0); 00046 } 00047 00048 QSize render_area::sizeHint() const 00049 { 00050 return QSize(800, 600); 00051 } 00052 00053 void render_area::paintEvent(QPaintEvent *) 00054 { 00055 QPainter painter(this); 00056 painter.setRenderHint(QPainter::Antialiasing); 00057 //draw everything... 00058 boost::shared_ptr<drawing_context> context(new qt_drawing_context(painter)); 00059 kernel_fassade::get_instance().draw_all(context); 00060 } 00061 00062 void render_area::mousePressEvent(QMouseEvent *event) 00063 { 00064 m_dragging_point = kernel_fassade::get_instance().get_point_at(event->x(), event->y()); 00065 00066 } 00067 void render_area::mouseMoveEvent(QMouseEvent *event) 00068 { 00069 if(m_dragging_point != geo_point_ref()) 00070 { 00071 if(m_dragging_point->is_free_point()) 00072 m_dragging_point->change_parent_algo(boost::shared_ptr<point_algorithm>(new free_point_algorithm(event->x()/10.0, event->y()/10.0))); 00073 } 00074 this->repaint(); 00075 } 00076 void render_area::mouseReleaseEvent(QMouseEvent *event) 00077 { 00078 m_dragging_point = geo_point_ref(); 00079 }