mirror of
https://github.com/genodelabs/genode.git
synced 2025-04-07 19:34:56 +00:00
qt5: Adapt qpluginwidget new nitpicker/loader
The QPluginWidget used to be a QNitpickerViewWidget but the new loader interface does no longer hand out a view capability. So we need to decouple both classes. This patch moves the view-geometry calculation to a separate class to make it easier reusable, in particular for the QPluginWidget.
This commit is contained in:
parent
dc1a08074a
commit
dc2da978f4
@ -21,41 +21,68 @@
|
||||
|
||||
#include <nitpicker_session/client.h>
|
||||
|
||||
class QNitpickerViewWidget : public QWidget
|
||||
|
||||
class QEmbeddedViewWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
QHash<QScrollBar*, bool> _scrollbars;
|
||||
|
||||
QHash<QScrollBar*, bool> _scrollbars;
|
||||
|
||||
int _orig_w = 0;
|
||||
int _orig_h = 0;
|
||||
int _orig_buf_x = 0;
|
||||
int _orig_buf_y = 0;
|
||||
|
||||
private slots:
|
||||
#if 0
|
||||
void windowEvent(QWSWindow *window,
|
||||
QWSServer::WindowEvent eventType);
|
||||
#endif
|
||||
void valueChanged();
|
||||
void destroyed(QObject *obj = 0);
|
||||
|
||||
void valueChanged();
|
||||
void destroyed(QObject *obj = 0);
|
||||
|
||||
protected:
|
||||
|
||||
Nitpicker::Session_client *nitpicker;
|
||||
Nitpicker::Session::View_handle view_handle;
|
||||
struct View_geometry
|
||||
{
|
||||
int x, y, w, h, buf_x, buf_y;
|
||||
};
|
||||
|
||||
int orig_w;
|
||||
int orig_h;
|
||||
int orig_buf_x;
|
||||
int orig_buf_y;
|
||||
QEmbeddedViewWidget(QWidget *parent = 0);
|
||||
|
||||
virtual void showEvent(QShowEvent *event);
|
||||
virtual void hideEvent(QHideEvent *event);
|
||||
virtual void paintEvent(QPaintEvent *event);
|
||||
virtual ~QEmbeddedViewWidget();
|
||||
|
||||
void _orig_geometry(int w, int h, int buf_x, int buf_y)
|
||||
{
|
||||
_orig_w = w;
|
||||
_orig_h = h;
|
||||
_orig_buf_x = buf_x;
|
||||
_orig_buf_y = buf_y;
|
||||
}
|
||||
|
||||
View_geometry _calc_view_geometry();
|
||||
};
|
||||
|
||||
|
||||
class QNitpickerViewWidget : public QEmbeddedViewWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
protected:
|
||||
|
||||
Nitpicker::Session_client *nitpicker;
|
||||
Nitpicker::Session::View_handle view_handle;
|
||||
|
||||
virtual void showEvent(QShowEvent *event);
|
||||
virtual void hideEvent(QHideEvent *event);
|
||||
virtual void paintEvent(QPaintEvent *event);
|
||||
|
||||
public:
|
||||
QNitpickerViewWidget(QWidget *parent =0);
|
||||
~QNitpickerViewWidget();
|
||||
void setNitpickerView(Nitpicker::Session_client *nitpicker,
|
||||
Nitpicker::Session::View_handle view_handle,
|
||||
int buf_x, int buf_y, int w, int h);
|
||||
|
||||
QNitpickerViewWidget(QWidget *parent =0);
|
||||
~QNitpickerViewWidget();
|
||||
void setNitpickerView(Nitpicker::Session_client *nitpicker,
|
||||
Nitpicker::Session::View_handle view_handle,
|
||||
int buf_x, int buf_y, int w, int h);
|
||||
};
|
||||
|
||||
#endif // QNITPICKERVIEWWIDGET_H
|
||||
|
@ -61,20 +61,29 @@ class PluginStarter : public QThread
|
||||
|
||||
public:
|
||||
PluginStarter(QUrl plugin_url, QString &args,
|
||||
int max_width, int max_height,
|
||||
Nitpicker::View_capability parent_view);
|
||||
int max_width, int max_height,
|
||||
Nitpicker::View_capability parent_view);
|
||||
|
||||
void run();
|
||||
enum Plugin_loading_state plugin_loading_state() { return _plugin_loading_state; }
|
||||
QString &plugin_loading_error_string() { return _plugin_loading_error_string; }
|
||||
Nitpicker::View_capability plugin_view(int *w, int *h, int *buf_x, int *buf_y);
|
||||
|
||||
/**
|
||||
* Requst size of the nitpicker view of the loaded subsystem
|
||||
*/
|
||||
Loader::Area view_size();
|
||||
|
||||
/**
|
||||
* Set geometry of the nitpicker view of the loaded subsystem
|
||||
*/
|
||||
void view_geometry(Loader::Rect rect, Loader::Point offset);
|
||||
|
||||
signals:
|
||||
void finished();
|
||||
};
|
||||
|
||||
|
||||
class QPluginWidget : public QNitpickerViewWidget
|
||||
class QPluginWidget : public QEmbeddedViewWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@ -100,8 +109,9 @@ class QPluginWidget : public QNitpickerViewWidget
|
||||
void cleanup();
|
||||
|
||||
protected:
|
||||
virtual void paintEvent(QPaintEvent *event);
|
||||
virtual void showEvent(QShowEvent *event);
|
||||
virtual void paintEvent(QPaintEvent *);
|
||||
virtual void showEvent(QShowEvent *);
|
||||
virtual void hideEvent(QHideEvent *);
|
||||
|
||||
protected slots:
|
||||
void pluginStartFinished();
|
||||
|
@ -9,84 +9,23 @@
|
||||
#include <string.h>
|
||||
|
||||
#include <QtGui>
|
||||
#if 0
|
||||
#include <private/qwindowsurface_qws_p.h>
|
||||
#include <private/qwindowsurface_nitpicker_qws_p.h>
|
||||
#endif
|
||||
|
||||
#include <qnitpickerplatformwindow.h>
|
||||
|
||||
#include <qnitpickerviewwidget/qnitpickerviewwidget.h>
|
||||
|
||||
|
||||
QNitpickerViewWidget::QNitpickerViewWidget(QWidget *parent)
|
||||
: QWidget(parent), nitpicker(0), orig_w(0), orig_h(0), orig_buf_x(0), orig_buf_y(0)
|
||||
/*************************
|
||||
** QEmbeddedViewWidget **
|
||||
*************************/
|
||||
|
||||
QEmbeddedViewWidget::QEmbeddedViewWidget(QWidget *parent) { }
|
||||
|
||||
|
||||
QEmbeddedViewWidget::~QEmbeddedViewWidget() { }
|
||||
|
||||
|
||||
QEmbeddedViewWidget::View_geometry QEmbeddedViewWidget::_calc_view_geometry()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void QNitpickerViewWidget::setNitpickerView(Nitpicker::Session_client *new_nitpicker,
|
||||
Nitpicker::Session::View_handle new_view_handle,
|
||||
int buf_x, int buf_y, int w, int h)
|
||||
{
|
||||
orig_buf_x = buf_x;
|
||||
orig_buf_y = buf_y;
|
||||
orig_w = w;
|
||||
orig_h = h;
|
||||
// PDBG("orig_w = %d, orig_h = %d", orig_w, orig_h);
|
||||
|
||||
nitpicker = new_nitpicker;
|
||||
view_handle = new_view_handle;
|
||||
setFixedSize(orig_w, orig_h);
|
||||
}
|
||||
|
||||
|
||||
QNitpickerViewWidget::~QNitpickerViewWidget()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void QNitpickerViewWidget::showEvent(QShowEvent *event)
|
||||
{
|
||||
// qDebug() << "showEvent()";
|
||||
#if 0
|
||||
connect(qwsServer, SIGNAL(windowEvent(QWSWindow*, QWSServer::WindowEvent)),
|
||||
this, SLOT(windowEvent(QWSWindow*, QWSServer::WindowEvent)));
|
||||
#endif
|
||||
QWidget::showEvent(event);
|
||||
}
|
||||
|
||||
void QNitpickerViewWidget::hideEvent(QHideEvent *event)
|
||||
{
|
||||
// qDebug() << "hideEvent()";
|
||||
#if 0
|
||||
disconnect(this, SLOT(windowEvent(QWSWindow*, QWSServer::WindowEvent)));
|
||||
#endif
|
||||
QWidget::hideEvent(event);
|
||||
|
||||
if (nitpicker) {
|
||||
|
||||
typedef Nitpicker::Session::Command Command;
|
||||
|
||||
Nitpicker::Rect geometry(Nitpicker::Point(mapToGlobal(pos()).x(),
|
||||
mapToGlobal(pos()).y()),
|
||||
Nitpicker::Area(0, 0));
|
||||
nitpicker->enqueue<Command::Geometry>(view_handle, geometry);
|
||||
|
||||
Nitpicker::Point offset(orig_buf_x, orig_buf_y);
|
||||
nitpicker->enqueue<Command::Offset>(view_handle, offset);
|
||||
|
||||
nitpicker->execute();
|
||||
}
|
||||
}
|
||||
|
||||
void QNitpickerViewWidget::paintEvent(QPaintEvent *event)
|
||||
{
|
||||
QWidget::paintEvent(event);
|
||||
|
||||
if (!nitpicker)
|
||||
return;
|
||||
|
||||
/* mark all sliders as unchecked */
|
||||
QHashIterator<QScrollBar*, bool> i(_scrollbars);
|
||||
while(i.hasNext()) {
|
||||
@ -94,33 +33,6 @@ void QNitpickerViewWidget::paintEvent(QPaintEvent *event)
|
||||
_scrollbars.insert(i.key(), false);
|
||||
}
|
||||
|
||||
#if 0
|
||||
// qDebug() << "paintEvent()";
|
||||
qDebug() << "geometry: " << geometry(); /* widget relative to parent widget */
|
||||
qDebug() << "rect: " << rect(); /* (0, 0, width(), height()) without frames */
|
||||
qDebug() << "event->rect(): " << event->rect();
|
||||
qDebug() << "event->region(): " << event->region();
|
||||
qDebug() << "global(0, 0): " << mapToGlobal(QPoint(0, 0));
|
||||
qDebug() << "x(): " << x() << "y(): " << y();
|
||||
qDebug() << "global(x, y): " << mapToGlobal(QPoint(x(), y()));
|
||||
qDebug() << "window =" << window();
|
||||
// qDebug() << "window->geometry() =" << window()->geometry();
|
||||
// qDebug() << "mapToGlobal(window->geometry().topLeft()) =" <<
|
||||
mapToGlobal(window()->geometry().topLeft());
|
||||
qDebug() << "window->rect().topLeft() =" << window()->rect().topLeft();
|
||||
qDebug() << "mapToGlobal(window->rect().topLeft()) =" <<
|
||||
mapToGlobal(window()->rect().topLeft());
|
||||
qDebug() << "mapToGlobal(window->childrenRect().topLeft()) =" <<
|
||||
mapToGlobal(window()->childrenRect().topLeft());
|
||||
qDebug() << "mapToGlobal(window->contentsRect().topLeft()) =" <<
|
||||
mapToGlobal(window()->contentsRect().topLeft());
|
||||
qDebug() << "mapToGlobal(mask().boundingRect().bottomRight()) =" <<
|
||||
mapToGlobal(mask().boundingRect().bottomRight());
|
||||
#endif
|
||||
|
||||
// QPainter painter(this);
|
||||
// painter.fillRect(rect(), Qt::black);
|
||||
|
||||
QWidget *parent = parentWidget();
|
||||
|
||||
int w = 0;
|
||||
@ -130,47 +42,11 @@ void QNitpickerViewWidget::paintEvent(QPaintEvent *event)
|
||||
int diff_y = 0;
|
||||
|
||||
int x0 = mapToGlobal(QPoint(0, 0)).x();
|
||||
// qDebug() << "x0 = " << x0;
|
||||
int x1 = mapToGlobal(QPoint(orig_w - 1, 0)).x();
|
||||
// qDebug() << "x1 = " << x1;
|
||||
int x1 = mapToGlobal(QPoint(_orig_w - 1, 0)).x();
|
||||
int y0 = mapToGlobal(QPoint(0, 0)).y();
|
||||
// qDebug() << "y0 = " << y0;
|
||||
int y1 = mapToGlobal(QPoint(0, orig_h - 1)).y();
|
||||
// qDebug() << "y1 = " << y1;
|
||||
int y1 = mapToGlobal(QPoint(0, _orig_h - 1)).y();
|
||||
|
||||
while(parent) {
|
||||
#if 0
|
||||
qDebug() << "parent =" << parent;
|
||||
qDebug() << "parent's rect: " << parent->rect();
|
||||
qDebug() << "parent's children rect:" << parent->childrenRect();
|
||||
qDebug() << "parent's contents rect:" << parent->contentsRect();
|
||||
|
||||
/* start of view = most right window start position */
|
||||
// qDebug() << "parent->geometry() =" << parent->geometry();
|
||||
// qDebug() << "parent->frameGeometry() =" << parent->frameGeometry();
|
||||
// qDebug() << "mapToGlobal(parent->frameGeometry().topLeft()) =" <<
|
||||
parent->mapToGlobal(parent->frameGeometry().topLeft());
|
||||
qDebug() << "mapToGlobal(parent->geometry().bottomRight()) =" <<
|
||||
parent->mapToGlobal(parent->geometry().bottomRight());
|
||||
qDebug() << "mapToGlobal(parent->rect().topLeft()) =" <<
|
||||
parent->mapToGlobal(parent->rect().topLeft());
|
||||
qDebug() << "mapToGlobal(parent->rect().bottomRight()) =" <<
|
||||
parent->mapToGlobal(parent->rect().bottomRight());
|
||||
qDebug() << "mapToGlobal(parent->childrenRect().topLeft()) =" <<
|
||||
parent->mapToGlobal(parent->childrenRect().topLeft());
|
||||
qDebug() << "mapToGlobal(parent->childrenRect().bottomRight()) =" <<
|
||||
parent->mapToGlobal(parent->childrenRect().bottomRight());
|
||||
qDebug() << "mapToGlobal(parent->contentsRect().topLeft()) =" <<
|
||||
parent->mapToGlobal(parent->contentsRect().topLeft());
|
||||
qDebug() << "mapToGlobal(parent->contentsRect().bottomRight()) =" <<
|
||||
parent->mapToGlobal(parent->contentsRect().bottomRight());
|
||||
qDebug() << "parentWidget()->childAt(" << geometry().topRight() << ") = " <<
|
||||
parentWidget()->childAt(geometry().topRight());
|
||||
qDebug() << "visibleRegion() = " << visibleRegion();
|
||||
qDebug() << "geometry().contains(" << geometry().topRight() << ") = " <<
|
||||
geometry().contains(geometry().topRight());
|
||||
qDebug() << "mask() = " << mask();
|
||||
#endif
|
||||
|
||||
if (parent->inherits("QAbstractScrollArea")) {
|
||||
QAbstractScrollArea *scrollarea = qobject_cast<QAbstractScrollArea*>(parent);
|
||||
@ -191,28 +67,15 @@ void QNitpickerViewWidget::paintEvent(QPaintEvent *event)
|
||||
}
|
||||
/* update/insert value */
|
||||
_scrollbars.insert(scrollbar, true);
|
||||
|
||||
// w = qMin(w, parent->contentsRect().width() + parent->childrenRect().x());
|
||||
/* qDebug() << "mapToGlobal(viewport->rect().topLeft()) =" <<
|
||||
scrollarea->viewport()->mapToGlobal(scrollarea->viewport()->rect().topLeft()); */
|
||||
/* qDebug() << "mapToGlobal(viewport->rect().bottomRight()) =" <<
|
||||
scrollarea->viewport()->mapToGlobal(scrollarea->viewport()->rect().bottomRight()); */
|
||||
}
|
||||
|
||||
x0 = qMax(x0, parent->mapToGlobal(parent->contentsRect().topLeft()).x());
|
||||
// qDebug() << "x0 = " << x0;
|
||||
x1 = qMin(x1, parent->mapToGlobal(parent->contentsRect().bottomRight()).x());
|
||||
// qDebug() << "x1 = " << x1;
|
||||
y0 = qMax(y0, parent->mapToGlobal(parent->contentsRect().topLeft()).y());
|
||||
// qDebug() << "y0 = " << y0;
|
||||
y1 = qMin(y1, parent->mapToGlobal(parent->contentsRect().bottomRight()).y());
|
||||
// qDebug() << "y1 = " << y1;
|
||||
|
||||
//w = qMin(w, parent->contentsRect().width() /*+ parent->childrenRect().x()*/);
|
||||
w = x1 - x0 + 1;
|
||||
// qDebug() << "w = " << w;
|
||||
h = y1 - y0 + 1;
|
||||
// qDebug() << "h = " << h;
|
||||
|
||||
if (parent->childrenRect().x() < 0) {
|
||||
diff_x += parent->childrenRect().x();
|
||||
@ -236,27 +99,108 @@ void QNitpickerViewWidget::paintEvent(QPaintEvent *event)
|
||||
}
|
||||
}
|
||||
|
||||
return QEmbeddedViewWidget::View_geometry { x0, y0, w, h,
|
||||
_orig_buf_x + diff_x,
|
||||
_orig_buf_y + diff_y };
|
||||
}
|
||||
|
||||
|
||||
void QEmbeddedViewWidget::valueChanged()
|
||||
{
|
||||
if (isVisible()) {
|
||||
QPaintEvent e(rect());
|
||||
paintEvent(&e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void QEmbeddedViewWidget::destroyed(QObject *obj)
|
||||
{
|
||||
_scrollbars.remove(qobject_cast<QScrollBar*>(obj));
|
||||
}
|
||||
|
||||
|
||||
/**************************
|
||||
** QNitpickerViewWidget **
|
||||
**************************/
|
||||
|
||||
QNitpickerViewWidget::QNitpickerViewWidget(QWidget *parent)
|
||||
:
|
||||
QEmbeddedViewWidget(parent), nitpicker(0)
|
||||
{ }
|
||||
|
||||
|
||||
void QNitpickerViewWidget::setNitpickerView(Nitpicker::Session_client *new_nitpicker,
|
||||
Nitpicker::Session::View_handle new_view_handle,
|
||||
int buf_x, int buf_y, int w, int h)
|
||||
{
|
||||
QEmbeddedViewWidget::_orig_geometry(w, h, buf_x, buf_y);
|
||||
|
||||
nitpicker = new_nitpicker;
|
||||
view_handle = new_view_handle;
|
||||
setFixedSize(w, h);
|
||||
}
|
||||
|
||||
|
||||
QNitpickerViewWidget::~QNitpickerViewWidget() { }
|
||||
|
||||
|
||||
void QNitpickerViewWidget::showEvent(QShowEvent *event)
|
||||
{
|
||||
QWidget::showEvent(event);
|
||||
}
|
||||
|
||||
|
||||
void QNitpickerViewWidget::hideEvent(QHideEvent *event)
|
||||
{
|
||||
QWidget::hideEvent(event);
|
||||
|
||||
if (nitpicker) {
|
||||
|
||||
QEmbeddedViewWidget::View_geometry const view_geometry =
|
||||
QEmbeddedViewWidget::_calc_view_geometry();
|
||||
|
||||
typedef Nitpicker::Session::Command Command;
|
||||
|
||||
Nitpicker::Rect const geometry(Nitpicker::Point(mapToGlobal(pos()).x(),
|
||||
mapToGlobal(pos()).y()),
|
||||
Nitpicker::Area(0, 0));
|
||||
nitpicker->enqueue<Command::Geometry>(view_handle, geometry);
|
||||
|
||||
Nitpicker::Point const offset(view_geometry.buf_x, view_geometry.buf_y);
|
||||
nitpicker->enqueue<Command::Offset>(view_handle, offset);
|
||||
|
||||
nitpicker->execute();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void QNitpickerViewWidget::paintEvent(QPaintEvent *event)
|
||||
{
|
||||
QWidget::paintEvent(event);
|
||||
|
||||
if (!nitpicker)
|
||||
return;
|
||||
|
||||
QEmbeddedViewWidget::View_geometry const view_geometry =
|
||||
QEmbeddedViewWidget::_calc_view_geometry();
|
||||
|
||||
typedef Nitpicker::Session::Command Command;
|
||||
|
||||
/* argument to mapToGlobal() is relative to the Widget's origin
|
||||
* the plugin view starts at (0, 0)
|
||||
*/
|
||||
if (mask().isEmpty()) {
|
||||
// PDBG("x0 = %d, y0 = %d, w = %d, h = %d, buf_x = %d, buf_y = %d",
|
||||
// x0, y0, w, h, orig_buf_x + diff_x, orig_buf_y + diff_y);
|
||||
|
||||
Nitpicker::Rect geometry(Nitpicker::Point(x0, y0),
|
||||
Nitpicker::Area(w, h));
|
||||
Nitpicker::Rect const geometry(Nitpicker::Point(view_geometry.x,
|
||||
view_geometry.y),
|
||||
Nitpicker::Area(view_geometry.w,
|
||||
view_geometry.h));
|
||||
nitpicker->enqueue<Command::Geometry>(view_handle, geometry);
|
||||
Nitpicker::Point offset(orig_buf_x + diff_x, orig_buf_y + diff_y);
|
||||
Nitpicker::Point const offset(view_geometry.buf_x,
|
||||
view_geometry.buf_y);
|
||||
nitpicker->enqueue<Command::Offset>(view_handle, offset);
|
||||
} else {
|
||||
/* PDBG("x = %d, y = %d, w = %d, h = %d, buf_x = %d, buf_y = %d",
|
||||
mapToGlobal(mask().boundingRect().topLeft()).x(),
|
||||
mapToGlobal(mask().boundingRect().topLeft()).y(),
|
||||
mask().boundingRect().width(),
|
||||
mask().boundingRect().height(),
|
||||
orig_buf_x + diff_x, orig_buf_y + diff_y); */
|
||||
|
||||
Nitpicker::Rect const
|
||||
geometry(Nitpicker::Point(mapToGlobal(mask().boundingRect().topLeft()).x(),
|
||||
@ -265,7 +209,7 @@ void QNitpickerViewWidget::paintEvent(QPaintEvent *event)
|
||||
mask().boundingRect().height()));
|
||||
nitpicker->enqueue<Command::Geometry>(view_handle, geometry);
|
||||
|
||||
Nitpicker::Point offset(orig_buf_x + diff_x, orig_buf_y + diff_y);
|
||||
Nitpicker::Point const offset(view_geometry.buf_x, view_geometry.buf_y);
|
||||
nitpicker->enqueue<Command::Offset>(view_handle, offset);
|
||||
}
|
||||
|
||||
@ -273,7 +217,7 @@ void QNitpickerViewWidget::paintEvent(QPaintEvent *event)
|
||||
QNitpickerPlatformWindow *platform_window =
|
||||
dynamic_cast<QNitpickerPlatformWindow*>(window()->windowHandle()->handle());
|
||||
|
||||
Nitpicker::Session::View_handle neighbor_handle =
|
||||
Nitpicker::Session::View_handle const neighbor_handle =
|
||||
nitpicker->view_handle(platform_window->view_cap());
|
||||
|
||||
nitpicker->enqueue<Command::To_front>(view_handle, neighbor_handle);
|
||||
@ -281,53 +225,4 @@ void QNitpickerViewWidget::paintEvent(QPaintEvent *event)
|
||||
|
||||
nitpicker->release_view_handle(neighbor_handle);
|
||||
}
|
||||
#if 0
|
||||
void QNitpickerViewWidget::windowEvent(QWSWindow *window,
|
||||
QWSServer::WindowEvent eventType)
|
||||
{
|
||||
if (this->window()->windowSurface() && (window->winId() == static_cast<QWSWindowSurface*>(this->window()->windowSurface())->winId())) {
|
||||
|
||||
switch (eventType) {
|
||||
|
||||
/* the window has changed its geometry */
|
||||
case QWSServer::Geometry:
|
||||
{
|
||||
if (isVisible()) {
|
||||
QPaintEvent e(rect());
|
||||
paintEvent(&e);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case QWSServer::Raise:
|
||||
{
|
||||
if (vc) {
|
||||
try {
|
||||
vc->stack(Nitpicker::View_capability(), true, true);
|
||||
} catch (Genode::Ipc_error) {
|
||||
delete vc;
|
||||
vc = 0;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
void QNitpickerViewWidget::valueChanged()
|
||||
{
|
||||
// qDebug() << "valueChanged()";
|
||||
if (isVisible()) {
|
||||
QPaintEvent e(rect());
|
||||
paintEvent(&e);
|
||||
}
|
||||
}
|
||||
|
||||
void QNitpickerViewWidget::destroyed(QObject *obj)
|
||||
{
|
||||
_scrollbars.remove(qobject_cast<QScrollBar*>(obj));
|
||||
}
|
||||
|
@ -89,17 +89,17 @@ class Signal_wait_thread : public QThread
|
||||
PluginStarter::PluginStarter(QUrl plugin_url, QString &args,
|
||||
int max_width, int max_height,
|
||||
Nitpicker::View_capability parent_view)
|
||||
: _plugin_url(plugin_url),
|
||||
_args(args.toLatin1()),
|
||||
_max_width(max_width),
|
||||
_max_height(max_height),
|
||||
_parent_view(parent_view),
|
||||
_pc(0),
|
||||
_plugin_loading_state(LOADING),
|
||||
_qnam(0),
|
||||
_reply(0)
|
||||
{
|
||||
}
|
||||
:
|
||||
_plugin_url(plugin_url),
|
||||
_args(args.toLatin1()),
|
||||
_max_width(max_width),
|
||||
_max_height(max_height),
|
||||
_parent_view(parent_view),
|
||||
_pc(0),
|
||||
_plugin_loading_state(LOADING),
|
||||
_qnam(0),
|
||||
_reply(0)
|
||||
{ }
|
||||
|
||||
|
||||
void PluginStarter::_start_plugin(QString &file_name, QByteArray const &file_buf)
|
||||
@ -191,7 +191,7 @@ void PluginStarter::_start_plugin(QString &file_name, QByteArray const &file_buf
|
||||
Signal_receiver sig_rec;
|
||||
|
||||
_pc->view_ready_sigh(sig_rec.manage(&sig_ctx));
|
||||
_pc->constrain_geometry(_max_width, _max_height);
|
||||
_pc->constrain_geometry(Loader::Area(_max_width, _max_height));
|
||||
_pc->parent_view(_parent_view);
|
||||
_pc->start("init", "init");
|
||||
|
||||
@ -274,21 +274,27 @@ void PluginStarter::networkReplyFinished()
|
||||
}
|
||||
|
||||
|
||||
Nitpicker::View_capability PluginStarter::plugin_view(int *w, int *h, int *buf_x, int *buf_y)
|
||||
Loader::Area PluginStarter::view_size()
|
||||
{
|
||||
Loader::Session::View_geometry geometry = _pc->view_geometry();
|
||||
if (w) *w = geometry.width;
|
||||
if (h) *h = geometry.height;
|
||||
if (buf_x) *buf_x = geometry.buf_x;
|
||||
if (buf_y) *buf_y = geometry.buf_y;
|
||||
return _pc->view();
|
||||
return _pc ? _pc->view_size() : Loader::Area();
|
||||
}
|
||||
|
||||
|
||||
void PluginStarter::view_geometry(Loader::Rect rect, Loader::Point offset)
|
||||
{
|
||||
if (_pc)
|
||||
_pc->view_geometry(rect, offset);
|
||||
}
|
||||
|
||||
|
||||
/*******************
|
||||
** QPluginWidget **
|
||||
*******************/
|
||||
|
||||
QPluginWidget::QPluginWidget(QWidget *parent, QUrl plugin_url, QString &args,
|
||||
int max_width, int max_height)
|
||||
:
|
||||
QNitpickerViewWidget(parent),
|
||||
QEmbeddedViewWidget(parent),
|
||||
_plugin_loading_state(LOADING),
|
||||
_plugin_starter(0),
|
||||
_plugin_starter_started(false),
|
||||
@ -329,18 +335,46 @@ void QPluginWidget::cleanup()
|
||||
/* delete the QThread object */
|
||||
delete _plugin_starter;
|
||||
_plugin_starter = 0;
|
||||
delete vc;
|
||||
vc = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void QPluginWidget::paintEvent(QPaintEvent *event)
|
||||
{
|
||||
if (_plugin_loading_state == LOADED)
|
||||
QNitpickerViewWidget::paintEvent(event);
|
||||
else {
|
||||
QWidget::paintEvent(event);
|
||||
QWidget::paintEvent(event);
|
||||
|
||||
if (_plugin_loading_state == LOADED) {
|
||||
|
||||
QEmbeddedViewWidget::View_geometry const view_geometry =
|
||||
QEmbeddedViewWidget::_calc_view_geometry();
|
||||
|
||||
if (mask().isEmpty()) {
|
||||
|
||||
Loader::Rect const geometry(Loader::Point(view_geometry.x,
|
||||
view_geometry.y),
|
||||
Loader::Area(view_geometry.w,
|
||||
view_geometry.h));
|
||||
|
||||
Loader::Point const offset(view_geometry.buf_x,
|
||||
view_geometry.buf_y);
|
||||
|
||||
_plugin_starter->view_geometry(geometry, offset);
|
||||
|
||||
} else {
|
||||
|
||||
Loader::Rect const
|
||||
geometry(Loader::Point(mapToGlobal(mask().boundingRect().topLeft()).x(),
|
||||
mapToGlobal(mask().boundingRect().topLeft()).y()),
|
||||
Loader::Area(mask().boundingRect().width(),
|
||||
mask().boundingRect().height()));
|
||||
|
||||
Loader::Point const offset(view_geometry.buf_x, view_geometry.buf_y);
|
||||
|
||||
_plugin_starter->view_geometry(geometry, offset);
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
QPainter painter(this);
|
||||
painter.drawRect(0, 0, width() - 1, height() - 1);
|
||||
switch (_plugin_loading_state) {
|
||||
@ -391,7 +425,7 @@ void QPluginWidget::showEvent(QShowEvent *event)
|
||||
_plugin_starter_started = true;
|
||||
}
|
||||
|
||||
QNitpickerViewWidget::showEvent(event);
|
||||
QEmbeddedViewWidget::showEvent(event);
|
||||
}
|
||||
|
||||
|
||||
@ -400,15 +434,19 @@ void QPluginWidget::pluginStartFinished()
|
||||
_plugin_loading_state = _plugin_starter->plugin_loading_state();
|
||||
|
||||
if (_plugin_loading_state == LOADED) {
|
||||
Nitpicker::View_capability view = _plugin_starter->plugin_view(&orig_w, &orig_h, &orig_buf_x, &orig_buf_y);
|
||||
|
||||
vc = new Nitpicker::View_client(view);
|
||||
Loader::Area const size = _plugin_starter->view_size();
|
||||
|
||||
QEmbeddedViewWidget::_orig_geometry(size.w(), size.h(), 0, 0);
|
||||
|
||||
int w = (_max_width > -1) ? qMin(size.w(), (unsigned)_max_width) : size.w();
|
||||
int h = (_max_height > -1) ? qMin(size.h(), (unsigned)_max_height) : size.h();
|
||||
|
||||
setFixedSize(w, h);
|
||||
|
||||
setFixedSize((_max_width > -1) ? qMin(orig_w, _max_width) : orig_w,
|
||||
(_max_height > -1) ? qMin(orig_h, _max_height) : orig_h);
|
||||
} else {
|
||||
_plugin_loading_error_string = _plugin_starter->plugin_loading_error_string();
|
||||
setFixedSize((_max_width > -1) ? _max_width : 100,
|
||||
setFixedSize((_max_width > -1) ? _max_width : 100,
|
||||
(_max_height > -1) ? _max_height : 100);
|
||||
cleanup();
|
||||
}
|
||||
@ -416,3 +454,25 @@ void QPluginWidget::pluginStartFinished()
|
||||
update();
|
||||
}
|
||||
|
||||
|
||||
void QPluginWidget::hideEvent(QHideEvent *event)
|
||||
{
|
||||
QWidget::hideEvent(event);
|
||||
|
||||
if (_plugin_loading_state == LOADED) {
|
||||
|
||||
QEmbeddedViewWidget::View_geometry const view_geometry =
|
||||
QEmbeddedViewWidget::_calc_view_geometry();
|
||||
|
||||
typedef Nitpicker::Session::Command Command;
|
||||
|
||||
Loader::Rect geometry(Loader::Point(mapToGlobal(pos()).x(),
|
||||
mapToGlobal(pos()).y()),
|
||||
Loader::Area(0, 0));
|
||||
|
||||
Loader::Point offset(view_geometry.buf_x, view_geometry.buf_y);
|
||||
|
||||
_plugin_starter->view_geometry(geometry, offset);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user