mirror of
https://github.com/GoldenCheetah/GoldenCheetah.git
synced 2026-04-15 05:32:21 +00:00
Deprecate ScopeBar code, cleaner ChartBar
.. the chart bar used some of the code from the old scopebar widget so decoupled that and made it a little more modern. .. GcScopeBar now deprecated
This commit is contained in:
@@ -17,7 +17,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "ChartBar.h"
|
#include "ChartBar.h"
|
||||||
#include "GcScopeBar.h"
|
|
||||||
#include "DiaryWindow.h"
|
#include "DiaryWindow.h"
|
||||||
#include "DiarySidebar.h"
|
#include "DiarySidebar.h"
|
||||||
#include "Context.h"
|
#include "Context.h"
|
||||||
@@ -37,6 +36,7 @@ ChartBar::ChartBar(Context *context) : QWidget(context->mainWindow), context(con
|
|||||||
|
|
||||||
setContentsMargins(0,0,0,0);
|
setContentsMargins(0,0,0,0);
|
||||||
|
|
||||||
|
|
||||||
// main layout
|
// main layout
|
||||||
QHBoxLayout *mlayout = new QHBoxLayout(this);
|
QHBoxLayout *mlayout = new QHBoxLayout(this);
|
||||||
mlayout->setSpacing(0);
|
mlayout->setSpacing(0);
|
||||||
@@ -65,10 +65,6 @@ ChartBar::ChartBar(Context *context) : QWidget(context->mainWindow), context(con
|
|||||||
scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||||
scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||||
|
|
||||||
QFontMetrics fs(buttonFont);
|
|
||||||
setFixedHeight(fs.height()+(spacing_*dpiXFactor));
|
|
||||||
scrollArea->setFixedHeight(fs.height()+(spacing_*dpiXFactor));
|
|
||||||
buttonBar->setFixedHeight(fs.height()+(spacing_*dpiXFactor));
|
|
||||||
|
|
||||||
scrollArea->setWidget(buttonBar);
|
scrollArea->setWidget(buttonBar);
|
||||||
|
|
||||||
@@ -138,6 +134,8 @@ ChartBar::ChartBar(Context *context) : QWidget(context->mainWindow), context(con
|
|||||||
|
|
||||||
// appearance update
|
// appearance update
|
||||||
connect(context, SIGNAL(configChanged(qint32)), this, SLOT(configChanged(qint32)));
|
connect(context, SIGNAL(configChanged(qint32)), this, SLOT(configChanged(qint32)));
|
||||||
|
|
||||||
|
configChanged(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -145,29 +143,35 @@ ChartBar::configChanged(qint32)
|
|||||||
{
|
{
|
||||||
buttonFont = QFont();
|
buttonFont = QFont();
|
||||||
QFontMetrics fs(buttonFont);
|
QFontMetrics fs(buttonFont);
|
||||||
setFixedHeight(fs.height()+(spacing_*dpiXFactor));
|
int height = (fs.height()+(spacing_*dpiXFactor));
|
||||||
scrollArea->setFixedHeight(fs.height()+(spacing_*dpiXFactor));
|
|
||||||
buttonBar->setFixedHeight(fs.height()+(spacing_*dpiXFactor));
|
setFixedHeight(height);
|
||||||
foreach(GcScopeButton *b, buttons) {
|
scrollArea->setFixedHeight(height);
|
||||||
int width = fs.width(b->text);
|
buttonBar->setFixedHeight(height);
|
||||||
|
|
||||||
|
foreach(ChartBarItem *b, buttons) {
|
||||||
|
int width = fs.width(b->text) + (30 * dpiXFactor);
|
||||||
|
if (width < (80*dpiXFactor)) width=80*dpiXFactor;
|
||||||
b->setFont(buttonFont);
|
b->setFont(buttonFont);
|
||||||
b->setFixedWidth(width+(20*dpiXFactor));
|
b->setFixedWidth(width);
|
||||||
b->setFixedHeight(fs.height()+(2*dpiYFactor));
|
b->setFixedHeight(height);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ChartBar::addWidget(QString title)
|
ChartBar::addWidget(QString title)
|
||||||
{
|
{
|
||||||
GcScopeButton *newbutton = new GcScopeButton(this);
|
ChartBarItem *newbutton = new ChartBarItem(this);
|
||||||
newbutton->setText(title);
|
newbutton->setText(title);
|
||||||
newbutton->setFont(buttonFont);
|
newbutton->setFont(buttonFont);
|
||||||
|
|
||||||
// make the right size
|
// make the right size
|
||||||
QFontMetrics fontMetric(buttonFont);
|
QFontMetrics fontMetric(buttonFont);
|
||||||
int width = fontMetric.width(title);
|
int width = fontMetric.width(title) + (30 * dpiXFactor);
|
||||||
newbutton->setFixedWidth(width+(20*dpiXFactor));
|
int height = (fontMetric.height()+(spacing_*dpiXFactor));
|
||||||
newbutton->setFixedHeight(fontMetric.height()+(2*dpiYFactor));
|
if (width < (80*dpiXFactor)) width=80*dpiXFactor;
|
||||||
|
newbutton->setFixedWidth(width);
|
||||||
|
newbutton->setFixedHeight(height);
|
||||||
|
|
||||||
// add to layout
|
// add to layout
|
||||||
layout->addWidget(newbutton);
|
layout->addWidget(newbutton);
|
||||||
@@ -201,19 +205,20 @@ ChartBar::setText(int index, QString text)
|
|||||||
{
|
{
|
||||||
buttons[index]->setText(text);
|
buttons[index]->setText(text);
|
||||||
QFontMetrics fontMetric(buttonFont);
|
QFontMetrics fontMetric(buttonFont);
|
||||||
int width = fontMetric.width(text);
|
int width = fontMetric.width(text) + (30*dpiXFactor);
|
||||||
buttons[index]->setWidth(width+(20*dpiXFactor));
|
buttons[index]->setWidth(width < (80*dpiXFactor) ? (80*dpiXFactor) : width);
|
||||||
|
|
||||||
tidy(); // still fit ?
|
tidy(); // still fit ?
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// tidy up the scrollers on first show...
|
// tidy up the scrollers on first show...
|
||||||
void
|
void
|
||||||
ChartBar::tidy()
|
ChartBar::tidy()
|
||||||
{
|
{
|
||||||
// resize to button widths + 2px spacing
|
// resize to button widths + 2px spacing
|
||||||
int width = 2*dpiXFactor;
|
int width = 2*dpiXFactor;
|
||||||
foreach (GcScopeButton *button, buttons) {
|
foreach (ChartBarItem *button, buttons) {
|
||||||
width += button->geometry().width() + (2*dpiXFactor);
|
width += button->geometry().width() + (2*dpiXFactor);
|
||||||
}
|
}
|
||||||
buttonBar->setMinimumWidth(width);
|
buttonBar->setMinimumWidth(width);
|
||||||
@@ -272,7 +277,7 @@ ChartBar::scrollLeft()
|
|||||||
void
|
void
|
||||||
ChartBar::clear()
|
ChartBar::clear()
|
||||||
{
|
{
|
||||||
foreach(GcScopeButton *button, buttons) {
|
foreach(ChartBarItem *button, buttons) {
|
||||||
layout->removeWidget(button);
|
layout->removeWidget(button);
|
||||||
delete button;
|
delete button;
|
||||||
}
|
}
|
||||||
@@ -311,36 +316,7 @@ ChartBar::clicked(int index)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#if 0
|
ChartBar::~ChartBar() { }
|
||||||
ChartBar::setHighlighted()
|
|
||||||
{
|
|
||||||
if (context->isfiltered) {
|
|
||||||
searchLabel->setHighlighted(true);
|
|
||||||
searchLabel->show();
|
|
||||||
#ifndef Q_OS_MAC
|
|
||||||
home->setHighlighted(true);
|
|
||||||
anal->setHighlighted(true);
|
|
||||||
#ifdef GC_HAVE_ICAL
|
|
||||||
diary->setHighlighted(true);
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
} else {
|
|
||||||
searchLabel->setHighlighted(false);
|
|
||||||
searchLabel->hide();
|
|
||||||
#ifndef Q_OS_MAC
|
|
||||||
home->setHighlighted(false);
|
|
||||||
anal->setHighlighted(false);
|
|
||||||
#ifdef GC_HAVE_ICAL
|
|
||||||
diary->setHighlighted(false);
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
ChartBar::~ChartBar()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ChartBar::paintEvent (QPaintEvent *event)
|
ChartBar::paintEvent (QPaintEvent *event)
|
||||||
@@ -422,51 +398,48 @@ ButtonBar::paintBackground(QPaintEvent *)
|
|||||||
painter.restore();
|
painter.restore();
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
ChartBarItem::ChartBarItem(QWidget *parent) : QWidget(parent)
|
||||||
int
|
|
||||||
ChartBar::selected()
|
|
||||||
{
|
{
|
||||||
if (home->isChecked()) return 0;
|
red = highlighted = checked = false;
|
||||||
#ifdef GC_HAVE_ICAL
|
QFont font;
|
||||||
if (diary->isChecked()) return 1;
|
font.setPointSize(10);
|
||||||
if (anal->isChecked()) return 2;
|
//font.setWeight(QFont::Black);
|
||||||
if (train->isChecked()) return 3;
|
setFont(font);
|
||||||
#else
|
|
||||||
if (anal->isChecked()) return 1;
|
|
||||||
if (train->isChecked()) return 2;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// never gets here - shutup compiler
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ChartBar::setSelected(int index)
|
ChartBarItem::paintEvent(QPaintEvent *)
|
||||||
{
|
{
|
||||||
// we're already there
|
QPainter painter(this);
|
||||||
if (index == selected()) return;
|
painter.save();
|
||||||
|
painter.setRenderHints(QPainter::Antialiasing|QPainter::TextAntialiasing, true);
|
||||||
|
|
||||||
// mainwindow wants to tell us to switch to a selection
|
// widget rectangle
|
||||||
home->setChecked(false);
|
QRectF body(0,0,width(), height());
|
||||||
#ifdef GC_HAVE_ICAL
|
|
||||||
diary->setChecked(false);
|
|
||||||
#endif
|
|
||||||
anal->setChecked(false);
|
|
||||||
train->setChecked(false);
|
|
||||||
|
|
||||||
#ifdef GC_HAVE_ICAL
|
painter.setClipRect(body);
|
||||||
switch (index) {
|
painter.setPen(Qt::NoPen);
|
||||||
case 0 : home->setChecked(true); break;
|
|
||||||
case 1 : diary->setChecked(true); break;
|
// background - chrome or slected colour
|
||||||
case 2 : anal->setChecked(true); break;
|
QBrush brush(GColor(CCHROME));
|
||||||
case 3 : train->setChecked(true); break;
|
if (checked) brush = QBrush(GColor(CPLOTBACKGROUND));
|
||||||
}
|
painter.fillRect(body, brush);
|
||||||
#else
|
|
||||||
switch (index) {
|
// now paint the text
|
||||||
case 0 : home->setChecked(true); break;
|
QPen pen(GCColor::invertColor(brush.color()));
|
||||||
case 1 : anal->setChecked(true); break;
|
painter.setPen(pen);
|
||||||
case 2 : train->setChecked(true); break;
|
painter.drawText(body, text, Qt::AlignBottom | Qt::AlignCenter);
|
||||||
}
|
|
||||||
#endif
|
// draw the bar
|
||||||
|
if (checked) painter.fillRect(QRect(0,0,geometry().width(), 3*dpiXFactor), QBrush(GColor(CPLOTMARKER)));
|
||||||
|
painter.restore();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
ChartBarItem::event(QEvent *e)
|
||||||
|
{
|
||||||
|
// entry / exit event repaint for hover color
|
||||||
|
if (e->type() == QEvent::Leave || e->type() == QEvent::Enter) repaint();
|
||||||
|
if (e->type() == QEvent::MouseButtonPress && underMouse()) emit clicked(checked);
|
||||||
|
return QWidget::event(e);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|||||||
@@ -29,7 +29,7 @@
|
|||||||
#include <QEvent>
|
#include <QEvent>
|
||||||
|
|
||||||
class Context;
|
class Context;
|
||||||
class GcScopeButton;
|
class ChartBarItem;
|
||||||
class GcLabel;
|
class GcLabel;
|
||||||
class ButtonBar;
|
class ButtonBar;
|
||||||
|
|
||||||
@@ -75,7 +75,7 @@ private:
|
|||||||
QHBoxLayout *layout;
|
QHBoxLayout *layout;
|
||||||
|
|
||||||
QFont buttonFont;
|
QFont buttonFont;
|
||||||
QVector<GcScopeButton*> buttons;
|
QVector<ChartBarItem*> buttons;
|
||||||
QSignalMapper *signalMapper;
|
QSignalMapper *signalMapper;
|
||||||
|
|
||||||
QMenu *barMenu, *chartMenu;
|
QMenu *barMenu, *chartMenu;
|
||||||
@@ -103,4 +103,31 @@ private:
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class ChartBarItem : public QWidget
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
ChartBarItem(QWidget *parent);
|
||||||
|
void setText(QString _text) { text = _text; }
|
||||||
|
void setChecked(bool _checked) { checked = _checked; repaint(); }
|
||||||
|
bool isChecked() { return checked; }
|
||||||
|
void setWidth(int x) { setFixedWidth(x); }
|
||||||
|
void setHighlighted(bool x) { highlighted = x; }
|
||||||
|
bool ishighlighted() const { return highlighted; }
|
||||||
|
void setRed(bool x) { red = x; }
|
||||||
|
|
||||||
|
QString text;
|
||||||
|
signals:
|
||||||
|
void clicked(bool);
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void paintEvent(QPaintEvent *);
|
||||||
|
bool event(QEvent *e);
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool checked;
|
||||||
|
bool highlighted;
|
||||||
|
bool red;
|
||||||
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ void
|
|||||||
GcToolBar::paintEvent (QPaintEvent *event)
|
GcToolBar::paintEvent (QPaintEvent *event)
|
||||||
{
|
{
|
||||||
// paint the darn thing!
|
// paint the darn thing!
|
||||||
paintBackground(event);
|
//paintBackground(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|||||||
@@ -2205,6 +2205,7 @@ void
|
|||||||
MainWindow::configChanged(qint32)
|
MainWindow::configChanged(qint32)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
#if 0
|
||||||
// Windows and Linux menu bar should match chrome
|
// Windows and Linux menu bar should match chrome
|
||||||
#if defined (WIN32) || defined (Q_OS_LINUX)
|
#if defined (WIN32) || defined (Q_OS_LINUX)
|
||||||
QColor textCol(Qt::black);
|
QColor textCol(Qt::black);
|
||||||
@@ -2214,6 +2215,7 @@ MainWindow::configChanged(qint32)
|
|||||||
"QMenuBar::item { color: %1; background: %2; }")
|
"QMenuBar::item { color: %1; background: %2; }")
|
||||||
.arg(textCol.name()).arg(menuColorString));
|
.arg(textCol.name()).arg(menuColorString));
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
// Mac and Linux
|
// Mac and Linux
|
||||||
QPalette tabbarPalette;
|
QPalette tabbarPalette;
|
||||||
|
|||||||
@@ -750,7 +750,7 @@ HEADERS += FileIO/ArchiveFile.h FileIO/AthleteBackup.h FileIO/Bin2RideFile.h Fi
|
|||||||
# GUI components
|
# GUI components
|
||||||
HEADERS += Gui/AboutDialog.h Gui/AddIntervalDialog.h Gui/AnalysisSidebar.h Gui/ChooseCyclistDialog.h Gui/ColorButton.h \
|
HEADERS += Gui/AboutDialog.h Gui/AddIntervalDialog.h Gui/AnalysisSidebar.h Gui/ChooseCyclistDialog.h Gui/ColorButton.h \
|
||||||
Gui/Colors.h Gui/CompareDateRange.h Gui/CompareInterval.h Gui/ComparePane.h Gui/ConfigDialog.h Gui/DiarySidebar.h \
|
Gui/Colors.h Gui/CompareDateRange.h Gui/CompareInterval.h Gui/ComparePane.h Gui/ConfigDialog.h Gui/DiarySidebar.h \
|
||||||
Gui/DragBar.h Gui/EstimateCPDialog.h Gui/GcCrashDialog.h Gui/GcScopeBar.h Gui/GcSideBarItem.h Gui/GcToolBar.h Gui/GcWindowLayout.h \
|
Gui/DragBar.h Gui/EstimateCPDialog.h Gui/GcCrashDialog.h Gui/GcSideBarItem.h Gui/GcToolBar.h Gui/GcWindowLayout.h \
|
||||||
Gui/GcWindowRegistry.h Gui/GenerateHeatMapDialog.h Gui/GProgressDialog.h Gui/HelpWhatsThis.h Gui/HelpWindow.h \
|
Gui/GcWindowRegistry.h Gui/GenerateHeatMapDialog.h Gui/GProgressDialog.h Gui/HelpWhatsThis.h Gui/HelpWindow.h \
|
||||||
Gui/IntervalTreeView.h Gui/LTMSidebar.h Gui/MainWindow.h Gui/NewCyclistDialog.h Gui/Pages.h Gui/RideNavigator.h Gui/RideNavigatorProxy.h \
|
Gui/IntervalTreeView.h Gui/LTMSidebar.h Gui/MainWindow.h Gui/NewCyclistDialog.h Gui/Pages.h Gui/RideNavigator.h Gui/RideNavigatorProxy.h \
|
||||||
Gui/SaveDialogs.h Gui/SearchBox.h Gui/SearchFilterBox.h Gui/SolveCPDialog.h Gui/Tab.h Gui/TabView.h Gui/ToolsRhoEstimator.h \
|
Gui/SaveDialogs.h Gui/SearchBox.h Gui/SearchFilterBox.h Gui/SolveCPDialog.h Gui/Tab.h Gui/TabView.h Gui/ToolsRhoEstimator.h \
|
||||||
@@ -848,7 +848,7 @@ SOURCES += FileIO/ArchiveFile.cpp FileIO/AthleteBackup.cpp FileIO/Bin2RideFile.c
|
|||||||
## GUI Elements and Dialogs
|
## GUI Elements and Dialogs
|
||||||
SOURCES += Gui/AboutDialog.cpp Gui/AddIntervalDialog.cpp Gui/AnalysisSidebar.cpp Gui/ChooseCyclistDialog.cpp Gui/ColorButton.cpp \
|
SOURCES += Gui/AboutDialog.cpp Gui/AddIntervalDialog.cpp Gui/AnalysisSidebar.cpp Gui/ChooseCyclistDialog.cpp Gui/ColorButton.cpp \
|
||||||
Gui/Colors.cpp Gui/CompareDateRange.cpp Gui/CompareInterval.cpp Gui/ComparePane.cpp Gui/ConfigDialog.cpp Gui/DiarySidebar.cpp \
|
Gui/Colors.cpp Gui/CompareDateRange.cpp Gui/CompareInterval.cpp Gui/ComparePane.cpp Gui/ConfigDialog.cpp Gui/DiarySidebar.cpp \
|
||||||
Gui/DragBar.cpp Gui/EstimateCPDialog.cpp Gui/GcCrashDialog.cpp Gui/GcScopeBar.cpp Gui/GcSideBarItem.cpp Gui/GcToolBar.cpp Gui/GcWindowLayout.cpp \
|
Gui/DragBar.cpp Gui/EstimateCPDialog.cpp Gui/GcCrashDialog.cpp Gui/GcSideBarItem.cpp Gui/GcToolBar.cpp Gui/GcWindowLayout.cpp \
|
||||||
Gui/GcWindowRegistry.cpp Gui/GenerateHeatMapDialog.cpp Gui/GProgressDialog.cpp Gui/HelpWhatsThis.cpp Gui/HelpWindow.cpp \
|
Gui/GcWindowRegistry.cpp Gui/GenerateHeatMapDialog.cpp Gui/GProgressDialog.cpp Gui/HelpWhatsThis.cpp Gui/HelpWindow.cpp \
|
||||||
Gui/IntervalTreeView.cpp Gui/LTMSidebar.cpp Gui/MainWindow.cpp Gui/NewCyclistDialog.cpp Gui/Pages.cpp Gui/RideNavigator.cpp Gui/SaveDialogs.cpp \
|
Gui/IntervalTreeView.cpp Gui/LTMSidebar.cpp Gui/MainWindow.cpp Gui/NewCyclistDialog.cpp Gui/Pages.cpp Gui/RideNavigator.cpp Gui/SaveDialogs.cpp \
|
||||||
Gui/SearchBox.cpp Gui/SearchFilterBox.cpp Gui/SolveCPDialog.cpp Gui/Tab.cpp Gui/TabView.cpp Gui/ToolsRhoEstimator.cpp Gui/Views.cpp \
|
Gui/SearchBox.cpp Gui/SearchFilterBox.cpp Gui/SolveCPDialog.cpp Gui/Tab.cpp Gui/TabView.cpp Gui/ToolsRhoEstimator.cpp Gui/Views.cpp \
|
||||||
|
|||||||
Reference in New Issue
Block a user