QtUtil.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #pragma once
  9. #include <QString>
  10. #include <CryCommon/StlUtils.h>
  11. #include <QApplication>
  12. #include <QDropEvent>
  13. #include <QWidget>
  14. #ifdef LoadCursor
  15. #undef LoadCursor
  16. #endif
  17. class QWaitCursor
  18. {
  19. public:
  20. QWaitCursor()
  21. {
  22. QGuiApplication::setOverrideCursor(Qt::BusyCursor);
  23. }
  24. ~QWaitCursor()
  25. {
  26. QGuiApplication::restoreOverrideCursor();
  27. }
  28. };
  29. namespace QtUtil
  30. {
  31. inline QString trimRight(const QString& str)
  32. {
  33. // We prepend a char, so that the left doesn't get trimmed, then we remove it after trimming
  34. return QString(QStringLiteral("A") + str).trimmed().remove(0, 1);
  35. }
  36. template<typename ... Args>
  37. struct Select
  38. {
  39. template<typename C, typename R>
  40. static auto OverloadOf(R(C::* pmf)(Args...))->decltype(pmf) {
  41. return pmf;
  42. }
  43. };
  44. }
  45. namespace stl
  46. {
  47. //! Case insensitive less key for QString
  48. template <>
  49. struct less_stricmp<QString>
  50. {
  51. bool operator()(const QString& left, const QString& right) const
  52. {
  53. return left.compare(right, Qt::CaseInsensitive) < 0;
  54. }
  55. };
  56. }