Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
proview
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Esteban Blanc
proview
Commits
6584106c
Commit
6584106c
authored
Jun 29, 2018
by
Christoffer Ackelman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed event handling when using QScrollArea
parent
5dcb0632
Changes
6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
242 additions
and
159 deletions
+242
-159
xtt/lib/flow/qt/flow_draw_qt.cqt
xtt/lib/flow/qt/flow_draw_qt.cqt
+99
-35
xtt/lib/flow/qt/flow_scroll_widget_qt.cqt
xtt/lib/flow/qt/flow_scroll_widget_qt.cqt
+44
-48
xtt/lib/flow/qt/flow_scroll_widget_qt.h
xtt/lib/flow/qt/flow_scroll_widget_qt.h
+14
-9
xtt/lib/glow/qt/glow_draw_qt.cqt
xtt/lib/glow/qt/glow_draw_qt.cqt
+26
-7
xtt/lib/glow/qt/glow_scroll_widget_qt.cqt
xtt/lib/glow/qt/glow_scroll_widget_qt.cqt
+45
-51
xtt/lib/glow/qt/glow_scroll_widget_qt.h
xtt/lib/glow/qt/glow_scroll_widget_qt.h
+14
-9
No files found.
xtt/lib/flow/qt/flow_draw_qt.cqt
View file @
6584106c
This diff is collapsed.
Click to expand it.
xtt/lib/flow/qt/flow_scroll_widget_qt.cqt
View file @
6584106c
...
...
@@ -42,16 +42,24 @@
#include <assert.h>
#include <QMainWindow>
#include <QPainter>
#include <QScrollArea>
#include "cow_qt_helpers.h"
QImage QtScrollWidgetFlow::createBuffer(QSize size)
{
QImage image = QImage(size, QImage::Format_RGB32);
QPainter imPainter(&image);
imPainter.fillRect(image.rect(), palette().color(QPalette::Background));
return image;
}
void QtScrollWidgetFlow::init(
unsigned int eCtxType, int (*init_proc)(FlowCtx *ctx, void *client_data),
void *client_data, int (*init_proc2)(QWidget *w, FlowCtx *ctx,
void *client_data))
{
this->image =
QImage(size(), QImage::Format_RGB32
);
this->image =
createBuffer(size()
);
this->ctxType = eCtxType;
this->init_proc = init_proc;
this->init_widget_proc = init_proc2;
...
...
@@ -63,15 +71,13 @@ QWidget *QtScrollWidgetFlow::initScroll(
void *client_data, int (*init_proc2)(QWidget *w, FlowCtx *ctx,
void *client_data))
{
this->image =
QImage(size(), QImage::Format_RGB32
);
this->image =
createBuffer(size()
);
this->ctxType = eCtxType;
this->init_proc = init_proc;
this->init_widget_proc = init_proc2;
this->client_data = client_data;
QMainWindow *window = new QMainWindow();
window->setAttribute(Qt::WA_DeleteOnClose);
QScrollArea *form = new QScrollArea();
QScrollAreaFlow *form = new QScrollAreaFlow();
scroll_h = form->horizontalScrollBar();
scroll_v = form->verticalScrollBar();
QObject::connect(scroll_h, SIGNAL(valueChanged(int)), this,
...
...
@@ -79,15 +85,21 @@ QWidget *QtScrollWidgetFlow::initScroll(
QObject::connect(scroll_v, SIGNAL(valueChanged(int)), this,
SLOT(scroll_v_action(int)));
form->setWidgetResizable(true);
form->setWidget(this);
window->setCentralWidget(form);
return window;
form->setWidgetResizable(true);
return form;
}
bool QScrollAreaFlow::event(QEvent *event)
{
QtScrollWidgetFlow *child = ((QtScrollWidgetFlow *) widget());
child->handleEvent(event);
return QScrollArea::event(event);
}
void QtScrollWidgetFlow::init(unsigned int eCtxType, QWidget *main)
{
this->image =
QImage(size(), QImage::Format_RGB32
);
this->image =
createBuffer(size()
);
this->ctxType = eCtxType;
is_navigator = 1;
main_widget = main;
...
...
@@ -200,37 +212,12 @@ void QtScrollWidgetFlow::scroll_v_action(int value)
void QtScrollWidgetFlow::paintEvent(QPaintEvent *event)
{
handleEvent(event);
QWidget::paintEvent(event);
QPainter painter(this);
QRect dirtyRect = event->rect();
painter.drawImage(dirtyRect, image, dirtyRect);
}
void QtScrollWidgetFlow::mouseMoveEvent(QMouseEvent *event)
{
handleEvent(event, false, true);
QWidget::mouseMoveEvent(event);
}
void QtScrollWidgetFlow::moveEvent(QMoveEvent *event)
{
handleEvent(event, true);
QWidget::moveEvent(event);
}
void QtScrollWidgetFlow::resizeEvent(QResizeEvent *event)
{
this->image = QImage(event->size(), QImage::Format_RGB32);
realize();
handleEvent(event, true);
QWidget::resizeEvent(event);
}
void QtScrollWidgetFlow::showEvent(QShowEvent *event)
{
realize();
QWidget::showEvent(event);
QPainter imPainter(&image);
imPainter.fillRect(image.rect(), palette().color(QPalette::Background));
QWidget::paintEvent(event);
}
void QtScrollWidgetFlow::closeEvent(QCloseEvent *event)
...
...
@@ -249,17 +236,16 @@ void QtScrollWidgetFlow::closeEvent(QCloseEvent *event)
QWidget::closeEvent(event);
}
void QtScrollWidgetFlow::handleEvent(QEvent *event, bool conf_scroll,
bool update)
void QtScrollWidgetFlow::handleEvent(QEvent *event)
{
if (!destroyed) {
if (
conf_scroll
) {
if (
event->type() == QEvent::Resize || event->type() == QEvent::Move
) {
scroll_configure = 1;
}
if (parent_ctx) {
FlowCtx * ctx = (FlowCtx *) parent_ctx;
FlowDrawQt *drawer = ((FlowDrawQt *) ctx->fdraw);
if (
updat
e) {
if (
event->type() == QEvent::MouseMov
e) {
drawer->window->update();
}
drawer->event_handler(event);
...
...
@@ -267,11 +253,22 @@ void QtScrollWidgetFlow::handleEvent(QEvent *event, bool conf_scroll,
}
}
void QtScrollWidgetFlow::realize(
)
bool QtScrollWidgetFlow::event(QEvent *event
)
{
if (is_realized) {
return;
if (event->type() == QEvent::Resize) {
this->image = createBuffer(((QResizeEvent *) event)->size());
}
if (!is_realized && (event->type() == QEvent::Show || event->type() == QEvent::Resize)) {
realize();
is_realized = true;
}
handleEvent(event);
return QWidget::event(event);
}
void QtScrollWidgetFlow::realize()
{
debug_print("realize\n");
if (!parent_ctx) {
if (is_navigator) {
...
...
@@ -280,6 +277,7 @@ void QtScrollWidgetFlow::realize()
if (main && !main->is_realized) {
main->realize();
main->is_realized = true;
}
assert(main->parent_ctx != NULL);
...
...
@@ -294,6 +292,4 @@ void QtScrollWidgetFlow::realize()
static_cast<flow_eCtxType>(ctxType));
}
}
is_realized = true;
}
\ No newline at end of file
xtt/lib/flow/qt/flow_scroll_widget_qt.h
View file @
6584106c
...
...
@@ -45,11 +45,9 @@
#include "flow_ctx.h"
#include "flow_draw_qt.h"
#include <QMouseEvent>
#include <QMoveEvent>
#include <QPaintEvent>
#include <QResizeEvent>
#include <QScrollBar>
#include <QScrollArea>
#include <QWidget>
typedef
struct
{
...
...
@@ -61,6 +59,13 @@ typedef struct {
int
scroll_v_managed
;
}
widget_sScroll
;
// QScrollArea does not forward events to its child widget
// So we subclass QScrollArea and override the event() handler
class
QScrollAreaFlow
:
public
QScrollArea
{
protected:
bool
event
(
QEvent
*
event
);
};
class
QtScrollWidgetFlow
:
public
QWidget
{
Q_OBJECT
...
...
@@ -100,22 +105,22 @@ public:
QImage
image
;
virtual
void
handleEvent
(
QEvent
*
event
);
protected:
virtual
void
realize
();
virtual
void
handleEvent
(
QEvent
*
event
,
bool
conf_scroll
=
false
,
bool
update
=
false
);
void
paintEvent
(
QPaintEvent
*
event
);
void
mouseMoveEvent
(
QMouseEvent
*
event
);
void
moveEvent
(
QMoveEvent
*
event
);
void
resizeEvent
(
QResizeEvent
*
event
);
void
closeEvent
(
QCloseEvent
*
event
);
void
showEvent
(
QShow
Event
*
event
);
bool
event
(
Q
Event
*
event
);
bool
is_realized
;
unsigned
int
ctxType
;
private:
QImage
createBuffer
(
QSize
size
);
public
slots
:
void
scroll_h_action
(
int
value
);
void
scroll_v_action
(
int
value
);
...
...
xtt/lib/glow/qt/glow_draw_qt.cqt
View file @
6584106c
...
...
@@ -340,8 +340,29 @@ int GlowDrawQt::event_handler(QEvent *event)
return 1;
}
if (QApplication::focusWidget() == m_wind->window->window() ||
event->type() == QEvent::KeyPress) {
QObject *parent = m_wind->window;
bool windowEvent = false;
while (parent != NULL) {
if (QApplication::focusWidget() == parent) {
windowEvent = true;
break;
}
parent = parent->parent();
}
bool navWindowEvent = false;
if (!windowEvent) {
parent = nav_wind->window;
while (parent != NULL) {
if (QApplication::focusWidget() == parent) {
navWindowEvent = true;
break;
}
parent = parent->parent();
}
}
if (windowEvent || event->type() == QEvent::KeyPress) {
if (GlowCtx::eventlog_enabled) {
log_event(event);
}
...
...
@@ -852,7 +873,7 @@ int GlowDrawQt::event_handler(QEvent *event)
default:
break;
}
} else if (
QApplication::focusWidget() == nav_wind->window
) {
} else if (
navWindowEvent
) {
switch (event->type()) {
case QEvent::MouseButtonPress: {
QMouseEvent *mouseEvent = ((QMouseEvent *) event);
...
...
@@ -1834,10 +1855,8 @@ void GlowDrawQt::set_clip(DrawWind *wind, QPainter *painter)
void GlowDrawQt::set_image_clip_mask(QPainter *painter, glow_tPixmap pixmap,
int x, int y)
{
QBitmap mask = QBitmap(*((QPixmap *) pixmap));
QRegion clipRegion = QRegion(mask);
clipRegion.translate(x, y);
painter->setClipRegion(clipRegion);
QRegion clipRegion = QRegion(((QPixmap *) pixmap)->createMaskFromColor(Qt::black));
painter->setClipRegion(clipRegion.translated(x, y));
painter->setClipping(true);
}
...
...
xtt/lib/glow/qt/glow_scroll_widget_qt.cqt
View file @
6584106c
...
...
@@ -40,16 +40,26 @@
*/
#include "glow_scroll_widget_qt.h"
#include <QMainWindow>
#include <assert.h>
#include <QPainter>
#include <QScrollArea>
#include "cow_qt_helpers.h"
QImage QtScrollWidgetGlow::createBuffer(QSize size)
{
QImage image = QImage(size, QImage::Format_RGB32);
QPainter imPainter(&image);
imPainter.fillRect(image.rect(), palette().color(QPalette::Background));
return image;
}
void QtScrollWidgetGlow::init(
unsigned int eCtxType, int (*init_proc)(GlowCtx *ctx, void *client_data),
void *client_data, int (*init_proc2)(QWidget *w, GlowCtx *ctx,
void *client_data))
{
this->image =
QImage(size(), QImage::Format_RGB32
);
this->image =
createBuffer(size()
);
this->ctxType = eCtxType;
this->init_proc = init_proc;
this->init_widget_proc = init_proc2;
...
...
@@ -61,15 +71,13 @@ QWidget *QtScrollWidgetGlow::initScroll(
void *client_data, int (*init_proc2)(QWidget *w, GlowCtx *ctx,
void *client_data))
{
this->image =
QImage(size(), QImage::Format_RGB32
);
this->image =
createBuffer(size()
);
this->ctxType = eCtxType;
this->init_proc = init_proc;
this->init_widget_proc = init_proc2;
this->client_data = client_data;
QMainWindow *window = new QMainWindow();
window->setAttribute(Qt::WA_DeleteOnClose);
QScrollArea *form = new QScrollArea();
QScrollAreaGlow *form = new QScrollAreaGlow();
scroll_h = form->horizontalScrollBar();
scroll_v = form->verticalScrollBar();
QObject::connect(scroll_h, SIGNAL(valueChanged(int)), this,
...
...
@@ -77,15 +85,21 @@ QWidget *QtScrollWidgetGlow::initScroll(
QObject::connect(scroll_v, SIGNAL(valueChanged(int)), this,
SLOT(scroll_v_action(int)));
form->setWidgetResizable(true);
form->setWidget(this);
window->setCentralWidget(form);
return window;
form->setWidgetResizable(true);
return form;
}
bool QScrollAreaGlow::event(QEvent *event)
{
QtScrollWidgetGlow *child = ((QtScrollWidgetGlow *) widget());
child->handleEvent(event);
return QScrollArea::event(event);
}
void QtScrollWidgetGlow::init(unsigned int eCtxType, QWidget *main)
{
this->image =
QImage(size(), QImage::Format_RGB32
);
this->image =
createBuffer(size()
);
this->ctxType = eCtxType;
is_navigator = 1;
main_widget = main;
...
...
@@ -198,39 +212,12 @@ void QtScrollWidgetGlow::scroll_v_action(int value)
void QtScrollWidgetGlow::paintEvent(QPaintEvent *event)
{
handleEvent(event);
QWidget::paintEvent(event);
QPainter painter(this);
QRect dirtyRect = event->rect();
painter.drawImage(dirtyRect, image, dirtyRect);
}
void QtScrollWidgetGlow::mouseMoveEvent(
QMouseEvent *event)
{
handleEvent(event, false, true);
QWidget::mouseMoveEvent(event);
}
void QtScrollWidgetGlow::moveEvent(QMoveEvent *event)
{
handleEvent(event, true);
QWidget::moveEvent(event);
}
void QtScrollWidgetGlow::resizeEvent(
QResizeEvent *event)
{
this->image = QImage(event->size(), QImage::Format_RGB32);
realize();
handleEvent(event, true);
QWidget::resizeEvent(event);
}
void QtScrollWidgetGlow::showEvent(QShowEvent *event)
{
realize();
QWidget::showEvent(event);
QPainter imPainter(&image);
imPainter.fillRect(image.rect(), palette().color(QPalette::Background));
QWidget::paintEvent(event);
}
void QtScrollWidgetGlow::closeEvent(QCloseEvent *event)
...
...
@@ -249,17 +236,16 @@ void QtScrollWidgetGlow::closeEvent(QCloseEvent *event)
QWidget::closeEvent(event);
}
void QtScrollWidgetGlow::handleEvent(QEvent *event, bool conf_scroll,
bool update)
void QtScrollWidgetGlow::handleEvent(QEvent *event)
{
if (!destroyed) {
if (
conf_scroll
) {
if (
event->type() == QEvent::Resize || event->type() == QEvent::Move
) {
scroll_configure = 1;
}
if (parent_ctx) {
GlowCtx *ctx = (GlowCtx *) parent_ctx;
GlowDrawQt *drawer = ((GlowDrawQt *) ctx->gdraw);
if (
updat
e) {
if (
event->type() == QEvent::MouseMov
e) {
drawer->m_wind->window->update();
}
drawer->event_handler(event);
...
...
@@ -267,13 +253,22 @@ void QtScrollWidgetGlow::handleEvent(QEvent *event, bool conf_scroll,
}
}
#include <assert.h>
bool QtScrollWidgetGlow::event(QEvent *event)
{
if (event->type() == QEvent::Resize) {
this->image = createBuffer(((QResizeEvent *) event)->size());
}
if (!is_realized && (event->type() == QEvent::Show || event->type() == QEvent::Resize)) {
realize();
is_realized = true;
}
handleEvent(event);
return QWidget::event(event);
}
void QtScrollWidgetGlow::realize()
{
if (is_realized) {
return;
}
debug_print("realize\n");
if (!parent_ctx) {
if (is_navigator) {
...
...
@@ -282,6 +277,7 @@ void QtScrollWidgetGlow::realize()
if (main && !main->is_realized) {
main->realize();
main->is_realized = true;
}
assert(main->parent_ctx != NULL);
...
...
@@ -296,6 +292,4 @@ void QtScrollWidgetGlow::realize()
static_cast<glow_eCtxType>(ctxType));
}
}
is_realized = true;
}
\ No newline at end of file
xtt/lib/glow/qt/glow_scroll_widget_qt.h
View file @
6584106c
...
...
@@ -45,11 +45,9 @@
#include "glow_ctx.h"
#include "glow_draw_qt.h"
#include <QMouseEvent>
#include <QMoveEvent>
#include <QPaintEvent>
#include <QResizeEvent>
#include <QScrollBar>
#include <QScrollArea>
#include <QWidget>
typedef
struct
{
...
...
@@ -61,6 +59,13 @@ typedef struct {
int
scroll_v_managed
;
}
widget_sScroll
;
// QScrollArea does not forward events to its child widget
// So we subclass QScrollArea and override the event() handler
class
QScrollAreaGlow
:
public
QScrollArea
{
protected:
bool
event
(
QEvent
*
event
);
};
class
QtScrollWidgetGlow
:
public
QWidget
{
Q_OBJECT
...
...
@@ -100,22 +105,22 @@ public:
QImage
image
;
virtual
void
handleEvent
(
QEvent
*
event
);
protected:
virtual
void
realize
();
virtual
void
handleEvent
(
QEvent
*
event
,
bool
conf_scroll
=
false
,
bool
update
=
false
);
void
paintEvent
(
QPaintEvent
*
event
);
void
mouseMoveEvent
(
QMouseEvent
*
event
);
void
moveEvent
(
QMoveEvent
*
event
);
void
resizeEvent
(
QResizeEvent
*
event
);
void
closeEvent
(
QCloseEvent
*
event
);
void
showEvent
(
QShow
Event
*
event
);
bool
event
(
Q
Event
*
event
);
bool
is_realized
;
unsigned
int
ctxType
;
private:
QImage
createBuffer
(
QSize
size
);
public
slots
:
void
scroll_h_action
(
int
value
);
void
scroll_v_action
(
int
value
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment