[brlcad-commits] SF.net SVN: brlcad:[57795] brlcad/trunk/src/libdm/dm-qt.cpp
Open Source Solid Modeling CAD
Brought to you by:
brlcad
From: <vla...@us...> - 2013-09-21 19:59:09
|
Revision: 57795 http://sourceforge.net/p/brlcad/code/57795 Author: vladbogo Date: 2013-09-21 19:59:07 +0000 (Sat, 21 Sep 2013) Log Message: ----------- Added new events + comments and small fixes Modified Paths: -------------- brlcad/trunk/src/libdm/dm-qt.cpp Modified: brlcad/trunk/src/libdm/dm-qt.cpp =================================================================== --- brlcad/trunk/src/libdm/dm-qt.cpp 2013-09-21 13:37:32 UTC (rev 57794) +++ brlcad/trunk/src/libdm/dm-qt.cpp 2013-09-21 19:59:07 UTC (rev 57795) @@ -40,7 +40,13 @@ #include "dm.h" #include "dm_xvars.h" +#define DM_QT_DEFAULT_POINT_SIZE 1.0 + +/* token used to cancel previous scheduled function using Tcl_CreateTimerHandler */ +Tcl_TimerToken token = NULL; + + HIDDEN bool qt_sendRepaintEvent(struct dm *dmp) { @@ -67,7 +73,7 @@ delete privars->font; delete privars->painter; delete privars->pix; - privars->win->~QTkMainWindow(); + delete privars->win; delete privars->parent; privars->qapp->quit(); @@ -80,6 +86,7 @@ bu_free((genptr_t)dmp->dm_vars.pub_vars, "qt_close: dm_xvars"); bu_free((genptr_t)dmp, "qt_close: dmp"); + bu_log("close called"); return TCL_OK; } @@ -284,6 +291,7 @@ fastf_t delta; point_t *pt_prev = NULL; fastf_t dist_prev=1.0; + fastf_t pointSize = DM_QT_DEFAULT_POINT_SIZE; struct qt_vars *privars = (struct qt_vars *)dmp->dm_vars.priv_vars; if (dmp->dm_debugLevel) { @@ -430,7 +438,48 @@ } break; case BN_VLIST_POINT_DRAW: + if (dmp->dm_debugLevel > 2) { + bu_log("before transformation:\n"); + bu_log("pt - %lf %lf %lf\n", V3ARGS(*pt)); + } + + if (dmp->dm_perspective > 0) { + dist = VDOT(*pt, &privars->qmat[12]) + privars->qmat[15]; + + if (dist <= 0.0) { + /* nothing to plot - point is behind eye plane */ + continue; + } + } + + MAT4X3PNT(pnt, privars->qmat, *pt); + + pnt[0] *= 2047; + pnt[1] *= 2047 * dmp->dm_aspect; + pnt[2] *= 2047; + + if (dmp->dm_debugLevel > 2) { + bu_log("after clipping:\n"); + bu_log("pt - %lf %lf %lf\n", pnt[X], pnt[Y], pnt[Z]); + } + + if (pointSize <= DM_QT_DEFAULT_POINT_SIZE) { + privars->painter->drawPoint(GED_TO_Xx(dmp, pnt[0]), GED_TO_Xy(dmp, pnt[1])); + } else { + int upperLeft[2]; + + upperLeft[X] = GED_TO_Xx(dmp, pnt[0]) - pointSize / 2.0; + upperLeft[Y] = GED_TO_Xy(dmp, pnt[1]) - pointSize / 2.0; + + privars->painter->drawRect(upperLeft[X], upperLeft[Y], pointSize, pointSize); + } break; + case BN_VLIST_POINT_SIZE: + pointSize = (*pt)[0]; + if (pointSize < DM_QT_DEFAULT_POINT_SIZE) { + pointSize = DM_QT_DEFAULT_POINT_SIZE; + } + break; } } } @@ -513,6 +562,7 @@ bu_log("qt_setBGColor\n"); } + privars->bg.setRgb(r, g, b); dmp->dm_bg[0] = r; @@ -769,6 +819,7 @@ privars->qapp->processEvents(); } + /** * P R O C E S S Q T E V E N T S * @@ -780,7 +831,6 @@ qt_processEvents(&dm_qt); } -Tcl_TimerToken token = NULL; /** * I D L E C A L L @@ -1067,6 +1117,7 @@ * ================================================== Event bindings declaration ========================================================== */ +/* left click press */ char* qt_mouseButton1Press(QEvent *event) { if (event->type() == QEvent::MouseButtonPress) { QMouseEvent *mouseEv = (QMouseEvent *)event; @@ -1079,6 +1130,7 @@ return NULL; } +/* left click release */ char* qt_mouseButton1Release(QEvent *event) { if (event->type() == QEvent::MouseButtonRelease) { QMouseEvent *mouseEv = (QMouseEvent *)event; @@ -1091,7 +1143,8 @@ return NULL; } -char* qt_mouseButton2Press(QEvent *event) { +/* right click press */ +char* qt_mouseButton3Press(QEvent *event) { if (event->type() == QEvent::MouseButtonPress) { QMouseEvent *mouseEv = (QMouseEvent *)event; if (mouseEv->button() == Qt::RightButton) { @@ -1103,7 +1156,8 @@ return NULL; } -char* qt_mouseButton2Release(QEvent *event) { +/* right click release */ +char* qt_mouseButton3Release(QEvent *event) { if (event->type() == QEvent::MouseButtonPress) { QMouseEvent *mouseEv = (QMouseEvent *)event; if (mouseEv->button() == Qt::RightButton) { @@ -1115,6 +1169,32 @@ return NULL; } +/* middle mouse button press */ +char* qt_mouseButton2Press(QEvent *event) { + if (event->type() == QEvent::MouseButtonPress) { + QMouseEvent *mouseEv = (QMouseEvent *)event; + if (mouseEv->button() == Qt::MiddleButton) { + struct bu_vls str = BU_VLS_INIT_ZERO; + bu_vls_printf(&str, "<2> -x %d -y %d", mouseEv->x(), mouseEv->y()); + return bu_vls_addr(&str); + } + } + return NULL; +} + +/* middle mouse button release */ +char* qt_mouseButton2Release(QEvent *event) { + if (event->type() == QEvent::MouseButtonPress) { + QMouseEvent *mouseEv = (QMouseEvent *)event; + if (mouseEv->button() == Qt::MiddleButton) { + struct bu_vls str = BU_VLS_INIT_ZERO; + bu_vls_printf(&str, "<ButtonRelease-2>"); + return bu_vls_addr(&str); + } + } + return NULL; +} + char* qt_controlMousePress(QEvent *event) { if (event->type() == QEvent::MouseButtonPress) { QMouseEvent *mouseEv = (QMouseEvent *)event; @@ -1127,6 +1207,42 @@ return NULL; } +char* qt_altMousePress(QEvent *event) { + if (event->type() == QEvent::MouseButtonPress) { + QMouseEvent *mouseEv = (QMouseEvent *)event; + if (mouseEv->button() == Qt::LeftButton && mouseEv->modifiers() == Qt::AltModifier) { + struct bu_vls str = BU_VLS_INIT_ZERO; + bu_vls_printf(&str, "<Alt-ButtonPress-1> -x %d -y %d", mouseEv->x(), mouseEv->y()); + return bu_vls_addr(&str); + } + } + return NULL; +} + +char* qt_altControlMousePress(QEvent *event) { + if (event->type() == QEvent::MouseButtonPress) { + QMouseEvent *mouseEv = (QMouseEvent *)event; + if (mouseEv->button() == Qt::LeftButton && mouseEv->modifiers() & Qt::AltModifier && mouseEv->modifiers() & Qt::ControlModifier) { + struct bu_vls str = BU_VLS_INIT_ZERO; + bu_vls_printf(&str, "<Control-Alt-ButtonPress-1> -x %d -y %d", mouseEv->x(), mouseEv->y()); + return bu_vls_addr(&str); + } + } + return NULL; +} + +char* qt_controlShiftMousePress(QEvent *event) { + if (event->type() == QEvent::MouseButtonPress) { + QMouseEvent *mouseEv = (QMouseEvent *)event; + if (mouseEv->button() == Qt::LeftButton && mouseEv->modifiers() & Qt::ShiftModifier && mouseEv->modifiers() & Qt::ControlModifier) { + struct bu_vls str = BU_VLS_INIT_ZERO; + bu_vls_printf(&str, "<Shift-Alt-ButtonPress-1> -x %d -y %d", mouseEv->x(), mouseEv->y()); + return bu_vls_addr(&str); + } + } + return NULL; +} + char* qt_mouseMove(QEvent *event) { if (event->type() == QEvent::MouseMove) { QMouseEvent *mouseEv = (QMouseEvent *)event; @@ -1138,7 +1254,8 @@ } char* qt_keyPress(QEvent *event) { - if (event->type() == 6 /* Key Press */) { + /* FIXME numeric constant needs to be changed to QEvent::KeyPress but at this moment this does not compile */ + if (event->type() == 6 /* QEvent::KeyPress */) { QKeyEvent *keyEv = (QKeyEvent *)event; struct bu_vls str = BU_VLS_INIT_ZERO; bu_vls_printf(&str, "<KeyPress-%s>", keyEv->text().data()); @@ -1147,11 +1264,28 @@ return NULL; } +char* qt_keyRelease(QEvent *event) { + /* FIXME numeric constant needs to be changed to QEvent::KeyRelease but at this moment this does not compile */ + if (event->type() == 7 /* QEvent::KeyRelease */) { + QKeyEvent *keyEv = (QKeyEvent *)event; + struct bu_vls str = BU_VLS_INIT_ZERO; + bu_vls_printf(&str, "<KeyRelease-%s>", keyEv->text().data()); + return bu_vls_addr(&str); + } + return NULL; +} + static struct qt_tk_bind qt_bindings[] = { {qt_keyPress, "keypress"}, + {qt_keyRelease, "keyrelease"}, {qt_controlMousePress, "controlbutton1"}, + {qt_altMousePress, "altbutton1"}, + {qt_altControlMousePress, "altcontrolbutton1"}, + {qt_controlShiftMousePress, "controlshiftbutton1"}, {qt_mouseButton1Press, "button1press"}, {qt_mouseButton1Release, "button1release"}, + {qt_mouseButton3Press, "button3press"}, + {qt_mouseButton3Release, "button3release"}, {qt_mouseButton2Press, "button2press"}, {qt_mouseButton2Release, "button2release"}, {qt_mouseMove, "mouseMove"}, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |