Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Function to call manually to update tab dropdown #28

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
1 change: 1 addition & 0 deletions AdvancedDockingSystem/include/ads/API.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class QSplitter;
ADS_NAMESPACE_BEGIN
class ContainerWidget;
class SectionWidget;
class SectionContent;

enum DropArea
{
Expand Down
11 changes: 8 additions & 3 deletions AdvancedDockingSystem/include/ads/ContainerWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ class ADS_EXPORT_API ContainerWidget : public QFrame
* Deserilizes the state of contents from <em>data</em>, which was written with <em>saveState()</em>.
* \see saveState()
*/
bool restoreState(const QByteArray& data);
bool restoreState(const QByteArray& data);


//
// Advanced Public API
// You usually should not need access to this methods
//
Expand All @@ -117,7 +117,12 @@ class ADS_EXPORT_API ContainerWidget : public QFrame
*/
QList<SectionContent::RefPtr> contents() const;

QPointer<DropOverlay> dropOverlay() const;
QPointer<DropOverlay> dropOverlay() const;

// return section widgets to be sure to add new dock to an existing one
const QList<SectionWidget*>& sectionWidgets() const;

void updateSectionContentTabMenus();

private:
//
Expand Down
13 changes: 12 additions & 1 deletion AdvancedDockingSystem/src/ContainerWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,13 @@ ContainerWidget::ContainerWidget(QWidget *parent) :
_mainLayout->setContentsMargins(9, 9, 9, 9);
_mainLayout->setSpacing(0);
setLayout(_mainLayout);
}
}

void ContainerWidget::updateSectionContentTabMenus()
{
for(auto& section : _sections)
section->updateTabsMenu();
}

ContainerWidget::~ContainerWidget()
{
Expand Down Expand Up @@ -479,6 +485,11 @@ SectionWidget* ContainerWidget::newSectionWidget()
_sections.append(sw);
return sw;
}

const QList<SectionWidget*>& ContainerWidget::sectionWidgets() const
{
return _sections;
}

