@@ -118,7 +118,27 @@ void MainWindow::loadConfigLabels() {
118118 item->setFlags (Qt::ItemIsSelectable | Qt::ItemIsEnabled);
119119 list_label->addItem (item);
120120 list_label->setItemWidget (item, label_widget);
121- labels[it.key ()].item = item;
121+
122+ auto & ref = labels[it.key ()];
123+ ref.item = item;
124+
125+ int id = list_label->row (item);
126+ const QString shortcut_key = (id < 9 ) ? QString (" Ctrl+%1" ).arg (id + 1 ) :
127+ (id < 19 ) ? QString (" Alt+%1" ).arg (id - 10 + 1 ) :
128+ (id < 29 ) ? QString (" Ctrl+Alt+%1" ).arg (id - 20 + 1 ) :
129+ (id < 39 ) ? QString (" Ctrl+Shift+Alt+%1" ).arg (id - 30 + 1 ) :
130+ QString ();
131+
132+ if (id < 39 ) {
133+ QShortcut *shortcut = new QShortcut (QKeySequence (shortcut_key), this );
134+ ref.shortcut = shortcut;
135+
136+ QString text = label.name + " (" + ref.shortcut ->key ().toString () + " )" ;
137+ label_widget->setText (text);
138+
139+ connect (shortcut, &QShortcut::activated, this , [=]{onLabelShortcut (id);});
140+ }
141+
122142 }
123143 id_labels = getId2Label (labels);
124144}
@@ -157,7 +177,7 @@ void MainWindow::changeLabel(QListWidgetItem* current, QListWidgetItem* previous
157177 label->setSelected (true );
158178
159179 QString str;
160- QString key = label->text ();
180+ QString key = label->getName ();
161181 QTextStream sstr (&str);
162182 sstr <<" label=[" << key <<" ] id=[" << labels[key].id << " ] categorie=[" << labels[key].categorie << " ] color=[" << labels[key].color .name () << " ]" ;
163183 statusBar ()->showMessage (str);
@@ -421,3 +441,7 @@ void MainWindow::swapView() {
421441 ic->update ();
422442}
423443
444+ void MainWindow::onLabelShortcut (int row) {
445+ if (list_label->isEnabled ())
446+ list_label->setCurrentRow (row);
447+ }
0 commit comments