1 /* 2 * Copyright (c) 2020-2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 #include "mousewheel_input.h" 16 #include <QtCore/qcoreevent.h> 17 #include <QtCore/qvariant.h> 18 #include <qdebug.h> 19 20 static int16_t g_rotate = 0; 21 22 namespace OHOS { 23 #if defined(USE_MOUSEWHEEL) && USE_MOUSEWHEEL 24 #if ENABLE_ROTATE_INPUT GetInstance()25MousewheelInput* MousewheelInput::GetInstance() 26 { 27 static MousewheelInput mousewheelInput; 28 return &mousewheelInput; 29 } 30 Read(DeviceData & data)31bool MousewheelInput::Read(DeviceData &data) 32 { 33 data.rotate = g_rotate; 34 g_rotate = 0; 35 return false; 36 } MousewheelHandler(QWheelEvent * event)37void MousewheelInput::MousewheelHandler(QWheelEvent *event) 38 { 39 if (event == nullptr) { 40 return; 41 } 42 g_rotate += -event->delta() / 120; // 120 : Qt use 120 as one mousewheel step value 43 } 44 #endif 45 #endif 46 } // namespace OHOS 47