SceneRenameDelegate.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /******************************************************************************
  2. Copyright (C) 2023 by Lain Bailey <[email protected]>
  3. Zachary Lund <[email protected]>
  4. Philippe Groarke <[email protected]>
  5. This program is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. ******************************************************************************/
  16. #include "SceneRenameDelegate.hpp"
  17. #include <QKeyEvent>
  18. #include <QLineEdit>
  19. #include "moc_SceneRenameDelegate.cpp"
  20. SceneRenameDelegate::SceneRenameDelegate(QObject *parent) : QStyledItemDelegate(parent) {}
  21. void SceneRenameDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
  22. {
  23. QStyledItemDelegate::setEditorData(editor, index);
  24. QLineEdit *lineEdit = qobject_cast<QLineEdit *>(editor);
  25. if (lineEdit)
  26. lineEdit->selectAll();
  27. }
  28. bool SceneRenameDelegate::eventFilter(QObject *editor, QEvent *event)
  29. {
  30. if (event->type() == QEvent::KeyPress) {
  31. QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
  32. switch (keyEvent->key()) {
  33. case Qt::Key_Escape: {
  34. QLineEdit *lineEdit = qobject_cast<QLineEdit *>(editor);
  35. if (lineEdit)
  36. lineEdit->undo();
  37. break;
  38. }
  39. case Qt::Key_Tab:
  40. case Qt::Key_Backtab:
  41. return false;
  42. }
  43. }
  44. return QStyledItemDelegate::eventFilter(editor, event);
  45. }