视图展示和拖动开发中
This commit is contained in:
parent
d66fa76b0f
commit
891a4de933
|
@ -3,7 +3,7 @@ TEMPLATE = subdirs
|
|||
SUBDIRS += \
|
||||
libGenericConsole \
|
||||
libSplitView \
|
||||
WordsIDE \
|
||||
# WordsIDE \
|
||||
libConfig \
|
||||
libProjectManager \
|
||||
# libTextEdit \
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE QtCreatorProject>
|
||||
<!-- Written by QtCreator 4.15.0, 2024-01-27T09:48:04. -->
|
||||
<!-- Written by QtCreator 4.15.0, 2024-02-07T16:25:47. -->
|
||||
<qtcreator>
|
||||
<data>
|
||||
<variable>EnvironmentId</variable>
|
||||
|
@ -94,16 +94,16 @@
|
|||
<variable>ProjectExplorer.Project.Target.0</variable>
|
||||
<valuemap type="QVariantMap">
|
||||
<value type="QString" key="DeviceType">Desktop</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Desktop Qt 5.12.11 MinGW 64-bit</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Desktop Qt 5.12.11 MinGW 64-bit</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">qt.qt5.51211.win64_mingw73_kit</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Desktop Qt 5.12.11 MSVC2017 64bit</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Desktop Qt 5.12.11 MSVC2017 64bit</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">qt.qt5.51211.win64_msvc2017_64_kit</value>
|
||||
<value type="int" key="ProjectExplorer.Target.ActiveBuildConfiguration">0</value>
|
||||
<value type="int" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value>
|
||||
<value type="int" key="ProjectExplorer.Target.ActiveRunConfiguration">1</value>
|
||||
<value type="int" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value>
|
||||
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0">
|
||||
<value type="int" key="EnableQmlDebugging">0</value>
|
||||
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">D:\Projects\Cpp\build-QtNovelDesc-Desktop_Qt_5_12_11_MinGW_64_bit-Debug</value>
|
||||
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory.shadowDir">D:/Projects/Cpp/build-QtNovelDesc-Desktop_Qt_5_12_11_MinGW_64_bit-Debug</value>
|
||||
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">D:\Projects\Cpp\build-QtNovelDesc-Desktop_Qt_5_12_11_MSVC2017_64bit-Debug</value>
|
||||
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory.shadowDir">D:/Projects/Cpp/build-QtNovelDesc-Desktop_Qt_5_12_11_MSVC2017_64bit-Debug</value>
|
||||
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
|
||||
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
|
||||
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
|
||||
|
@ -140,8 +140,8 @@
|
|||
<value type="int" key="Qt4ProjectManager.Qt4BuildConfiguration.BuildConfiguration">2</value>
|
||||
</valuemap>
|
||||
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.1">
|
||||
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">D:\Projects\Cpp\build-QtNovelDesc-Desktop_Qt_5_12_11_MinGW_64_bit-Release</value>
|
||||
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory.shadowDir">D:/Projects/Cpp/build-QtNovelDesc-Desktop_Qt_5_12_11_MinGW_64_bit-Release</value>
|
||||
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">D:\Projects\Cpp\build-QtNovelDesc-Desktop_Qt_5_12_11_MSVC2017_64bit-Release</value>
|
||||
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory.shadowDir">D:/Projects/Cpp/build-QtNovelDesc-Desktop_Qt_5_12_11_MSVC2017_64bit-Release</value>
|
||||
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
|
||||
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
|
||||
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
|
||||
|
@ -180,8 +180,8 @@
|
|||
</valuemap>
|
||||
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.2">
|
||||
<value type="int" key="EnableQmlDebugging">0</value>
|
||||
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">D:\Projects\Cpp\build-QtNovelDesc-Desktop_Qt_5_12_11_MinGW_64_bit-Profile</value>
|
||||
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory.shadowDir">D:/Projects/Cpp/build-QtNovelDesc-Desktop_Qt_5_12_11_MinGW_64_bit-Profile</value>
|
||||
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">D:\Projects\Cpp\build-QtNovelDesc-Desktop_Qt_5_12_11_MSVC2017_64bit-Profile</value>
|
||||
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory.shadowDir">D:/Projects/Cpp/build-QtNovelDesc-Desktop_Qt_5_12_11_MSVC2017_64bit-Profile</value>
|
||||
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
|
||||
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
|
||||
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
|
||||
|
@ -304,82 +304,9 @@
|
|||
<value type="bool" key="RunConfiguration.UseLibrarySearchPath">true</value>
|
||||
<value type="bool" key="RunConfiguration.UseQmlDebugger">false</value>
|
||||
<value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
|
||||
<value type="QString" key="RunConfiguration.WorkingDirectory.default">D:/Projects/Cpp/build-QtNovelDesc-Desktop_Qt_5_12_11_MinGW_64_bit-Debug/u_test</value>
|
||||
<value type="QString" key="RunConfiguration.WorkingDirectory.default">D:/Projects/Cpp/build-QtNovelDesc-Desktop_Qt_5_12_11_MSVC2017_64bit-Debug/u_test</value>
|
||||
</valuemap>
|
||||
<valuemap type="QVariantMap" key="ProjectExplorer.Target.RunConfiguration.1">
|
||||
<value type="QString" key="Analyzer.Perf.CallgraphMode">dwarf</value>
|
||||
<valuelist type="QVariantList" key="Analyzer.Perf.Events">
|
||||
<value type="QString">cpu-cycles</value>
|
||||
</valuelist>
|
||||
<valuelist type="QVariantList" key="Analyzer.Perf.ExtraArguments"/>
|
||||
<value type="int" key="Analyzer.Perf.Frequency">250</value>
|
||||
<valuelist type="QVariantList" key="Analyzer.Perf.RecordArguments">
|
||||
<value type="QString">-e</value>
|
||||
<value type="QString">cpu-cycles</value>
|
||||
<value type="QString">--call-graph</value>
|
||||
<value type="QString">dwarf,4096</value>
|
||||
<value type="QString">-F</value>
|
||||
<value type="QString">250</value>
|
||||
</valuelist>
|
||||
<value type="QString" key="Analyzer.Perf.SampleMode">-F</value>
|
||||
<value type="bool" key="Analyzer.Perf.Settings.UseGlobalSettings">true</value>
|
||||
<value type="int" key="Analyzer.Perf.StackSize">4096</value>
|
||||
<value type="bool" key="Analyzer.QmlProfiler.AggregateTraces">false</value>
|
||||
<value type="bool" key="Analyzer.QmlProfiler.FlushEnabled">false</value>
|
||||
<value type="uint" key="Analyzer.QmlProfiler.FlushInterval">1000</value>
|
||||
<value type="QString" key="Analyzer.QmlProfiler.LastTraceFile"></value>
|
||||
<value type="bool" key="Analyzer.QmlProfiler.Settings.UseGlobalSettings">true</value>
|
||||
<valuelist type="QVariantList" key="Analyzer.Valgrind.AddedSuppressionFiles"/>
|
||||
<value type="QString" key="Analyzer.Valgrind.Callgrind.Arguments"></value>
|
||||
<value type="bool" key="Analyzer.Valgrind.Callgrind.CollectBusEvents">false</value>
|
||||
<value type="bool" key="Analyzer.Valgrind.Callgrind.CollectSystime">false</value>
|
||||
<value type="bool" key="Analyzer.Valgrind.Callgrind.EnableBranchSim">false</value>
|
||||
<value type="bool" key="Analyzer.Valgrind.Callgrind.EnableCacheSim">false</value>
|
||||
<value type="bool" key="Analyzer.Valgrind.Callgrind.EnableEventToolTips">true</value>
|
||||
<value type="double" key="Analyzer.Valgrind.Callgrind.MinimumCostRatio">0.01</value>
|
||||
<value type="double" key="Analyzer.Valgrind.Callgrind.VisualisationMinimumCostRatio">10</value>
|
||||
<value type="bool" key="Analyzer.Valgrind.FilterExternalIssues">true</value>
|
||||
<value type="QString" key="Analyzer.Valgrind.KCachegrindExecutable">kcachegrind</value>
|
||||
<value type="int" key="Analyzer.Valgrind.LeakCheckOnFinish">1</value>
|
||||
<value type="QString" key="Analyzer.Valgrind.Memcheck.Arguments"></value>
|
||||
<value type="int" key="Analyzer.Valgrind.NumCallers">25</value>
|
||||
<valuelist type="QVariantList" key="Analyzer.Valgrind.RemovedSuppressionFiles"/>
|
||||
<value type="int" key="Analyzer.Valgrind.SelfModifyingCodeDetection">1</value>
|
||||
<value type="bool" key="Analyzer.Valgrind.Settings.UseGlobalSettings">true</value>
|
||||
<value type="bool" key="Analyzer.Valgrind.ShowReachable">false</value>
|
||||
<value type="bool" key="Analyzer.Valgrind.TrackOrigins">true</value>
|
||||
<value type="QString" key="Analyzer.Valgrind.ValgrindArguments"></value>
|
||||
<value type="QString" key="Analyzer.Valgrind.ValgrindExecutable">valgrind</value>
|
||||
<valuelist type="QVariantList" key="Analyzer.Valgrind.VisibleErrorKinds">
|
||||
<value type="int">0</value>
|
||||
<value type="int">1</value>
|
||||
<value type="int">2</value>
|
||||
<value type="int">3</value>
|
||||
<value type="int">4</value>
|
||||
<value type="int">5</value>
|
||||
<value type="int">6</value>
|
||||
<value type="int">7</value>
|
||||
<value type="int">8</value>
|
||||
<value type="int">9</value>
|
||||
<value type="int">10</value>
|
||||
<value type="int">11</value>
|
||||
<value type="int">12</value>
|
||||
<value type="int">13</value>
|
||||
<value type="int">14</value>
|
||||
</valuelist>
|
||||
<valuelist type="QVariantList" key="CustomOutputParsers"/>
|
||||
<value type="int" key="PE.EnvironmentAspect.Base">2</value>
|
||||
<valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4RunConfiguration:D:/Projects/Cpp/QtNovelDesc/WordsIDE/WordsIDE.pro</value>
|
||||
<value type="QString" key="ProjectExplorer.RunConfiguration.BuildKey">D:/Projects/Cpp/QtNovelDesc/WordsIDE/WordsIDE.pro</value>
|
||||
<value type="bool" key="RunConfiguration.UseCppDebugger">false</value>
|
||||
<value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value>
|
||||
<value type="bool" key="RunConfiguration.UseLibrarySearchPath">true</value>
|
||||
<value type="bool" key="RunConfiguration.UseQmlDebugger">false</value>
|
||||
<value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
|
||||
<value type="QString" key="RunConfiguration.WorkingDirectory.default">D:/Projects/Cpp/build-QtNovelDesc-Desktop_Qt_5_12_11_MinGW_64_bit-Debug/WordsIDE</value>
|
||||
</valuemap>
|
||||
<value type="int" key="ProjectExplorer.Target.RunConfigurationCount">2</value>
|
||||
<value type="int" key="ProjectExplorer.Target.RunConfigurationCount">1</value>
|
||||
</valuemap>
|
||||
</data>
|
||||
<data>
|
||||
|
|
|
@ -0,0 +1,153 @@
|
|||
#include "acceptpanel.h"
|
||||
|
||||
#include <QDragMoveEvent>
|
||||
#include <QPainter>
|
||||
|
||||
|
||||
using namespace split_frame;
|
||||
|
||||
accept_panel::AcceptPanel::AcceptPanel(QMainWindow *win, split_frame::ResManager *mgr)
|
||||
: QWidget(nullptr), bind_win(win), view_manager(mgr) {
|
||||
this->setMouseTracking(true);
|
||||
this->setAcceptDrops(true);
|
||||
}
|
||||
|
||||
void accept_panel::AcceptPanel::bindWith(split_frame::ViewBase *target)
|
||||
{
|
||||
this->setParent(target->widget());
|
||||
this->anchor_view = target;
|
||||
this->paint_panel = this->anchor_view->widget()->grab();
|
||||
this->setGeometry(QRect(QPoint(), target->widget()->size()));
|
||||
}
|
||||
|
||||
void accept_panel::AcceptPanel::resizeEvent(QResizeEvent *ev)
|
||||
{
|
||||
QWidget::resizeEvent(ev);
|
||||
|
||||
auto render_width = this->width() / 3;
|
||||
auto render_height = this->height() / 3;
|
||||
this->cube_center = QRectF(render_width, render_height, render_width, render_height) - QMargins(15, 15, 15, 15);
|
||||
this->cube_left = QRectF(0, render_height, render_width, render_height) - QMargins(15, 15, 15, 15);
|
||||
this->cube_right = QRectF(this->width() - render_width, render_height, render_width, render_height) - QMargins(15, 15, 15, 15);
|
||||
this->cube_top = QRectF(render_width, 0, render_width, render_height) - QMargins(15, 15, 15, 15);
|
||||
this->cube_bottom = QRectF(render_width, this->height() - render_height, render_width, render_height) - QMargins(15, 15, 15, 15);
|
||||
|
||||
this->target_type = HoverType::CUBE_UNDEFINED;
|
||||
}
|
||||
|
||||
void accept_panel::AcceptPanel::paintEvent(QPaintEvent *ev)
|
||||
{
|
||||
QWidget::paintEvent(ev);
|
||||
|
||||
QPainter t(this);
|
||||
t.fillRect(this->rect(), this->paint_panel);
|
||||
|
||||
|
||||
switch(this->target_type){
|
||||
case HoverType::CUBE_LEFT:
|
||||
t.fillRect(this->cube_left + QMargins(15, 15, 15, 15), Qt::gray);
|
||||
break;
|
||||
case HoverType::CUBE_RIGHT:
|
||||
t.fillRect(this->cube_right + QMargins(15, 15, 15, 15), Qt::gray);
|
||||
break;
|
||||
case HoverType::CUBE_TOP:
|
||||
t.fillRect(this->cube_top+ QMargins(15, 15, 15, 15), Qt::gray);
|
||||
break;
|
||||
case HoverType::CUBE_BOTTOM:
|
||||
t.fillRect(this->cube_bottom + QMargins(15, 15, 15, 15), Qt::gray);
|
||||
break;
|
||||
case HoverType::CUBE_CENTER:
|
||||
t.fillRect(this->cube_center + QMargins(15, 15, 15, 15), Qt::gray);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
t.fillRect(this->cube_left, Qt::green);
|
||||
t.fillRect(this->cube_right, Qt::green);
|
||||
t.fillRect(this->cube_top, Qt::green);
|
||||
t.fillRect(this->cube_bottom, Qt::green);
|
||||
t.fillRect(this->cube_center, Qt::green);
|
||||
}
|
||||
|
||||
void accept_panel::AcceptPanel::dragMoveEvent(QDragMoveEvent *ev)
|
||||
{
|
||||
QWidget::dragMoveEvent(ev);
|
||||
|
||||
if(this->cube_left.contains(ev->pos()))
|
||||
this->target_type = HoverType::CUBE_LEFT;
|
||||
else if(this->cube_right.contains(ev->pos()))
|
||||
this->target_type = HoverType::CUBE_RIGHT;
|
||||
else if(this->cube_top.contains(ev->pos()))
|
||||
this->target_type = HoverType::CUBE_TOP;
|
||||
else if(this->cube_bottom.contains(ev->pos()))
|
||||
this->target_type = HoverType::CUBE_BOTTOM;
|
||||
else if(this->cube_center.contains(ev->pos()))
|
||||
this->target_type = HoverType::CUBE_CENTER;
|
||||
else
|
||||
this->target_type = HoverType::CUBE_UNDEFINED;
|
||||
|
||||
this->update();
|
||||
}
|
||||
|
||||
void accept_panel::AcceptPanel::dragEnterEvent(QDragEnterEvent *ev)
|
||||
{
|
||||
QWidget::dragEnterEvent(ev);
|
||||
|
||||
if(view_manager->adjustView())
|
||||
ev->acceptProposedAction();
|
||||
}
|
||||
|
||||
#include "splitpanel.h"
|
||||
#include <QDebug>
|
||||
void accept_panel::AcceptPanel::dropEvent(QDropEvent *ev)
|
||||
{
|
||||
auto view = view_manager->adjustView();
|
||||
if(view){
|
||||
switch (target_type) {
|
||||
case HoverType::CUBE_LEFT:
|
||||
view_manager->doRetrieve(view);
|
||||
view_manager->siblingAttach(view, anchor_view, SplitType::SPLIT_H_LFIRST);
|
||||
break;
|
||||
case HoverType::CUBE_RIGHT:
|
||||
view_manager->doRetrieve(view);
|
||||
view_manager->siblingAttach(view, anchor_view, SplitType::SPLIT_H_RFIRST);
|
||||
break;
|
||||
case HoverType::CUBE_TOP:
|
||||
view_manager->doRetrieve(view);
|
||||
view_manager->siblingAttach(view, anchor_view, SplitType::SPLIT_V_TFIRST);
|
||||
break;
|
||||
case HoverType::CUBE_BOTTOM:
|
||||
view_manager->doRetrieve(view);
|
||||
view_manager->siblingAttach(view, anchor_view, SplitType::SPLIT_V_BFIRST);
|
||||
break;
|
||||
case HoverType::CUBE_CENTER:
|
||||
view_manager->doRetrieve(view);
|
||||
anchor_view->parentRes()->replaceView(view, anchor_view);
|
||||
view_manager->doRetrieve(anchor_view);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
view_manager->setAdjustView();
|
||||
target_type = HoverType::CUBE_UNDEFINED;
|
||||
}
|
||||
|
||||
this->setParent(bind_win);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
#ifndef ACCEPTPANEL_H
|
||||
#define ACCEPTPANEL_H
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <QWidget>
|
||||
#include "splitview_interface.h"
|
||||
|
||||
namespace accept_panel {
|
||||
enum class HoverType{
|
||||
CUBE_LEFT, CUBE_RIGHT, CUBE_TOP, CUBE_BOTTOM, CUBE_CENTER, CUBE_UNDEFINED,
|
||||
};
|
||||
|
||||
class AcceptPanel : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
AcceptPanel(QMainWindow* win, split_frame::ResManager *mgr);
|
||||
|
||||
void bindWith(split_frame::ViewBase *target);
|
||||
|
||||
protected:
|
||||
void resizeEvent(QResizeEvent *ev) override;
|
||||
void paintEvent(QPaintEvent *ev) override;
|
||||
void dragMoveEvent(QDragMoveEvent *ev) override;
|
||||
void dragEnterEvent(QDragEnterEvent *ev) override;
|
||||
void dropEvent(QDropEvent *ev) override;
|
||||
|
||||
private:
|
||||
QWidget *const bind_win;
|
||||
QRectF cube_left, cube_right, cube_top, cube_bottom, cube_center;
|
||||
split_frame::ResManager *const view_manager;
|
||||
split_frame::ViewBase *anchor_view = nullptr;
|
||||
HoverType target_type = HoverType::CUBE_UNDEFINED;
|
||||
QPixmap paint_panel;
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#endif // ACCEPTPANEL_H
|
|
@ -8,7 +8,7 @@
|
|||
#include <QMouseEvent>
|
||||
#include <QPushButton>
|
||||
|
||||
using namespace base_view;
|
||||
using namespace dock_panel;
|
||||
|
||||
DragHeader::DragHeader(const QString &title, DockableView *bind_core)
|
||||
: QFrame(bind_core),
|
||||
|
@ -91,7 +91,7 @@ DockableView::DockableView(split_frame::ResManager *mgr, QWidget *present, bool
|
|||
|
||||
auto layout = new QVBoxLayout(this);
|
||||
layout->addWidget(title_header);
|
||||
if(present_cube){\
|
||||
if(present_cube){
|
||||
layout->addWidget(present);
|
||||
}
|
||||
else {
|
||||
|
@ -106,10 +106,9 @@ DockableView::DockableView(split_frame::ResManager *mgr, QWidget *present, bool
|
|||
this->title_header->setFrameShadow(QFrame::Shadow::Raised);
|
||||
this->title_header->setLineWidth(3);
|
||||
|
||||
this->manager_inst->appendPresentView(this);
|
||||
connect(this, &QObject::destroyed, [this](){
|
||||
this->manager_inst->removePresentView(this);
|
||||
});
|
||||
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);
|
||||
}
|
||||
|
||||
void DockableView::viewConfig(bool replace, bool close, bool retrieve)
|
||||
|
@ -134,10 +133,10 @@ void DockableView::adjustAccept(const QPoint &pos)
|
|||
{
|
||||
Q_UNUSED(pos);
|
||||
|
||||
manager_inst->setAdjustView(this);
|
||||
|
||||
auto drag_trans = new QDrag(this);
|
||||
auto mime_date = new QMimeData();
|
||||
mime_date->setText(QString("view-drags(view-id:%1)").arg(this->hashCode()));
|
||||
drag_trans->setMimeData(mime_date);
|
||||
drag_trans->setMimeData(new QMimeData);
|
||||
drag_trans->setPixmap(this->grab(this->rect()));
|
||||
drag_trans->setHotSpot(QPoint(5,5));
|
||||
drag_trans->exec();
|
||||
|
@ -153,6 +152,18 @@ 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;
|
||||
|
@ -166,6 +177,12 @@ split_frame::SplitView *DockableView::parentRes() const
|
|||
void DockableView::setParentRes(split_frame::SplitView *inst)
|
||||
{
|
||||
this->parent_res = inst;
|
||||
if(inst){
|
||||
this->setParent(inst->widget());
|
||||
}
|
||||
else{
|
||||
this->setParent(nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
QWidget *DockableView::widget() const
|
||||
|
@ -193,6 +210,16 @@ qulonglong DockableView::hashCode() const
|
|||
return (qulonglong)this;
|
||||
}
|
||||
|
||||
void DockableView::setVisible(bool state)
|
||||
{
|
||||
QWidget::setVisible(state);
|
||||
}
|
||||
|
||||
bool DockableView::isVisible() const
|
||||
{
|
||||
return QWidget::isVisible();
|
||||
}
|
||||
|
||||
QIcon DockableView::icon() const
|
||||
{
|
||||
return icon_store;
|
||||
|
@ -210,12 +237,12 @@ QSizeF DockableView::stiffSize() const
|
|||
return sizex;
|
||||
}
|
||||
|
||||
QSizeF DockableView::viewSize() const
|
||||
QRectF DockableView::outlineRect() const
|
||||
{
|
||||
return this->size();
|
||||
return this->rect();
|
||||
}
|
||||
|
||||
void DockableView::resizeView(const QSizeF &outline)
|
||||
void DockableView::setOutline(const QRectF &rect)
|
||||
{
|
||||
this->resize(outline.toSize());
|
||||
this->setGeometry(rect.toRect());
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
#include <QPushButton>
|
||||
#include <QString>
|
||||
|
||||
namespace base_view {
|
||||
namespace dock_panel {
|
||||
class DockableView;
|
||||
|
||||
/**
|
||||
|
@ -54,7 +54,7 @@ namespace base_view {
|
|||
/**
|
||||
* @brief 基础内容视图组件
|
||||
*/
|
||||
class SPLITVIEW_EXPORT DockableView : public QWidget, public split_frame::ViewBase, public split_frame::ViewRes {
|
||||
class SPLITVIEW_EXPORT DockableView : public QWidget, public split_frame::ViewBase {
|
||||
public:
|
||||
/**
|
||||
* @brief 构建新的呈现视图实例
|
||||
|
@ -77,11 +77,15 @@ namespace base_view {
|
|||
void setTitle(const QString &title);
|
||||
void setTitle(const QIcon &icon, const QString &title);
|
||||
|
||||
public slots:
|
||||
|
||||
void adjustAccept(const QPoint &pos);
|
||||
void closeAccept();
|
||||
void retrieveAccept();
|
||||
|
||||
protected:
|
||||
void showEvent(QShowEvent *ev) override;
|
||||
void hideEvent(QHideEvent *ev) override;
|
||||
|
||||
private:
|
||||
DragHeader *const title_header;
|
||||
QWidget *const present_cube;
|
||||
|
@ -96,18 +100,21 @@ namespace base_view {
|
|||
virtual split_frame::SplitView *parentRes() const override;
|
||||
virtual void setParentRes(split_frame::SplitView *inst) override;
|
||||
virtual QWidget *widget() const override;
|
||||
virtual bool canRetrieve() const override;
|
||||
virtual bool canClose() const override;
|
||||
virtual bool canReplace() const override;
|
||||
virtual QSizeF stiffSize() const override;
|
||||
virtual QRectF outlineRect() const override;
|
||||
virtual void setOutline(const QRectF &rect) override;
|
||||
virtual qulonglong hashCode() const override;
|
||||
virtual void setVisible(bool state) override;
|
||||
virtual bool isVisible() const override;
|
||||
|
||||
// ViewBase interface
|
||||
public:
|
||||
virtual QIcon icon() const override;
|
||||
virtual QString title() const override;
|
||||
virtual QSizeF stiffSize() const override;
|
||||
virtual QSizeF viewSize() const override;
|
||||
virtual void resizeView(const QSizeF &outline) override;
|
||||
virtual bool canRetrieve() const override;
|
||||
virtual bool canClose() const override;
|
||||
virtual bool canReplace() const override;
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -15,11 +15,13 @@ msvc{
|
|||
}
|
||||
|
||||
SOURCES += \
|
||||
acceptpanel.cpp \
|
||||
dockpanel.cpp \
|
||||
splitpanel.cpp \
|
||||
splitwindow.cpp
|
||||
|
||||
HEADERS += \
|
||||
acceptpanel.h \
|
||||
dockpanel.h \
|
||||
splitpanel.h \
|
||||
splitview_interface.h \
|
||||
|
|
|
@ -13,7 +13,8 @@ DragSplitter::DragSplitter(split_frame::SplitType split, split_frame::ViewRes *p
|
|||
this->setFrameShadow(QFrame::Shadow::Raised);
|
||||
|
||||
switch (split) {
|
||||
case split_frame::SplitType::SPLIT_H:
|
||||
case split_frame::SplitType::SPLIT_H_LFIRST:
|
||||
case split_frame::SplitType::SPLIT_H_RFIRST:
|
||||
this->setCursor(Qt::CursorShape::SplitHCursor);
|
||||
break;
|
||||
default:
|
||||
|
@ -29,147 +30,192 @@ void DragSplitter::mouseMoveEvent(QMouseEvent *event)
|
|||
|
||||
|
||||
//=====================================================
|
||||
SplitPanel::SplitPanel(ResManager *mgr, ViewBase *a, ViewBase *b, SplitType split, ViewRes *parent)
|
||||
: QWidget(parent->widget()), parent_inst(parent)
|
||||
SplitPanel::SplitPanel(ResManager *mgr, SplitType split)
|
||||
: QWidget(nullptr),
|
||||
manager_inst(mgr),
|
||||
parent_inst(nullptr),
|
||||
splitter_inst(new DragSplitter(split, this))
|
||||
{
|
||||
this->split_member = std::make_tuple(a, b);
|
||||
this->split_info_value = std::make_tuple(SplitType::SPLIT_H, 0.5, 8);
|
||||
connect(this->splitter_inst, &DragSplitter::adjustRequest, this, &SplitPanel::splitter_adjust);
|
||||
this->split_info = std::make_tuple(split, 0.5, 8);
|
||||
}
|
||||
|
||||
SplitPanel::~SplitPanel()
|
||||
{
|
||||
#include <QDebug>
|
||||
SplitPanel::~SplitPanel() {
|
||||
|
||||
}
|
||||
|
||||
ResManager *SplitPanel::splitManager() const { return this->parent_inst->splitManager(); }
|
||||
|
||||
SplitView *SplitPanel::parentRes() const
|
||||
void SplitPanel::resizeEvent(QResizeEvent *e)
|
||||
{
|
||||
return parent_inst;
|
||||
QWidget::resizeEvent(e);
|
||||
this->sync_status();
|
||||
}
|
||||
|
||||
bool SplitPanel::canRetrieve() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
ResManager *SplitPanel::splitManager() const { return this->manager_inst; }
|
||||
|
||||
bool SplitPanel::canClose() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
SplitView *SplitPanel::parentRes() const { return parent_inst; }
|
||||
|
||||
bool SplitPanel::canReplace() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
qulonglong SplitPanel::hashCode() const
|
||||
{
|
||||
return (qulonglong)this;
|
||||
}
|
||||
|
||||
QIcon SplitPanel::icon() const
|
||||
{
|
||||
return QIcon();
|
||||
}
|
||||
|
||||
QString SplitPanel::title() const
|
||||
{
|
||||
return QString("split-view:%1").arg((int64_t)this);
|
||||
}
|
||||
|
||||
QWidget *SplitPanel::widget() const
|
||||
{
|
||||
return const_cast<SplitPanel*>(this);
|
||||
}
|
||||
|
||||
QSizeF SplitPanel::viewSize() const
|
||||
{
|
||||
return this->size();
|
||||
}
|
||||
|
||||
void SplitPanel::resizeView(const QSizeF &outline)
|
||||
{
|
||||
if(outline != this->size()){
|
||||
this->resize(outline.toSize());
|
||||
}
|
||||
|
||||
|
||||
auto tuple_values = this->child();
|
||||
|
||||
if(view_list().size() == 1){
|
||||
view_list().first()->resizeView(this->viewSize());
|
||||
void SplitPanel::setParentRes(SplitView *inst) {
|
||||
this->parent_inst = inst;
|
||||
if(inst){
|
||||
this->setParent(inst->widget());
|
||||
}
|
||||
else{
|
||||
switch (std::get<2>(tuple_values)) {
|
||||
case SplitType::SPLIT_H: {
|
||||
auto width_value = QWidget::width() * this->splitterPos();
|
||||
std::get<0>(tuple_values)->widget()->setGeometry(0, 0, width_value, QWidget::height());
|
||||
|
||||
auto second_pos = width_value + splitterWidth();
|
||||
auto second_width = QWidget::width() - second_pos;
|
||||
std::get<1>(tuple_values)->widget()->setGeometry(second_pos, 0, second_width, QWidget::height());
|
||||
} break;
|
||||
case SplitType::SPLIT_V: {
|
||||
auto height_value = QWidget::height() * this->splitterPos();
|
||||
std::get<0>(tuple_values)->widget()->setGeometry(0, 0, QWidget::width(), height_value);
|
||||
|
||||
auto second_pos = height_value + splitterWidth();
|
||||
auto second_height = QWidget::height() - second_pos;
|
||||
std::get<1>(tuple_values)->widget()->setGeometry(0, second_pos, QWidget::width(), second_height);
|
||||
} break;
|
||||
}
|
||||
this->setParent(nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
std::tuple<ViewBase *, ViewBase *, SplitType> SplitPanel::child() const
|
||||
qulonglong SplitPanel::hashCode() const { return (qulonglong)this; }
|
||||
|
||||
void SplitPanel::setVisible(bool state)
|
||||
{
|
||||
return std::make_tuple(std::get<0>(split_member), std::get<1>(split_member), std::get<0>(split_info_value));
|
||||
QWidget::setVisible(state);
|
||||
}
|
||||
|
||||
void SplitPanel::replaceComp(ViewBase *view, ViewBase *old)
|
||||
bool SplitPanel::isVisible() const
|
||||
{
|
||||
QList<ViewBase*> mbrs = view_list();
|
||||
return QWidget::isVisible();
|
||||
}
|
||||
|
||||
if(!mbrs.contains(view) && mbrs.contains(old)){
|
||||
if(std::get<1>(split_member) == old){
|
||||
this->split_member = std::make_tuple(std::get<0>(split_member), view);
|
||||
}
|
||||
else if(std::get<0>(split_member) == old){
|
||||
this->split_member = std::make_tuple(view, std::get<1>(split_member));
|
||||
}
|
||||
void SplitPanel::initViews(ViewRes *a, ViewRes *b)
|
||||
{
|
||||
this->split_member = std::make_pair(a, b);
|
||||
|
||||
view->setParentRes(this);
|
||||
view->widget()->setParent(this);
|
||||
old->widget()->setParent(nullptr);
|
||||
this->resizeView(this->viewSize());
|
||||
a->setParentRes(this);
|
||||
b->setParentRes(this);
|
||||
}
|
||||
|
||||
QWidget *SplitPanel::widget() const { return const_cast<SplitPanel *>(this); }
|
||||
|
||||
QSizeF SplitPanel::stiffSize() const
|
||||
{
|
||||
auto size_a = split_member.first->stiffSize();
|
||||
auto size_b = split_member.second->stiffSize();
|
||||
|
||||
switch (this->splitType()) {
|
||||
case SplitType::SPLIT_H_LFIRST:
|
||||
case SplitType::SPLIT_H_RFIRST:
|
||||
return QSizeF(size_a.width() + size_b.width() + std::get<2>(split_info), std::max(size_a.height(), size_b.height()));
|
||||
default:
|
||||
return QSizeF(std::max(size_a.width(), size_b.width()), size_a.height() + size_b.height() + std::get<2>(split_info));
|
||||
}
|
||||
}
|
||||
|
||||
QRectF SplitPanel::outlineRect() const { return this->rect(); }
|
||||
|
||||
void SplitPanel::setOutline(const QRectF &outline)
|
||||
{
|
||||
if(outline != this->outlineRect()){
|
||||
this->setGeometry(outline.toRect());
|
||||
this->sync_status();
|
||||
}
|
||||
}
|
||||
|
||||
std::pair<ViewRes *, int> SplitPanel::except(ViewRes *inst) const
|
||||
{
|
||||
if(!contains(inst))
|
||||
throw new SimpleException<QString>("运行异常", "传入的视图实例不属于本组件");
|
||||
|
||||
if(split_member.first == inst)
|
||||
return std::make_pair(split_member.second, 1);
|
||||
return std::make_pair(split_member.first, 0);
|
||||
}
|
||||
|
||||
bool SplitPanel::contains(ViewRes *inst) const
|
||||
{
|
||||
return split_member.first == inst || split_member.second == inst;
|
||||
}
|
||||
|
||||
void SplitPanel::replaceView(ViewRes *_new, ViewRes *_old)
|
||||
{
|
||||
if(!contains(_old)){
|
||||
throw new SimpleException<QString>("运行异常", "指定替换的视图不属于本组件");
|
||||
}
|
||||
|
||||
_new->setParentRes(this);
|
||||
auto elsev = except(_old);
|
||||
switch (std::get<1>(elsev)) {
|
||||
case 0:
|
||||
this->split_member = std::make_pair(elsev.first, _new);
|
||||
break;
|
||||
default:
|
||||
this->split_member = std::make_pair(_new, elsev.first);
|
||||
}
|
||||
|
||||
sync_status();
|
||||
this->update();
|
||||
}
|
||||
|
||||
float SplitPanel::splitterWidth() const
|
||||
{
|
||||
return std::get<1>(split_info_value);
|
||||
return std::get<2>(split_info);
|
||||
}
|
||||
|
||||
float SplitPanel::splitterPos() const
|
||||
{
|
||||
return std::get<1>(split_info_value);
|
||||
return std::get<1>(split_info);
|
||||
}
|
||||
|
||||
void SplitPanel::setSplitInfo(split_frame::SplitType type, float pos, float width)
|
||||
SplitType SplitPanel::splitType() const
|
||||
{
|
||||
this->split_info_value = std::make_tuple(type, pos, width);
|
||||
return std::get<0>(split_info);
|
||||
}
|
||||
|
||||
|
||||
QList<ViewBase *> SplitPanel::view_list() const
|
||||
void SplitPanel::setSplitInfo(float pos, float width)
|
||||
{
|
||||
QList<ViewBase*> items;
|
||||
|
||||
if(std::get<0>(split_member))
|
||||
items << std::get<0>(split_member);
|
||||
if(std::get<1>(split_member))
|
||||
items << std::get<1>(split_member);
|
||||
|
||||
return items;
|
||||
this->split_info = std::make_tuple(std::get<0>(split_info), pos, width);
|
||||
this->sync_status();
|
||||
this->update();
|
||||
}
|
||||
|
||||
|
||||
void SplitPanel::sync_status()
|
||||
{
|
||||
auto total_w = this->width();
|
||||
auto total_h = this->height();
|
||||
switch (std::get<0>(split_info)) {
|
||||
case SplitType::SPLIT_H_LFIRST:
|
||||
case SplitType::SPLIT_H_RFIRST: {
|
||||
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));
|
||||
this->splitter_inst->setGeometry(QRect(width_a, 0, std::get<2>(split_info), total_h));
|
||||
} break;
|
||||
case SplitType::SPLIT_V_BFIRST:
|
||||
case SplitType::SPLIT_V_TFIRST: {
|
||||
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));
|
||||
splitter_inst->setGeometry(QRect(0, height_a, total_w, std::get<2>(split_info)));
|
||||
} break;
|
||||
}
|
||||
|
||||
split_member.first->setVisible(true);
|
||||
split_member.second->setVisible(true);
|
||||
}
|
||||
|
||||
void SplitPanel::splitter_adjust(const QPoint &pos)
|
||||
{
|
||||
switch (std::get<0>(split_info)) {
|
||||
case SplitType::SPLIT_H_LFIRST:
|
||||
case SplitType::SPLIT_H_RFIRST:{
|
||||
auto lwidth = split_member.first->stiffSize().width();
|
||||
auto rwidth = split_member.second->stiffSize().width();
|
||||
if(pos.x() >= lwidth && pos.x() <= this->width() - rwidth - std::get<2>(split_info))
|
||||
this->split_info = std::make_tuple(std::get<0>(split_info), pos.x()/(float)this->width(), std::get<2>(split_info));
|
||||
}break;
|
||||
case SplitType::SPLIT_V_BFIRST:
|
||||
case SplitType::SPLIT_V_TFIRST:{
|
||||
auto theight = split_member.first->stiffSize().height();
|
||||
auto bheight = split_member.second->stiffSize().height();
|
||||
if(pos.y() >= theight && pos.y() <= this->height() - bheight - std::get<2>(split_info))
|
||||
this->split_info = std::make_tuple(std::get<0>(split_info), pos.y()/this->height(), std::get<2>(split_info));
|
||||
}break;
|
||||
}
|
||||
|
||||
this->sync_status();
|
||||
}
|
||||
|
|
|
@ -6,11 +6,13 @@
|
|||
#include <QFrame>
|
||||
|
||||
namespace split_panel {
|
||||
|
||||
class DragSplitter : public QFrame{
|
||||
/**
|
||||
* @brief 分割边栏
|
||||
*/
|
||||
class SPLITVIEW_EXPORT DragSplitter : public QFrame{
|
||||
Q_OBJECT
|
||||
signals:
|
||||
void adjustRequest(QPoint);
|
||||
void adjustRequest(const QPoint&);
|
||||
|
||||
public:
|
||||
DragSplitter(split_frame::SplitType split, split_frame::ViewRes *parent);
|
||||
|
@ -23,56 +25,54 @@ namespace split_panel {
|
|||
/**
|
||||
* @brief 分割视图
|
||||
*/
|
||||
class SPLITVIEW_EXPORT SplitPanel :
|
||||
public QWidget,
|
||||
public split_frame::SplitView,
|
||||
public split_frame::ViewBase,
|
||||
public split_frame::ViewRes
|
||||
class SPLITVIEW_EXPORT SplitPanel : public QWidget, public split_frame::SplitView
|
||||
{
|
||||
typedef float split_pos;
|
||||
typedef float split_width;
|
||||
|
||||
private:
|
||||
split_frame::ResManager *const manager_inst;
|
||||
ViewRes *parent_inst;
|
||||
std::tuple<ViewBase*, ViewBase*> split_member;
|
||||
SplitView *parent_inst;
|
||||
DragSplitter *const splitter_inst;
|
||||
std::pair<split_frame::ViewRes*, split_frame::ViewRes*> split_member;
|
||||
// type, pos, width
|
||||
std::tuple<split_frame::SplitType, split_pos, split_width> split_info_value;
|
||||
std::tuple<split_frame::SplitType, split_pos, split_width> split_info;
|
||||
|
||||
void sync_status();
|
||||
void splitter_adjust(const QPoint &pos);
|
||||
|
||||
QList<split_frame::ViewBase*> view_list() const;
|
||||
|
||||
public:
|
||||
SplitPanel(split_frame::ResManager *mgr, ViewBase *a, ViewBase *b, split_frame::SplitType split, ViewRes *parent);
|
||||
SplitPanel(split_frame::ResManager *mgr,split_frame::SplitType split);
|
||||
virtual ~SplitPanel();
|
||||
|
||||
protected:
|
||||
void resizeEvent(QResizeEvent *e) override;
|
||||
|
||||
|
||||
// ViewRes interface
|
||||
public:
|
||||
virtual split_frame::ResManager *splitManager() const override;
|
||||
virtual split_frame::SplitView *parentRes() const override;
|
||||
virtual void setParentRes(SplitView *inst) override;
|
||||
virtual bool canRetrieve() const override;
|
||||
virtual bool canClose() const override;
|
||||
virtual bool canReplace() const override;
|
||||
virtual qulonglong hashCode() const override;
|
||||
|
||||
// ViewBase interface
|
||||
public:
|
||||
virtual QIcon icon() const override;
|
||||
virtual QString title() const override;
|
||||
virtual QWidget* widget() const override;
|
||||
virtual QSizeF stiffSize() const override;
|
||||
virtual QSizeF viewSize() const override;
|
||||
virtual void resizeView(const QSizeF &outline) override;
|
||||
virtual QRectF outlineRect() const override;
|
||||
virtual void setOutline(const QRectF &outline) override;
|
||||
virtual qulonglong hashCode() const override;
|
||||
virtual void setVisible(bool state) override;
|
||||
virtual bool isVisible() const override;
|
||||
|
||||
// SplitView interface
|
||||
public:
|
||||
virtual std::tuple<split_frame::ViewBase *, split_frame::ViewBase *, split_frame::SplitType> child() const override;
|
||||
virtual void replaceComp(ViewBase *view, ViewBase *old) override;
|
||||
virtual void initViews(ViewRes *a, ViewRes *b) override;
|
||||
virtual std::pair<split_frame::ViewRes*, int> except(split_frame::ViewRes *inst) const override;
|
||||
virtual bool contains(split_frame::ViewRes *inst) const override;
|
||||
virtual void replaceView(split_frame::ViewRes *_new, split_frame::ViewRes *_old) override;
|
||||
virtual void setSplitInfo(float pos, float width) override;
|
||||
virtual float splitterWidth() const override;
|
||||
virtual float splitterPos() const override;
|
||||
virtual void setSplitInfo(split_frame::SplitType type, float pos, float width) override;
|
||||
|
||||
virtual split_frame::SplitType splitType() const override;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ namespace split_frame {
|
|||
/**
|
||||
* @brief 面板分割方向
|
||||
*/
|
||||
enum class SplitType { SPLIT_H = 0, SPLIT_V = 1 };
|
||||
enum class SplitType { SPLIT_H_LFIRST = 0, SPLIT_H_RFIRST = 1, SPLIT_V_TFIRST = 2, SPLIT_V_BFIRST = 3 };
|
||||
/**
|
||||
* @brief 临时视图贴附方位
|
||||
*/
|
||||
|
@ -36,19 +36,73 @@ namespace split_frame {
|
|||
*/
|
||||
virtual ResManager *splitManager() const = 0;
|
||||
|
||||
|
||||
/**
|
||||
* @brief 父资源实例
|
||||
* @return
|
||||
*/
|
||||
virtual SplitView *parentRes() const = 0;
|
||||
/**
|
||||
* @brief 设置父资源实例
|
||||
* @param inst
|
||||
*/
|
||||
virtual void setParentRes(SplitView *inst) = 0;
|
||||
|
||||
|
||||
/**
|
||||
* @brief 视图组件
|
||||
* @return
|
||||
*/
|
||||
virtual QWidget *widget() const = 0;
|
||||
|
||||
/**
|
||||
* @brief 不可压缩的最小尺寸
|
||||
* @return
|
||||
*/
|
||||
virtual QSizeF stiffSize() const = 0;
|
||||
|
||||
/**
|
||||
* @brief 获取外形尺寸
|
||||
* @return
|
||||
*/
|
||||
virtual QRectF outlineRect() const = 0;
|
||||
/**
|
||||
* @brief 重新设置外形尺寸
|
||||
* @param outline
|
||||
*/
|
||||
virtual void setOutline(const QRectF &rect) = 0;
|
||||
/**
|
||||
* @brief 设置可见性
|
||||
* @param state
|
||||
*/
|
||||
virtual void setVisible(bool state) = 0;
|
||||
virtual bool isVisible() const = 0;
|
||||
|
||||
/**
|
||||
* @brief 资源唯一标号
|
||||
* @return
|
||||
*/
|
||||
virtual qulonglong hashCode() const = 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief 视图展示接口
|
||||
*/
|
||||
class ViewBase : public ViewRes {
|
||||
public:
|
||||
virtual ~ViewBase() = default;
|
||||
|
||||
/**
|
||||
* @brief 视图图标
|
||||
* @return
|
||||
*/
|
||||
virtual QIcon icon() const = 0;
|
||||
/**
|
||||
* @brief 视图标题
|
||||
* @return
|
||||
*/
|
||||
virtual QString title() const = 0;
|
||||
|
||||
/**
|
||||
* @brief 可以被回收
|
||||
*/
|
||||
|
@ -64,63 +118,28 @@ namespace split_frame {
|
|||
* @return
|
||||
*/
|
||||
virtual bool canReplace() const = 0;
|
||||
|
||||
/**
|
||||
* @brief 资源唯一标号
|
||||
* @return
|
||||
*/
|
||||
virtual qulonglong hashCode() const = 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief 视图展示接口
|
||||
*/
|
||||
class ViewBase {
|
||||
public:
|
||||
virtual ~ViewBase() = default;
|
||||
|
||||
/**
|
||||
* @brief 视图图标
|
||||
* @return
|
||||
*/
|
||||
virtual QIcon icon() const = 0;
|
||||
/**
|
||||
* @brief 视图标题
|
||||
* @return
|
||||
*/
|
||||
virtual QString title() const = 0;
|
||||
|
||||
/**
|
||||
* @brief 不可压缩的最小尺寸
|
||||
* @return
|
||||
*/
|
||||
virtual QSizeF stiffSize() const = 0;
|
||||
|
||||
/**
|
||||
* @brief 获取外形尺寸
|
||||
* @return
|
||||
*/
|
||||
virtual QSizeF viewSize() const = 0;
|
||||
/**
|
||||
* @brief 重新设置外形尺寸
|
||||
* @param outline
|
||||
*/
|
||||
virtual void resizeView(const QSizeF &outline) = 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief 分裂视图规划和约束组件
|
||||
*/
|
||||
class SplitView {
|
||||
class SplitView : public ViewRes {
|
||||
public:
|
||||
virtual ~SplitView() = default;
|
||||
|
||||
/**
|
||||
* @brief 替换子视图
|
||||
* @param view
|
||||
* @param old
|
||||
* @brief 载入视图成员
|
||||
* @param a 成员视图a
|
||||
* @param b 成员视图b
|
||||
*/
|
||||
virtual void replaceComp(ViewBase *view, ViewBase *old) = 0;
|
||||
virtual void initViews(ViewRes *a, ViewRes *b) = 0;
|
||||
|
||||
/**
|
||||
* @brief 构建子视图
|
||||
* @param old 不为nullptr
|
||||
* @param view 不为nullptr
|
||||
*/
|
||||
virtual void replaceView(ViewRes *_new, ViewRes *_old) = 0;
|
||||
|
||||
/**
|
||||
* @brief 设置分割信息
|
||||
|
@ -128,13 +147,19 @@ namespace split_frame {
|
|||
* @param pos
|
||||
* @param width
|
||||
*/
|
||||
virtual void setSplitInfo(SplitType type, float pos, float width) = 0;
|
||||
virtual void setSplitInfo(float pos, float width) = 0;
|
||||
|
||||
/**
|
||||
* @brief 获取子视图列表和分割方式
|
||||
* @brief 获取本视图中的其他视图
|
||||
* @return std::pair<ptr, index>
|
||||
*/
|
||||
virtual std::pair<ViewRes*, int> except(ViewRes *inst) const = 0;
|
||||
/**
|
||||
* @brief 测试是否包含指定视图
|
||||
* @param inst
|
||||
* @return
|
||||
*/
|
||||
virtual std::tuple<ViewBase *, ViewBase *, SplitType> child() const = 0;
|
||||
virtual bool contains(ViewRes *inst) const = 0;
|
||||
/**
|
||||
* @brief 分隔符的宽度
|
||||
* @return
|
||||
|
@ -145,6 +170,11 @@ namespace split_frame {
|
|||
* @return
|
||||
*/
|
||||
virtual float splitterPos() const = 0;
|
||||
/**
|
||||
* @brief 分割方向
|
||||
* @return 分割类型
|
||||
*/
|
||||
virtual SplitType splitType() const = 0;
|
||||
};
|
||||
|
||||
|
||||
|
@ -158,12 +188,23 @@ namespace split_frame {
|
|||
* @brief 闲置视图增加
|
||||
* @param ins
|
||||
*/
|
||||
virtual void freedomAppended(ViewBase *ins) = 0;
|
||||
virtual void freedomAppend(ViewBase *ins) = 0;
|
||||
/**
|
||||
* @brief 闲置视图减少
|
||||
* @param ins
|
||||
*/
|
||||
virtual void freedomRemoved(ViewBase *ins) = 0;
|
||||
virtual void freedomRemove(ViewBase *ins) = 0;
|
||||
|
||||
/**
|
||||
* @brief 视图关闭
|
||||
* @param inst
|
||||
*/
|
||||
virtual void aboutToBeDelete(ViewBase *inst) = 0;
|
||||
/**
|
||||
* @brief 视图增加
|
||||
* @param inst
|
||||
*/
|
||||
virtual void hasBeenAppend(ViewBase *inst) = 0;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -176,6 +217,9 @@ namespace split_frame {
|
|||
virtual void addListener(FreedomViewsListener *lsn) = 0;
|
||||
virtual void removeListener(FreedomViewsListener *lsn) = 0;
|
||||
|
||||
virtual ViewBase* adjustView() const = 0;
|
||||
virtual void setAdjustView(ViewBase *target = nullptr) = 0;
|
||||
|
||||
/**
|
||||
* @brief 在系统中移除指定视图
|
||||
* @param inst
|
||||
|
@ -191,19 +235,19 @@ namespace split_frame {
|
|||
* @brief 回收视图显示,转换视图为自由(闲置)状态
|
||||
* @param inst
|
||||
*/
|
||||
virtual void doRetrieve(ViewRes *inst) = 0;
|
||||
virtual void doRetrieve(ViewBase *inst) = 0;
|
||||
|
||||
/**
|
||||
* @brief 回收视图,清除内存实例
|
||||
*/
|
||||
virtual void doClose(ViewRes *inst) = 0;
|
||||
virtual void doClose(ViewBase *inst) = 0;
|
||||
|
||||
/**
|
||||
* @brief 替换指定视图
|
||||
* @param view
|
||||
* @param old
|
||||
*/
|
||||
virtual void doReplace(ViewRes *view, ViewRes *old) = 0;
|
||||
virtual void siblingAttach(ViewBase *view, ViewRes *pos, SplitType ori) = 0;
|
||||
};
|
||||
|
||||
} // namespace SplitFrame
|
||||
|
|
|
@ -11,11 +11,180 @@
|
|||
#include <QPushButton>
|
||||
#include <QResizeEvent>
|
||||
#include <QStyleOption>
|
||||
#include <QWindow>
|
||||
#include <libConfig.h>
|
||||
|
||||
using namespace split_panel;
|
||||
using namespace split_window;
|
||||
using namespace split_frame;
|
||||
|
||||
SplitWindow::SplitWindow(QWidget *parent) : QMainWindow(parent) {}
|
||||
void SplitWindow::setRoot(split_frame::ViewRes *inst)
|
||||
{
|
||||
if(inst){
|
||||
this->view_root = inst;
|
||||
inst->setParentRes(nullptr);
|
||||
this->setCentralWidget(inst->widget());
|
||||
}
|
||||
else{
|
||||
this->takeCentralWidget();
|
||||
this->view_root = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
SplitWindow::SplitWindow(QWidget *parent) : QMainWindow(parent), view_root(nullptr), accept_port(new accept_panel::AcceptPanel(this, this)) {
|
||||
this->setRoot(nullptr);
|
||||
accept_port->setVisible(false);
|
||||
}
|
||||
|
||||
SplitWindow::~SplitWindow() {}
|
||||
|
||||
bool SplitWindow::eventFilter(QObject *sender, QEvent *ev)
|
||||
{
|
||||
switch (ev->type()) {
|
||||
case QEvent::Type::DragMove: {
|
||||
if (sender->isWidgetType() || sender->isWindowType()) {
|
||||
auto evn_pos = static_cast<QDragMoveEvent *>(ev)->pos();
|
||||
QPoint global_pos;
|
||||
if (sender->isWindowType()) {
|
||||
dynamic_cast<QWindow *>(sender)->requestActivate();
|
||||
global_pos = dynamic_cast<QWindow *>(sender)->mapToGlobal(evn_pos);
|
||||
} else if (sender->isWidgetType()) {
|
||||
global_pos = dynamic_cast<QWidget *>(sender)->mapToGlobal(evn_pos);
|
||||
}
|
||||
|
||||
for (auto &cmp : this->views_store) {
|
||||
auto local_pos = cmp->widget()->mapFromGlobal(global_pos);
|
||||
auto rect_shape = cmp->outlineRect();
|
||||
rect_shape.moveTopLeft(QPointF());
|
||||
|
||||
if (rect_shape.contains(local_pos) && cmp->widget()->isActiveWindow()) {
|
||||
accept_port->bindWith(cmp);
|
||||
accept_port->raise();
|
||||
accept_port->setVisible(true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} break;
|
||||
case QEvent::Type::MouseButtonRelease:
|
||||
accept_port->setVisible(false);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return QMainWindow::eventFilter(sender, ev);
|
||||
}
|
||||
|
||||
void SplitWindow::addListener(split_frame::FreedomViewsListener *lsn)
|
||||
{
|
||||
if(listener_list.contains(lsn))
|
||||
return;
|
||||
listener_list << lsn;
|
||||
}
|
||||
|
||||
void SplitWindow::removeListener(split_frame::FreedomViewsListener *lsn)
|
||||
{
|
||||
this->listener_list.removeAll(lsn);
|
||||
}
|
||||
|
||||
void SplitWindow::appendPresentView(split_frame::ViewBase *inst)
|
||||
{
|
||||
if(inst)
|
||||
this->views_store[inst->hashCode()] = inst;
|
||||
}
|
||||
|
||||
void SplitWindow::removePresentView(split_frame::ViewBase *inst)
|
||||
{
|
||||
if(inst)
|
||||
this->views_store.remove(inst->hashCode());
|
||||
}
|
||||
|
||||
void SplitWindow::present_remove(split_frame::ViewRes *inst)
|
||||
{
|
||||
// 面板树中间节点
|
||||
if(inst != view_root && inst->parentRes()){
|
||||
auto pinst = inst->parentRes();
|
||||
|
||||
auto remains = pinst->except(inst);
|
||||
remains.first->setParentRes(nullptr);
|
||||
inst->setParentRes(nullptr);
|
||||
|
||||
// 父节点不是根节点
|
||||
auto ppinst = pinst->parentRes();
|
||||
if (ppinst) {
|
||||
ppinst->replaceView(remains.first, pinst);
|
||||
} else {
|
||||
this->setRoot(remains.first);
|
||||
}
|
||||
delete pinst;
|
||||
}
|
||||
else if(inst == view_root){
|
||||
setRoot(nullptr);
|
||||
}
|
||||
}
|
||||
void SplitWindow::doRetrieve(split_frame::ViewBase *inst)
|
||||
{
|
||||
// 呈现视图结构调整
|
||||
present_remove(inst);
|
||||
|
||||
// 回收当前视图
|
||||
for(auto &lsn : listener_list)
|
||||
lsn->freedomAppend(inst);
|
||||
|
||||
inst->setParentRes(nullptr);
|
||||
inst->setVisible(false);
|
||||
removePresentView(inst);
|
||||
}
|
||||
|
||||
void SplitWindow::doClose(split_frame::ViewBase *inst)
|
||||
{
|
||||
// 呈现视图结构调整
|
||||
present_remove(inst);
|
||||
|
||||
// 回收当前视图
|
||||
for(auto &lsn : listener_list)
|
||||
lsn->aboutToBeDelete(inst);
|
||||
|
||||
removePresentView(inst);
|
||||
delete inst;
|
||||
}
|
||||
|
||||
void SplitWindow::siblingAttach(ViewBase *view, ViewRes *pos, SplitType ori)
|
||||
{
|
||||
doRetrieve(view);
|
||||
|
||||
auto split_slot = new split_panel::SplitPanel(this, ori);
|
||||
auto remains_frm = pos->parentRes();
|
||||
remains_frm->replaceView(split_slot, pos);
|
||||
|
||||
switch (ori) {
|
||||
case SplitType::SPLIT_H_LFIRST:
|
||||
split_slot->initViews(view, pos);
|
||||
split_slot->setSplitInfo(0.333, 8);
|
||||
break;
|
||||
case SplitType::SPLIT_H_RFIRST:
|
||||
split_slot->initViews(pos, view);
|
||||
split_slot->setSplitInfo(0.666, 8);
|
||||
break;
|
||||
case SplitType::SPLIT_V_TFIRST:
|
||||
split_slot->initViews(view, pos);
|
||||
split_slot->setSplitInfo(0.333, 8);
|
||||
break;
|
||||
case SplitType::SPLIT_V_BFIRST:
|
||||
split_slot->initViews(pos, view);
|
||||
split_slot->setSplitInfo(0.666, 8);
|
||||
break;
|
||||
}
|
||||
|
||||
for(auto &lsn : listener_list)
|
||||
lsn->freedomRemove(view);
|
||||
}
|
||||
|
||||
ViewBase *SplitWindow::adjustView() const
|
||||
{
|
||||
return adjust_target;
|
||||
}
|
||||
|
||||
void SplitWindow::setAdjustView(split_frame::ViewBase *target)
|
||||
{
|
||||
this->adjust_target = target;
|
||||
}
|
||||
|
|
|
@ -2,34 +2,59 @@
|
|||
#define SPLITWINDOW_H
|
||||
|
||||
#include "splitview_interface.h"
|
||||
#include "acceptpanel.h"
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <QWidget>
|
||||
#include <libConfig.h>
|
||||
|
||||
namespace split_panel {
|
||||
|
||||
namespace split_window {
|
||||
|
||||
/**
|
||||
* @brief 鍒嗚瑙嗗浘鍛堢幇缁勪欢
|
||||
* @brief 窗口即视图资源管理器
|
||||
*/
|
||||
class SPLITVIEW_EXPORT SplitWindow : public QMainWindow, public split_frame::SplitView {
|
||||
class SPLITVIEW_EXPORT SplitWindow : public QMainWindow, public split_frame::ResManager {
|
||||
typedef float pos;
|
||||
typedef float width;
|
||||
|
||||
private:
|
||||
QList<split_frame::FreedomViewsListener*> listener_list;
|
||||
QHash<qulonglong, split_frame::ViewBase*> views_store;
|
||||
split_frame::ViewRes *view_root;
|
||||
accept_panel::AcceptPanel *const accept_port;
|
||||
split_frame::ViewBase *adjust_target = nullptr;
|
||||
|
||||
void present_remove(split_frame::ViewRes *inst);
|
||||
|
||||
public:
|
||||
SplitWindow(QWidget *parent = nullptr);
|
||||
virtual ~SplitWindow();
|
||||
|
||||
//======================================================
|
||||
/**
|
||||
* @brief 涓存椂鏄剧ず鎸囧畾瑙嗗浘
|
||||
* @brief 临时展示
|
||||
* @param t
|
||||
* @param target
|
||||
*/
|
||||
void tempShow(split_frame::DockType t, split_frame::ViewBase *target);
|
||||
|
||||
|
||||
void setRoot(split_frame::ViewRes *inst);
|
||||
|
||||
|
||||
bool eventFilter(QObject *sender, QEvent *ev) override;
|
||||
|
||||
// ResManager interface
|
||||
public:
|
||||
virtual void addListener(split_frame::FreedomViewsListener *lsn) override;
|
||||
virtual void removeListener(split_frame::FreedomViewsListener *lsn) override;
|
||||
virtual void appendPresentView(split_frame::ViewBase *inst) override;
|
||||
virtual void removePresentView(split_frame::ViewBase *inst) override;
|
||||
virtual void doRetrieve(split_frame::ViewBase *inst) override;
|
||||
virtual void doClose(split_frame::ViewBase *inst) override;
|
||||
virtual void siblingAttach(split_frame::ViewBase *view, split_frame::ViewRes *pos, split_frame::SplitType ori) override;
|
||||
virtual split_frame::ViewBase *adjustView() const override;
|
||||
virtual void setAdjustView(split_frame::ViewBase *target) override;
|
||||
};
|
||||
|
||||
} // namespace split_panel
|
||||
|
|
|
@ -13,25 +13,21 @@
|
|||
#include <dockpanel.h>
|
||||
#include <splitwindow.h>
|
||||
#include <splitpanel.h>
|
||||
|
||||
using namespace SplitFrame;
|
||||
#include <dockpanel.h>
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
QApplication a(argc, argv);
|
||||
|
||||
auto win = new QMainWindow();
|
||||
win->show();
|
||||
split_window::SplitWindow w;
|
||||
auto spb = new split_panel::SplitPanel(&w, split_frame::SplitType::SPLIT_H_LFIRST);
|
||||
w.setRoot(spb);
|
||||
|
||||
QWidget *firstPageWidget = new XWidget(nullptr, Qt::GlobalColor::green);
|
||||
QWidget *secondPageWidget = new XWidget(nullptr, Qt::black);
|
||||
QWidget *thirdPageWidget = new XWidget(nullptr, Qt::black);
|
||||
auto bview = new dock_panel::DockableView(&w, new QWidget, true);
|
||||
auto dview = new dock_panel::DockableView(&w, new QWidget, true);
|
||||
spb->initViews(bview, dview);
|
||||
|
||||
QStackedWidget *stackedWidget = new QStackedWidget;
|
||||
stackedWidget->addWidget(firstPageWidget);
|
||||
stackedWidget->addWidget(secondPageWidget);
|
||||
stackedWidget->addWidget(thirdPageWidget);
|
||||
|
||||
win->setCentralWidget(stackedWidget);
|
||||
a.installEventFilter(&w);
|
||||
|
||||
w.show();
|
||||
return a.exec();
|
||||
}
|
||||
|
|
|
@ -1,22 +1,3 @@
|
|||
#include "unnnn.h"
|
||||
|
||||
#include <QPainter>
|
||||
using namespace SplitFrame;
|
||||
|
||||
XWidget::XWidget(SplitPanel *host, Qt::GlobalColor c, QWidget *parent) : FnWrap<XWidget, false>(host), c_store(c) {}
|
||||
|
||||
void XWidget::paintEvent(QPaintEvent *ev) {
|
||||
QPainter p(this);
|
||||
p.fillRect(this->rect(), c_store);
|
||||
}
|
||||
|
||||
void XWidget::closeProcess() {}
|
||||
|
||||
YWidget::YWidget(SplitPanel *host, QWidget *parent) : FnWrap<XWidget, true>(host) {}
|
||||
|
||||
void YWidget::paintEvent(QPaintEvent *ev) {
|
||||
QPainter p(this);
|
||||
p.fillRect(this->rect(), Qt::blue);
|
||||
}
|
||||
|
||||
void YWidget::closeProcess() {}
|
||||
|
|
|
@ -5,26 +5,5 @@
|
|||
#include <QWidget>
|
||||
#include <splitwindow.h>
|
||||
|
||||
class XWidget : public SplitFrame::FnWrap<XWidget, false> {
|
||||
public:
|
||||
XWidget(SplitFrame::SplitPanel *host, Qt::GlobalColor c, QWidget *parent = nullptr);
|
||||
virtual void paintEvent(QPaintEvent *ev) override;
|
||||
|
||||
// FnWrap interface
|
||||
public:
|
||||
virtual void closeProcess() override;
|
||||
|
||||
private:
|
||||
Qt::GlobalColor c_store;
|
||||
};
|
||||
|
||||
class YWidget : public SplitFrame::FnWrap<XWidget, true> {
|
||||
public:
|
||||
YWidget(SplitFrame::SplitPanel *host, QWidget *parent = nullptr);
|
||||
virtual void paintEvent(QPaintEvent *ev) override;
|
||||
// FnWrap interface
|
||||
public:
|
||||
virtual void closeProcess() override;
|
||||
};
|
||||
|
||||
#endif // UNNNN_H
|
||||
|
|
Loading…
Reference in New Issue