Spaces:
Running
Running
File size: 6,052 Bytes
b4f9490 |
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 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 |
<template>
<div class="labeling-view">
<div class="labels-container" v-if="selectedObject">
<div class="label-options">
<div class="label-list">
<div
v-for="label in predefinedLabels"
:key="label.name"
class="label-item"
>
<button
class="label-btn"
:class="{ active: selectedObject.label === label.name }"
:style="{
backgroundColor: label.color,
border: selectedObject.label === label.name ? '3px solid #fff' : '3px solid transparent'
}"
@click="assignLabel(label.name)"
>
<span class="label-text">{{ label.name }}</span>
<span class="shortcut-key">{{ getShortcutKey(label.name) }}</span>
</button>
<input
type="color"
:value="label.color"
@input="updateLabelColor(label.name, $event.target.value)"
class="color-picker"
:title="`Changer la couleur de ${label.name}`"
/>
</div>
</div>
</div>
</div>
<div v-else class="no-object-message">
<p>Sélectionnez un objet dans la timeline pour lui attribuer un label</p>
</div>
</div>
</template>
<script>
import { useAnnotationStore } from '@/stores/annotationStore'
export default {
name: 'LabelingView',
data() {
return {
predefinedLabels: [
{ name: 'Player Team 1', color: '#dc3545' },
{ name: 'Player Team 2', color: '#000000' },
{ name: 'Ball', color: '#28a745' }
]
}
},
setup() {
const annotationStore = useAnnotationStore()
return {
annotationStore
}
},
mounted() {
// Ajouter l'écouteur d'événement clavier
window.addEventListener('keydown', this.handleKeyPress)
},
beforeUnmount() {
// Supprimer l'écouteur d'événement clavier
window.removeEventListener('keydown', this.handleKeyPress)
},
computed: {
selectedObject() {
if (!this.annotationStore.selectedObjectId) return null
return this.annotationStore.objects[this.annotationStore.selectedObjectId]
}
},
methods: {
assignLabel(labelName) {
if (!this.selectedObject) return
// Mettre à jour l'objet avec le nouveau label
this.annotationStore.objects[this.selectedObject.id] = {
...this.selectedObject,
label: labelName
}
console.log(`Label "${labelName}" assigné à l'objet ${this.selectedObject.name}`)
},
updateLabelColor(labelName, newColor) {
const labelIndex = this.predefinedLabels.findIndex(label => label.name === labelName)
if (labelIndex !== -1) {
this.predefinedLabels[labelIndex].color = newColor
}
},
removeLabel() {
if (!this.selectedObject) return
// Supprimer le label de l'objet
const updatedObject = { ...this.selectedObject }
delete updatedObject.label
this.annotationStore.objects[this.selectedObject.id] = updatedObject
console.log(`Label supprimé de l'objet ${this.selectedObject.name}`)
},
getLabelColor(labelName) {
const predefinedLabel = this.predefinedLabels.find(label => label.name === labelName)
return predefinedLabel ? predefinedLabel.color : '#6c757d'
},
getShortcutKey(labelName) {
const shortcuts = {
'Player Team 1': '1',
'Player Team 2': '2',
'Ball': '3'
}
return shortcuts[labelName] || ''
},
handleKeyPress(event) {
// Vérifier que nous ne sommes pas dans un champ de saisie
if (event.target.tagName === 'INPUT' || event.target.tagName === 'TEXTAREA') {
return
}
// Vérifier qu'un objet est sélectionné
if (!this.selectedObject) {
return
}
// Gérer les raccourcis clavier
switch(event.key) {
case '1':
event.preventDefault()
this.assignLabel('Player Team 1')
break
case '2':
event.preventDefault()
this.assignLabel('Player Team 2')
break
case '3':
event.preventDefault()
this.assignLabel('Ball')
break
}
}
}
}
</script>
<style scoped>
.labeling-view {
height: 100%;
padding: 16px;
color: white;
overflow-y: auto;
}
.labels-container {
display: flex;
flex-direction: column;
gap: 20px;
}
.label-list {
display: flex;
flex-direction: column;
gap: 8px;
}
.label-item {
display: flex;
align-items: center;
gap: 8px;
}
.label-btn {
flex: 1;
padding: 8px 12px;
border-radius: 4px;
color: white;
font-size: 0.8rem;
font-weight: 500;
cursor: pointer;
transition: all 0.2s;
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
}
.label-btn:hover {
opacity: 0.8;
transform: translateY(-1px);
}
.label-btn.active {
box-shadow: 0 0 0 1px #fff;
}
.color-picker {
width: 32px;
height: 32px;
border: none;
border-radius: 4px;
cursor: pointer;
background: none;
padding: 0;
}
.color-picker::-webkit-color-swatch-wrapper {
padding: 0;
border-radius: 4px;
}
.color-picker::-webkit-color-swatch {
border: none;
border-radius: 4px;
}
.label-text {
flex: 1;
text-align: left;
}
.shortcut-key {
background-color: rgba(255, 255, 255, 0.2);
border-radius: 3px;
padding: 2px 6px;
font-size: 11px;
font-weight: bold;
min-width: 16px;
text-align: center;
}
.no-object-message {
display: flex;
align-items: center;
justify-content: center;
height: 100%;
text-align: center;
}
.no-object-message p {
color: #999;
font-style: italic;
}
</style> |