121 lines
3.0 KiB
Plaintext
121 lines
3.0 KiB
Plaintext
// Copyright (C) 2010, Guy Barrand. All rights reserved.
|
|
// See the file tools.license for terms.
|
|
|
|
#ifndef toolx_Qt_zb_viewer
|
|
#define toolx_Qt_zb_viewer
|
|
|
|
#include "pixwin"
|
|
#include <tools/sg/zb_viewer>
|
|
|
|
#include "session"
|
|
|
|
#include <QtCore/qglobal.h> //For QT_VERSION.
|
|
|
|
#if QT_VERSION < 0x050000
|
|
#include <QtGui/qboxlayout.h>
|
|
#else
|
|
#include <QtWidgets/qboxlayout.h>
|
|
#endif
|
|
|
|
namespace toolx {
|
|
namespace Qt {
|
|
|
|
class zb_viewer: public tools::sg::zb_viewer {
|
|
typedef tools::sg::zb_viewer parent;
|
|
typedef pixwin render_area_t;
|
|
public:
|
|
zb_viewer(session& a_session,
|
|
int a_x = 0,int a_y = 0,
|
|
unsigned int a_width = 500,unsigned int a_height = 500,
|
|
const std::string& a_win_title = "")
|
|
:parent(a_session.out(),a_width,a_height)
|
|
,m_session(a_session)
|
|
,m_shell(0)
|
|
,m_own_shell(false)
|
|
,m_render_area(0)
|
|
{
|
|
if(!m_session.is_valid()) return; //throw
|
|
m_shell = m_session.create_window(a_win_title.c_str(),a_x,a_y,a_width,a_height);
|
|
if(!m_shell) return; //throw
|
|
m_own_shell = true;
|
|
|
|
m_render_area = new render_area_t(0,*this);
|
|
|
|
QVBoxLayout* layout = new QVBoxLayout;
|
|
layout->setContentsMargins(0,0,0,0);
|
|
layout->addWidget(m_render_area);
|
|
m_shell->setLayout(layout);
|
|
}
|
|
virtual ~zb_viewer() {
|
|
if(m_render_area) m_render_area->set_device_interactor(0);
|
|
if(m_shell && m_own_shell) {
|
|
m_session.delete_window(m_shell);
|
|
//m_session.sync();
|
|
}
|
|
}
|
|
protected:
|
|
zb_viewer(const zb_viewer& a_from)
|
|
:parent(a_from)
|
|
,m_session(a_from.m_session)
|
|
,m_shell(0)
|
|
,m_own_shell(false)
|
|
,m_render_area(0)
|
|
{}
|
|
zb_viewer& operator=(const zb_viewer& a_from){
|
|
parent::operator=(a_from);
|
|
return *this;
|
|
}
|
|
public:
|
|
bool has_window() const {return m_shell?true:false;} //for SWIG
|
|
|
|
bool show() {
|
|
if(!m_shell) return false;
|
|
m_shell->show();
|
|
return true;
|
|
}
|
|
|
|
void win_render() {
|
|
if(!m_render_area) return;
|
|
m_render_area->repaint(); //immediate.
|
|
m_session.sync();
|
|
}
|
|
|
|
void emit_win_render() {
|
|
if(!m_render_area) return;
|
|
m_render_area->update(); //delayed.
|
|
}
|
|
|
|
bool window_size(unsigned int& a_w,unsigned int& a_h) {
|
|
if(!m_render_area) {a_w = 0;a_h = 0;return false;}
|
|
a_w = (unsigned int)m_render_area->width();
|
|
a_h = (unsigned int)m_render_area->height();
|
|
return true;
|
|
}
|
|
void render_area_size(unsigned int& a_w,unsigned int& a_h) {
|
|
a_w = parent::width();
|
|
a_h = parent::height();
|
|
}
|
|
|
|
void set_device_interactor(tools::sg::device_interactor* a_interactor) { //we do not have ownership.
|
|
if(!m_render_area) return;
|
|
m_render_area->set_device_interactor(a_interactor);
|
|
}
|
|
public:
|
|
QWidget* shell() {return m_shell;}
|
|
void set_own_shell(bool a_value) {m_own_shell = a_value;}
|
|
render_area_t* render_area() {return m_render_area;}
|
|
void enable_keyboard_focus() {
|
|
if(!m_render_area) return;
|
|
m_render_area->setFocusPolicy(::Qt::StrongFocus);
|
|
}
|
|
protected:
|
|
session& m_session;
|
|
QWidget* m_shell;
|
|
bool m_own_shell;
|
|
render_area_t* m_render_area;
|
|
};
|
|
|
|
}}
|
|
|
|
#endif
|