253 lines
6.0 KiB
C++
253 lines
6.0 KiB
C++
#include "DockPanel.h"
|
|
|
|
#include <QApplication>
|
|
#include <QDebug>
|
|
#include <QDrag>
|
|
#include <QHBoxLayout>
|
|
#include <QMimeData>
|
|
#include <QMouseEvent>
|
|
#include <QPushButton>
|
|
|
|
using namespace dock_panel;
|
|
|
|
DragHeader::DragHeader(const QString &title, DockableView *bind_core)
|
|
: QFrame(bind_core),
|
|
bind_core(bind_core),
|
|
title_holder(new QLabel(this)),
|
|
close_btn(new QPushButton("x",this)),
|
|
minimal_btn(new QPushButton("-",this)) {
|
|
setWindowTitle(title);
|
|
|
|
auto layout = new QHBoxLayout(this);
|
|
layout->setSpacing(0);
|
|
layout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
title_holder->setText(title);
|
|
title_holder->setContentsMargins(2,0, 0, 0);
|
|
layout->addWidget(title_holder, 1, Qt::AlignLeft);
|
|
|
|
minimal_btn->setMinimumSize(22,22);
|
|
minimal_btn->setMaximumSize(22,22);
|
|
layout->addWidget(minimal_btn, 0, Qt::AlignRight);
|
|
connect(minimal_btn, &QPushButton::clicked, this, &DragHeader::retrieveRequest);
|
|
|
|
close_btn->setMinimumSize(22,22);
|
|
close_btn->setMaximumSize(22,22);
|
|
layout->addWidget(close_btn, 0, Qt::AlignRight);
|
|
connect(close_btn, &QPushButton::clicked, this, &DragHeader::closeRequest);
|
|
}
|
|
|
|
DragHeader::DragHeader(const QString &title, const QIcon &icon, DockableView *bind_core) : DragHeader(title, bind_core) {
|
|
setWindowIcon(icon);
|
|
this->title_holder->setPixmap(icon.pixmap(22, 22));
|
|
}
|
|
|
|
void DragHeader::setTitle(const QString &title)
|
|
{
|
|
this->title_holder->setText(title);
|
|
this->setWindowTitle(title);
|
|
}
|
|
|
|
void DragHeader::setTitle(const QString &title, const QIcon &icon)
|
|
{
|
|
this->setTitle(title);
|
|
this->title_holder->setPixmap(icon.pixmap(22, 22));
|
|
}
|
|
|
|
void DragHeader::optConfig(bool retrieve, bool close)
|
|
{
|
|
this->minimal_btn->setVisible(retrieve);
|
|
this->minimal_btn->setEnabled(retrieve);
|
|
this->close_btn->setVisible(close);
|
|
this->close_btn->setEnabled(close);
|
|
}
|
|
|
|
void DragHeader::mousePressEvent(QMouseEvent *event)
|
|
{
|
|
QFrame::mousePressEvent(event);
|
|
this->press_flag = std::make_pair(true, this->mapToParent(event->pos()));
|
|
}
|
|
|
|
void DragHeader::mouseReleaseEvent(QMouseEvent *event)
|
|
{
|
|
QFrame::mouseReleaseEvent(event);
|
|
this->press_flag = std::make_pair(false, QPoint());
|
|
}
|
|
|
|
void DragHeader::mouseMoveEvent(QMouseEvent *event)
|
|
{
|
|
QFrame::mouseMoveEvent(event);
|
|
auto sub = event->pos() - std::get<1>(press_flag);
|
|
|
|
if(std::get<0>(this->press_flag) && sub.manhattanLength() > QApplication::startDragDistance()){
|
|
emit this->adjustRequest(event->pos());
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ===============================================================================
|
|
|
|
DockableView::DockableView(split_frame::ResManager *mgr, QWidget *present)
|
|
: title_header(new DragHeader("未命名", this)),
|
|
present_cube(present),
|
|
manager_inst(mgr)
|
|
{
|
|
auto layout = new QVBoxLayout(this);
|
|
layout->addWidget(title_header);
|
|
if(present_cube){
|
|
layout->addWidget(present);
|
|
}
|
|
else {
|
|
layout->addWidget(new QWidget(this));
|
|
}
|
|
|
|
layout->setSpacing(0);
|
|
layout->setContentsMargins(0, 2, 0, 0);
|
|
|
|
this->title_header->setVisible(true);
|
|
this->title_header->setMinimumHeight(26);
|
|
this->title_header->setMaximumHeight(26);
|
|
this->title_header->setFrameShape(QFrame::Shape::Panel);
|
|
this->title_header->setFrameShadow(QFrame::Shadow::Raised);
|
|
this->title_header->setLineWidth(3);
|
|
|
|
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);
|
|
}
|
|
|
|
DockableView::~DockableView() {
|
|
manager_inst->removePresentView(this);
|
|
qDebug() << "view-deleted";
|
|
}
|
|
|
|
void DockableView::viewConfig(bool replace, bool close, bool retrieve)
|
|
{
|
|
this->m_replace = replace;
|
|
this->m_retrieve = retrieve;
|
|
this->m_close = close;
|
|
|
|
this->title_header->optConfig(retrieve, close);
|
|
}
|
|
|
|
void DockableView::setTitle(const QString &title)
|
|
{
|
|
this->title_header->setTitle(title);
|
|
}
|
|
|
|
void DockableView::setTitle(const QIcon &icon, const QString &title)
|
|
{
|
|
this->title_header->setTitle(title, icon);
|
|
this->icon_store = icon;
|
|
}
|
|
|
|
void DockableView::adjustAccept(const QPoint &pos)
|
|
{
|
|
Q_UNUSED(pos);
|
|
|
|
manager_inst->setAdjustView(this);
|
|
|
|
auto drag_trans = new QDrag(this);
|
|
drag_trans->setMimeData(new QMimeData);
|
|
drag_trans->setPixmap(this->grab(this->rect()));
|
|
drag_trans->setHotSpot(QPoint(5,5));
|
|
drag_trans->exec();
|
|
}
|
|
|
|
void DockableView::closeAccept()
|
|
{
|
|
this->manager_inst->doRetrieve(this);
|
|
this->manager_inst->doClose(this);
|
|
}
|
|
|
|
void DockableView::retrieveAccept()
|
|
{
|
|
this->manager_inst->doRetrieve(this);
|
|
}
|
|
|
|
split_frame::ResManager *DockableView::splitManager() const
|
|
{
|
|
return this->manager_inst;
|
|
}
|
|
|
|
split_frame::SplitView *DockableView::parentRes() const
|
|
{
|
|
return parent_res;
|
|
}
|
|
|
|
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
|
|
{
|
|
return const_cast<DockableView*>(this);
|
|
}
|
|
|
|
bool DockableView::canRetrieve() const
|
|
{
|
|
return m_retrieve;
|
|
}
|
|
|
|
bool DockableView::canClose() const
|
|
{
|
|
return m_close;
|
|
}
|
|
|
|
bool DockableView::canReplace() const
|
|
{
|
|
return m_replace;
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
QString DockableView::title() const
|
|
{
|
|
return title_header->windowTitle();
|
|
}
|
|
|
|
QSizeF DockableView::stiffSize() const
|
|
{
|
|
auto sizex = present_cube->minimumSize();
|
|
sizex.setHeight(sizex.height() + title_header->height());
|
|
return sizex;
|
|
}
|
|
|
|
QRectF DockableView::outlineRect() const
|
|
{
|
|
return this->rect();
|
|
}
|
|
|
|
void DockableView::setOutline(const QRectF &rect)
|
|
{
|
|
this->setGeometry(rect.toRect());
|
|
}
|