LCOV - code coverage report
Current view: top level - src/engraving/editing - editdata.h Coverage Total Hit
Test: filtered_coverage.info Lines: 50.0 % 6 3
Test Date: 2026-11-05 04:07:02

            Line data    Source code
       1              : /*
       2              :  * SPDX-License-Identifier: GPL-3.0-only
       3              :  * MuseScore-Studio-CLA-applies
       4              :  *
       5              :  * MuseScore Studio
       6              :  * Music Composition & Notation
       7              :  *
       8              :  * Copyright (C) 2021 MuseScore Limited and others
       9              :  *
      10              :  * This program is free software: you can redistribute it and/or modify
      11              :  * it under the terms of the GNU General Public License version 3 as
      12              :  * published by the Free Software Foundation.
      13              :  *
      14              :  * This program is distributed in the hope that it will be useful,
      15              :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      16              :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      17              :  * GNU General Public License for more details.
      18              :  *
      19              :  * You should have received a copy of the GNU General Public License
      20              :  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
      21              :  */
      22              : 
      23              : #pragma once
      24              : 
      25              : #include <memory>
      26              : 
      27              : #include "types/flags.h"
      28              : #include "types/string.h"
      29              : #include "../types/types.h"
      30              : 
      31              : namespace mu::engraving {
      32              : enum KeyboardModifier {
      33              :     NoModifier           = 0x00000000,
      34              :     ShiftModifier        = 0x02000000,
      35              :     ControlModifier      = 0x04000000,
      36              :     AltModifier          = 0x08000000,
      37              :     MetaModifier         = 0x10000000,
      38              :     KeypadModifier       = 0x20000000,
      39              :     GroupSwitchModifier  = 0x40000000,
      40              :     // Do not extend the mask to include 0x01000000
      41              :     KeyboardModifierMask = 0xfe000000
      42              : };
      43              : DECLARE_FLAGS(KeyboardModifiers, KeyboardModifier)
      44            2 : DECLARE_OPERATORS_FOR_FLAGS(KeyboardModifiers)
      45              : 
      46              : #ifdef Q_OS_MAC
      47              : constexpr KeyboardModifier TextEditingControlModifier = AltModifier;
      48              : #else
      49              : constexpr KeyboardModifier TextEditingControlModifier = ControlModifier;
      50              : #endif
      51              : 
      52              : enum KeyboardKey {
      53              :     Key_Escape = 0x01000000,                // misc keys
      54              :     Key_Tab = 0x01000001,
      55              :     Key_Backtab = 0x01000002,
      56              :     Key_Backspace = 0x01000003,
      57              :     Key_Return = 0x01000004,
      58              :     Key_Enter = 0x01000005,
      59              :     Key_Insert = 0x01000006,
      60              :     Key_Delete = 0x01000007,
      61              :     Key_Pause = 0x01000008,
      62              :     Key_Print = 0x01000009,               // print screen
      63              :     Key_SysReq = 0x0100000a,
      64              :     Key_Clear = 0x0100000b,
      65              :     Key_Home = 0x01000010,                // cursor movement
      66              :     Key_End = 0x01000011,
      67              :     Key_Left = 0x01000012,
      68              :     Key_Up = 0x01000013,
      69              :     Key_Right = 0x01000014,
      70              :     Key_Down = 0x01000015,
      71              :     Key_PageUp = 0x01000016,
      72              :     Key_PageDown = 0x01000017,
      73              :     Key_Shift = 0x01000020,                // modifiers
      74              :     Key_Control = 0x01000021,
      75              :     Key_Meta = 0x01000022,
      76              :     Key_Alt = 0x01000023,
      77              :     Key_CapsLock = 0x01000024,
      78              :     Key_NumLock = 0x01000025,
      79              :     Key_ScrollLock = 0x01000026,
      80              :     Key_F1 = 0x01000030,                // function keys
      81              :     Key_F2 = 0x01000031,
      82              :     Key_F3 = 0x01000032,
      83              :     Key_F4 = 0x01000033,
      84              :     Key_F5 = 0x01000034,
      85              :     Key_F6 = 0x01000035,
      86              :     Key_F7 = 0x01000036,
      87              :     Key_F8 = 0x01000037,
      88              :     Key_F9 = 0x01000038,
      89              :     Key_F10 = 0x01000039,
      90              :     Key_F11 = 0x0100003a,
      91              :     Key_F12 = 0x0100003b,
      92              :     Key_F13 = 0x0100003c,
      93              :     Key_F14 = 0x0100003d,
      94              :     Key_F15 = 0x0100003e,
      95              :     Key_F16 = 0x0100003f,
      96              :     Key_F17 = 0x01000040,
      97              :     Key_F18 = 0x01000041,
      98              :     Key_F19 = 0x01000042,
      99              :     Key_F20 = 0x01000043,
     100              :     Key_F21 = 0x01000044,
     101              :     Key_F22 = 0x01000045,
     102              :     Key_F23 = 0x01000046,
     103              :     Key_F24 = 0x01000047,
     104              :     Key_F25 = 0x01000048,                // F25 .. F35 only on X11
     105              :     Key_F26 = 0x01000049,
     106              :     Key_F27 = 0x0100004a,
     107              :     Key_F28 = 0x0100004b,
     108              :     Key_F29 = 0x0100004c,
     109              :     Key_F30 = 0x0100004d,
     110              :     Key_F31 = 0x0100004e,
     111              :     Key_F32 = 0x0100004f,
     112              :     Key_F33 = 0x01000050,
     113              :     Key_F34 = 0x01000051,
     114              :     Key_F35 = 0x01000052,
     115              :     Key_Super_L = 0x01000053,                 // extra keys
     116              :     Key_Super_R = 0x01000054,
     117              :     Key_Menu = 0x01000055,
     118              :     Key_Hyper_L = 0x01000056,
     119              :     Key_Hyper_R = 0x01000057,
     120              :     Key_Help = 0x01000058,
     121              :     Key_Direction_L = 0x01000059,
     122              :     Key_Direction_R = 0x01000060,
     123              :     Key_Space = 0x20,                // 7 bit printable ASCII
     124              :     Key_Any = Key_Space,
     125              :     Key_Exclam = 0x21,
     126              :     Key_QuoteDbl = 0x22,
     127              :     Key_NumberSign = 0x23,
     128              :     Key_Dollar = 0x24,
     129              :     Key_Percent = 0x25,
     130              :     Key_Ampersand = 0x26,
     131              :     Key_Apostrophe = 0x27,
     132              :     Key_ParenLeft = 0x28,
     133              :     Key_ParenRight = 0x29,
     134              :     Key_Asterisk = 0x2a,
     135              :     Key_Plus = 0x2b,
     136              :     Key_Comma = 0x2c,
     137              :     Key_Minus = 0x2d,
     138              :     Key_Period = 0x2e,
     139              :     Key_Slash = 0x2f,
     140              :     Key_0 = 0x30,
     141              :     Key_1 = 0x31,
     142              :     Key_2 = 0x32,
     143              :     Key_3 = 0x33,
     144              :     Key_4 = 0x34,
     145              :     Key_5 = 0x35,
     146              :     Key_6 = 0x36,
     147              :     Key_7 = 0x37,
     148              :     Key_8 = 0x38,
     149              :     Key_9 = 0x39,
     150              :     Key_Colon = 0x3a,
     151              :     Key_Semicolon = 0x3b,
     152              :     Key_Less = 0x3c,
     153              :     Key_Equal = 0x3d,
     154              :     Key_Greater = 0x3e,
     155              :     Key_Question = 0x3f,
     156              :     Key_At = 0x40,
     157              :     Key_A = 0x41,
     158              :     Key_B = 0x42,
     159              :     Key_C = 0x43,
     160              :     Key_D = 0x44,
     161              :     Key_E = 0x45,
     162              :     Key_F = 0x46,
     163              :     Key_G = 0x47,
     164              :     Key_H = 0x48,
     165              :     Key_I = 0x49,
     166              :     Key_J = 0x4a,
     167              :     Key_K = 0x4b,
     168              :     Key_L = 0x4c,
     169              :     Key_M = 0x4d,
     170              :     Key_N = 0x4e,
     171              :     Key_O = 0x4f,
     172              :     Key_P = 0x50,
     173              :     Key_Q = 0x51,
     174              :     Key_R = 0x52,
     175              :     Key_S = 0x53,
     176              :     Key_T = 0x54,
     177              :     Key_U = 0x55,
     178              :     Key_V = 0x56,
     179              :     Key_W = 0x57,
     180              :     Key_X = 0x58,
     181              :     Key_Y = 0x59,
     182              :     Key_Z = 0x5a,
     183              :     Key_BracketLeft = 0x5b,
     184              :     Key_Backslash = 0x5c,
     185              :     Key_BracketRight = 0x5d,
     186              :     Key_AsciiCircum = 0x5e,
     187              :     Key_Underscore = 0x5f,
     188              :     Key_QuoteLeft = 0x60,
     189              :     Key_BraceLeft = 0x7b,
     190              :     Key_Bar = 0x7c,
     191              :     Key_BraceRight = 0x7d,
     192              :     Key_AsciiTilde = 0x7e,
     193              : 
     194              :     Key_nobreakspace = 0x0a0,
     195              :     Key_periodcentered = 0x0b7,
     196              :     Key_ydiaeresis = 0x0ff,
     197              : };
     198              : 
     199              : enum MouseButton {
     200              :     NoButton         = 0x00000000,
     201              :     LeftButton       = 0x00000001,
     202              :     RightButton      = 0x00000002,
     203              :     MiddleButton     = 0x00000004
     204              : };
     205              : DECLARE_FLAGS(MouseButtons, MouseButton)
     206              : DECLARE_OPERATORS_FOR_FLAGS(MouseButtons)
     207              : 
     208              : //---------------------------------------------------------
     209              : //   Grip
     210              : //---------------------------------------------------------
     211              : 
     212              : enum class Grip : signed char {
     213              :     NO_GRIP = -1,
     214              :     START = 0, END = 1,                           // arpeggio etc.
     215              :     LEFT = START, RIGHT = END,                    // aliases for dynamic
     216              :     MIDDLE = 2, APERTURE = 3,                     // Line
     217              :     /*START, END , */
     218              :     BEZIER1 = 2, SHOULDER = 3, BEZIER2 = 4, DRAG = 5,       // Slur
     219              :     GRIPS = 6                       // number of grips for slur
     220              : };
     221              : 
     222              : //---------------------------------------------------------
     223              : //   EditData
     224              : //    used in dragGrip
     225              : //---------------------------------------------------------
     226              : class ElementEditData;
     227              : using ElementEditDataPtr = std::shared_ptr<ElementEditData>;
     228              : 
     229              : class MuseScoreView;
     230              : 
     231              : class EngravingItem;
     232              : class EditData
     233              : {
     234              : public:
     235            0 :     MuseScoreView* view() const { return m_view; }
     236              : 
     237              :     bool isEditMode = false; // refers to the legacy concept of "edit mode"
     238              : 
     239              :     std::vector<RectF> grip;
     240              :     int grips = 0;                 // number of grips
     241              :     Grip curGrip = Grip::NO_GRIP;
     242              : 
     243              :     PointF pos;
     244              :     PointF startMove;
     245              :     PointF normalizedStartMove; ///< Introduced for transition of drag logic. Don't use in new code.
     246              :     Point startMovePixel;
     247              :     PointF lastPos;
     248              :     PointF delta;               ///< This property is deprecated, use evtDelta or moveDelta instead. In normal drag equals to moveDelta, in edit drag - to evtDelta
     249              :     PointF evtDelta;            ///< Mouse offset for the last mouse move event
     250              :     PointF moveDelta;           ///< Mouse offset from the start of mouse move
     251              :     bool hRaster = false;
     252              :     bool vRaster = false;
     253              :     bool isHairpinDragCreatedFromDynamic = false;
     254              : 
     255              :     int key = 0;
     256              :     KeyboardModifiers modifiers;
     257              :     String s;
     258              :     String preeditString;
     259              : 
     260              :     MouseButtons buttons = NoButton;
     261              : 
     262              :     // drop data:
     263              :     PointF dragOffset;
     264              :     EngravingItem* element = nullptr;
     265              :     EngravingItem* dropElement = nullptr;
     266              :     track_idx_t track = muse::nidx;
     267              : 
     268          136 :     EditData(MuseScoreView* v = nullptr)
     269          136 :         : m_view(v) {}
     270              : 
     271              :     void clear();
     272              : 
     273              :     std::shared_ptr<ElementEditData> getData(const EngravingItem*) const;
     274              :     void addData(std::shared_ptr<ElementEditData>);
     275              :     bool control(bool textEditing = false) const;
     276              :     bool shift() const { return modifiers & ShiftModifier; }
     277            0 :     bool isStartEndGrip() const { return curGrip == Grip::START || curGrip == Grip::END; }
     278            0 :     bool hasCurrentGrip() const { return curGrip != Grip::NO_GRIP; }
     279              : 
     280              : private:
     281              :     std::vector<std::shared_ptr<ElementEditData> > m_data;
     282              :     MuseScoreView* m_view = nullptr;
     283              : };
     284              : }
        

Generated by: LCOV version 2.0-1