switch from QToolBox to QComboBox

This patch removes the QToolBox from commit e93970 and replaces it with
a QComboBox instead. A new object ViewSelection can be included in any
new views and will manage the interaction with MainWindow to switch
between views. It is essentially a QComboBox with some code to interact
with MainWindow.

A new signal viewChanged(int) has been implemented in MainWindow to
notify of a view change. The parameter will be set to VIEW_ANALYSIS
or VIEW_TRAIN depending upon which view was selected.

In addition, a new TrainWindow object has been created which implements
the Realtime code and is comprised of the TrainTool and TrainTabs
implemented in e93970. It also sets its splitters from remembered values
in the same fashion as the central splitter on the Analysis view.
This commit is contained in:
Mark Liversedge
2009-12-21 15:39:19 +00:00
committed by Sean Rhea
parent 0d96ba220d
commit d10b08e86f
12 changed files with 291 additions and 44 deletions

View File

@@ -57,8 +57,7 @@
#include "MetricAggregator.h"
#include "SplitRideDialog.h"
#include "PerformanceManagerWindow.h"
#include "TrainTabs.h"
#include "TrainTool.h"
#include "TrainWindow.h"
#ifndef GC_VERSION
#define GC_VERSION "(developer build)"
@@ -125,8 +124,7 @@ MainWindow::MainWindow(const QDir &home) :
else
setGeometry(geom.toRect());
splitter = new QSplitter(this);
setCentralWidget(splitter);
splitter = new QSplitter;
splitter->setContentsMargins(10, 20, 10, 10); // attempting to follow some UI guides
// Analysis toolbox contents
@@ -177,21 +175,16 @@ MainWindow::MainWindow(const QDir &home) :
intervalsplitter->setCollapsible(1, true);
leftLayout = new QSplitter;
viewSelection = new ViewSelection(this, VIEW_ANALYSIS);
leftLayout->setOrientation(Qt::Vertical);
leftLayout->addWidget(viewSelection);
leftLayout->setCollapsible(0, false);
leftLayout->addWidget(calendar);
leftLayout->setCollapsible(0, true);
leftLayout->setCollapsible(1, true);
leftLayout->addWidget(intervalsplitter);
leftLayout->setCollapsible(1, false);
leftLayout->setCollapsible(2, false);
// Train toolbox contents
TrainTool *trainTool = new TrainTool(this, home);
// Setup Toolbox
leftToolBox = new QToolBox;
leftToolBox->addItem(leftLayout, tr("Ride Analysis"));
leftToolBox->addItem(trainTool, tr("Racing and Training"));
splitter->addWidget(leftToolBox);
splitter->addWidget(leftLayout);
splitter->setCollapsible(0, true);
QVariant calendarSizes = settings->value(GC_SETTINGS_CALENDAR_SIZES);
if (calendarSizes != QVariant()) {
@@ -212,16 +205,18 @@ MainWindow::MainWindow(const QDir &home) :
}
tabWidget = new QTabWidget;
trainTabs = new TrainTabs(this, trainTool, home);
tabWidget->setUsesScrollButtons(true);
rightSide = new QStackedWidget;
rightSide->addWidget(tabWidget);
rightSide->addWidget(trainTabs);
// setup trainWindow
trainWindow = new TrainWindow(this, home);
// Start with Analysis by default
rightSide->setCurrentIndex(0);
leftToolBox->setCurrentIndex(0);
// Setup the two views
// add the two views; Analysis and Train
views = new QStackedWidget(this);
setCentralWidget(views);
views->addWidget(splitter); // Analysis stuff
views->addWidget(trainWindow); // Train Stuff
views->setCurrentIndex(0); // default to Analysis
rideSummaryWindow = new RideSummaryWindow(this);
QLabel *notesLabel = new QLabel(tr("Notes:"));
@@ -241,6 +236,7 @@ MainWindow::MainWindow(const QDir &home) :
summarySplitter->addWidget(notesWidget);
summarySplitter->setCollapsible(1, true);
// the sizes are somewhat arbitrary,
// just trying to force the smallest non-hidden notes size by default
QList<int> summarySizes;
@@ -253,7 +249,7 @@ MainWindow::MainWindow(const QDir &home) :
/////////////////////////// Ride Plot Tab ///////////////////////////
allPlotWindow = new AllPlotWindow(this);
tabWidget->addTab(allPlotWindow, tr("Ride Plot"));
splitter->addWidget(rightSide);
splitter->addWidget(tabWidget);
splitter->setCollapsible(1, true);
QVariant splitterSizes = settings->value(GC_SETTINGS_SPLITTER_SIZES);
@@ -312,8 +308,6 @@ MainWindow::MainWindow(const QDir &home) :
this, SLOT(intervalTreeWidgetSelectionChanged()));
connect(intervalWidget,SIGNAL(itemChanged(QTreeWidgetItem *,int)),
this, SLOT(intervalEdited(QTreeWidgetItem*, int)));
connect(leftToolBox, SIGNAL(currentChanged(int)),
this, SLOT(toolboxChanged(int)));
/////////////////////////////// Menus ///////////////////////////////
@@ -382,9 +376,15 @@ MainWindow::MainWindow(const QDir &home) :
}
void
MainWindow::toolboxChanged(int index)
MainWindow::selectView(int view)
{
rightSide->setCurrentIndex(index); // right stack has one page per toolbox
if (view == VIEW_ANALYSIS)
views->setCurrentIndex(0); // set stacked widget to Analysis
else if (view == VIEW_TRAIN)
views->setCurrentIndex(1); // set stacked widget to Train
// notify with a signal
viewChanged(view);
}
void

