Skip to content

Commit

Permalink
Perspectives - Part 1 of 4
Browse files Browse the repository at this point in the history
The user will be able to create collections of charts as opposed to
the single long list of charts in each of the four views.

This first update:

.. update toolbar to include a perspective selector

.. also updated aesthetics of toolbar (mostly icons on hidpi)

Further updates pending will:

.. part 2 will introduce code to add, save and restore perspectives

.. part 3 will introduce code to manage and rename perspectives

.. part 4 will introduce new defaults for each perspective

A future enhancement may allow the perspective to be aligned to a
specific sport in activity view, so the perspective can be selected
based upon the sport of the activity being analysed. But that will
not be part of these changes.
  • Loading branch information
liversedge committed Jun 18, 2021
1 parent 061cb93 commit 3888246
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 28 deletions.
13 changes: 13 additions & 0 deletions src/Gui/GcSideBarItem.cpp
Expand Up @@ -55,6 +55,19 @@ QIcon iconFromPNG(QString filename, bool emboss)
return QIcon(QPixmap::fromImage(white));
}

QIcon iconFromPNG(QString filename, QSize size)
{
QImage pngImage;
pngImage.load(filename);

// use muted dark gray color
QImage gray8 = pngImage.convertToFormat(QImage::Format_Indexed8);
gray8.setColor(0, QColor(80,80,80, 170).rgb());

return QIcon(QPixmap::fromImage(gray8,Qt::ColorOnly|Qt::PreferDither|Qt::DiffuseAlphaDither).scaled(size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));

}

//
// GcSplitter -- The sidebar is largely comprised of this which contains a splitter (GcSubSplitter)
// and a control (GcSplitterControl) at the bottom with icons to show/hide items.
Expand Down
1 change: 1 addition & 0 deletions src/Gui/GcSideBarItem.h
Expand Up @@ -170,5 +170,6 @@ public slots:

};

extern QIcon iconFromPNG(QString filename, QSize size);
extern QIcon iconFromPNG(QString filename, bool emboss = true);
#endif
66 changes: 52 additions & 14 deletions src/Gui/MainWindow.cpp
Expand Up @@ -273,26 +273,26 @@ MainWindow::MainWindow(const QDir &home)
metal.setColor(QPalette::Button, QColor(215,215,215));

// get those icons
sidebarIcon = iconFromPNG(":images/mac/sidebar.png");
lowbarIcon = iconFromPNG(":images/mac/lowbar.png");
tabbedIcon = iconFromPNG(":images/mac/tabbed.png");
tiledIcon = iconFromPNG(":images/mac/tiled.png");
sidebarIcon = iconFromPNG(":images/mac/sidebar.png", QSize(16*dpiXFactor,16*dpiXFactor));
lowbarIcon = iconFromPNG(":images/mac/lowbar.png", QSize(16*dpiXFactor,16*dpiXFactor));
tabbedIcon = iconFromPNG(":images/mac/tabbed.png", QSize(20*dpiXFactor,20*dpiXFactor));
tiledIcon = iconFromPNG(":images/mac/tiled.png", QSize(20*dpiXFactor,20*dpiXFactor));
backIcon = iconFromPNG(":images/mac/back.png");
forwardIcon = iconFromPNG(":images/mac/forward.png");
QSize isize(19 *dpiXFactor,19 *dpiYFactor);
QSize isize(20 *dpiXFactor,20 *dpiYFactor);

back = new QPushButton(this);
back->setIcon(backIcon);
back->setFixedHeight(24 *dpiYFactor);
back->setFixedWidth(32 *dpiYFactor);
back->setFixedWidth(24 *dpiYFactor);
back->setIconSize(isize);
back->setStyle(toolStyle);
connect(back, SIGNAL(clicked(bool)), this, SIGNAL(backClicked()));

forward = new QPushButton(this);
forward->setIcon(forwardIcon);
forward->setFixedHeight(24 *dpiYFactor);
forward->setFixedWidth(32 *dpiYFactor);
forward->setFixedWidth(24 *dpiYFactor);
forward->setIconSize(isize);
forward->setStyle(toolStyle);
connect(forward, SIGNAL(clicked(bool)), this, SIGNAL(forwardClicked()));
Expand Down Expand Up @@ -327,7 +327,7 @@ MainWindow::MainWindow(const QDir &home)
styleSelector->setSegmentToolTip(0, tr("Tabbed View"));
styleSelector->setSegmentToolTip(1, tr("Tiled View"));
styleSelector->setSelectionBehavior(QtSegmentControl::SelectOne); //wince. spelling. ugh
styleSelector->setFixedHeight(24 * dpiXFactor);
styleSelector->setFixedHeight(24 * dpiYFactor);
styleSelector->setIconSize(isize);
styleSelector->setPalette(metal);
connect(styleSelector, SIGNAL(segmentSelected(int)), this, SLOT(setStyleFromSegment(int))); //avoid toggle infinitely
Expand All @@ -354,6 +354,12 @@ MainWindow::MainWindow(const QDir &home)
#endif

