mirror of
https://github.com/GoldenCheetah/GoldenCheetah.git
synced 2026-02-13 16:18:42 +00:00
UI Nits: Chart settings and Chart Close Menu
The chart settings are no longer in the side bar and can be selected from a drop down menu on the chart. This works in tiled and tabbed mode and allows for further enhancements e.g. custom menu options for commonly use config options (ala Android). This is part of a series of updates to migrate away from a sidebar that is a toolbox of ridelist etc and move back towards a context sensitive sidebar.
This commit is contained in:
62
src/ChartSettings.cpp
Normal file
62
src/ChartSettings.cpp
Normal file
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright (c) 2012 Mark Liversedge (liversedge@gmail.com)
|
||||
*
|
||||
* 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 2 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., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#include "ChartSettings.h"
|
||||
#include <QVBoxLayout>
|
||||
|
||||
ChartSettings::ChartSettings(QWidget *parent, QWidget *contents) : QDialog(parent)
|
||||
{
|
||||
// Set the main window title.
|
||||
setWindowTitle(tr("Chart Settings"));
|
||||
setAttribute(Qt::WA_DeleteOnClose);
|
||||
setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint | Qt::WindowCloseButtonHint);
|
||||
setModal(true);
|
||||
|
||||
// Create the main layout box.
|
||||
QVBoxLayout *mainVBox = new QVBoxLayout(this);
|
||||
|
||||
// Set up the instructions field.
|
||||
mainVBox->addWidget(contents);
|
||||
|
||||
// "Done" button.
|
||||
mainVBox->addSpacing(15);
|
||||
QHBoxLayout *buttonHBox = new QHBoxLayout;
|
||||
btnOK = new QPushButton(this);
|
||||
btnOK->setFocusPolicy(Qt::NoFocus);
|
||||
btnOK->setText(tr("Done"));
|
||||
buttonHBox->addStretch();
|
||||
buttonHBox->addWidget(btnOK);
|
||||
mainVBox->addLayout(buttonHBox);
|
||||
connect(btnOK, SIGNAL(clicked()), this, SLOT(on_btnOK_clicked()));
|
||||
|
||||
hide();
|
||||
}
|
||||
|
||||
void ChartSettings::on_btnOK_clicked() {
|
||||
// all done!
|
||||
hide();
|
||||
}
|
||||
|
||||
// close doesnt really close, just hides
|
||||
void
|
||||
ChartSettings::closeEvent(QCloseEvent* event)
|
||||
{
|
||||
event->ignore();
|
||||
hide();
|
||||
}
|
||||
43
src/ChartSettings.h
Normal file
43
src/ChartSettings.h
Normal file
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright (c) 2012 Mark Liversedge (liversedge@gmal.com)
|
||||
*
|
||||
* 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 2 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., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#include "GoldenCheetah.h"
|
||||
#include <QDialog>
|
||||
#include <QPushButton>
|
||||
#include <QCloseEvent>
|
||||
|
||||
#ifndef GC_ChartSettings_h
|
||||
#define GC_ChartSettings_h
|
||||
|
||||
class ChartSettings : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
G_OBJECT
|
||||
|
||||
public:
|
||||
ChartSettings(QWidget *parent, QWidget *contents);
|
||||
void closeEvent(QCloseEvent* event);
|
||||
|
||||
private:
|
||||
QPushButton *btnOK;
|
||||
|
||||
private slots:
|
||||
void on_btnOK_clicked();
|
||||
};
|
||||
#endif
|
||||
@@ -35,6 +35,12 @@ void GcWindow::setControls(QWidget *x)
|
||||
{
|
||||
_controls = x;
|
||||
emit controlsChanged(_controls);
|
||||
|
||||
if (x != NULL) {
|
||||
menu->clear();
|
||||
menu->addAction(tr("Chart Settings"), this, SIGNAL(showControls()));
|
||||
menu->addAction(tr("Close"), this, SLOT(_closeWindow()));
|
||||
}
|
||||
}
|
||||
|
||||
QString GcWindow::instanceName() const
|
||||
@@ -145,6 +151,23 @@ GcWindow::GcWindow()
|
||||
setResizable(false);
|
||||
setMouseTracking(true);
|
||||
setProperty("color", Qt::white);
|
||||
|
||||
// make sure its underneath the toggle button
|
||||
menuButton = new QToolButton(this);
|
||||
menuButton->setStyleSheet("QToolButton { border: none; padding: 0px; }");
|
||||
menuButton->setCursor(Qt::ArrowCursor);
|
||||
menuButton->setPopupMode(QToolButton::InstantPopup);
|
||||
menuButton->setFixedSize(15,20);
|
||||
|
||||
menu = new QMenu(this);
|
||||
menuButton->setMenu(menu);
|
||||
menu->addAction(tr("Close"), this, SLOT(_closeWindow()));
|
||||
|
||||
menuButton->hide();
|
||||
|
||||
#ifndef Q_OS_MAC // spacing ..
|
||||
menuButton->move(0,0);
|
||||
#endif
|
||||
}
|
||||
|
||||
GcWindow::GcWindow(QWidget *parent) : QFrame(parent), dragState(None) {
|
||||
@@ -160,6 +183,23 @@ GcWindow::GcWindow(QWidget *parent) : QFrame(parent), dragState(None) {
|
||||
setResizable(false);
|
||||
setMouseTracking(true);
|
||||
setProperty("color", Qt::white);
|
||||
|
||||
// make sure its underneath the toggle button
|
||||
menuButton = new QToolButton(this);
|
||||
menuButton->setStyleSheet("QToolButton { border: none; padding: 0px; }");
|
||||
menuButton->setCursor(Qt::ArrowCursor);
|
||||
menuButton->setPopupMode(QToolButton::InstantPopup);
|
||||
menuButton->setFixedSize(15,20);
|
||||
|
||||
menu = new QMenu(this);
|
||||
menuButton->setMenu(menu);
|
||||
menu->addAction(tr("Close"), this, SLOT(_closeWindow()));
|
||||
|
||||
menuButton->hide();
|
||||
|
||||
#ifndef Q_OS_MAC // spacing ..
|
||||
menuButton->move(0,0);
|
||||
#endif
|
||||
}
|
||||
|
||||
GcWindow::~GcWindow()
|
||||
@@ -229,11 +269,13 @@ GcWindow::paintEvent(QPaintEvent * /*event*/)
|
||||
// border
|
||||
painter.setBrush(Qt::NoBrush);
|
||||
if (underMouse()) {
|
||||
#if 0
|
||||
QPixmap sized = closeImage.scaled(QSize(contentsMargins().top()-6,
|
||||
contentsMargins().top()-6));
|
||||
painter.setPen(Qt::black);
|
||||
//painter.drawRect(QRect(0,0,width()-1,height()-1));//XXX pointless
|
||||
painter.drawPixmap(width()-3-sized.width(), 3, sized.width(), sized.height(), sized);
|
||||
#endif
|
||||
} else {
|
||||
painter.setPen(Qt::darkGray);
|
||||
//painter.drawRect(QRect(0,0,width()-1,height()-1)); //XXX pointless
|
||||
@@ -351,8 +393,8 @@ GcWindow::spotHotSpot(QMouseEvent *e)
|
||||
int _height = height();
|
||||
int _width = width();
|
||||
|
||||
if (e->x() > (2 + width() - corner) && e->y() < corner) return (Close);
|
||||
else if (_x <= corner && _y <= corner) return (TLCorner);
|
||||
//if (e->x() > (2 + width() - corner) && e->y() < corner) return (Close);
|
||||
if (_x <= corner && _y <= corner) return (TLCorner);
|
||||
else if (_x >= (_width-corner) && _y <= corner) return (TRCorner);
|
||||
else if (_x <= corner && _y >= (_height-corner)) return (BLCorner);
|
||||
else if (_x >= (_width-corner) && _y >= (_height-corner)) return (BRCorner);
|
||||
@@ -574,3 +616,26 @@ GcWindow::setCursorShape(DragState d)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
GcWindow::enterEvent(QEvent *)
|
||||
{
|
||||
if (property("isManager").toBool() == false) {
|
||||
if (contentsMargins().top() > 20) menuButton->setFixedSize(15,20);
|
||||
else menuButton->setFixedSize(15,15);
|
||||
menuButton->show();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
GcWindow::leaveEvent(QEvent *)
|
||||
{
|
||||
menuButton->hide();
|
||||
}
|
||||
|
||||
void
|
||||
GcWindow::_closeWindow()
|
||||
{
|
||||
emit closeWindow(this);
|
||||
}
|
||||
|
||||
@@ -24,6 +24,9 @@
|
||||
#define myRideItem property("ride").value<RideItem*>()
|
||||
|
||||
#include <QString>
|
||||
#include <QMenu>
|
||||
#include <QPushButton>
|
||||
#include <QToolButton>
|
||||
#include <QWidget>
|
||||
#include <QObject>
|
||||
#include <QMetaObject>
|
||||
@@ -91,6 +94,8 @@ private:
|
||||
int oWidth, oHeight, oX, oY, mX, mY;
|
||||
double oHeightFactor, oWidthFactor;
|
||||
|
||||
public slots:
|
||||
void _closeWindow();
|
||||
|
||||
signals:
|
||||
void controlsChanged(QWidget*);
|
||||
@@ -104,6 +109,9 @@ signals:
|
||||
void resized(GcWindow*); // finished resizing
|
||||
void moved(GcWindow*); // finished moving
|
||||
|
||||
void showControls();
|
||||
void closeWindow(GcWindow*);
|
||||
|
||||
public:
|
||||
|
||||
GcWindow();
|
||||
@@ -155,11 +163,16 @@ public:
|
||||
virtual void mousePressEvent(QMouseEvent *);
|
||||
virtual void mouseReleaseEvent(QMouseEvent *);
|
||||
virtual void mouseMoveEvent(QMouseEvent *);
|
||||
void enterEvent(QEvent *);
|
||||
void leaveEvent(QEvent *);
|
||||
void setDragState(DragState);
|
||||
void setCursorShape(DragState);
|
||||
DragState spotHotSpot(QMouseEvent *);
|
||||
void setNewSize(int w, int h);
|
||||
|
||||
QPushButton *settingsButton, *closeButton;
|
||||
QToolButton *menuButton;
|
||||
QMenu *menu;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -126,6 +126,9 @@ HomeWindow::HomeWindow(MainWindow *mainWindow, QString name, QString /* windowti
|
||||
tabLayout->setContentsMargins(0,0,0,0);
|
||||
tabLayout->setSpacing(0);
|
||||
tabbed = new QTabWidget(this);
|
||||
#ifdef Q_OS_MAC
|
||||
tabbed->setAttribute(Qt::WA_MacShowFocusRect, 0);
|
||||
#endif
|
||||
tabbed->setContentsMargins(0,0,0,0);
|
||||
tabbed->setTabsClosable(false);
|
||||
tabbed->setPalette(palette);
|
||||
@@ -554,6 +557,10 @@ HomeWindow::addChart(GcWindow* newone)
|
||||
QWidget *x = dynamic_cast<GcWindow*>(newone)->controls();
|
||||
QWidget *c = (x != NULL) ? x : new QWidget(this);
|
||||
|
||||
// link settings button to show controls
|
||||
connect(newone, SIGNAL(showControls()), mainWindow->chartSettings, SLOT(show()));
|
||||
connect(newone, SIGNAL(closeWindow(GcWindow*)), this, SLOT(closeWindow(GcWindow*)));
|
||||
|
||||
if (currentStyle == 2 && chartCursor >= 0)
|
||||
controlStack->insertWidget(chartCursor, c);
|
||||
else
|
||||
@@ -833,12 +840,6 @@ HomeWindow::eventFilter(QObject *object, QEvent *e)
|
||||
for(int i=0; i<charts.count(); i++) {
|
||||
if (charts[i] == object) {
|
||||
|
||||
// close button?
|
||||
if (x > (charts[i]->width()-15)) {
|
||||
return removeChart(i);
|
||||
|
||||
} else {
|
||||
|
||||
if (charts[i] != clicked) { // we aren't clicking to toggle
|
||||
|
||||
// clear the chart that is currently clicked
|
||||
@@ -858,8 +859,6 @@ HomeWindow::eventFilter(QObject *object, QEvent *e)
|
||||
charts[i]->repaint();
|
||||
clicked = NULL;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1477,3 +1476,8 @@ bool ViewParser::endDocument()
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void HomeWindow::closeWindow(GcWindow*thisone)
|
||||
{
|
||||
if (charts.contains(thisone)) removeChart(charts.indexOf(thisone));
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#ifndef _GC_HomeWindow_h
|
||||
#define _GC_HomeWindow_h 1
|
||||
#include "GoldenCheetah.h"
|
||||
#include "ChartSettings.h"
|
||||
#include "GcWindowRegistry.h"
|
||||
#include "GcWindowLayout.h"
|
||||
|
||||
@@ -73,6 +74,9 @@ class HomeWindow : public GcWindow
|
||||
bool removeChart(int, bool confirm = true);
|
||||
void titleChanged();
|
||||
|
||||
// window wants to close...
|
||||
void closeWindow(GcWindow*);
|
||||
|
||||
// save / restore window state
|
||||
void saveState();
|
||||
void restoreState(bool useDefault = false);
|
||||
|
||||
@@ -95,6 +95,8 @@
|
||||
#include "NamedSearch.h"
|
||||
#endif
|
||||
|
||||
#include "ChartSettings.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <QApplication>
|
||||
#include <QtGui>
|
||||
@@ -581,7 +583,12 @@ MainWindow::MainWindow(const QDir &home) :
|
||||
toolBox->addItem(activityHistory, QIcon(":images/activity.png"), "Activity History");
|
||||
toolBox->addItem(intervalSplitter, QIcon(":images/stopwatch.png"), "Activity Intervals");
|
||||
toolBox->addItem(trainTool->controls(), QIcon(":images/library.png"), "Workout Library");
|
||||
toolBox->addItem(masterControls, QIcon(":images/settings.png"), "Chart Settings");
|
||||
|
||||
// Chart Settings now in their own dialog box
|
||||
chartSettings = new ChartSettings(this, masterControls);
|
||||
//toolBox->addItem(masterControls, QIcon(":images/settings.png"), "Chart Settings");
|
||||
chartSettings->hide();
|
||||
|
||||
#if 0 // XXX NOT YET IMPLEMENTED
|
||||
toolBox->addItem(new AthleteTool(QFileInfo(home.path()).path(), this), QIcon(":images/toolbar/main/athlete.png"), "Athletes");
|
||||
#endif
|
||||
|
||||
@@ -64,6 +64,7 @@ class QTFullScreen;
|
||||
class TrainTool;
|
||||
class Lucene;
|
||||
class NamedSearches;
|
||||
class ChartSettings;
|
||||
|
||||
extern QList<MainWindow *> mainwindows; // keep track of all the MainWindows we have open
|
||||
|
||||
@@ -138,6 +139,7 @@ class MainWindow : public QMainWindow
|
||||
HomeWindow *trainWindow;
|
||||
HomeWindow *analWindow;
|
||||
HomeWindow *currentWindow; // tracks the curerntly showing window
|
||||
ChartSettings *chartSettings;
|
||||
|
||||
// state data
|
||||
SpecialFields specialFields;
|
||||
|
||||
@@ -218,6 +218,7 @@ HEADERS += \
|
||||
Bin2RideFile.h \
|
||||
BingMap.h \
|
||||
CalendarDownload.h \
|
||||
ChartSettings.h \
|
||||
ChooseCyclistDialog.h \
|
||||
Colors.h \
|
||||
ColorButton.h \
|
||||
@@ -401,6 +402,7 @@ SOURCES += \
|
||||
Bin2RideFile.cpp \
|
||||
BingMap.cpp \
|
||||
CalendarDownload.cpp \
|
||||
ChartSettings.cpp \
|
||||
ChooseCyclistDialog.cpp \
|
||||
Coggan.cpp \
|
||||
Colors.cpp \
|
||||
|
||||
Reference in New Issue
Block a user