diff --git a/modules/gui/src/gl_canvas.cc b/modules/gui/src/gl_canvas.cc index 83dd63ccc2f9a9b4fd743d734fe7f36af5d7bd0e..41e192786143236ed6d3aefcafd0bc393bede569 100644 --- a/modules/gui/src/gl_canvas.cc +++ b/modules/gui/src/gl_canvas.cc @@ -16,180 +16,94 @@ // along with this library; if not, write to the Free Software Foundation, Inc., // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA //------------------------------------------------------------------------------ -#include <ost/gui/python_shell/python_interpreter.hh> -#ifndef _MSC_VER -#include <sys/time.h> -#endif + +#include <chrono> #include "gl_canvas.hh" -#include "gl_win.hh" #include <ost/log.hh> -#include <ost/dyn_cast.hh> -#include <ost/mol/view_op.hh> - -#include <ost/seq/alignment_handle.hh> - - - #include <ost/gfx/scene.hh> -#include <ost/gfx/entity.hh> -#include <QTimer> -#include <QStatusBar> -#include <QApplication> -#include <QClipboard> -#include <QTime> -#include <QBasicTimer> +#include <ost/gui/tools/tool_manager.hh> +#include <ost/gui/perspective.hh> +#include <ost/gui/gosty_app.hh> + +#include <QResizeEvent> #include <QMouseEvent> -#include <QMenu> -#if QT_VERSION >= 0x040600 -# include <QGesture> -#endif -#include "tools/tool_manager.hh" namespace ost { namespace gui { -using gfx::Scene; - -GLCanvas::GLCanvas(GLWin* gl_win, QWidget* parent, const QSurfaceFormat& f): - QOpenGLWidget(parent), - glwin_(gl_win), - mouse_key_mask_(), - refresh_(true), - master_timer_(), - bench_flag_(false), - last_pos_(), - scene_menu_(NULL), - show_beacon_(false), - angular_speed_(0.0) -{ - this->setFormat(f); - master_timer_.start(10,this); - setFocusPolicy(Qt::StrongFocus); - setMouseTracking(true); - scene_menu_=new SceneMenu(); - this->setContextMenuPolicy(Qt::CustomContextMenu); - this->setAutoFillBackground(false); - connect(this, SIGNAL(customContextMenuRequested(const QPoint&)), this, - SLOT(RequestContextMenu(const QPoint&))); -#if QT_VERSION >= 0x040600 - this->grabGesture(Qt::PinchGesture); -#endif -} - -bool GLCanvas::event(QEvent* event) -{ -#if QT_VERSION >= 0x040600 - if (event->type()==QEvent::Gesture) { - return this->GestureEvent(static_cast<QGestureEvent*>(event)); +ost::gui::GLCanvas::GLCanvas(): QOpenGLWindow(), + last_pos_(), + show_beacon_(false), + bench_flag_(false) { } + +void GLCanvas::StatusMessage(const String& m) { + // This Window can also be displayed without a full blown GostyApp. + // We therefore only feed the message into Gosty if there's already + // a valid instance. + if(GostyApp::ValidInstance()) { + GostyApp::Instance()->GetPerspective()->StatusMessage(m); } -#endif - return QOpenGLWidget::event(event); } - -#if QT_VERSION >= 0x040600 - -bool GLCanvas::GestureEvent(QGestureEvent* event) -{ - if (QGesture* pinch=event->gesture(Qt::PinchGesture)) { - QPinchGesture* pinch_gesture=static_cast<QPinchGesture*>(pinch); - QPinchGesture::ChangeFlags changeFlags = pinch_gesture->changeFlags(); - if (changeFlags & QPinchGesture::RotationAngleChanged) { - qreal value=pinch_gesture->rotationAngle(); - qreal lastValue=pinch_gesture->lastRotationAngle(); - this->OnTransform(gfx::INPUT_COMMAND_ROTZ, 0, gfx::TRANSFORM_VIEW, - static_cast<Real>(value - lastValue)); - this->update(); - event->accept(); - if (pinch_gesture->state()==Qt::GestureFinished) { - angular_speed_=value-lastValue; - if (!gesture_timer_.isActive()) - gesture_timer_.start(10, this); - } - return true; - } - } - return false; -} - -#endif - - - - -void GLCanvas::MakeActive() -{ - makeCurrent(); +QSurfaceFormat GLCanvas::GetDefaultFormat() { + QSurfaceFormat f = QSurfaceFormat::defaultFormat(); + f.setRedBufferSize(8); + f.setGreenBufferSize(8); + f.setBlueBufferSize(8); + f.setAlphaBufferSize(8); + f.setDepthBufferSize(24); + return f; } -void GLCanvas::DoRefresh() -{ - refresh_=true; +void GLCanvas::SetDefaultFormat() { + this->setFormat(GLCanvas::GetDefaultFormat()); } -void GLCanvas::StatusMessage(const String& m) -{ - glwin_->StatusMessage(m); -} - -void GLCanvas::OnTransform(gfx::InputCommand com, int indx, - gfx::TransformTarget trg, Real val) -{ - // does not request a redraw on purpose, in order to chain OnTransform calls - Scene::Instance().Apply(gfx::InputEvent(gfx::INPUT_DEVICE_MOUSE,com,indx, - trg,val*0.5),false); -} - -void GLCanvas::initializeGL() -{ - static bool init=false; - if(!init) { - init=true; - } - +void GLCanvas::initializeGL() { LOG_DEBUG("GLCanvas::initializeGL()"); - Scene::Instance().InitGL(); + gfx::Scene::Instance().InitGL(); LOG_DEBUG("GLCanvas::registering with scene"); - Scene::Instance().Register(this); + gfx::Scene::Instance().Register(this); } -void GLCanvas::resizeGL(int w, int h) -{ - LOG_DEBUG("GLCanvas::resizeGL("<<w<<","<<h<<")"); - Scene::Instance().Resize(w,h); -} +void GLCanvas::paintGL() { + + // static variables for benchmarking + static int benchmark_count = 0; + static std::chrono::steady_clock::time_point timer; + + if(bench_flag_) { + ++benchmark_count; + if(benchmark_count == 20) { + benchmark_count = 0; + int ms = std::chrono::duration_cast<std::chrono::milliseconds>( + std::chrono::steady_clock::now() - timer).count(); + Real fps = Real(20) / (Real(ms) * 0.001); + LOG_ERROR(fps << " fps"); + timer = std::chrono::steady_clock::now(); + } + this->update(); + } -void GLCanvas::paintGL() -{ - Scene::Instance().RenderGL(); + gfx::Scene::Instance().RenderGL(); Tool* tool=ToolManager::Instance().GetActiveTool(); if (tool) { tool->RenderGL(); } } -void GLCanvas::wheelEvent(QWheelEvent* event) -{ - OnTransform(gfx::INPUT_COMMAND_TRANSZ,0,gfx::TRANSFORM_VIEW, - 0.2*static_cast<Real>(-event->delta())); -} -bool GLCanvas::IsToolEvent(QInputEvent* event) const -{ - return (event->modifiers() & Qt::ControlModifier) == Qt::ControlModifier; +void GLCanvas::resizeGL(int w, int h) { + gfx::Scene::Instance().Resize(w, h); } -MouseEvent::Buttons GLCanvas::TranslateButtons(Qt::MouseButtons buttons) const -{ - return MouseEvent::Buttons(buttons); -} +void GLCanvas::mouseMoveEvent(QMouseEvent* event) { -void GLCanvas::mouseMoveEvent(QMouseEvent* event) -{ if (!(show_beacon_ || event->buttons())) { return; } + if (this->IsToolEvent(event)) { if (ToolManager::Instance().GetActiveTool()) { MouseEvent mouse_event(this->TranslateButtons(event->buttons()), @@ -205,8 +119,8 @@ void GLCanvas::mouseMoveEvent(QMouseEvent* event) this->DoRefresh(); } -void GLCanvas::mousePressEvent(QMouseEvent* event) -{ +void GLCanvas::mousePressEvent(QMouseEvent* event) { + if (this->IsToolEvent(event)) { if (ToolManager::Instance().GetActiveTool()) { MouseEvent mouse_event(this->TranslateButtons(event->button()), @@ -222,8 +136,8 @@ void GLCanvas::mousePressEvent(QMouseEvent* event) this->DoRefresh(); } -void GLCanvas::mouseReleaseEvent(QMouseEvent* event) -{ +void GLCanvas::mouseReleaseEvent(QMouseEvent* event) { + if (this->IsToolEvent(event)) { if (ToolManager::Instance().GetActiveTool()) { MouseEvent mouse_event(this->TranslateButtons(event->button()), @@ -240,8 +154,8 @@ void GLCanvas::mouseReleaseEvent(QMouseEvent* event) this->DoRefresh(); } -void GLCanvas::mouseDoubleClickEvent(QMouseEvent* event) -{ +void GLCanvas::mouseDoubleClickEvent(QMouseEvent* event) { + if (this->IsToolEvent(event)) { if (ToolManager::Instance().GetActiveTool()) { MouseEvent mouse_event(this->TranslateButtons(event->button()), @@ -264,32 +178,47 @@ void GLCanvas::mouseDoubleClickEvent(QMouseEvent* event) } } -void GLCanvas::RequestContextMenu(const QPoint& pos) -{ - QPoint pick_pos(pos.x(),this->height()-pos.y()); - scene_menu_->SetPickPoint(pick_pos); - scene_menu_->ShowMenu(this->mapToGlobal(pos)); +void GLCanvas::OnTransform(gfx::InputCommand com, int indx, + gfx::TransformTarget trg, Real val) { + // does not request a redraw on purpose, in order to chain OnTransform calls + ost::gfx::Scene::Instance().Apply(gfx::InputEvent(gfx::INPUT_DEVICE_MOUSE, com, indx, + trg, val*0.5),false); +} + +void GLCanvas::SetTestMode(bool f) { + gfx::Scene::Instance().SetTestMode(f); +} + +bool GLCanvas::IsToolEvent(QInputEvent* event) const { + return event->modifiers() & Qt::ControlModifier; +} + +MouseEvent::Buttons GLCanvas::TranslateButtons(Qt::MouseButtons buttons) const { + return MouseEvent::Buttons(buttons); } -void GLCanvas::HandleMousePressEvent(QMouseEvent* event) -{ +void GLCanvas::HandleMousePressEvent(QMouseEvent* event) { gfx::Scene& scene=gfx::Scene::Instance(); scene.Pick(event->x(), scene.GetViewport().height-event->y(), 0); event->accept(); + + // if its a right click, we emit the ContextMenu signal, + // maybe someone wants to implement something interactive on top... + if(event->buttons() == Qt::RightButton) { + emit CustomContextMenuRequested(event->pos()); + } } -void GLCanvas::HandleMouseReleaseEvent(QMouseEvent* event) -{ +void GLCanvas::HandleMouseReleaseEvent(QMouseEvent* event) { event->accept(); } -void GLCanvas::HandleMouseMoveEvent(QMouseEvent* event) -{ +void GLCanvas::HandleMouseMoveEvent(QMouseEvent* event) { int indx=0; gfx::TransformTarget trg=gfx::TRANSFORM_VIEW; if(show_beacon_) { - Scene::Instance().SetBeacon(event->x(),size().height()-event->y()); + ost::gfx::Scene::Instance().SetBeacon(event->x(),size().height()-event->y()); } QPoint delta=QPoint(event->x(), event->y())-last_pos_; @@ -334,62 +263,10 @@ void GLCanvas::HandleMouseMoveEvent(QMouseEvent* event) event->accept(); } - -void GLCanvas::CopySelectionToClipboard() -{ - gfx::EntityP ent; - - // TODO: this needs a re-write based on the new GfxNodeVisitor -#if 0 - // find first entity connect with non-empty selection - gfx::GfxObjList& obj=gfx::Scene::Instance().SceneObjects(); - for (gfx::GfxObjList::iterator i=obj.begin(), e=obj.end(); i!=e; ++i) { - if (ent=dyn_cast<gfx::Entity>(*i)) { - if (ent->GetView().GetAtomCount()>0) { - break; - } else { - ent=gfx::EntityP(); - } - } - } -#endif - - if (!ent) - return; - - mol::EntityView sel=ent->GetSelection(); - mol::EntityView view=ent->GetView(); - mol::ChainViewList chains=view.GetChainList(); - QString pretty; - for (mol::ChainViewList::iterator c=chains.begin(), ec=chains.end(); c!=ec; ++c) { - mol::ResidueViewList res=c->GetResidueList(); - std::stringstream seq1; - std::stringstream seq2; - for (mol::ResidueViewList::iterator r=res.begin(), er=res.end(); r!=er; ++r) { - mol::ResidueView rv=*r; - if (!rv.IsPeptideLinking() || rv.GetOneLetterCode()=='?') - continue; - seq1 << rv.GetOneLetterCode(); - if (sel.ViewForHandle(rv.GetHandle()).IsValid()) { - seq2 << rv.GetOneLetterCode(); - } else { - seq2 << '-'; - } - } - seq::AlignmentHandle a=seq::CreateAlignment(); - a.AddSequence(seq::CreateSequence(ent->GetName(), seq1.str())); - a.AddSequence(seq::CreateSequence(ent->GetName()+" SEL", seq2.str())); - pretty+=QString(a.ToString(80).c_str()); - } - QClipboard *clipboard = QApplication::clipboard(); - clipboard->setText(pretty); -} - -void GLCanvas::keyPressEvent(QKeyEvent* event) -{ +void GLCanvas::keyPressEvent(QKeyEvent* event) { if(event->key()==Qt::Key_Space) { show_beacon_=true; - Scene::Instance().SetBeacon(last_pos_.x(),size().height()-last_pos_.y()); + gfx::Scene::Instance().SetBeacon(last_pos_.x(),size().height()-last_pos_.y()); DoRefresh(); setCursor(Qt::BlankCursor); } @@ -401,12 +278,9 @@ void GLCanvas::keyPressEvent(QKeyEvent* event) } else if(event->key()==Qt::Key_F) { OnTransform(gfx::INPUT_COMMAND_TOGGLE_FOG,0,gfx::TRANSFORM_VIEW,0.0); return; - } else if(event->key()==Qt::Key_B) { + } else if(event->key()==Qt::Key_B) { bench_flag_=!bench_flag_; return; - } else if (event->key()==Qt::Key_C) { - this->CopySelectionToClipboard(); - return; } else if(event->key()==Qt::Key_1) { gfx::Scene::Instance().SetShadingMode("fallback"); DoRefresh(); @@ -452,75 +326,23 @@ void GLCanvas::keyPressEvent(QKeyEvent* event) event->ignore(); } -void GLCanvas::keyReleaseEvent(QKeyEvent* event) -{ +void GLCanvas::keyReleaseEvent(QKeyEvent* event) { if(event->key()==Qt::Key_Space) { show_beacon_=false; - Scene::Instance().SetBeaconOff(); + gfx::Scene::Instance().SetBeaconOff(); DoRefresh(); setCursor(Qt::ArrowCursor); return; } - if(event->key()==Qt::Key_Alt){ - emit ReleaseFocus(); - return; - } - QOpenGLWidget::keyReleaseEvent(event); } -#ifndef _MSC_VER -Real delta_time(const timeval& t1, const timeval& t2) -{ - return 1e-6*static_cast<Real>((t2.tv_sec*1e6+t2.tv_usec)-(t1.tv_sec*1e6+t1.tv_usec)); -} -#endif - -void GLCanvas::timerEvent(QTimerEvent * event) -{ - -#if QT_VERSION>= 0x040600 - // gesture support - if (gesture_timer_.timerId()==event->timerId()) { - if (angular_speed_!=0.0) { - angular_speed_*=0.95; - this->OnTransform(gfx::INPUT_COMMAND_ROTZ, 0, gfx::TRANSFORM_VIEW, - static_cast<Real>(angular_speed_)); - if (std::abs(angular_speed_)<0.001) { - angular_speed_=0.0; - gesture_timer_.stop(); - } - this->update(); - } - return; - } -#endif -#ifndef _MSC_VER - static struct timeval time0,time1; - static int count=0; -#endif - if(refresh_ || bench_flag_) { - refresh_=false; - master_timer_.stop(); - this->update(); - master_timer_.start(10,this); - } - -#ifndef _MSC_VER - if(bench_flag_) { - ++count; - if(count==20) { - count=0; - gettimeofday(&time1,NULL); - LOG_ERROR(20.0/delta_time(time0,time1) << " fps"); - gettimeofday(&time0,NULL); - } - } -#endif +void GLCanvas::wheelEvent(QWheelEvent* event) { + OnTransform(gfx::INPUT_COMMAND_TRANSZ,0,gfx::TRANSFORM_VIEW, + 0.2*static_cast<Real>(-event->delta())); } -void GLCanvas::SetTestMode(bool f) -{ - Scene::Instance().SetTestMode(f); +bool GLCanvas::event(QEvent* event) { + return QOpenGLWindow::event(event); } }} // ns diff --git a/modules/gui/src/gl_canvas.hh b/modules/gui/src/gl_canvas.hh index 152f18fc3e745e09ad979738d8637b2294fa27f1..7ec714d18e04a7829854fa5e84fa0ba8c486b467 100644 --- a/modules/gui/src/gl_canvas.hh +++ b/modules/gui/src/gl_canvas.hh @@ -19,101 +19,74 @@ #ifndef OST_GUI_GL_CANVAS_HH #define OST_GUI_GL_CANVAS_HH - - -#include <ost/gui/tools/tool.hh> -#include <ost/gui/scene_menu.hh> #include <ost/gfx/glwin_base.hh> +#include <ost/gui/tools/tool.hh> #include <ost/gfx/input.hh> -#include <ost/gfx/gfx_object_fw.hh> - // Qt includes must come last -#include <QOpenGLWidget> -#include <QOpenGLContext> -#include <QOpenGLFunctions> +#include <QOpenGLWindow> #include <QSurfaceFormat> -#include <QBasicTimer> -class QMenu; -class QMouseEvent; -#if QT_VERSION >= 0x040600 -class QGestureEvent; -#endif +// forward declaration +class QResizeEvent; namespace ost { namespace gui { -class GLCanvas; - -class GLWin; - -class DLLEXPORT_OST_GUI GLCanvas : public QOpenGLWidget, public gfx::GLWinBase -{ +class GLCanvas : public QOpenGLWindow, public gfx::GLWinBase { Q_OBJECT; + public: - GLCanvas(GLWin *gl_win, QWidget* parent, - const QSurfaceFormat& f = QSurfaceFormat::defaultFormat()); + GLCanvas(); // gfx::GLWinBase interface - virtual void MakeActive(); - virtual void DoRefresh(); + virtual void MakeActive() { this->makeCurrent(); } + virtual void DoRefresh() {this->update(); } virtual void StatusMessage(const String& m); virtual bool HasStereo() const {return format().stereo();}; virtual bool HasMultisample() const {return format().samples() > 1;} + // QSurfaceFormat for GL context setup + static QSurfaceFormat GetDefaultFormat(); + void SetDefaultFormat(); + // central point for sending input to the gfx layer void OnTransform(gfx::InputCommand, int indx, gfx::TransformTarget, Real val); void SetTestMode(bool f); - + signals: - void ReleaseFocus(); - + void CustomContextMenuRequested(const QPoint& point); + protected: - void Select(const String& query); - void CopySelectionToClipboard(); - // QGLWidget interface + + // QOpenGLWindow interface virtual void initializeGL(); - virtual void resizeGL(int w, int h); virtual void paintGL(); + virtual void resizeGL(int w, int h); + // event handling virtual void mouseMoveEvent(QMouseEvent* event); virtual void mousePressEvent(QMouseEvent* event); virtual void mouseReleaseEvent(QMouseEvent* event); - virtual void mouseDoubleClickEvent(QMouseEvent* event); - + virtual void mouseDoubleClickEvent(QMouseEvent* event); + virtual void keyPressEvent(QKeyEvent* event); virtual void keyReleaseEvent(QKeyEvent* event); - virtual void timerEvent(QTimerEvent * event); virtual void wheelEvent(QWheelEvent* event); virtual bool event(QEvent* event); -private slots: - virtual void RequestContextMenu(const QPoint& pos); private: -#if QT_VERSION >= 0x040600 - bool GestureEvent(QGestureEvent* event); -#endif + bool IsToolEvent(QInputEvent* event) const; MouseEvent::Buttons TranslateButtons(Qt::MouseButtons buttons) const; void HandleMousePressEvent(QMouseEvent* event); void HandleMouseReleaseEvent(QMouseEvent* event); void HandleMouseMoveEvent(QMouseEvent* event); - void build_context_menu(); - void prepare_context_menu(const QPoint& pos); - GLWin* glwin_; - int mouse_key_mask_; - bool refresh_; - QBasicTimer master_timer_; - bool bench_flag_; + QPoint last_pos_; - SceneMenu* scene_menu_; - bool show_beacon_; - float angular_speed_; -#if QT_VERSION>=0x04600 - QBasicTimer gesture_timer_; -#endif + bool show_beacon_; + bool bench_flag_; }; }} // ns diff --git a/modules/gui/src/gl_win.cc b/modules/gui/src/gl_win.cc index aa4925897349a799181c9fa8f7804e25bbe158e6..d0fe7b5cb0a2d378dc9b13632663d50fbcafcedb 100644 --- a/modules/gui/src/gl_win.cc +++ b/modules/gui/src/gl_win.cc @@ -22,78 +22,44 @@ #include <ost/gfx/scene.hh> #include <ost/gui/gl_win.hh> +#include <ost/gui/gl_canvas.hh> #include <ost/gui/tools/tool_manager.hh> #include <ost/gui/tools/selection_tool.hh> #include <ost/gui/tools/manipulator.hh> #include <ost/gui/tools/measure_tool.hh> #include <ost/gui/perspective.hh> -#include <ost/gui/gl_canvas.hh> #include <ost/gui/tools/tool.hh> #include <ost/gui/tools/tool_bar.hh> +#include <ost/gui/scene_menu.hh> #if OST_IMG_ENABLED # include <ost/gui/tools/map_tool.hh> #endif -#include <QApplication> -#include <QDesktopWidget> -#include <QIcon> -#include <QActionGroup> -#include <QLabel> -#include <QStatusBar> -#include <QVBoxLayout> -#include <QStatusBar> - /* Authors: Ansgar Philippsen, Marco Biasini */ namespace ost { namespace gui { -GLWin::GLWin(QWidget* p, bool try_stereo): -Widget(NULL, p), -gl_canvas_(NULL) -{ - QMainWindow* main=new QMainWindow; - +GLWin::GLWin(QWidget* p, bool try_stereo): Widget(NULL, p) { + + + gl_canvas_ = new GLCanvas; + if(try_stereo) { - LOG_VERBOSE("GLCanvas: trying stereo visuals first"); - QSurfaceFormat format=QSurfaceFormat::defaultFormat(); - format.setStereo(true); - gl_canvas_=new GLCanvas(this, main, format); - } - if(!gl_canvas_) { - if(try_stereo) { - LOG_VERBOSE("GLCanvas: no stereo visual found, trying normal ones"); - } - gl_canvas_=new GLCanvas(this, main); + QSurfaceFormat f = GLCanvas::GetDefaultFormat(); + f.setStereo(true); + gl_canvas_->setFormat(f); + } else{ + gl_canvas_->SetDefaultFormat(); } + + gl_canvas_widget_ = QWidget::createWindowContainer(gl_canvas_); + gl_canvas_widget_->setFocusPolicy(Qt::StrongFocus); + gl_canvas_widget_->setMouseTracking(true); - this->SetInternalWidget(main); - gfx::Scene::Instance().AttachObserver(this); - QSurfaceFormat format = gl_canvas_->format(); - - LOG_VERBOSE("GLCanvas: using " << format.redBufferSize() << "." - << format.greenBufferSize() << "." - << format.blueBufferSize() << "." - << format.alphaBufferSize() << " RGBA bits, " - << format.depthBufferSize() << " depth bits, " - << format.stencilBufferSize() << " stencil bits") - if(gl_canvas_->format().stereo()) { - LOG_VERBOSE("GLCanvas: using stereo visual"); - } else { - LOG_VERBOSE("GLCanvas: no stereo visual found"); - } - if(format.samples() > 1) { - LOG_VERBOSE("GLCanvas: using multisampling with " << format.samples() << " samples per pixel"); - } else { - LOG_VERBOSE("GLCanvas: no multisampling"); - } - main->setCentralWidget(gl_canvas_); - connect(gl_canvas_, SIGNAL(ReleaseFocus()), this, SIGNAL(ReleaseFocus())); - connect(&ToolManager::Instance(), SIGNAL(ActiveToolChanged(Tool*)), this, SLOT(ActiveToolChanged(Tool*))); - toolbar_=build_toolbar(); - main->addToolBar(Qt::LeftToolBarArea, toolbar_); + toolbar_ = new ToolBar(this); ToolManager::Instance().AddTool(new SelectionTool); ToolManager::Instance().AddTool(new Manipulator); ToolManager::Instance().AddTool(new MeasureTool); @@ -101,46 +67,48 @@ gl_canvas_(NULL) ToolManager::Instance().AddTool(new MapTool); #endif - if(!gl_canvas_ || !gl_canvas_->isValid()) { - LOG_ERROR("GLCanvas: no valid GL context found, this is pretty fatal"); - return; - } + scene_menu_ = new SceneMenu(); + + QMainWindow* main = new QMainWindow; + main->setCentralWidget(gl_canvas_widget_); + main->addToolBar(Qt::LeftToolBarArea, toolbar_); + this->SetInternalWidget(main); + gfx::Scene::Instance().AttachObserver(this); + + connect(gl_canvas_, SIGNAL(CustomContextMenuRequested(const QPoint&)), + this, SLOT(RequestContextMenu(const QPoint&))); + connect(&ToolManager::Instance(), SIGNAL(ActiveToolChanged(Tool*)), + this, SLOT(ActiveToolChanged(Tool*))); } -void GLWin::ActiveToolChanged(Tool* t) -{ +void GLWin::ActiveToolChanged(Tool* t) { gfx::Scene::Instance().RequestRedraw(); } -GLWin::~GLWin() -{ +GLWin::~GLWin() { gfx::Scene::Instance().DetachObserver(this); } -void GLWin::SetTestMode(bool f) -{ +void GLWin::SetTestMode(bool f) { gl_canvas_->SetTestMode(f); } -ToolBar* GLWin::build_toolbar() -{ - ToolBar* tb=new ToolBar(this); - return tb; -} - -void GLWin::StatusMessage(const String& m) -{ +void GLWin::StatusMessage(const String& m) { GostyApp::Instance()->GetPerspective()->StatusMessage(m); } -bool GLWin::Restore(const QString& prefix) -{ +bool GLWin::Restore(const QString& prefix) { return true; } -bool GLWin::Save(const QString& prefix) -{ +bool GLWin::Save(const QString& prefix) { return true; } +void GLWin::RequestContextMenu(const QPoint& pos) { + QPoint pick_pos(pos.x(), gl_canvas_->height()-pos.y()); + scene_menu_->SetPickPoint(pick_pos); + scene_menu_->ShowMenu(gl_canvas_->mapToGlobal(pos)); +} + }} // ns diff --git a/modules/gui/src/gl_win.hh b/modules/gui/src/gl_win.hh index 8b2ccda0f9e9ba8f99f89f7efdea6792b5b3cfe2..2daf43d3d876a715b9f7b6969c65155c503c556c 100644 --- a/modules/gui/src/gl_win.hh +++ b/modules/gui/src/gl_win.hh @@ -21,24 +21,20 @@ #include <ost/gfx/scene_observer.hh> - #include <ost/gui/module_config.hh> #include <ost/gui/widget.hh> -#include <QActionGroup> - -class QStatusBar; -class QAction; - /* Authors: Ansgar Philippsen, Marco Biasini */ + namespace ost { namespace gui { class GLCanvas; class ToolBar; class Tool; +class SceneMenu; class DLLEXPORT_OST_GUI GLWin: public Widget, public gfx::SceneObserver { @@ -48,9 +44,6 @@ public: ~GLWin(); void SetTestMode(bool f); -signals: - void ReleaseFocus(); - public: virtual bool Restore(const QString& prefix); virtual bool Save(const QString& prefix); @@ -58,20 +51,15 @@ public: public slots: void StatusMessage(const String& m); void ActiveToolChanged(Tool* t); -private: - GLCanvas* gl_canvas_; - QAction* edit_rigid_action_; - QAction* edit_torsion_action_; - QAction* edit_angle_action_; - QAction* edit_rotamer_action_; - QAction* smode_atom_action_; - QAction* smode_residue_action_; - QAction* smode_chain_action_; - - ToolBar* toolbar_; - QStatusBar* status_bar_; - ToolBar* build_toolbar(); +private slots: + virtual void RequestContextMenu(const QPoint& pos); + +private: + GLCanvas* gl_canvas_; + QWidget* gl_canvas_widget_; + ToolBar* toolbar_; + SceneMenu* scene_menu_; }; }} // ns