// add a search box on far right, but with a little space too
perspectiveSelector = new QComboBox(this);
perspectiveSelector->setStyle(toolStyle);
perspectiveSelector->setFixedWidth(200 * dpiXFactor);
perspectiveSelector->setFixedHeight(28 * dpiYFactor);
connect(perspectiveSelector, SIGNAL(currentIndexChanged(int)), this, SLOT(perspectiveSelected(int)));

searchBox = new SearchFilterBox(this,context,false);

searchBox->setStyle(toolStyle);
Expand All @@ -367,6 +373,7 @@ MainWindow::MainWindow(const QDir &home)
head->addWidget(space);
head->addWidget(back);
head->addWidget(forward);
head->addWidget(perspectiveSelector);
head->addStretch();
head->addWidget(sidelist);
head->addWidget(lowbar);
Expand All @@ -379,13 +386,13 @@ MainWindow::MainWindow(const QDir &home)
HelpWhatsThis *helpSearchBox = new HelpWhatsThis(searchBox);
searchBox->setWhatsThis(helpSearchBox->getWhatsThisText(HelpWhatsThis::SearchFilterBox));

Spacer *spacer = new Spacer(this);
spacer->setFixedWidth(5 *dpiYFactor);
head->addWidget(spacer);
space = new Spacer(this);
space->setFixedWidth(5 *dpiYFactor);
head->addWidget(space);
head->addWidget(searchBox);
spacer = new Spacer(this);
spacer->setFixedWidth(5 *dpiYFactor);
head->addWidget(spacer);
space = new Spacer(this);
space->setFixedWidth(5 *dpiYFactor);
head->addWidget(space);

#ifdef Q_OS_LINUX
// check opengl is available with version 2 or higher
Expand Down Expand Up @@ -1258,6 +1265,7 @@ void
MainWindow::selectAthlete()
{
viewStack->setCurrentIndex(0);
perspectiveSelector->hide();
}

void
Expand All @@ -1266,6 +1274,8 @@ MainWindow::selectAnalysis()
viewStack->setCurrentIndex(1);
sidebar->setItemSelected(3, true);
currentTab->selectView(1);
currentTab->analysisView->setPerspectives(perspectiveSelector);
perspectiveSelector->show();
setToolButtons();
}

Expand All @@ -1275,6 +1285,8 @@ MainWindow::selectTrain()
viewStack->setCurrentIndex(1);
sidebar->setItemSelected(5, true);
currentTab->selectView(3);
currentTab->trainView->setPerspectives(perspectiveSelector);
perspectiveSelector->show();
setToolButtons();
}

Expand All @@ -1283,6 +1295,8 @@ MainWindow::selectDiary()
{
viewStack->setCurrentIndex(1);
currentTab->selectView(2);
currentTab->diaryView->setPerspectives(perspectiveSelector);
perspectiveSelector->show();
setToolButtons();
}

Expand All @@ -1292,6 +1306,8 @@ MainWindow::selectHome()
viewStack->setCurrentIndex(1);
sidebar->setItemSelected(2, true);
currentTab->selectView(0);
currentTab->homeView->setPerspectives(perspectiveSelector);
perspectiveSelector->show();
setToolButtons();
}

Expand Down Expand Up @@ -1347,6 +1363,20 @@ MainWindow::setToolButtons()
#endif
}

void
MainWindow::perspectiveSelected(int index)
{
// set the perspective for the current view
int view = currentTab->currentView();

switch (view) {
case 0: currentTab->homeView->perspectiveSelected(index); break;
case 1: currentTab->diaryView->perspectiveSelected(index); break;
case 2: currentTab->analysisView->perspectiveSelected(index); break;
case 3: currentTab->trainView->perspectiveSelected(index); break;
}
}

/*----------------------------------------------------------------------
* Drag and Drop
*--------------------------------------------------------------------*/
Expand Down Expand Up @@ -2264,6 +2294,14 @@ MainWindow::configChanged(qint32)
// search filter box match chrome color
searchBox->setStyleSheet(QString("QLineEdit { background: %1; color: %2; }").arg(GColor(CCHROME).name()).arg(GCColor::invertColor(GColor(CCHROME)).name()));

