Krita Source Code Documentation
Loading...
Searching...
No Matches
KoToolBoxScrollArea Class Reference

#include <KoToolBoxScrollArea_p.h>

+ Inheritance diagram for KoToolBoxScrollArea:

Public Slots

void slotScrollerStateChange (QScroller::State state)
 

Public Member Functions

 KoToolBoxScrollArea (KoToolBox *toolBox, QWidget *parent)
 
QSize minimumSizeHint () const override
 
Qt::Orientation orientation () const
 
void setOrientation (Qt::Orientation orientation)
 
QSize sizeHint () const override
 

Protected Member Functions

bool event (QEvent *event) override
 
bool eventFilter (QObject *watched, QEvent *event) override
 
void resizeEvent (QResizeEvent *event) override
 
void scrollContentsBy (int dx, int dy) override
 
void wheelEvent (QWheelEvent *event) override
 

Private Slots

void doScrollNext ()
 
void doScrollPrev ()
 

Private Member Functions

void layoutItems ()
 
int scrollButtonWidth () const
 
void updateScrollButtons ()
 

Private Attributes

Qt::Orientation m_orientation
 
QToolButton * m_scrollNext
 
QToolButton * m_scrollPrev
 
KoToolBoxm_toolBox
 

Detailed Description

Definition at line 20 of file KoToolBoxScrollArea_p.h.

Constructor & Destructor Documentation

◆ KoToolBoxScrollArea()

KoToolBoxScrollArea::KoToolBoxScrollArea ( KoToolBox * toolBox,
QWidget * parent )
inline

Definition at line 24 of file KoToolBoxScrollArea_p.h.

25 : QScrollArea(parent)
26 , m_toolBox(toolBox)
27 , m_orientation(Qt::Vertical)
28 , m_scrollPrev(new QToolButton(this))
29 , m_scrollNext(new QToolButton(this))
30 {
31 setFrameShape(QFrame::NoFrame);
32 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
33 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
34
36 setWidget(m_toolBox);
37
38 m_scrollPrev->setAutoRepeat(true);
39 m_scrollPrev->setAutoFillBackground(true);
40 m_scrollPrev->setFocusPolicy(Qt::NoFocus);
41 connect(m_scrollPrev, &QToolButton::clicked, this, &KoToolBoxScrollArea::doScrollPrev);
42 m_scrollNext->setAutoRepeat(true);
43 m_scrollNext->setAutoFillBackground(true);
44 m_scrollNext->setFocusPolicy(Qt::NoFocus);
45 connect(m_scrollNext, &QToolButton::clicked, this, &KoToolBoxScrollArea::doScrollNext);
46 // These are for filtering the mouse wheel events:
47 m_scrollPrev->installEventFilter(this);
48 m_scrollNext->installEventFilter(this);
49
50 QScroller *scroller = KisKineticScroller::createPreconfiguredScroller(this);
51 if (!scroller) {
52 QScroller::grabGesture(viewport(), QScroller::MiddleMouseButtonGesture);
53 scroller = QScroller::scroller(viewport());
54 QScrollerProperties sp = scroller->scrollerProperties();
55
56 sp.setScrollMetric(QScrollerProperties::MaximumVelocity, 0.0);
57 sp.setScrollMetric(QScrollerProperties::OvershootDragResistanceFactor, 0.1);
58 sp.setScrollMetric(QScrollerProperties::OvershootDragDistanceFactor, 0.1);
59 sp.setScrollMetric(QScrollerProperties::OvershootScrollDistanceFactor, 0.0);
60 sp.setScrollMetric(QScrollerProperties::OvershootScrollTime, 0.4);
61
62 scroller->setScrollerProperties(sp);
63 }
64 connect(scroller, SIGNAL(stateChanged(QScroller::State)), this, SLOT(slotScrollerStateChange(QScroller::State)));
65 }
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
void slotScrollerStateChange(QScroller::State state)
void setOrientation(Qt::Orientation orientation)
Set the orientation of the layout to orientation.
KRITAWIDGETUTILS_EXPORT QScroller * createPreconfiguredScroller(QAbstractScrollArea *target)

References connect(), KisKineticScroller::createPreconfiguredScroller(), doScrollNext(), doScrollPrev(), m_orientation, m_scrollNext, m_scrollPrev, m_toolBox, KoToolBox::setOrientation(), and slotScrollerStateChange().

Member Function Documentation

◆ doScrollNext

void KoToolBoxScrollArea::doScrollNext ( )
inlineprivateslot

Definition at line 149 of file KoToolBoxScrollArea_p.h.

