修复了拖拽bug
This commit is contained in:
parent
75982278b4
commit
480b259a53
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE QtCreatorProject>
|
||||
<!-- Written by QtCreator 4.15.0, 2024-02-09T16:03:39. -->
|
||||
<!-- Written by QtCreator 4.15.0, 2024-02-10T14:34:11. -->
|
||||
<qtcreator>
|
||||
<data>
|
||||
<variable>EnvironmentId</variable>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#include "acceptpanel.h"
|
||||
#include "AcceptPanel.h"
|
||||
|
||||
#include <QDragMoveEvent>
|
||||
#include <QPainter>
|
||||
|
@ -107,7 +107,7 @@ void accept_panel::AcceptPanel::dragEnterEvent(QDragEnterEvent *ev)
|
|||
ev->acceptProposedAction();
|
||||
}
|
||||
|
||||
#include "splitpanel.h"
|
||||
#include "SplitPanel.h"
|
||||
#include <QDebug>
|
||||
void accept_panel::AcceptPanel::dropEvent(QDropEvent *ev)
|
||||
{
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
#include <QMainWindow>
|
||||
#include <QWidget>
|
||||
#include "splitview_interface.h"
|
||||
#include "libSplitView.h"
|
||||
|
||||
namespace accept_panel {
|
||||
enum class HoverType{
|
|
@ -1,4 +1,4 @@
|
|||
#include "dockpanel.h"
|
||||
#include "DockPanel.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QDebug>
|
||||
|
@ -113,6 +113,11 @@ DockableView::DockableView(split_frame::ResManager *mgr, QWidget *present, bool
|
|||
connect(this->title_header, &DragHeader::adjustRequest, this, &DockableView::adjustAccept);
|
||||
}
|
||||
|
||||
DockableView::~DockableView() {
|
||||
manager_inst->removePresentView(this);
|
||||
qDebug() << "view-deleted";
|
||||
}
|
||||
|
||||
void DockableView::viewConfig(bool replace, bool close, bool retrieve)
|
||||
{
|
||||
this->m_replace = replace;
|
||||
|
@ -155,18 +160,6 @@ void DockableView::retrieveAccept()
|
|||
this->manager_inst->doRetrieve(this);
|
||||
}
|
||||
|
||||
void DockableView::showEvent(QShowEvent *ev)
|
||||
{
|
||||
QWidget::showEvent(ev);
|
||||
manager_inst->appendPresentView(this);
|
||||
}
|
||||
|
||||
void DockableView::hideEvent(QHideEvent *ev)
|
||||
{
|
||||
QWidget::hideEvent(ev);
|
||||
manager_inst->removePresentView(this);
|
||||
}
|
||||
|
||||
split_frame::ResManager *DockableView::splitManager() const
|
||||
{
|
||||
return this->manager_inst;
|
|
@ -1,7 +1,7 @@
|
|||
#ifndef BASEVIEW_H
|
||||
#define BASEVIEW_H
|
||||
|
||||
#include "splitview_interface.h"
|
||||
#include "libSplitView.h"
|
||||
#include <QFrame>
|
||||
#include <QIcon>
|
||||
#include <QLabel>
|
||||
|
@ -62,6 +62,7 @@ namespace dock_panel {
|
|||
* @param custom_header 是否添加标题栏
|
||||
*/
|
||||
DockableView(split_frame::ResManager*mgr, QWidget *present, bool drag_header = false);
|
||||
virtual ~DockableView();
|
||||
/**
|
||||
* @brief 配置视图基本特性
|
||||
* @param replace 可以被隐藏和替换
|
||||
|
@ -82,10 +83,6 @@ namespace dock_panel {
|
|||
void closeAccept();
|
||||
void retrieveAccept();
|
||||
|
||||
protected:
|
||||
void showEvent(QShowEvent *ev) override;
|
||||
void hideEvent(QHideEvent *ev) override;
|
||||
|
||||
private:
|
||||
DragHeader *const title_header;
|
||||
QWidget *const present_cube;
|
|
@ -1,5 +1,5 @@
|
|||
#include "splitpanel.h"
|
||||
#include "dockpanel.h"
|
||||
#include "SplitPanel.h"
|
||||
#include "DockPanel.h"
|
||||
#include <QPainter>
|
||||
#include <libConfig.h>
|
||||
|
||||
|
@ -80,10 +80,10 @@ bool SplitPanel::isVisible() const
|
|||
void SplitPanel::initViews(ViewRes *a, ViewRes *b)
|
||||
{
|
||||
a->setParentRes(this);
|
||||
manager_inst->appendPresentView(dynamic_cast<ViewBase*>(a));
|
||||
b->setParentRes(this);
|
||||
manager_inst->appendPresentView(dynamic_cast<ViewBase*>(b));
|
||||
this->split_member = std::make_pair(a, b);
|
||||
|
||||
this->sync_status();
|
||||
}
|
||||
|
||||
QWidget *SplitPanel::widget() const { return const_cast<SplitPanel *>(this); }
|
||||
|
@ -181,8 +181,11 @@ void SplitPanel::sync_status()
|
|||
auto width_a = total_w * std::get<1>(split_info);
|
||||
auto width_b = total_w - width_a - std::get<2>(split_info);
|
||||
|
||||
this->split_member.first->setOutline(QRectF(0, 0, width_a, total_h));
|
||||
this->split_member.second->setOutline(QRectF(width_a + std::get<2>(split_info), 0, width_b, total_h));
|
||||
auto first = this->split_member.first;
|
||||
auto second = this->split_member.second;
|
||||
|
||||
first->setOutline(QRectF(0, 0, width_a, total_h));
|
||||
second->setOutline(QRectF(width_a + std::get<2>(split_info), 0, width_b, total_h));
|
||||
this->splitter_inst->setGeometry(QRect(width_a, 0, std::get<2>(split_info), total_h));
|
||||
} break;
|
||||
case SplitType::SPLIT_V_BFIRST:
|
||||
|
@ -190,8 +193,10 @@ void SplitPanel::sync_status()
|
|||
auto height_a = total_h * std::get<1>(split_info);
|
||||
auto height_b = total_h - height_a - std::get<2>(split_info);
|
||||
|
||||
split_member.first->setOutline(QRectF(0, 0, total_w, height_a));
|
||||
split_member.second->setOutline(QRectF(0, height_a + std::get<2>(split_info) - 1, total_w, height_b + 1));
|
||||
auto first = this->split_member.first;
|
||||
auto second = this->split_member.second;
|
||||
first->setOutline(QRectF(0, 0, total_w, height_a));
|
||||
second->setOutline(QRectF(0, height_a + std::get<2>(split_info) - 1, total_w, height_b + 1));
|
||||
splitter_inst->setGeometry(QRect(0, height_a, total_w, std::get<2>(split_info)));
|
||||
} break;
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
#ifndef SPLITPANEL
|
||||
#define SPLITPANEL
|
||||
|
||||
#include "splitwindow.h"
|
||||
#include "SplitWindow.h"
|
||||
|
||||
#include <QFrame>
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
#include "splitwindow.h"
|
||||
#include "dockpanel.h"
|
||||
#include "splitpanel.h"
|
||||
#include "SplitWindow.h"
|
||||
#include "DockPanel.h"
|
||||
#include "SplitPanel.h"
|
||||
#include <QApplication>
|
||||
#include <QDebug>
|
||||
#include <QDrag>
|
||||
|
@ -17,9 +17,7 @@
|
|||
using namespace split_window;
|
||||
using namespace split_frame;
|
||||
|
||||
|
||||
SplitWindow::SplitWindow(QWidget *parent) : QMainWindow(parent), view_root(nullptr), accept_port(new accept_panel::AcceptPanel(this, this)) {
|
||||
this->view_root = nullptr;
|
||||
SplitWindow::SplitWindow(QWidget *parent) : QMainWindow(parent), accept_port(new accept_panel::AcceptPanel(this, this)), view_root(nullptr) {
|
||||
accept_port->setVisible(false);
|
||||
}
|
||||
|
||||
|
@ -33,11 +31,14 @@ void SplitWindow::tempShow(split_frame::DockType t, split_frame::ViewBase *targe
|
|||
|
||||
void SplitWindow::setPresentTarget(split_frame::ViewRes *inst)
|
||||
{
|
||||
if(inst){
|
||||
if(inst && this->view_root != inst){
|
||||
this->takeCentralWidget();
|
||||
this->view_root = nullptr;
|
||||
|
||||
inst->setParentRes(nullptr);
|
||||
inst->widget()->setParent(this);
|
||||
this->setCentralWidget(inst->widget());
|
||||
}
|
||||
else{
|
||||
} else if (!inst) {
|
||||
this->takeCentralWidget();
|
||||
}
|
||||
|
||||
|
@ -129,18 +130,24 @@ void SplitWindow::doRetrieve(split_frame::ViewBase *inst)
|
|||
inst->setParentRes(nullptr);
|
||||
}
|
||||
else if(inst->parentRes() == view_root){
|
||||
auto pinst_root = inst->parentRes();
|
||||
auto pinst = inst->parentRes();
|
||||
|
||||
auto remains = pinst_root->except(inst);
|
||||
auto remains = pinst->except(inst);
|
||||
inst->setParentRes(nullptr);
|
||||
remains.first->setParentRes(nullptr);
|
||||
|
||||
auto awidget = inst->widget()->parent();
|
||||
auto cwidget = inst->widget()->parentWidget();
|
||||
auto bwidget = inst->widget()->parent();
|
||||
|
||||
setPresentTarget(remains.first);
|
||||
delete pinst_root;
|
||||
delete pinst;
|
||||
}
|
||||
else if(inst->parentRes()){
|
||||
auto pinst = inst->parentRes();
|
||||
|
||||
auto remains = pinst->except(inst);
|
||||
remains.first->setParentRes(nullptr);
|
||||
inst->setParentRes(nullptr);
|
||||
|
||||
auto ppinst = pinst->parentRes();
|
||||
|
@ -166,7 +173,6 @@ void SplitWindow::doClose(split_frame::ViewBase *inst)
|
|||
for(auto &lsn : listener_list)
|
||||
lsn->aboutToBeDelete(inst);
|
||||
|
||||
removePresentView(inst);
|
||||
delete inst;
|
||||
}
|
||||
|
||||
|
@ -181,7 +187,15 @@ void SplitWindow::siblingAttach(ViewBase *view, ViewBase *pos, SplitType ori)
|
|||
|
||||
auto remains_frm = pos->parentRes();
|
||||
auto split_slot = new split_panel::SplitPanel(this, ori);
|
||||
remains_frm->replaceView(split_slot, pos);
|
||||
if(pos == view_root){
|
||||
setPresentTarget(split_slot);
|
||||
}
|
||||
else{
|
||||
if(!remains_frm)
|
||||
throw new Config::SimpleException<QString>("参数错误", "指定吸附视图父引用为空");
|
||||
|
||||
remains_frm->replaceView(split_slot, pos);
|
||||
}
|
||||
|
||||
switch (ori) {
|
||||
case SplitType::SPLIT_H_LFIRST:
|
|
@ -1,8 +1,8 @@
|
|||
#ifndef SPLITWINDOW_H
|
||||
#define SPLITWINDOW_H
|
||||
|
||||
#include "splitview_interface.h"
|
||||
#include "acceptpanel.h"
|
||||
#include "libSplitView.h"
|
||||
#include "AcceptPanel.h"
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <QWidget>
|
||||
|
@ -40,8 +40,7 @@ namespace split_window {
|
|||
|
||||
|
||||
/**
|
||||
* @brief 设置指定视图为根视图或者取消
|
||||
* @param inst
|
||||
* @brief 璁剧疆鎸囧畾瑙嗗浘涓烘牴瑙嗗浘鎴栬€呭彇娑 * @param inst
|
||||
*/
|
||||
void setPresentTarget(split_frame::ViewRes *inst = nullptr);
|
||||
|
|
@ -1,15 +1,9 @@
|
|||
#ifndef SPLITVIEW_INTERFACE_H
|
||||
#define SPLITVIEW_INTERFACE_H
|
||||
|
||||
#include <QtCore/qglobal.h>
|
||||
|
||||
#if defined(SPLITVIEW_LIBRARY)
|
||||
# define SPLITVIEW_EXPORT Q_DECL_EXPORT
|
||||
#else
|
||||
# define SPLITVIEW_EXPORT Q_DECL_IMPORT
|
||||
#endif
|
||||
#ifndef LIBSPLITVIEW_H
|
||||
#define LIBSPLITVIEW_H
|
||||
|
||||
#include "libSplitView_Global.h"
|
||||
#include <QWidget>
|
||||
#include <QSizeF>
|
||||
|
||||
namespace split_frame {
|
||||
class SplitView;
|
||||
|
@ -128,16 +122,14 @@ namespace split_frame {
|
|||
virtual ~SplitView() = default;
|
||||
|
||||
/**
|
||||
* @brief 载入视图成员,构建父子引用关系
|
||||
* @brief 载入视图成员
|
||||
* @param a 成员视图a
|
||||
* @param b 成员视图b
|
||||
*/
|
||||
virtual void initViews(ViewRes *a, ViewRes *b) = 0;
|
||||
|
||||
/**
|
||||
* @brief 使用新视图替换指定视图,重构呈现树
|
||||
* @param view 实例需要属于闲置视图,调用完成被重建父子引用
|
||||
* @param pos 实例属于呈现树,调用完成将被解除父子引用
|
||||
* @brief 浣跨敤鏂拌鍥炬浛鎹㈡寚瀹氳鍥撅紝閲嶆瀯鍛堢幇鏍 * @param view 瀹炰緥闇€瑕佸睘浜庨棽缃鍥撅紝璋冪敤瀹屾垚琚噸寤虹埗瀛愬紩鐢 * @param pos 瀹炰緥灞炰簬鍛堢幇鏍戯紝璋冪敤瀹屾垚灏嗚瑙i櫎鐖跺瓙寮曠敤
|
||||
*/
|
||||
virtual void replaceView(ViewRes *_new, ViewRes *_old) = 0;
|
||||
|
||||
|
@ -232,31 +224,29 @@ namespace split_frame {
|
|||
virtual void appendPresentView(ViewBase *inst) = 0;
|
||||
|
||||
/**
|
||||
* @brief 测试指定视图是否处于呈现状态
|
||||
* @param inst 指定视图
|
||||
* @brief 回收视图显示,转换视图为自由(闲置)状态
|
||||
* @param inst
|
||||
*/
|
||||
virtual bool isPresented(ViewBase *inst) const = 0;
|
||||
|
||||
/**
|
||||
* @brief 回收视图显示,转换视图为自由(闲置)状态
|
||||
* @param inst 视图实例需要确实处于可视状态(临时显示或位于呈现树内)
|
||||
* @brief 鍥炴敹瑙嗗浘鏄剧ず锛岃浆鎹㈣鍥句负鑷敱锛堥棽缃級鐘舵€ * @param inst 瑙嗗浘瀹炰緥闇€瑕佺‘瀹炲浜庡彲瑙嗙姸鎬侊紙涓存椂鏄剧ず鎴栦綅浜庡憟鐜版爲鍐咃級
|
||||
*/
|
||||
virtual void doRetrieve(ViewBase *inst) = 0;
|
||||
|
||||
/**
|
||||
* @brief 回收视图,清除内存实例
|
||||
* @param inst 视图实例需要处于闲置状态
|
||||
*/
|
||||
virtual void doClose(ViewBase *inst) = 0;
|
||||
|
||||
/**
|
||||
* @brief 使用指定视图合并显示
|
||||
* @param view 需要合并的闲置视图
|
||||
* @param pos 指定合并目标位置
|
||||
* @brief 替换指定视图
|
||||
* @param view
|
||||
* @param old
|
||||
*/
|
||||
virtual void siblingAttach(ViewBase *view, ViewBase *pos, SplitType ori) = 0;
|
||||
};
|
||||
|
||||
} // namespace SplitFrame
|
||||
|
||||
#endif // SPLITVIEW_INTERFACE_H
|
||||
#endif // LIBSPLITVIEW_H
|
|
@ -15,17 +15,18 @@ msvc{
|
|||
}
|
||||
|
||||
SOURCES += \
|
||||
acceptpanel.cpp \
|
||||
dockpanel.cpp \
|
||||
splitpanel.cpp \
|
||||
splitwindow.cpp
|
||||
AcceptPanel.cpp \
|
||||
DockPanel.cpp \
|
||||
SplitPanel.cpp \
|
||||
SplitWindow.cpp
|
||||
|
||||
HEADERS += \
|
||||
acceptpanel.h \
|
||||
dockpanel.h \
|
||||
splitpanel.h \
|
||||
splitview_interface.h \
|
||||
splitwindow.h
|
||||
AcceptPanel.h \
|
||||
DockPanel.h \
|
||||
SplitPanel.h \
|
||||
SplitWindow.h \
|
||||
libSplitView.h \
|
||||
libSplitView_Global.h
|
||||
|
||||
# Default rules for deployment.
|
||||
unix {
|
||||
|
|
|
@ -10,23 +10,23 @@
|
|||
#include <QStackedWidget>
|
||||
#include <QStyle>
|
||||
#include <QToolBar>
|
||||
#include <dockpanel.h>
|
||||
#include <splitwindow.h>
|
||||
#include <splitpanel.h>
|
||||
#include <dockpanel.h>
|
||||
#include <DockPanel.h>
|
||||
#include <SplitWindow.h>
|
||||
#include <SplitPanel.h>
|
||||
#include <DockPanel.h>
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
QApplication a(argc, argv);
|
||||
|
||||
split_window::SplitWindow w;
|
||||
auto spb = new split_panel::SplitPanel(&w, split_frame::SplitType::SPLIT_H_LFIRST);
|
||||
auto bview = new dock_panel::DockableView(&w, new QWidget, true);
|
||||
auto dview = new dock_panel::DockableView(&w, new QWidget, true);
|
||||
auto w = new split_window::SplitWindow;
|
||||
auto spb = new split_panel::SplitPanel(w, split_frame::SplitType::SPLIT_H_LFIRST);
|
||||
auto bview = new dock_panel::DockableView(w, new QWidget, true);
|
||||
auto dview = new dock_panel::DockableView(w, new QWidget, true);
|
||||
spb->initViews(bview, dview);
|
||||
|
||||
w.setPresentTarget(spb);
|
||||
a.installEventFilter(&w);
|
||||
w->setPresentTarget(spb);
|
||||
a.installEventFilter(w);
|
||||
|
||||
w.show();
|
||||
w->show();
|
||||
return a.exec();
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
#include <QString>
|
||||
#include <QWidget>
|
||||
#include <splitwindow.h>
|
||||
#include <SplitWindow.h>
|
||||
|
||||
|
||||
#endif // UNNNN_H
|
||||
|
|
Loading…
Reference in New Issue