Commit 17941b95 authored by Christoffer Ackelman's avatar Christoffer Ackelman

QT: Fixed annoyance with double buffering

parent 62ee6b21
......@@ -295,6 +295,7 @@ void set_pane_position(QSplitter* pane, int right)
if (right > 0) {
sizes << right << total - right;
} else {
right = -right;
sizes << total - right << right;
}
pane->setSizes(sizes);
......
......@@ -94,6 +94,7 @@ static char font_names[draw_eFont__][DRAW_FONT_SIZE][80]
"-*-Helvetica-Medium-R-Normal--24-*-*-*-P-*-ISO8859-1" } };
static QMouseEvent* last_event;
static QWidget* last_target;
static QColor flow_allocate_color(
FlowDrawQt* draw_ctx, const char* named_color);
......@@ -293,7 +294,7 @@ int FlowDrawQt::init_nav(QWidget* nav_widget, void* flow_ctx)
return 1;
}
int FlowDrawQt::event_handler(QEvent* event)
int FlowDrawQt::event_handler(QEvent* event, QWidget* target)
{
static int button_pressed = 0;
static int button_clicked = 0;
......@@ -309,24 +310,7 @@ int FlowDrawQt::event_handler(QEvent* event)
return 1;
}
QObject* windowParent = window;
QObject* navWindowParent = nav_window;
bool windowEvent = false;
bool navWindowEvent = false;
if (QApplication::focusWidget() != NULL) {
while (!(windowParent == NULL && navWindowParent == NULL)) {
windowEvent = (QApplication::focusWidget() == windowParent);
navWindowEvent = (QApplication::focusWidget() == navWindowParent);
if (windowEvent || navWindowEvent) {
break;
}
windowParent = (windowParent == NULL) ? NULL : windowParent->parent();
navWindowParent
= (navWindowParent == NULL) ? NULL : navWindowParent->parent();
}
}
if (windowEvent || event->type() == QEvent::KeyPress) {
if (target == window || event->type() == QEvent::KeyPress) {
switch (event->type()) {
case QEvent::KeyPress: {
QKeyEvent* keyEvent = ((QKeyEvent*)event);
......@@ -462,14 +446,14 @@ int FlowDrawQt::event_handler(QEvent* event)
button_pressed = mouseEvent->button();
last_press_x = mouseEvent->x();
last_press_y = mouseEvent->y();
event_timer(mouseEvent);
event_timer(mouseEvent, target);
return 1;
}
if (!button_pressed) {
button_pressed = mouseEvent->button();
last_press_x = mouseEvent->x();
last_press_y = mouseEvent->y();
event_timer(mouseEvent);
event_timer(mouseEvent, target);
return 1;
} else {
// debug_print("event_handler: MouseButtonPress from timer\n");
......@@ -599,7 +583,7 @@ int FlowDrawQt::event_handler(QEvent* event)
if (!button_clicked_and_pressed) {
/* wait for button double click */
button_clicked = 1;
event_timer(mouseEvent);
event_timer(mouseEvent, target);
button_pressed = 0;
return 1;
} else {
......@@ -787,7 +771,7 @@ int FlowDrawQt::event_handler(QEvent* event)
default:
break;
}
} else if (navWindowEvent) {
} else if (target == nav_window) {
switch (event->type()) {
case QEvent::MouseButtonPress: {
QMouseEvent* mouseEvent = ((QMouseEvent*)event);
......@@ -1622,7 +1606,7 @@ bool FlowDrawQt::draw_timer_cb()
bool FlowDrawQt::event_timer_cb()
{
timer_id->stop();
event_handler(last_event);
event_handler(last_event, last_target);
return FALSE;
}
......@@ -1633,13 +1617,14 @@ void FlowDrawQt::cancel_event_timer()
}
}
void FlowDrawQt::event_timer(QMouseEvent* event)
void FlowDrawQt::event_timer(QMouseEvent* event, QWidget *target)
{
if (last_event) {
delete last_event;
}
last_event = new QMouseEvent(event->type(), event->pos(), event->globalPos(),
event->button(), event->buttons(), event->modifiers());
last_target = target;
initOneShotTimer(timer_id, SLOT(event_timer_cb()), 200);
}
......
......@@ -72,7 +72,7 @@ public:
int init_nav(QWidget* nav_widget, void* flow_ctx);
int event_handler(QEvent* event);
int event_handler(QEvent* event, QWidget *target);
void enable_event(FlowCtx* ctx, flow_eEvent event, flow_eEventType event_type,
int (*event_cb)(FlowCtx* ctx, flow_tEvent event));
......@@ -255,7 +255,7 @@ private:
int x, int y, char* text, int len);
void cursor_helper(FlowCtx* ctx, draw_eCursor cursor, bool nav = false);
void event_timer(QMouseEvent *event);
void event_timer(QMouseEvent *event, QWidget *target);
void cancel_event_timer();
flow_draw_sTimerCb* timer_cb;
......
......@@ -246,7 +246,7 @@ void QtScrollWidgetFlow::handleEvent(QEvent* event)
if (event->type() == QEvent::MouseMove) {
drawer->window->update();
}
drawer->event_handler(event);
drawer->event_handler(event, this);
}
}
}
......
......@@ -142,6 +142,7 @@ static char font_names[glow_eFont__][glow_eDrawFont__][DRAW_FONT_SIZE][80] = {
};
static QMouseEvent* last_event;
static QWidget* last_target;
static QColor glow_allocate_named_color(
GlowDrawQt* draw_ctx, const char* named_color);
......@@ -369,7 +370,7 @@ GlowDrawQt::GlowDrawQt(QWidget* toplevel, void** glow_ctx,
init_proc(toplevel, ctx, client_data);
}
int GlowDrawQt::event_handler(QEvent* event)
int GlowDrawQt::event_handler(QEvent* event, QWidget* target)
{
static int button_pressed = 0;
static int button_clicked = 0;
......@@ -385,24 +386,7 @@ int GlowDrawQt::event_handler(QEvent* event)
return 1;
}
QObject* windowParent = m_wind->window;
QObject* navWindowParent = nav_wind->window;
bool windowEvent = false;
bool navWindowEvent = false;
if (QApplication::focusWidget() != NULL) {
while (!(windowParent == NULL && navWindowParent == NULL)) {
windowEvent = (QApplication::focusWidget() == windowParent);
navWindowEvent = (QApplication::focusWidget() == navWindowParent);
if (windowEvent || navWindowEvent) {
break;
}
windowParent = (windowParent == NULL) ? NULL : windowParent->parent();
navWindowParent
= (navWindowParent == NULL) ? NULL : navWindowParent->parent();
}
}
if (windowEvent || event->type() == QEvent::KeyPress) {
if (target == m_wind->window || event->type() == QEvent::KeyPress) {
if (GlowCtx::eventlog_enabled) {
log_event(event);
}
......@@ -533,14 +517,14 @@ int GlowDrawQt::event_handler(QEvent* event)
button_pressed = mouseEvent->button();
last_press_x = mouseEvent->x();
last_press_y = mouseEvent->y();
event_timer(mouseEvent);
event_timer(mouseEvent, target);
return 1;
}
if (!button_pressed) {
button_pressed = mouseEvent->button();
last_press_x = mouseEvent->x();
last_press_y = mouseEvent->y();
event_timer(mouseEvent);
event_timer(mouseEvent, target);
return 1;
} else {
/* Press event, callback from timer */
......@@ -687,7 +671,7 @@ int GlowDrawQt::event_handler(QEvent* event)
if (!button_clicked_and_pressed) {
/* wait for button double click */
button_clicked = 1;
event_timer(mouseEvent);
event_timer(mouseEvent, target);
button_pressed = 0;
return 1;
} else {
......@@ -879,7 +863,7 @@ int GlowDrawQt::event_handler(QEvent* event)
default:
break;
}
} else if (navWindowEvent) {
} else if (target == nav_wind->window) {
switch (event->type()) {
case QEvent::MouseButtonPress: {
QMouseEvent* mouseEvent = ((QMouseEvent*)event);
......@@ -1602,7 +1586,7 @@ bool GlowDrawQt::draw_timer_cb()
bool GlowDrawQt::event_timer_cb()
{
timer_id->stop();
event_handler(last_event);
event_handler(last_event, last_target);
return FALSE;
}
......@@ -1611,13 +1595,14 @@ void GlowDrawQt::cancel_event_timer()
timer_id->stop();
}
void GlowDrawQt::event_timer(QMouseEvent* event)
void GlowDrawQt::event_timer(QMouseEvent* event, QWidget *target)
{
if (last_event) {
delete last_event;
}
last_event = new QMouseEvent(event->type(), event->pos(), event->globalPos(),
event->button(), event->buttons(), event->modifiers());
last_target = target;
initOneShotTimer(timer_id, SLOT(event_timer_cb()), 200);
}
......@@ -3416,7 +3401,7 @@ void GlowDrawQt::event_exec(void* event, unsigned int size)
default:;
}
event_handler(&e);
event_handler(&e, m_wind->window);
}
int GlowDrawQt::open_color_selection(double* r, double* g, double* b)
......
......@@ -101,7 +101,7 @@ public:
int closing_down;
std::stack<GlowCustomColors> customcolors;
int event_handler(QEvent* event);
int event_handler(QEvent* event, QWidget *target);
virtual void enable_event(glow_eEvent event, glow_eEventType event_type,
int (*event_cb)(GlowCtx* ctx, glow_tEvent event));
virtual void clear(GlowWind* w);
......@@ -271,7 +271,7 @@ private:
int image_helper(GlowWind* wind, int x, int y, int width, int height,
glow_tImImage image, glow_tPixmap clip_mask, bool d = false);
void event_timer(QMouseEvent *event);
void event_timer(QMouseEvent *event, QWidget *target);
void cancel_event_timer();
glow_draw_sTimerCb* timer_cb;
......
......@@ -251,7 +251,7 @@ void QtScrollWidgetGlow::handleEvent(QEvent* event)
if (event->type() == QEvent::MouseMove) {
drawer->m_wind->window->update();
}
drawer->event_handler(event);
drawer->event_handler(event, this);
}
}
}
......
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