150 {
151 if (m_orientation == Qt::Vertical) {
152 verticalScrollBar()->triggerAction(QAbstractSlider::SliderSingleStepAdd);
153 } else {
154 horizontalScrollBar()->triggerAction(QAbstractSlider::SliderSingleStepAdd);
155 }
156 }

References m_orientation.

◆ doScrollPrev

void KoToolBoxScrollArea::doScrollPrev ( )
inlineprivateslot

Definition at line 140 of file KoToolBoxScrollArea_p.h.

141 {
142 if (m_orientation == Qt::Vertical) {
143 verticalScrollBar()->triggerAction(QAbstractSlider::SliderSingleStepSub);
144 } else {
145 horizontalScrollBar()->triggerAction(QAbstractSlider::SliderSingleStepSub);
146 }
147 }

References m_orientation.

◆ event()

bool KoToolBoxScrollArea::event ( QEvent * event)
inlineoverrideprotected

Definition at line 96 of file KoToolBoxScrollArea_p.h.

97 {
98 if (event->type() == QEvent::LayoutRequest) {
99 // LayoutRequest can be triggered by icon changes, so resize the toolbox
100 layoutItems();
101 // The toolbox might have changed the sizeHint and minimumSizeHint
102 updateGeometry();
103 }
104 return QScrollArea::event(event);
105 }
bool event(QEvent *event) override

References event(), and layoutItems().

◆ eventFilter()

bool KoToolBoxScrollArea::eventFilter ( QObject * watched,
QEvent * event )
inlineoverrideprotected

Definition at line 107 of file KoToolBoxScrollArea_p.h.

108 {
109 // The toolbuttons eat the wheel events, so we filter them for our use.
110 if ((watched == m_scrollPrev || watched == m_scrollNext) && event->type() == QEvent::Wheel) {
111 wheelEvent(static_cast<QWheelEvent *>(event));
112 return true;
113 }
114 return QScrollArea::eventFilter(watched, event);
115 }
void wheelEvent(QWheelEvent *event) override

References event(), m_scrollNext, m_scrollPrev, and wheelEvent().

◆ layoutItems()

void KoToolBoxScrollArea::layoutItems ( )
inlineprivate

Definition at line 166 of file KoToolBoxScrollArea_p.h.

167 {
169 QSize newSize = viewport()->size();
170 if (m_orientation == Qt::Vertical) {
171 newSize.setHeight(l->heightForWidth(newSize.width()));
172 } else {
173 newSize.setWidth(l->widthForHeight(newSize.height()));
174 }
175 m_toolBox->resize(newSize);
176
178 }
int heightForWidth(int width) const override
int widthForHeight(int height) const
KoToolBoxLayout * toolBoxLayout() const

References KoToolBoxLayout::heightForWidth(), m_orientation, m_toolBox, KoToolBox::toolBoxLayout(), updateScrollButtons(), and KoToolBoxLayout::widthForHeight().

◆ minimumSizeHint()

QSize KoToolBoxScrollArea::minimumSizeHint ( ) const
inlineoverride

Definition at line 82 of file KoToolBoxScrollArea_p.h.

83 {
84 return m_toolBox->minimumSizeHint();
85 }

References m_toolBox.

◆ orientation()

Qt::Orientation KoToolBoxScrollArea::orientation ( ) const
inline

Definition at line 77 of file KoToolBoxScrollArea_p.h.

78 {
79 return m_orientation;
80 }

References m_orientation.

◆ resizeEvent()

void KoToolBoxScrollArea::resizeEvent ( QResizeEvent * event)
inlineoverrideprotected

Definition at line 117 of file KoToolBoxScrollArea_p.h.

118 {
119 layoutItems();
120 QScrollArea::resizeEvent(event);
122 }

References event(), layoutItems(), and updateScrollButtons().

◆ scrollButtonWidth()

int KoToolBoxScrollArea::scrollButtonWidth ( ) const
inlineprivate

Definition at line 159 of file KoToolBoxScrollArea_p.h.

160 {
161 QStyleOption opt;
162 opt.initFrom(this);
163 return style()->pixelMetric(QStyle::PM_TabBarScrollButtonWidth, &opt, this);
164 }

◆ scrollContentsBy()

void KoToolBoxScrollArea::scrollContentsBy ( int dx,
int dy )
inlineoverrideprotected

Definition at line 133 of file KoToolBoxScrollArea_p.h.

134 {
135 QScrollArea::scrollContentsBy(dx, dy);
137 }

References updateScrollButtons().

◆ setOrientation()

void KoToolBoxScrollArea::setOrientation ( Qt::Orientation orientation)
inline

