HistoryLineEdit.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. * HistoryLineEdit.cpp
  3. * nirc
  4. *
  5. * Created by Niklas Bölter on 03.02.10.
  6. * Copyright 2010 Frubar Corporation.
  7. *
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. *
  15. *
  16. */
  17. #include "HistoryLineEdit.h"
  18. HistoryLineEdit::HistoryLineEdit(QWidget *parent) : QLineEdit(parent) {}
  19. void HistoryLineEdit::keyPressEvent(QKeyEvent *event)
  20. {
  21. switch (event->key()) {
  22. case Qt::Key_Enter:
  23. case Qt::Key_Return:
  24. emit returnPressed();
  25. event->accept(); // This fixes an issue on Mac OS X which makes a weird noise
  26. //because LineEdit does not allow return as a valid input
  27. // Should be fixed in the next Release of QT ( > 4.6 )
  28. break;
  29. case Qt::Key_Up:
  30. emit upPressed(); // Scroll back in the input history
  31. event->accept();
  32. break;
  33. case Qt::Key_Down:
  34. emit downPressed(); // Scroll forward in the input history
  35. event->accept();
  36. break;
  37. case Qt::Key_Tab:
  38. emit tabPressed();
  39. event->accept();
  40. break;
  41. default:
  42. QLineEdit::keyPressEvent(event);
  43. break;
  44. }
  45. }
  46. bool HistoryLineEdit::focusNextPrevChild(bool)
  47. {
  48. return true; // Show that we have found the "nextprevchild" - we will keep focus!
  49. }