// perspective selector mimics sidebar colors
QColor selected;
if (GCColor::invertColor(GColor(CCHROME)).name() == Qt::white) selected = QColor(Qt::lightGray);
else selected = QColor(Qt::darkGray);
perspectiveSelector->setStyleSheet(QString("QComboBox { background: %1; color: %2; }"
"QComboBox::item { background: %1; color: %2; }"
"QComboBox::item::selected { background: %3; color: %1; }").arg(GColor(CCHROME).name()).arg(GCColor::invertColor(GColor(CCHROME)).name()).arg(selected.name()));

#endif
QString buttonstyle = QString("QPushButton { border: none; background-color: %1; }").arg(CCHROME);
back->setStyleSheet(buttonstyle);
Expand Down
4 changes: 4 additions & 0 deletions src/Gui/MainWindow.h
Expand Up @@ -141,6 +141,9 @@ class MainWindow : public QMainWindow
void support();
void actionClicked(int);

// perspective selected
void perspectiveSelected(int index);

// chart importing
void importCharts(QStringList);

Expand Down Expand Up @@ -287,6 +290,7 @@ class MainWindow : public QMainWindow
QTFullScreen *fullScreen;
#endif

QComboBox *perspectiveSelector;
SearchFilterBox *searchBox;

// Not on Mac so use other types
Expand Down
30 changes: 18 additions & 12 deletions src/Gui/SearchBox.cpp
Expand Up @@ -39,7 +39,7 @@ SearchBox::SearchBox(Context *context, QWidget *parent, bool nochooser)
//clear button
clearButton = new QToolButton(this);
clearButton->setStyleSheet("QToolButton { border: none; padding: 0px; }");
QIcon pixmap(":images/toolbar/popbutton.png");
QIcon pixmap = QPixmap::fromImage(QImage(":images/toolbar/popbutton.png").scaled(12*dpiXFactor, 12*dpiXFactor));
clearButton->setIcon(QIcon(pixmap));
clearButton->setIconSize(QSize(12 *dpiXFactor,12 *dpiYFactor));
clearButton->setCursor(Qt::ArrowCursor);
Expand All @@ -50,12 +50,13 @@ SearchBox::SearchBox(Context *context, QWidget *parent, bool nochooser)

// make sure its underneath the toggle button
toolButton = new QToolButton(this);
toolButton->setFixedSize(QSize(16 *dpiXFactor,16 *dpiYFactor));
toolButton->setFixedSize(QSize(12 *dpiXFactor,12 *dpiYFactor));
#ifdef Q_OS_MAC
toolButton->setStyleSheet("QToolButton { background: transparent; }");
#else
toolButton->setStyleSheet("QToolButton { border: none; padding: 0px; }");
#endif
toolButton->move(10*dpiXFactor,0);
toolButton->setCursor(Qt::ArrowCursor);
toolButton->setPopupMode(QToolButton::InstantPopup);

Expand All @@ -66,11 +67,12 @@ SearchBox::SearchBox(Context *context, QWidget *parent, bool nochooser)

// search button
searchButton = new QToolButton(this);
QIcon search = iconFromPNG(":images/toolbar/search3.png", false);
searchButton->setStyleSheet("QToolButton { border: none; padding: 0px; }");
searchButton->setStyleSheet("QToolButton { border: none; padding: 1px; }");
QIcon search = iconFromPNG(":images/toolbar/search3.png", QSize(12 *dpiXFactor,12*dpiYFactor));
searchButton->setIconSize(QSize(12 *dpiXFactor,12 *dpiYFactor));
searchButton->setIcon(search);
searchButton->setIconSize(QSize(11 *dpiXFactor,11 *dpiYFactor));
searchButton->setCursor(Qt::ArrowCursor);
searchButton->move(3*dpiXFactor,6*dpiYFactor);
connect(searchButton, SIGNAL(clicked()), this, SLOT(toggleMode()));

// create an empty completer, configchanged will fix it
Expand Down Expand Up @@ -263,11 +265,11 @@ void SearchBox::resizeEvent(QResizeEvent *)
QSize sz = clearButton->sizeHint();
int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
clearButton->move(rect().right() - frameWidth - sz.width() - 1, 3);
searchButton->move(5 *dpiXFactor, 3 *dpiYFactor);
searchButton->move(3 *dpiXFactor, 6 *dpiYFactor);
#ifndef Q_OS_MAC
toolButton->move(15, 0);
toolButton->move(10*dpiXFactor, 0);
#else
toolButton->move(13, 0);
toolButton->move(10*dpiXFactor, 0);
#endif

