391 lines
11 KiB
C++
Executable File
391 lines
11 KiB
C++
Executable File
#include "viewwidget.h"
|
|
#include "viewwidgetstate.h"
|
|
#include <QApplication>
|
|
#include <QVBoxLayout>
|
|
#include <QEvent>
|
|
#include <QGLWidget>
|
|
#include <QWindow>
|
|
#include <dtEntity/log.h>
|
|
|
|
namespace BuildingViewer
|
|
{
|
|
ViewWidgetState::ViewWidgetState(VCtrl::ViewWidget* pView)
|
|
: m_featureID(pView->featureID())
|
|
, m_usedTransparencyValue(pView->transparency())
|
|
, m_windowWidth(pView->accessView()->width())
|
|
, m_windowHeight(pView->accessView()->height())
|
|
, m_lockActive(pView->lockedRotation())
|
|
, m_dotsActive(pView->dotModeActive())
|
|
, m_isMaximized(pView->isMaximized())
|
|
, m_namesActive(pView->nameModeActive())
|
|
, m_usesOrtho(pView->viewMode() == VCtrl::ViewMode::ORTHOGRAPHIC)
|
|
, m_usesExactPos(pView->exactPos())
|
|
{}
|
|
}
|
|
|
|
namespace VCtrl
|
|
{
|
|
const QColor ViewWidget::ColorBorder = QColor(48, 136, 209);
|
|
const QColor ViewWidget::ColorSelected = QColor(90, 200, 255);
|
|
const QColor ViewWidget::ColorHighlighted = Qt::green;
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
ViewWidget::ViewWidget(unsigned int contextid, dtEntity::EntityId bid, const std::string &strFeatureID, bool usesExactPos, QWidget *parent)
|
|
: QFrame(parent),
|
|
m_locked(false),
|
|
m_useDotMode(false),
|
|
m_entityID(bid),
|
|
m_featureID(strFeatureID),
|
|
mContextId(contextid),
|
|
m_usesExactPos(usesExactPos),
|
|
mViewerInterface(nullptr),
|
|
mClosedByAPI(false),
|
|
m_pView(nullptr)
|
|
{
|
|
setupUi(this);
|
|
|
|
m_toolButton_maximize->setIcon(QIcon(QStringLiteral("icon:bgv_view_maximize.svg")));
|
|
m_toolButton_close->setIcon(QIcon(QStringLiteral("icon:bgv_view_close.svg")));
|
|
m_toolButton_viewmode->setIcon(QIcon(QStringLiteral("icon:bgv_view_iso.svg")));
|
|
m_toolButton_dots->setIcon(QIcon(QStringLiteral("icon:bgv_view_symbols.svg")));
|
|
m_toolButton_lockRotation->setIcon(QIcon(QStringLiteral("icon:bgv_view_unlock.svg")));
|
|
m_toolButton_rooms->setIcon(QIcon(QStringLiteral("icon:bgv_room_edit.svg")));
|
|
|
|
m_toolButton_viewmode->setChecked(m_viewmode != ViewMode::ISOMETRIC);
|
|
m_toolButton_dots->setChecked(m_useDotMode);
|
|
m_toolButton_lockRotation->setChecked(m_locked);
|
|
|
|
m_toolButton_ZoomOut->setIcon(QIcon(QStringLiteral("icon:bgv_zoom_out.svg")));
|
|
m_toolButton_ZoomIn->setIcon(QIcon(QStringLiteral("icon:bgv_zoom_in.svg")));
|
|
|
|
QIcon iconT(QStringLiteral("icon:bgv_transparency.svg"));
|
|
QPixmap image(iconT.pixmap(30,30));
|
|
m_label_transparency->setPixmap(image);
|
|
|
|
connect(m_toolButton_viewmode, &QToolButton::clicked, this, &ViewWidget::viewModeChanged);
|
|
connect(_transparency, &QSlider::valueChanged, this, &ViewWidget::transparencyChanged);
|
|
connect(m_toolButton_lockRotation, &QToolButton::clicked, this, &ViewWidget::lockRotationToggled);
|
|
connect(m_toolButton_dots, &QToolButton::clicked, this, &ViewWidget::dotModeToggled);
|
|
connect(m_toolButton_rooms, &QToolButton::clicked, this, &ViewWidget::nameModeToggled);
|
|
connect(m_toolButton_more, &QToolButton::clicked, this, &ViewWidget::slotShowMore);
|
|
connect(m_toolButton_maximize, &QToolButton::clicked, this, &ViewWidget::OnButtonMaximize);
|
|
connect(m_toolButton_close, &QToolButton::clicked, this, &ViewWidget::OnButtonClose);
|
|
|
|
connect(m_toolButton_ZoomOut, &QToolButton::clicked, this, [this](){
|
|
emit signal_Zoom(this, false);
|
|
});
|
|
connect(m_toolButton_ZoomIn, &QToolButton::clicked, this, [this](){
|
|
emit signal_Zoom(this, true);
|
|
});
|
|
|
|
m_toolButton_maximize->setEnabled(true);
|
|
|
|
setSelected(false);
|
|
setMouseTracking(true); // Otherwise ViewWidget::mouseMoveEvent would not receive any events
|
|
|
|
slotShowMore(false);
|
|
}
|
|
|
|
|
|
void ViewWidget::highlightBorder(bool highlight)
|
|
{
|
|
if (highlight)
|
|
drawBorder(ColorHighlighted);
|
|
else
|
|
drawBorder(isSelected() ? ColorSelected : ColorBorder);
|
|
}
|
|
|
|
|
|
void ViewWidget::dotModeToggled()
|
|
{
|
|
if (!mViewerInterface) return;
|
|
|
|
m_useDotMode ^= true;
|
|
mViewerInterface->SetPlayerDisplayMode(mContextId, m_useDotMode ? PlayerDisplayMode::Dots : PlayerDisplayMode::Icons);
|
|
}
|
|
|
|
|
|
void ViewWidget::drawBorder(const QColor &col)
|
|
{
|
|
setStyleSheet(QStringLiteral("#ViewWidget { border: 2px solid %1; }").arg(col.name()));
|
|
}
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
void ViewWidget::closeByAPI()
|
|
{
|
|
mClosedByAPI = true;
|
|
this->close();
|
|
}
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
void ViewWidget::setText(const QString &strText)
|
|
{
|
|
m_label_description->setText(strText);
|
|
}
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
void ViewWidget::closeEvent(QCloseEvent *e)
|
|
{
|
|
if (mViewerInterface && !mClosedByAPI)
|
|
mViewerInterface->CloseView(mContextId);
|
|
QFrame::closeEvent(e);
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
void ViewWidget::setDisplayedViewMode(ViewMode vm)
|
|
{
|
|
if (vm == ViewMode::ORTHOGRAPHIC)
|
|
{
|
|
m_toolButton_viewmode->setIcon(QIcon(QStringLiteral("icon:bgv_view_iso.svg")));
|
|
}
|
|
else if (vm == ViewMode::ISOMETRIC)
|
|
{
|
|
m_toolButton_viewmode->setIcon(QIcon(QStringLiteral("icon:bgv_view_ortho.svg")));
|
|
}
|
|
|
|
m_viewmode = vm;
|
|
m_toolButton_viewmode->setChecked(m_viewmode != ViewMode::ISOMETRIC);
|
|
m_toolButton_dots->setChecked(m_useDotMode);
|
|
m_toolButton_lockRotation->setChecked(m_locked);
|
|
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
void ViewWidget::viewModeChanged()
|
|
{
|
|
if (!mViewerInterface) return;
|
|
|
|
if (m_viewmode == ViewMode::ORTHOGRAPHIC)
|
|
{
|
|
m_viewmode = ViewMode::ISOMETRIC;
|
|
m_toolButton_viewmode->setIcon(QIcon(QStringLiteral("icon:bgv_view_iso.svg")));
|
|
mViewerInterface->ChangeViewMode(mContextId, m_viewmode);
|
|
}
|
|
else if (m_viewmode == ViewMode::ISOMETRIC)
|
|
{
|
|
m_viewmode = ViewMode::ORTHOGRAPHIC;
|
|
m_toolButton_viewmode->setIcon(QIcon(QStringLiteral("icon:bgv_view_ortho.svg")));
|
|
mViewerInterface->ChangeViewMode(mContextId, m_viewmode);
|
|
}
|
|
m_toolButton_viewmode->setChecked(m_viewmode != ViewMode::ISOMETRIC);
|
|
}
|
|
|
|
bool ViewWidget::isOpenGlWindowExposed() const
|
|
{
|
|
QGLWidget *gl = qobject_cast<QGLWidget*>(m_pView);
|
|
if (!gl || !gl->windowHandle())
|
|
return false;
|
|
return gl->windowHandle()->isExposed();
|
|
}
|
|
|
|
void ViewWidget::setMaximized(bool maximized)
|
|
{
|
|
m_toolButton_maximize->setIcon(maximized ?
|
|
QIcon(QStringLiteral("icon:bgv_view_minimize.svg")) :
|
|
QIcon(QStringLiteral("icon:bgv_view_maximize.svg")));
|
|
m_isMaximized = maximized;
|
|
}
|
|
|
|
|
|
void ViewWidget::setSelected(bool selected)
|
|
{
|
|
m_isSelected = selected;
|
|
drawBorder(m_isSelected ? ColorSelected : ColorBorder);
|
|
}
|
|
|
|
|
|
|
|
double ViewWidget::transparency() const {
|
|
return static_cast<double>(_transparency->value()) / 100.0;
|
|
}
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
void ViewWidget::setTransparency(float value)
|
|
{
|
|
_transparency->setValue(qRound(value * 100));
|
|
}
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
void ViewWidget::transparencyChanged(int v)
|
|
{
|
|
if (!mViewerInterface) return;
|
|
mViewerInterface->SetWallTransparency(mContextId, float(v) / 100.0f);
|
|
}
|
|
|
|
|
|
|
|
bool ViewWidget::lockedRotation() const
|
|
{
|
|
return m_locked;
|
|
}
|
|
|
|
|
|
bool ViewWidget::dotModeActive() const
|
|
{
|
|
return m_useDotMode;
|
|
}
|
|
|
|
|
|
bool ViewWidget::nameModeActive() const
|
|
{
|
|
return m_toolButton_rooms->isChecked();
|
|
}
|
|
|
|
|
|
ViewMode ViewWidget::viewMode() const {
|
|
return m_viewmode;
|
|
}
|
|
|
|
bool ViewWidget::exactPos() const
|
|
{
|
|
return m_usesExactPos;
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
void ViewWidget::setLockRotationCheckbox(bool v)
|
|
{
|
|
m_locked = v;
|
|
m_toolButton_lockRotation->setIcon(m_locked ?
|
|
QIcon(QStringLiteral("icon:bgv_view_lock.svg")) :
|
|
QIcon(QStringLiteral("icon:bgv_view_unlock.svg")));
|
|
m_toolButton_lockRotation->setChecked(m_locked);
|
|
}
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
void ViewWidget::setDotModeCheckbox(bool v)
|
|
{
|
|
m_useDotMode = v;
|
|
m_toolButton_dots->setIcon(m_useDotMode ?
|
|
QIcon(QStringLiteral("icon:bgv_view_dots.svg")) :
|
|
QIcon(QStringLiteral("icon:bgv_view_symbols.svg")));
|
|
m_toolButton_dots->setChecked(m_useDotMode);
|
|
}
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
void ViewWidget::setNameModeCheckbox(bool v)
|
|
{
|
|
m_toolButton_rooms->setChecked(v);
|
|
}
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
void ViewWidget::lockRotationToggled()
|
|
{
|
|
if (!mViewerInterface) return;
|
|
|
|
m_locked ^= true;
|
|
mViewerInterface->LockViewRotationToMapRotation(mContextId, m_locked);
|
|
}
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
void ViewWidget::slotShowMore(bool v)
|
|
{
|
|
widget->setVisible(v);
|
|
}
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
void ViewWidget::nameModeToggled(bool v)
|
|
{
|
|
if(!mViewerInterface) return;
|
|
mViewerInterface->ChangeNameMode(mContextId, v);
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
void ViewWidget::OnButtonMaximize(bool)
|
|
{
|
|
if (m_isMaximized)
|
|
{
|
|
emit signal_MinimizeRequest(this);
|
|
}
|
|
else
|
|
{
|
|
emit signal_MaximizeRequest(this);
|
|
}
|
|
}
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
void ViewWidget::OnButtonClose(bool)
|
|
{
|
|
emit signal_CloseRequest(this);
|
|
}
|
|
|
|
|
|
QWidget* ViewWidget::accessView()
|
|
{
|
|
return m_pView;
|
|
}
|
|
|
|
|
|
void ViewWidget::mouseMoveEvent(QMouseEvent *event)
|
|
{
|
|
emit signal_FocusRequest(this);
|
|
QFrame::mouseMoveEvent(event);
|
|
}
|
|
|
|
|
|
bool ViewWidget::eventFilter(QObject *obj, QEvent *event)
|
|
{
|
|
if (event->type() == QEvent::MouseMove)
|
|
emit signal_FocusRequest(this);
|
|
if (obj == m_pView && event->type() == QEvent::Show)
|
|
emit signal_ViewIsShown(this);
|
|
|
|
return QFrame::eventFilter(obj, event);
|
|
}
|
|
|
|
void ViewWidget::showEvent(QShowEvent *event)
|
|
{
|
|
QWidget::showEvent(event);
|
|
updateTlwTransientParent();
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
void ViewWidget::setView(QWidget *view)
|
|
{
|
|
if (m_pView)
|
|
{
|
|
m_pView->removeEventFilter(this);
|
|
layout()->removeWidget(m_pView);
|
|
}
|
|
m_pView = view;
|
|
m_pView->installEventFilter(this);
|
|
QVBoxLayout *vLay = qobject_cast<QVBoxLayout*>(layout());
|
|
if (!vLay)
|
|
{
|
|
Q_ASSERT(false);
|
|
return;
|
|
}
|
|
vLay->addWidget(m_pView);
|
|
updateTlwTransientParent();
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
void ViewWidget::updateTlwTransientParent()
|
|
{
|
|
// this is a workaround for Qt < 5.12 which does not set the correct blocking state for
|
|
// the toplevel widget where this ViewWidget lives in when there is a model dialog (which
|
|
// means all other TLWs are blocked) and a native window (like e.g. QGLWidget) is added as
|
|
// a child therefore we have to trigger and update of the blocking state of the complete
|
|
// hierarchy to make sure we don't get out of sync. It's fixed in at least 5.12, but could
|
|
// not find out the commit / bug report for it. If you want to debug,
|
|
// QGuiApplicationPrivate::updateBlockedStatus() is a good starting point for this.
|
|
if (QApplication::activeModalWidget())
|
|
{
|
|
QWidget *tlw = window();
|
|
if (tlw && tlw->windowHandle())
|
|
tlw->windowHandle()->setTransientParent(tlw->windowHandle()->transientParent());
|
|
}
|
|
}
|
|
}
|