MCPcopy Create free account
hub / github.com/Liniyous/ElaWidgetTools / ElaPivot

Method ElaPivot

ElaWidgetTools/ElaPivot.cpp:11–75  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9#include "ElaPivotStyle.h"
10#include "ElaPivotView.h"
11ElaPivot::ElaPivot(QWidget* parent)
12 : QWidget{parent}, d_ptr(new ElaPivotPrivate())
13{
14 Q_D(ElaPivot);
15 d->q_ptr = this;
16 d->_pTextPixelSize = 20;
17 setFixedHeight(40);
18 setObjectName("ElaPivot");
19 setStyleSheet("#ElaPivot{background-color:transparent;}");
20 setMouseTracking(true);
21
22 d->_listView = new ElaPivotView(this);
23 d->_listView->setMinimumHeight(0);
24 d->_listView->setFlow(QListView::LeftToRight);
25 d->_listView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
26 d->_listView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
27 d->_listModel = new ElaPivotModel(this);
28 d->_listView->setModel(d->_listModel);
29 d->_listStyle = new ElaPivotStyle(d->_listView->style());
30 d->_listView->setStyle(d->_listStyle);
31 d->_listView->setPivotStyle(d->_listStyle);
32
33 QFont textFont = this->font();
34 textFont.setLetterSpacing(QFont::AbsoluteSpacing, 0.5);
35 textFont.setPixelSize(d->_pTextPixelSize);
36 d->_listView->setFont(textFont);
37
38 QScroller::grabGesture(d->_listView->viewport(), QScroller::LeftMouseButtonGesture);
39 QScroller* scroller = QScroller::scroller(d->_listView->viewport());
40 QScrollerProperties properties = scroller->scrollerProperties();
41 properties.setScrollMetric(QScrollerProperties::MousePressEventDelay, 0);
42 properties.setScrollMetric(QScrollerProperties::HorizontalOvershootPolicy, QScrollerProperties::OvershootAlwaysOn);
43 properties.setScrollMetric(QScrollerProperties::OvershootDragResistanceFactor, 0.35);
44 properties.setScrollMetric(QScrollerProperties::OvershootScrollTime, 0.5);
45 properties.setScrollMetric(QScrollerProperties::FrameRate, QScrollerProperties::Fps60);
46 scroller->setScrollerProperties(properties);
47
48 connect(scroller, &QScroller::stateChanged, this, [=](QScroller::State newstate) {
49 if (newstate == QScroller::Pressed)
50 {
51 d->_listStyle->setPressIndex(d->_listView->indexAt(d->_listView->mapFromGlobal(QCursor::pos())));
52 d->_listView->viewport()->update();
53 }
54 else if (newstate == QScroller::Scrolling || newstate == QScroller::Inactive)
55 {
56 d->_listStyle->setPressIndex(QModelIndex());
57 d->_listView->viewport()->update();
58 }
59 });
60 connect(d->_listView, &ElaPivotView::clicked, this, [=](const QModelIndex& index) {
61 if (index.row() != d->_listStyle->getCurrentIndex())
62 {
63 Q_EMIT pCurrentIndexChanged();
64 }
65 d->_listView->doCurrentIndexChangedAnimation(index);
66 d->_listStyle->setCurrentIndex(index.row());
67 Q_EMIT pivotClicked(index.row());
68 });

Callers

nothing calls this directly

Calls 4

addWidgetMethod · 0.80
getCurrentIndexMethod · 0.45
setCurrentIndexMethod · 0.45

Tested by

no test coverage detected