forked from github_mirror/framelesshelper
double click resize handler will change geometry
This commit is contained in:
parent
5f58937588
commit
9b2dc893b6
|
@ -29,6 +29,7 @@
|
||||||
#include <QtCore/qdebug.h>
|
#include <QtCore/qdebug.h>
|
||||||
#include <QtGui/qevent.h>
|
#include <QtGui/qevent.h>
|
||||||
#include <QtGui/qwindow.h>
|
#include <QtGui/qwindow.h>
|
||||||
|
#include <QtGui/qscreen.h>
|
||||||
#include "framelesswindowsmanager.h"
|
#include "framelesswindowsmanager.h"
|
||||||
#include "utilities.h"
|
#include "utilities.h"
|
||||||
|
|
||||||
|
@ -163,6 +164,7 @@ Qt::WindowFrameSection FramelessHelper::mapPosToFrameSection(const QPoint& pos)
|
||||||
const int sysBorder = Utilities::getSystemMetric(m_window, SystemMetric::ResizeBorderThickness, false);
|
const int sysBorder = Utilities::getSystemMetric(m_window, SystemMetric::ResizeBorderThickness, false);
|
||||||
|
|
||||||
Qt::WindowStates states = m_window->windowState();
|
Qt::WindowStates states = m_window->windowState();
|
||||||
|
// Resizing is disabled when WindowMaximized or WindowFullScreen
|
||||||
if (!(states & Qt::WindowMaximized) && !(states & Qt::WindowFullScreen))
|
if (!(states & Qt::WindowMaximized) && !(states & Qt::WindowFullScreen))
|
||||||
{
|
{
|
||||||
border = resizeBorderThickness();
|
border = resizeBorderThickness();
|
||||||
|
@ -313,23 +315,19 @@ void FramelessHelper::updateHoverStates(const QPoint& pos)
|
||||||
m_hoveredFrameSection = mapPosToFrameSection(pos);
|
m_hoveredFrameSection = mapPosToFrameSection(pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FramelessHelper::startMove(QMouseEvent* event)
|
void FramelessHelper::startMove(const QPoint &globalPos)
|
||||||
{
|
{
|
||||||
#ifdef Q_OS_LINUX
|
#ifdef Q_OS_LINUX
|
||||||
Utilities::sendX11ButtonReleaseEvent(m_window, event->globalPos());
|
Utilities::sendX11ButtonReleaseEvent(m_window, globalPos);
|
||||||
Utilities::startX11Moving(m_window, event->globalPos());
|
Utilities::startX11Moving(m_window, globalPos);
|
||||||
event->accept();
|
|
||||||
return;
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void FramelessHelper::startResize(QMouseEvent* event, Qt::WindowFrameSection frameSection)
|
void FramelessHelper::startResize(const QPoint &globalPos, Qt::WindowFrameSection frameSection)
|
||||||
{
|
{
|
||||||
#ifdef Q_OS_LINUX
|
#ifdef Q_OS_LINUX
|
||||||
Utilities::sendX11ButtonReleaseEvent(m_window, event->globalPos());
|
Utilities::sendX11ButtonReleaseEvent(m_window, globalPos);
|
||||||
Utilities::startX11Resizing(m_window, event->globalPos(), frameSection);
|
Utilities::startX11Resizing(m_window, globalPos, frameSection);
|
||||||
event->accept();
|
|
||||||
return;
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -376,13 +374,20 @@ bool FramelessHelper::eventFilter(QObject *object, QEvent *event)
|
||||||
if (m_clickedFrameSection == Qt::TitleBarArea
|
if (m_clickedFrameSection == Qt::TitleBarArea
|
||||||
&& isInTitlebarArea(ev->pos())) {
|
&& isInTitlebarArea(ev->pos())) {
|
||||||
// Start system move
|
// Start system move
|
||||||
startMove(ev);
|
startMove(ev->globalPos());
|
||||||
|
filterOut = true;
|
||||||
|
} else if (isClickResizeHandler() && isHoverResizeHandler()) {
|
||||||
|
// Start system resize
|
||||||
|
startResize(ev->globalPos(), m_hoveredFrameSection);
|
||||||
filterOut = true;
|
filterOut = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// We don't rely on the MouseMove event to determine the resize operation,
|
// This case takes into account that the mouse moves outside the window boundary
|
||||||
// because when the mouse is moved out of the window, the resize cannot
|
QRect windowRect(0, 0, windowSize().width(), windowSize().height());
|
||||||
// be triggered.
|
if (m_clickedFrameSection != Qt::NoSection && !windowRect.contains(ev->pos())) {
|
||||||
|
startResize(ev->globalPos(), m_clickedFrameSection);
|
||||||
|
filterOut = true;
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -399,11 +404,6 @@ bool FramelessHelper::eventFilter(QObject *object, QEvent *event)
|
||||||
if (ev->button() == Qt::LeftButton)
|
if (ev->button() == Qt::LeftButton)
|
||||||
m_clickedFrameSection = m_hoveredFrameSection;
|
m_clickedFrameSection = m_hoveredFrameSection;
|
||||||
|
|
||||||
if (ev->button() == Qt::LeftButton && isHoverResizeHandler()) {
|
|
||||||
// Start system resize
|
|
||||||
startResize(ev, m_hoveredFrameSection);
|
|
||||||
filterOut = true;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -418,14 +418,28 @@ bool FramelessHelper::eventFilter(QObject *object, QEvent *event)
|
||||||
case QEvent::MouseButtonDblClick:
|
case QEvent::MouseButtonDblClick:
|
||||||
{
|
{
|
||||||
auto ev = static_cast<QMouseEvent *>(event);
|
auto ev = static_cast<QMouseEvent *>(event);
|
||||||
if (isInTitlebarArea(ev->pos()) && ev->button() == Qt::LeftButton) {
|
if (isHoverResizeHandler() && ev->button() == Qt::LeftButton) {
|
||||||
|
// double click resize handler
|
||||||
|
if (m_clickedFrameSection == Qt::TopSection
|
||||||
|
|| m_clickedFrameSection == Qt::BottomSection) {
|
||||||
|
QRect screenRect = m_window->screen()->availableGeometry();
|
||||||
|
QRect winRect = m_window->geometry();
|
||||||
|
m_window->setGeometry(winRect.x(), 0, winRect.width(), screenRect.height());
|
||||||
|
} else if (m_clickedFrameSection == Qt::LeftSection
|
||||||
|
|| m_clickedFrameSection == Qt::RightSection) {
|
||||||
|
QRect screenRect = m_window->screen()->availableGeometry();
|
||||||
|
QRect winRect = m_window->geometry();
|
||||||
|
m_window->setGeometry(0, winRect.y(), screenRect.width(), winRect.height());
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if (isInTitlebarArea(ev->pos()) && ev->button() == Qt::LeftButton) {
|
||||||
Qt::WindowStates states = m_window->windowState();
|
Qt::WindowStates states = m_window->windowState();
|
||||||
if (states & Qt::WindowMaximized)
|
if (states & Qt::WindowMaximized)
|
||||||
m_window->showNormal();
|
m_window->showNormal();
|
||||||
else
|
else
|
||||||
m_window->showMaximized();
|
m_window->showMaximized();
|
||||||
}
|
}
|
||||||
// TODO: double click resize handler
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -84,8 +84,8 @@ public:
|
||||||
void updateMouse(const QPoint& pos);
|
void updateMouse(const QPoint& pos);
|
||||||
void updateHoverStates(const QPoint& pos);
|
void updateHoverStates(const QPoint& pos);
|
||||||
|
|
||||||
void startMove(QMouseEvent* event);
|
void startMove(const QPoint &globalPos);
|
||||||
void startResize(QMouseEvent* event, Qt::WindowFrameSection frameSection);
|
void startResize(const QPoint &globalPos, Qt::WindowFrameSection frameSection);
|
||||||
|
|
||||||
void setHitTestVisible(QObject *obj);
|
void setHitTestVisible(QObject *obj);
|
||||||
bool isHitTestVisible(QObject *obj);
|
bool isHitTestVisible(QObject *obj);
|
||||||
|
|
Loading…
Reference in New Issue