File indexing completed on 2024-04-21 05:51:27
0001 /* 0002 SPDX-FileCopyrightText: 2015 Lindsay Roberts <os@lindsayr.com> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef SCROLLSTATE_H 0008 #define SCROLLSTATE_H 0009 0010 class QWheelEvent; 0011 0012 namespace Konsole 0013 { 0014 /** 0015 * Represents accumulation of wheel scroll from scroll events. 0016 * 0017 * Modern high precision scroll events supply many smaller events 0018 * that may or may not translate into a UI action to support smooth 0019 * pixel level scrolling. Builtin classes such as QScrollBar 0020 * support these events under Qt5, but custom code 0021 * written to handle scroll events in other ways must be modified 0022 * to accumulate small deltas and act when suitable thresholds have 0023 * been reached (ideally 1 for pixel scroll values towards any action 0024 * that can be mapped to a pixel movement). 0025 */ 0026 struct ScrollState { 0027 enum { 0028 DEFAULT_ANGLE_SCROLL_LINE = 120, 0029 }; 0030 enum { 0031 DEGREES_PER_ANGLE_UNIT = 8, 0032 }; 0033 static inline int degreesToAngle(const int angle) 0034 { 0035 return angle * DEGREES_PER_ANGLE_UNIT; 0036 } 0037 0038 int angle() const 0039 { 0040 return _remainingScrollAngle; 0041 } 0042 0043 int pixel() const 0044 { 0045 return _remainingScrollPixel; 0046 } 0047 0048 /** Add scroll values from a QWheelEvent to the accumulated totals */ 0049 void addWheelEvent(const QWheelEvent *wheel); 0050 0051 /** Clear all - used when scroll is consumed by another class like QScrollBar */ 0052 void clearAll(); 0053 /** Return the (signed) multiple of @p stepsize available and subtract it from 0054 * accumulated totals. Also clears accumulated pixel scroll. */ 0055 int consumeLegacySteps(int stepsize); 0056 /** Return the (signed) multiple of @p pixelStepSize if any pixel scroll is 0057 * available - that is, if pixel scroll is being supplied, or the same from 0058 * the @p angleStepSize else. The corresponding value is subtracted from 0059 * the accumulated total. The other scroll style value is cleared. */ 0060 int consumeSteps(int pixelStepSize, int angleStepSize); 0061 0062 ScrollState() 0063 : _remainingScrollAngle(0) 0064 , _remainingScrollPixel(0) 0065 { 0066 } 0067 0068 int _remainingScrollAngle; 0069 int _remainingScrollPixel; 0070 }; 0071 } 0072 0073 #endif // SCROLLSTATE_H