Open Source Snapmatic picture and Savegame viewer/editor for GTA V https://gta5view.syping.de/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

UiModWidget.cpp 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*****************************************************************************
  2. * gta5view Grand Theft Auto V Profile Viewer
  3. * Copyright (C) 2017 Syping
  4. *
  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 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. *****************************************************************************/
  18. #include "UiModWidget.h"
  19. #include <QStyleOption>
  20. #include <QDropEvent>
  21. #include <QMimeData>
  22. #include <QPainter>
  23. #include <QDebug>
  24. #include <QUrl>
  25. UiModWidget::UiModWidget(QWidget *parent) : QWidget(parent)
  26. {
  27. filesDropEnabled = false;
  28. imageDropEnabled = false;
  29. }
  30. UiModWidget::~UiModWidget()
  31. {
  32. }
  33. void UiModWidget::setFilesDropEnabled(bool enabled)
  34. {
  35. filesDropEnabled = enabled;
  36. }
  37. void UiModWidget::setImageDropEnabled(bool enabled)
  38. {
  39. imageDropEnabled = enabled;
  40. }
  41. void UiModWidget::dragEnterEvent(QDragEnterEvent *dragEnterEvent)
  42. {
  43. if (filesDropEnabled && dragEnterEvent->mimeData()->hasUrls())
  44. {
  45. QStringList pathList;
  46. const QList<QUrl> urlList = dragEnterEvent->mimeData()->urls();
  47. for (const QUrl &currentUrl : urlList)
  48. {
  49. if (currentUrl.isLocalFile())
  50. {
  51. pathList.append(currentUrl.toLocalFile());
  52. }
  53. }
  54. if (!pathList.isEmpty())
  55. {
  56. dragEnterEvent->acceptProposedAction();
  57. }
  58. }
  59. else if (imageDropEnabled && dragEnterEvent->mimeData()->hasImage())
  60. {
  61. dragEnterEvent->acceptProposedAction();
  62. }
  63. }
  64. void UiModWidget::dropEvent(QDropEvent *dropEvent)
  65. {
  66. dropEvent->acceptProposedAction();
  67. emit dropped(dropEvent->mimeData());
  68. }
  69. void UiModWidget::paintEvent(QPaintEvent *paintEvent)
  70. {
  71. Q_UNUSED(paintEvent)
  72. QStyleOption opt;
  73. opt.init(this);
  74. QPainter p(this);
  75. style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
  76. }