3 Copyright (C) 2010 Dzmitry Kamiahin <dnk-88@tut.by>
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include "graphics_viewport.h"
22 #include "../core/Nel3DWidget/nel3d_widget.h"
27 #include <QtGui/QAction>
28 #include <QtGui/QResizeEvent>
29 #include <QtGui/QColorDialog>
30 #include <QtGui/QFileDialog>
33 #include <nel/misc/rgba.h>
35 #include <nel/misc/event_server.h>
36 #include <nel/misc/events.h>
38 #include <nel/3d/u_driver.h>
39 #include <nel/3d/driver_user.h>
50 CGraphicsViewport::CGraphicsViewport(QObject
*parent
)
53 w
= new Nel3DWidget();
54 connect( w
, SIGNAL( resize( int, int ) ), this, SLOT( onResize( int, int ) ) );
57 CGraphicsViewport::~CGraphicsViewport()
59 disconnect( w
, SIGNAL( resize( int, int ) ), this, SLOT( onResize( int, int ) ) );
64 void CGraphicsViewport::init()
67 nldebug("CGraphicsViewport::init");
70 Modules::objView().init( w
->getDriver() );
71 Modules::psEdit().init();
72 Modules::veget().init();
74 w
->setMouseTracking(true);
75 w
->setFocusPolicy(Qt::StrongFocus
);
78 void CGraphicsViewport::release()
81 nldebug("CGraphicsViewport::release");
83 Modules::veget().release();
84 Modules::psEdit().release();
85 Modules::objView().release();
89 QAction
*CGraphicsViewport::createSaveScreenshotAction(QObject
*parent
)
91 QAction
*action
= new QAction(parent
);
92 connect(action
, SIGNAL(triggered()), this, SLOT(saveScreenshot()));
96 QAction
*CGraphicsViewport::createSetBackgroundColor(QObject
*parent
)
98 QAction
*action
= new QAction(parent
);
99 connect(action
, SIGNAL(triggered()), this, SLOT(setBackgroundColor()));
103 QWidget
* CGraphicsViewport::widget()
108 void CGraphicsViewport::saveScreenshot()
110 Modules::objView().saveScreenshot("screenshot", false, true, false);
113 void CGraphicsViewport::setBackgroundColor()
115 QColor color
= QColorDialog::getColor(QColor(Modules::objView().getBackgroundColor().R
,
116 Modules::objView().getBackgroundColor().G
,
117 Modules::objView().getBackgroundColor().B
));
119 Modules::objView().setBackgroundColor(NLMISC::CRGBA(color
.red(), color
.green(), color
.blue()));
122 void CGraphicsViewport::onResize( int width
, int height
)
124 if (Modules::objView().getDriver())
125 Modules::objView().setSizeViewport( width
, height
);
128 } /* namespace NLQT */