Files
sunnypilot/selfdrive/ui/qt/widgets/scrollview.cc
Dean Lee ce0e2ec905 AGNOS setup: multi-lang support (#25680)
* multilang

* update translations

* Specifies dependency

* load lang from json file

* update translations

* fix white border

* remove stretch

* update translations

* fix tr

* no default language

* update translations

* rm main_en.qm

* cleanup

* cleanup

* add language files

* remove type=unfinish

* build languages before assets

* depends lrelease
old-commit-hash: 0767a6dee5
2023-08-26 08:17:07 -07:00

50 lines
1.7 KiB
C++

#include "selfdrive/ui/qt/widgets/scrollview.h"
#include <QScrollBar>
#include <QScroller>
// TODO: disable horizontal scrolling and resize
ScrollView::ScrollView(QWidget *w, QWidget *parent) : QScrollArea(parent) {
setWidget(w);
setWidgetResizable(true);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setStyleSheet("background-color: transparent; border:none");
QString style = R"(
QScrollBar:vertical {
border: none;
background: transparent;
width: 10px;
margin: 0;
}
QScrollBar::handle:vertical {
min-height: 0px;
border-radius: 5px;
background-color: white;
}
QScrollBar::add-line:vertical, QScrollBar::sub-line:vertical {
height: 0px;
}
QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical {
background: none;
}
)";
verticalScrollBar()->setStyleSheet(style);
horizontalScrollBar()->setStyleSheet(style);
QScroller *scroller = QScroller::scroller(this->viewport());
QScrollerProperties sp = scroller->scrollerProperties();
sp.setScrollMetric(QScrollerProperties::VerticalOvershootPolicy, QVariant::fromValue<QScrollerProperties::OvershootPolicy>(QScrollerProperties::OvershootAlwaysOff));
sp.setScrollMetric(QScrollerProperties::HorizontalOvershootPolicy, QVariant::fromValue<QScrollerProperties::OvershootPolicy>(QScrollerProperties::OvershootAlwaysOff));
sp.setScrollMetric(QScrollerProperties::MousePressEventDelay, 0.01);
scroller->grabGesture(this->viewport(), QScroller::LeftMouseButtonGesture);
scroller->setScrollerProperties(sp);
}
void ScrollView::hideEvent(QHideEvent *e) {
verticalScrollBar()->setValue(0);
}