Added a toolbar to the profile

The toolbar adds two buttons to the profile.
The user can now toggle the scaling (zoomed to dive/round up to 30 mins)
and adding /removing ruler to/from the profile using this toolbar.

Signed-off-by: Maximilian Güntner <maximilian.guentner@gmail.com>
This commit is contained in:
Maximilian Güntner 2013-09-25 02:39:21 +02:00
parent 248f1b86d1
commit 88172571ca
5 changed files with 209 additions and 1 deletions

View file

@ -15,6 +15,7 @@
#include <QPropertyAnimation>
#include <QGraphicsSceneHoverEvent>
#include <QMouseEvent>
#include <QToolBar>
#include <qtextdocument.h>
#include <limits>
@ -44,7 +45,7 @@ extern struct ev_select *ev_namelist;
extern int evn_allocated;
extern int evn_used;
ProfileGraphicsView::ProfileGraphicsView(QWidget* parent) : QGraphicsView(parent), toolTip(0) , dive(0), diveDC(0), rulerItem(0)
ProfileGraphicsView::ProfileGraphicsView(QWidget* parent) : QGraphicsView(parent), toolTip(0) , dive(0), diveDC(0), rulerItem(0), toolBarProxy(0)
{
printMode = false;
isGrayscale = false;
@ -182,6 +183,11 @@ void ProfileGraphicsView::clear()
toolTip->deleteLater();
toolTip = 0;
}
if(toolBarProxy) {
scene()->removeItem(toolBarProxy);
toolBarProxy->deleteLater();
toolBarProxy = 0;
}
if(rulerItem) {
remove_ruler();
rulerItem->destNode()->deleteLater();
@ -349,6 +355,9 @@ void ProfileGraphicsView::plot(struct dive *d, bool forceRedraw)
scene()->addItem(timeEditor);
}
if (!printMode)
addControlItems();
if (rulerEnabled && !printMode)
add_ruler();
}
@ -383,6 +392,23 @@ void ProfileGraphicsView::plot_depth_scale()
depthMarkers->setPos(depthMarkers->pos().x() - 10, 0);
}
void ProfileGraphicsView::addControlItems()
{
QAction *scaleAction = new QAction(QIcon(":scale"), tr("Scale"), this);
QAction *rulerAction = new QAction(QIcon(":ruler"), tr("Ruler"), this);
QToolBar *toolBar = new QToolBar("", 0);
toolBar->addAction(rulerAction);
toolBar->addAction(scaleAction);
//make toolbar transparent
toolBar->setStyleSheet(QString::fromUtf8 ("background-color: rgba(255,255,255,0);"));
connect(scaleAction, SIGNAL(triggered()), this, SLOT(on_scaleAction()));
connect(rulerAction, SIGNAL(triggered()), this, SLOT(on_rulerAction()));
toolBarProxy = scene()->addWidget(toolBar);
//Put it into the lower right corner of the profile
toolBarProxy->setPos(gc.maxx-toolBar->width(), gc.maxy-toolBar->height());
}
void ProfileGraphicsView::plot_pp_text()
{
double pp, dpp, m;
@ -1241,6 +1267,18 @@ void ProfileGraphicsView::edit_dive_time(const QString& time)
refresh();
}
void ProfileGraphicsView::on_rulerAction()
{
rulerEnabled = !rulerEnabled;
refresh();
}
void ProfileGraphicsView::on_scaleAction()
{
zoomed_plot = !zoomed_plot;
refresh();
}
void ToolTipItem::addToolTip(const QString& toolTip, const QIcon& icon)
{
QGraphicsPixmapItem *iconItem = 0;