//container->move(rect().left(), rect().bottom() + 3); // named dialog...
Expand All @@ -287,19 +289,23 @@ void SearchBox::setMode(SearchBoxMode mode)

case Filter:
{
QIcon filter = iconFromPNG(":images/toolbar/filter3.png", false);
QIcon filter = iconFromPNG(":images/toolbar/filter3.png", QSize(12 *dpiXFactor,12*dpiYFactor));
searchButton->setStyleSheet("QToolButton { border: none; padding: 1px; }");
searchButton->setIconSize(QSize(12 *dpiXFactor,12 *dpiYFactor));
searchButton->setIcon(filter);
searchButton->setIconSize(QSize(11 *dpiXFactor,11 *dpiYFactor));
searchButton->move(3 *dpiXFactor, 6 *dpiYFactor);
setPlaceholderText(tr("Filter..."));
}
break;

case Search:
default:
{
QIcon search = iconFromPNG(":images/toolbar/search3.png", false);
QIcon search = iconFromPNG(":images/toolbar/search3.png", QSize(12 *dpiXFactor,12*dpiYFactor));
searchButton->setStyleSheet("QToolButton { border: none; padding: 1px; }");
searchButton->setIconSize(QSize(12 *dpiXFactor,12 *dpiYFactor));
searchButton->setIcon(search);
searchButton->setIconSize(QSize(11 *dpiXFactor,11 *dpiYFactor));
searchButton->move(3 *dpiXFactor, 6 *dpiYFactor);
setPlaceholderText(tr("Search..."));
}
break;
Expand Down
26 changes: 25 additions & 1 deletion src/Gui/TabView.cpp
Expand Up @@ -34,7 +34,7 @@
TabView::TabView(Context *context, int type) :
QWidget(context->tab), context(context), type(type),
_sidebar(true), _tiled(false), _selected(false), lastHeight(130*dpiYFactor), sidewidth(0),
active(false), bottomRequested(false), bottomHideOnIdle(false),
active(false), bottomRequested(false), bottomHideOnIdle(false), perspectiveactive(false),
stack(NULL), splitter(NULL), mainSplitter(NULL),
sidebar_(NULL), bottom_(NULL), page_(NULL), blank_(NULL)
{
Expand Down Expand Up @@ -413,6 +413,30 @@ TabView::sidebarChanged()
} else sidebar_->hide();
}

void
TabView::setPerspectives(QComboBox *perspectiveSelector)
{
perspectiveactive=true;
perspectiveSelector->clear();
perspectiveSelector->addItem("General");
perspectiveSelector->addItem("Bike");
perspectiveSelector->addItem("Run");
perspectiveSelector->addItem("Swim");
perspectiveSelector->addItem("Add New Perspective...");
perspectiveSelector->addItem("Manage Perspectives...");
perspectiveSelector->insertSeparator(4);
perspectiveactive=false;
}


void
TabView::perspectiveSelected(int index)
{
if (perspectiveactive || index <0) return;
fprintf(stderr, "Selected perspective: %d\n", index); fflush(stderr);
}


void
TabView::tileModeChanged()
{
Expand Down
8 changes: 7 additions & 1 deletion src/Gui/TabView.h
Expand Up @@ -69,6 +69,10 @@ class TabView : public QWidget
void setTiled(bool x) { _tiled=x; tileModeChanged(); }
bool isTiled() const { return _tiled; }

// set perspective
void setPerspectives(QComboBox *perspectiveSelector); // set the combobox when view selected
void perspectiveSelected(int index); // combobox selections changed because the user selected a perspective

// bottom
void dragEvent(bool); // showbottom on drag event
void setShowBottom(bool x);
Expand Down Expand Up @@ -139,14 +143,16 @@ class TabView : public QWidget
bool active;
bool bottomRequested;
bool bottomHideOnIdle;
bool perspectiveactive;

QStackedWidget *stack;
QSplitter *splitter;
ViewSplitter *mainSplitter;
QPropertyAnimation *anim;
QWidget *sidebar_;
QWidget *bottom_;
HomeWindow *page_;
HomeWindow *page_; // currently selected page
QList<HomeWindow> pages_;
BlankStatePage *blank_;

private slots:
Expand Down

0 comments on commit 3888246

Please sign in to comment.