Definition at line 67 of file KoToolBoxScrollArea_p.h.

68 {
70 return;
71 }
75 }
Qt::Orientation orientation() const

References layoutItems(), m_orientation, m_toolBox, orientation(), and KoToolBox::setOrientation().

◆ sizeHint()

QSize KoToolBoxScrollArea::sizeHint ( ) const
inlineoverride

Definition at line 87 of file KoToolBoxScrollArea_p.h.

88 {
89 return m_toolBox->sizeHint();
90 }

References m_toolBox.

◆ slotScrollerStateChange

void KoToolBoxScrollArea::slotScrollerStateChange ( QScroller::State state)
inlineslot

Definition at line 93 of file KoToolBoxScrollArea_p.h.

KRITAWIDGETUTILS_EXPORT void updateCursor(QWidget *source, QScroller::State state)

References KisKineticScroller::updateCursor().

◆ updateScrollButtons()

void KoToolBoxScrollArea::updateScrollButtons ( )
inlineprivate

Definition at line 180 of file KoToolBoxScrollArea_p.h.

181 {
182 // We move the scroll buttons outside the widget rect instead of setting
183 // the visibility, because setting the visibility triggers a relayout
184 // of QAbstractScrollArea, which occasionally causes an offset bug when
185 // QScroller performs the overshoot animation. (Overshoot is done by
186 // moving the viewport widget, but the viewport position is reset during
187 // a relayout.)
188 const int scrollButtonWidth = this->scrollButtonWidth();
189 const QScrollBar *scrollbar = m_orientation == Qt::Vertical ? verticalScrollBar() : horizontalScrollBar();
190 const bool canPrev = scrollbar->value() != scrollbar->minimum();
191 const bool canNext = scrollbar->value() != scrollbar->maximum();
192 m_scrollPrev->setEnabled(canPrev);
193 m_scrollNext->setEnabled(canNext);
194 if (m_orientation == Qt::Vertical) {
195 m_scrollPrev->setArrowType(Qt::UpArrow);
196 m_scrollPrev->setGeometry(canPrev ? 0 : -width(), 0, width(), scrollButtonWidth);
197 m_scrollNext->setArrowType(Qt::DownArrow);
198 m_scrollNext->setGeometry(canNext? 0 : -width(), height() - scrollButtonWidth, width(), scrollButtonWidth);
199 } else if (isLeftToRight()) {
200 m_scrollPrev->setArrowType(Qt::LeftArrow);
201 m_scrollPrev->setGeometry(0, canPrev ? 0 : -height(), scrollButtonWidth, height());
202 m_scrollNext->setArrowType(Qt::RightArrow);
203 m_scrollNext->setGeometry(width() - scrollButtonWidth, canNext ? 0 : -height(), scrollButtonWidth, height());
204 } else {
205 // Right-to-left is mirrored.
206 m_scrollPrev->setArrowType(Qt::RightArrow);
207 m_scrollPrev->setGeometry(width() - scrollButtonWidth, canPrev ? 0 : -height(), scrollButtonWidth, height());
208 m_scrollNext->setArrowType(Qt::LeftArrow);
209 m_scrollNext->setGeometry(0, canNext ? 0 : -height(), scrollButtonWidth, height());
210 }
211 }

References m_orientation, m_scrollNext, m_scrollPrev, and scrollButtonWidth().

◆ wheelEvent()

void KoToolBoxScrollArea::wheelEvent ( QWheelEvent * event)
inlineoverrideprotected

Definition at line 124 of file KoToolBoxScrollArea_p.h.

125 {
126 if (m_orientation == Qt::Vertical) {
127 QApplication::sendEvent(verticalScrollBar(), event);
128 } else {
129 QApplication::sendEvent(horizontalScrollBar(), event);
130 }
131 }

References event(), and m_orientation.

Member Data Documentation

◆ m_orientation

Qt::Orientation KoToolBoxScrollArea::m_orientation
private

Definition at line 214 of file KoToolBoxScrollArea_p.h.

◆ m_scrollNext

QToolButton* KoToolBoxScrollArea::m_scrollNext
private

Definition at line 217 of file KoToolBoxScrollArea_p.h.

◆ m_scrollPrev

QToolButton* KoToolBoxScrollArea::m_scrollPrev
private

Definition at line 216 of file KoToolBoxScrollArea_p.h.

◆ m_toolBox

KoToolBox* KoToolBoxScrollArea::m_toolBox
private

Definition at line 213 of file KoToolBoxScrollArea_p.h.


The documentation for this class was generated from the following file: