#include "CustomGrip.h" #include #include #include CustomGrip::CustomGrip(QWidget *parent, Qt::Edge positon, bool disableColor) : QWidget(parent) { wi = new Widgets(this); switch (positon) { // SHOW TOP GRIP case Qt::TopEdge: { this->wi->top(this); setGeometry(0, 0, qobject_cast(this->parent())->width(), 10); setMaximumHeight(10); // GRIPS QSizeGrip *topLeft = new QSizeGrip(this->wi->m_topLeft); QSizeGrip *topRight = new QSizeGrip(this->wi->m_topRight); if (disableColor) { this->wi->m_topLeft->setStyleSheet("background: transparent"); this->wi->m_topRight->setStyleSheet("background: transparent"); this->wi->m_top->setStyleSheet("background: transparent"); } wi->m_top->installEventFilter(this); } break; // SHOW BOTTOM GRIP case Qt::BottomEdge: { this->wi->bottom(this); setGeometry(0, qobject_cast(this->parent())->height() - 10, qobject_cast(this->parent())->width(), 10); setMaximumHeight(10); // GRIPS QSizeGrip *bottom_left = new QSizeGrip(this->wi->m_bottomLeft); QSizeGrip *bottom_right = new QSizeGrip(this->wi->m_bottomRight); if (disableColor) { this->wi->m_bottomLeft->setStyleSheet("background: transparent"); this->wi->m_bottomRight->setStyleSheet("background: transparent"); this->wi->m_bottom->setStyleSheet("background: transparent"); } wi->m_bottom->installEventFilter(this); } break; // SHOW LEFT GRIP case Qt::LeftEdge: { this->wi->left(this); setGeometry(0, 10, 10, qobject_cast(this->parent())->height()); setMaximumWidth(10); if (disableColor) { this->wi->m_leftgrip->setStyleSheet("background: transparent"); } wi->m_leftgrip->installEventFilter(this); } break; case Qt::RightEdge: { this->wi->right(this); setGeometry(qobject_cast(this->parent())->width() - 10, 10, 10, qobject_cast(this->parent())->height()); setMaximumWidth(10); if (disableColor) { this->wi->m_rightgrip->setStyleSheet("background: transparent"); } wi->m_rightgrip->installEventFilter(this); } break; default: break; } } void CustomGrip::mouseReleaseEvent(QMouseEvent *event) { Q_UNUSED(event) mousePos = QPoint(); } void CustomGrip::resizeEvent(QResizeEvent *event) { Q_UNUSED(event) if (this->wi->property("container_top").isValid()) { this->wi->m_containerTop->setGeometry(0, 0, this->width(), 10); } else if (this->wi->property("container_bottom").isValid()) { this->wi->m_containerBottom->setGeometry(0, 0, this->width(), 10); } else if (this->wi->property("leftgrip").isValid()) { this->wi->m_leftgrip->setGeometry(0, 0, 10, this->height() - 20); } else if (this->wi->property("rightgrip").isValid()) { this->wi->m_rightgrip->setGeometry(0, 0, 10, this->height() - 20); } } bool CustomGrip::eventFilter(QObject *watched, QEvent *event) { if (watched != nullptr && event->type() == QEvent::MouseMove) { QMouseEvent *mouseEvent = static_cast(event); if (watched == this->wi->m_top) { // RESIZE TOP QPoint delta = mouseEvent->pos(); QWidget *parent = qobject_cast(this->parent()); int height = std::max(parent->minimumHeight(), parent->height() - delta.y()); QRect geo = parent->geometry(); geo.setTop(geo.bottom() - height); parent->setGeometry(geo); event->accept(); } else if (watched == this->wi->m_bottom) { // RESIZE BOTTOM QPoint delta = mouseEvent->pos(); QWidget *parent = qobject_cast(this->parent()); int height = std::max(parent->minimumHeight(), parent->height() + delta.y()); parent->resize(parent->width(), height); event->accept(); } else if (watched == this->wi->m_leftgrip) { // RESIZE LEFT QPoint delta = mouseEvent->pos(); QWidget *parent = qobject_cast(this->parent()); int width = std::max(parent->minimumWidth(), parent->width() - delta.x()); QRect geo = parent->geometry(); geo.setLeft(geo.right() - width); parent->setGeometry(geo); event->accept(); } else if (watched == this->wi->m_rightgrip) { // RESIZE RIGHT QPoint delta = mouseEvent->pos(); QWidget *parent = qobject_cast(this->parent()); int width = std::max(parent->minimumWidth(), parent->width() + delta.x()); parent->resize(width, parent->height()); event->accept(); } } return QWidget::eventFilter(watched, event); } //////////////////////////////////////////////////////////////////////////////////////////////// Widgets::Widgets(QObject *parent) : QObject(parent) { m_containerTop = nullptr; m_topLayout = nullptr; m_topLeft = nullptr; m_top = nullptr; m_topRight = nullptr; m_containerBottom = nullptr; m_bottomLayout = nullptr; m_bottomLeft = nullptr; m_bottom = nullptr; m_bottomRight = nullptr; m_leftgrip = nullptr; m_rightgrip = nullptr; } void Widgets::top(QWidget *form) { if (form->objectName().isEmpty()) { form->setObjectName("Form"); } this->setProperty("container_top", "container_top"); this->m_containerTop = new QFrame(form); this->m_containerTop->setObjectName("container-top"); this->m_containerTop->setGeometry(QRect(0, 0, 500, 10)); this->m_containerTop->setMinimumSize(QSize(0, 10)); this->m_containerTop->setMaximumSize(QSize(16777215, 10)); this->m_containerTop->setFrameShape(QFrame::NoFrame); this->m_containerTop->setFrameShadow(QFrame::Raised); this->m_topLayout = new QHBoxLayout(this->m_containerTop); this->m_topLayout->setSpacing(0); this->m_topLayout->setObjectName("top-layout"); this->m_topLayout->setContentsMargins(0, 0, 0, 0); this->m_topLeft = new QFrame(this->m_containerTop); this->m_topLeft->setObjectName("top-left"); this->m_topLeft->setMinimumSize(QSize(10, 10)); this->m_topLeft->setMaximumSize(QSize(10, 10)); this->m_topLeft->setCursor(QCursor(Qt::SizeFDiagCursor)); this->m_topLeft->setStyleSheet("background-color: rgb(33, 37, 43);"); this->m_topLeft->setFrameShape(QFrame::NoFrame); this->m_topLeft->setFrameShadow(QFrame::Raised); this->m_topLayout->addWidget(this->m_topLeft); this->m_top = new QFrame(this->m_containerTop); this->m_top->setObjectName("top"); this->m_top->setCursor(QCursor(Qt::SizeVerCursor)); this->m_top->setStyleSheet("background-color: rgb(85, 255, 255);"); this->m_top->setFrameShape(QFrame::NoFrame); this->m_top->setFrameShadow(QFrame::Raised); this->m_topLayout->addWidget(this->m_top); this->m_topRight = new QFrame(this->m_containerTop); this->m_topRight->setObjectName("top_right"); this->m_topRight->setMinimumSize(QSize(10, 10)); this->m_topRight->setMaximumSize(QSize(10, 10)); this->m_topRight->setCursor(QCursor(Qt::SizeBDiagCursor)); this->m_topRight->setStyleSheet("background-color: rgb(33, 37, 43);"); this->m_topRight->setFrameShape(QFrame::NoFrame); this->m_topRight->setFrameShadow(QFrame::Raised); this->m_topLayout->addWidget(this->m_topRight); } void Widgets::bottom(QWidget *form) { if (form->objectName().isEmpty()) { form->setObjectName("Form"); } this->setProperty("container_bottom", "container_bottom"); this->m_containerBottom = new QFrame(form); this->m_containerBottom->setObjectName("container_bottom"); this->m_containerBottom->setGeometry(QRect(0, 0, 500, 10)); this->m_containerBottom->setMinimumSize(QSize(0, 10)); this->m_containerBottom->setMaximumSize(QSize(16777215, 10)); this->m_containerBottom->setFrameShape(QFrame::NoFrame); this->m_containerBottom->setFrameShadow(QFrame::Raised); this->m_bottomLayout = new QHBoxLayout(this->m_containerBottom); this->m_bottomLayout->setSpacing(0); this->m_bottomLayout->setObjectName("bottom_layout"); this->m_bottomLayout->setContentsMargins(0, 0, 0, 0); this->m_bottomLeft = new QFrame(this->m_containerBottom); this->m_bottomLeft->setObjectName("bottom_left"); this->m_bottomLeft->setMinimumSize(QSize(10, 10)); this->m_bottomLeft->setMaximumSize(QSize(10, 10)); this->m_bottomLeft->setCursor(QCursor(Qt::SizeBDiagCursor)); this->m_bottomLeft->setStyleSheet("background-color: rgb(33, 37, 43);"); this->m_bottomLeft->setFrameShape(QFrame::NoFrame); this->m_bottomLeft->setFrameShadow(QFrame::Raised); this->m_bottomLayout->addWidget(this->m_bottomLeft); this->m_bottom = new QFrame(this->m_containerBottom); this->m_bottom->setObjectName("bottom"); this->m_bottom->setCursor(QCursor(Qt::SizeVerCursor)); this->m_bottom->setStyleSheet("background-color: rgb(85, 170, 0);"); this->m_bottom->setFrameShape(QFrame::NoFrame); this->m_bottom->setFrameShadow(QFrame::Raised); this->m_bottomLayout->addWidget(this->m_bottom); this->m_bottomRight = new QFrame(this->m_containerBottom); this->m_bottomRight->setObjectName("bottom_right"); this->m_bottomRight->setMinimumSize(QSize(10, 10)); this->m_bottomRight->setMaximumSize(QSize(10, 10)); this->m_bottomRight->setCursor(QCursor(Qt::SizeFDiagCursor)); this->m_bottomRight->setStyleSheet("background-color: rgb(33, 37, 43);"); this->m_bottomRight->setFrameShape(QFrame::NoFrame); this->m_bottomRight->setFrameShadow(QFrame::Raised); this->m_bottomLayout->addWidget(this->m_bottomRight); } void Widgets::left(QWidget *form) { if (form->objectName().isEmpty()) { form->setObjectName("Form"); } this->setProperty("leftgrip", "leftgrip"); this->m_leftgrip = new QFrame(form); this->m_leftgrip->setObjectName("left"); this->m_leftgrip->setGeometry(QRect(0, 10, 10, 480)); this->m_leftgrip->setMinimumSize(QSize(10, 0)); this->m_leftgrip->setCursor(QCursor(Qt::SizeHorCursor)); this->m_leftgrip->setStyleSheet("background-color: rgb(255, 121, 198);"); this->m_leftgrip->setFrameShape(QFrame::NoFrame); this->m_leftgrip->setFrameShadow(QFrame::Raised); } void Widgets::right(QWidget *form) { if (form->objectName().isEmpty()) { form->setObjectName("Form"); } this->setProperty("rightgrip", "rightgrip"); form->resize(500, 500); this->m_rightgrip = new QFrame(form); this->m_rightgrip->setObjectName("right"); this->m_rightgrip->setGeometry(QRect(0, 0, 10, 500)); this->m_rightgrip->setMinimumSize(QSize(10, 0)); this->m_rightgrip->setCursor(QCursor(Qt::SizeHorCursor)); this->m_rightgrip->setStyleSheet("background-color: rgb(255, 0, 127);"); this->m_rightgrip->setFrameShape(QFrame::NoFrame); this->m_rightgrip->setFrameShadow(QFrame::Raised); }