Skip to content

Commit 9d00a27

Browse files
Merge pull request #7 from Opostol/master
DockWidgetMovable implemented, some signals introduced
2 parents f823b67 + b470dd5 commit 9d00a27

File tree

5 files changed

+41
-14
lines changed

5 files changed

+41
-14
lines changed

src/DockAreaWidget.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,9 @@ void CDockAreaWidget::setCurrentIndex(int index)
533533
{
534534
qWarning() << Q_FUNC_INFO << "Invalid index" << index;
535535
return;
536-
}
536+
}
537+
538+
emit currentChanging(index);
537539

538540
// Set active TAB and update all other tabs to be inactive
539541
for (int i = 0; i < d->TabsLayout->count(); ++i)

src/DockAreaWidget.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,13 @@ public slots:
187187
*/
188188
void tabBarClicked(int index);
189189

190+
/**
191+
* This signal is emitted when the tab bar's current tab is about to be changed. The new
192+
* current has the given index, or -1 if there isn't a new one.
193+
* @param index
194+
*/
195+
void currentChanging(int index);
196+
190197
/**
191198
* This signal is emitted when the tab bar's current tab changes. The new
192199
* current has the given index, or -1 if there isn't a new one

src/DockManager.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,8 @@ bool CDockManager::restoreState(const QByteArray &state, int version)
369369
}
370370
}
371371

372+
emit stateChanged();
373+
372374
return true;
373375
}
374376

src/DockManager.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,11 @@ public slots:
187187
* This signal is emitted if the list of perspectives changed
188188
*/
189189
void perspectiveListChanged();
190+
191+
/**
192+
* This signal is emitted if the state changed in restoreState
193+
*/
194+
void stateChanged();
190195
}; // class DockManager
191196
} // namespace ads
192197
//-----------------------------------------------------------------------------

src/DockWidgetTitleBar.cpp

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -240,16 +240,19 @@ void CDockWidgetTitleBar::mouseReleaseEvent(QMouseEvent* ev)
240240
// End of tab moving, change order now
241241
if (d->isDraggingState(DraggingTab) && d->DockArea)
242242
{
243-
// Find tab under mouse
244-
QPoint pos = d->DockArea->mapFromGlobal(ev->globalPos());
245-
int fromIndex = d->DockArea->tabIndex(d->DockWidget);
246-
int toIndex = d->DockArea->indexOfContentByTitlePos(pos, this);
247-
if (-1 == toIndex)
248-
{
249-
toIndex = d->DockArea->count() - 1;
243+
if (d->DockWidget->features() & CDockWidget::DockWidgetMovable) {
244+
// Find tab under mouse
245+
QPoint pos = d->DockArea->mapFromGlobal(ev->globalPos());
246+
int fromIndex = d->DockArea->tabIndex(d->DockWidget);
247+
int toIndex = d->DockArea->indexOfContentByTitlePos(pos, this);
248+
if (-1 == toIndex)
249+
{
250+
toIndex = d->DockArea->count() - 1;
251+
}
252+
qDebug() << "Move tab from " << fromIndex << " to " << toIndex;
253+
d->DockArea->reorderDockWidget(fromIndex, toIndex);
250254
}
251-
qDebug() << "Move tab from " << fromIndex << " to " << toIndex;
252-
d->DockArea->reorderDockWidget(fromIndex, toIndex);
255+
253256
}
254257

255258
if (!d->DragStartMousePosition.isNull())
@@ -275,27 +278,35 @@ void CDockWidgetTitleBar::mouseMoveEvent(QMouseEvent* ev)
275278

276279
if (d->isDraggingState(DraggingFloatingWidget))
277280
{
278-
d->FloatingWidget->moveFloating();
281+
if (d->DockWidget->features() & CDockWidget::DockWidgetMovable) {
282+
d->FloatingWidget->moveFloating();
283+
}
279284
QFrame::mouseMoveEvent(ev);
280285
return;
281286
}
282287

283288
// move tab
284289
if (d->isDraggingState(DraggingTab))
285290
{
286-
d->moveTab(ev);
291+
if (d->DockWidget->features() & CDockWidget::DockWidgetMovable) {
292+
d->moveTab(ev);
293+
}
287294
}
288295

289296
bool MouseInsideTitleArea = d->titleAreaGeometryContains(ev->globalPos());
290297
if (!MouseInsideTitleArea)
291298
{
292-
d->startFloating();
299+
if (d->DockWidget->features() & CDockWidget::DockWidgetMovable) {
300+
d->startFloating();
301+
}
293302
return;
294303
}
295304
else if (d->DockArea->count() > 1
296305
&& (ev->pos() - d->DragStartMousePosition).manhattanLength() >= QApplication::startDragDistance()) // Wait a few pixels before start moving
297306
{
298-
d->DragState = DraggingTab;
307+
if (d->DockWidget->features() & CDockWidget::DockWidgetMovable) {
308+
d->DragState = DraggingTab;
309+
}
299310
return;
300311
}
301312

0 commit comments

Comments
 (0)