All files / src/components/navigation/annotation AnnotationMenu.vue

0% Statements 0/30
0% Branches 0/14
0% Functions 0/17
0% Lines 0/30

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151                                                                                                                                                                                                                                                                                                             
<template>
  <v-menu
    data-testid="menu"
    v-model="m_open"
  >
    <template #activator="{ props: menu }">
      <v-tooltip
        location="bottom"
        open-delay="1000"
      >
        <template #activator="{ props: tooltip }">
          <v-btn
            v-bind="mergeProps(menu, tooltip)"
            data-testid="activator"
            :icon="true"
            size="24"
            variant="text"
          >
            <v-icon
              icon="more_vert"
              size="16"
              color="shark_400"
            />
          </v-btn>
        </template>
        <span>{{ t('labels.moreActions') }}</span>
      </v-tooltip>
    </template>
    <v-list id="annotation_menu">
      <v-list-item
        class="px-4 py-2"
        data-testid="focus"
        prepend-icon="center_focus_strong"
        @click="focus"
      >
        <v-list-item-title>{{ t('labels.focus') }}</v-list-item-title>
        <v-spacer />
        <v-list-item-subtitle class="ml-4">{{
          translateTooltipShortcut(SHORTCUT_TEXT.f)
        }}</v-list-item-subtitle>
      </v-list-item>
      <v-list-item
        class="px-4 py-2"
        data-testid="update"
        prepend-icon="edit_square"
        @click="updateAnnotation"
      >
        <v-list-item-title>{{ t('labels.edit') }}</v-list-item-title>
        <v-spacer />
        <v-list-item-subtitle class="ml-4">{{
          translateTooltipShortcut(SHORTCUT_TEXT.e)
        }}</v-list-item-subtitle>
      </v-list-item>
      <v-list-item
        class="px-4 py-2"
        data-testid="delete"
        prepend-icon="delete"
        @click="deleteAnnotation"
      >
        <v-list-item-title>{{ t('labels.delete') }}</v-list-item-title>
        <v-spacer />
        <v-list-item-subtitle class="ml-4">{{
          translateTooltipShortcut(SHORTCUT_TEXT.del)
        }}</v-list-item-subtitle>
      </v-list-item>
    </v-list>
  </v-menu>
  <annotation-update-modal
    v-model="m_update"
    :annotation="annotation"
  />
  <annotation-delete-modal
    v-model="m_delete"
    :annotation="annotation"
  />
</template>
 
<script setup lang="ts">
import { mergeProps, ref, watch } from 'vue';
import { useViewer3cr } from '@/composables/useViewer3cr';
import { initialScanState } from '@/models/scanState';
import { SlidersActions } from '@3cr/types-ts';
import {
  defineHotkeys,
  Hotkeys,
  HotkeyScope,
  resetScope,
} from '@/functions/HotkeyScope';
import { useI18n } from 'vue-i18n';
import {
  SHORTCUT_TEXT,
  translateTooltipShortcut,
} from '@/functions/translateTooltipShortcut';
import { DataOverlayAnnotation } from '@3cr/viewer-types-ts';
 
interface Props {
  annotation: DataOverlayAnnotation;
}
 
const props = defineProps<Props>();
 
const { t } = useI18n();
const viewer3cr = useViewer3cr();
 
const m_update = ref<boolean>(false);
const m_delete = ref<boolean>(false);
const m_open = ref<boolean>(false);
 
watch(m_open, (isOpen: boolean) => {
  if (isOpen) {
    defineHotkeys(HotkeyScope.ANNOTATION_MENU, {
      [Hotkeys.CTRL_SHIFT_E]: async () => {
        updateAnnotation();
      },
      [Hotkeys.CTRL_SHIFT_F]: async () => {
        await focus();
      },
      [Hotkeys.CTRL_SHIFT_DEL]: async () => {
        deleteAnnotation();
      },
    });
  } else {
    resetScope(HotkeyScope.ANNOTATION_MENU);
  }
});
 
function updateAnnotation(): void {
  m_update.value = true;
}
 
function deleteAnnotation(): void {
  m_delete.value = true;
}
 
async function focus(): Promise<void> {
  const { X, Y, Z } = props.annotation.Position;
  const { XSpacing, YSpacing, ZSpacing } = initialScanState.value;
  await viewer3cr.sliderHandler(SlidersActions.sl09, Z / (ZSpacing || 1));
  await viewer3cr.sliderHandler(SlidersActions.sl12, X / (XSpacing || 1));
  await viewer3cr.sliderHandler(SlidersActions.sl15, Y / (YSpacing || 1));
}
</script>
 
<style scoped lang="scss">
:deep(.v-list-item__content) {
  display: flex;
  align-items: baseline;
  width: 100%;
}
</style>