focus-list.cpp 597 B

123456789101112131415161718192021222324252627
  1. #include "focus-list.hpp"
  2. #include <QDragMoveEvent>
  3. FocusList::FocusList(QWidget *parent) : QListWidget(parent) {}
  4. void FocusList::focusInEvent(QFocusEvent *event)
  5. {
  6. QListWidget::focusInEvent(event);
  7. emit GotFocus();
  8. }
  9. void FocusList::dragMoveEvent(QDragMoveEvent *event)
  10. {
  11. #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
  12. QPoint pos = event->position().toPoint();
  13. #else
  14. QPoint pos = event->pos();
  15. #endif
  16. int itemRow = row(itemAt(pos));
  17. if ((itemRow == currentRow() + 1) ||
  18. (currentRow() == count() - 1 && itemRow == -1))
  19. event->ignore();
  20. else
  21. QListWidget::dragMoveEvent(event);
  22. }