|
| 1 | +//============================================================================ |
| 2 | +/// \file DockAreaTabBar.cpp |
| 3 | +/// \author Uwe Kindler |
| 4 | +/// \date 24.08.2018 |
| 5 | +/// \brief Implementation of CDockAreaTabBar class |
| 6 | +//============================================================================ |
| 7 | + |
| 8 | +//============================================================================ |
| 9 | +// INCLUDES |
| 10 | +//============================================================================ |
| 11 | +#include "DockAreaTabBar.h" |
| 12 | + |
| 13 | +#include <QMouseEvent> |
| 14 | +#include <QScrollBar> |
| 15 | +#include <QDebug> |
| 16 | + |
| 17 | +#include "FloatingDockContainer.h" |
| 18 | +#include "DockAreaWidget.h" |
| 19 | +#include "DockOverlay.h" |
| 20 | +#include "DockManager.h" |
| 21 | + |
| 22 | +namespace ads |
| 23 | +{ |
| 24 | +/** |
| 25 | + * Private data class of CDockAreaTabBar class (pimpl) |
| 26 | + */ |
| 27 | +struct DockAreaTabBarPrivate |
| 28 | +{ |
| 29 | + CDockAreaTabBar* _this; |
| 30 | + QPoint DragStartMousePos; |
| 31 | + CDockAreaWidget* DockArea; |
| 32 | + CFloatingDockContainer* FloatingWidget = nullptr; |
| 33 | + |
| 34 | + /** |
| 35 | + * Private data constructor |
| 36 | + */ |
| 37 | + DockAreaTabBarPrivate(CDockAreaTabBar* _public); |
| 38 | +}; |
| 39 | +// struct DockAreaTabBarPrivate |
| 40 | + |
| 41 | +//============================================================================ |
| 42 | +DockAreaTabBarPrivate::DockAreaTabBarPrivate(CDockAreaTabBar* _public) : |
| 43 | + _this(_public) |
| 44 | +{ |
| 45 | + |
| 46 | +} |
| 47 | + |
| 48 | +//============================================================================ |
| 49 | +CDockAreaTabBar::CDockAreaTabBar(CDockAreaWidget* parent) : |
| 50 | + QScrollArea(parent), |
| 51 | + d(new DockAreaTabBarPrivate(this)) |
| 52 | +{ |
| 53 | + d->DockArea = parent; |
| 54 | + setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Ignored); |
| 55 | + setFrameStyle(QFrame::NoFrame); |
| 56 | + setWidgetResizable(true); |
| 57 | + setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
| 58 | + setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
| 59 | +} |
| 60 | + |
| 61 | +//============================================================================ |
| 62 | +CDockAreaTabBar::~CDockAreaTabBar() |
| 63 | +{ |
| 64 | + delete d; |
| 65 | +} |
| 66 | + |
| 67 | + |
| 68 | +//============================================================================ |
| 69 | +void CDockAreaTabBar::wheelEvent(QWheelEvent* Event) |
| 70 | +{ |
| 71 | + Event->accept(); |
| 72 | + const int direction = Event->angleDelta().y(); |
| 73 | + if (direction < 0) |
| 74 | + { |
| 75 | + horizontalScrollBar()->setValue(horizontalScrollBar()->value() + 20); |
| 76 | + } |
| 77 | + else |
| 78 | + { |
| 79 | + horizontalScrollBar()->setValue(horizontalScrollBar()->value() - 20); |
| 80 | + } |
| 81 | +} |
| 82 | + |
| 83 | + |
| 84 | +//============================================================================ |
| 85 | +void CDockAreaTabBar::mousePressEvent(QMouseEvent* ev) |
| 86 | +{ |
| 87 | + if (ev->button() == Qt::LeftButton) |
| 88 | + { |
| 89 | + ev->accept(); |
| 90 | + d->DragStartMousePos = ev->pos(); |
| 91 | + return; |
| 92 | + } |
| 93 | + QScrollArea::mousePressEvent(ev); |
| 94 | +} |
| 95 | + |
| 96 | + |
| 97 | +//============================================================================ |
| 98 | +void CDockAreaTabBar::mouseReleaseEvent(QMouseEvent* ev) |
| 99 | +{ |
| 100 | + if (ev->button() == Qt::LeftButton) |
| 101 | + { |
| 102 | + qDebug() << "CTabsScrollArea::mouseReleaseEvent"; |
| 103 | + ev->accept(); |
| 104 | + d->FloatingWidget = nullptr; |
| 105 | + d->DragStartMousePos = QPoint(); |
| 106 | + return; |
| 107 | + } |
| 108 | + QScrollArea::mouseReleaseEvent(ev); |
| 109 | +} |
| 110 | + |
| 111 | + |
| 112 | +//============================================================================ |
| 113 | +void CDockAreaTabBar::mouseMoveEvent(QMouseEvent* ev) |
| 114 | +{ |
| 115 | + QScrollArea::mouseMoveEvent(ev); |
| 116 | + if (ev->buttons() != Qt::LeftButton) |
| 117 | + { |
| 118 | + return; |
| 119 | + } |
| 120 | + |
| 121 | + if (d->FloatingWidget) |
| 122 | + { |
| 123 | + d->FloatingWidget->moveFloating(); |
| 124 | + return; |
| 125 | + } |
| 126 | + |
| 127 | + // If this is the last dock area in a dock container it does not make |
| 128 | + // sense to move it to a new floating widget and leave this one |
| 129 | + // empty |
| 130 | + if (d->DockArea->dockContainer()->isFloating() |
| 131 | + && d->DockArea->dockContainer()->visibleDockAreaCount() == 1) |
| 132 | + { |
| 133 | + return; |
| 134 | + } |
| 135 | + |
| 136 | + if (!this->geometry().contains(ev->pos())) |
| 137 | + { |
| 138 | + qDebug() << "CTabsScrollArea::startFloating"; |
| 139 | + startFloating(d->DragStartMousePos); |
| 140 | + auto Overlay = d->DockArea->dockManager()->containerOverlay(); |
| 141 | + Overlay->setAllowedAreas(OuterDockAreas); |
| 142 | + } |
| 143 | + |
| 144 | + return; |
| 145 | +} |
| 146 | + |
| 147 | + |
| 148 | +//============================================================================ |
| 149 | +void CDockAreaTabBar::mouseDoubleClickEvent(QMouseEvent *event) |
| 150 | +{ |
| 151 | + // If this is the last dock area in a dock container it does not make |
| 152 | + // sense to move it to a new floating widget and leave this one |
| 153 | + // empty |
| 154 | + if (d->DockArea->dockContainer()->isFloating() && d->DockArea->dockContainer()->dockAreaCount() == 1) |
| 155 | + { |
| 156 | + return; |
| 157 | + } |
| 158 | + startFloating(event->pos()); |
| 159 | +} |
| 160 | + |
| 161 | + |
| 162 | +//============================================================================ |
| 163 | +void CDockAreaTabBar::startFloating(const QPoint& Pos) |
| 164 | +{ |
| 165 | + QSize Size = d->DockArea->size(); |
| 166 | + CFloatingDockContainer* FloatingWidget = new CFloatingDockContainer(d->DockArea); |
| 167 | + FloatingWidget->startFloating(Pos, Size); |
| 168 | + d->FloatingWidget = FloatingWidget; |
| 169 | +} |
| 170 | +} // namespace ads |
| 171 | + |
| 172 | +//--------------------------------------------------------------------------- |
| 173 | +// EOF DockAreaTabBar.cpp |
0 commit comments