Fixes the positioning of the ToolBar

This is a workaround, I plan to remove that toolbar from inside
of the Profile for the next version, but since it's there for now,
let's keep it.

This patch hides the toolbar when the zoomLevel != 0, since the
profile is unclickable while zoomed...

Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Tomaz Canabrava 2013-11-26 16:04:21 -02:00 committed by Dirk Hohndel
parent e175b1d1ab
commit 97fd22b1be

View file

@ -47,6 +47,10 @@ extern struct ev_select *ev_namelist;
extern int evn_allocated; extern int evn_allocated;
extern int evn_used; extern int evn_used;
#define TOOLBAR_POS \
QPoint(viewport()->geometry().width() - toolBarProxy->boundingRect().width(), \
viewport()->geometry().height() - toolBarProxy->boundingRect().height() )
ProfileGraphicsView::ProfileGraphicsView(QWidget* parent) : QGraphicsView(parent), toolTip(0) , dive(0), diveDC(0), rulerItem(0), toolBarProxy(0) ProfileGraphicsView::ProfileGraphicsView(QWidget* parent) : QGraphicsView(parent), toolTip(0) , dive(0), diveDC(0), rulerItem(0), toolBarProxy(0)
{ {
printMode = false; printMode = false;
@ -110,8 +114,15 @@ void ProfileGraphicsView::wheelEvent(QWheelEvent* event)
scale(1.0 / scaleFactor, 1.0 / scaleFactor); scale(1.0 / scaleFactor, 1.0 / scaleFactor);
zoomLevel--; zoomLevel--;
} }
scrollViewTo(event->pos()); scrollViewTo(event->pos());
toolTip->setPos(mapToScene(toolTipPos).x(), mapToScene(toolTipPos).y()); toolTip->setPos(mapToScene(toolTipPos));
toolBarProxy->setPos(mapToScene(TOOLBAR_POS));
if(zoomLevel != 0){
toolBarProxy->hide();
}else{
toolBarProxy->show();
}
} }
void ProfileGraphicsView::contextMenuEvent(QContextMenuEvent* event) void ProfileGraphicsView::contextMenuEvent(QContextMenuEvent* event)
@ -233,12 +244,15 @@ void ProfileGraphicsView::mouseMoveEvent(QMouseEvent* event)
toolTip->refresh(&gc, mapToScene(event->pos())); toolTip->refresh(&gc, mapToScene(event->pos()));
QPoint toolTipPos = mapFromScene(toolTip->pos()); QPoint toolTipPos = mapFromScene(toolTip->pos());
QPoint toolBarPos = mapFromScene(toolBarProxy->pos());
scrollViewTo(event->pos()); scrollViewTo(event->pos());
if (zoomLevel == 0) if (zoomLevel == 0)
QGraphicsView::mouseMoveEvent(event); QGraphicsView::mouseMoveEvent(event);
else else{
toolTip->setPos(mapToScene(toolTipPos).x(), mapToScene(toolTipPos).y()); toolTip->setPos(mapToScene(toolTipPos));
toolBarProxy->setPos(mapToScene(TOOLBAR_POS));
}
} }
bool ProfileGraphicsView::eventFilter(QObject* obj, QEvent* event) bool ProfileGraphicsView::eventFilter(QObject* obj, QEvent* event)
@ -284,6 +298,8 @@ void ProfileGraphicsView::showEvent(QShowEvent* event)
dive = 0; dive = 0;
plot(get_dive(selected_dive)); plot(get_dive(selected_dive));
} }
if (toolBarProxy)
toolBarProxy->setPos(mapToScene(TOOLBAR_POS));
} }
void ProfileGraphicsView::clear() void ProfileGraphicsView::clear()
@ -516,7 +532,8 @@ void ProfileGraphicsView::addControlItems(struct dive *d)
connect(editAction, SIGNAL(triggered()), mainWindow(), SLOT(editCurrentDive())); connect(editAction, SIGNAL(triggered()), mainWindow(), SLOT(editCurrentDive()));
} }
toolBarProxy = scene()->addWidget(toolBar); toolBarProxy = scene()->addWidget(toolBar);
toolBarProxy->setPos(gc.maxx-toolBar->width(), gc.maxy-toolBar->height()); toolBarProxy->setPos(mapToScene(TOOLBAR_POS));
toolBarProxy->setFlag(QGraphicsItem::ItemIgnoresTransformations);
} }
void ProfileGraphicsView::plot_pp_text() void ProfileGraphicsView::plot_pp_text()
@ -896,9 +913,9 @@ void ProfileGraphicsView::plot_events(struct divecomputer *dc)
{ {
struct event *event = dc->events; struct event *event = dc->events;
// if (gc->printer) { // if (gc->printer) {
// return; // return;
// } // }
while (event) { while (event) {
plot_one_event(event); plot_one_event(event);