From 1b6606bc487c566a4f6e9e5423fd7d81debb2ccf Mon Sep 17 00:00:00 2001 From: lm Date: Sun, 10 Jul 2011 19:39:45 +0200 Subject: [PATCH] Fixed bogus gitignore file --- .gitignore | 1 - src/Waypoint.cc | 5 +- src/Waypoint.h | 8 + src/libs/opmapcontrol/src/core/opmaps.h | 2 +- src/libs/opmapcontrol/src/internals/core.cpp | 17 +- .../src/mapwidget/mapgraphicitem.h | 3 +- .../opmapcontrol/src/mapwidget/opmapwidget.h | 3 +- .../src/mapwidget/waypointitem.cpp | 54 ++- .../opmapcontrol/src/mapwidget/waypointitem.h | 17 +- .../src/mapwidget/waypointlineitem.cpp | 10 +- .../src/mapwidget/waypointlineitem.h | 2 + src/libs/qtconcurrent/QtConcurrentTools | 31 ++ src/libs/qtconcurrent/multitask.h | 196 +++++++++ src/libs/qtconcurrent/qtconcurrent.pri | 1 + src/libs/qtconcurrent/qtconcurrent.pro | 10 + src/libs/qtconcurrent/qtconcurrent_global.h | 40 ++ src/libs/qtconcurrent/runextensions.h | 393 ++++++++++++++++++ src/libs/utils/qtcassert.h | 44 ++ src/libs/utils/qtcolorbutton.cpp | 285 +++++++++++++ src/libs/utils/qtcolorbutton.h | 78 ++++ src/libs/utils/utils_external.pri | 3 +- src/ui/map/QGCMapWidget.cc | 17 +- src/ui/map/Waypoint2DIcon.cc | 129 ++++-- src/ui/map/Waypoint2DIcon.h | 13 +- 24 files changed, 1265 insertions(+), 97 deletions(-) create mode 100644 src/libs/qtconcurrent/QtConcurrentTools create mode 100644 src/libs/qtconcurrent/multitask.h create mode 100644 src/libs/qtconcurrent/qtconcurrent.pri create mode 100644 src/libs/qtconcurrent/qtconcurrent.pro create mode 100644 src/libs/qtconcurrent/qtconcurrent_global.h create mode 100644 src/libs/qtconcurrent/runextensions.h create mode 100644 src/libs/utils/qtcassert.h create mode 100644 src/libs/utils/qtcolorbutton.cpp create mode 100644 src/libs/utils/qtcolorbutton.h diff --git a/.gitignore b/.gitignore index a294f37fb..886849d6f 100644 --- a/.gitignore +++ b/.gitignore @@ -8,7 +8,6 @@ Info.plist obj *.log *~ -*qtc* bin/*.exe bin/*.txt bin/mac diff --git a/src/Waypoint.cc b/src/Waypoint.cc index a210d083d..48efb6978 100644 --- a/src/Waypoint.cc +++ b/src/Waypoint.cc @@ -49,7 +49,8 @@ Waypoint::Waypoint(quint16 _id, double _x, double _y, double _z, double _param1, param1(_param1), param2(_param2), name(QString("WP%1").arg(id, 2, 10, QChar('0'))), - description(_description) + description(_description), + reachedTime(0) { } @@ -79,7 +80,7 @@ void Waypoint::save(QTextStream &saveStream) bool Waypoint::load(QTextStream &loadStream) { const QStringList &wpParams = loadStream.readLine().split("\t"); - if (wpParams.size() == 13) { + if (wpParams.size() == 12) { this->id = wpParams[0].toInt(); this->current = (wpParams[1].toInt() == 1 ? true : false); this->frame = (MAV_FRAME) wpParams[2].toInt(); diff --git a/src/Waypoint.h b/src/Waypoint.h index 3de577c9b..d02981149 100644 --- a/src/Waypoint.h +++ b/src/Waypoint.h @@ -37,6 +37,7 @@ This file is part of the PIXHAWK project #include #include #include "QGCMAVLink.h" +#include "QGC.h" class Waypoint : public QObject { @@ -145,6 +146,7 @@ protected: int turns; QString name; QString description; + quint64 reachedTime; public slots: void setId(quint16 id); @@ -177,6 +179,12 @@ public slots: void setHoldTime(double holdTime); /** @brief Number of turns for loiter waypoints */ void setTurns(int turns); + /** @brief Set waypoint as reached */ + void setReached() { reachedTime = QGC::groundTimeMilliseconds(); } + /** @brief Wether this waypoint has been reached yet */ + bool isReached() { return (reachedTime > 0); } + /** @brief Get the time this waypoint was reached */ + quint64 getReachedTime() { return reachedTime; } signals: /** @brief Announces a change to the waypoint data */ diff --git a/src/libs/opmapcontrol/src/core/opmaps.h b/src/libs/opmapcontrol/src/core/opmaps.h index f94f3fa06..723f967f4 100644 --- a/src/libs/opmapcontrol/src/core/opmaps.h +++ b/src/libs/opmapcontrol/src/core/opmaps.h @@ -78,7 +78,7 @@ namespace core { // PureImageCache ImageCacheLocal;//TODO Criar acesso Get Set TileCacheQueue TileDBcacheQueue; OPMaps(); - OPMaps(OPMaps const&){} + //OPMaps(OPMaps const&){} OPMaps& operator=(OPMaps const&){ return *this; } static OPMaps* m_pInstance; diagnostics diag; diff --git a/src/libs/opmapcontrol/src/internals/core.cpp b/src/libs/opmapcontrol/src/internals/core.cpp index 8a3fafc05..a059583c7 100644 --- a/src/libs/opmapcontrol/src/internals/core.cpp +++ b/src/libs/opmapcontrol/src/internals/core.cpp @@ -33,8 +33,21 @@ qlonglong internals::Core::debugcounter=0; using namespace projections; namespace internals { - Core::Core():MouseWheelZooming(false),currentPosition(0,0),currentPositionPixel(0,0),LastLocationInBounds(-1,-1),sizeOfMapArea(0,0) - ,minOfTiles(0,0),maxOfTiles(0,0),zoom(0),isDragging(false),TooltipTextPadding(10,10),loaderLimit(5),maxzoom(21),started(false),runningThreads(0) + Core::Core() : + MouseWheelZooming(false), + currentPosition(0,0), + currentPositionPixel(0,0), + LastLocationInBounds(-1,-1), + sizeOfMapArea(0,0), + minOfTiles(0,0), + maxOfTiles(0,0), + zoom(0), + isDragging(false), + TooltipTextPadding(10,10), + loaderLimit(5), + maxzoom(21), + runningThreads(0), + started(false) { mousewheelzoomtype=MouseWheelZoomType::MousePositionAndCenter; SetProjection(new MercatorProjection()); diff --git a/src/libs/opmapcontrol/src/mapwidget/mapgraphicitem.h b/src/libs/opmapcontrol/src/mapwidget/mapgraphicitem.h index 5fd18c981..da846d31a 100644 --- a/src/libs/opmapcontrol/src/mapwidget/mapgraphicitem.h +++ b/src/libs/opmapcontrol/src/mapwidget/mapgraphicitem.h @@ -169,6 +169,7 @@ namespace mapcontrol internals::PointLatLng selectionStart; internals::PointLatLng selectionEnd; double zoomReal; + qreal rotation; double zoomDigi; QRectF maprect; bool isSelected; @@ -176,7 +177,7 @@ namespace mapcontrol QPixmap dragons; void SetIsMouseOverMarker(bool const& value){isMouseOverMarker = value;} - qreal rotation; + /** * @brief Creates a rectangle that represents the "view" of the cuurent map, to compensate * rotation diff --git a/src/libs/opmapcontrol/src/mapwidget/opmapwidget.h b/src/libs/opmapcontrol/src/mapwidget/opmapwidget.h index f5e596ed8..ee97bd7b2 100644 --- a/src/libs/opmapcontrol/src/mapwidget/opmapwidget.h +++ b/src/libs/opmapcontrol/src/mapwidget/opmapwidget.h @@ -391,8 +391,9 @@ namespace mapcontrol bool showuav; bool showhome; QTimer * diagTimer; - QGraphicsTextItem * diagGraphItem; bool showDiag; + QGraphicsTextItem * diagGraphItem; + private slots: void diagRefresh(); // WayPointItem* item;//apagar diff --git a/src/libs/opmapcontrol/src/mapwidget/waypointitem.cpp b/src/libs/opmapcontrol/src/mapwidget/waypointitem.cpp index 20dd644cb..89a5cb80d 100644 --- a/src/libs/opmapcontrol/src/mapwidget/waypointitem.cpp +++ b/src/libs/opmapcontrol/src/mapwidget/waypointitem.cpp @@ -27,7 +27,7 @@ #include "waypointitem.h" namespace mapcontrol { - WayPointItem::WayPointItem(const internals::PointLatLng &coord,double const& altitude, MapGraphicItem *map):coord(coord),reached(false),description(""),shownumber(true),isDragging(false),altitude(altitude),heading(0),map(map) + WayPointItem::WayPointItem(const internals::PointLatLng &coord,double const& altitude, MapGraphicItem *map):coord(coord),reached(false),description(""),shownumber(true),isDragging(false),altitude(altitude),heading(0),map(map),autoreachedEnabled(true) { text=0; numberI=0; @@ -169,28 +169,53 @@ namespace mapcontrol } void WayPointItem::SetReached(const bool &value) { - reached=value; - emit WPValuesChanged(this); - if(value) - picture.load(QString::fromUtf8(":/markers/images/bigMarkerGreen.png")); - else - picture.load(QString::fromUtf8(":/markers/images/marker.png")); - this->update(); - + if (autoreachedEnabled) + { + reached=value; + emit WPValuesChanged(this); + if(value) + picture.load(QString::fromUtf8(":/markers/images/bigMarkerGreen.png")); + else + picture.load(QString::fromUtf8(":/markers/images/marker.png")); + this->update(); + } } void WayPointItem::SetShowNumber(const bool &value) { +// shownumber=value; +// if((numberI==0) && value) +// { +// numberI=new QGraphicsSimpleTextItem(this); +// numberIBG=new QGraphicsRectItem(this); +// numberIBG->setBrush(Qt::white); +// numberIBG->setOpacity(0.5); +// numberI->setZValue(3); +// numberI->setPen(QPen(Qt::blue)); +// numberI->setPos(0,-13-picture.height()); +// numberIBG->setPos(0,-13-picture.height()); +// numberI->setText(QString::number(number)); +// numberIBG->setRect(numberI->boundingRect().adjusted(-2,0,1,0)); +// } +// else if (!value && numberI) +// { +// delete numberI; +// delete numberIBG; +// } +// this->update(); + + + shownumber=value; if((numberI==0) && value) { numberI=new QGraphicsSimpleTextItem(this); numberIBG=new QGraphicsRectItem(this); - numberIBG->setBrush(Qt::white); + numberIBG->setBrush(Qt::black); numberIBG->setOpacity(0.5); numberI->setZValue(3); - numberI->setPen(QPen(Qt::blue)); - numberI->setPos(0,-13-picture.height()); - numberIBG->setPos(0,-13-picture.height()); + numberI->setPen(QPen(Qt::white)); + numberI->setPos(18,-picture.height()/2-2); + numberIBG->setPos(18,-picture.height()/2-2); numberI->setText(QString::number(number)); numberIBG->setRect(numberI->boundingRect().adjusted(-2,0,1,0)); } @@ -200,6 +225,9 @@ namespace mapcontrol delete numberIBG; } this->update(); + + + } void WayPointItem::WPDeleted(const int &onumber) { diff --git a/src/libs/opmapcontrol/src/mapwidget/waypointitem.h b/src/libs/opmapcontrol/src/mapwidget/waypointitem.h index 793e995d1..e732211dc 100644 --- a/src/libs/opmapcontrol/src/mapwidget/waypointitem.h +++ b/src/libs/opmapcontrol/src/mapwidget/waypointitem.h @@ -121,7 +121,7 @@ public: * * @param value */ - void SetShowNumber(bool const& value); + virtual void SetShowNumber(bool const& value); /** * @brief Returns the WayPoint altitude in meters * @@ -162,8 +162,12 @@ protected: void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ); MapGraphicItem* map; - -private: + bool autoreachedEnabled; ///< If the waypoint should change appearance once it has been reached + QGraphicsSimpleTextItem* text; + QGraphicsRectItem* textBG; + QGraphicsSimpleTextItem* numberI; + QGraphicsRectItem* numberIBG; + QTransform transf; internals::PointLatLng coord;//coordinates of this WayPoint bool reached; QString description; @@ -173,13 +177,6 @@ private: float heading; int number; - - QGraphicsSimpleTextItem* text; - QGraphicsRectItem* textBG; - QGraphicsSimpleTextItem* numberI; - QGraphicsRectItem* numberIBG; - QTransform transf; - public slots: /** * @brief Called when a WayPoint is deleted diff --git a/src/libs/opmapcontrol/src/mapwidget/waypointlineitem.cpp b/src/libs/opmapcontrol/src/mapwidget/waypointlineitem.cpp index 67b448f00..a2d2e5f7d 100644 --- a/src/libs/opmapcontrol/src/mapwidget/waypointlineitem.cpp +++ b/src/libs/opmapcontrol/src/mapwidget/waypointlineitem.cpp @@ -3,12 +3,13 @@ namespace mapcontrol { WaypointLineItem::WaypointLineItem(WayPointItem* wp1, WayPointItem* wp2, QColor color, mapcontrol::MapGraphicItem* map) : + QGraphicsLineItem(map), wp1(wp1), wp2(wp2), map(map) { // Make sure this stick to the map - this->setFlag(QGraphicsItem::ItemIgnoresTransformations,true); + //this->setFlag(QGraphicsItem::Item,true); setParentItem(map); // Set up the pen for this icon with the UAV color @@ -30,6 +31,8 @@ WaypointLineItem::WaypointLineItem(WayPointItem* wp1, WayPointItem* wp2, QColor // Delete line if one of the waypoints get deleted connect(wp1, SIGNAL(destroyed()), this, SLOT(deleteLater())); connect(wp2, SIGNAL(destroyed()), this, SLOT(deleteLater())); + + // Map Zoom and move } void WaypointLineItem::updateWPValues(WayPointItem* waypoint) @@ -50,4 +53,9 @@ void WaypointLineItem::updateWPValues(WayPointItem* waypoint) } } +int WaypointLineItem::type()const +{ + return Type; +} + } diff --git a/src/libs/opmapcontrol/src/mapwidget/waypointlineitem.h b/src/libs/opmapcontrol/src/mapwidget/waypointlineitem.h index 1fecd62c0..e138700b5 100644 --- a/src/libs/opmapcontrol/src/mapwidget/waypointlineitem.h +++ b/src/libs/opmapcontrol/src/mapwidget/waypointlineitem.h @@ -10,7 +10,9 @@ class WaypointLineItem : public QObject,public QGraphicsLineItem Q_OBJECT Q_INTERFACES(QGraphicsItem) public: + enum { Type = UserType + 7 }; WaypointLineItem(WayPointItem* wp1, WayPointItem* wp2, QColor color=QColor(Qt::red), MapGraphicItem* parent=0); + int type() const; public slots: /** diff --git a/src/libs/qtconcurrent/QtConcurrentTools b/src/libs/qtconcurrent/QtConcurrentTools new file mode 100644 index 000000000..b8c36c1dd --- /dev/null +++ b/src/libs/qtconcurrent/QtConcurrentTools @@ -0,0 +1,31 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** Commercial Usage +** +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Nokia. +** +** GNU Lesser General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://qt.nokia.com/contact. +** +**************************************************************************/ + +#include "qtconcurrent/multitask.h" +#include "qtconcurrent/runextensions.h" diff --git a/src/libs/qtconcurrent/multitask.h b/src/libs/qtconcurrent/multitask.h new file mode 100644 index 000000000..18a748c0e --- /dev/null +++ b/src/libs/qtconcurrent/multitask.h @@ -0,0 +1,196 @@ +/** + ****************************************************************************** + * + * @file multitask.h + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. + * Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009. + * @brief + * @see The GNU Public License (GPL) Version 3 + * @defgroup + * @{ + * + *****************************************************************************/ +/* + * 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, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef MULTITASK_H +#define MULTITASK_H + +#include "qtconcurrent_global.h" +#include "runextensions.h" + +#include +#include +#include +#include +#include +#include + +#include + +QT_BEGIN_NAMESPACE + +namespace QtConcurrent { + +class QTCONCURRENT_EXPORT MultiTaskBase : public QObject, public QRunnable +{ + Q_OBJECT +protected slots: + virtual void cancelSelf() = 0; + virtual void setFinished() = 0; + virtual void setProgressRange(int min, int max) = 0; + virtual void setProgressValue(int value) = 0; + virtual void setProgressText(QString value) = 0; +}; + +template +class MultiTask : public MultiTaskBase +{ +public: + MultiTask(void (Class::*fn)(QFutureInterface &), const QList &objects) + : fn(fn), + objects(objects) + { + maxProgress = 100*objects.size(); + } + + QFuture future() + { + futureInterface.reportStarted(); + return futureInterface.future(); + } + + void run() + { + QThreadPool::globalInstance()->releaseThread(); + futureInterface.setProgressRange(0, maxProgress); + foreach (Class *object, objects) { + QFutureWatcher *watcher = new QFutureWatcher(); + watchers.insert(object, watcher); + finished.insert(watcher, false); + connect(watcher, SIGNAL(finished()), this, SLOT(setFinished())); + connect(watcher, SIGNAL(progressRangeChanged(int,int)), this, SLOT(setProgressRange(int,int))); + connect(watcher, SIGNAL(progressValueChanged(int)), this, SLOT(setProgressValue(int))); + connect(watcher, SIGNAL(progressTextChanged(QString)), this, SLOT(setProgressText(QString))); + watcher->setFuture(QtConcurrent::run(fn, object)); + } + selfWatcher = new QFutureWatcher(); + connect(selfWatcher, SIGNAL(canceled()), this, SLOT(cancelSelf())); + selfWatcher->setFuture(futureInterface.future()); + loop = new QEventLoop; + loop->exec(); + futureInterface.reportFinished(); + QThreadPool::globalInstance()->reserveThread(); + qDeleteAll(watchers.values()); + delete selfWatcher; + delete loop; + } +protected: + void cancelSelf() + { + foreach (QFutureWatcher *watcher, watchers) + watcher->future().cancel(); + } + + void setFinished() + { + updateProgress(); + QFutureWatcher *watcher = static_cast *>(sender()); + if (finished.contains(watcher)) + finished[watcher] = true; + bool allFinished = true; + const QList finishedValues = finished.values(); + foreach (bool isFinished, finishedValues) { + if (!isFinished) { + allFinished = false; + break; + } + } + if (allFinished) + loop->quit(); + } + + void setProgressRange(int min, int max) + { + Q_UNUSED(min) + Q_UNUSED(max) + updateProgress(); + } + + void setProgressValue(int value) + { + Q_UNUSED(value) + updateProgress(); + } + + void setProgressText(QString value) + { + Q_UNUSED(value) + updateProgressText(); + } +private: + void updateProgress() + { + int progressSum = 0; + const QList *> watchersValues = watchers.values(); + foreach (QFutureWatcher *watcher, watchersValues) { + if (watcher->progressMinimum() == watcher->progressMaximum()) { + if (watcher->future().isFinished() && !watcher->future().isCanceled()) + progressSum += 100; + } else { + progressSum += 100*(watcher->progressValue()-watcher->progressMinimum())/(watcher->progressMaximum()-watcher->progressMinimum()); + } + } + futureInterface.setProgressValue(progressSum); + } + + void updateProgressText() + { + QString text; + const QList *> watchersValues = watchers.values(); + foreach (QFutureWatcher *watcher, watchersValues) { + if (!watcher->progressText().isEmpty()) + text += watcher->progressText() + "\n"; + } + text = text.trimmed(); + futureInterface.setProgressValueAndText(futureInterface.progressValue(), text); + } + + QFutureInterface futureInterface; + void (Class::*fn)(QFutureInterface &); + QList objects; + + QFutureWatcher *selfWatcher; + QMap *> watchers; + QMap *, bool> finished; + QEventLoop *loop; + int maxProgress; +}; + +template +QFuture run(void (Class::*fn)(QFutureInterface &), const QList &objects, int priority = 0) +{ + MultiTask *task = new MultiTask(fn, objects); + QFuture future = task->future(); + QThreadPool::globalInstance()->start(task, priority); + return future; +} + +} // namespace QtConcurrent + +QT_END_NAMESPACE + +#endif // MULTITASK_H diff --git a/src/libs/qtconcurrent/qtconcurrent.pri b/src/libs/qtconcurrent/qtconcurrent.pri new file mode 100644 index 000000000..57929a4cf --- /dev/null +++ b/src/libs/qtconcurrent/qtconcurrent.pri @@ -0,0 +1 @@ +LIBS *= -l$$qtLibraryTarget(QtConcurrent) diff --git a/src/libs/qtconcurrent/qtconcurrent.pro b/src/libs/qtconcurrent/qtconcurrent.pro new file mode 100644 index 000000000..ef29d9188 --- /dev/null +++ b/src/libs/qtconcurrent/qtconcurrent.pro @@ -0,0 +1,10 @@ +TEMPLATE = lib +TARGET = QtConcurrent +DEFINES += BUILD_QTCONCURRENT + +include(../../openpilotgcslibrary.pri) + +HEADERS += \ + qtconcurrent_global.h \ + multitask.h \ + runextensions.h diff --git a/src/libs/qtconcurrent/qtconcurrent_global.h b/src/libs/qtconcurrent/qtconcurrent_global.h new file mode 100644 index 000000000..ba8c071f3 --- /dev/null +++ b/src/libs/qtconcurrent/qtconcurrent_global.h @@ -0,0 +1,40 @@ +/** + ****************************************************************************** + * + * @file qtconcurrent_global.h + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. + * Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009. + * @brief + * @see The GNU Public License (GPL) Version 3 + * @defgroup + * @{ + * + *****************************************************************************/ +/* + * 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, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef QTCONCURRENT_GLOBAL_H +#define QTCONCURRENT_GLOBAL_H + +#include + +#if defined(BUILD_QTCONCURRENT) +# define QTCONCURRENT_EXPORT Q_DECL_EXPORT +#else +# define QTCONCURRENT_EXPORT Q_DECL_IMPORT +#endif + +#endif // QTCONCURRENT_GLOBAL_H diff --git a/src/libs/qtconcurrent/runextensions.h b/src/libs/qtconcurrent/runextensions.h new file mode 100644 index 000000000..96f5c7dab --- /dev/null +++ b/src/libs/qtconcurrent/runextensions.h @@ -0,0 +1,393 @@ +/** + ****************************************************************************** + * + * @file runextensions.h + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. + * Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009. + * @brief + * @see The GNU Public License (GPL) Version 3 + * @defgroup + * @{ + * + *****************************************************************************/ +/* + * 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, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef QTCONCURRENT_RUNEX_H +#define QTCONCURRENT_RUNEX_H + +#include +#include +#include + +QT_BEGIN_NAMESPACE + +namespace QtConcurrent { + +template +class StoredInterfaceFunctionCall0 : public QRunnable +{ +public: + StoredInterfaceFunctionCall0(void (fn)(QFutureInterface &)) + : fn(fn) { } + + QFuture start() + { + futureInterface.reportStarted(); + QFuture future = futureInterface.future(); + QThreadPool::globalInstance()->start(this); + return future; + } + + void run() + { + fn(futureInterface); + futureInterface.reportFinished(); + } +private: + QFutureInterface futureInterface; + FunctionPointer fn; + +}; +template +class StoredInterfaceMemberFunctionCall0 : public QRunnable +{ +public: + StoredInterfaceMemberFunctionCall0(void (Class::*fn)(QFutureInterface &), Class *object) + : fn(fn), object(object) { } + + QFuture start() + { + futureInterface.reportStarted(); + QFuture future = futureInterface.future(); + QThreadPool::globalInstance()->start(this); + return future; + } + + void run() + { + (object->*fn)(futureInterface); + futureInterface.reportFinished(); + } +private: + QFutureInterface futureInterface; + FunctionPointer fn; + Class *object; + +}; + +template +class StoredInterfaceFunctionCall1 : public QRunnable +{ +public: + StoredInterfaceFunctionCall1(void (fn)(QFutureInterface &, Arg1), Arg1 arg1) + : fn(fn), arg1(arg1) { } + + QFuture start() + { + futureInterface.reportStarted(); + QFuture future = futureInterface.future(); + QThreadPool::globalInstance()->start(this); + return future; + } + + void run() + { + fn(futureInterface, arg1); + futureInterface.reportFinished(); + } +private: + QFutureInterface futureInterface; + FunctionPointer fn; + Arg1 arg1; +}; +template +class StoredInterfaceMemberFunctionCall1 : public QRunnable +{ +public: + StoredInterfaceMemberFunctionCall1(void (Class::*fn)(QFutureInterface &, Arg1), Class *object, Arg1 arg1) + : fn(fn), object(object), arg1(arg1) { } + + QFuture start() + { + futureInterface.reportStarted(); + QFuture future = futureInterface.future(); + QThreadPool::globalInstance()->start(this); + return future; + } + + void run() + { + (object->*fn)(futureInterface, arg1); + futureInterface.reportFinished(); + } +private: + QFutureInterface futureInterface; + FunctionPointer fn; + Class *object; + Arg1 arg1; +}; + +template +class StoredInterfaceFunctionCall2 : public QRunnable +{ +public: + StoredInterfaceFunctionCall2(void (fn)(QFutureInterface &, Arg1, Arg2), Arg1 arg1, Arg2 arg2) + : fn(fn), arg1(arg1), arg2(arg2) { } + + QFuture start() + { + futureInterface.reportStarted(); + QFuture future = futureInterface.future(); + QThreadPool::globalInstance()->start(this); + return future; + } + + void run() + { + fn(futureInterface, arg1, arg2); + futureInterface.reportFinished(); + } +private: + QFutureInterface futureInterface; + FunctionPointer fn; + Arg1 arg1; Arg2 arg2; +}; +template +class StoredInterfaceMemberFunctionCall2 : public QRunnable +{ +public: + StoredInterfaceMemberFunctionCall2(void (Class::*fn)(QFutureInterface &, Arg1, Arg2), Class *object, Arg1 arg1, Arg2 arg2) + : fn(fn), object(object), arg1(arg1), arg2(arg2) { } + + QFuture start() + { + futureInterface.reportStarted(); + QFuture future = futureInterface.future(); + QThreadPool::globalInstance()->start(this); + return future; + } + + void run() + { + (object->*fn)(futureInterface, arg1, arg2); + futureInterface.reportFinished(); + } +private: + QFutureInterface futureInterface; + FunctionPointer fn; + Class *object; + Arg1 arg1; Arg2 arg2; +}; + +template +class StoredInterfaceFunctionCall3 : public QRunnable +{ +public: + StoredInterfaceFunctionCall3(void (fn)(QFutureInterface &, Arg1, Arg2, Arg3), Arg1 arg1, Arg2 arg2, Arg3 arg3) + : fn(fn), arg1(arg1), arg2(arg2), arg3(arg3) { } + + QFuture start() + { + futureInterface.reportStarted(); + QFuture future = futureInterface.future(); + QThreadPool::globalInstance()->start(this); + return future; + } + + void run() + { + fn(futureInterface, arg1, arg2, arg3); + futureInterface.reportFinished(); + } +private: + QFutureInterface futureInterface; + FunctionPointer fn; + Arg1 arg1; Arg2 arg2; Arg3 arg3; +}; +template +class StoredInterfaceMemberFunctionCall3 : public QRunnable +{ +public: + StoredInterfaceMemberFunctionCall3(void (Class::*fn)(QFutureInterface &, Arg1, Arg2, Arg3), Class *object, Arg1 arg1, Arg2 arg2, Arg3 arg3) + : fn(fn), object(object), arg1(arg1), arg2(arg2), arg3(arg3) { } + + QFuture start() + { + futureInterface.reportStarted(); + QFuture future = futureInterface.future(); + QThreadPool::globalInstance()->start(this); + return future; + } + + void run() + { + (object->*fn)(futureInterface, arg1, arg2, arg3); + futureInterface.reportFinished(); + } +private: + QFutureInterface futureInterface; + FunctionPointer fn; + Class *object; + Arg1 arg1; Arg2 arg2; Arg3 arg3; +}; + +template +class StoredInterfaceFunctionCall4 : public QRunnable +{ +public: + StoredInterfaceFunctionCall4(void (fn)(QFutureInterface &, Arg1, Arg2, Arg3, Arg4), Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4) + : fn(fn), arg1(arg1), arg2(arg2), arg3(arg3), arg4(arg4) { } + + QFuture start() + { + futureInterface.reportStarted(); + QFuture future = futureInterface.future(); + QThreadPool::globalInstance()->start(this); + return future; + } + + void run() + { + fn(futureInterface, arg1, arg2, arg3, arg4); + futureInterface.reportFinished(); + } +private: + QFutureInterface futureInterface; + FunctionPointer fn; + Arg1 arg1; Arg2 arg2; Arg3 arg3; Arg4 arg4; +}; +template +class StoredInterfaceMemberFunctionCall4 : public QRunnable +{ +public: + StoredInterfaceMemberFunctionCall4(void (Class::*fn)(QFutureInterface &, Arg1, Arg2, Arg3, Arg4), Class *object, Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4) + : fn(fn), object(object), arg1(arg1), arg2(arg2), arg3(arg3), arg4(arg4) { } + + QFuture start() + { + futureInterface.reportStarted(); + QFuture future = futureInterface.future(); + QThreadPool::globalInstance()->start(this); + return future; + } + + void run() + { + (object->*fn)(futureInterface, arg1, arg2, arg3, arg4); + futureInterface.reportFinished(); + } +private: + QFutureInterface futureInterface; + FunctionPointer fn; + Class *object; + Arg1 arg1; Arg2 arg2; Arg3 arg3; Arg4 arg4; +}; + +template +class StoredInterfaceFunctionCall5 : public QRunnable +{ +public: + StoredInterfaceFunctionCall5(void (fn)(QFutureInterface &, Arg1, Arg2, Arg3, Arg4, Arg5), Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4, Arg5 arg5) + : fn(fn), arg1(arg1), arg2(arg2), arg3(arg3), arg4(arg4), arg5(arg5) { } + + QFuture start() + { + futureInterface.reportStarted(); + QFuture future = futureInterface.future(); + QThreadPool::globalInstance()->start(this); + return future; + } + + void run() + { + fn(futureInterface, arg1, arg2, arg3, arg4, arg5); + futureInterface.reportFinished(); + } +private: + QFutureInterface futureInterface; + FunctionPointer fn; + Arg1 arg1; Arg2 arg2; Arg3 arg3; Arg4 arg4; Arg5 arg5; +}; +template +class StoredInterfaceMemberFunctionCall5 : public QRunnable +{ +public: + StoredInterfaceMemberFunctionCall5(void (Class::*fn)(QFutureInterface &, Arg1, Arg2, Arg3, Arg4, Arg5), Class *object, Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4, Arg5 arg5) + : fn(fn), object(object), arg1(arg1), arg2(arg2), arg3(arg3), arg4(arg4), arg5(arg5) { } + + QFuture start() + { + futureInterface.reportStarted(); + QFuture future = futureInterface.future(); + QThreadPool::globalInstance()->start(this); + return future; + } + + void run() + { + (object->*fn)(futureInterface, arg1, arg2, arg3, arg4, arg5); + futureInterface.reportFinished(); + } +private: + QFutureInterface futureInterface; + FunctionPointer fn; + Class *object; + Arg1 arg1; Arg2 arg2; Arg3 arg3; Arg4 arg4; Arg5 arg5; +}; + +template +QFuture run(void (*functionPointer)(QFutureInterface &)) +{ + return (new StoredInterfaceFunctionCall0 &)>(functionPointer))->start(); +} +template +QFuture run(void (*functionPointer)(QFutureInterface &, Arg1), Arg1 arg1) +{ + return (new StoredInterfaceFunctionCall1 &, Arg1), Arg1>(functionPointer, arg1))->start(); +} +template +QFuture run(void (*functionPointer)(QFutureInterface &, Arg1, Arg2), Arg1 arg1, Arg2 arg2) +{ + return (new StoredInterfaceFunctionCall2 &, Arg1, Arg2), Arg1, Arg2>(functionPointer, arg1, arg2))->start(); +} +template +QFuture run(void (*functionPointer)(QFutureInterface &, Arg1, Arg2, Arg3), Arg1 arg1, Arg2 arg2, Arg3 arg3) +{ + return (new StoredInterfaceFunctionCall3 &, Arg1, Arg2, Arg3), Arg1, Arg2, Arg3>(functionPointer, arg1, arg2, arg3))->start(); +} +template +QFuture run(void (*functionPointer)(QFutureInterface &, Arg1, Arg2, Arg3, Arg4), Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4) +{ + return (new StoredInterfaceFunctionCall4 &, Arg1, Arg2, Arg3, Arg4), Arg1, Arg2, Arg3, Arg4>(functionPointer, arg1, arg2, arg3, arg4))->start(); +} +template +QFuture run(void (*functionPointer)(QFutureInterface &, Arg1, Arg2, Arg3, Arg4, Arg5), Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4, Arg5 arg5) +{ + return (new StoredInterfaceFunctionCall5 &, Arg1, Arg2, Arg3, Arg4, Arg5), Arg1, Arg2, Arg3, Arg4, Arg5>(functionPointer, arg1, arg2, arg3, arg4, arg5))->start(); +} + +template +QFuture run(void (Class::*fn)(QFutureInterface &), Class *object) +{ + return (new StoredInterfaceMemberFunctionCall0 &), Class>(fn, object))->start(); +} + +} // namespace QtConcurrent + +QT_END_NAMESPACE + +#endif // QTCONCURRENT_RUNEX_H diff --git a/src/libs/utils/qtcassert.h b/src/libs/utils/qtcassert.h new file mode 100644 index 000000000..01b10345b --- /dev/null +++ b/src/libs/utils/qtcassert.h @@ -0,0 +1,44 @@ +/** + ****************************************************************************** + * + * @file qtcassert.h + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. + * Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009. + * @brief + * @see The GNU Public License (GPL) Version 3 + * @defgroup + * @{ + * + *****************************************************************************/ +/* + * 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, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef QTC_ASSERT_H +#define QTC_ASSERT_H + +#include + +#define QTC_ASSERT_STRINGIFY_INTERNAL(x) #x +#define QTC_ASSERT_STRINGIFY(x) QTC_ASSERT_STRINGIFY_INTERNAL(x) + +// we do not use the 'do {...} while (0)' idiom here to be able to use +// 'break' and 'continue' as 'actions'. + +#define QTC_ASSERT(cond, action) \ + if(cond){}else{qDebug()<<"ASSERTION " #cond " FAILED AT " __FILE__ ":" QTC_ASSERT_STRINGIFY(__LINE__);action;} + +#endif // QTC_ASSERT_H + diff --git a/src/libs/utils/qtcolorbutton.cpp b/src/libs/utils/qtcolorbutton.cpp new file mode 100644 index 000000000..aab8d71c0 --- /dev/null +++ b/src/libs/utils/qtcolorbutton.cpp @@ -0,0 +1,285 @@ +/** + ****************************************************************************** + * + * @file qtcolorbutton.cpp + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. + * Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009. + * @brief + * @see The GNU Public License (GPL) Version 3 + * @defgroup + * @{ + * + *****************************************************************************/ +/* + * 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, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "qtcolorbutton.h" + +#include +#include +#include +#include +#include + +namespace Utils { + +class QtColorButtonPrivate +{ + QtColorButton *q_ptr; + Q_DECLARE_PUBLIC(QtColorButton) +public: + QColor m_color; +#ifndef QT_NO_DRAGANDDROP + QColor m_dragColor; + QPoint m_dragStart; + bool m_dragging; +#endif + bool m_backgroundCheckered; + bool m_alphaAllowed; + + void slotEditColor(); + QColor shownColor() const; + QPixmap generatePixmap() const; +}; + +void QtColorButtonPrivate::slotEditColor() +{ + QColor newColor; + if (m_alphaAllowed) { + bool ok; + const QRgb rgba = QColorDialog::getRgba(m_color.rgba(), &ok, q_ptr); + if (!ok) + return; + newColor = QColor::fromRgba(rgba); + } else { + newColor = QColorDialog::getColor(m_color, q_ptr); + if (!newColor.isValid()) + return; + } + if (newColor == q_ptr->color()) + return; + q_ptr->setColor(newColor); + emit q_ptr->colorChanged(m_color); +} + +QColor QtColorButtonPrivate::shownColor() const +{ +#ifndef QT_NO_DRAGANDDROP + if (m_dragging) + return m_dragColor; +#endif + return m_color; +} + +QPixmap QtColorButtonPrivate::generatePixmap() const +{ + QPixmap pix(24, 24); + + int pixSize = 20; + QBrush br(shownColor()); + + QPixmap pm(2 * pixSize, 2 * pixSize); + QPainter pmp(&pm); + pmp.fillRect(0, 0, pixSize, pixSize, Qt::lightGray); + pmp.fillRect(pixSize, pixSize, pixSize, pixSize, Qt::lightGray); + pmp.fillRect(0, pixSize, pixSize, pixSize, Qt::darkGray); + pmp.fillRect(pixSize, 0, pixSize, pixSize, Qt::darkGray); + pmp.fillRect(0, 0, 2 * pixSize, 2 * pixSize, shownColor()); + br = QBrush(pm); + + QPainter p(&pix); + int corr = 1; + QRect r = pix.rect().adjusted(corr, corr, -corr, -corr); + p.setBrushOrigin((r.width() % pixSize + pixSize) / 2 + corr, (r.height() % pixSize + pixSize) / 2 + corr); + p.fillRect(r, br); + + p.fillRect(r.width() / 4 + corr, r.height() / 4 + corr, + r.width() / 2, r.height() / 2, + QColor(shownColor().rgb())); + p.drawRect(pix.rect().adjusted(0, 0, -1, -1)); + + return pix; +} + +/////////////// + +QtColorButton::QtColorButton(QWidget *parent) + : QToolButton(parent) +{ + d_ptr = new QtColorButtonPrivate; + d_ptr->q_ptr = this; + d_ptr->m_dragging = false; + d_ptr->m_backgroundCheckered = true; + d_ptr->m_alphaAllowed = true; + + setAcceptDrops(true); + + connect(this, SIGNAL(clicked()), this, SLOT(slotEditColor())); + setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred)); +} + +QtColorButton::~QtColorButton() +{ + delete d_ptr; +} + +void QtColorButton::setColor(const QColor &color) +{ + if (d_ptr->m_color == color) + return; + d_ptr->m_color = color; + update(); +} + +QColor QtColorButton::color() const +{ + return d_ptr->m_color; +} + +void QtColorButton::setBackgroundCheckered(bool checkered) +{ + if (d_ptr->m_backgroundCheckered == checkered) + return; + d_ptr->m_backgroundCheckered = checkered; + update(); +} + +bool QtColorButton::isBackgroundCheckered() const +{ + return d_ptr->m_backgroundCheckered; +} + +void QtColorButton::setAlphaAllowed(bool allowed) +{ + d_ptr->m_alphaAllowed = allowed; +} + +bool QtColorButton::isAlphaAllowed() const +{ + return d_ptr->m_alphaAllowed; +} + +void QtColorButton::paintEvent(QPaintEvent *event) +{ + QToolButton::paintEvent(event); + if (!isEnabled()) + return; + + const int pixSize = 10; + QBrush br(d_ptr->shownColor()); + if (d_ptr->m_backgroundCheckered) { + QPixmap pm(2 * pixSize, 2 * pixSize); + QPainter pmp(&pm); + pmp.fillRect(0, 0, pixSize, pixSize, Qt::white); + pmp.fillRect(pixSize, pixSize, pixSize, pixSize, Qt::white); + pmp.fillRect(0, pixSize, pixSize, pixSize, Qt::black); + pmp.fillRect(pixSize, 0, pixSize, pixSize, Qt::black); + pmp.fillRect(0, 0, 2 * pixSize, 2 * pixSize, d_ptr->shownColor()); + br = QBrush(pm); + } + + QPainter p(this); + const int corr = 5; + QRect r = rect().adjusted(corr, corr, -corr, -corr); + p.setBrushOrigin((r.width() % pixSize + pixSize) / 2 + corr, (r.height() % pixSize + pixSize) / 2 + corr); + p.fillRect(r, br); + + //const int adjX = qRound(r.width() / 4.0); + //const int adjY = qRound(r.height() / 4.0); + //p.fillRect(r.adjusted(adjX, adjY, -adjX, -adjY), + // QColor(d_ptr->shownColor().rgb())); + /* + p.fillRect(r.adjusted(0, r.height() * 3 / 4, 0, 0), + QColor(d_ptr->shownColor().rgb())); + p.fillRect(r.adjusted(0, 0, 0, -r.height() * 3 / 4), + QColor(d_ptr->shownColor().rgb())); + */ + /* + const QColor frameColor0(0, 0, 0, qRound(0.2 * (0xFF - d_ptr->shownColor().alpha()))); + p.setPen(frameColor0); + p.drawRect(r.adjusted(adjX, adjY, -adjX - 1, -adjY - 1)); + */ + + const QColor frameColor1(0, 0, 0, 26); + p.setPen(frameColor1); + p.drawRect(r.adjusted(1, 1, -2, -2)); + const QColor frameColor2(0, 0, 0, 51); + p.setPen(frameColor2); + p.drawRect(r.adjusted(0, 0, -1, -1)); +} + +void QtColorButton::mousePressEvent(QMouseEvent *event) +{ +#ifndef QT_NO_DRAGANDDROP + if (event->button() == Qt::LeftButton) + d_ptr->m_dragStart = event->pos(); +#endif + QToolButton::mousePressEvent(event); +} + +void QtColorButton::mouseMoveEvent(QMouseEvent *event) +{ +#ifndef QT_NO_DRAGANDDROP + if (event->buttons() & Qt::LeftButton && + (d_ptr->m_dragStart - event->pos()).manhattanLength() > QApplication::startDragDistance()) { + QMimeData *mime = new QMimeData; + mime->setColorData(color()); + QDrag *drg = new QDrag(this); + drg->setMimeData(mime); + drg->setPixmap(d_ptr->generatePixmap()); + setDown(false); + event->accept(); + drg->start(); + return; + } +#endif + QToolButton::mouseMoveEvent(event); +} + +#ifndef QT_NO_DRAGANDDROP +void QtColorButton::dragEnterEvent(QDragEnterEvent *event) +{ + const QMimeData *mime = event->mimeData(); + if (!mime->hasColor()) + return; + + event->accept(); + d_ptr->m_dragColor = qvariant_cast(mime->colorData()); + d_ptr->m_dragging = true; + update(); +} + +void QtColorButton::dragLeaveEvent(QDragLeaveEvent *event) +{ + event->accept(); + d_ptr->m_dragging = false; + update(); +} + +void QtColorButton::dropEvent(QDropEvent *event) +{ + event->accept(); + d_ptr->m_dragging = false; + if (d_ptr->m_dragColor == color()) + return; + setColor(d_ptr->m_dragColor); + emit colorChanged(color()); +} +#endif + +} // namespace Utils + +#include "moc_qtcolorbutton.cpp" diff --git a/src/libs/utils/qtcolorbutton.h b/src/libs/utils/qtcolorbutton.h new file mode 100644 index 000000000..6dd5f5068 --- /dev/null +++ b/src/libs/utils/qtcolorbutton.h @@ -0,0 +1,78 @@ +/** + ****************************************************************************** + * + * @file qtcolorbutton.h + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. + * Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009. + * @brief + * @see The GNU Public License (GPL) Version 3 + * @defgroup + * @{ + * + *****************************************************************************/ +/* + * 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, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef QTCOLORBUTTON_H +#define QTCOLORBUTTON_H + +#include "utils_global.h" + +#include + +namespace Utils { + +class QTCREATOR_UTILS_EXPORT QtColorButton : public QToolButton +{ + Q_OBJECT + Q_PROPERTY(bool backgroundCheckered READ isBackgroundCheckered WRITE setBackgroundCheckered) + Q_PROPERTY(bool alphaAllowed READ isAlphaAllowed WRITE setAlphaAllowed) +public: + QtColorButton(QWidget *parent = 0); + ~QtColorButton(); + + bool isBackgroundCheckered() const; + void setBackgroundCheckered(bool checkered); + + bool isAlphaAllowed() const; + void setAlphaAllowed(bool allowed); + + QColor color() const; + +public slots: + void setColor(const QColor &color); + +signals: + void colorChanged(const QColor &color); +protected: + void paintEvent(QPaintEvent *event); + void mousePressEvent(QMouseEvent *event); + void mouseMoveEvent(QMouseEvent *event); +#ifndef QT_NO_DRAGANDDROP + void dragEnterEvent(QDragEnterEvent *event); + void dragLeaveEvent(QDragLeaveEvent *event); + void dropEvent(QDropEvent *event); +#endif +private: + class QtColorButtonPrivate *d_ptr; + friend class QtColorButtonPrivate; + Q_DISABLE_COPY(QtColorButton) + Q_PRIVATE_SLOT(d_ptr, void slotEditColor()) +}; + +} // namespace Utils + +#endif // QTCOLORBUTTON_H diff --git a/src/libs/utils/utils_external.pri b/src/libs/utils/utils_external.pri index a9dae3f59..74b0cb57d 100644 --- a/src/libs/utils/utils_external.pri +++ b/src/libs/utils/utils_external.pri @@ -55,8 +55,7 @@ HEADERS += abstractprocess.h \ xmlconfig.h win32 { -HEADERS += winutils.h \ - qwineventnotifier_p.h +HEADERS += winutils.h } FORMS += checkablemessagebox.ui \ diff --git a/src/ui/map/QGCMapWidget.cc b/src/ui/map/QGCMapWidget.cc index 1d1fa2581..05c969fb3 100644 --- a/src/ui/map/QGCMapWidget.cc +++ b/src/ui/map/QGCMapWidget.cc @@ -155,19 +155,18 @@ void QGCMapWidget::storeSettings() void QGCMapWidget::mouseDoubleClickEvent(QMouseEvent* event) { - OPMapWidget::mouseDoubleClickEvent(event); + // FIXME HACK! - currEditMode = EDIT_MODE_WAYPOINTS; - if (currEditMode == EDIT_MODE_WAYPOINTS) + //if (currEditMode == EDIT_MODE_WAYPOINTS) { // If a waypoint manager is available if (currWPManager) { // Create new waypoint - internals::PointLatLng pos = this->currentMousePosition(); + internals::PointLatLng pos = map->FromLocalToLatLng(event->pos().x(), event->pos().y()); Waypoint* wp = currWPManager->createWaypoint(); // wp->blockSignals(true); - wp->setFrame(MAV_FRAME_GLOBAL_RELATIVE_ALT); +// wp->setFrame(MAV_FRAME_GLOBAL_RELATIVE_ALT); wp->setLatitude(pos.Lat()); wp->setLongitude(pos.Lng()); wp->setAltitude(0); @@ -175,6 +174,7 @@ void QGCMapWidget::mouseDoubleClickEvent(QMouseEvent* event) // currWPManager->notifyOfChange(wp); } } + OPMapWidget::mouseDoubleClickEvent(event); } @@ -471,12 +471,13 @@ void QGCMapWidget::updateWaypoint(int uas, Waypoint* wp) if (prevIcon) { mapcontrol::WaypointLineItem* line = new mapcontrol::WaypointLineItem(prevIcon, icon, wpColor, map); + line->setParentItem(map); QGraphicsItemGroup* group = waypointLines.value(uas, NULL); if (group) { group->addToGroup(line); + group->setParentItem(map); } - line->setVisible(true); } } } else { @@ -588,13 +589,13 @@ void QGCMapWidget::updateWaypointList(int uas) QColor wpColor(Qt::red); if (uasInstance) wpColor = uasInstance->getColor(); mapcontrol::WaypointLineItem* line = new mapcontrol::WaypointLineItem(prevIcon, currIcon, wpColor, map); + line->setParentItem(map); QGraphicsItemGroup* group = waypointLines.value(uas, NULL); if (group) { group->addToGroup(line); - qDebug() << "ADDED LINE!"; + group->setParentItem(map); } - line->setVisible(true); } prevIcon = currIcon; } diff --git a/src/ui/map/Waypoint2DIcon.cc b/src/ui/map/Waypoint2DIcon.cc index f4b30a6d2..ab85b4463 100644 --- a/src/ui/map/Waypoint2DIcon.cc +++ b/src/ui/map/Waypoint2DIcon.cc @@ -1,6 +1,7 @@ #include "Waypoint2DIcon.h" #include #include "opmapcontrol.h" +#include "QGC.h" Waypoint2DIcon::Waypoint2DIcon(mapcontrol::MapGraphicItem* map, mapcontrol::OPMapWidget* parent, qreal latitude, qreal longitude, qreal altitude, int listindex, QString name, QString description, int radius) : mapcontrol::WayPointItem(internals::PointLatLng(latitude, longitude), altitude, description, map), @@ -13,10 +14,11 @@ Waypoint2DIcon::Waypoint2DIcon(mapcontrol::MapGraphicItem* map, mapcontrol::OPMa { SetHeading(0); SetNumber(listindex); - if (mypen == NULL) mypen = new QPen(Qt::red); -// drawIcon(mypen); this->setFlag(QGraphicsItem::ItemIgnoresTransformations,true); picture = QPixmap(radius+1, radius+1); + autoreachedEnabled = false; // In contrast to the use in OpenPilot, we don't + // want to let the map interfere with the actual mission logic + // wether a WP is reached depends solely on the UAV's state machine drawIcon(); } @@ -31,22 +33,16 @@ Waypoint2DIcon::Waypoint2DIcon(mapcontrol::MapGraphicItem* map, mapcontrol::OPMa { SetHeading(wp->getYaw()); SetNumber(listindex); - if (mypen == NULL) mypen = new QPen(Qt::red); -// drawIcon(mypen); this->setFlag(QGraphicsItem::ItemIgnoresTransformations,true); picture = QPixmap(radius+1, radius+1); + autoreachedEnabled = false; // In contrast to the use in OpenPilot, we don't + // want to let the map interfere with the actual mission logic + // wether a WP is reached depends solely on the UAV's state machine updateWaypoint(); } Waypoint2DIcon::~Waypoint2DIcon() { - delete &picture; -} - -void Waypoint2DIcon::setPen(QPen* pen) -{ - mypen = pen; -// drawIcon(pen); } void Waypoint2DIcon::SetHeading(float heading) @@ -114,45 +110,43 @@ QRectF Waypoint2DIcon::boundingRect() const return QRectF(-width,-height,2*width,2*height); } -void Waypoint2DIcon::SetReached(const bool &value) -{ - // DO NOTHING - Q_UNUSED(value); -// reached=value; -// emit WPValuesChanged(this); -// if(value) -// picture.load(QString::fromUtf8(":/markers/images/bigMarkerGreen.png")); -// else -// picture.load(QString::fromUtf8(":/markers/images/marker.png")); -// this->update(); - -} - void Waypoint2DIcon::drawIcon() { picture.fill(Qt::transparent); QPainter painter(&picture); - painter.setRenderHint(QPainter::TextAntialiasing, true); painter.setRenderHint(QPainter::Antialiasing, true); painter.setRenderHint(QPainter::HighQualityAntialiasing, true); + QFont font("Bitstream Vera Sans"); + int fontSize = picture.height()*0.8f; + font.setPixelSize(fontSize); + + QFontMetrics metrics = QFontMetrics(font); + int border = qMax(4, metrics.leading()); + painter.setFont(font); + painter.setRenderHint(QPainter::TextAntialiasing); + + + QPen pen1(Qt::black); pen1.setWidth(4); QPen pen2(color); pen2.setWidth(2); painter.setBrush(Qt::NoBrush); + int penWidth = pen1.width(); + // DRAW WAYPOINT QPointF p(picture.width()/2, picture.height()/2); QPolygonF poly(4); // Top point - poly.replace(0, QPointF(p.x(), p.y()-picture.height()/2.0f+8*painter.pen().width())); + poly.replace(0, QPointF(p.x(), p.y()-picture.height()/2.0f+penWidth/2)); // Right point - poly.replace(1, QPointF(p.x()+picture.width()/2.0f-8*painter.pen().width(), p.y())); + poly.replace(1, QPointF(p.x()+picture.width()/2.0f-penWidth/2, p.y())); // Bottom point - poly.replace(2, QPointF(p.x(), p.y() + picture.height()/2.0f-8*painter.pen().width())); - poly.replace(3, QPointF(p.x() - picture.width()/2.0f+8*painter.pen().width(), p.y())); + poly.replace(2, QPointF(p.x(), p.y() + picture.height()/2.0f-penWidth/2)); + poly.replace(3, QPointF(p.x() - picture.width()/2.0f+penWidth/2, p.y())); int waypointSize = qMin(picture.width(), picture.height()); float rad = (waypointSize/2.0f) * 0.7f * (1/sqrt(2.0f)); @@ -178,28 +172,36 @@ void Waypoint2DIcon::drawIcon() if ((waypoint != NULL) && (waypoint->getAction() == (int)MAV_CMD_NAV_TAKEOFF)) { // Takeoff waypoint - int width = picture.width()-2*painter.pen().width(); - int height = picture.height()-2*-painter.pen().width(); - painter.drawRect(painter.pen().width()/2, painter.pen().width()/2, width, height); - painter.drawRect(width*0.2+painter.pen().width()/2, height*0.2f+painter.pen().width()/2, width*0.6f, height*0.6f); + int width = picture.width()-penWidth; + int height = picture.height()-penWidth; + + painter.setPen(pen1); + painter.drawRect(penWidth/2, penWidth/2, width, height); + painter.setPen(pen2); + painter.drawRect(penWidth/2, penWidth/2, width, height); + + painter.setPen(pen1); + painter.drawRect(width*0.3, height*0.3f, width*0.6f, height*0.6f); + painter.setPen(pen2); + painter.drawRect(width*0.3, height*0.3f, width*0.6f, height*0.6f); } else if ((waypoint != NULL) && (waypoint->getAction() == (int)MAV_CMD_NAV_LAND)) { // Landing waypoint - int width = (picture.width())/2-painter.pen().width(); - int height = (picture.height())/2-painter.pen().width(); + int width = (picture.width())/2-penWidth; + int height = (picture.height())/2-penWidth; painter.setPen(pen1); painter.drawEllipse(p, width, height); - painter.drawLine(p.x()-width/2, p.y()-height/2, width, height); + painter.drawLine(p.x()-width/2, p.y()-height/2, 2*width, 2*height); painter.setPen(pen2); painter.drawEllipse(p, width, height); - painter.drawLine(p.x()-width/2, p.y()-height/2, width, height); + painter.drawLine(p.x()-width/2, p.y()-height/2, 2*width, 2*height); } else if ((waypoint != NULL) && ((waypoint->getAction() == (int)MAV_CMD_NAV_LOITER_UNLIM) || (waypoint->getAction() == (int)MAV_CMD_NAV_LOITER_TIME) || (waypoint->getAction() == (int)MAV_CMD_NAV_LOITER_TURNS))) { // Loiter waypoint - int width = (picture.width())/2-9*painter.pen().width(); - int height = (picture.height())/2-9*painter.pen().width(); + int width = (picture.width()-penWidth)/2; + int height = (picture.height()-penWidth)/2; painter.setPen(pen1); painter.drawEllipse(p, width, height); painter.drawPoint(p); @@ -210,10 +212,24 @@ void Waypoint2DIcon::drawIcon() else if ((waypoint != NULL) && (waypoint->getAction() == (int)MAV_CMD_NAV_RETURN_TO_LAUNCH)) { // Return to launch waypoint - int width = picture.width()-2*painter.pen().width(); - int height = picture.height()-2*-painter.pen().width(); - painter.drawRect(painter.pen().width()/2, painter.pen().width()/2, width, height); - painter.drawText(width/10, width/10, width/10*8, width/10*8, 0, QString("R")); + int width = picture.width()-penWidth; + int height = picture.height()-penWidth; + painter.setPen(pen1); + painter.drawRect(penWidth/2, penWidth/2, width, height); + painter.setPen(pen2); + painter.drawRect(penWidth/2, penWidth/2, width, height); + + QString text("R"); + + painter.setPen(pen1); + QRect rect = metrics.boundingRect(0, 0, width - 2*border, height, Qt::AlignLeft | Qt::TextWordWrap, text); + painter.drawText(width/4, height/6, rect.width(), rect.height(), + Qt::AlignCenter | Qt::TextWordWrap, text); + painter.setPen(pen2); + + font.setPixelSize(fontSize*0.85f); + painter.setFont(font); + painter.drawText(width/4, height/6, rect.width(), rect.height(), Qt::AlignCenter | Qt::TextWordWrap, text); } else { @@ -225,6 +241,30 @@ void Waypoint2DIcon::drawIcon() } } +void Waypoint2DIcon::SetShowNumber(const bool &value) +{ + shownumber=value; + if((numberI==0) && value) + { + numberI=new QGraphicsSimpleTextItem(this); + numberIBG=new QGraphicsRectItem(this); + numberIBG->setBrush(Qt::black); + numberIBG->setOpacity(0.5); + numberI->setZValue(3); + numberI->setPen(QPen(QGC::colorCyan)); + numberI->setPos(5,-picture.height()); + numberIBG->setPos(5,-picture.height()); + numberI->setText(QString::number(number)); + numberIBG->setRect(numberI->boundingRect().adjusted(-2,0,1,0)); + } + else if (!value && numberI) + { + delete numberI; + delete numberIBG; + } + this->update(); +} + void Waypoint2DIcon::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { Q_UNUSED(option); @@ -246,6 +286,7 @@ void Waypoint2DIcon::paint(QPainter *painter, const QStyleOptionGraphicsItem *op { QPen redPen = QPen(pen); redPen.setColor(Qt::yellow); + redPen.setWidth(1); painter->setPen(redPen); const int acceptance = map->metersToPixels(waypoint->getAcceptanceRadius(), Coord()); painter->setPen(penBlack); diff --git a/src/ui/map/Waypoint2DIcon.h b/src/ui/map/Waypoint2DIcon.h index 72af64123..0ce1d6160 100644 --- a/src/ui/map/Waypoint2DIcon.h +++ b/src/ui/map/Waypoint2DIcon.h @@ -26,14 +26,6 @@ public: virtual ~Waypoint2DIcon(); - //! sets the QPen which is used for drawing the circle - /*! - * A QPen can be used to modify the look of the drawn circle - * @param pen the QPen which should be used for drawing - * @see http://doc.trolltech.com/4.3/qpen.html - */ - virtual void setPen(QPen* pen); - void SetHeading(float heading); /** @brief Rectangle to be updated on changes */ @@ -42,8 +34,8 @@ public: void drawIcon(); /** @brief Draw the icon on a QPainter device (map) */ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); - /** @brief UNUSED FUNCTION: Waypoints in QGC are purely passive */ - void SetReached(const bool &value); + /** @brief Enable and format the waypoint number display */ + void SetShowNumber(const bool &value); public: void updateWaypoint(); @@ -52,7 +44,6 @@ protected: mapcontrol::OPMapWidget* parent; ///< Parent widget int radius; ///< Radius / diameter of the icon in pixels Waypoint* waypoint; ///< Waypoint data container this icon represents - QPen* mypen; QColor color; bool showAcceptanceRadius; bool showOrbit; -- 2.22.0