diff --git a/src/AllPlotWindow.cpp b/src/AllPlotWindow.cpp index d94b4197e..f88d65ad0 100644 --- a/src/AllPlotWindow.cpp +++ b/src/AllPlotWindow.cpp @@ -550,6 +550,8 @@ AllPlotWindow::AllPlotWindow(Context *context) : void AllPlotWindow::configChanged() { + setProperty("color", GColor(CRIDEPLOTBACKGROUND)); + // we're going to replot, but only if we're active // and all the other guff RideItem *ride = myRideItem; @@ -558,9 +560,6 @@ AllPlotWindow::configChanged() return; } - // ignore if null, or manual / empty - if (!ride || !ride->ride() || !ride->ride()->dataPoints().count()) return; - // Container widgets should not paint // since they tend to use naff defaults and // 'complicate' or 'make busy' the general @@ -571,6 +570,9 @@ AllPlotWindow::configChanged() stackFrame->widget()->setPalette(palette); fullPlot->setCanvasBackground(GColor(CRIDEPLOTBACKGROUND)); + // ignore if null, or manual / empty + if (!ride || !ride->ride() || !ride->ride()->dataPoints().count()) return; + // reset the charts etc if (isCompare()) { diff --git a/src/ChartBar.cpp b/src/ChartBar.cpp index 449269b64..fd6ce6561 100644 --- a/src/ChartBar.cpp +++ b/src/ChartBar.cpp @@ -25,9 +25,12 @@ ChartBar::ChartBar(Context *context) : QWidget(context->mainWindow), context(context) { + // left / right scroller icon + static QIcon leftIcon = iconFromPNG(":images/mac/left.png"); + static QIcon rightIcon = iconFromPNG(":images/mac/right.png"); setFixedHeight(23); - setContentsMargins(10,0,10,0); + setContentsMargins(3,0,3,0); // main layout QHBoxLayout *mlayout = new QHBoxLayout(this); @@ -61,8 +64,32 @@ ChartBar::ChartBar(Context *context) : QWidget(context->mainWindow), context(con scrollArea->setWidget(buttonBar); // scroll area turns it on .. we turn it off! buttonBar->setAutoFillBackground(false); + + // scroller buttons + left = new QToolButton(this); + left->setStyleSheet("QToolButton { border: none; padding: 0px; }"); + left->setAutoFillBackground(false); + left->setFixedSize(20,20); + left->setIcon(leftIcon); + left->setIconSize(QSize(20,20)); + left->setFocusPolicy(Qt::NoFocus); + mlayout->addWidget(left); + connect(left, SIGNAL(clicked()), this, SLOT(scrollLeft())); + + // menu bar in the middle of the buttons mlayout->addWidget(scrollArea); + right = new QToolButton(this); + right->setStyleSheet("QToolButton { border: none; padding: 0px; }"); + right->setAutoFillBackground(false); + right->setFixedSize(20,20); + right->setIcon(rightIcon); + right->setIconSize(QSize(20,20)); + right->setFocusPolicy(Qt::NoFocus); + mlayout->addWidget(right); + connect(right, SIGNAL(clicked()), this, SLOT(scrollRight())); + + buttonFont.setPointSize(10); buttonFont.setWeight(QFont::Black); @@ -87,6 +114,9 @@ ChartBar::ChartBar(Context *context) : QWidget(context->mainWindow), context(con signalMapper = new QSignalMapper(this); // maps each option connect(signalMapper, SIGNAL(mapped(int)), this, SLOT(clicked(int))); + + // trap resize / mouse events + installEventFilter(this); } void @@ -112,6 +142,11 @@ ChartBar::addWidget(QString title) // map signals connect(newbutton, SIGNAL(clicked(bool)), signalMapper, SLOT(map())); signalMapper->setMapping(newbutton, buttons.count()-1); + + newbutton->installEventFilter(this); + + // tidy up scrollers etc + tidy(); } void @@ -122,8 +157,61 @@ ChartBar::setText(int index, QString text) int width = fontMetric.width(text); buttons[index]->setWidth(width+20); + tidy(); // still fit ? } +// tidy up the scrollers on first show... +void +ChartBar::tidy() +{ + if (buttonBar->width() > scrollArea->width()) { + left->show(); right->show(); + } else { + left->hide(); right->hide(); + } +} + +bool +ChartBar::eventFilter(QObject *object, QEvent *e) +{ + // show/hide scrollers on resize event + if (object == this && e->type() == QEvent::Resize) { + + // we do NOT move the position, we just show/hide + // the left and right scrollers + tidy(); + } + + // showing us - tidy up + if (object == this && e->type() == QEvent::Show) { + tidy(); + } + + // enter/leave we can track approximate mouse position and decide + // if we want to 'autoscroll' + if (e->type() == QEvent::Leave || e->type() == QEvent::Enter) { + tidy(); // tidy up anyway + + // XXX for later, perhaps when drag/dropping + // we should try and be a little more fluid / animate ... + // which will probably mean using QScrollArea::ScrollContentsBy + } +} + +void +ChartBar::scrollRight() +{ + // scroll to the right... + int w = buttonBar->width(); + scrollArea->ensureVisible(w-10,0,10,10); +} + +void +ChartBar::scrollLeft() +{ + // scroll to the left + scrollArea->ensureVisible(0,0,10,10); +} void ChartBar::clear() diff --git a/src/ChartBar.h b/src/ChartBar.h index acc55111f..f28c0de9f 100644 --- a/src/ChartBar.h +++ b/src/ChartBar.h @@ -24,6 +24,9 @@ #include #include #include +#include +#include +#include class Context; #ifdef Q_OS_MAC @@ -49,12 +52,16 @@ public: public slots: void paintEvent (QPaintEvent *event); + bool eventFilter(QObject *object, QEvent *e); // trap resize void addWidget(QString); void clear(); void clicked(int); void removeWidget(int); void setText(int index, QString); //void setCurrentIndex(int index); + void scrollLeft(); + void scrollRight(); + void tidy(); signals: void currentIndexChanged(int); @@ -65,6 +72,7 @@ private: Context *context; ButtonBar *buttonBar; + QToolButton *left, *right; // scrollers, hidden if menu fits QScrollArea *scrollArea; QHBoxLayout *layout; diff --git a/src/GoldenCheetah.cpp b/src/GoldenCheetah.cpp index d107154e9..896b8bef8 100644 --- a/src/GoldenCheetah.cpp +++ b/src/GoldenCheetah.cpp @@ -177,25 +177,23 @@ GcWindow::GcWindow() setProperty("nomenu", false); // 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); + menuButton = new QPushButton(this); + menuButton->setStyleSheet("QPushButton::menu-indicator { image: none; } QPushButton { border: 0px; padding: 0px; }"); + //menuButton->setToolButtonStyle(Qt::ToolButtonTextOnly); + menuButton->setText(tr("More...")); + //menuButton->setArrowType(Qt::NoArrow); + //menuButton->setPopupMode(QPushButton::InstantPopup); 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 + menuButton->move(00,0); } -GcWindow::GcWindow(Context *context) : QFrame(context->mainWindow), dragState(None) { +GcWindow::GcWindow(Context *context) : QFrame(context->mainWindow), dragState(None) +{ qRegisterMetaType("controls"); qRegisterMetaType("ride"); qRegisterMetaType("type"); @@ -214,21 +212,19 @@ GcWindow::GcWindow(Context *context) : QFrame(context->mainWindow), dragState(No setProperty("nomenu", false); // 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); + menuButton = new QPushButton(this); + menuButton->setStyleSheet("QPushButton::menu-indicator { image: none; } QPushButton { border: 0px; padding: 0px; }"); + //menuButton->setToolButtonStyle(Qt::ToolButtonTextOnly); + menuButton->setText(tr("More...")); + //menuButton->setArrowType(Qt::NoArrow); + //menuButton->setPopupMode(QPushButton::InstantPopup); 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() @@ -243,7 +239,20 @@ GcWindow::amVisible() return true; } +void +GcWindow::setColor(QColor x) +{ + if (_color != x) { + _color = x; + emit colorChanged(x); + } +} +QColor +GcWindow::color() const +{ + return _color; +} void GcWindow::paintEvent(QPaintEvent * /*event*/) @@ -651,8 +660,8 @@ void GcWindow::enterEvent(QEvent *) { if (property("nomenu") == false && property("isManager").toBool() == false) { - if (contentsMargins().top() > 20) menuButton->setFixedSize(15,20); - else menuButton->setFixedSize(15,15); + if (contentsMargins().top() > 20) menuButton->setFixedSize(80,30); + else menuButton->setFixedSize(80, 15); menuButton->show(); } } @@ -670,7 +679,8 @@ GcWindow::_closeWindow() emit closeWindow(this); } -GcChartWindow::GcChartWindow(Context *context) : GcWindow(context) { +GcChartWindow::GcChartWindow(Context *context) : GcWindow(context) +{ // // Default layout // @@ -720,6 +730,8 @@ GcChartWindow::GcChartWindow(Context *context) : GcWindow(context) { _mainLayout->addWidget(_revealControls,0,0, Qt::AlignTop); _mainWidget->setLayout(_mainLayout); + connect(this, SIGNAL(colorChanged(QColor)), this, SLOT(colorChanged(QColor))); + // // Default Blank layout // @@ -750,6 +762,30 @@ GcChartWindow::GcChartWindow(Context *context) : GcWindow(context) { _blank->setLayout(_defaultBlankLayout); } +void +GcChartWindow::colorChanged(QColor z) +{ + QColor cRGB = z.convertTo(QColor::Rgb); + // lets work it out.. + int r = cRGB.red() < 128 ? 255 : 0; + int g = cRGB.green() < 128 ? 255 : 0; + int b = cRGB.blue() < 128 ? 255 : 0; + QColor fgColor = QColor(r,g,b); + + // so z is color for bg and fgColor is for fg + QString stylesheet = QString("color: rgb(%1, %2, %3); background-color: rgb(%4, %5, %6)") + .arg(fgColor.red()) + .arg(fgColor.green()) + .arg(fgColor.blue()) + .arg(z.red()) + .arg(z.green()) + .arg(z.blue()); + + menuButton->setStyleSheet(QString("QPushButton::menu-indicator { image: none; } QPushButton { border: 0px; padding: 0px; %1 }").arg(stylesheet)); + _revealControls->setStyleSheet(stylesheet); + menuButton->setStyleSheet(stylesheet); +} + void GcChartWindow:: setChartLayout(QLayout *layout) { diff --git a/src/GoldenCheetah.h b/src/GoldenCheetah.h index 186483b68..892aebae3 100644 --- a/src/GoldenCheetah.h +++ b/src/GoldenCheetah.h @@ -81,6 +81,9 @@ private: Q_PROPERTY(bool resizable READ resizable WRITE setResizable USER true) Q_PROPERTY(bool gripped READ gripped WRITE setGripped) + Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged USER false) + QColor _color; + QWidget *_controls; QString _title; @@ -111,6 +114,7 @@ signals: void rideItemChanged(RideItem*); void heightFactorChanged(double); void widthFactorChanged(double); + void colorChanged(QColor); void dateRangeChanged(DateRange); void resizing(GcWindow*); void moving(GcWindow*); @@ -151,6 +155,9 @@ public: void setHeightFactor(double); double heightFactor() const; + void setColor(QColor); + QColor color() const; + void setResizable(bool); bool resizable() const; @@ -194,7 +201,7 @@ public: void setNewSize(int w, int h); QPushButton *settingsButton, *closeButton; - QToolButton *menuButton; + QPushButton *menuButton; QMenu *menu; }; @@ -244,6 +251,7 @@ public: public slots: void hideRevealControls(); void saveImage(); + void colorChanged(QColor); };