2021-10-06 00:27:49 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <QFrame>
|
|
|
|
|
#include <QSize>
|
2022-12-21 17:07:25 +00:00
|
|
|
#include <optional>
|
2021-10-06 00:27:49 +01:00
|
|
|
#include <QEvent>
|
|
|
|
|
#include <QMouseEvent>
|
|
|
|
|
#include <QEnterEvent>
|
|
|
|
|
|
2022-02-06 20:28:46 +00:00
|
|
|
#include "PanelState.hpp"
|
|
|
|
|
|
2021-10-06 00:27:49 +01:00
|
|
|
namespace Bloom::Widgets
|
|
|
|
|
{
|
|
|
|
|
Q_NAMESPACE
|
|
|
|
|
|
|
|
|
|
enum class PanelWidgetType: int
|
|
|
|
|
{
|
|
|
|
|
LEFT,
|
2022-09-19 20:14:42 +01:00
|
|
|
RIGHT,
|
2021-10-06 00:27:49 +01:00
|
|
|
BOTTOM,
|
|
|
|
|
};
|
|
|
|
|
Q_ENUM_NS(PanelWidgetType)
|
|
|
|
|
|
2021-10-21 19:24:48 +01:00
|
|
|
class PanelWidget: public QFrame
|
2021-10-06 00:27:49 +01:00
|
|
|
{
|
2021-10-06 21:12:31 +01:00
|
|
|
Q_OBJECT
|
2021-10-06 00:27:49 +01:00
|
|
|
Q_PROPERTY(int handleSize READ getHandleSize WRITE setHandleSize DESIGNABLE true)
|
|
|
|
|
Q_PROPERTY(int minimumResize READ getMinimumResize WRITE setMinimumResize DESIGNABLE true)
|
|
|
|
|
|
|
|
|
|
public:
|
2022-08-13 18:41:52 +01:00
|
|
|
PanelState& state;
|
|
|
|
|
|
|
|
|
|
explicit PanelWidget(PanelWidgetType type, PanelState& state, QWidget* parent);
|
2021-10-06 00:27:49 +01:00
|
|
|
|
|
|
|
|
void setHandleSize(int handleSize) {
|
|
|
|
|
this->handleSize = handleSize;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void setMinimumResize(int minimumResize);
|
|
|
|
|
|
|
|
|
|
void setMaximumResize(int maximumResize);
|
|
|
|
|
|
2022-02-06 20:28:46 +00:00
|
|
|
void setSize(int size);
|
|
|
|
|
|
2021-10-21 19:24:48 +01:00
|
|
|
[[nodiscard]] int getHandleSize() const {
|
2021-10-06 00:27:49 +01:00
|
|
|
return this->handleSize;
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-21 19:24:48 +01:00
|
|
|
[[nodiscard]] int getMinimumResize() const {
|
2021-10-06 00:27:49 +01:00
|
|
|
return this->minimumResize;
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-21 19:24:48 +01:00
|
|
|
[[nodiscard]] int getMaximumResize() const {
|
2021-10-06 00:27:49 +01:00
|
|
|
return this->maximumResize;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-16 19:07:09 +01:00
|
|
|
/**
|
|
|
|
|
* Will evaluate whether the panel should still be visible or not (depending on whether there are any
|
|
|
|
|
* visible and attached child panes).
|
|
|
|
|
*
|
|
|
|
|
* This function is called whenever a child pane is activated/deactivate/attached/detached.
|
|
|
|
|
* See PaneWidget::PaneWidget() for more.
|
|
|
|
|
*/
|
|
|
|
|
void updateVisibility();
|
|
|
|
|
|
2022-07-20 19:13:16 +01:00
|
|
|
signals:
|
|
|
|
|
void closed();
|
|
|
|
|
void opened();
|
|
|
|
|
|
2021-10-06 21:12:31 +01:00
|
|
|
protected:
|
|
|
|
|
int handleSize = 10;
|
|
|
|
|
int minimumResize = 10;
|
|
|
|
|
int maximumResize = 500;
|
|
|
|
|
|
|
|
|
|
PanelWidgetType panelType = PanelWidgetType::LEFT;
|
2022-09-19 20:14:42 +01:00
|
|
|
|
2021-10-06 21:12:31 +01:00
|
|
|
QCursor resizeCursor = Qt::SplitHCursor;
|
2022-09-19 20:14:42 +01:00
|
|
|
std::optional<QPoint> initialResizePoint = std::nullopt;
|
|
|
|
|
int initialResizeSize = 0;
|
2021-10-06 21:12:31 +01:00
|
|
|
|
|
|
|
|
bool event(QEvent* event) override;
|
|
|
|
|
void mousePressEvent(QMouseEvent* event) override;
|
|
|
|
|
void mouseReleaseEvent(QMouseEvent* event) override;
|
|
|
|
|
void mouseMoveEvent(QMouseEvent* event) override;
|
|
|
|
|
|
2021-10-21 19:24:48 +01:00
|
|
|
[[nodiscard]] std::pair<QPoint, QPoint> getHandleArea() const;
|
|
|
|
|
[[nodiscard]] bool isPositionWithinHandleArea(const QPoint& position) const;
|
2021-10-06 00:27:49 +01:00
|
|
|
};
|
|
|
|
|
}
|