forked from mfreiholz/Qt-Advanced-Docking-System
-
Notifications
You must be signed in to change notification settings - Fork 575
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the possibility to open an auto-hide dock on a drag & drop (#667)
* Add open auto-hide dock on hover from drag and drop (#663) * Fix formatting (#663) * Fix formatting#2 (#663) * Add AutoHideDragNDrop example
- Loading branch information
Showing
18 changed files
with
498 additions
and
17 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
cmake_minimum_required(VERSION 3.5) | ||
project(ads_example_autohide_dragndrop VERSION ${VERSION_SHORT}) | ||
find_package(QT NAMES Qt6 Qt5 COMPONENTS Core REQUIRED) | ||
find_package(Qt${QT_VERSION_MAJOR} 5.5 COMPONENTS Core Gui Widgets REQUIRED) | ||
set(CMAKE_INCLUDE_CURRENT_DIR ON) | ||
add_executable(AutoHideDragNDropExample WIN32 | ||
main.cpp | ||
mainwindow.cpp | ||
mainwindow.ui | ||
droppableitem.cpp | ||
) | ||
target_include_directories(AutoHideDragNDropExample PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/../../src") | ||
target_link_libraries(AutoHideDragNDropExample PRIVATE qt${QT_VERSION_MAJOR}advanceddocking) | ||
target_link_libraries(AutoHideDragNDropExample PUBLIC Qt${QT_VERSION_MAJOR}::Core | ||
Qt${QT_VERSION_MAJOR}::Gui | ||
Qt${QT_VERSION_MAJOR}::Widgets) | ||
set_target_properties(AutoHideDragNDropExample PROPERTIES | ||
AUTOMOC ON | ||
AUTORCC ON | ||
AUTOUIC ON | ||
CXX_STANDARD 14 | ||
CXX_STANDARD_REQUIRED ON | ||
CXX_EXTENSIONS OFF | ||
VERSION ${VERSION_SHORT} | ||
EXPORT_NAME "Qt Advanced Docking System Auto Hide With Drag N Drop Example" | ||
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${ads_PlatformDir}/lib" | ||
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${ads_PlatformDir}/lib" | ||
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${ads_PlatformDir}/bin" | ||
) |
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,36 @@ | ||
ADS_OUT_ROOT = $${OUT_PWD}/../.. | ||
|
||
QT += core gui widgets | ||
|
||
TARGET = AutoHideDragNDropExample | ||
DESTDIR = $${ADS_OUT_ROOT}/lib | ||
TEMPLATE = app | ||
CONFIG += c++14 | ||
CONFIG += debug_and_release | ||
adsBuildStatic { | ||
DEFINES += ADS_STATIC | ||
} | ||
|
||
# The following define makes your compiler emit warnings if you use | ||
# any Qt feature that has been marked deprecated (the exact warnings | ||
# depend on your compiler). Please consult the documentation of the | ||
# deprecated API in order to know how to port your code away from it. | ||
DEFINES += QT_DEPRECATED_WARNINGS | ||
|
||
SOURCES += \ | ||
main.cpp \ | ||
mainwindow.cpp \ | ||
droppableitem.cpp | ||
|
||
HEADERS += \ | ||
mainwindow.h | ||
droppableitem.h | ||
|
||
FORMS += \ | ||
mainwindow.ui | ||
|
||
LIBS += -L$${ADS_OUT_ROOT}/lib | ||
include(../../ads.pri) | ||
INCLUDEPATH += ../../src | ||
DEPENDPATH += ../../src | ||
|
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,37 @@ | ||
#include "droppableitem.h" | ||
|
||
#include <QDragEnterEvent> | ||
#include <QDragLeaveEvent> | ||
#include <QDropEvent> | ||
#include <QMimeData> | ||
#include <qsizepolicy.h> | ||
|
||
DroppableItem::DroppableItem(const QString& text, QWidget* parent) | ||
: QPushButton(text, parent) | ||
{ | ||
setAcceptDrops(true); | ||
setSizePolicy(QSizePolicy::Policy::Expanding, QSizePolicy::Policy::Expanding); | ||
} | ||
|
||
void DroppableItem::dragEnterEvent(QDragEnterEvent* event) | ||
{ | ||
if (event->mimeData()->hasText()) | ||
{ | ||
event->acceptProposedAction(); | ||
setCursor(Qt::DragMoveCursor); | ||
} | ||
} | ||
|
||
void DroppableItem::dragLeaveEvent(QDragLeaveEvent* event) | ||
{ | ||
unsetCursor(); | ||
} | ||
|
||
void DroppableItem::dropEvent(QDropEvent* event) | ||
{ | ||
if (event->mimeData()->hasText()) | ||
{ | ||
event->acceptProposedAction(); | ||
setText(event->mimeData()->text()); | ||
} | ||
} |
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,19 @@ | ||
#include <QObject> | ||
#include <QPushButton> | ||
|
||
class QDragEnterEvent; | ||
class QDragLeaveEvent; | ||
class QDropEvent; | ||
|
||
class DroppableItem : public QPushButton | ||
{ | ||
Q_OBJECT; | ||
|
||
public: | ||
DroppableItem(const QString& text = QString(), QWidget* parent = nullptr); | ||
|
||
protected: | ||
void dragEnterEvent(QDragEnterEvent* event) override; | ||
void dragLeaveEvent(QDragLeaveEvent* event) override; | ||
void dropEvent(QDropEvent* event) override; | ||
}; |
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,10 @@ | ||
#include <mainwindow.h> | ||
#include <QApplication> | ||
|
||
int main(int argc, char *argv[]) | ||
{ | ||
QApplication a(argc, argv); | ||
CMainWindow w; | ||
w.show(); | ||
return a.exec(); | ||
} |
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,84 @@ | ||
import os | ||
import sys | ||
|
||
from PyQt5 import uic | ||
from PyQt5.QtCore import Qt, QTimer, QDir, QSignalBlocker | ||
from PyQt5.QtGui import QCloseEvent, QIcon | ||
from PyQt5.QtWidgets import (QApplication, QLabel, QCalendarWidget, QFrame, QTreeView, | ||
QTableWidget, QFileSystemModel, QPlainTextEdit, QToolBar, | ||
QWidgetAction, QComboBox, QAction, QSizePolicy, QInputDialog) | ||
|
||
import PyQtAds as QtAds | ||
|
||
UI_FILE = os.path.join(os.path.dirname(__file__), 'mainwindow.ui') | ||
MainWindowUI, MainWindowBase = uic.loadUiType(UI_FILE) | ||
|
||
class MainWindow(MainWindowUI, MainWindowBase): | ||
|
||
def __init__(self, parent=None): | ||
super().__init__(parent) | ||
|
||
self.setupUi(self) | ||
|
||
QtAds.CDockManager.setConfigFlag(QtAds.CDockManager.OpaqueSplitterResize, True) | ||
QtAds.CDockManager.setConfigFlag(QtAds.CDockManager.XmlCompressionEnabled, False) | ||
QtAds.CDockManager.setConfigFlag(QtAds.CDockManager.FocusHighlighting, True) | ||
QtAds.CDockManager.setAutoHideConfigFlag(QtAds.CDockManager.AutoHideOpenOnDragHover, True); | ||
self.dock_manager = QtAds.CDockManager(self) | ||
|
||
# Set central widget | ||
text_edit = QPlainTextEdit() | ||
text_edit.setPlaceholderText("This is the central editor. Enter your text here.") | ||
central_dock_widget = QtAds.CDockWidget("CentralWidget") | ||
central_dock_widget.setWidget(text_edit) | ||
central_dock_area = self.dock_manager.setCentralWidget(central_dock_widget) | ||
central_dock_area.setAllowedAreas(QtAds.DockWidgetArea.OuterDockAreas) | ||
|
||
|
||
droppable_item = DroppableItem("Drop text here.") | ||
drop_dock_widget = QtAds.CDockWidget("Tab") | ||
drop_dock_widget.setWidget(droppable_item) | ||
drop_dock_widget.setMinimumSizeHintMode(QtAds.CDockWidget.MinimumSizeHintFromDockWidget) | ||
drop_dock_widget.setMinimumSize(200, 150) | ||
drop_dock_widget.setAcceptDrops(True) | ||
drop_area = self.dock_manager.addDockWidget(QtAds.DockWidgetArea.LeftDockWidgetArea, drop_dock_widget) | ||
drop_area.setAcceptDrops(True) | ||
self.menuView.addAction(drop_dock_widget.toggleViewAction()) | ||
|
||
self.create_perspective_ui() | ||
|
||
def create_perspective_ui(self): | ||
save_perspective_action = QAction("Create Perspective", self) | ||
save_perspective_action.triggered.connect(self.save_perspective) | ||
perspective_list_action = QWidgetAction(self) | ||
self.perspective_combobox = QComboBox(self) | ||
self.perspective_combobox.setSizeAdjustPolicy(QComboBox.AdjustToContents) | ||
self.perspective_combobox.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred) | ||
self.perspective_combobox.activated[str].connect(self.dock_manager.openPerspective) | ||
perspective_list_action.setDefaultWidget(self.perspective_combobox) | ||
self.toolBar.addSeparator() | ||
self.toolBar.addAction(perspective_list_action) | ||
self.toolBar.addAction(save_perspective_action) | ||
|
||
def save_perspective(self): | ||
perspective_name, ok = QInputDialog.getText(self, "Save Perspective", "Enter Unique name:") | ||
if not ok or not perspective_name: | ||
return | ||
|
||
self.dock_manager.addPerspective(perspective_name) | ||
blocker = QSignalBlocker(self.perspective_combobox) | ||
self.perspective_combobox.clear() | ||
self.perspective_combobox.addItems(self.dock_manager.perspectiveNames()) | ||
self.perspective_combobox.setCurrentText(perspective_name) | ||
|
||
def closeEvent(self, event: QCloseEvent): | ||
self.dock_manager.deleteLater() | ||
super().closeEvent(event) | ||
|
||
|
||
if __name__ == '__main__': | ||
app = QApplication(sys.argv) | ||
|
||
w = MainWindow() | ||
w.show() | ||
app.exec_() |
Oops, something went wrong.