Skip to content

Commit

Permalink
Hi-DPI Support - Chart titles and reveals
Browse files Browse the repository at this point in the history
.. some nasty bugs caused by QT losing contentsMargins when
   hidpi and not scaled. Really weird.

.. but now titles and reveal controls and More.. menu works
   as they would when not on hi-dpi screens
  • Loading branch information
liversedge committed Mar 14, 2017
1 parent 2f69d3f commit 161b83e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 17 deletions.
11 changes: 7 additions & 4 deletions src/Charts/GoldenCheetah.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,9 @@ GcWindow::paintEvent(QPaintEvent * /*event*/)

// heading
QFont font;
font.setPointSize((contentsMargins().top()/2)+2);
// font too large on hidpi scaling
int pixelsize =pixelSizeForFont(font, ((contentsMargins().top()/2)+2));
font.setPixelSize(pixelsize);
font.setWeight(QFont::Bold);
painter.setFont(font);
QString subtitle = property("subtitle").toString();
Expand Down Expand Up @@ -647,8 +649,9 @@ GcWindow::enterEvent(QEvent *)
if (_noevents) return;

if (property("nomenu") == false && property("isManager").toBool() == false) {
if (contentsMargins().top() > 20) menuButton->setFixedSize(80*dpiXFactor,30*dpiYFactor);
if (contentsMargins().top() > (20*dpiYFactor)) menuButton->setFixedSize(80*dpiXFactor,30*dpiYFactor);
else menuButton->setFixedSize(80*dpiXFactor, 15*dpiYFactor);
menuButton->raise();
menuButton->show();
}
}
Expand Down Expand Up @@ -693,12 +696,12 @@ GcChartWindow::GcChartWindow(Context *context) : GcWindow(context), context(cont
// Main layout
_mainLayout = new QStackedLayout(_mainWidget);
_mainLayout->setStackingMode(QStackedLayout::StackAll);
_mainLayout->setContentsMargins(2,2,2,2);
_mainLayout->setContentsMargins(2 *dpiXFactor,2 *dpiYFactor,2 *dpiXFactor,2 *dpiYFactor);

// reveal widget
_revealControls = new QWidget(this);
_revealControls->hide();
_revealControls->setFixedHeight(50);
_revealControls->setFixedHeight(50 *dpiYFactor);
_revealControls->setStyleSheet("background-color: rgba(100%, 100%, 100%, 80%)");
_revealControls->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum);

Expand Down
34 changes: 21 additions & 13 deletions src/Charts/HomeWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,6 @@ HomeWindow::HomeWindow(Context *context, QString name, QString /* windowtitle */

QVBoxLayout *layout = new QVBoxLayout(this);

QFont bigandbold;
bigandbold.setPointSize(bigandbold.pointSize() + 2);
bigandbold.setWeight(QFont::Bold);

style = new QStackedWidget(this);
style->setAutoFillBackground(false);
layout->setSpacing(0);
Expand Down Expand Up @@ -307,9 +303,9 @@ HomeWindow::selected()
resizeEvent(NULL); // force a relayout
rideSelected();
dateRangeChanged(DateRange());

setUpdatesEnabled(true);
update();

}

void
Expand Down Expand Up @@ -384,6 +380,13 @@ HomeWindow::tabSelected(int index)

if (index >= 0) {

// HACK XXX Fixup contents margins that are being wiped out "somewhere" but
// only manifested when QT_SCALE_FACTOR > 1 and a tabbed view.
if (currentStyle == 0) {
if(charts[index]->showTitle() == true) charts[index]->setContentsMargins(0,25*dpiYFactor,0,0);
else charts[index]->setContentsMargins(0,0,0,0);
}

// show
charts[index]->show();
controlStack->setCurrentIndex(index);
Expand Down Expand Up @@ -476,23 +479,24 @@ HomeWindow::styleChanged(int id)
case 0 : // they are tabs in a TabWidget
tabbed->addWidget(charts[i]);
chartbar->addWidget(charts[i]->property("title").toString());
if(charts[i]->showTitle() == true) charts[i]->setContentsMargins(0,25,0,0);
else charts[i]->setContentsMargins(0,0,0,0);
charts[i]->setResizable(false); // we need to show on tab selection!
charts[i]->setProperty("dateRange", property("dateRange"));
charts[i]->hide(); // we need to show on tab selection!
// weird bug- set margins *after* tabbed->addwidget since it resets margins (!!)
if(charts[i]->showTitle() == true) charts[i]->setContentsMargins(0,25*dpiYFactor,0,0);
else charts[i]->setContentsMargins(0,0,0,0);
break;
case 1 : // they are lists in a GridLayout
tileGrid->addWidget(charts[i], i,0);
charts[i]->setContentsMargins(0,25,0,0);
charts[i]->setContentsMargins(0,25*dpiYFactor,0,0);
charts[i]->setResizable(false); // we need to show on tab selection!
charts[i]->show();
charts[i]->setProperty("dateRange", property("dateRange"));
charts[i]->setProperty("ride", property("ride"));
break;
case 2 : // thet are in a FlowLayout
winFlow->addWidget(charts[i]);
charts[i]->setContentsMargins(0,15,0,0);
charts[i]->setContentsMargins(0,15*dpiYFactor,0,0);
charts[i]->setResizable(true); // we need to show on tab selection!
charts[i]->show();
charts[i]->setProperty("dateRange", property("dateRange"));
Expand Down Expand Up @@ -627,12 +631,14 @@ HomeWindow::addChart(GcChartWindow* newone)
switch (currentStyle) {

case 0 :
if (newone->showTitle()) newone->setContentsMargins(0,25,0,0);
else newone->setContentsMargins(0,0,0,0);
newone->setResizable(false); // we need to show on tab selection!
//tabbed->addTab(newone, newone->property("title").toString());
tabbed->addWidget(newone);
chartbar->addWidget(newone->property("title").toString());

// weird bug- set margins *after* tabbed->addwidget since it resets margins (!!)
if (newone->showTitle()) newone->setContentsMargins(0,25*dpiYFactor,0,0);
else newone->setContentsMargins(0,0,0,0);
break;
case 1 :
{
Expand All @@ -643,7 +649,7 @@ HomeWindow::addChart(GcChartWindow* newone)
newone->setResizable(false); // we need to show on tab selection!
int row = chartnum; // / 2;
int column = 0; //chartnum % 2;
newone->setContentsMargins(0,25,0,0);
newone->setContentsMargins(0,25*dpiYFactor,0,0);
tileGrid->addWidget(newone, row, column);
}
break;
Expand Down Expand Up @@ -671,7 +677,7 @@ HomeWindow::addChart(GcChartWindow* newone)
newone->setFixedWidth(newwidth);
if (newheight < minHeight) newheight = minHeight;
else newone->setFixedHeight(newheight);
newone->setContentsMargins(0,15,0,0);
newone->setContentsMargins(0,15*dpiYFactor,0,0);
newone->setResizable(true); // we need to show on tab selection!

if (currentStyle == 2 && chartCursor >= 0) winFlow->insert(chartCursor, newone);
Expand Down Expand Up @@ -1416,8 +1422,10 @@ HomeWindow::restoreState(bool useDefault)
if (currentStyle != 0) charts[i]->show();

}

setUpdatesEnabled(true);
if (currentStyle == 0 && charts.count()) tabSelected(0);

}

//
Expand Down

0 comments on commit 161b83e

Please sign in to comment.