mirror of
https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System.git
synced 2024-12-25 07:31:33 +08:00
Central widget update
Updated the setting of central widget with option to set where the possible old central widget will be placed. Fixed option of "unsetting" central widget by setting it to nullptr.
This commit is contained in:
parent
691c9683ce
commit
14c29f695c
1
.gitignore
vendored
1
.gitignore
vendored
@ -382,3 +382,4 @@ MigrationBackup/
|
||||
FodyWeavers.xsd
|
||||
/ build
|
||||
/Settings.ini
|
||||
.vscode/settings.json
|
||||
|
@ -22,12 +22,10 @@ DEFINES += QT_DEPRECATED_WARNINGS
|
||||
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
|
||||
|
||||
SOURCES += \
|
||||
digitalclock.cpp \
|
||||
main.cpp \
|
||||
mainwindow.cpp
|
||||
|
||||
HEADERS += \
|
||||
digitalclock.h \
|
||||
mainwindow.h
|
||||
|
||||
FORMS += \
|
||||
|
@ -1,27 +0,0 @@
|
||||
#include "digitalclock.h"
|
||||
|
||||
#include <QTime>
|
||||
#include <QTimer>
|
||||
|
||||
CDigitalClock::CDigitalClock(QWidget *parent)
|
||||
: QLCDNumber(parent)
|
||||
{
|
||||
setDigitCount(8);
|
||||
setSegmentStyle(Filled);
|
||||
|
||||
QTimer *timer = new QTimer(this);
|
||||
connect(timer, &QTimer::timeout, this, &CDigitalClock::showTime);
|
||||
timer->start(1000);
|
||||
|
||||
showTime();
|
||||
|
||||
setWindowTitle(tr("Digital Clock"));
|
||||
resize(150, 60);
|
||||
}
|
||||
|
||||
void CDigitalClock::showTime()
|
||||
{
|
||||
QTime time = QTime::currentTime();
|
||||
QString text = time.toString("hh:mm:ss");
|
||||
display(text);
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
#ifndef DIGITALCLOCK_H
|
||||
#define DIGITALCLOCK_H
|
||||
|
||||
#include <QLCDNumber>
|
||||
|
||||
class CDigitalClock : public QLCDNumber
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
CDigitalClock(QWidget *parent = nullptr);
|
||||
|
||||
private slots:
|
||||
void showTime();
|
||||
};
|
||||
|
||||
#endif // DIGITALCLOCK_H
|
@ -1,6 +1,5 @@
|
||||
#include "mainwindow.h"
|
||||
#include "ui_mainwindow.h"
|
||||
#include "digitalclock.h"
|
||||
|
||||
#include <QWidgetAction>
|
||||
#include <QLabel>
|
||||
@ -96,12 +95,8 @@ CMainWindow::CMainWindow(QWidget *parent)
|
||||
QCalendarWidget* calendar = new QCalendarWidget();
|
||||
CDockWidget* CentralDockWidget = new CDockWidget("CentralWidget");
|
||||
CentralDockWidget->setWidget(calendar);
|
||||
CentralDockWidget->setFeature(CDockWidget::DockWidgetClosable, false);
|
||||
CentralDockWidget->setFeature(CDockWidget::DockWidgetMovable, false);
|
||||
CentralDockWidget->setFeature(CDockWidget::DockWidgetFloatable, false);
|
||||
auto* CentralDockArea = DockManager->setCentralWidget(CentralDockWidget);
|
||||
CentralDockArea->setAllowedAreas(DockWidgetArea::OuterDockAreas);
|
||||
CentralDockArea->setDockAreaFlag(CDockAreaWidget::eDockAreaFlag::HideSingleWidgetTitleBar, true);
|
||||
|
||||
QTreeView* fileTree = new QTreeView();
|
||||
fileTree->setFrameShape(QFrame::NoFrame);
|
||||
@ -139,20 +134,18 @@ CMainWindow::CMainWindow(QWidget *parent)
|
||||
QRadioButton* radioDockTop = new QRadioButton("Top", timeLineWidget);
|
||||
QRadioButton* radioDockBottom = new QRadioButton("Bottom", timeLineWidget);
|
||||
radioDockTop->setChecked(true);
|
||||
timelineLayout->addWidget(new QLabel("Fixed height Dock widget."));
|
||||
timelineLayout->addWidget(new QLabel("Test Widget."));
|
||||
timelineLayout->addStretch(1);
|
||||
timelineLayout->addWidget(new QLabel("Apply predefined perspective: ", this));
|
||||
timelineLayout->addWidget(radioDockTop);
|
||||
timelineLayout->addWidget(radioDockBottom);
|
||||
TimelineDockWidget = new CDockWidget("Timeline");
|
||||
TimelineDockWidget->setWidget(timeLineWidget);
|
||||
// TimelineDockWidget->setResizeMode(CDockWidget::eResizeMode::ResizeHorizontal);
|
||||
TimelineDockWidget->setFeature(CDockWidget::DockWidgetClosable, false);
|
||||
TimelineDockWidget->setFeature(CDockWidget::DockWidgetMovable, false);
|
||||
TimelineDockWidget->setFeature(CDockWidget::DockWidgetFloatable, false);
|
||||
TimelineDockWidget->setMinimumSizeHintMode(CDockWidget::MinimumSizeHintFromDockWidget);
|
||||
TimelineDockWidget->setMinimumSize(QSize(50, 50));
|
||||
TimelineDockWidget->setFixedHeight(50);
|
||||
auto *TimelineDockArea = DockManager->addDockWidget(DockWidgetArea::TopDockWidgetArea, TimelineDockWidget);
|
||||
TimelineDockArea->setDockAreaFlag(CDockAreaWidget::eDockAreaFlag::HideSingleWidgetTitleBar, true);
|
||||
TimelineDockArea->setAllowedAreas(DockWidgetArea::OuterDockAreas);
|
||||
@ -177,7 +170,6 @@ CMainWindow::CMainWindow(QWidget *parent)
|
||||
QWidget* statusWidget = new QWidget();
|
||||
QHBoxLayout* statusLayout = new QHBoxLayout(statusWidget);
|
||||
statusLayout->setSpacing(10);
|
||||
CDigitalClock* clock = new CDigitalClock(statusWidget);
|
||||
statusLayout->addWidget(new QLabel("Status Bar"));
|
||||
QPushButton* OpenPerspectiveButton = new QPushButton("Open Perspective", statusWidget);
|
||||
connect(OpenPerspectiveButton, &QPushButton::clicked, [this](){
|
||||
@ -215,19 +207,16 @@ CMainWindow::CMainWindow(QWidget *parent)
|
||||
statusLayout->addWidget(OpenPerspectiveButton);
|
||||
statusLayout->addWidget(SavePerspectiveButton);
|
||||
statusLayout->addStretch(1);
|
||||
statusLayout->addWidget(clock);
|
||||
CDockWidget* StatusDockWidget = new CDockWidget("Status");
|
||||
StatusDockWidget->setWidget(statusWidget);
|
||||
// StatusDockWidget->setResizeMode(CDockWidget::eResizeMode::ResizeHorizontal);
|
||||
StatusDockWidget->setFeature(CDockWidget::DockWidgetClosable, false);
|
||||
StatusDockWidget->setFeature(CDockWidget::DockWidgetMovable, false);
|
||||
StatusDockWidget->setFeature(CDockWidget::DockWidgetFloatable, false);
|
||||
StatusDockWidget->setMinimumSizeHintMode(CDockWidget::MinimumSizeHintFromDockWidget);
|
||||
StatusDockWidget->setMinimumSize(QSize(50, 50));
|
||||
StatusDockWidget->setFixedHeight(50);
|
||||
StatusDockArea = DockManager->addDockWidget(DockWidgetArea::BottomDockWidgetArea, StatusDockWidget);
|
||||
StatusDockArea->setAllowedAreas(DockWidgetArea::OuterDockAreas);
|
||||
StatusDockArea->setDockAreaFlag(CDockAreaWidget::eDockAreaFlag::HideSingleWidgetTitleBar, true);
|
||||
StatusDockArea->setDockAreaFlag(ads::CDockAreaWidget::eDockAreaFlag::HideSingleWidgetTitleBar, true);
|
||||
}
|
||||
|
||||
CMainWindow::~CMainWindow()
|
||||
|
@ -711,11 +711,14 @@ void DockContainerWidgetPrivate::moveToNewSection(QWidget* Widget, CDockAreaWidg
|
||||
//============================================================================
|
||||
void DockContainerWidgetPrivate::updateSplitterHandles( QSplitter* splitter )
|
||||
{
|
||||
if( splitter )
|
||||
if(DockManager->centralWidget())
|
||||
{
|
||||
for( int index = 0; index < splitter->count(); index++ )
|
||||
if( splitter )
|
||||
{
|
||||
splitter->setStretchFactor(index, widgetResizesWithContainer(splitter->widget(index)) ? 1 : 0);
|
||||
for( int index = 0; index < splitter->count(); index++ )
|
||||
{
|
||||
splitter->setStretchFactor(index, widgetResizesWithContainer(splitter->widget(index)) ? 1 : 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1256,7 +1259,6 @@ CDockAreaWidget* DockContainerWidgetPrivate::addDockWidgetToDockArea(DockWidgetA
|
||||
auto TargetAreaSizes = TargetAreaSplitter->sizes();
|
||||
QSplitter* NewSplitter = newSplitter(InsertParam.orientation());
|
||||
NewSplitter->addWidget(TargetDockArea);
|
||||
// updateSplitterHandles(NewSplitter);
|
||||
|
||||
insertWidgetIntoSplitter(NewSplitter, NewDockArea, InsertParam.append());
|
||||
updateSplitterHandles(NewSplitter);
|
||||
|
@ -407,6 +407,7 @@ bool DockManagerPrivate::restoreState(const QByteArray& State, int version)
|
||||
return false;
|
||||
}
|
||||
|
||||
CentralWidget = nullptr;
|
||||
// Hide updates of floating widgets from use
|
||||
hideFloatingWidgets();
|
||||
markDockWidgetsDirty();
|
||||
@ -830,15 +831,25 @@ CDockWidget* CDockManager::centralWidget()
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
CDockAreaWidget* CDockManager::setCentralWidget(CDockWidget* widget)
|
||||
CDockAreaWidget* CDockManager::setCentralWidget(CDockWidget* widget, CDockWidget* oldCentralWidget, DockWidgetArea oldCentralWidgetArea)
|
||||
{
|
||||
if(d->CentralWidget)
|
||||
oldCentralWidget = d->CentralWidget;
|
||||
if(oldCentralWidget)
|
||||
{
|
||||
addDockWidget(RightDockWidgetArea, d->CentralWidget);
|
||||
addDockWidget(oldCentralWidgetArea, oldCentralWidget);
|
||||
}
|
||||
|
||||
d->CentralWidget = widget;
|
||||
return addDockWidget(CenterDockWidgetArea, widget);
|
||||
if(widget)
|
||||
{
|
||||
widget->setFeature(CDockWidget::DockWidgetClosable, false);
|
||||
widget->setFeature(CDockWidget::DockWidgetMovable, false);
|
||||
widget->setFeature(CDockWidget::DockWidgetFloatable, false);
|
||||
d->CentralWidget = widget;
|
||||
CDockAreaWidget* CentralArea = addDockWidget(CenterDockWidgetArea, widget);
|
||||
CentralArea->setDockAreaFlag(CDockAreaWidget::eDockAreaFlag::HideSingleWidgetTitleBar, true);
|
||||
return CentralArea;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
|
@ -387,8 +387,10 @@ public:
|
||||
* Adds dockwidget into the central area and marks it as central widget.
|
||||
* If central widget is set, it will be the only dock widget
|
||||
* that will resize with the dock container.
|
||||
* If a central widget does exist, it will be docked to oldCentralWidgetArea
|
||||
* and returned in oldCentralWidget.
|
||||
*/
|
||||
CDockAreaWidget* setCentralWidget(CDockWidget* widget);
|
||||
CDockAreaWidget* setCentralWidget(CDockWidget* widget, CDockWidget* oldCentralWidget = nullptr, DockWidgetArea oldCentralWidgetArea = DockWidgetArea::RightDockWidgetArea);
|
||||
|
||||
/**
|
||||
* Adds a toggle view action to the the internal view menu.
|
||||
|
Loading…
Reference in New Issue
Block a user