SectionWidget* ContainerWidget::dropContent(const InternalContentData& data, SectionWidget* targetSection, DropArea area, bool autoActive)
{
Expand Down
8 changes: 4 additions & 4 deletions AdvancedDockingSystem/src/FloatingWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,17 @@ FloatingWidget::FloatingWidget(ContainerWidget* container, SectionContent::RefPt

if (sc->flags().testFlag(SectionContent::Closeable))
{
QPushButton* closeButton = new QPushButton();
/*QPushButton* closeButton = new QPushButton();
closeButton->setObjectName("closeButton");
closeButton->setFlat(true);
closeButton->setIcon(style()->standardIcon(QStyle::SP_TitleBarCloseButton));
closeButton->setToolTip(tr("Close"));
closeButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
_titleLayout->addWidget(closeButton);
_titleLayout->addWidget(closeButton);*/
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
QObject::connect(closeButton, &QPushButton::clicked, this, &FloatingWidget::onCloseButtonClicked);
//QObject::connect(closeButton, &QPushButton::clicked, this, &FloatingWidget::onCloseButtonClicked);
#else
QObject::connect(closeButton, SIGNAL(clicked(bool)), this, SLOT(onCloseButtonClicked()));
//QObject::connect(closeButton, SIGNAL(clicked(bool)), this, SLOT(onCloseButtonClicked()));
#endif
}

Expand Down
89 changes: 48 additions & 41 deletions AdvancedDockingSystem/src/SectionTitleWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <QCursor>
#include <QStyle>
#include <QSplitter>
#include <QLabel>

#ifdef ADS_ANIMATIONS_ENABLED
#include <QPropertyAnimation>
Expand All @@ -24,13 +25,12 @@

ADS_NAMESPACE_BEGIN

SectionTitleWidget::SectionTitleWidget(SectionContent::RefPtr content, QWidget* parent) :
QFrame(parent),
_content(content),
_tabMoving(false),
_activeTab(false)
SectionTitleWidget::SectionTitleWidget(SectionContent::RefPtr content, QWidget *parent) : QFrame(parent),
_content(content),
_tabMoving(false),
_activeTab(false)
{
QBoxLayout* l = new QBoxLayout(QBoxLayout::LeftToRight);
QBoxLayout *l = new QBoxLayout(QBoxLayout::LeftToRight);
l->setContentsMargins(0, 0, 0, 0);
l->setSpacing(0);
l->addWidget(content->titleWidget());
Expand All @@ -57,11 +57,27 @@ void SectionTitleWidget::setActiveTab(bool active)
style()->polish(this);
update();

if (auto titleWidget = _content->titleWidget())
{
titleWidget->style()->unpolish(titleWidget);
titleWidget->style()->polish(titleWidget);
titleWidget->update();

// also find QLabel below that and unpolish them (special titleWidget)
QWidget *labelChild = titleWidget->findChild<QLabel *>();
if (labelChild)
{
labelChild->style()->unpolish(labelChild);
labelChild->style()->polish(labelChild);
labelChild->update();
}
}

emit activeTabChanged();
}
}

void SectionTitleWidget::mousePressEvent(QMouseEvent* ev)
void SectionTitleWidget::mousePressEvent(QMouseEvent *ev)
{
if (ev->button() == Qt::LeftButton)
{
Expand All @@ -72,15 +88,15 @@ void SectionTitleWidget::mousePressEvent(QMouseEvent* ev)
QFrame::mousePressEvent(ev);
}

void SectionTitleWidget::mouseReleaseEvent(QMouseEvent* ev)
void SectionTitleWidget::mouseReleaseEvent(QMouseEvent *ev)
{
SectionWidget* section = NULL;
ContainerWidget* cw = findParentContainerWidget(this);
SectionWidget *section = NULL;
ContainerWidget *cw = findParentContainerWidget(this);

// Drop contents of FloatingWidget into SectionWidget.
if (_fw)
{
SectionWidget* sw = cw->sectionAt(cw->mapFromGlobal(ev->globalPos()));
SectionWidget *sw = cw->sectionAt(cw->mapFromGlobal(ev->globalPosition().toPoint()));
if (sw)
{
cw->_dropOverlay->setAllowedAreas(ADS_NS::AllAreas);
Expand All @@ -98,24 +114,23 @@ void SectionTitleWidget::mouseReleaseEvent(QMouseEvent* ev)
#endif
cw->dropContent(data, sw, loc, true);
#else
QPropertyAnimation* moveAnim = new QPropertyAnimation(_fw, "pos", this);
QPropertyAnimation *moveAnim = new QPropertyAnimation(_fw, "pos", this);
moveAnim->setStartValue(_fw->pos());
moveAnim->setEndValue(sw->mapToGlobal(sw->rect().topLeft()));
moveAnim->setDuration(ADS_ANIMATION_DURATION);

QPropertyAnimation* resizeAnim = new QPropertyAnimation(_fw, "size", this);
QPropertyAnimation *resizeAnim = new QPropertyAnimation(_fw, "size", this);
resizeAnim->setStartValue(_fw->size());
resizeAnim->setEndValue(sw->size());
resizeAnim->setDuration(ADS_ANIMATION_DURATION);

QParallelAnimationGroup* animGroup = new QParallelAnimationGroup(this);
QParallelAnimationGroup *animGroup = new QParallelAnimationGroup(this);
QObject::connect(animGroup, &QPropertyAnimation::finished, [this, data, sw, loc]()
{
{
InternalContentData data = _fw->takeContent();
_fw->deleteLater();
_fw.clear();
cw->dropContent(data, sw, loc);
});
cw->dropContent(data, sw, loc); });
animGroup->addAnimation(moveAnim);
animGroup->addAnimation(resizeAnim);
animGroup->start(QAbstractAnimation::DeleteWhenStopped);
Expand All @@ -126,13 +141,13 @@ void SectionTitleWidget::mouseReleaseEvent(QMouseEvent* ev)
else
{
DropArea dropArea = ADS_NS::InvalidDropArea;
if (cw->outerTopDropRect().contains(cw->mapFromGlobal(ev->globalPos())))
if (cw->outerTopDropRect().contains(cw->mapFromGlobal(ev->globalPosition().toPoint())))
dropArea = ADS_NS::TopDropArea;
if (cw->outerRightDropRect().contains(cw->mapFromGlobal(ev->globalPos())))
if (cw->outerRightDropRect().contains(cw->mapFromGlobal(ev->globalPosition().toPoint())))
dropArea = ADS_NS::RightDropArea;
if (cw->outerBottomDropRect().contains(cw->mapFromGlobal(ev->globalPos())))
if (cw->outerBottomDropRect().contains(cw->mapFromGlobal(ev->globalPosition().toPoint())))
dropArea = ADS_NS::BottomDropArea;
if (cw->outerLeftDropRect().contains(cw->mapFromGlobal(ev->globalPos())))
if (cw->outerLeftDropRect().contains(cw->mapFromGlobal(ev->globalPosition().toPoint())))
dropArea = ADS_NS::LeftDropArea;

if (dropArea != ADS_NS::InvalidDropArea)
Expand All @@ -153,11 +168,10 @@ void SectionTitleWidget::mouseReleaseEvent(QMouseEvent* ev)
}
}
// End of tab moving, change order now
else if (_tabMoving
&& (section = findParentSectionWidget(this)) != NULL)
else if (_tabMoving && (section = findParentSectionWidget(this)) != NULL)
{
// Find tab under mouse
QPoint pos = ev->globalPos();
QPoint pos = ev->globalPosition().toPoint();
pos = section->mapFromGlobal(pos);
const int fromIndex = section->indexOfContent(_content);
const int toIndex = section->indexOfContentByTitlePos(pos, this);
Expand All @@ -174,17 +188,17 @@ void SectionTitleWidget::mouseReleaseEvent(QMouseEvent* ev)
QFrame::mouseReleaseEvent(ev);
}

void SectionTitleWidget::mouseMoveEvent(QMouseEvent* ev)
void SectionTitleWidget::mouseMoveEvent(QMouseEvent *ev)
{
ContainerWidget* cw = findParentContainerWidget(this);
SectionWidget* section = NULL;
ContainerWidget *cw = findParentContainerWidget(this);
SectionWidget *section = NULL;

// Move already existing FloatingWidget
if (_fw && (ev->buttons() & Qt::LeftButton))
{
ev->accept();

const QPoint moveToPos = ev->globalPos() - (_dragStartPos + QPoint(ADS_WINDOW_FRAME_BORDER_WIDTH, ADS_WINDOW_FRAME_BORDER_WIDTH));
const QPoint moveToPos = ev->globalPosition().toPoint() - (_dragStartPos + QPoint(ADS_WINDOW_FRAME_BORDER_WIDTH, ADS_WINDOW_FRAME_BORDER_WIDTH));
_fw->move(moveToPos);

// Show drop indicator
Expand Down Expand Up @@ -227,9 +241,7 @@ void SectionTitleWidget::mouseMoveEvent(QMouseEvent* ev)
return;
}
// Begin to drag/float the SectionContent.
else if (!_fw && !_dragStartPos.isNull() && (ev->buttons() & Qt::LeftButton)
&& (section = findParentSectionWidget(this)) != NULL
&& !section->titleAreaGeometry().contains(section->mapFromGlobal(ev->globalPos())))
else if (!_fw && !_dragStartPos.isNull() && (ev->buttons() & Qt::LeftButton) && (section = findParentSectionWidget(this)) != NULL && !section->titleAreaGeometry().contains(section->mapFromGlobal(ev->globalPosition().toPoint())))
{
ev->accept();

Expand All @@ -245,7 +257,7 @@ void SectionTitleWidget::mouseMoveEvent(QMouseEvent* ev)
_fw->resize(section->size());
cw->_floatings.append(_fw); // Note: I don't like this...

const QPoint moveToPos = ev->globalPos() - (_dragStartPos + QPoint(ADS_WINDOW_FRAME_BORDER_WIDTH, ADS_WINDOW_FRAME_BORDER_WIDTH));
const QPoint moveToPos = ev->globalPosition().toPoint() - (_dragStartPos + QPoint(ADS_WINDOW_FRAME_BORDER_WIDTH, ADS_WINDOW_FRAME_BORDER_WIDTH));
_fw->move(moveToPos);
_fw->show();

Expand All @@ -259,24 +271,19 @@ void SectionTitleWidget::mouseMoveEvent(QMouseEvent* ev)
return;
}
// Handle movement of this tab
else if (_tabMoving
&& (section = findParentSectionWidget(this)) != NULL)
else if (_tabMoving && (section = findParentSectionWidget(this)) != NULL)
{
ev->accept();

int left, top, right, bottom;
getContentsMargins(&left, &top, &right, &bottom);
QPoint moveToPos = mapToParent(ev->pos()) - _dragStartPos;
moveToPos.setY(0/* + top*/);
moveToPos.setY(0 /* + top*/);
move(moveToPos);

return;
}
// Begin to drag title inside the title area to switch its position inside the SectionWidget.
else if (!_dragStartPos.isNull() && (ev->buttons() & Qt::LeftButton)
&& (ev->pos() - _dragStartPos).manhattanLength() >= QApplication::startDragDistance() // Wait a few pixels before start moving
&& (section = findParentSectionWidget(this)) != NULL
&& section->titleAreaGeometry().contains(section->mapFromGlobal(ev->globalPos())))
else if (!_dragStartPos.isNull() && (ev->buttons() & Qt::LeftButton) && (ev->pos() - _dragStartPos).manhattanLength() >= QApplication::startDragDistance() // Wait a few pixels before start moving
&& (section = findParentSectionWidget(this)) != NULL && section->titleAreaGeometry().contains(section->mapFromGlobal(ev->globalPosition().toPoint())))
{
ev->accept();

Expand Down
14 changes: 7 additions & 7 deletions AdvancedDockingSystem/src/SectionWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,18 @@ SectionWidget::SectionWidget(ContainerWidget* parent) :
#else
//QObject::connect(_tabsMenuButton, SIGNAL(clicked()), this, SLOT(onTabsMenuButtonClicked()));
#endif

_closeButton = new QPushButton();
/*_closeButton = new QPushButton();
_closeButton->setObjectName("closeButton");
_closeButton->setFlat(true);
_closeButton->setIcon(style()->standardIcon(QStyle::SP_TitleBarCloseButton));
_closeButton->setToolTip(tr("Close"));
_closeButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
_topLayout->addWidget(_closeButton, 0);
_topLayout->addWidget(_closeButton, 0);*/
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
QObject::connect(_closeButton, &QPushButton::clicked, this, &SectionWidget::onCloseButtonClicked);
//QObject::connect(_closeButton, &QPushButton::clicked, this, &SectionWidget::onCloseButtonClicked);
#else
QObject::connect(_closeButton, SIGNAL(clicked(bool)), this, SLOT(onCloseButtonClicked()));
//QObject::connect(_closeButton, SIGNAL(clicked(bool)), this, SLOT(onCloseButtonClicked()));
#endif

_tabsLayoutInitCount = _tabsLayout->count();
Expand Down Expand Up @@ -349,10 +349,10 @@ void SectionWidget::setCurrentIndex(int index)
{
stw->setActiveTab(true);
_tabsScrollArea->ensureWidgetVisible(stw);
if (stw->_content->flags().testFlag(SectionContent::Closeable))
/*if (stw->_content->flags().testFlag(SectionContent::Closeable))
_closeButton->setEnabled(true);
else
_closeButton->setEnabled(false);
_closeButton->setEnabled(false);*/
}
else
stw->setActiveTab(false);
Expand Down