You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

99 lines
2.6 KiB
C++

#include "FITKMdiSubWindow.h"
#include "FITKMdiArea.h"
#include <QDrag>
#include <QStyle>
#include <QMimeData>
#include <QMouseEvent>
#include <QApplication>
#include <QMenu>
namespace Comp
{
//互斥锁初始化
QMutex FITKMdiSubWindow::_mutex;
FITKMdiSubWindow::FITKMdiSubWindow(QWidget * parent)
{
//设置窗口外部移动属性
QMenu* menu = this->systemMenu();
//添加外部移动动作-将内部窗口移除
QAction* eMoveAction = menu->addAction("ExteriorMove");
connect(eMoveAction, &QAction::triggered, this, &FITKMdiSubWindow::widgetExteriorMove);
}
FITKMdiSubWindow::~FITKMdiSubWindow()
{
}
void FITKMdiSubWindow::setWidget(QWidget *widget)
{
m_widget = widget;
this->QMdiSubWindow::setWidget(widget);
this->initWidget();
}
QWidget *FITKMdiSubWindow::widget() const
{
return m_widget;
}
void FITKMdiSubWindow::setParent(FITKMdiArea* parent)
{
m_parent = parent;
}
void FITKMdiSubWindow::initWidget()
{
if (!m_widget)return;
m_widget->setWindowFlags(Qt::WindowMaximizeButtonHint | Qt::WindowCloseButtonHint);
//右键 不可少否则右键无反应
m_widget->setContextMenuPolicy(Qt::CustomContextMenu);
//创建右键移回操作
connect(m_widget, &QWidget::customContextMenuRequested, [=]() {
if (m_widget == this->QMdiSubWindow::widget())
return;
QMenu menu;
QAction* moveRAction = menu.addAction("MoveRestore");
connect(moveRAction, &QAction::triggered, this, &FITKMdiSubWindow::widgetMoveRestore);
menu.exec(QCursor::pos());
});
}
void FITKMdiSubWindow::mousePressEvent(QMouseEvent *event)
{
QMdiSubWindow::mousePressEvent(event);
}
void FITKMdiSubWindow::mouseMoveEvent(QMouseEvent *event)
{
QMdiSubWindow::mouseMoveEvent(event);
}
void FITKMdiSubWindow::mouseReleaseEvent(QMouseEvent *event)
{
QMdiSubWindow::mouseReleaseEvent(event);
}
void FITKMdiSubWindow::widgetExteriorMove()
{
if (!m_widget)return;
this->QMdiSubWindow::setWidget(nullptr);
m_widget->show();
this->close();
}
void FITKMdiSubWindow::widgetMoveRestore()
{
this->QMdiSubWindow::setWidget(m_widget);
if (!m_widget || !m_parent)return;
QList<QMdiSubWindow *> list = m_parent->subWindowList();
if (!list.contains(this))
m_parent->addSubWindow(this);
m_widget->show();
this->show();
}
}