Skip to content

Commit

Permalink
Overview Chart base code fixups
Browse files Browse the repository at this point in the history
.. to tidy up embedding chart widgets in the dashboard

.. not so much about the web view for the map as fixing
   bugs that will impact embedding more interesting kinds
   of charts.

.. there is a really irritating bug related to setCursor()
   not working once the mouse has hovered over the
   QWebEngine window in the dashboard.

.. did I ever mention how much I hate QWebEngine ?
  • Loading branch information
liversedge committed Feb 18, 2017
1 parent a733b14 commit b7d7629
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 44 deletions.
2 changes: 1 addition & 1 deletion src/Charts/BlankState.cpp
Expand Up @@ -24,7 +24,7 @@
//
// Replace home window when no ride
//
BlankStatePage::BlankStatePage(Context *context) : context(context), canShow_(true)
BlankStatePage::BlankStatePage(Context *context) : GcWindow(context), context(context), canShow_(true)
{
QVBoxLayout *mainLayout = new QVBoxLayout(this);
mainLayout->addStretch();
Expand Down
55 changes: 18 additions & 37 deletions src/Charts/GoldenCheetah.cpp
Expand Up @@ -168,6 +168,8 @@ bool GcWindow::resizable() const
// tiny sizes as a result
void GcWindow::moveEvent(QMoveEvent *)
{
if (_noevents) return;

if (dragState != Move) setDragState(None);
}

Expand All @@ -181,43 +183,6 @@ bool GcWindow::gripped() const
return _gripped;
}

GcWindow::GcWindow()
{
qRegisterMetaType<QWidget*>("controls");
qRegisterMetaType<RideItem*>("ride");
qRegisterMetaType<GcWinID>("type");
qRegisterMetaType<QColor>("color");
qRegisterMetaType<DateRange>("dateRange");
qRegisterMetaType<bool>("nomenu");
revealed = false;
setControls(NULL);
setRideItem(NULL);
setTitle("");
setContentsMargins(0,0,0,0);
setResizable(false);
setMouseTracking(true);
setProperty("color", GColor(CPLOTBACKGROUND));
setProperty("nomenu", false);
showtitle = true;
menu = NULL;

// make sure its underneath the toggle button
menuButton = new QPushButton(this);
menuButton->setStyleSheet("QPushButton::menu-indicator { image: none; } QPushButton { border: 0px; padding: 0px; }");
//menuButton->setToolButtonStyle(Qt::ToolButtonTextOnly);
menuButton->setText(tr("More..."));
menuButton->setFocusPolicy(Qt::NoFocus);
//menuButton->setArrowType(Qt::NoArrow);
//menuButton->setPopupMode(QPushButton::InstantPopup);

menu = new QMenu(this);
menuButton->setMenu(menu);
menu->addAction(tr("Remove Chart"), this, SLOT(_closeWindow()));
menuButton->hide();

menuButton->move(1,1);
}

