176 lines
4.4 KiB
C++
176 lines
4.4 KiB
C++
#include "splitpanel.h"
|
||
#include "dockpanel.h"
|
||
#include <QPainter>
|
||
#include <libConfig.h>
|
||
|
||
using namespace split_frame;
|
||
using namespace split_panel;
|
||
using namespace Config;
|
||
|
||
DragSplitter::DragSplitter(split_frame::SplitType split, split_frame::ViewRes *parent)
|
||
: QFrame(parent->widget()){
|
||
this->setFrameShape(QFrame::Shape::WinPanel);
|
||
this->setFrameShadow(QFrame::Shadow::Raised);
|
||
|
||
switch (split) {
|
||
case split_frame::SplitType::SPLIT_H:
|
||
this->setCursor(Qt::CursorShape::SplitHCursor);
|
||
break;
|
||
default:
|
||
this->setCursor(Qt::CursorShape::SizeVerCursor);
|
||
}
|
||
}
|
||
|
||
void DragSplitter::mouseMoveEvent(QMouseEvent *event)
|
||
{
|
||
QFrame::mouseMoveEvent(event);
|
||
emit this->adjustRequest(mapToParent(event->pos()));
|
||
}
|
||
|
||
|
||
//=====================================================
|
||
SplitPanel::SplitPanel(ViewBase *first, ViewBase *next, ViewRes *parent)
|
||
: QWidget(parent->widget()), parent_inst(parent)
|
||
{
|
||
this->split_member = std::make_tuple(first, next);
|
||
this->split_info_value = std::make_tuple(SplitType::SPLIT_H, 0.5, 8);
|
||
}
|
||
|
||
SplitPanel::~SplitPanel()
|
||
{
|
||
|
||
}
|
||
|
||
ResManager *SplitPanel::splitManager() const { return this->parent_inst->splitManager(); }
|
||
|
||
SplitView *SplitPanel::parentRes() const
|
||
{
|
||
return parent_inst;
|
||
}
|
||
|
||
bool SplitPanel::canRetrieve() const
|
||
{
|
||
return true;
|
||
}
|
||
|
||
bool SplitPanel::canClose() const
|
||
{
|
||
return true;
|
||
}
|
||
|
||
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());
|
||
}
|
||
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;
|
||
}
|
||
}
|
||
}
|
||
|
||
std::tuple<ViewBase *, ViewBase *, SplitType> SplitPanel::child() const
|
||
{
|
||
return std::make_tuple(std::get<0>(split_member), std::get<1>(split_member), std::get<0>(split_info_value));
|
||
}
|
||
|
||
void SplitPanel::replaceComp(ViewBase *view, ViewBase *old)
|
||
{
|
||
QList<ViewBase*> mbrs = view_list();
|
||
|
||
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));
|
||
}
|
||
|
||
view->setParentRes(this);
|
||
view->widget()->setParent(this);
|
||
old->widget()->setParent(nullptr);
|
||
this->resizeView(this->viewSize());
|
||
}
|
||
}
|
||
|
||
float SplitPanel::splitterWidth() const
|
||
{
|
||
return std::get<1>(split_info_value);
|
||
}
|
||
|
||
float SplitPanel::splitterPos() const
|
||
{
|
||
return std::get<1>(split_info_value);
|
||
}
|
||
|
||
void SplitPanel::setSplitInfo(split_frame::SplitType type, float pos, float width)
|
||
{
|
||
this->split_info_value = std::make_tuple(type, pos, width);
|
||
}
|
||
|
||
|
||
QList<ViewBase *> SplitPanel::view_list() const
|
||
{
|
||
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;
|
||
}
|