Changed: Merge
commit
e8c6bc896a
@ -0,0 +1,285 @@
|
|||||||
|
/*
|
||||||
|
Object Viewer Qt
|
||||||
|
Copyright (C) 2010 Dzmitry Kamiahin <dnk-88@tut.by>
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "stdpch.h"
|
||||||
|
#include "camera_control.h"
|
||||||
|
|
||||||
|
// STL includes
|
||||||
|
|
||||||
|
// Qt includes
|
||||||
|
|
||||||
|
// NeL includes
|
||||||
|
#include "nel/misc/debug.h"
|
||||||
|
#include "nel/3d/u_driver.h"
|
||||||
|
#include "nel/3d/u_scene.h"
|
||||||
|
#include <nel/3d/u_camera.h>
|
||||||
|
#include <nel/3d/u_3d_mouse_listener.h>
|
||||||
|
|
||||||
|
// Project includes
|
||||||
|
#include "modules.h"
|
||||||
|
|
||||||
|
static int camId = 0;
|
||||||
|
|
||||||
|
namespace NLQT
|
||||||
|
{
|
||||||
|
|
||||||
|
CCameraItem::CCameraItem(const QString &name):
|
||||||
|
_cameraFocal(75),
|
||||||
|
_speed(5.0),
|
||||||
|
_active(false),
|
||||||
|
_name(name)
|
||||||
|
{
|
||||||
|
_camera = Modules::objView().getScene()->createCamera();
|
||||||
|
_camera.setTransformMode (NL3D::UTransformable::DirectMatrix);
|
||||||
|
reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
CCameraItem::~CCameraItem()
|
||||||
|
{
|
||||||
|
Modules::objView().getScene()->deleteCamera(_camera);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CCameraItem::setActive(bool active)
|
||||||
|
{
|
||||||
|
if (active)
|
||||||
|
{
|
||||||
|
sint w = Modules::objView().getDriver()->getWindowWidth();
|
||||||
|
sint h = Modules::objView().getDriver()->getWindowHeight();
|
||||||
|
_camera.setPerspective(_cameraFocal * float(NLMISC::Pi) / 180.f, float(w) / h, 0.1f, 1000);
|
||||||
|
Modules::objView().getScene()->setCam(_camera);
|
||||||
|
setupListener();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_hotSpot = Modules::objView().get3dMouseListener()->getHotSpot();
|
||||||
|
}
|
||||||
|
_active = active;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CCameraItem::setSpeed(float value)
|
||||||
|
{
|
||||||
|
_speed = value;
|
||||||
|
Modules::objView().get3dMouseListener()->setSpeed(_speed);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CCameraItem::reset()
|
||||||
|
{
|
||||||
|
_hotSpot = NLMISC::CVector(0, 0, 0);
|
||||||
|
float radius=10.f;
|
||||||
|
|
||||||
|
// Setup camera
|
||||||
|
_camera.lookAt(_hotSpot + NLMISC::CVector(0.57735f, 0.57735f, 0.57735f) * radius, _hotSpot);
|
||||||
|
|
||||||
|
if (_active)
|
||||||
|
setupListener();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CCameraItem::setupListener()
|
||||||
|
{
|
||||||
|
NL3D::U3dMouseListener *_mouseListener = Modules::objView().get3dMouseListener();
|
||||||
|
_mouseListener->setMatrix (_camera.getMatrix());
|
||||||
|
_mouseListener->setFrustrum (_camera.getFrustum());
|
||||||
|
_mouseListener->setViewport (NL3D::CViewport());
|
||||||
|
_mouseListener->setHotSpot (_hotSpot);
|
||||||
|
Modules::objView().get3dMouseListener()->setSpeed(_speed);
|
||||||
|
}
|
||||||
|
|
||||||
|
CCameraControl::CCameraControl(QWidget *parent)
|
||||||
|
: QObject(parent),
|
||||||
|
_currentCamera(0)
|
||||||
|
{
|
||||||
|
_camToolBar = new QToolBar(tr("CameraControl"), parent);
|
||||||
|
|
||||||
|
_fpsAction = _camToolBar->addAction(tr("Fly"));
|
||||||
|
_fpsAction->setStatusTip(tr("Set firstPerson camera mode"));
|
||||||
|
_fpsAction->setCheckable(true);
|
||||||
|
|
||||||
|
_edit3dAction = _camToolBar->addAction(tr("Edit"));
|
||||||
|
_edit3dAction->setStatusTip(tr("Set edit3d camera mode"));
|
||||||
|
_edit3dAction->setCheckable(true);
|
||||||
|
|
||||||
|
QActionGroup *cameraModeGroup = new QActionGroup(this);
|
||||||
|
cameraModeGroup->addAction(_fpsAction);
|
||||||
|
cameraModeGroup->addAction(_edit3dAction);
|
||||||
|
_edit3dAction->setChecked(true);
|
||||||
|
|
||||||
|
connect(_fpsAction, SIGNAL(triggered()), this, SLOT(setFirstPersonMode()));
|
||||||
|
connect(_edit3dAction, SIGNAL(triggered()), this, SLOT(setEditMode()));
|
||||||
|
|
||||||
|
_renderModeMenu = new QMenu(tr("Render Mode"), _camToolBar);
|
||||||
|
_renderModeMenu->setIcon(QIcon(":/images/polymode.png"));
|
||||||
|
_camToolBar->addAction(_renderModeMenu->menuAction());
|
||||||
|
connect(_renderModeMenu->menuAction(), SIGNAL(triggered()), this, SLOT(setRenderMode()));
|
||||||
|
|
||||||
|
QSignalMapper *modeMapper = new QSignalMapper(this);
|
||||||
|
|
||||||
|
_pointRenderModeAction = _renderModeMenu->addAction(tr("Point mode"));
|
||||||
|
_pointRenderModeAction->setIcon(QIcon(":/images/rmpoints.png"));
|
||||||
|
_pointRenderModeAction->setStatusTip(tr("Set point render mode"));
|
||||||
|
connect(_pointRenderModeAction, SIGNAL(triggered()), modeMapper, SLOT(map()));
|
||||||
|
modeMapper->setMapping(_pointRenderModeAction, 0);
|
||||||
|
|
||||||
|
_lineRenderModeAction = _renderModeMenu->addAction(tr("Line mode"));
|
||||||
|
_lineRenderModeAction->setStatusTip(tr("Set line render mode"));
|
||||||
|
_lineRenderModeAction->setIcon(QIcon(":/images/rmline.png"));
|
||||||
|
connect(_lineRenderModeAction, SIGNAL(triggered()), modeMapper, SLOT(map()));
|
||||||
|
modeMapper->setMapping(_lineRenderModeAction, 1);
|
||||||
|
|
||||||
|
_fillRenderModeAction = _renderModeMenu->addAction(tr("Fill mode"));
|
||||||
|
_fillRenderModeAction->setIcon(QIcon(":/images/rmfill.png"));
|
||||||
|
_fillRenderModeAction->setStatusTip(tr("Set fill render mode"));
|
||||||
|
connect(_fillRenderModeAction, SIGNAL(triggered()), modeMapper, SLOT(map()));
|
||||||
|
modeMapper->setMapping(_fillRenderModeAction, 2);
|
||||||
|
|
||||||
|
connect(modeMapper, SIGNAL(mapped(int)), this, SLOT(setRenderMode(int)));
|
||||||
|
|
||||||
|
_camToolBar->addSeparator();
|
||||||
|
_speedLabel = new QLabel(tr("Speed:"), _camToolBar);
|
||||||
|
_camToolBar->addWidget(_speedLabel);
|
||||||
|
_speedSpinBox = new QSpinBox(_camToolBar);
|
||||||
|
_speedSpinBox->setMinimum(1);
|
||||||
|
_speedSpinBox->setMaximum(1000);
|
||||||
|
_camToolBar->addWidget(_speedSpinBox);
|
||||||
|
connect(_speedSpinBox, SIGNAL(valueChanged(int)), this, SLOT(setSpeed(int)));
|
||||||
|
|
||||||
|
_camToolBar->addSeparator();
|
||||||
|
_addCamAction = _camToolBar->addAction(tr("Create camera"));
|
||||||
|
_addCamAction->setIcon(QIcon(":/images/cam_add.png"));
|
||||||
|
_addCamAction->setStatusTip(tr("Create new camera"));
|
||||||
|
connect(_addCamAction, SIGNAL(triggered()), this, SLOT(addCamera()));
|
||||||
|
|
||||||
|
_delCamAction = _camToolBar->addAction(tr("Delete camera"));
|
||||||
|
_delCamAction->setIcon(QIcon(":/images/cam_del.png"));
|
||||||
|
_delCamAction->setStatusTip(tr("Delete current camera"));
|
||||||
|
connect(_delCamAction, SIGNAL(triggered()), this, SLOT(delCamera()));
|
||||||
|
|
||||||
|
_listCamComboBox = new QComboBox(_camToolBar);
|
||||||
|
connect(_listCamComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(changeCamera(int)));
|
||||||
|
_listCamComboBox->setCurrentIndex(createCamera(tr("defaultCamera")));
|
||||||
|
_camToolBar->addWidget(_listCamComboBox);
|
||||||
|
|
||||||
|
_camToolBar->addSeparator();
|
||||||
|
_resetCamAction = _camToolBar->addAction(tr("Reset camera"));
|
||||||
|
_resetCamAction->setStatusTip(tr("Reset current camera"));
|
||||||
|
//_resetCamAction->setShortcut(tr("Ctrl+R"));
|
||||||
|
connect(_resetCamAction, SIGNAL(triggered()), this, SLOT(resetCamera()));
|
||||||
|
}
|
||||||
|
|
||||||
|
CCameraControl::~CCameraControl()
|
||||||
|
{
|
||||||
|
for(size_t i = 0; i < _cameraList.size(); ++i)
|
||||||
|
delete _cameraList[i];
|
||||||
|
_cameraList.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CCameraControl::setEditMode()
|
||||||
|
{
|
||||||
|
Modules::objView().get3dMouseListener()->setMouseMode(NL3D::U3dMouseListener::edit3d);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CCameraControl::setFirstPersonMode()
|
||||||
|
{
|
||||||
|
Modules::objView().get3dMouseListener()->setMouseMode(NL3D::U3dMouseListener::firstPerson);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CCameraControl::addCamera()
|
||||||
|
{
|
||||||
|
_listCamComboBox->setCurrentIndex(createCamera(tr("%1_Camera").arg(++camId)));
|
||||||
|
}
|
||||||
|
|
||||||
|
void CCameraControl::delCamera()
|
||||||
|
{
|
||||||
|
int index = _listCamComboBox->currentIndex();
|
||||||
|
_listCamComboBox->setCurrentIndex(index - 1);
|
||||||
|
|
||||||
|
_listCamComboBox->removeItem(index);
|
||||||
|
delete _cameraList[index];
|
||||||
|
_cameraList.erase(_cameraList.begin() + index);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CCameraControl::setSpeed(int value)
|
||||||
|
{
|
||||||
|
nlassert(_currentCamera);
|
||||||
|
_currentCamera->setSpeed(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CCameraControl::changeCamera(int index)
|
||||||
|
{
|
||||||
|
if (_currentCamera)
|
||||||
|
_currentCamera->setActive(false);
|
||||||
|
|
||||||
|
if (index == 0)
|
||||||
|
_delCamAction->setEnabled(false);
|
||||||
|
else
|
||||||
|
_delCamAction->setEnabled(true);
|
||||||
|
|
||||||
|
_currentCamera = _cameraList[index];
|
||||||
|
|
||||||
|
nlassert(_currentCamera);
|
||||||
|
_currentCamera->setActive(true);
|
||||||
|
_speedSpinBox->setValue(int(_currentCamera->getSpeed()));
|
||||||
|
}
|
||||||
|
|
||||||
|
void CCameraControl::setRenderMode(int value)
|
||||||
|
{
|
||||||
|
switch (value)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
Modules::objView().getDriver()->setPolygonMode (NL3D::UDriver::Point);
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
Modules::objView().getDriver()->setPolygonMode (NL3D::UDriver::Line);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
Modules::objView().getDriver()->setPolygonMode (NL3D::UDriver::Filled);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CCameraControl::setRenderMode()
|
||||||
|
{
|
||||||
|
switch (Modules::objView().getDriver()->getPolygonMode())
|
||||||
|
{
|
||||||
|
case NL3D::UDriver::Filled:
|
||||||
|
Modules::objView().getDriver()->setPolygonMode (NL3D::UDriver::Line);
|
||||||
|
break;
|
||||||
|
case NL3D::UDriver::Line:
|
||||||
|
Modules::objView().getDriver()->setPolygonMode (NL3D::UDriver::Point);
|
||||||
|
break;
|
||||||
|
case NL3D::UDriver::Point:
|
||||||
|
Modules::objView().getDriver()->setPolygonMode (NL3D::UDriver::Filled);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CCameraControl::resetCamera()
|
||||||
|
{
|
||||||
|
nlassert(_currentCamera);
|
||||||
|
_currentCamera->reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
int CCameraControl::createCamera(const QString &name)
|
||||||
|
{
|
||||||
|
CCameraItem *newCamera = new CCameraItem(name);
|
||||||
|
_cameraList.push_back(newCamera);
|
||||||
|
_listCamComboBox->addItem(newCamera->getName());
|
||||||
|
return _cameraList.size() - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
} /* namespace NLQT */
|
@ -0,0 +1,125 @@
|
|||||||
|
/*
|
||||||
|
Object Viewer Qt
|
||||||
|
Copyright (C) 2010 Dzmitry Kamiahin <dnk-88@tut.by>
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef CAMERA_CONTROL_H
|
||||||
|
#define CAMERA_CONTROL_H
|
||||||
|
|
||||||
|
// STL includes
|
||||||
|
|
||||||
|
// Qt includes
|
||||||
|
#include <QtCore/QSignalMapper>
|
||||||
|
#include <QtGui/QAction>
|
||||||
|
#include <QtGui/QComboBox>
|
||||||
|
#include <QtGui/QSpinBox>
|
||||||
|
#include <QtGui/QLabel>
|
||||||
|
#include <QtGui/QMenu>
|
||||||
|
#include <QtGui/QToolBar>
|
||||||
|
|
||||||
|
// NeL includes
|
||||||
|
#include <nel/3d/u_camera.h>
|
||||||
|
#include "nel/misc/vector.h"
|
||||||
|
|
||||||
|
// Project includes
|
||||||
|
|
||||||
|
namespace NLQT
|
||||||
|
{
|
||||||
|
|
||||||
|
class CCameraItem
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CCameraItem(const QString &name);
|
||||||
|
~CCameraItem();
|
||||||
|
|
||||||
|
void setSpeed(float value);
|
||||||
|
float getSpeed()
|
||||||
|
{
|
||||||
|
return _speed;
|
||||||
|
}
|
||||||
|
void setActive(bool active);
|
||||||
|
void setName(const QString &name)
|
||||||
|
{
|
||||||
|
_name = name;
|
||||||
|
}
|
||||||
|
QString getName() const
|
||||||
|
{
|
||||||
|
return _name;
|
||||||
|
}
|
||||||
|
void reset();
|
||||||
|
|
||||||
|
private:
|
||||||
|
void setupListener();
|
||||||
|
|
||||||
|
NL3D::UCamera _camera;
|
||||||
|
NLMISC::CVector _hotSpot;
|
||||||
|
|
||||||
|
float _cameraFocal;
|
||||||
|
float _speed;
|
||||||
|
bool _active;
|
||||||
|
QString _name;
|
||||||
|
};
|
||||||
|
|
||||||
|
class CCameraControl: public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
CCameraControl(QWidget *parent = 0);
|
||||||
|
~CCameraControl();
|
||||||
|
|
||||||
|
QToolBar *getToolBar() const
|
||||||
|
{
|
||||||
|
return _camToolBar;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Q_SLOTS:
|
||||||
|
void setEditMode();
|
||||||
|
void setFirstPersonMode();
|
||||||
|
void addCamera();
|
||||||
|
void delCamera();
|
||||||
|
void setSpeed(int value);
|
||||||
|
void changeCamera(int index);
|
||||||
|
void setRenderMode(int value);
|
||||||
|
void setRenderMode();
|
||||||
|
void resetCamera();
|
||||||
|
|
||||||
|
private:
|
||||||
|
int createCamera(const QString &name);
|
||||||
|
|
||||||
|
QAction *_fpsAction;
|
||||||
|
QAction *_edit3dAction;
|
||||||
|
QAction *_pointRenderModeAction;
|
||||||
|
QAction *_lineRenderModeAction;
|
||||||
|
QAction *_fillRenderModeAction;
|
||||||
|
QAction *_addCamAction;
|
||||||
|
QAction *_delCamAction;
|
||||||
|
QAction *_resetCamAction;
|
||||||
|
QSpinBox *_speedSpinBox;
|
||||||
|
QComboBox *_listCamComboBox;
|
||||||
|
QMenu *_renderModeMenu;
|
||||||
|
QLabel *_speedLabel;
|
||||||
|
QToolBar *_camToolBar;
|
||||||
|
|
||||||
|
CCameraItem *_currentCamera;
|
||||||
|
std::vector<CCameraItem *> _cameraList;
|
||||||
|
|
||||||
|
}; /* class CCameraControl */
|
||||||
|
|
||||||
|
} /* namespace NLQT */
|
||||||
|
|
||||||
|
#endif // CAMERA_CONTROL_H
|
Binary file not shown.
After Width: | Height: | Size: 5.6 KiB |
Binary file not shown.
After Width: | Height: | Size: 5.8 KiB |
Binary file not shown.
After Width: | Height: | Size: 2.8 KiB |
Binary file not shown.
After Width: | Height: | Size: 3.7 KiB |
Binary file not shown.
After Width: | Height: | Size: 5.2 KiB |
@ -0,0 +1,55 @@
|
|||||||
|
// Object Viewer Qt - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
|
||||||
|
// Copyright (C) 2010 Winch Gate Property Limited
|
||||||
|
// Copyright (C) 2011 Dzmitry Kamiahin <dnk-88@tut.by>
|
||||||
|
//
|
||||||
|
// This program is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Affero General Public License as
|
||||||
|
// published by the Free Software Foundation, either version 3 of the
|
||||||
|
// License, or (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU Affero General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Affero General Public License
|
||||||
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#ifndef IAPP_PAGE_H
|
||||||
|
#define IAPP_PAGE_H
|
||||||
|
|
||||||
|
#include <QtCore/QObject>
|
||||||
|
|
||||||
|
class QWidget;
|
||||||
|
|
||||||
|
namespace Core
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
@interface IAppPage
|
||||||
|
@brief The IAppPage is an interface for providing app pages in main window.
|
||||||
|
@details You need to subclass this interface and put an instance of your subclass
|
||||||
|
into the plugin manager object pool.
|
||||||
|
*/
|
||||||
|
class IAppPage
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual ~IAppPage() {}
|
||||||
|
|
||||||
|
/// id() is a unique identifier for referencing this page
|
||||||
|
virtual QString id() const = 0;
|
||||||
|
|
||||||
|
/// trName() is the (translated) name for display.
|
||||||
|
virtual QString trName() const = 0;
|
||||||
|
|
||||||
|
/// icon() is the icon for display
|
||||||
|
virtual QIcon icon() const = 0;
|
||||||
|
|
||||||
|
/// The widget will be destroyed by the widget hierarchy when the main window closes
|
||||||
|
virtual QWidget *widget() = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Core
|
||||||
|
|
||||||
|
Q_DECLARE_INTERFACE(Core::IAppPage, "dev.ryzom.com.IAppPage/0.1")
|
||||||
|
|
||||||
|
#endif // IAPP_PAGE_H
|
@ -0,0 +1,56 @@
|
|||||||
|
// Object Viewer Qt - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
|
||||||
|
// Copyright (C) 2010 Winch Gate Property Limited
|
||||||
|
// Copyright (C) 2011 Dzmitry Kamiahin <dnk-88@tut.by>
|
||||||
|
// Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
|
||||||
|
//
|
||||||
|
// This program is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Affero General Public License as
|
||||||
|
// published by the Free Software Foundation, either version 3 of the
|
||||||
|
// License, or (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU Affero General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Affero General Public License
|
||||||
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#ifndef ICORE_LISTENER_H
|
||||||
|
#define ICORE_LISTENER_H
|
||||||
|
|
||||||
|
#include <QtCore/QObject>
|
||||||
|
|
||||||
|
class QWidget;
|
||||||
|
|
||||||
|
namespace Core
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
@interface ICoreListener
|
||||||
|
@brief The ICoreListener is an interface for providing a hook for plugins to veto on close event emitted from
|
||||||
|
the core plugin.
|
||||||
|
@details You implement this interface if you want to prevent the closing of the whole application.
|
||||||
|
If the application window requests a close, then first ICoreListener::closeMainWindow() is called
|
||||||
|
(in arbitrary order) on all registered objects implementing this interface.
|
||||||
|
If one if these calls returns false, the process is aborted and the event is ignored. If all calls return
|
||||||
|
true, the corresponding signal is emitted and the event is accepted/performed.
|
||||||
|
|
||||||
|
You need to add your implementing object to the plugin managers objects:
|
||||||
|
PluginManager->addObject(yourImplementingObject);
|
||||||
|
Don't forget to remove the object again at deconstruction (e.g. in the destructor of
|
||||||
|
your plugin)
|
||||||
|
*/
|
||||||
|
class ICoreListener
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual ~ICoreListener() {}
|
||||||
|
|
||||||
|
/// Return false from the implemented method if you want to prevent the event.
|
||||||
|
virtual bool closeMainWindow() const = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Core
|
||||||
|
|
||||||
|
Q_DECLARE_INTERFACE(Core::ICoreListener, "dev.ryzom.com.ICoreListener/0.1")
|
||||||
|
|
||||||
|
#endif // ICORE_LISTENER_H
|
@ -0,0 +1,241 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
||||||
|
**
|
||||||
|
** Use, modification and distribution is allowed without limitation,
|
||||||
|
** warranty, liability or support of any kind.
|
||||||
|
**
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include "qtwin.h"
|
||||||
|
#include <QLibrary>
|
||||||
|
#include <QApplication>
|
||||||
|
#include <QWidget>
|
||||||
|
#include <QList>
|
||||||
|
#include <QPointer>
|
||||||
|
|
||||||
|
#ifdef Q_WS_WIN
|
||||||
|
|
||||||
|
#include <qt_windows.h>
|
||||||
|
|
||||||
|
// Blur behind data structures
|
||||||
|
#define DWM_BB_ENABLE 0x00000001 // fEnable has been specified
|
||||||
|
#define DWM_BB_BLURREGION 0x00000002 // hRgnBlur has been specified
|
||||||
|
#define DWM_BB_TRANSITIONONMAXIMIZED 0x00000004 // fTransitionOnMaximized has been specified
|
||||||
|
#define WM_DWMCOMPOSITIONCHANGED 0x031E // Composition changed window message
|
||||||
|
|
||||||
|
typedef struct _DWM_BLURBEHIND
|
||||||
|
{
|
||||||
|
DWORD dwFlags;
|
||||||
|
BOOL fEnable;
|
||||||
|
HRGN hRgnBlur;
|
||||||
|
BOOL fTransitionOnMaximized;
|
||||||
|
} DWM_BLURBEHIND, *PDWM_BLURBEHIND;
|
||||||
|
|
||||||
|
typedef struct _MARGINS
|
||||||
|
{
|
||||||
|
int cxLeftWidth;
|
||||||
|
int cxRightWidth;
|
||||||
|
int cyTopHeight;
|
||||||
|
int cyBottomHeight;
|
||||||
|
} MARGINS, *PMARGINS;
|
||||||
|
|
||||||
|
typedef HRESULT (WINAPI *PtrDwmIsCompositionEnabled)(BOOL* pfEnabled);
|
||||||
|
typedef HRESULT (WINAPI *PtrDwmExtendFrameIntoClientArea)(HWND hWnd, const MARGINS* pMarInset);
|
||||||
|
typedef HRESULT (WINAPI *PtrDwmEnableBlurBehindWindow)(HWND hWnd, const DWM_BLURBEHIND* pBlurBehind);
|
||||||
|
typedef HRESULT (WINAPI *PtrDwmGetColorizationColor)(DWORD *pcrColorization, BOOL *pfOpaqueBlend);
|
||||||
|
|
||||||
|
static PtrDwmIsCompositionEnabled pDwmIsCompositionEnabled= 0;
|
||||||
|
static PtrDwmEnableBlurBehindWindow pDwmEnableBlurBehindWindow = 0;
|
||||||
|
static PtrDwmExtendFrameIntoClientArea pDwmExtendFrameIntoClientArea = 0;
|
||||||
|
static PtrDwmGetColorizationColor pDwmGetColorizationColor = 0;
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Internal helper class that notifies windows if the
|
||||||
|
* DWM compositing state changes and updates the widget
|
||||||
|
* flags correspondingly.
|
||||||
|
*/
|
||||||
|
class WindowNotifier : public QWidget
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
WindowNotifier()
|
||||||
|
{
|
||||||
|
winId();
|
||||||
|
}
|
||||||
|
void addWidget(QWidget *widget)
|
||||||
|
{
|
||||||
|
widgets.append(widget);
|
||||||
|
}
|
||||||
|
void removeWidget(QWidget *widget)
|
||||||
|
{
|
||||||
|
widgets.removeAll(widget);
|
||||||
|
}
|
||||||
|
bool winEvent(MSG *message, long *result);
|
||||||
|
|
||||||
|
private:
|
||||||
|
QWidgetList widgets;
|
||||||
|
};
|
||||||
|
|
||||||
|
static bool resolveLibs()
|
||||||
|
{
|
||||||
|
if (!pDwmIsCompositionEnabled)
|
||||||
|
{
|
||||||
|
QLibrary dwmLib(QString::fromAscii("dwmapi"));
|
||||||
|
pDwmIsCompositionEnabled =(PtrDwmIsCompositionEnabled)dwmLib.resolve("DwmIsCompositionEnabled");
|
||||||
|
pDwmExtendFrameIntoClientArea = (PtrDwmExtendFrameIntoClientArea)dwmLib.resolve("DwmExtendFrameIntoClientArea");
|
||||||
|
pDwmEnableBlurBehindWindow = (PtrDwmEnableBlurBehindWindow)dwmLib.resolve("DwmEnableBlurBehindWindow");
|
||||||
|
pDwmGetColorizationColor = (PtrDwmGetColorizationColor)dwmLib.resolve("DwmGetColorizationColor");
|
||||||
|
}
|
||||||
|
return pDwmIsCompositionEnabled != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* Chekcs and returns true if Windows DWM composition
|
||||||
|
* is currently enabled on the system.
|
||||||
|
*
|
||||||
|
* To get live notification on the availability of
|
||||||
|
* this feature, you will currently have to
|
||||||
|
* reimplement winEvent() on your widget and listen
|
||||||
|
* for the WM_DWMCOMPOSITIONCHANGED event to occur.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
bool QtWin::isCompositionEnabled()
|
||||||
|
{
|
||||||
|
#ifdef Q_WS_WIN
|
||||||
|
if (resolveLibs())
|
||||||
|
{
|
||||||
|
HRESULT hr = S_OK;
|
||||||
|
BOOL isEnabled = false;
|
||||||
|
hr = pDwmIsCompositionEnabled(&isEnabled);
|
||||||
|
if (SUCCEEDED(hr))
|
||||||
|
return isEnabled;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* Enables Blur behind on a Widget.
|
||||||
|
*
|
||||||
|
* \a enable tells if the blur should be enabled or not
|
||||||
|
*/
|
||||||
|
bool QtWin::enableBlurBehindWindow(QWidget *widget, bool enable)
|
||||||
|
{
|
||||||
|
Q_ASSERT(widget);
|
||||||
|
bool result = false;
|
||||||
|
#ifdef Q_WS_WIN
|
||||||
|
if (resolveLibs())
|
||||||
|
{
|
||||||
|
DWM_BLURBEHIND bb = {0};
|
||||||
|
HRESULT hr = S_OK;
|
||||||
|
bb.fEnable = enable;
|
||||||
|
bb.dwFlags = DWM_BB_ENABLE;
|
||||||
|
bb.hRgnBlur = NULL;
|
||||||
|
widget->setAttribute(Qt::WA_TranslucentBackground, enable);
|
||||||
|
widget->setAttribute(Qt::WA_NoSystemBackground, enable);
|
||||||
|
hr = pDwmEnableBlurBehindWindow(widget->winId(), &bb);
|
||||||
|
if (SUCCEEDED(hr))
|
||||||
|
{
|
||||||
|
result = true;
|
||||||
|
windowNotifier()->addWidget(widget);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* ExtendFrameIntoClientArea.
|
||||||
|
*
|
||||||
|
* This controls the rendering of the frame inside the window.
|
||||||
|
* Note that passing margins of -1 (the default value) will completely
|
||||||
|
* remove the frame from the window.
|
||||||
|
*
|
||||||
|
* \note you should not call enableBlurBehindWindow before calling
|
||||||
|
* this functions
|
||||||
|
*
|
||||||
|
* \a enable tells if the blur should be enabled or not
|
||||||
|
*/
|
||||||
|
bool QtWin::extendFrameIntoClientArea(QWidget *widget, int left, int top, int right, int bottom)
|
||||||
|
{
|
||||||
|
|
||||||
|
Q_ASSERT(widget);
|
||||||
|
Q_UNUSED(left);
|
||||||
|
Q_UNUSED(top);
|
||||||
|
Q_UNUSED(right);
|
||||||
|
Q_UNUSED(bottom);
|
||||||
|
|
||||||
|
bool result = false;
|
||||||
|
#ifdef Q_WS_WIN
|
||||||
|
if (resolveLibs())
|
||||||
|
{
|
||||||
|
QLibrary dwmLib(QString::fromAscii("dwmapi"));
|
||||||
|
HRESULT hr = S_OK;
|
||||||
|
MARGINS m = {left, top, right, bottom};
|
||||||
|
hr = pDwmExtendFrameIntoClientArea(widget->winId(), &m);
|
||||||
|
if (SUCCEEDED(hr))
|
||||||
|
{
|
||||||
|
result = true;
|
||||||
|
windowNotifier()->addWidget(widget);
|
||||||
|
}
|
||||||
|
widget->setAttribute(Qt::WA_TranslucentBackground, result);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* Returns the current colorizationColor for the window.
|
||||||
|
*
|
||||||
|
* \a enable tells if the blur should be enabled or not
|
||||||
|
*/
|
||||||
|
QColor QtWin::colorizatinColor()
|
||||||
|
{
|
||||||
|
QColor resultColor = QApplication::palette().window().color();
|
||||||
|
|
||||||
|
#ifdef Q_WS_WIN
|
||||||
|
if (resolveLibs())
|
||||||
|
{
|
||||||
|
DWORD color = 0;
|
||||||
|
BOOL opaque = FALSE;
|
||||||
|
QLibrary dwmLib(QString::fromAscii("dwmapi"));
|
||||||
|
HRESULT hr = S_OK;
|
||||||
|
hr = pDwmGetColorizationColor(&color, &opaque);
|
||||||
|
if (SUCCEEDED(hr))
|
||||||
|
resultColor = QColor(color);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
return resultColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef Q_WS_WIN
|
||||||
|
WindowNotifier *QtWin::windowNotifier()
|
||||||
|
{
|
||||||
|
static WindowNotifier *windowNotifierInstance = 0;
|
||||||
|
if (!windowNotifierInstance)
|
||||||
|
windowNotifierInstance = new WindowNotifier;
|
||||||
|
return windowNotifierInstance;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Notify all enabled windows that the DWM state changed */
|
||||||
|
bool WindowNotifier::winEvent(MSG *message, long *result)
|
||||||
|
{
|
||||||
|
if (message && message->message == WM_DWMCOMPOSITIONCHANGED)
|
||||||
|
{
|
||||||
|
bool compositionEnabled = QtWin::isCompositionEnabled();
|
||||||
|
Q_FOREACH(QWidget * widget, widgets)
|
||||||
|
{
|
||||||
|
if (widget)
|
||||||
|
{
|
||||||
|
widget->setAttribute(Qt::WA_NoSystemBackground, compositionEnabled);
|
||||||
|
}
|
||||||
|
widget->update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return QWidget::winEvent(message, result);
|
||||||
|
}
|
||||||
|
#endif
|
@ -0,0 +1,37 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
||||||
|
**
|
||||||
|
** Use, modification and distribution is allowed without limitation,
|
||||||
|
** warranty, liability or support of any kind.
|
||||||
|
**
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifndef QTWIN_H
|
||||||
|
#define QTWIN_H
|
||||||
|
|
||||||
|
#include <QColor>
|
||||||
|
#include <QWidget>
|
||||||
|
/**
|
||||||
|
* This is a helper class for using the Desktop Window Manager
|
||||||
|
* functionality on Windows 7 and Windows Vista. On other platforms
|
||||||
|
* these functions will simply not do anything.
|
||||||
|
*/
|
||||||
|
|
||||||
|
class WindowNotifier;
|
||||||
|
|
||||||
|
class QtWin
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static bool enableBlurBehindWindow(QWidget *widget, bool enable = true);
|
||||||
|
static bool extendFrameIntoClientArea(QWidget *widget,
|
||||||
|
int left = -1, int top = -1,
|
||||||
|
int right = -1, int bottom = -1);
|
||||||
|
static bool isCompositionEnabled();
|
||||||
|
static QColor colorizatinColor();
|
||||||
|
|
||||||
|
private:
|
||||||
|
static WindowNotifier *windowNotifier();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // QTWIN_H
|
@ -0,0 +1,54 @@
|
|||||||
|
// Object Viewer Qt - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
|
||||||
|
// Copyright (C) 2010 Winch Gate Property Limited
|
||||||
|
// Copyright (C) 2011 Dzmitry Kamiahin <dnk-88@tut.by>
|
||||||
|
//
|
||||||
|
// This program is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Affero General Public License as
|
||||||
|
// published by the Free Software Foundation, either version 3 of the
|
||||||
|
// License, or (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU Affero General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Affero General Public License
|
||||||
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include "simple_viewer.h"
|
||||||
|
|
||||||
|
// Qt includes
|
||||||
|
#include <QtGui/QWidget>
|
||||||
|
#include <QtGui/QGridLayout>
|
||||||
|
#include <QtGui/QMessageBox>
|
||||||
|
|
||||||
|
// NeL includes
|
||||||
|
|
||||||
|
// Project includes
|
||||||
|
|
||||||
|
namespace Plugin
|
||||||
|
{
|
||||||
|
|
||||||
|
CSimpleViewer::CSimpleViewer(QWidget *parent)
|
||||||
|
: QWidget(parent)
|
||||||
|
{
|
||||||
|
QGridLayout *gridLayout = new QGridLayout(this);
|
||||||
|
gridLayout->setObjectName(QString::fromUtf8("gridLayoutSimpleViewer"));
|
||||||
|
gridLayout->setContentsMargins(0, 0, 0, 0);
|
||||||
|
NLQT::QNLWidget *_nelWidget = new NLQT::QNLWidget(this);
|
||||||
|
gridLayout->addWidget(_nelWidget, 0, 0, 1, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CCoreListener::closeMainWindow() const
|
||||||
|
{
|
||||||
|
int ret = QMessageBox::question(0, tr("Example close event hook"),
|
||||||
|
tr("Do you want to close window?"),
|
||||||
|
QMessageBox::Yes | QMessageBox::No);
|
||||||
|
|
||||||
|
if (ret == QMessageBox::Yes)
|
||||||
|
return true;
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
} /* namespace Plugin */
|
@ -0,0 +1,55 @@
|
|||||||
|
// Object Viewer Qt - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
|
||||||
|
// Copyright (C) 2010 Winch Gate Property Limited
|
||||||
|
// Copyright (C) 2011 Dzmitry Kamiahin <dnk-88@tut.by>
|
||||||
|
//
|
||||||
|
// This program is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Affero General Public License as
|
||||||
|
// published by the Free Software Foundation, either version 3 of the
|
||||||
|
// License, or (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU Affero General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Affero General Public License
|
||||||
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef SIMPLE_VIEWER_H
|
||||||
|
#define SIMPLE_VIEWER_H
|
||||||
|
|
||||||
|
// Project includes
|
||||||
|
#include "qnel_widget.h"
|
||||||
|
#include "../core/icore_listener.h"
|
||||||
|
|
||||||
|
// Qt includes
|
||||||
|
#include <QtCore/QObject>
|
||||||
|
|
||||||
|
class QWidget;
|
||||||
|
|
||||||
|
namespace Plugin
|
||||||
|
{
|
||||||
|
|
||||||
|
class CSimpleViewer : public QWidget
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
CSimpleViewer(QWidget *parent = 0);
|
||||||
|
virtual ~CSimpleViewer() {}
|
||||||
|
};
|
||||||
|
|
||||||
|
class CCoreListener : public QObject, public Core::ICoreListener
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_INTERFACES(Core::ICoreListener)
|
||||||
|
public:
|
||||||
|
CCoreListener(QObject *parent = 0): QObject(parent) {}
|
||||||
|
virtual ~CCoreListener() {}
|
||||||
|
|
||||||
|
virtual bool closeMainWindow() const;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Plugin
|
||||||
|
|
||||||
|
#endif // SIMPLE_VIEWER_H
|
Loading…
Reference in New Issue