-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
flutter: Added floating item and DockRegistry
- Loading branch information
Showing
14 changed files
with
146 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,8 +9,7 @@ | |
Contact KDAB at <[email protected]> for commercial licensing options. | ||
*/ | ||
|
||
import 'package:flutter/widgets.dart'; | ||
import 'package:signals_slots/signals_slots.dart'; | ||
part of kddockwidgets; | ||
|
||
/// represents the state of a dock widget | ||
|
@@ -24,7 +23,9 @@ class DockItem { | |
DockItem({ | ||
required this.uniqueName, | ||
this.guestWidget, | ||
}); | ||
}) { | ||
DockRegistry.instance.addDockItem(this); | ||
} | ||
|
||
String get title { | ||
if (_title.isNotEmpty) return _title; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
This file is part of KDDockWidgets. | ||
SPDX-FileCopyrightText: 2024 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]> | ||
Author: Sérgio Martins <[email protected]> | ||
SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only | ||
Contact KDAB at <[email protected]> for commercial licensing options. | ||
*/ | ||
|
||
part of kddockwidgets; | ||
|
||
class DockRegistry { | ||
static final DockRegistry _instance = DockRegistry._internal(); | ||
|
||
final floatingItems = <FloatingItem>[]; | ||
final dockItems = <DockItem>[]; | ||
|
||
void addFloatingItem(FloatingItem floatingItem) { | ||
if (floatingItems.contains(floatingItem)) { | ||
throw Exception("FloatingItem already exists in registry"); | ||
} | ||
|
||
if (floatingItemForDropArea(floatingItem.dropArea) != null) { | ||
throw Exception("Already have a floating item for this drop area"); | ||
} | ||
|
||
floatingItems.add(floatingItem); | ||
} | ||
|
||
void removeFloatingItem(FloatingItem floatingItem) { | ||
if (!floatingItems.contains(floatingItem)) { | ||
throw Exception("FloatingItem doesn't exists in registry"); | ||
} | ||
|
||
floatingItems.remove(floatingItem); | ||
} | ||
|
||
void addDockItem(DockItem dockItem) { | ||
if (dockItems.contains(dockItem)) { | ||
throw Exception("DockItem already exists in registry"); | ||
} | ||
|
||
dockItems.add(dockItem); | ||
} | ||
|
||
void removeDockItem(DockItem dockItem) { | ||
if (!dockItems.contains(dockItem)) { | ||
throw Exception("DockItem doesn't exists in registry"); | ||
} | ||
|
||
dockItems.remove(dockItem); | ||
} | ||
|
||
FloatingItem? floatingItemForDropArea(DropArea da) { | ||
for (FloatingItem floatingItem in floatingItems) { | ||
if (floatingItem.dropArea == da) { | ||
return floatingItem; | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
|
||
bool containsFloatingItem(FloatingItem floatingItem) { | ||
return floatingItems.contains(floatingItem); | ||
} | ||
|
||
factory DockRegistry() { | ||
return _instance; | ||
} | ||
DockRegistry._internal(); | ||
|
||
static DockRegistry get instance => _instance; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
This file is part of KDDockWidgets. | ||
SPDX-FileCopyrightText: 2024 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]> | ||
Author: Sérgio Martins <[email protected]> | ||
SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only | ||
Contact KDAB at <[email protected]> for commercial licensing options. | ||
*/ | ||
|
||
part of kddockwidgets; | ||
|
||
class FloatingItem implements ItemWithTitleBar { | ||
final dropArea = DropArea(); | ||
late final TitleBar titleBar; | ||
late final Connection _groupCountChangedConnection; | ||
|
||
FloatingItem() { | ||
DockRegistry.instance.addFloatingItem(this); | ||
titleBar = TitleBar(this); | ||
|
||
_groupCountChangedConnection = | ||
dropArea.layoutChanged.connect(onGroupCountChanged); | ||
} | ||
|
||
void onGroupCountChanged() { | ||
if (!dropArea.hasGroups()) { | ||
close(); | ||
} | ||
} | ||
|
||
@override | ||
void close() { | ||
if (!DockRegistry.instance.containsFloatingItem(this)) { | ||
// we're closed already, can be removed once we can _groupCountChangedConnection.disconnect() | ||
return; | ||
} | ||
|
||
// _groupCountChangedConnection.disconnect(); signals_slot bug | ||
DockRegistry.instance.removeFloatingItem(this); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,8 +9,8 @@ | |
Contact KDAB at <[email protected]> for commercial licensing options. | ||
*/ | ||
|
||
import 'package:KDDockWidgets/models/DockItem.dart'; | ||
import 'package:flutter/widgets.dart'; | ||
import 'package:KDDockWidgets/KDDockWidgets.dart'; | ||
|
||
class DockWidget extends StatefulWidget { | ||
final DockItem dockItem; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,6 @@ | |
Contact KDAB at <[email protected]> for commercial licensing options. | ||
*/ | ||
|
||
import 'package:KDDockWidgets/models/DockItem.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:KDDockWidgets/KDDockWidgets.dart'; | ||
import 'package:KDDockWidgets/private/Bindings.dart'; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters