Skip to content

Commit

Permalink
feat: add "startDrag/stopDrag" for DTabBar
Browse files Browse the repository at this point in the history
Change-Id: I766bcec424d4c28b21e08c9f35daea60986e44d8
  • Loading branch information
zccrs committed Mar 6, 2018
1 parent 2b52248 commit 611bc0c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/widgets/dtabbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@

#include <private/qtabbar_p.h>
#define private public
#define protected public
#include <private/qdnd_p.h>
#include <private/qsimpledrag_p.h>
#include <private/qshapedpixmapdndwindow_p.h>
#undef private
#undef protected

DWIDGET_BEGIN_NAMESPACE

Expand Down Expand Up @@ -232,6 +234,8 @@ class DTabBarPrivate : public QTabBar, public DObjectPrivate

void initStyleOption(QStyleOptionTab *option, int tabIndex) const;

QTabBarPrivate *dd() const;

Q_SLOT void startDrag(int tabIndex);

void setupMovableTab();
Expand Down Expand Up @@ -1207,6 +1211,11 @@ void DTabBarPrivate::initStyleOption(QStyleOptionTab *option, int tabIndex) cons
QTabBar::initStyleOption(option, tabIndex);
}

QTabBarPrivate *DTabBarPrivate::dd() const
{
return reinterpret_cast<QTabBarPrivate *>(qGetPtrHelper(d_ptr));
}

DTabBar::DTabBar(QWidget *parent)
: QWidget(parent)
, DObject(*new DTabBarPrivate(this))
Expand Down Expand Up @@ -1580,6 +1589,25 @@ void DTabBar::setFlashColor(QColor flashColor)
d_func()->flashColor = flashColor;
}

void DTabBar::startDrag(int index)
{
D_D(DTabBar);

d->dd()->pressedIndex = index;
d->setupDragableTab();
}

void DTabBar::stopDrag(Qt::DropAction action)
{
if (QBasicDrag *drag = dynamic_cast<QBasicDrag*>(QDragManager::self()->m_platformDrag)) {
drag->cancel();
drag->m_executed_drop_action = action;

if (drag->m_eventLoop)
drag->m_eventLoop->quit();
}
}

void DTabBar::dragEnterEvent(QDragEnterEvent *e)
{
D_D(DTabBar);
Expand Down
3 changes: 3 additions & 0 deletions src/widgets/dtabbar.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,9 @@ public Q_SLOTS:
void setMaskColor(QColor maskColor);
void setFlashColor(QColor flashColor);

void startDrag(int index);
void stopDrag(Qt::DropAction action);

protected:
void dragEnterEvent(QDragEnterEvent *e) override;
void dragLeaveEvent(QDragLeaveEvent *e) override;
Expand Down

0 comments on commit 611bc0c

Please sign in to comment.