PreviewProgramSizeObserver.hpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /******************************************************************************
  2. Copyright (C) 2025 by Taylor Giampaolo <[email protected]>
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. ******************************************************************************/
  14. #pragma once
  15. #include <QObject>
  16. #include <QPointer>
  17. #include <QWidget>
  18. class PreviewProgramSizeObserver : public QObject {
  19. Q_OBJECT
  20. QPointer<QWidget> left;
  21. QPointer<QWidget> right;
  22. QPointer<QWidget> leftContainer;
  23. QPointer<QWidget> rightContainer;
  24. QSize leftOriginalMaxSize;
  25. QSize rightOriginalMaxSize;
  26. int leftTargetSize{};
  27. int rightTargetSize{};
  28. QPointer<QWidget> ancestorContainer;
  29. bool updating = false;
  30. Qt::Orientation orientation = Qt::Horizontal;
  31. std::pair<QWidget *, QWidget *> findSiblingParents(QWidget *a, QWidget *b);
  32. void syncContainerSizes(int containerSizeDelta);
  33. public:
  34. PreviewProgramSizeObserver(QWidget *widgetLeft, QWidget *widgetRight, QObject *parent = nullptr);
  35. ~PreviewProgramSizeObserver();
  36. void setOrientation(Qt::Orientation orientation_);
  37. protected:
  38. bool eventFilter(QObject *target, QEvent *event) override;
  39. };