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:
Mark Liversedge
2020-04-11 20:56:59 +01:00
parent 28b242815b
commit 587c631b82
7 changed files with 97 additions and 95 deletions

View File

@@ -17,7 +17,6 @@
*/
#include "ChartBar.h"
#include "GcScopeBar.h"
#include "DiaryWindow.h"
#include "DiarySidebar.h"
#include "Context.h"
@@ -37,6 +36,7 @@ ChartBar::ChartBar(Context *context) : QWidget(context->mainWindow), context(con
setContentsMargins(0,0,0,0);
// main layout
QHBoxLayout *mlayout = new QHBoxLayout(this);
mlayout->setSpacing(0);
@@ -65,10 +65,6 @@ ChartBar::ChartBar(Context *context) : QWidget(context->mainWindow), context(con
scrollArea->setHorizontalScrollBarPolicy(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);
@@ -138,6 +134,8 @@ ChartBar::ChartBar(Context *context) : QWidget(context->mainWindow), context(con
// appearance update
connect(context, SIGNAL(configChanged(qint32)), this, SLOT(configChanged(qint32)));
configChanged(0);
}
void
@@ -145,29 +143,35 @@ ChartBar::configChanged(qint32)
{
buttonFont = QFont();
QFontMetrics fs(buttonFont);
setFixedHeight(fs.height()+(spacing_*dpiXFactor));
scrollArea->setFixedHeight(fs.height()+(spacing_*dpiXFactor));
buttonBar->setFixedHeight(fs.height()+(spacing_*dpiXFactor));
foreach(GcScopeButton *b, buttons) {
int width = fs.width(b->text);
int height = (fs.height()+(spacing_*dpiXFactor));
setFixedHeight(height);
scrollArea->setFixedHeight(height);
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->setFixedWidth(width+(20*dpiXFactor));
b->setFixedHeight(fs.height()+(2*dpiYFactor));
b->setFixedWidth(width);
b->setFixedHeight(height);
}
}
void
ChartBar::addWidget(QString title)
{
GcScopeButton *newbutton = new GcScopeButton(this);
ChartBarItem *newbutton = new ChartBarItem(this);
newbutton->setText(title);
newbutton->setFont(buttonFont);
// make the right size
QFontMetrics fontMetric(buttonFont);
int width = fontMetric.width(title);
newbutton->setFixedWidth(width+(20*dpiXFactor));
newbutton->setFixedHeight(fontMetric.height()+(2*dpiYFactor));
int width = fontMetric.width(title) + (30 * dpiXFactor);
int height = (fontMetric.height()+(spacing_*dpiXFactor));
if (width < (80*dpiXFactor)) width=80*dpiXFactor;
newbutton->setFixedWidth(width);
newbutton->setFixedHeight(height);
// add to layout
layout->addWidget(newbutton);
@@ -201,19 +205,20 @@ ChartBar::setText(int index, QString text)
{
buttons[index]->setText(text);
QFontMetrics fontMetric(buttonFont);
int width = fontMetric.width(text);
buttons[index]->setWidth(width+(20*dpiXFactor));
int width = fontMetric.width(text) + (30*dpiXFactor);
buttons[index]->setWidth(width < (80*dpiXFactor) ? (80*dpiXFactor) : width);
tidy(); // still fit ?
}
// tidy up the scrollers on first show...
void
ChartBar::tidy()
{
// resize to button widths + 2px spacing
int width = 2*dpiXFactor;
foreach (GcScopeButton *button, buttons) {
foreach (ChartBarItem *button, buttons) {
width += button->geometry().width() + (2*dpiXFactor);
}
buttonBar->setMinimumWidth(width);
@@ -272,7 +277,7 @@ ChartBar::scrollLeft()
void
ChartBar::clear()
{
foreach(GcScopeButton *button, buttons) {
foreach(ChartBarItem *button, buttons) {
layout->removeWidget(button);
delete button;
}
@@ -311,36 +316,7 @@ ChartBar::clicked(int index)
}
#if 0
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()
{
}
ChartBar::~ChartBar() { }
void
ChartBar::paintEvent (QPaintEvent *event)
@@ -422,51 +398,48 @@ ButtonBar::paintBackground(QPaintEvent *)
painter.restore();
}
#if 0
int
ChartBar::selected()
ChartBarItem::ChartBarItem(QWidget *parent) : QWidget(parent)
{
if (home->isChecked()) return 0;
#ifdef GC_HAVE_ICAL
if (diary->isChecked()) return 1;
if (anal->isChecked()) return 2;
if (train->isChecked()) return 3;
#else
if (anal->isChecked()) return 1;
if (train->isChecked()) return 2;
#endif
// never gets here - shutup compiler
return 0;
red = highlighted = checked = false;
QFont font;
font.setPointSize(10);
//font.setWeight(QFont::Black);
setFont(font);
}
void
ChartBar::setSelected(int index)
ChartBarItem::paintEvent(QPaintEvent *)
{
// we're already there
if (index == selected()) return;
QPainter painter(this);
painter.save();
painter.setRenderHints(QPainter::Antialiasing|QPainter::TextAntialiasing, true);
// mainwindow wants to tell us to switch to a selection
home->setChecked(false);
#ifdef GC_HAVE_ICAL
diary->setChecked(false);
#endif
anal->setChecked(false);
train->setChecked(false);
// widget rectangle
QRectF body(0,0,width(), height());
#ifdef GC_HAVE_ICAL
switch (index) {
case 0 : home->setChecked(true); break;
case 1 : diary->setChecked(true); break;
case 2 : anal->setChecked(true); break;
case 3 : train->setChecked(true); break;
}
#else
switch (index) {
case 0 : home->setChecked(true); break;
case 1 : anal->setChecked(true); break;
case 2 : train->setChecked(true); break;
}
#endif
painter.setClipRect(body);
painter.setPen(Qt::NoPen);
// background - chrome or slected colour
QBrush brush(GColor(CCHROME));
if (checked) brush = QBrush(GColor(CPLOTBACKGROUND));
painter.fillRect(body, brush);
// now paint the text
QPen pen(GCColor::invertColor(brush.color()));
painter.setPen(pen);
painter.drawText(body, text, Qt::AlignBottom | Qt::AlignCenter);
// 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

View File

@@ -29,7 +29,7 @@
#include <QEvent>
class Context;
class GcScopeButton;
class ChartBarItem;
class GcLabel;
class ButtonBar;
@@ -75,7 +75,7 @@ private:
QHBoxLayout *layout;
QFont buttonFont;
QVector<GcScopeButton*> buttons;
QVector<ChartBarItem*> buttons;
QSignalMapper *signalMapper;
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

View File

@@ -46,7 +46,7 @@ void
GcToolBar::paintEvent (QPaintEvent *event)
{
// paint the darn thing!
paintBackground(event);
//paintBackground(event);
}
void

View File

@@ -2205,6 +2205,7 @@ void
MainWindow::configChanged(qint32)
{
#if 0
// Windows and Linux menu bar should match chrome
#if defined (WIN32) || defined (Q_OS_LINUX)
QColor textCol(Qt::black);
@@ -2214,6 +2215,7 @@ MainWindow::configChanged(qint32)
"QMenuBar::item { color: %1; background: %2; }")
.arg(textCol.name()).arg(menuColorString));
#endif
#endif
// Mac and Linux
QPalette tabbarPalette;

View File

@@ -750,7 +750,7 @@ HEADERS += FileIO/ArchiveFile.h FileIO/AthleteBackup.h FileIO/Bin2RideFile.h Fi
# GUI components
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/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/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 \
@@ -848,7 +848,7 @@ SOURCES += FileIO/ArchiveFile.cpp FileIO/AthleteBackup.cpp FileIO/Bin2RideFile.c
## GUI Elements and Dialogs
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/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/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 \