GcWindow::GcWindow(Context *context) : QFrame(context->mainWindow), dragState(None)
{
qRegisterMetaType<QWidget*>("controls");
Expand Down Expand Up @@ -254,6 +219,8 @@ GcWindow::GcWindow(Context *context) : QFrame(context->mainWindow), dragState(No

menuButton->hide();
menuButton->move(1,1);

_noevents = false;
}

GcWindow::~GcWindow()
Expand Down Expand Up @@ -368,6 +335,8 @@ GcWindow::paintEvent(QPaintEvent * /*event*/)
void
GcWindow::mousePressEvent(QMouseEvent *e)
{
if (_noevents) return;

// always propagate
e->ignore();

Expand Down Expand Up @@ -404,6 +373,8 @@ GcWindow::mousePressEvent(QMouseEvent *e)
void
GcWindow::mouseReleaseEvent(QMouseEvent *e)
{
if (_noevents) return;

// always propagate
e->ignore();

Expand Down Expand Up @@ -457,6 +428,8 @@ GcWindow::spotHotSpot(QMouseEvent *e)
void
GcWindow::mouseMoveEvent(QMouseEvent *e)
{
if (_noevents) return;

// always propagate
e->ignore();

Expand Down Expand Up @@ -627,6 +600,8 @@ GcWindow::setNewSize(int w, int h)
void
GcWindow::setDragState(DragState d)
{
if (_noevents) return;

dragState = d;
setProperty("gripped", dragState == Move ? true : false);
setCursorShape(d);
Expand All @@ -635,6 +610,8 @@ GcWindow::setDragState(DragState d)
void
GcWindow::setCursorShape(DragState d)
{
if (_noevents) return;

// set cursor
switch (d) {
case Bottom:
Expand Down Expand Up @@ -667,6 +644,8 @@ GcWindow::setCursorShape(DragState d)
void
GcWindow::enterEvent(QEvent *)
{
if (_noevents) return;

if (property("nomenu") == false && property("isManager").toBool() == false) {
if (contentsMargins().top() > 20) menuButton->setFixedSize(80,30);
else menuButton->setFixedSize(80, 15);
Expand All @@ -678,6 +657,8 @@ GcWindow::enterEvent(QEvent *)
void
GcWindow::leaveEvent(QEvent *)
{
if (_noevents) return;

menuButton->hide();
}

Expand Down
5 changes: 3 additions & 2 deletions src/Charts/GoldenCheetah.h
Expand Up @@ -100,6 +100,7 @@ class GcWindow : public QFrame
bool _resizable;
bool _gripped;
int _style;
bool _noevents; // don't work with events

enum drag { None, Close, Flip, Move, Left, Right, Top, Bottom, TLCorner, TRCorner, BLCorner, BRCorner };
typedef enum drag DragState;
Expand Down Expand Up @@ -131,15 +132,15 @@ public slots:

public:

GcWindow();
~GcWindow();
GcWindow(Context *context);
~GcWindow();

//void _setInstanceName(QString x); // GOBJECTS can set their instance name, but not be GcWindows
//QString instanceName() const;

// must call this before set controls
void addAction(QAction *act) { actions << act; }
void setNoEvents(bool x) { _noevents = x; }

void virtual setControls(QWidget *x);
QWidget *controls() const;
Expand Down
18 changes: 14 additions & 4 deletions src/Charts/OverviewWindow.cpp
Expand Up @@ -158,7 +158,12 @@ Card::setType(CardType type)
map = new RideMapWindow(parent->context, RideMapWindow::GOOGLE);
map->setParent(NULL);

// set sensible settings
// disable gc chart specific functionality
map->setNoEvents(true); // disable chart window mouse events
map->setProperty("nomenu", true);
map->setProperty("color", GColor(CCARDBACKGROUND));

// set map to sensible defaults
map->setShowIntervals(false);
map->setShowMarkers(false);
map->setShowIntervals(false);
Expand Down Expand Up @@ -434,8 +439,13 @@ Card::setData(RideItem *item)
// when we update a chart in the middle of its animation
if (chart) chart->setAnimationOptions(QChart::NoAnimation);

if (type == ROUTE) {
map->setProperty("ride", QVariant::fromValue<RideItem*>(item));
if (type == ROUTE && scene() != NULL) {

// only if we're place on the scene
if (item->ride() && item->ride()->areDataPresent()->lat) {
if (map->isHidden()) map->show();
map->setProperty("ride", QVariant::fromValue<RideItem*>(item));
} else map->hide();
}

if (type == METRIC) {
Expand Down Expand Up @@ -1450,7 +1460,7 @@ OverviewWindow::eventFilter(QObject *, QEvent *event)

// not hovering over tile, so if still have a resize cursor
// set it back to the normal arrow pointer
if (yresizecursor || xresizecursor) {
if (yresizecursor || xresizecursor || cursor().shape() != Qt::ArrowCursor) {
xresizecursor = yresizecursor = false;
setCursor(QCursor(Qt::ArrowCursor));
}
Expand Down

5 comments on commit b7d7629

@amtriathlon
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably this is intended as part of Ride/Interval Summary deprecation but, in the meantime, the side effect is that is not possible to scroll over Ride/Interval Summary or LTM Charts in data table mode anymore.

@liversedge
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thats annoying -- QWebEngine steals focus, but equally, you need to be able to scroll. So I'll undo that for the RideSummaryWindow -- so if someone wants to use it, they pay the price that it steals focus.

@amtriathlon
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For me the most annoying part is not being able to scroll on Interval summary overlay on Activity chart!

@liversedge
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will be rewriting that. For now I'll re-enable.

@amtriathlon
Copy link
Member

@amtriathlon amtriathlon commented on b7d7629 Feb 21, 2017 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.