From 3089c4bbc10e98d18f43e8a70e7a3d0c0eaf0900 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Fri, 22 Mar 2013 20:48:17 +0100 Subject: Downcase. PLEASE TURN OFF IGNORING CASE IN GIT CONFIG!!! .git/config: [core] ignorecase = false --- ...erequisites for using widget in Qt Designer.png | Bin 0 -> 21422 bytes qfunctionconfigurator/QFunctionConfigurator.sln | 20 + .../QFunctionConfigurator/FunctionConfig.cpp | Bin 0 -> 17350 bytes .../QFunctionConfigurator/FunctionConfig.h | Bin 0 -> 3888 bytes .../QFunctionConfigurator.vcproj | 355 ++++++++++ .../QFunctionConfigurator_vc9.vcproj | 354 ++++++++++ .../QFunctionConfigurator/postbuild.bat | 30 + .../qfunctionconfigurator.cpp | 721 +++++++++++++++++++++ .../QFunctionConfigurator/qfunctionconfigurator.h | 206 ++++++ .../qfunctionconfiguratorplugin.cpp | 146 +++++ .../qfunctionconfiguratorplugin.h | 30 + .../QFunctionConfigurator_vc9.sln | 20 + 12 files changed, 1882 insertions(+) create mode 100644 qfunctionconfigurator/Prerequisites for using widget in Qt Designer.png create mode 100644 qfunctionconfigurator/QFunctionConfigurator.sln create mode 100644 qfunctionconfigurator/QFunctionConfigurator/FunctionConfig.cpp create mode 100644 qfunctionconfigurator/QFunctionConfigurator/FunctionConfig.h create mode 100644 qfunctionconfigurator/QFunctionConfigurator/QFunctionConfigurator.vcproj create mode 100644 qfunctionconfigurator/QFunctionConfigurator/QFunctionConfigurator_vc9.vcproj create mode 100644 qfunctionconfigurator/QFunctionConfigurator/postbuild.bat create mode 100644 qfunctionconfigurator/QFunctionConfigurator/qfunctionconfigurator.cpp create mode 100644 qfunctionconfigurator/QFunctionConfigurator/qfunctionconfigurator.h create mode 100644 qfunctionconfigurator/QFunctionConfigurator/qfunctionconfiguratorplugin.cpp create mode 100644 qfunctionconfigurator/QFunctionConfigurator/qfunctionconfiguratorplugin.h create mode 100644 qfunctionconfigurator/QFunctionConfigurator_vc9.sln (limited to 'qfunctionconfigurator') diff --git a/qfunctionconfigurator/Prerequisites for using widget in Qt Designer.png b/qfunctionconfigurator/Prerequisites for using widget in Qt Designer.png new file mode 100644 index 00000000..6e4d8903 Binary files /dev/null and b/qfunctionconfigurator/Prerequisites for using widget in Qt Designer.png differ diff --git a/qfunctionconfigurator/QFunctionConfigurator.sln b/qfunctionconfigurator/QFunctionConfigurator.sln new file mode 100644 index 00000000..91b827df --- /dev/null +++ b/qfunctionconfigurator/QFunctionConfigurator.sln @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 9.00 +# Visual Studio 2005 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "QFunctionConfigurator", "QFunctionConfigurator\QFunctionConfigurator.vcproj", "{2527B683-7EFC-4D51-B25A-843668649C54}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {2527B683-7EFC-4D51-B25A-843668649C54}.Debug|Win32.ActiveCfg = Debug|Win32 + {2527B683-7EFC-4D51-B25A-843668649C54}.Debug|Win32.Build.0 = Debug|Win32 + {2527B683-7EFC-4D51-B25A-843668649C54}.Release|Win32.ActiveCfg = Release|Win32 + {2527B683-7EFC-4D51-B25A-843668649C54}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/qfunctionconfigurator/QFunctionConfigurator/FunctionConfig.cpp b/qfunctionconfigurator/QFunctionConfigurator/FunctionConfig.cpp new file mode 100644 index 00000000..243564d1 Binary files /dev/null and b/qfunctionconfigurator/QFunctionConfigurator/FunctionConfig.cpp differ diff --git a/qfunctionconfigurator/QFunctionConfigurator/FunctionConfig.h b/qfunctionconfigurator/QFunctionConfigurator/FunctionConfig.h new file mode 100644 index 00000000..8dc9cf98 Binary files /dev/null and b/qfunctionconfigurator/QFunctionConfigurator/FunctionConfig.h differ diff --git a/qfunctionconfigurator/QFunctionConfigurator/QFunctionConfigurator.vcproj b/qfunctionconfigurator/QFunctionConfigurator/QFunctionConfigurator.vcproj new file mode 100644 index 00000000..29a06271 --- /dev/null +++ b/qfunctionconfigurator/QFunctionConfigurator/QFunctionConfigurator.vcproj @@ -0,0 +1,355 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/qfunctionconfigurator/QFunctionConfigurator/QFunctionConfigurator_vc9.vcproj b/qfunctionconfigurator/QFunctionConfigurator/QFunctionConfigurator_vc9.vcproj new file mode 100644 index 00000000..940a6198 --- /dev/null +++ b/qfunctionconfigurator/QFunctionConfigurator/QFunctionConfigurator_vc9.vcproj @@ -0,0 +1,354 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/qfunctionconfigurator/QFunctionConfigurator/postbuild.bat b/qfunctionconfigurator/QFunctionConfigurator/postbuild.bat new file mode 100644 index 00000000..3fe2e3ca --- /dev/null +++ b/qfunctionconfigurator/QFunctionConfigurator/postbuild.bat @@ -0,0 +1,30 @@ +@echo off +rem Copies required DLL files into output folder. + +setlocal +set COPY=xcopy /D /S /C /I /H /R /Y +set FILTER=find /v "File(s) copied" + +echo parameters %1 en %2 en %3 en %4 + +set API_BIN=%1 +set OUTDIR=%2 +set CONFIG=%3 +set FTN_BIN=%4 + +if %CONFIG%==Debug (goto Debug) +if %CONFIG%==Release (goto Release) + +echo Unknown build configuration %CONFIG% +exit /b -1 + +:Debug +%COPY% %API_BIN%\*.* %OUTDIR%\ | %FILTER% +%COPY% %API_BIN%\*.dll %FTN_BIN%\ | %FILTER% +exit /b 0 + +:Release +%COPY% %API_BIN%\*.* %OUTDIR%\ | %FILTER% +%COPY% %API_BIN%\*.dll %FTN_BIN%\ | %FILTER% +exit /b 0 + diff --git a/qfunctionconfigurator/QFunctionConfigurator/qfunctionconfigurator.cpp b/qfunctionconfigurator/QFunctionConfigurator/qfunctionconfigurator.cpp new file mode 100644 index 00000000..fe2ad49d --- /dev/null +++ b/qfunctionconfigurator/QFunctionConfigurator/qfunctionconfigurator.cpp @@ -0,0 +1,721 @@ +/******************************************************************************** +* FaceTrackNoIR This program is a private project of some enthusiastic * +* gamers from Holland, who don't like to pay much for * +* head-tracking. * +* * +* Copyright (C) 2012 Wim Vriend (Developing) * +* Ron Hendriks (Researching and Testing) * +* * +* Homepage http://facetracknoir.sourceforge.net/home/default.htm * +* * +* This program is free software; you can redistribute it and/or modify it * +* under the terms of the GNU General Public License as published by the * +* Free Software Foundation; either version 3 of the License, or (at your * +* option) any later version. * +* * +* This program is distributed in the hope that it will be useful, but * +* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * +* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * +* more details. * +* * +* You should have received a copy of the GNU General Public License along * +* with this program; if not, see . * +* * +* The FunctionConfigurator was made by Stanislaw Halik, and adapted to * +* FaceTrackNoIR. * +* * +* All credits for this nice piece of code should go to Stanislaw. * +* * +* Copyright (c) 2011-2012, Stanislaw Halik * +* Permission to use, copy, modify, and/or distribute this * +* software for any purpose with or without fee is hereby granted, * +* provided that the above copyright notice and this permission * +* notice appear in all copies. * +********************************************************************************/ +/* + Modifications (last one on top): + 20120830 - WVR: Changed functionality a bit. Now only draw the handles, when the function is drawn. + Only check mouseMoves, when they occur 'in range'. Redraw the curve, when a resize occurs. + Somehow, the curve was not drawn correctly, when this was not done (all points were too high). + After a 'Reset' this would disappear... + 20120828 - WVR: Removed bSkipText, which was used to not show a number below each vertical gridline. +*/ +#include "qfunctionconfigurator.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include + +QFunctionConfigurator::~QFunctionConfigurator() +{ + WaitForSingleObject(_mutex, INFINITE); + CloseHandle(_mutex); + delete btnReset; +} + +static const int pointSize = 5; + +QFunctionConfigurator::QFunctionConfigurator(QWidget *parent) + : QWidget(parent) +{ + + // + // Defaults, for when the widget has no values different from the domXML() + // + MaxInput = 50; // Maximum input limit + MaxOutput = 180; // Maximum output limit + pPerEGU_Output = 1; // Number of pixels, per EGU + pPerEGU_Input = 4; // Number of pixels, per EGU + gDistEGU_Input = 5; // Distance of gridlines + gDistEGU_Output = 10; // Distance of gridlines + + + // Change compared to BezierConfigurator: X = horizontal (input), Y = vertical (output) + // This will require the Curve-Dialog to be higher (which was the reason it was reversed in the first place..) + range = QRectF(40, 20, MaxInput * pPerEGU_Input, MaxOutput * pPerEGU_Output); + + setMouseTracking(true); + moving = NULL; // Pointer to the curve-point, that's being moved + movingPoint = 1; // Index of that same point + + // + // Add a Reset-button + // + btnReset = new QPushButton(QString("Reset"), this); + connect(btnReset, SIGNAL(clicked()), this, SLOT(resetCurve())); + + // + // Variables for FunctionConfig + // + _config = 0; + _points = QList(); + _draw_points = QList(); + _mutex = CreateMutex(NULL, false, NULL); + _draw_background = true; + _draw_function = true; + +// qDebug() << "QFunctionConfigurator::QFunctionConfigurator object created."; + +} + +// +// Attach an existing FunctionConfig to the Widget. +// +void QFunctionConfigurator::setConfig(FunctionConfig* config, QString settingsFile) { +QPointF currentPoint; +QPointF drawPoint; +qreal x; + + WaitForSingleObject(_mutex, INFINITE); + _config = config; + _points = config->getPoints(); + strSettingsFile = settingsFile; // Remember for Reset() + + qDebug() << "QFunctionConfigurator::setConfig" << config->getTitle(); + setCaption(config->getTitle()); + + // + // Get the Function Points, one for each pixel in the horizontal range. + // If the curve does not change, there is no need to run this code every time (it slows down drawing). + // + _draw_points.clear(); + for (int j = 0; j < MaxInput * pPerEGU_Input; j++) { + // + // Weird: not casting to float causes C++ to round the number... + // + x = (float) j / (float) pPerEGU_Input; + currentPoint.setX ( x ); + currentPoint.setY (_config->getValue( x )); + drawPoint = graphicalizePoint(currentPoint, "setConfig"); + if (withinRect(drawPoint, range)) { + _draw_points.append(drawPoint); +// qDebug() << "QFunctionConfigurator::setConfig _draw_Point to add = " << drawPoint; + } + } + + ReleaseMutex(_mutex); + _draw_function = true; + this->update(); +} + +// +// Load the FunctionConfig (points) from the INI-file. +// +void QFunctionConfigurator::loadSettings(QString settingsFile) { + + QSettings iniFile( settingsFile, QSettings::IniFormat ); // Application settings (in INI-file) + strSettingsFile = settingsFile; // Remember for Reset() + qDebug() << "QFunctionConfigurator::loadSettings = " << settingsFile; + WaitForSingleObject(_mutex, INFINITE); + if (_config) { + _config->loadSettings(iniFile); + setConfig(_config, settingsFile); + } + ReleaseMutex(_mutex); +} + +// +// Save the FunctionConfig (points) to the INI-file. +// +void QFunctionConfigurator::saveSettings(QString settingsFile) { + QSettings iniFile( settingsFile, QSettings::IniFormat ); // Application settings (in INI-file) + strSettingsFile = settingsFile; // Remember for Reset() + qDebug() << "QFunctionConfigurator::saveSettings = " << settingsFile; + + WaitForSingleObject(_mutex, INFINITE); + if (_config) { + _config->saveSettings(iniFile); + } + ReleaseMutex(_mutex); +} + +// +// Draw the Background for the graph, the gridlines and the gridpoints. +// The static objects are drawn on a Pixmap, so it does not have to be repeated every paintEvent. Hope this speeds things up... +// +void QFunctionConfigurator::drawBackground(const QRectF &fullRect) +{ +int i; +QRect scale; + + qDebug() << "QFunctionConfigurator::drawBackground."; + + _background = QPixmap(fullRect.width(), fullRect.height()); + QPainter painter(&_background); + + painter.save(); + painter.setRenderHint(QPainter::Antialiasing); + painter.fillRect(fullRect, colBackground); + QColor bg_color(112, 154, 209); + painter.fillRect(range, bg_color); + + QFont font("ComicSans", 4); + font.setPointSize(8); + painter.setFont(font); + + QPen pen(QColor(55, 104, 170, 127), 1, Qt::SolidLine); + + // + // Draw the Caption + // + if (_config) { + strCaption = _config->getTitle(); + } + + scale.setCoords(range.left(), 0, range.right(), 20); + painter.drawText(scale, Qt::AlignCenter, strCaption); + + // + // Draw the horizontal grid + // + for (i = range.bottom() - gDistEGU_Output * pPerEGU_Output; i >= range.top(); i -= gDistEGU_Output * pPerEGU_Output) { + drawLine(&painter, QPointF(40, i), QPointF(range.right(), i), pen); + scale.setCoords(0, i - 5, range.left() - 5, i + 5); + painter.drawText(scale, Qt::AlignRight, tr("%1").arg(((range.bottom() - i))/pPerEGU_Output)); + } + + // + // Draw the vertical guidelines + // + for (i = range.left(); i <= range.right(); i += gDistEGU_Input * pPerEGU_Input) { + drawLine(&painter, QPointF(i, range.top()), QPointF(i, range.bottom()), pen); + scale.setCoords(i - 10, range.bottom() + 2, i + 10, range.bottom() + 15); + painter.drawText(scale, Qt::AlignCenter, tr("%1").arg(abs(((range.left() - i))/pPerEGU_Input))); + } + + scale.setCoords(range.left(), range.bottom() + 20, range.right(), range.bottom() + 35); + painter.drawText(scale, Qt::AlignRight, strInputEGU); + + // + // Draw the EGU of the vertical axis (vertically!) + // + font.setPointSize(10); + painter.translate(range.topLeft().x() - 35, range.topLeft().y()); + painter.rotate(90); + painter.drawText(0,0,strOutputEGU ); + + // + // Draw the two axis + // + pen.setWidth(2); + pen.setColor( Qt::black ); + drawLine(&painter, range.topLeft() - QPointF(2,0), range.bottomLeft() - QPointF(2,0), pen); + drawLine(&painter, range.bottomLeft(), range.bottomRight(), pen); + + painter.restore(); +} + + +// +// Draw the Function for the graph, on a Pixmap. +// +void QFunctionConfigurator::drawFunction(const QRectF &fullRect) +{ + if (!_config) + return; +int i; +QPointF prevPoint; +QPointF currentPoint; + + // + // Use the background picture to draw on. + // ToDo: find out how to add Pixmaps, without getting it all green... + // + _function = QPixmap(_background); + QPainter painter(&_function); + + painter.save(); + painter.setRenderHint(QPainter::Antialiasing, false); + + // + // Draw the handles for the Points + // + for (i = 0; i < _points.size(); i++) { + currentPoint = graphicalizePoint( _points[i], "drawFunction handles" ); // Get the next point and convert it to Widget measures + drawPoint(&painter, currentPoint, QColor(200, 200, 210, 120)); + lastPoint = currentPoint; // Remember which point is the rightmost in the graph +//qDebug() << "QFunctionConfigurator::paintEvent, drawing handle for " << currentPoint; + } + + + QPen pen(colBezier, 2, Qt::SolidLine); + + prevPoint = graphicalizePoint( QPointF(0,0), "drawFunction lines" ); // Start at the Axis + double max = maxInputEGU(); + QPointF prev = graphicalizePoint(QPointF(0, 0)); + double step = 1 / (double) pixPerEGU_Input(); + for (double i = 0; i < max; i += step) { + double val = _config->getValue(i); + QPointF cur = graphicalizePoint(QPointF(i, val)); + drawLine(&painter, prev, cur, pen); + prev = cur; + } + painter.restore(); +} + +// +// The Widget paints the surface every x msecs. +// +void QFunctionConfigurator::paintEvent(QPaintEvent *e) +{ +QPointF prevPoint; +QPointF currentPoint; +QPointF actualPos; +int i; + +// qDebug() << "QFunctionConfigurator::paintEvent."; + + QPainter p(this); + p.setRenderHint(QPainter::Antialiasing); + p.setClipRect(e->rect()); + + if (_draw_background) { + drawBackground(e->rect()); // Draw the static parts on a Pixmap + p.drawPixmap(0, 0, _background); // Paint the background + _draw_background = false; + + btnReset->move(e->rect().left(), e->rect().bottom() - btnReset->height() - 2); + } + + if (_draw_function) { + drawFunction(e->rect()); // Draw the Function on a Pixmap + _draw_function = false; + } + p.drawPixmap(0, 0, _function); // Always draw the background and the function + + QPen pen(Qt::white, 1, Qt::SolidLine); + + // + // Draw the Points, that make up the Curve + // + WaitForSingleObject(_mutex, INFINITE); + if (_config) { + + // + // When moving, also draw a sketched version of the Function. + // + if (moving) { + prevPoint = graphicalizePoint( QPointF(0,0), "paintEvent moving" ); // Start at the Axis + for (i = 0; i < _points.size(); i++) { + currentPoint = graphicalizePoint( _points[i], "paintEvent moving" ); // Get the next point and convert it to Widget measures + drawLine(&p, prevPoint, currentPoint, pen); + prevPoint = currentPoint; +// qDebug() << "QFunctionConfigurator::paintEvent, drawing while moving " << currentPoint; + } + + // + // When moving, also draw a few help-lines, so positioning the point gets easier. + // + pen.setWidth(1); + pen.setColor( Qt::white ); + pen.setStyle( Qt::DashLine ); + actualPos = graphicalizePoint(*moving, "paintEvent moving help line(s)"); + drawLine(&p, QPoint(range.left(), actualPos.y()), QPoint(actualPos.x(), actualPos.y()), pen); + drawLine(&p, QPoint(actualPos.x(), actualPos.y()), QPoint(actualPos.x(), range.bottom()), pen); + } + + // + // If the Tracker is active, the 'Last Point' it requested is recorded. + // Show that point on the graph, with some lines to assist. + // This new feature is very handy for tweaking the curves! + // + if (_config->getLastPoint( currentPoint )) { + +// qDebug() << "QFunctionConfigurator::paintEvent, drawing tracked Point " << currentPoint; + + actualPos = graphicalizePoint( currentPoint, "paintEvent tracking" ); + drawPoint(&p, actualPos, QColor(255, 0, 0, 120)); + + pen.setWidth(1); + pen.setColor( Qt::black ); + pen.setStyle( Qt::SolidLine ); + drawLine(&p, QPoint(range.left(), actualPos.y()), QPoint(actualPos.x(), actualPos.y()), pen); + drawLine(&p, QPoint(actualPos.x(), actualPos.y()), QPoint(actualPos.x(), range.bottom()), pen); + } + + } + ReleaseMutex(_mutex); + + // + // Draw the delimiters + // + pen.setWidth(1); + pen.setColor( Qt::white ); + pen.setStyle( Qt::SolidLine ); + drawLine(&p, QPoint(lastPoint.x(), range.top()), QPoint(lastPoint.x(), range.bottom()), pen); + drawLine(&p, QPoint(range.left(), lastPoint.y()), QPoint(range.right(), lastPoint.y()), pen); + + QTimer::singleShot(250, this, SLOT(update())); +} + +// +// Draw the handle, to move the Bezier-curve. +// +void QFunctionConfigurator::drawPoint(QPainter *painter, const QPointF &pos, QColor colBG ) +{ + painter->save(); + painter->setPen(QColor(50, 100, 120, 200)); + painter->setBrush( colBG ); + painter->drawEllipse(QRectF(pos.x() - pointSize, + pos.y() - pointSize, + pointSize*2, pointSize*2)); + painter->restore(); +} + +void QFunctionConfigurator::drawLine(QPainter *painter, const QPointF &start, const QPointF &end, QPen pen) +{ + painter->save(); + painter->setPen(pen); + painter->setBrush(Qt::NoBrush); + painter->drawLine(start, end); + painter->restore(); +} + +// +// If the mousebutton is pressed, check if it is inside one of the Points. +// If so: start moving that Point, until mouse release. +// +void QFunctionConfigurator::mousePressEvent(QMouseEvent *e) +{ + // + // First: check the left mouse-button + // + if (e->button() == Qt::LeftButton) { + + // + // Check to see if the cursor is touching one of the points. + // + bool bTouchingPoint = false; + movingPoint = -1; + WaitForSingleObject(_mutex, INFINITE); + if (_config) { + + for (int i = 0; i < _points.size(); i++) { + if ( markContains( graphicalizePoint( _points[i], "mousePressEvent markContains" ), e->pos() ) ) { + bTouchingPoint = true; + moving = &_points[i]; + movingPoint = i; + } + } + + // + // If the Left Mouse-button was clicked without touching a Point, add a new Point + // + if (!bTouchingPoint) { + if (withinRect(e->pos(), range)) { + _config->addPoint(normalizePoint(e->pos())); + setConfig(_config, strSettingsFile); + moving = NULL; + emit CurveChanged( true ); + } + } + } + ReleaseMutex(_mutex); + } + + // + // Then: check the right mouse-button + // + if (e->button() == Qt::RightButton) { + + // + // Check to see if the cursor is touching one of the points. + // + moving = NULL; + movingPoint = -1; + WaitForSingleObject(_mutex, INFINITE); + if (_config) { + + for (int i = 0; i < _points.size(); i++) { + if ( markContains( graphicalizePoint( _points[i], "mousePressEvent RightButton" ), e->pos() ) ) { + movingPoint = i; + } + } + + // + // If the Right Mouse-button was clicked while touching a Point, remove the Point + // + if (movingPoint >= 0) { + _config->removePoint(movingPoint); + setConfig(_config, strSettingsFile); + movingPoint = -1; + emit CurveChanged( true ); + } + } + ReleaseMutex(_mutex); + } + +} + +// +// If the mouse if moving, make sure the Bezier moves along. +// Of course, only when a Point is selected... +// +void QFunctionConfigurator::mouseMoveEvent(QMouseEvent *e) +{ + + if (moving) { + + setCursor(Qt::ClosedHandCursor); + + // + // Change the currently moving Point. + // + *moving = normalizePoint(e->pos()); + update(); + } + else { + + // + // Check to see if the cursor is touching one of the points. + // + bool bTouchingPoint = false; + WaitForSingleObject(_mutex, INFINITE); + if (_config) { + + for (int i = 0; i < _points.size(); i++) { + if ( markContains( graphicalizePoint( _points[i], "mouseMoveEvent" ), e->pos() ) ) { + bTouchingPoint = true; + } + } + } + ReleaseMutex(_mutex); + + if ( bTouchingPoint ) { + setCursor(Qt::OpenHandCursor); + } + else { + setCursor(Qt::ArrowCursor); + } + + } +} + +void QFunctionConfigurator::mouseReleaseEvent(QMouseEvent *e) +{ + //qDebug()<<"releasing"; + if (moving > 0) { + emit CurveChanged( true ); + + // + // Update the Point in the _config + // + WaitForSingleObject(_mutex, INFINITE); + if (_config) { + _config->movePoint(movingPoint, normalizePoint(e->pos())); + setConfig(_config, strSettingsFile); + } + ReleaseMutex(_mutex); + + } + setCursor(Qt::ArrowCursor); + moving = NULL; + movingPoint = 0; +} + +// +// Determine if the mousebutton was pressed within the range of the Point. +// +bool QFunctionConfigurator::markContains(const QPointF &pos, const QPointF &coord) const +{ + QRectF rect(pos.x() - pointSize, + pos.y() - pointSize, + pointSize*2, pointSize*2); + QPainterPath path; + path.addEllipse(rect); + return path.contains(coord); +} + +bool QFunctionConfigurator::withinRect( const QPointF &coord, const QRectF &rect ) const +{ + QPainterPath path; + path.addRect(rect); + return path.contains(coord); +} + +// +// Convert the Point in the graph, to the real-life Point. +// +QPointF QFunctionConfigurator::normalizePoint(QPointF point) const +{ + QPointF norm; + + norm.setX( (point.x() - range.left()) / pPerEGU_Input ); + norm.setY( (range.bottom() - point.y()) / pPerEGU_Output ); + + if (norm.x() > maxInputEGU()) + norm.setX(maxInputEGU()); + else if (norm.x() < 0) + norm.setX(0); + if (norm.y() > maxOutputEGU()) + norm.setY(maxOutputEGU()); + else if (norm.y() < 0) + norm.setY(0); + + return norm; +} + +// +// Convert the real-life Point into the graphical Point. +// +QPointF QFunctionConfigurator::graphicalizePoint(QPointF point, QString source) const +{ +QPointF graph; + + graph.setX( range.left() + (fabs(point.x()) * pPerEGU_Input) ); + graph.setY( range.bottom() - (fabs(point.y()) * pPerEGU_Output) ); + +// qDebug() << "QFunctionConfigurator::graphicalizePoint source = " << source << ", point = " << point << ", graph = " << graph; + + return graph; +} + +void QFunctionConfigurator::setmaxInputEGU(int value) +{ + MaxInput = value; + setMinimumWidth(MaxInput * pPerEGU_Input + 55); +// resetCurve(); + resize( MaxInput * pPerEGU_Input + 55, MaxOutput * pPerEGU_Output + 60 ); +} +void QFunctionConfigurator::setmaxOutputEGU(int value) +{ + MaxOutput = value; + setMinimumHeight(MaxOutput * pPerEGU_Output + 60); +// resetCurve(); + resize( MaxInput * pPerEGU_Input + 55, MaxOutput * pPerEGU_Output + 60 ); +} + +// +// To make configuration more visibly attractive, the number of pixels 'per EGU' can be defined. +// +void QFunctionConfigurator::setpixPerEGU_Input(int value) +{ + pPerEGU_Input = value; + setMinimumWidth(MaxInput * pPerEGU_Input + 55); + resize( MaxInput * pPerEGU_Input + 55, MaxOutput * pPerEGU_Output + 60 ); +} + +// +// To make configuration more visibly attractive, the number of pixels 'per EGU' can be defined. +// +void QFunctionConfigurator::setpixPerEGU_Output(int value) +{ + pPerEGU_Output = value; + setMinimumHeight(MaxOutput * pPerEGU_Output + 60); + resize( MaxInput * pPerEGU_Input + 55, MaxOutput * pPerEGU_Output + 60 ); +} + +// +// Define the distance of the grid 'in EGU' points. +// +void QFunctionConfigurator::setgridDistEGU_Input(int value) +{ + gDistEGU_Input = value; + _draw_background = true; + _draw_function = true; + repaint(); +} + +// +// Define the distance of the grid 'in EGU' points. +// +void QFunctionConfigurator::setgridDistEGU_Output(int value) +{ + gDistEGU_Output = value; + _draw_background = true; + _draw_function = true; + repaint(); +} + +void QFunctionConfigurator::setColorBezier(QColor color) +{ + colBezier = color; + update(); +} +void QFunctionConfigurator::setColorBackground(QColor color) +{ + colBackground = color; + update(); +} + +void QFunctionConfigurator::setInputEGU(QString egu) +{ + strInputEGU = egu; + update(); +} +void QFunctionConfigurator::setOutputEGU(QString egu) +{ + strOutputEGU = egu; + update(); +} +void QFunctionConfigurator::setCaption(QString cap) +{ + strCaption = cap; + update(); +} + +void QFunctionConfigurator::resizeEvent(QResizeEvent *e) +{ + QSize s = e->size(); + range = QRectF(40, 20, MaxInput * pPerEGU_Input, MaxOutput * pPerEGU_Output); + + qDebug() << "QFunctionConfigurator::resizeEvent, name = " << strCaption << ",range = " << range; + + if (_config) { + setConfig(_config, strSettingsFile); + } + _draw_background = true; + _draw_function = true; + repaint(); +} diff --git a/qfunctionconfigurator/QFunctionConfigurator/qfunctionconfigurator.h b/qfunctionconfigurator/QFunctionConfigurator/qfunctionconfigurator.h new file mode 100644 index 00000000..c467bc92 --- /dev/null +++ b/qfunctionconfigurator/QFunctionConfigurator/qfunctionconfigurator.h @@ -0,0 +1,206 @@ +/******************************************************************************** +* FaceTrackNoIR This program is a private project of some enthusiastic * +* gamers from Holland, who don't like to pay much for * +* head-tracking. * +* * +* Copyright (C) 2012 Wim Vriend (Developing) * +* Ron Hendriks (Researching and Testing) * +* * +* Homepage http://facetracknoir.sourceforge.net/home/default.htm * +* * +* This program is free software; you can redistribute it and/or modify it * +* under the terms of the GNU General Public License as published by the * +* Free Software Foundation; either version 3 of the License, or (at your * +* option) any later version. * +* * +* This program is distributed in the hope that it will be useful, but * +* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * +* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * +* more details. * +* * +* You should have received a copy of the GNU General Public License along * +* with this program; if not, see . * +* * +* The FunctionConfigurator was made by Stanislaw Halik, and adapted to * +* FaceTrackNoIR. * +* * +* All credits for this nice piece of code should go to Stanislaw. * +* * +* Copyright (c) 2011-2012, Stanislaw Halik * +* Permission to use, copy, modify, and/or distribute this * +* software for any purpose with or without fee is hereby granted, * +* provided that the above copyright notice and this permission * +* notice appear in all copies. * +********************************************************************************/ +#ifndef QFUNCTIONCONFIGURATOR_H +#define QFUNCTIONCONFIGURATOR_H + +#include +#include +#include +#include "FunctionConfig.h" + +// +// The FunctionConfigurator Widget is used to display and configure a function (curve). +// The Function is used by FaceTrackNoIR to 'translate' the actual head-pose to the virtual headpose. Every axis is configured by a separate Function. +// +// The Function is coded in a separate Class and can exists, without the Widget. When the widget is displayed (therefore 'created'), the Function can be attached to the +// Widget and the Widget used to change the Function. +// +class QDESIGNER_WIDGET_EXPORT QFunctionConfigurator : public QWidget +{ + Q_OBJECT + Q_PROPERTY(int maxInputEGU READ maxInputEGU WRITE setmaxInputEGU); + Q_PROPERTY(int maxOutputEGU READ maxOutputEGU WRITE setmaxOutputEGU); + Q_PROPERTY(int pixPerEGU_Input READ pixPerEGU_Input WRITE setpixPerEGU_Input); + Q_PROPERTY(int pixPerEGU_Output READ pixPerEGU_Output WRITE setpixPerEGU_Output); + Q_PROPERTY(int gridDistEGU_Input READ gridDistEGU_Input WRITE setgridDistEGU_Input); + Q_PROPERTY(int gridDistEGU_Output READ gridDistEGU_Output WRITE setgridDistEGU_Output); + + Q_PROPERTY(QColor colorBezier READ colorBezier WRITE setColorBezier); + Q_PROPERTY(QColor colorBackground READ colorBackground WRITE setColorBackground); + Q_PROPERTY(QString stringInputEGU READ stringInputEGU WRITE setInputEGU); + Q_PROPERTY(QString stringOutputEGU READ stringOutputEGU WRITE setOutputEGU); + Q_PROPERTY(QString stringCaption READ stringCaption WRITE setCaption); + + // Return the current value to Designer + int maxInputEGU() const + { + return MaxInput; + } + int maxOutputEGU() const + { + return MaxOutput; + } + int pixPerEGU_Input() const + { + return pPerEGU_Input; + } + int pixPerEGU_Output() const + { + return pPerEGU_Output; + } + int gridDistEGU_Input() const + { + return gDistEGU_Input; + } + int gridDistEGU_Output() const + { + return gDistEGU_Output; + } + + // Return the current color to Designer + QColor colorBezier() const + { + return colBezier; + } + // Return the current color to Designer + QColor colorBackground() const + { + return colBackground; + } + // Return the current string to Designer + QString stringInputEGU() const + { + return strInputEGU; + } + // Return the current string to Designer + QString stringOutputEGU() const + { + return strOutputEGU; + } + // Return the current string to Designer + QString stringCaption() const + { + return strCaption; + } + +public: + QFunctionConfigurator(QWidget *parent = 0); + ~QFunctionConfigurator(); + FunctionConfig* config(); + + void setConfig(FunctionConfig* config, QString settingsFile); // Connect the FunctionConfig to the Widget. + void loadSettings(QString settingsFile); // Load the FunctionConfig (points) from the INI-file + void saveSettings(QString settingsFile); // Save the FunctionConfig (points) to the INI-file + +signals: + void CurveChanged(bool); + +public slots: + void setmaxInputEGU(int); + void setmaxOutputEGU(int); + void setpixPerEGU_Input(int); + void setpixPerEGU_Output(int); + void setgridDistEGU_Input(int); + void setgridDistEGU_Output(int); + + void setColorBezier(QColor); + void setColorBackground(QColor); + void setInputEGU(QString); + void setOutputEGU(QString); + void setCaption(QString); + + void resetCurve() { + qDebug() << "QFunctionConfigurator::resetCurve = " << strSettingsFile; + loadSettings( strSettingsFile ); + } + +protected slots: + void paintEvent(QPaintEvent *e); + void mousePressEvent(QMouseEvent *e); + void mouseMoveEvent(QMouseEvent *e); + void mouseReleaseEvent(QMouseEvent *e); + +protected: + void drawBackground(const QRectF &rect); + void drawFunction(const QRectF &rect); + void drawPoint(QPainter *painter, const QPointF &pt, QColor colBG ); + void drawLine(QPainter *painter, const QPointF &start, const QPointF &end, QPen pen); + bool markContains(const QPointF &pt, const QPointF &coord) const; +// bool withinRange( const QPointF &coord ) const; + bool withinRect( const QPointF &coord, const QRectF &rect ) const; + +protected: + virtual void resizeEvent(QResizeEvent *); + +private: + QRectF range; // The actual rectangle for the Bezier-curve + QPointF lastPoint; // The right-most point of the Function + QPointF normalizePoint (QPointF point) const; // Convert the graphical Point to a real-life Point + QPointF graphicalizePoint (QPointF point, QString source = "") const; // Convert the Point to a graphical Point + + QPointF *moving; + int movingPoint; + + int MaxInput; // Maximum input limit + int MaxOutput; // Maximum output limit + int pPerEGU_Input; // Number of pixels, per EGU of Input + int pPerEGU_Output; // Number of pixels, per EGU of Output + int gDistEGU_Input; // Distance of the grid, in EGU of Input + int gDistEGU_Output; // Distance of the grid, in EGU of Output + + QColor colBezier; // Color of Bezier curve + QColor colBackground; // Color of widget background + QString strInputEGU; // Engineering Units input (vertical axis) + QString strOutputEGU; // Engineering Units output (horizontal axis) + QString strCaption; // Caption of the graph + QString strSettingsFile; // Name of last read INI-file + QPushButton *btnReset; // Reset Curve + + bool _draw_background; // Flag to determine if the background should be (re-)drawn on the QPixmap + QPixmap _background; // Image of the static parts (axis, lines, etc.) + bool _draw_function; // Flag to determine if the function should be (re-)drawn on the QPixmap + QPixmap _function; // Image of the function (static unless edited by the user) + + // + // Properties of the CurveConfigurator Widget + // + QString _title; // Title do display in Widget and to load Settings + FunctionConfig* _config; + QList _points; // Function-points + QList _draw_points; // Curve-points needed for drawing + HANDLE _mutex; +}; + +#endif // QFUNCTIONCONFIGURATOR_H diff --git a/qfunctionconfigurator/QFunctionConfigurator/qfunctionconfiguratorplugin.cpp b/qfunctionconfigurator/QFunctionConfigurator/qfunctionconfiguratorplugin.cpp new file mode 100644 index 00000000..44e9f831 --- /dev/null +++ b/qfunctionconfigurator/QFunctionConfigurator/qfunctionconfiguratorplugin.cpp @@ -0,0 +1,146 @@ +/******************************************************************************** +* FaceTrackNoIR This program is a private project of some enthusiastic * +* gamers from Holland, who don't like to pay much for * +* head-tracking. * +* * +* Copyright (C) 2012 Wim Vriend (Developing) * +* Ron Hendriks (Researching and Testing) * +* * +* Homepage http://facetracknoir.sourceforge.net/home/default.htm * +* * +* This program is free software; you can redistribute it and/or modify it * +* under the terms of the GNU General Public License as published by the * +* Free Software Foundation; either version 3 of the License, or (at your * +* option) any later version. * +* * +* This program is distributed in the hope that it will be useful, but * +* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * +* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * +* more details. * +* * +* You should have received a copy of the GNU General Public License along * +* with this program; if not, see . * +* * +* The FunctionConfigurator was made by Stanislaw Halik, and adapted to * +* FaceTrackNoIR. * +* * +* All credits for this nice piece of code should go to Stanislaw. * +* * +* Copyright (c) 2011-2012, Stanislaw Halik * +* Permission to use, copy, modify, and/or distribute this * +* software for any purpose with or without fee is hereby granted, * +* provided that the above copyright notice and this permission * +* notice appear in all copies. * +********************************************************************************/ +#include "qfunctionconfigurator.h" + +#include +#include "qfunctionconfiguratorplugin.h" + + +QFunctionConfiguratorPlugin::QFunctionConfiguratorPlugin(QObject *parent) + : QObject(parent) +{ + initialized = false; +} + +void QFunctionConfiguratorPlugin::initialize(QDesignerFormEditorInterface */*core*/) +{ + if (initialized) + return; + + initialized = true; +} + +bool QFunctionConfiguratorPlugin::isInitialized() const +{ + return initialized; +} + +QWidget *QFunctionConfiguratorPlugin::createWidget(QWidget *parent) +{ + return new QFunctionConfigurator(parent); +} + +QString QFunctionConfiguratorPlugin::name() const +{ + return "QFunctionConfigurator"; +} + +QString QFunctionConfiguratorPlugin::group() const +{ + return "My Plugins"; +} + +QIcon QFunctionConfiguratorPlugin::icon() const +{ + return QIcon(); +} + +QString QFunctionConfiguratorPlugin::toolTip() const +{ + return QString(); +} + +QString QFunctionConfiguratorPlugin::whatsThis() const +{ + return QString(); +} + +bool QFunctionConfiguratorPlugin::isContainer() const +{ + return false; +} + +QString QFunctionConfiguratorPlugin::domXml() const +{ + return "\n" + " \n" + " \n" + " 0\n" + " 0\n" + " 161\n" + " 220\n" + " \n" + " \n" + " \n" + " \n" + " 255\n" + " 170\n" + " 0\n" + " \n" + " \n" + " \n" + " \n" + " 192\n" + " 192\n" + " 192\n" + " \n" + " \n" + " \n" + " Input Yaw (degr.)\n" + " \n" + " \n" + " Output Yaw (degr.)\n" + " \n" + " \n" + " 50\n" + " \n" + " \n" + " 180\n" + " \n" + " \n" + " 2\n" + " \n" + " \n" + " 1\n" + " \n" + "\n"; +} + +QString QFunctionConfiguratorPlugin::includeFile() const +{ + return "qfunctionconfigurator.h"; +} + +Q_EXPORT_PLUGIN2(qfunctionconfigurator, QFunctionConfiguratorPlugin) diff --git a/qfunctionconfigurator/QFunctionConfigurator/qfunctionconfiguratorplugin.h b/qfunctionconfigurator/QFunctionConfigurator/qfunctionconfiguratorplugin.h new file mode 100644 index 00000000..31bf0b2e --- /dev/null +++ b/qfunctionconfigurator/QFunctionConfigurator/qfunctionconfiguratorplugin.h @@ -0,0 +1,30 @@ +#ifndef QFUNCTIONCONFIGURATORPLUGIN_H +#define QFUNCTIONCONFIGURATORPLUGIN_H + +#include + +class QFunctionConfiguratorPlugin : public QObject, public QDesignerCustomWidgetInterface +{ + Q_OBJECT + Q_INTERFACES(QDesignerCustomWidgetInterface) + +public: + QFunctionConfiguratorPlugin(QObject *parent = 0); + + bool isContainer() const; + bool isInitialized() const; + QIcon icon() const; + QString domXml() const; + QString group() const; + QString includeFile() const; + QString name() const; + QString toolTip() const; + QString whatsThis() const; + QWidget *createWidget(QWidget *parent); + void initialize(QDesignerFormEditorInterface *core); + +private: + bool initialized; +}; + +#endif // QFUNCTIONCONFIGURATORPLUGIN_H diff --git a/qfunctionconfigurator/QFunctionConfigurator_vc9.sln b/qfunctionconfigurator/QFunctionConfigurator_vc9.sln new file mode 100644 index 00000000..3e82962f --- /dev/null +++ b/qfunctionconfigurator/QFunctionConfigurator_vc9.sln @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 10.00 +# Visual Studio 2008 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "QFunctionConfigurator", "QFunctionConfigurator\QFunctionConfigurator_vc9.vcproj", "{2527B683-7EFC-4D51-B25A-843668649C54}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {2527B683-7EFC-4D51-B25A-843668649C54}.Debug|Win32.ActiveCfg = Debug|Win32 + {2527B683-7EFC-4D51-B25A-843668649C54}.Debug|Win32.Build.0 = Debug|Win32 + {2527B683-7EFC-4D51-B25A-843668649C54}.Release|Win32.ActiveCfg = Release|Win32 + {2527B683-7EFC-4D51-B25A-843668649C54}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal -- cgit v1.2.3