|
@@ -1,18 +1,23 @@
|
|
-/**
|
|
|
|
- * Ò¶º£»Ô
|
|
|
|
- * QQȺ121376426
|
|
|
|
|
|
+/**
|
|
|
|
+ * �海辉
|
|
|
|
+ * QQ群321159586
|
|
* http://blog.yundiantech.com/
|
|
* http://blog.yundiantech.com/
|
|
*/
|
|
*/
|
|
|
|
|
|
#include "DragAbleWidget.h"
|
|
#include "DragAbleWidget.h"
|
|
#include "ui_DragAbleWidget.h"
|
|
#include "ui_DragAbleWidget.h"
|
|
|
|
|
|
|
|
+#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
|
|
|
+#include <QScreen>
|
|
|
|
+#else
|
|
#include <QDesktopWidget>
|
|
#include <QDesktopWidget>
|
|
|
|
+#endif
|
|
|
|
+
|
|
#include <QMouseEvent>
|
|
#include <QMouseEvent>
|
|
#include <QTimer>
|
|
#include <QTimer>
|
|
#include <QDebug>
|
|
#include <QDebug>
|
|
|
|
|
|
-#define MARGINS 2 //´°Ìå±ß¿ò
|
|
|
|
|
|
+#define MARGINS 2 //窗体边框
|
|
|
|
|
|
DragAbleWidget::DragAbleWidget(QWidget *parent) :
|
|
DragAbleWidget::DragAbleWidget(QWidget *parent) :
|
|
QWidget(parent),
|
|
QWidget(parent),
|
|
@@ -20,19 +25,24 @@ DragAbleWidget::DragAbleWidget(QWidget *parent) :
|
|
{
|
|
{
|
|
ui->setupUi(this);
|
|
ui->setupUi(this);
|
|
|
|
|
|
- ///¶¨Ê±Æ÷ÓÃÓÚ¶¨ÖƼì²âÊó±êλÖ㬷ÀÖ¹Êó±ê¿ìËÙÒÆÈë´°¿Ú£¬Ã»Óмì²âµ½£¬µ¼ÖÂÊó±ê¼ýÍ·³ÊÏÖÍÏÀµÄÐÎ×´
|
|
|
|
|
|
+ ///å®šæ—¶å™¨ç”¨äºŽå®šåˆ¶æ£€æµ‹é¼ æ ‡ä½�置,防æ¢é¼ æ ‡å¿«é€Ÿç§»å…¥çª—å�£ï¼Œæ²¡æœ‰æ£€æµ‹åˆ°ï¼Œå¯¼è‡´é¼ æ ‡ç®å¤´å‘ˆçŽ°æ‹–æ‹‰çš„å½¢çŠ¶
|
|
mTimer = new QTimer;
|
|
mTimer = new QTimer;
|
|
mTimer->setInterval(1000);
|
|
mTimer->setInterval(1000);
|
|
connect(mTimer, &QTimer::timeout, this, &DragAbleWidget::slotTimerTimeOut);
|
|
connect(mTimer, &QTimer::timeout, this, &DragAbleWidget::slotTimerTimeOut);
|
|
mTimer->start();
|
|
mTimer->start();
|
|
|
|
|
|
-///¸Ä±ä´°Ìå´óСÏà¹Ø
|
|
|
|
|
|
+///改�窗体大�相关
|
|
isMax = false;
|
|
isMax = false;
|
|
|
|
|
|
int w = this->width();
|
|
int w = this->width();
|
|
int h = this->height();
|
|
int h = this->height();
|
|
|
|
|
|
- QRect screenRect = QApplication::desktop()->screenGeometry();//»ñÈ¡É豸ÆÁÄ»´óС
|
|
|
|
|
|
+#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
|
|
|
+ QRect screenRect = QApplication::primaryScreen()->availableGeometry();//获�设备�幕大�
|
|
|
|
+#else
|
|
|
|
+ QRect screenRect = QApplication::desktop()->screenGeometry();//获�设备�幕大�
|
|
|
|
+#endif
|
|
|
|
+
|
|
int x = (screenRect.width() - w) / 2;
|
|
int x = (screenRect.width() - w) / 2;
|
|
int y = (screenRect.height() - h) / 2;
|
|
int y = (screenRect.height() - h) / 2;
|
|
|
|
|
|
@@ -42,7 +52,7 @@ DragAbleWidget::DragAbleWidget(QWidget *parent) :
|
|
|
|
|
|
isLeftPressDown = false;
|
|
isLeftPressDown = false;
|
|
this->dir = NONE;
|
|
this->dir = NONE;
|
|
- this->setMouseTracking(true);// ×·×ÙÊó±ê
|
|
|
|
|
|
+ this->setMouseTracking(true);// è¿½è¸ªé¼ æ ‡
|
|
ui->widget_frame->setMouseTracking(true);
|
|
ui->widget_frame->setMouseTracking(true);
|
|
ui->widget_back->setMouseTracking(true);
|
|
ui->widget_back->setMouseTracking(true);
|
|
ui->widget_container->setMouseTracking(true);
|
|
ui->widget_container->setMouseTracking(true);
|
|
@@ -55,7 +65,7 @@ DragAbleWidget::DragAbleWidget(QWidget *parent) :
|
|
|
|
|
|
// ui->widget_frame->setContentsMargins(1, 1, 1, 1);
|
|
// ui->widget_frame->setContentsMargins(1, 1, 1, 1);
|
|
|
|
|
|
- //°²×°Ê¼þ¼àÌýÆ÷,ÈñêÌâÀ¸Ê¶±ðÊó±êË«»÷
|
|
|
|
|
|
+ //安装事件监å�¬å™¨,è®©æ ‡é¢˜æ �è¯†åˆ«é¼ æ ‡å�Œå‡»
|
|
// ui->widget_beingClass_back->installEventFilter(this);
|
|
// ui->widget_beingClass_back->installEventFilter(this);
|
|
|
|
|
|
}
|
|
}
|
|
@@ -76,7 +86,7 @@ void DragAbleWidget::setTitle(QString str)
|
|
this->setWindowTitle(str);
|
|
this->setWindowTitle(str);
|
|
}
|
|
}
|
|
|
|
|
|
-////////////¸Ä±ä´°Ìå´óСÏà¹Ø
|
|
|
|
|
|
+////////////改�窗体大�相关
|
|
|
|
|
|
void DragAbleWidget::mouseReleaseEvent(QMouseEvent *event)
|
|
void DragAbleWidget::mouseReleaseEvent(QMouseEvent *event)
|
|
{
|
|
{
|
|
@@ -100,7 +110,7 @@ void DragAbleWidget::mousePressEvent(QMouseEvent *event)
|
|
{
|
|
{
|
|
// if(QApplication::keyboardModifiers() == (Qt::ControlModifier|Qt::ShiftModifier|Qt::AltModifier))
|
|
// if(QApplication::keyboardModifiers() == (Qt::ControlModifier|Qt::ShiftModifier|Qt::AltModifier))
|
|
{
|
|
{
|
|
- doChangeFullScreen(); //ctrl + ×ó¼ü
|
|
|
|
|
|
+ doChangeFullScreen(); //ctrl + 左键
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -219,7 +229,11 @@ void DragAbleWidget::mouseMoveEvent(QMouseEvent *event)
|
|
{
|
|
{
|
|
QPoint point = event->globalPos() - dragPosition;
|
|
QPoint point = event->globalPos() - dragPosition;
|
|
|
|
|
|
|
|
+#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
|
|
|
+ QRect mLimitRect = QApplication::primaryScreen()->availableGeometry();
|
|
|
|
+#else
|
|
QRect mLimitRect = QApplication::desktop()->availableGeometry();
|
|
QRect mLimitRect = QApplication::desktop()->availableGeometry();
|
|
|
|
+#endif
|
|
|
|
|
|
if (point.x() < mLimitRect.x())
|
|
if (point.x() < mLimitRect.x())
|
|
point.setX(mLimitRect.x());
|
|
point.setX(mLimitRect.x());
|
|
@@ -240,13 +254,13 @@ void DragAbleWidget::mouseMoveEvent(QMouseEvent *event)
|
|
event->accept();
|
|
event->accept();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-// QWidget::mouseMoveEvent(event);¡¢
|
|
|
|
|
|
+// QWidget::mouseMoveEvent(event);�
|
|
event->accept();
|
|
event->accept();
|
|
}
|
|
}
|
|
|
|
|
|
void DragAbleWidget::checkCursorDirect(const QPoint &cursorGlobalPoint)
|
|
void DragAbleWidget::checkCursorDirect(const QPoint &cursorGlobalPoint)
|
|
{
|
|
{
|
|
- // »ñÈ¡´°ÌåÔÚÆÁÄ»ÉϵÄλÖÃÇøÓò£¬tlΪtopleftµã£¬rbΪrightbottomµã
|
|
|
|
|
|
+ // 获�窗体在�幕上的�置区域,tl为topleft点,rb为rightbottom点
|
|
QRect rect = this->rect();
|
|
QRect rect = this->rect();
|
|
QPoint tl = mapToGlobal(rect.topLeft());
|
|
QPoint tl = mapToGlobal(rect.topLeft());
|
|
QPoint rb = mapToGlobal(rect.bottomRight());
|
|
QPoint rb = mapToGlobal(rect.bottomRight());
|
|
@@ -255,39 +269,39 @@ void DragAbleWidget::checkCursorDirect(const QPoint &cursorGlobalPoint)
|
|
int y = cursorGlobalPoint.y();
|
|
int y = cursorGlobalPoint.y();
|
|
|
|
|
|
if(tl.x() + PADDING >= x && tl.x() <= x && tl.y() + PADDING >= y && tl.y() <= y) {
|
|
if(tl.x() + PADDING >= x && tl.x() <= x && tl.y() + PADDING >= y && tl.y() <= y) {
|
|
- // ×óÉϽÇ
|
|
|
|
|
|
+ // 左上角
|
|
dir = LEFTTOP;
|
|
dir = LEFTTOP;
|
|
- this->setCursor(QCursor(Qt::SizeFDiagCursor)); // ÉèÖÃÊó±êÐÎ×´
|
|
|
|
|
|
+ this->setCursor(QCursor(Qt::SizeFDiagCursor)); // è®¾ç½®é¼ æ ‡å½¢çŠ¶
|
|
} else if(x >= rb.x() - PADDING && x <= rb.x() && y >= rb.y() - PADDING && y <= rb.y()) {
|
|
} else if(x >= rb.x() - PADDING && x <= rb.x() && y >= rb.y() - PADDING && y <= rb.y()) {
|
|
- // ÓÒϽÇ
|
|
|
|
|
|
+ // �下角
|
|
dir = RIGHTBOTTOM;
|
|
dir = RIGHTBOTTOM;
|
|
this->setCursor(QCursor(Qt::SizeFDiagCursor));
|
|
this->setCursor(QCursor(Qt::SizeFDiagCursor));
|
|
} else if(x <= tl.x() + PADDING && x >= tl.x() && y >= rb.y() - PADDING && y <= rb.y()) {
|
|
} else if(x <= tl.x() + PADDING && x >= tl.x() && y >= rb.y() - PADDING && y <= rb.y()) {
|
|
- //×óϽÇ
|
|
|
|
|
|
+ //左下角
|
|
dir = LEFTBOTTOM;
|
|
dir = LEFTBOTTOM;
|
|
this->setCursor(QCursor(Qt::SizeBDiagCursor));
|
|
this->setCursor(QCursor(Qt::SizeBDiagCursor));
|
|
} else if(x <= rb.x() && x >= rb.x() - PADDING && y >= tl.y() && y <= tl.y() + PADDING) {
|
|
} else if(x <= rb.x() && x >= rb.x() - PADDING && y >= tl.y() && y <= tl.y() + PADDING) {
|
|
- // ÓÒÉϽÇ
|
|
|
|
|
|
+ // �上角
|
|
dir = RIGHTTOP;
|
|
dir = RIGHTTOP;
|
|
this->setCursor(QCursor(Qt::SizeBDiagCursor));
|
|
this->setCursor(QCursor(Qt::SizeBDiagCursor));
|
|
} else if(x <= tl.x() + PADDING && x >= tl.x()) {
|
|
} else if(x <= tl.x() + PADDING && x >= tl.x()) {
|
|
- // ×ó±ß
|
|
|
|
|
|
+ // 左边
|
|
dir = LEFT;
|
|
dir = LEFT;
|
|
this->setCursor(QCursor(Qt::SizeHorCursor));
|
|
this->setCursor(QCursor(Qt::SizeHorCursor));
|
|
} else if( x <= rb.x() && x >= rb.x() - PADDING) {
|
|
} else if( x <= rb.x() && x >= rb.x() - PADDING) {
|
|
- // ÓÒ±ß
|
|
|
|
|
|
+ // �边
|
|
dir = RIGHT;
|
|
dir = RIGHT;
|
|
this->setCursor(QCursor(Qt::SizeHorCursor));
|
|
this->setCursor(QCursor(Qt::SizeHorCursor));
|
|
}else if(y >= tl.y() && y <= tl.y() + PADDING){
|
|
}else if(y >= tl.y() && y <= tl.y() + PADDING){
|
|
- // Éϱß
|
|
|
|
|
|
+ // 上边
|
|
dir = UP;
|
|
dir = UP;
|
|
this->setCursor(QCursor(Qt::SizeVerCursor));
|
|
this->setCursor(QCursor(Qt::SizeVerCursor));
|
|
} else if(y <= rb.y() && y >= rb.y() - PADDING) {
|
|
} else if(y <= rb.y() && y >= rb.y() - PADDING) {
|
|
- // 챧
|
|
|
|
|
|
+ // 下边
|
|
dir = DOWN;
|
|
dir = DOWN;
|
|
this->setCursor(QCursor(Qt::SizeVerCursor));
|
|
this->setCursor(QCursor(Qt::SizeVerCursor));
|
|
}else {
|
|
}else {
|
|
- // ĬÈÏ
|
|
|
|
|
|
+ // 默认
|
|
dir = NONE;
|
|
dir = NONE;
|
|
this->setCursor(QCursor(Qt::ArrowCursor));
|
|
this->setCursor(QCursor(Qt::ArrowCursor));
|
|
}
|
|
}
|
|
@@ -299,13 +313,13 @@ void DragAbleWidget::doShowFullScreen()
|
|
this->show();
|
|
this->show();
|
|
this->showFullScreen();
|
|
this->showFullScreen();
|
|
this->raise();
|
|
this->raise();
|
|
- ui->widget_frame->setContentsMargins(0,0,0,0); //Òþ²Ø±ß¿ò
|
|
|
|
|
|
+ ui->widget_frame->setContentsMargins(0,0,0,0); //��边框
|
|
|
|
|
|
showBorderRadius(false);
|
|
showBorderRadius(false);
|
|
|
|
|
|
ui->btnMenu_Max->setIcon(QIcon(":/image/shownormalbtn.png"));
|
|
ui->btnMenu_Max->setIcon(QIcon(":/image/shownormalbtn.png"));
|
|
|
|
|
|
- ui->widget_title->hide(); //Òþ²Ø±êÌâÀ¸
|
|
|
|
|
|
+ ui->widget_title->hide(); //éš�è—�æ ‡é¢˜æ �
|
|
// ui->verticalLayout_titleWidget_Back->removeWidget(ui->widget_title);
|
|
// ui->verticalLayout_titleWidget_Back->removeWidget(ui->widget_title);
|
|
// ui->widget_title->setParent(NULL);
|
|
// ui->widget_title->setParent(NULL);
|
|
// ui->widget_title->setWindowFlags(Qt::FramelessWindowHint|Qt::WindowStaysOnTopHint|Qt::Tool|Qt::X11BypassWindowManagerHint);
|
|
// ui->widget_title->setWindowFlags(Qt::FramelessWindowHint|Qt::WindowStaysOnTopHint|Qt::Tool|Qt::X11BypassWindowManagerHint);
|