Compare commits

...

5 Commits

10 changed files with 160 additions and 37 deletions

View File

@ -130,11 +130,19 @@ void accept_panel::AcceptPanel::dropEvent(QDropEvent *ev)
view_manager->doRetrieve(view);
view_manager->siblingAttach(view, anchor_view, SplitType::SPLIT_V_BFIRST);
break;
case HoverType::CUBE_CENTER:
case HoverType::CUBE_CENTER: {
view_manager->doRetrieve(view);
anchor_view->parentRes()->replaceView(view, anchor_view);
view_manager->doRetrieve(anchor_view);
break;
auto pinst = anchor_view->parentRes();
if(pinst){
pinst->replaceView(view, anchor_view);
view_manager->doRetrieve(anchor_view);
dynamic_cast<split_window::SplitWindow*>(view_manager)->freedomHasBeenRemoved(view);
}else{
view_manager->doRetrieve(anchor_view);
dynamic_cast<split_window::SplitWindow*>(view_manager)->setPresentTarget(view);
}
view->setVisible(true);
} break;
default:
break;
}

View File

@ -13,6 +13,7 @@ using namespace dock_panel;
DragHeader::DragHeader(const QString &title, DockableView *bind_core)
: QFrame(bind_core),
bind_core(bind_core),
icon_holder(new QLabel(this)),
title_holder(new QLabel(this)),
close_btn(new QPushButton("x",this)),
minimal_btn(new QPushButton("-",this)) {
@ -22,6 +23,9 @@ DragHeader::DragHeader(const QString &title, DockableView *bind_core)
layout->setSpacing(0);
layout->setContentsMargins(0, 0, 0, 0);
icon_holder->setPixmap(QIcon(":/icons/headertop/story.png").pixmap(22,22));
layout->addWidget(icon_holder, 0, Qt::AlignLeft);
title_holder->setText(title);
title_holder->setContentsMargins(2,0, 0, 0);
layout->addWidget(title_holder, 1, Qt::AlignLeft);
@ -51,7 +55,7 @@ void DragHeader::setTitle(const QString &title)
void DragHeader::setTitle(const QString &title, const QIcon &icon)
{
this->setTitle(title);
this->title_holder->setPixmap(icon.pixmap(22, 22));
this->icon_holder->setPixmap(icon.pixmap(22, 22));
}
void DragHeader::optConfig(bool retrieve, bool close)
@ -104,6 +108,9 @@ DockableView::DockableView(split_frame::ResManager *mgr, QWidget *present)
layout->addWidget(new QWidget(this));
}
this->icon_store = QIcon(":/icons/headertop/story.png");
title_header->setTitle("未命名", icon_store);
layout->setSpacing(0);
layout->setContentsMargins(0, 2, 0, 0);
@ -117,11 +124,12 @@ DockableView::DockableView(split_frame::ResManager *mgr, QWidget *present)
connect(this->title_header, &DragHeader::retrieveRequest, this, &DockableView::retrieveAccept);
connect(this->title_header, &DragHeader::closeRequest, this, &DockableView::closeAccept);
connect(this->title_header, &DragHeader::adjustRequest, this, &DockableView::adjustAccept);
viewConfig(m_replace, m_close, m_retrieve);
}
DockableView::~DockableView() {
manager_inst->removePresentView(this);
qDebug() << "view-deleted";
}
void DockableView::viewConfig(bool replace, bool close, bool retrieve)

View File

