Commit 852ae8d7 authored by Claes Sjofors's avatar Claes Sjofors

Merge branch 'master'

parents 29de8b16 70030222
......@@ -623,6 +623,7 @@ int FlowDrawQt::event_handler(QEvent* event, QWidget* target)
case QEvent::Paint:
case QEvent::UpdateRequest: {
QPaintEvent* paintEvent = ((QPaintEvent*)event);
basectx->clear();
sts = basectx->event_handler(flow_eEvent_Exposure, paintEvent->rect().x(),
paintEvent->rect().y(), paintEvent->rect().width(),
paintEvent->rect().height());
......
......@@ -71,6 +71,11 @@ void QtScrollWidgetFlow::init(unsigned int eCtxType,
this->scroll_timerid = new QTimer(this);
}
bool QtScrollWidgetFlow::eventFilter(QObject *object, QEvent *event)
{
return (event->type() == QEvent::KeyPress);
}
QWidget* QtScrollWidgetFlow::initScroll(unsigned int eCtxType,
int (*init_proc)(FlowCtx* ctx, void* client_data), void* client_data,
int (*init_proc2)(QWidget* w, FlowCtx* ctx, void* client_data))
......@@ -83,13 +88,22 @@ QWidget* QtScrollWidgetFlow::initScroll(unsigned int eCtxType,
this->init_widget_proc = init_proc2;
this->client_data = client_data;
this->scroll_timerid = new QTimer(this);
QScrollArea* form = new QScrollArea();
form = new QScrollArea();
form->installEventFilter(this);
scroll_h = form->horizontalScrollBar();
scroll_v = form->verticalScrollBar();
scroll_h->setTracking(false);
scroll_v->setTracking(false);
QObject::connect(
scroll_h, SIGNAL(sliderMoved(int)), this, SLOT(scroll_h_action(int)));
QObject::connect(
scroll_v, SIGNAL(sliderMoved(int)), this, SLOT(scroll_v_action(int)));
// These are needed to prevent QT from scrolling the ScrollArea.
QObject::connect(
scroll_h, SIGNAL(valueChanged(int)), this, SLOT(scroll_h_action(int)));
scroll_h, SIGNAL(valueChanged(int)), this, SLOT(scroll_h_released(int)));
QObject::connect(
scroll_v, SIGNAL(valueChanged(int)), this, SLOT(scroll_v_action(int)));
scroll_v, SIGNAL(valueChanged(int)), this, SLOT(scroll_v_released(int)));
form->setWidget(this);
form->setWidgetResizable(true);
......@@ -114,31 +128,28 @@ void QtScrollWidgetFlow::scroll_callback_cb()
scroll_timerid->stop();
if (data->total_width <= data->window_width) {
if (data->offset_x == 0) {
data->total_width = data->window_width;
}
if (data->offset_x == 0 && data->total_width <= data->window_width) {
data->total_width = data->window_width;
if (scroll_data->scroll_h_managed) {
// Remove horizontal scrollbar
form->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
}
} else {
if (!scroll_data->scroll_h_managed) {
// Insert horizontal scrollbar
if (scroll_data->scroll_h_managed) {
form->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
}
}
if (data->total_height <= data->window_height) {
if (data->offset_y == 0) {
data->total_height = data->window_height;
}
if (data->offset_y == 0 && data->total_height <= data->window_height) {
data->total_height = data->window_height;
if (scroll_data->scroll_v_managed) {
// Remove vertical scrollbar
form->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
}
} else {
if (!scroll_data->scroll_v_managed) {
// Insert vertical scrollbar
if (scroll_data->scroll_v_managed) {
form->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
}
}
if (data->offset_x < 0) {
data->total_width += -data->offset_x;
data->offset_x = 0;
......@@ -161,57 +172,51 @@ void QtScrollWidgetFlow::scroll_callback_cb()
}
if (scroll_data->scroll_h_managed) {
scroll_h_ignore = 1;
scroll_h_value = (double)data->offset_x;
scroll_h_pagesize = data->window_width;
scroll_h_upper = data->total_width;
if (data->window_width != scroll_h_pagesize
|| data->total_width != scroll_h_upper || scroll_configure) {
scroll_data->scroll_h->setMaximum(scroll_h_upper);
scroll_data->scroll_h->setPageStep(scroll_h_pagesize);
if (data->window_width != scroll_h->pageStep()
|| data->total_width != scroll_h->maximum() || scroll_configure) {
scroll_h->setMaximum(data->total_width - data->window_width);
scroll_h->setPageStep(data->window_width);
}
scroll_data->scroll_h->setSliderPosition(scroll_h_value);
scroll_h->setSliderPosition(data->offset_x);
}
if (scroll_data->scroll_v_managed) {
scroll_v_ignore = 1;
scroll_v_value = (double)data->offset_y;
scroll_v_pagesize = data->window_height;
scroll_v_upper = data->total_height;
if (data->window_height != scroll_v_pagesize
|| data->total_height != scroll_v_upper || scroll_configure) {
scroll_data->scroll_v->setMaximum(scroll_v_upper);
scroll_data->scroll_v->setPageStep(scroll_v_pagesize);
if (data->window_height != scroll_v->pageStep()
|| data->total_height != scroll_v->maximum() || scroll_configure) {
scroll_v->setMaximum(data->total_height - data->window_height);
scroll_v->setPageStep(data->window_height);
}
scroll_data->scroll_v->setSliderPosition(scroll_v_value);
scroll_v->setSliderPosition(data->offset_y);
}
scroll_configure = 0;
}
void QtScrollWidgetFlow::scroll_h_action(int value)
{
if (scroll_h_ignore) {
scroll_h_ignore = 0;
return;
}
scroll_h_value = value;
FlowCtx* ctx = (FlowCtx*)parent_ctx;
flow_scroll_horizontal(ctx, value, 0);
}
void QtScrollWidgetFlow::scroll_v_action(int value)
void QtScrollWidgetFlow::scroll_h_released(int value)
{
if (scroll_v_ignore) {
scroll_v_ignore = 0;
return;
}
// Prevent QT from scrolling the ScrollArea by setting the value to 0.
scroll_h->setValue(0);
scroll_h->setSliderPosition(value);
}
scroll_v_value = value;
void QtScrollWidgetFlow::scroll_v_action(int value)
{
FlowCtx* ctx = (FlowCtx*)parent_ctx;
flow_scroll_vertical(ctx, value, 0);
}
void QtScrollWidgetFlow::scroll_v_released(int value)
{
// Prevent QT from scrolling the ScrollArea by setting the value to 0.
scroll_v->setValue(0);
scroll_v->setSliderPosition(value);
}
void QtScrollWidgetFlow::paintEvent(QPaintEvent* event)
{
QPainter painter(this);
......
......@@ -69,6 +69,8 @@ public:
int (*init_proc2)(QWidget* w, FlowCtx* ctx, void* client_data));
void init(unsigned int eCtxType, QWidget* main);
bool eventFilter(QObject *object, QEvent *event);
void* parent_ctx;
FlowDrawQt* draw_ctx;
int (*init_proc)(FlowCtx* ctx, void* clien_data);
......@@ -78,18 +80,11 @@ public:
QWidget* main_widget;
QScrollBar* scroll_h;
QScrollBar* scroll_v;
int scroll_h_ignore;
int scroll_v_ignore;
double scroll_h_value;
double scroll_v_value;
int scroll_h_pagesize;
int scroll_v_pagesize;
int scroll_h_upper;
int scroll_v_upper;
QTimer* scroll_timerid;
flow_sScroll scroll_data;
int scroll_configure;
int destroyed;
QScrollArea* form;
QImage image;
......@@ -112,6 +107,8 @@ private:
public slots:
void scroll_h_action(int value);
void scroll_v_action(int value);
void scroll_h_released(int value);
void scroll_v_released(int value);
void scroll_callback_cb();
};
......
......@@ -690,6 +690,7 @@ int GlowDrawQt::event_handler(QEvent* event, QWidget* target)
case QEvent::Paint:
case QEvent::UpdateRequest: {
QPaintEvent* paintEvent = ((QPaintEvent*)event);
ctx->clear(&ctx->mw);
sts = ctx->event_handler(glow_eEvent_Exposure, paintEvent->rect().x(),
paintEvent->rect().y(), paintEvent->rect().width(),
paintEvent->rect().height());
......
......@@ -72,6 +72,11 @@ void QtScrollWidgetGlow::init(unsigned int eCtxType,
this->scroll_timerid = new QTimer(this);
}
bool QtScrollWidgetGlow::eventFilter(QObject *object, QEvent *event)
{
return (event->type() == QEvent::KeyPress);
}
QWidget* QtScrollWidgetGlow::initScroll(unsigned int eCtxType,
int (*init_proc)(GlowCtx* ctx, void* client_data), void* client_data,
int (*init_proc2)(QWidget* w, GlowCtx* ctx, void* client_data))
......@@ -84,14 +89,22 @@ QWidget* QtScrollWidgetGlow::initScroll(unsigned int eCtxType,
this->init_widget_proc = init_proc2;
this->client_data = client_data;
this->scroll_timerid = new QTimer(this);
QScrollArea* form = new QScrollArea();
form = new QScrollArea();
form->installEventFilter(this);
scroll_h = form->horizontalScrollBar();
scroll_v = form->verticalScrollBar();
scroll_h->setTracking(false);
scroll_v->setTracking(false);
QObject::connect(
scroll_h, SIGNAL(sliderMoved(int)), this, SLOT(scroll_h_action(int)));
QObject::connect(
scroll_v, SIGNAL(sliderMoved(int)), this, SLOT(scroll_v_action(int)));
// These are needed to prevent QT from scrolling the ScrollArea.
QObject::connect(
scroll_h, SIGNAL(valueChanged(int)), this, SLOT(scroll_h_action(int)));
scroll_h, SIGNAL(valueChanged(int)), this, SLOT(scroll_h_released(int)));
QObject::connect(
scroll_v, SIGNAL(valueChanged(int)), this, SLOT(scroll_v_action(int)));
scroll_v, SIGNAL(valueChanged(int)), this, SLOT(scroll_v_released(int)));
form->setWidget(this);
form->setWidgetResizable(true);
......@@ -116,31 +129,28 @@ void QtScrollWidgetGlow::scroll_callback_cb()
scroll_timerid->stop();
if (data->total_width <= data->window_width) {
if (data->offset_x == 0) {
data->total_width = data->window_width;
}
if (data->offset_x == 0 && data->total_width <= data->window_width) {
data->total_width = data->window_width;
if (scroll_data->scroll_h_managed) {
// Remove horizontal scrollbar
form->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
}
} else {
if (!scroll_data->scroll_h_managed) {
// Insert horizontal scrollbar
if (scroll_data->scroll_h_managed) {
form->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
}
}
if (data->total_height <= data->window_height) {
if (data->offset_y == 0) {
data->total_height = data->window_height;
}
if (data->offset_y == 0 && data->total_height <= data->window_height) {
data->total_height = data->window_height;
if (scroll_data->scroll_v_managed) {
// Remove vertical scrollbar
form->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
}
} else {
if (!scroll_data->scroll_v_managed) {
// Insert vertical scrollbar
if (scroll_data->scroll_v_managed) {
form->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
}
}
if (data->offset_x < 0) {
data->total_width += -data->offset_x;
data->offset_x = 0;
......@@ -163,57 +173,51 @@ void QtScrollWidgetGlow::scroll_callback_cb()
}
if (scroll_data->scroll_h_managed) {
scroll_h_ignore = 1;
scroll_h_value = (double)data->offset_x;
scroll_h_pagesize = data->window_width;
scroll_h_upper = data->total_width;
if (data->window_width != scroll_h_pagesize
|| data->total_width != scroll_h_upper || scroll_configure) {
scroll_data->scroll_h->setMaximum(scroll_h_upper);
scroll_data->scroll_h->setPageStep(scroll_h_pagesize);
if (data->window_width != scroll_h->pageStep()
|| data->total_width != scroll_h->maximum() || scroll_configure) {
scroll_h->setMaximum(data->total_width - data->window_width);
scroll_h->setPageStep(data->window_width);
}
scroll_data->scroll_h->setSliderPosition(scroll_h_value);
scroll_h->setSliderPosition(data->offset_x);
}
if (scroll_data->scroll_v_managed) {
scroll_v_ignore = 1;
scroll_v_value = (double)data->offset_y;
scroll_v_pagesize = data->window_height;
scroll_v_upper = data->total_height;
if (data->window_height != scroll_v_pagesize
|| data->total_height != scroll_v_upper || scroll_configure) {
scroll_data->scroll_v->setMaximum(scroll_v_upper);
scroll_data->scroll_v->setPageStep(scroll_v_pagesize);
if (data->window_height != scroll_v->pageStep()
|| data->total_height != scroll_v->maximum() || scroll_configure) {
scroll_v->setMaximum(data->total_height - data->window_height);
scroll_v->setPageStep(data->window_height);
}
scroll_data->scroll_v->setSliderPosition(scroll_v_value);
scroll_v->setSliderPosition(data->offset_y);
}
scroll_configure = 0;
}
void QtScrollWidgetGlow::scroll_h_action(int value)
{
if (scroll_h_ignore) {
scroll_h_ignore = 0;
return;
}
scroll_h_value = value;
GlowCtx* ctx = (GlowCtx*)parent_ctx;
glow_scroll_horizontal(ctx, value, 0);
}
void QtScrollWidgetGlow::scroll_v_action(int value)
void QtScrollWidgetGlow::scroll_h_released(int value)
{
if (scroll_v_ignore) {
scroll_v_ignore = 0;
return;
}
// Prevent QT from scrolling the ScrollArea by setting the value to 0.
scroll_h->setValue(0);
scroll_h->setSliderPosition(value);
}
scroll_v_value = value;
void QtScrollWidgetGlow::scroll_v_action(int value)
{
GlowCtx* ctx = (GlowCtx*)parent_ctx;
glow_scroll_vertical(ctx, value, 0);
}
void QtScrollWidgetGlow::scroll_v_released(int value)
{
// Prevent QT from scrolling the ScrollArea by setting the value to 0.
scroll_v->setValue(0);
scroll_v->setSliderPosition(value);
}
void QtScrollWidgetGlow::paintEvent(QPaintEvent* event)
{
QPainter painter(this);
......
......@@ -68,6 +68,8 @@ public:
int (*init_proc2)(QWidget* w, GlowCtx* ctx, void* client_data));
void init(unsigned int eCtxType, QWidget* main);
bool eventFilter(QObject *object, QEvent *event);
void* parent_ctx;
GlowDrawQt* draw_ctx;
int (*init_proc)(GlowCtx* ctx, void* clien_data);
......@@ -77,18 +79,11 @@ public:
QWidget* main_widget;
QScrollBar* scroll_h;
QScrollBar* scroll_v;
int scroll_h_ignore;
int scroll_v_ignore;
double scroll_h_value;
double scroll_v_value;
int scroll_h_pagesize;
int scroll_v_pagesize;
int scroll_h_upper;
int scroll_v_upper;
QTimer* scroll_timerid;
glow_sScroll scroll_data;
int scroll_configure;
int destroyed;
QScrollArea* form;
QImage image;
......@@ -111,6 +106,8 @@ private:
public slots:
void scroll_h_action(int value);
void scroll_v_action(int value);
void scroll_h_released(int value);
void scroll_v_released(int value);
void scroll_callback_cb();
signals:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment