diff --git a/src/ChartSettings.cpp b/src/ChartSettings.cpp new file mode 100644 index 000000000..92795ecd4 --- /dev/null +++ b/src/ChartSettings.cpp @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2012 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 "ChartSettings.h" +#include + +ChartSettings::ChartSettings(QWidget *parent, QWidget *contents) : QDialog(parent) +{ + // Set the main window title. + setWindowTitle(tr("Chart Settings")); + setAttribute(Qt::WA_DeleteOnClose); + setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint | Qt::WindowCloseButtonHint); + setModal(true); + + // Create the main layout box. + QVBoxLayout *mainVBox = new QVBoxLayout(this); + + // Set up the instructions field. + mainVBox->addWidget(contents); + + // "Done" button. + mainVBox->addSpacing(15); + QHBoxLayout *buttonHBox = new QHBoxLayout; + btnOK = new QPushButton(this); + btnOK->setFocusPolicy(Qt::NoFocus); + btnOK->setText(tr("Done")); + buttonHBox->addStretch(); + buttonHBox->addWidget(btnOK); + mainVBox->addLayout(buttonHBox); + connect(btnOK, SIGNAL(clicked()), this, SLOT(on_btnOK_clicked())); + + hide(); +} + +void ChartSettings::on_btnOK_clicked() { + // all done! + hide(); +} + +// close doesnt really close, just hides +void +ChartSettings::closeEvent(QCloseEvent* event) +{ + event->ignore(); + hide(); +} diff --git a/src/ChartSettings.h b/src/ChartSettings.h new file mode 100644 index 000000000..ff8d2f4ef --- /dev/null +++ b/src/ChartSettings.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2012 Mark Liversedge (liversedge@gmal.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 "GoldenCheetah.h" +#include +#include +#include + +#ifndef GC_ChartSettings_h +#define GC_ChartSettings_h + +class ChartSettings : public QDialog +{ + Q_OBJECT + G_OBJECT + + public: + ChartSettings(QWidget *parent, QWidget *contents); + void closeEvent(QCloseEvent* event); + + private: + QPushButton *btnOK; + + private slots: + void on_btnOK_clicked(); +}; +#endif diff --git a/src/GoldenCheetah.cpp b/src/GoldenCheetah.cpp index a09de4a25..f94424c34 100644 --- a/src/GoldenCheetah.cpp +++ b/src/GoldenCheetah.cpp @@ -35,6 +35,12 @@ void GcWindow::setControls(QWidget *x) { _controls = x; emit controlsChanged(_controls); + + if (x != NULL) { + menu->clear(); + menu->addAction(tr("Chart Settings"), this, SIGNAL(showControls())); + menu->addAction(tr("Close"), this, SLOT(_closeWindow())); + } } QString GcWindow::instanceName() const @@ -145,6 +151,23 @@ GcWindow::GcWindow() setResizable(false); setMouseTracking(true); setProperty("color", Qt::white); + + // 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); + + 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(QWidget *parent) : QFrame(parent), dragState(None) { @@ -160,6 +183,23 @@ GcWindow::GcWindow(QWidget *parent) : QFrame(parent), dragState(None) { setResizable(false); setMouseTracking(true); setProperty("color", Qt::white); + + // 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); + + 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() @@ -229,11 +269,13 @@ GcWindow::paintEvent(QPaintEvent * /*event*/) // border painter.setBrush(Qt::NoBrush); if (underMouse()) { +#if 0 QPixmap sized = closeImage.scaled(QSize(contentsMargins().top()-6, contentsMargins().top()-6)); painter.setPen(Qt::black); //painter.drawRect(QRect(0,0,width()-1,height()-1));//XXX pointless painter.drawPixmap(width()-3-sized.width(), 3, sized.width(), sized.height(), sized); +#endif } else { painter.setPen(Qt::darkGray); //painter.drawRect(QRect(0,0,width()-1,height()-1)); //XXX pointless @@ -351,8 +393,8 @@ GcWindow::spotHotSpot(QMouseEvent *e) int _height = height(); int _width = width(); - if (e->x() > (2 + width() - corner) && e->y() < corner) return (Close); - else if (_x <= corner && _y <= corner) return (TLCorner); + //if (e->x() > (2 + width() - corner) && e->y() < corner) return (Close); + if (_x <= corner && _y <= corner) return (TLCorner); else if (_x >= (_width-corner) && _y <= corner) return (TRCorner); else if (_x <= corner && _y >= (_height-corner)) return (BLCorner); else if (_x >= (_width-corner) && _y >= (_height-corner)) return (BRCorner); @@ -574,3 +616,26 @@ GcWindow::setCursorShape(DragState d) break; } } + +void +GcWindow::enterEvent(QEvent *) +{ + if (property("isManager").toBool() == false) { + if (contentsMargins().top() > 20) menuButton->setFixedSize(15,20); + else menuButton->setFixedSize(15,15); + menuButton->show(); + } +} + + +void +GcWindow::leaveEvent(QEvent *) +{ + menuButton->hide(); +} + +void +GcWindow::_closeWindow() +{ + emit closeWindow(this); +} diff --git a/src/GoldenCheetah.h b/src/GoldenCheetah.h index 211004f19..ad9c49f8e 100644 --- a/src/GoldenCheetah.h +++ b/src/GoldenCheetah.h @@ -24,6 +24,9 @@ #define myRideItem property("ride").value() #include +#include +#include +#include #include #include #include @@ -91,6 +94,8 @@ private: int oWidth, oHeight, oX, oY, mX, mY; double oHeightFactor, oWidthFactor; +public slots: + void _closeWindow(); signals: void controlsChanged(QWidget*); @@ -104,6 +109,9 @@ signals: void resized(GcWindow*); // finished resizing void moved(GcWindow*); // finished moving + void showControls(); + void closeWindow(GcWindow*); + public: GcWindow(); @@ -155,11 +163,16 @@ public: virtual void mousePressEvent(QMouseEvent *); virtual void mouseReleaseEvent(QMouseEvent *); virtual void mouseMoveEvent(QMouseEvent *); + void enterEvent(QEvent *); + void leaveEvent(QEvent *); void setDragState(DragState); void setCursorShape(DragState); DragState spotHotSpot(QMouseEvent *); void setNewSize(int w, int h); + QPushButton *settingsButton, *closeButton; + QToolButton *menuButton; + QMenu *menu; }; diff --git a/src/HomeWindow.cpp b/src/HomeWindow.cpp index ed9530179..9c09039a0 100644 --- a/src/HomeWindow.cpp +++ b/src/HomeWindow.cpp @@ -126,6 +126,9 @@ HomeWindow::HomeWindow(MainWindow *mainWindow, QString name, QString /* windowti tabLayout->setContentsMargins(0,0,0,0); tabLayout->setSpacing(0); tabbed = new QTabWidget(this); +#ifdef Q_OS_MAC + tabbed->setAttribute(Qt::WA_MacShowFocusRect, 0); +#endif tabbed->setContentsMargins(0,0,0,0); tabbed->setTabsClosable(false); tabbed->setPalette(palette); @@ -554,6 +557,10 @@ HomeWindow::addChart(GcWindow* newone) QWidget *x = dynamic_cast(newone)->controls(); QWidget *c = (x != NULL) ? x : new QWidget(this); + // link settings button to show controls + connect(newone, SIGNAL(showControls()), mainWindow->chartSettings, SLOT(show())); + connect(newone, SIGNAL(closeWindow(GcWindow*)), this, SLOT(closeWindow(GcWindow*))); + if (currentStyle == 2 && chartCursor >= 0) controlStack->insertWidget(chartCursor, c); else @@ -833,12 +840,6 @@ HomeWindow::eventFilter(QObject *object, QEvent *e) for(int i=0; i (charts[i]->width()-15)) { - return removeChart(i); - - } else { - if (charts[i] != clicked) { // we aren't clicking to toggle // clear the chart that is currently clicked @@ -858,8 +859,6 @@ HomeWindow::eventFilter(QObject *object, QEvent *e) charts[i]->repaint(); clicked = NULL; } - } - return false; } } } @@ -1477,3 +1476,8 @@ bool ViewParser::endDocument() { return TRUE; } + +void HomeWindow::closeWindow(GcWindow*thisone) +{ + if (charts.contains(thisone)) removeChart(charts.indexOf(thisone)); +} diff --git a/src/HomeWindow.h b/src/HomeWindow.h index ee1d3a496..937fb61f2 100644 --- a/src/HomeWindow.h +++ b/src/HomeWindow.h @@ -19,6 +19,7 @@ #ifndef _GC_HomeWindow_h #define _GC_HomeWindow_h 1 #include "GoldenCheetah.h" +#include "ChartSettings.h" #include "GcWindowRegistry.h" #include "GcWindowLayout.h" @@ -73,6 +74,9 @@ class HomeWindow : public GcWindow bool removeChart(int, bool confirm = true); void titleChanged(); + // window wants to close... + void closeWindow(GcWindow*); + // save / restore window state void saveState(); void restoreState(bool useDefault = false); diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index ef417d360..ee1ef8abf 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -95,6 +95,8 @@ #include "NamedSearch.h" #endif +#include "ChartSettings.h" + #include #include #include @@ -581,7 +583,12 @@ MainWindow::MainWindow(const QDir &home) : toolBox->addItem(activityHistory, QIcon(":images/activity.png"), "Activity History"); toolBox->addItem(intervalSplitter, QIcon(":images/stopwatch.png"), "Activity Intervals"); toolBox->addItem(trainTool->controls(), QIcon(":images/library.png"), "Workout Library"); - toolBox->addItem(masterControls, QIcon(":images/settings.png"), "Chart Settings"); + + // Chart Settings now in their own dialog box + chartSettings = new ChartSettings(this, masterControls); + //toolBox->addItem(masterControls, QIcon(":images/settings.png"), "Chart Settings"); + chartSettings->hide(); + #if 0 // XXX NOT YET IMPLEMENTED toolBox->addItem(new AthleteTool(QFileInfo(home.path()).path(), this), QIcon(":images/toolbar/main/athlete.png"), "Athletes"); #endif diff --git a/src/MainWindow.h b/src/MainWindow.h index 114fd89d5..974215602 100644 --- a/src/MainWindow.h +++ b/src/MainWindow.h @@ -64,6 +64,7 @@ class QTFullScreen; class TrainTool; class Lucene; class NamedSearches; +class ChartSettings; extern QList mainwindows; // keep track of all the MainWindows we have open @@ -138,6 +139,7 @@ class MainWindow : public QMainWindow HomeWindow *trainWindow; HomeWindow *analWindow; HomeWindow *currentWindow; // tracks the curerntly showing window + ChartSettings *chartSettings; // state data SpecialFields specialFields; diff --git a/src/src.pro b/src/src.pro index 30454049f..c209e3516 100644 --- a/src/src.pro +++ b/src/src.pro @@ -218,6 +218,7 @@ HEADERS += \ Bin2RideFile.h \ BingMap.h \ CalendarDownload.h \ + ChartSettings.h \ ChooseCyclistDialog.h \ Colors.h \ ColorButton.h \ @@ -401,6 +402,7 @@ SOURCES += \ Bin2RideFile.cpp \ BingMap.cpp \ CalendarDownload.cpp \ + ChartSettings.cpp \ ChooseCyclistDialog.cpp \ Coggan.cpp \ Colors.cpp \