CriticalPowerWindow::CriticalPowerWindow(const QDir &home, MainWindow *parent, bool rangemode) : GcWindow(parent), _dateRange("{00000000-0000-0000-0000-000000000001}"), home(home), mainWindow(parent), currentRide(NULL), rangemode(rangemode), stale(true), useCustom(false) { setInstanceName("Critical Power Window"); // main plot area QVBoxLayout *vlayout = new QVBoxLayout; cpintPlot = new CpintPlot(mainWindow, home.path(), mainWindow->zones()); vlayout->addWidget(cpintPlot); setLayout(vlayout); // controls QWidget *c = new QWidget; QFormLayout *cl = new QFormLayout(c); setControls(c); #ifdef GC_HAVE_LUCENE // searchbox searchBox = new SearchFilterBox(this, parent); connect(searchBox, SIGNAL(searchClear()), cpintPlot, SLOT(clearFilter())); connect(searchBox, SIGNAL(searchResults(QStringList)), cpintPlot, SLOT(setFilter(QStringList))); connect(searchBox, SIGNAL(searchClear()), this, SLOT(filterChanged())); connect(searchBox, SIGNAL(searchResults(QStringList)), this, SLOT(filterChanged())); cl->addRow(new QLabel(tr("Filter")), searchBox); cl->addWidget(new QLabel("")); //spacing #endif // picker details QLabel *cpintTimeLabel = new QLabel(tr("Duration:"), this); cpintTimeValue = new QLineEdit("0 s"); QLabel *cpintTodayLabel = new QLabel(tr("Today:"), this); cpintTodayValue = new QLabel(tr("no data")); QLabel *cpintAllLabel = new QLabel(tr("Best:"), this); cpintAllValue = new QLabel(tr("no data")); QLabel *cpintCPLabel = new QLabel(tr("CP Curve:"), this); cpintCPValue = new QLabel(tr("no data")); //QFontMetrics metrics(QApplication::font()); //int width = metrics.width("8888 watts (88/88/8888)") + 10; //cpintAllValue->setFixedWidth(width); //cpintCPValue->setFixedWidth(width); // so lines up nicely cpintTimeValue->setReadOnly(false); //cpintTodayValue->setReadOnly(true); //cpintAllValue->setReadOnly(true); //cpintCPValue->setReadOnly(true); QFont font = cpintTimeValue->font(); font.setPointSize(font.pointSize()); cpintTodayValue->setFont(font); cpintAllValue->setFont(font); cpintCPValue->setFont(font); cl->addRow(cpintTimeLabel, cpintTimeValue); cl->addRow(cpintTodayLabel, cpintTodayValue); cl->addRow(cpintAllLabel, cpintAllValue); cl->addRow(cpintCPLabel, cpintCPValue); cl->addWidget(new QLabel("")); //spacing // tools /properties seriesCombo = new QComboBox(this); addSeries(); cComboSeason = new QComboBox(this); seasons = parent->seasons; resetSeasons(); QLabel *label = new QLabel(tr("Date range")); QLabel *label2 = new QLabel(tr("Date range")); if (rangemode) { cComboSeason->hide(); label2->hide(); } cpintSetCPButton = new QPushButton(tr("&Save CP value"), this); cpintSetCPButton->setEnabled(false); cl->addRow(label2, cComboSeason); dateSetting = new DateSettingsEdit(this); cl->addRow(label, dateSetting); if (rangemode == false) { dateSetting->hide(); label->hide(); } cl->addWidget(new QLabel("")); //spacing cl->addRow(new QLabel(tr("Data series")), seriesCombo); cl->addRow(new QLabel(""), cpintSetCPButton); picker = new QwtPlotPicker(QwtPlot::xBottom, QwtPlot::yLeft, QwtPicker::VLineRubberBand, QwtPicker::AlwaysOff, cpintPlot->canvas()); picker->setStateMachine(new QwtPickerDragPointMachine); picker->setRubberBandPen(GColor(CPLOTTRACKER)); connect(picker, SIGNAL(moved(const QPoint &)), SLOT(pickerMoved(const QPoint &))); connect(cpintTimeValue, SIGNAL(editingFinished()), this, SLOT(cpintTimeValueEntered())); connect(cpintSetCPButton, SIGNAL(clicked()), this, SLOT(cpintSetCPButtonClicked())); if (rangemode) { connect(this, SIGNAL(dateRangeChanged(DateRange)), SLOT(dateRangeChanged(DateRange))); } else { connect(cComboSeason, SIGNAL(currentIndexChanged(int)), this, SLOT(seasonSelected(int))); } connect(seriesCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(setSeries(int))); //connect(mainWindow, SIGNAL(rideSelected()), this, SLOT(rideSelected())); connect(this, SIGNAL(rideItemChanged(RideItem*)), this, SLOT(rideSelected())); connect(mainWindow, SIGNAL(configChanged()), cpintPlot, SLOT(configChanged())); // redraw on config change -- this seems the simplest approach connect(mainWindow, SIGNAL(configChanged()), this, SLOT(rideSelected())); connect(mainWindow, SIGNAL(rideAdded(RideItem*)), this, SLOT(newRideAdded(RideItem*))); connect(mainWindow, SIGNAL(rideDeleted(RideItem*)), this, SLOT(newRideAdded(RideItem*))); connect(seasons, SIGNAL(seasonsChanged()), this, SLOT(resetSeasons())); connect(dateSetting, SIGNAL(useCustomRange(DateRange)), this, SLOT(useCustomRange(DateRange))); connect(dateSetting, SIGNAL(useThruToday()), this, SLOT(useThruToday())); connect(dateSetting, SIGNAL(useStandardRange()), this, SLOT(useStandardRange())); }
LTMSidebar::LTMSidebar(MainWindow *parent, const QDir &home) : QWidget(parent), home(home), main(parent), active(false) { QVBoxLayout *mainLayout = new QVBoxLayout(this); mainLayout->setContentsMargins(0,0,0,0); mainLayout->setSpacing(0); setContentsMargins(0,0,0,0); seasonsWidget = new GcSplitterItem(tr("Date Ranges"), iconFromPNG(":images/sidebar/calendar.png"), this); QAction *moreSeasonAct = new QAction(iconFromPNG(":images/sidebar/extra.png"), tr("Menu"), this); seasonsWidget->addAction(moreSeasonAct); connect(moreSeasonAct, SIGNAL(triggered(void)), this, SLOT(dateRangePopup(void))); dateRangeTree = new SeasonTreeView; //allDateRanges = new QTreeWidgetItem(dateRangeTree, ROOT_TYPE); allDateRanges=dateRangeTree->invisibleRootItem(); // Drop for Seasons allDateRanges->setFlags(Qt::ItemIsEnabled | Qt::ItemIsDropEnabled); allDateRanges->setText(0, tr("Date Ranges")); dateRangeTree->setFrameStyle(QFrame::NoFrame); dateRangeTree->setColumnCount(1); dateRangeTree->setSelectionMode(QAbstractItemView::SingleSelection); dateRangeTree->header()->hide(); dateRangeTree->setIndentation(5); dateRangeTree->expandItem(allDateRanges); dateRangeTree->setContextMenuPolicy(Qt::CustomContextMenu); #ifdef Q_OS_MAC dateRangeTree->setAttribute(Qt::WA_MacShowFocusRect, 0); #endif seasonsWidget->addWidget(dateRangeTree); eventsWidget = new GcSplitterItem(tr("Events"), iconFromPNG(":images/sidebar/bookmark.png"), this); QAction *moreEventAct = new QAction(iconFromPNG(":images/sidebar/extra.png"), tr("Menu"), this); eventsWidget->addAction(moreEventAct); connect(moreEventAct, SIGNAL(triggered(void)), this, SLOT(eventPopup(void))); eventTree = new QTreeWidget; eventTree->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); //allEvents = new QTreeWidgetItem(eventTree, ROOT_TYPE); allEvents = eventTree->invisibleRootItem(); allEvents->setText(0, tr("Events")); eventTree->setFrameStyle(QFrame::NoFrame); eventTree->setColumnCount(2); eventTree->setSelectionMode(QAbstractItemView::SingleSelection); eventTree->header()->hide(); eventTree->setIndentation(5); eventTree->expandItem(allEvents); eventTree->setContextMenuPolicy(Qt::CustomContextMenu); eventTree->horizontalScrollBar()->setDisabled(true); eventTree->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); #ifdef Q_OS_MAC eventTree->setAttribute(Qt::WA_MacShowFocusRect, 0); #endif eventsWidget->addWidget(eventTree); seasons = parent->seasons; resetSeasons(); // reset the season list configChanged(); // will reset the metric tree splitter = new GcSplitter(Qt::Vertical); splitter->addWidget(seasonsWidget); splitter->addWidget(eventsWidget); GcSplitterItem *summaryWidget = new GcSplitterItem(tr("Summary"), iconFromPNG(":images/sidebar/dashboard.png"), this); summary = new QWebView(this); summary->setContentsMargins(0,0,0,0); summary->page()->view()->setContentsMargins(0,0,0,0); summary->page()->mainFrame()->setScrollBarPolicy(Qt::Vertical, Qt::ScrollBarAlwaysOff); summary->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); summary->setAcceptDrops(false); summaryWidget->addWidget(summary); QFont defaultFont; // mainwindow sets up the defaults.. we need to apply summary->settings()->setFontSize(QWebSettings::DefaultFontSize, defaultFont.pointSize()); summary->settings()->setFontFamily(QWebSettings::StandardFont, defaultFont.family()); splitter->addWidget(summaryWidget); mainLayout->addWidget(splitter); splitter->prepare(main->cyclist, "LTM"); // our date ranges connect(dateRangeTree,SIGNAL(itemSelectionChanged()), this, SLOT(dateRangeTreeWidgetSelectionChanged())); connect(dateRangeTree,SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(dateRangePopup(const QPoint &))); connect(dateRangeTree,SIGNAL(itemChanged(QTreeWidgetItem *,int)), this, SLOT(dateRangeChanged(QTreeWidgetItem*, int))); connect(dateRangeTree,SIGNAL(itemMoved(QTreeWidgetItem *,int, int)), this, SLOT(dateRangeMoved(QTreeWidgetItem*, int, int))); connect(eventTree,SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(eventPopup(const QPoint &))); // GC signal connect(main, SIGNAL(configChanged()), this, SLOT(configChanged())); connect(seasons, SIGNAL(seasonsChanged()), this, SLOT(resetSeasons())); connect(this, SIGNAL(dateRangeChanged(DateRange)), this, SLOT(setSummary(DateRange))); // let everyone know what date range we are starting with dateRangeTreeWidgetSelectionChanged(); }