View File

@@ -42,8 +42,8 @@ class Zones;
class RideCalendar;
class PerformanceManagerWindow;
class RideSummaryWindow;
class TrainTabs;
class TrainTool;
class ViewSelection;
class TrainWindow;
class MainWindow : public QMainWindow
{
@@ -71,6 +71,7 @@ class MainWindow : public QMainWindow
void notifyConfigChanged(); // used by ConfigDialog to notify MainWindow
// when config has changed - and to get a
// signal emitted to notify its children
void selectView(int);
protected:
@@ -89,12 +90,12 @@ class MainWindow : public QMainWindow
void intervalsChanged();
void zonesChanged();
void configChanged();
void viewChanged(int);
private slots:
void rideTreeWidgetSelectionChanged();
void intervalTreeWidgetSelectionChanged();
void leftLayoutMoved();
void toolboxChanged(int);
void splitterMoved();
void newCyclist();
void openCyclist();
@@ -136,8 +137,8 @@ class MainWindow : public QMainWindow
boost::shared_ptr<QSettings> settings;
IntervalItem *activeInterval; // currently active for context menu popup
QToolBox *leftToolBox;
QStackedWidget *rightSide;
ViewSelection *viewSelection;
QStackedWidget *views;
// Analysis
RideCalendar *calendar;
@@ -159,8 +160,7 @@ class MainWindow : public QMainWindow
QSplitter *summarySplitter;
// Train
TrainTool *trainTool;
TrainTabs *trainTabs;
TrainWindow *trainWindow;
QwtPlotCurve *weeklyBSCurve;
QwtPlotCurve *weeklyRICurve;

View File

@@ -27,6 +27,9 @@
#include "ErgFile.h"
#include "ErgFilePlot.h"
class TrainTool;
class TrainTabs;
// Status settings
#define RT_MODE_ERGO 0x0001 // load generation modes
#define RT_MODE_SPIN 0x0002 // spinscan like modes

View File

@@ -50,6 +50,7 @@
#define GC_WARNCONVERT "warnconvert"
#define GC_WARNEXIT "warnexit"
#define GC_WORKOUTDIR "workoutDir"
#define GC_TRAIN_SPLITTER_SIZES "trainwindow/splitterSizes"
// device Configurations NAME/SPEC/TYPE/DEFI/DEFR all get a number appended
// to them to specify which configured device i.e. devices1 ... devicesn where

View File

@@ -17,11 +17,12 @@
*/
#include "TrainTabs.h"
#include "TrainTool.h"
#include "RealtimeWindow.h"
TrainTabs::TrainTabs(MainWindow *parent, TrainTool *trainTool, const QDir &home) :
trainTool(trainTool), home(home), main(parent)
{
realtimeWindow = new RealtimeWindow(parent, trainTool, home); // public so config dialog can notify it of changes config
addTab(realtimeWindow, tr("Turbo Training"));
addTab(realtimeWindow, tr("Solo Ride"));
};

View File

@@ -18,6 +18,7 @@
#include "TrainTool.h"
#include "MainWindow.h"
#include "ViewSelection.h"
#include "Settings.h"
#include "Units.h"
#include "DeviceTypes.h"
@@ -55,6 +56,8 @@ TrainTool::TrainTool(MainWindow *parent, const QDir &home) : QWidget(parent), ho
//connect(serverTree,SIGNAL(itemSelectionChanged()),
// this, SLOT(serverTreeWidgetSelectionChanged()));
viewSelection = new ViewSelection(main, VIEW_TRAIN);
workoutTree = new QTreeWidget;
workoutTree->setColumnCount(1);
workoutTree->setSelectionMode(QAbstractItemView::SingleSelection);
@@ -68,15 +71,16 @@ TrainTool::TrainTool(MainWindow *parent, const QDir &home) : QWidget(parent), ho
configChanged(); // will reset the workout tree
//trainSplitter = new QSplitter;
//trainSplitter->setOrientation(Qt::Vertical);
//trainSplitter->addWidget(serverTree);
//trainSplitter->setCollapsible(0, true);
//trainSplitter->addWidget(workoutTree);
//trainSplitter->setCollapsible(0, true);
trainSplitter = new QSplitter;
trainSplitter->setOrientation(Qt::Vertical);
//mainLayout->addWidget(trainSplitter);
mainLayout->addWidget(workoutTree); // XXX replace above line for this release
mainLayout->addWidget(trainSplitter);
trainSplitter->addWidget(viewSelection);
trainSplitter->setCollapsible(0, false);
trainSplitter->addWidget(workoutTree);
trainSplitter->setCollapsible(1, true);
//trainSplitter->addWidget(serverTree);
//trainSplitter->setCollapsible(2, true);
connect(workoutTree,SIGNAL(itemSelectionChanged()),
this, SLOT(workoutTreeWidgetSelectionChanged()));

View File

@@ -20,6 +20,7 @@
#define _GC_TrainTool_h 1
#include "MainWindow.h"
#include "ViewSelection.h"
#include <QDir>
#include <QtGui>
@@ -55,11 +56,13 @@ class TrainTool : public QWidget
const QDir home;
MainWindow *main;
ViewSelection *viewSelection;
QTreeWidget *workoutTree;
QTabWidget *trainTabs;
QTreeWidgetItem *allWorkouts;
QTreeWidgetItem *workout;
//QSplitter *trainSplitter; // XXX commented out for this release
QSplitter *trainSplitter;
//QTreeWidget *serverTree; // XXX commented out for this release
//QTreeWidgetItem *allServers; // XXX commented out for this release
//QTreeWidgetItem *server; // XXX commented out for this release

72
src/TrainWindow.cpp Normal file
View File

@@ -0,0 +1,72 @@
/*
* Copyright (c) 2009 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 "TrainWindow.h"
#include "TrainTool.h"
#include "TrainTabs.h"
#include "ViewSelection.h"
#include "MainWindow.h"
#include "Settings.h"
#include "Units.h"
#include <QApplication>
#include <QtGui>
TrainWindow::TrainWindow(MainWindow *parent, const QDir &home) : QWidget(parent), home(home), main(parent)
{
boost::shared_ptr<QSettings> settings = GetApplicationSettings();
QVBoxLayout *mainLayout = new QVBoxLayout;
setLayout(mainLayout);
// LeftSide
trainTool = new TrainTool(parent, home);
// Right side
trainTabs = new TrainTabs(parent, trainTool, home);
// setup splitter
splitter = new QSplitter;
splitter->addWidget(trainTool);
splitter->setCollapsible(0, true);
splitter->addWidget(trainTabs);
splitter->setCollapsible(1, true);
// splitter sizing
QVariant splitterSizes = settings->value(GC_TRAIN_SPLITTER_SIZES);
if (splitterSizes != QVariant())
splitter->restoreState(splitterSizes.toByteArray());
else {
QList<int> sizes;
sizes.append(250);
sizes.append(390);
splitter->setSizes(sizes);
}
// add to the layout
mainLayout->addWidget(splitter);
// watch resize of splitter and save away
connect(splitter, SIGNAL(splitterMoved(int,int)),
this, SLOT(splitterMoved()));
}
void
TrainWindow::splitterMoved()
{
boost::shared_ptr<QSettings> settings = GetApplicationSettings();
settings->setValue(GC_TRAIN_SPLITTER_SIZES, splitter->saveState());
}

50
src/TrainWindow.h Normal file
View File

@@ -0,0 +1,50 @@
/*
* Copyright (c) 2000 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
*/
#ifndef _GC_TrainWindow_h
#define _GC_TrainWindow_h 1
#include <QDir>
#include <QtGui>
#include "MainWindow.h"
#include "TrainTool.h"
#include "TrainTabs.h"
#include "RealtimeWindow.h"
class TrainWindow : public QWidget
{
Q_OBJECT
public:
TrainWindow(MainWindow *parent, const QDir &home);
public slots:
void splitterMoved();
private:
const QDir home;
const MainWindow *main;
QSplitter *splitter;
TrainTool *trainTool;
TrainTabs *trainTabs;
};
#endif // _GC_TrainWindow_h

62
src/ViewSelection.cpp Normal file
View File

@@ -0,0 +1,62 @@
/*
* Copyright (c) 2009 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 "ViewSelection.h"
#include "TrainTool.h"
#include "TrainTabs.h"
#include "MainWindow.h"
#include "Settings.h"
#include "Units.h"
#include <QApplication>
#include <QtGui>
#include <QFont>
#include <QFontMetrics>
ViewSelection::ViewSelection(const MainWindow *parent, const int homeView) :
QComboBox((QWidget *)parent),
main(parent),
homeView(homeView)
{
// don't make a fat ugly box...
setFixedHeight(((double)(QFontMetrics(font()).height()) * 1.6));
// set drop-down list
addItem(tr("Ride Analysis View"), VIEW_ANALYSIS);
addItem(tr("Train and Racing View"), VIEW_TRAIN);
// Default to home view
if (homeView == VIEW_ANALYSIS) setCurrentIndex(0);
if (homeView == VIEW_TRAIN) setCurrentIndex(1);
// set to this view
connect(this, SIGNAL(currentIndexChanged(int)), this, SLOT(changeView(int)));
}
void
ViewSelection::changeView(int index)
{
int view = itemData(index).toInt();
if (view != homeView) {
((MainWindow *)main)->selectView(view);
}
// now reset back to the homeView!
if (homeView == VIEW_ANALYSIS) setCurrentIndex(0);
if (homeView == VIEW_TRAIN) setCurrentIndex(1);
}

47
src/ViewSelection.h Normal file
View File

@@ -0,0 +1,47 @@
/*
* Copyright (c) 2000 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
*/
#ifndef _GC_ViewSelection_h
#define _GC_ViewSelection_h 1
#include <QDir>
#include <QtGui>
#include "MainWindow.h"
#include "TrainTool.h"
#include "RealtimeWindow.h"
#define VIEW_ANALYSIS 1
#define VIEW_TRAIN 2
class ViewSelection : public QComboBox
{
Q_OBJECT
public:
ViewSelection(const MainWindow *parent, const int homeView);
public slots:
void changeView(int);
private:
const MainWindow *main;
const int homeView;
};
#endif // _GC_ViewSelection_h

View File

@@ -113,7 +113,9 @@ HEADERS += \
ToolsDialog.h \
TrainTabs.h \
TrainTool.h \
TrainWindow.h \
Units.h \
ViewSelection.h \
WeeklySummaryWindow.h \
WkoRideFile.h \
Zones.h \
@@ -191,6 +193,8 @@ SOURCES += \
ToolsDialog.cpp \
TrainTabs.cpp \
TrainTool.cpp \
TrainWindow.cpp \
ViewSelection.cpp \
WeeklySummaryWindow.cpp \
WkoRideFile.cpp \
Zones.cpp \