2020-05-20 02:26:57 +08:00
|
|
|
#include <QMainWindow>
|
|
|
|
#include <QAction>
|
|
|
|
#include <QTextEdit>
|
|
|
|
#include <QApplication>
|
|
|
|
#include <QMenuBar>
|
|
|
|
#include "DockManager.h"
|
|
|
|
|
2020-07-22 17:28:41 +08:00
|
|
|
|
|
|
|
class MainWindow : public QMainWindow
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
ads::CDockManager* m_DockManager = nullptr;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual void closeEvent(QCloseEvent *event) override
|
|
|
|
{
|
|
|
|
QMainWindow::closeEvent(event);
|
|
|
|
if (m_DockManager)
|
|
|
|
{
|
|
|
|
m_DockManager->deleteLater();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
void setDockManager(ads::CDockManager* DockManager) {m_DockManager = DockManager;}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2020-05-20 02:26:57 +08:00
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
QApplication a(argc, argv);
|
2020-07-22 17:28:41 +08:00
|
|
|
MainWindow w;
|
2020-05-20 02:26:57 +08:00
|
|
|
|
2020-06-06 20:59:03 +08:00
|
|
|
ads::CDockManager::setConfigFlag(ads::CDockManager::FocusHighlighting, true);
|
2020-06-14 22:12:56 +08:00
|
|
|
ads::CDockManager::setConfigFlag(ads::CDockManager::AllTabsHaveCloseButton, true);
|
2020-05-20 02:26:57 +08:00
|
|
|
auto dockManager = new ads::CDockManager(&w);
|
2020-07-22 17:28:41 +08:00
|
|
|
w.setDockManager(dockManager);
|
2020-07-04 05:24:20 +08:00
|
|
|
QObject::connect(dockManager, &ads::CDockManager::focusedDockWidgetChanged, [] (ads::CDockWidget* old, ads::CDockWidget* now) {
|
2020-07-07 20:38:03 +08:00
|
|
|
static int Count = 0;
|
|
|
|
qDebug() << Count++ << " CDockManager::focusedDockWidgetChanged old: " << (old ? old->objectName() : "-") << " now: " << now->objectName() << " visible: " << now->isVisible();
|
2020-07-04 05:24:20 +08:00
|
|
|
now->widget()->setFocus();
|
|
|
|
});
|
2020-05-20 02:26:57 +08:00
|
|
|
|
|
|
|
QAction *action = new QAction("New Delete On Close", &w);
|
|
|
|
w.menuBar()->addAction(action);
|
|
|
|
|
|
|
|
int i = 0;
|
|
|
|
QObject::connect(action, &QAction::triggered, [&]() {
|
|
|
|
auto dw = new ads::CDockWidget(QStringLiteral("test doc %1").arg(i++), &w);
|
|
|
|
auto editor = new QTextEdit(QStringLiteral("lorem ipsum..."), dw);
|
|
|
|
dw->setWidget(editor);
|
|
|
|
dw->setFeature(ads::CDockWidget::DockWidgetDeleteOnClose, true);
|
|
|
|
auto area = dockManager->addDockWidgetTab(ads::CenterDockWidgetArea, dw);
|
|
|
|
qDebug() << "doc dock widget created!" << dw << area;
|
|
|
|
});
|
|
|
|
|
|
|
|
action = new QAction("New", &w);
|
|
|
|
w.menuBar()->addAction(action);
|
|
|
|
QObject::connect(action, &QAction::triggered, [&]() {
|
|
|
|
auto dw = new ads::CDockWidget(QStringLiteral("test %1").arg(i++), &w);
|
|
|
|
auto editor = new QTextEdit(QStringLiteral("lorem ipsum..."), dw);
|
|
|
|
dw->setWidget(editor);
|
|
|
|
auto area = dockManager->addDockWidgetTab(ads::CenterDockWidgetArea, dw);
|
|
|
|
qDebug() << "dock widget created!" << dw << area;
|
|
|
|
});
|
|
|
|
|
|
|
|
w.show();
|
|
|
|
|
|
|
|
return a.exec();
|
|
|
|
}
|