@ -18,6 +18,7 @@ namespace dock_panel {
Q_OBJECT
private:
DockableView *const bind_core;
QLabel *const icon_holder;
QLabel *const title_holder;
QPushButton *const close_btn, *const minimal_btn;
std::tuple<bool, QPointF> press_flag = std::make_tuple(false, QPointF());
@ -56,7 +57,7 @@ namespace dock_panel {
/**
* @brief
*/
class SPLITVIEW_EXPORT DockableView : public QWidget, public split_frame::ViewBase {
class SPLITVIEW_EXPORT DockableView : public QFrame, public split_frame::ViewBase {
public:
/**
* @brief
@ -65,13 +66,7 @@ namespace dock_panel {
*/
DockableView(split_frame::ResManager*mgr, QWidget *present);
virtual ~DockableView();
/**
* @brief
* @param replace
* @param close
* @param retrieve
*/
void viewConfig(bool replace, bool close, bool retrieve);
/**
* @brief
@ -91,7 +86,7 @@ namespace dock_panel {
split_frame::ResManager *const manager_inst;
QIcon icon_store;
split_frame::SplitView *parent_res = nullptr;
bool m_replace = false, m_retrieve = false, m_close = false;
bool m_replace = true, m_retrieve = true, m_close = true;
// ViewRes interface
public:
@ -108,6 +103,7 @@ namespace dock_panel {
// ViewBase interface
public:
virtual void viewConfig(bool replace, bool close, bool retrieve) override;
virtual QIcon icon() const override;
virtual QString title() const override;
virtual bool canRetrieve() const override;

View File

@ -9,7 +9,7 @@ using namespace Config;
DragSplitter::DragSplitter(split_frame::SplitType split, split_frame::ViewRes *parent)
: QFrame(parent->widget()){
this->setFrameShape(QFrame::Shape::WinPanel);
this->setFrameShape(QFrame::Shape::StyledPanel);
this->setFrameShadow(QFrame::Shadow::Raised);
switch (split) {
@ -185,7 +185,7 @@ void SplitPanel::sync_status()
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));
second->setOutline(QRectF(width_a + std::get<2>(split_info) - 1, 0, width_b + 1, total_h));
this->splitter_inst->setGeometry(QRect(width_a, 0, std::get<2>(split_info), total_h));
} break;
case SplitType::SPLIT_V_BFIRST:

View File

@ -25,14 +25,49 @@ SplitWindow::SplitWindow(QWidget *parent)
view_root(nullptr) {
accept_port->setVisible(false);
this->addToolBar(Qt::ToolBarArea::LeftToolBarArea, unused_stack);
unused_stack->setMovable(false);
this->addListener(this);
}
SplitWindow::~SplitWindow() {this->active = false;}
void SplitWindow::tempShow(split_frame::DockType t, split_frame::ViewBase *target)
void SplitWindow::tempShow(split_frame::ViewBase *target)
{
this->temp_show = target;
target->setVisible(true);
if(target){
this->temp_show = target;
auto current_center = centralWidget();
if(!current_center){
this->setCentralWidget(temp_show->widget());
freedomHasBeenRemoved(target);
appendPresentView(target);
view_root = target;
}
else{
auto twidget = this->centralWidget();
this->temp_show->widget()->setParent(twidget);
this->temp_show->widget()->setGeometry(0, 0, twidget->width()/3, twidget->height());
}
target->setVisible(true);
}
else if(temp_show){
this->temp_show->widget()->setParent(nullptr);
this->temp_show->setVisible(false);
this->temp_show = nullptr;
}
}
void SplitWindow::freedomHasBeenRemoved(split_frame::ViewBase *inst)
{
for(auto &it : listener_list)
it->freedomRemove(inst);
}
void SplitWindow::freedomHasBeenAppended(split_frame::ViewBase *inst)
{
for(auto &it : listener_list)
it->freedomAppend(inst);
}
void SplitWindow::setPresentTarget(split_frame::ViewRes *inst)
@ -44,6 +79,8 @@ void SplitWindow::setPresentTarget(split_frame::ViewRes *inst)
inst->setParentRes(nullptr);
inst->widget()->setParent(this);
this->setCentralWidget(inst->widget());
appendPresentView(dynamic_cast<ViewBase*>(inst));
freedomHasBeenRemoved(dynamic_cast<ViewBase*>(inst));
} else if (!inst) {
this->takeCentralWidget();
}
@ -103,8 +140,13 @@ void SplitWindow::removeListener(split_frame::FreedomViewsListener *lsn)
void SplitWindow::appendPresentView(split_frame::ViewBase *inst)
{
if(this->active && inst)
if(this->active && inst){
if(!isPresented(inst)){
freedomHasBeenRemoved(inst);
}
this->presents_store[inst->hashCode()] = inst;
}
}
void SplitWindow::removePresentView(split_frame::ViewBase *inst)
@ -123,15 +165,14 @@ bool SplitWindow::isPresented(split_frame::ViewBase *inst) const
void SplitWindow::doRetrieve(split_frame::ViewBase *inst)
{
if(!isPresented(inst)){
throw new Config::SimpleException<QString>("参数错误", "无法回收空闲视图!");
if(inst == temp_show){
temp_show->setVisible(false);
}
return;
}
// 呈现视图结构调整
if(inst == temp_show){
temp_show->setVisible(false);
return;
}
else if (inst == view_root) {
if (inst == view_root) {
setPresentTarget();
inst->setParentRes(nullptr);
}
@ -162,8 +203,7 @@ void SplitWindow::doRetrieve(split_frame::ViewBase *inst)
removePresentView(inst);
// 当前视图已被回收
for(auto &lsn : listener_list)
lsn->freedomAppend(inst);
freedomHasBeenAppended(inst);
}
void SplitWindow::doClose(split_frame::ViewBase *inst)
@ -218,8 +258,7 @@ void SplitWindow::siblingAttach(ViewBase *view, ViewBase *pos, SplitType ori)
break;
}
for(auto &lsn : listener_list)
lsn->freedomRemove(view);
freedomHasBeenRemoved(view);
}
ViewBase *SplitWindow::adjustView() const
@ -231,3 +270,49 @@ void SplitWindow::setAdjustView(split_frame::ViewBase *target)
{
this->adjust_target = target;
}
void SplitWindow::freedomAppend(split_frame::ViewBase *ins)
{
if(ins && !freedom_records.contains(ins->hashCode())){
freedom_records[ins->hashCode()]=std::make_tuple(ins, ins->canReplace(), ins->canClose(), ins->canRetrieve());
ins->viewConfig(false, false, false);
auto act = this->unused_stack->addAction(ins->title(), [this, ins](bool state) {
if (state) {
this->tempShow(ins);
} else {
this->tempShow(nullptr);
}
});
act->setData(ins->hashCode());
act->setIcon(ins->icon());
act->setCheckable(true);
}
}
void SplitWindow::freedomRemove(split_frame::ViewBase *ins)
{
if (ins && freedom_records.contains(ins->hashCode())) {
auto allacts = unused_stack->actions();
for (auto &act : allacts) {
if (act->data().toULongLong() == ins->hashCode()) {
unused_stack->removeAction(act);
break;
}
}
auto record = freedom_records[ins->hashCode()];
ins->viewConfig(std::get<1>(record), std::get<2>(record), std::get<3>(record));
freedom_records.remove(ins->hashCode());
}
}
void SplitWindow::aboutToBeDelete(split_frame::ViewBase *inst)
{
this->freedomRemove(inst);
}
void SplitWindow::hasBeenAppend(split_frame::ViewBase *inst)
{
}

View File

@ -14,10 +14,7 @@ namespace split_window {
/**
* @brief
*/
class SPLITVIEW_EXPORT SplitWindow : public QMainWindow, public split_frame::ResManager {
typedef float pos;
typedef float width;
class SPLITVIEW_EXPORT SplitWindow : public QMainWindow, public split_frame::ResManager, public split_frame::FreedomViewsListener {
private:
bool active = false;
QToolBar *const unused_stack;
@ -28,6 +25,9 @@ namespace split_window {
split_frame::ViewRes *view_root = nullptr, *temp_show = nullptr;
split_frame::ViewBase *adjust_target = nullptr;
// freedom-recordstuple<IDtuple<ptr,replace,close,retrieve>>
QHash<qulonglong, std::tuple<split_frame::ViewBase*, bool, bool, bool>> freedom_records;
public:
SplitWindow(QWidget *parent = nullptr);
@ -39,8 +39,10 @@ namespace split_window {
* @param t
* @param target
*/
void tempShow(split_frame::DockType t, split_frame::ViewBase *target);
void tempShow(split_frame::ViewBase *target);
void freedomHasBeenRemoved(split_frame::ViewBase *inst);
void freedomHasBeenAppended(split_frame::ViewBase *inst);
/**
* @brief * @param inst
@ -61,6 +63,13 @@ namespace split_window {
virtual void siblingAttach(split_frame::ViewBase *view, split_frame::ViewBase *pos, split_frame::SplitType ori) override;
virtual split_frame::ViewBase *adjustView() const override;
virtual void setAdjustView(split_frame::ViewBase *target) override;
// FreedomViewsListener interface
public:
virtual void freedomAppend(split_frame::ViewBase *ins) override;
virtual void freedomRemove(split_frame::ViewBase *ins) override;
virtual void aboutToBeDelete(split_frame::ViewBase *inst) override;
virtual void hasBeenAppend(split_frame::ViewBase *inst) override;
};
} // namespace split_panel

View File

@ -0,0 +1,5 @@
<RCC>
<qresource prefix="/icons/headertop">
<file>story.png</file>
</qresource>
</RCC>

View File

@ -86,6 +86,13 @@ namespace split_frame {
public:
virtual ~ViewBase() = default;
/**
* @brief
* @param replace
* @param close
* @param retrieve
*/
virtual void viewConfig(bool replace, bool close, bool retrieve) = 0;
/**
* @brief
* @return
@ -129,7 +136,9 @@ namespace split_frame {
virtual void initViews(ViewRes *a, ViewRes *b) = 0;
/**
* @brief * @param view * @param pos
* @brief
* @param view
* @param pos
*/
virtual void replaceView(ViewRes *_new, ViewRes *_old) = 0;

View File

@ -40,3 +40,6 @@ else:unix: LIBS += -L$$OUT_PWD/../libConfig/ -llibConfig
INCLUDEPATH += $$PWD/../libConfig
DEPENDPATH += $$PWD/../libConfig
RESOURCES += \
defaulticon.qrc

BIN
libSplitView/story.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB