mirror of
https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System.git
synced 2024-12-25 23:51:33 +08:00
Implemented proper updating of floating widget title
This commit is contained in:
parent
81523b0346
commit
6617cf6f19
@ -177,13 +177,13 @@ void MainWindowPrivate::createContent()
|
||||
DockWidget->setFeature(ads::CDockWidget::DockWidgetClosable, false);
|
||||
DockManager->addDockWidget(ads::LeftDockWidgetArea, DockWidget);
|
||||
DockManager->addDockWidget(ads::LeftDockWidgetArea, createLongTextLabelDockWidget(ViewMenu));
|
||||
auto FileSystemWidget = createFileSystemTreeDockWidget(ViewMenu);
|
||||
/*auto FileSystemWidget = createFileSystemTreeDockWidget(ViewMenu);
|
||||
auto ToolBar = FileSystemWidget->toolBar();
|
||||
ToolBar->addAction(ui.actionSaveState);
|
||||
ToolBar->addAction(ui.actionRestoreState);
|
||||
DockManager->addDockWidget(ads::BottomDockWidgetArea, FileSystemWidget);
|
||||
DockManager->addDockWidget(ads::BottomDockWidgetArea, FileSystemWidget);*/
|
||||
|
||||
FileSystemWidget = createFileSystemTreeDockWidget(ViewMenu);
|
||||
/*FileSystemWidget = createFileSystemTreeDockWidget(ViewMenu);
|
||||
ToolBar = FileSystemWidget->toolBar();
|
||||
ToolBar->addAction(ui.actionSaveState);
|
||||
ToolBar->addAction(ui.actionRestoreState);
|
||||
@ -198,7 +198,7 @@ void MainWindowPrivate::createContent()
|
||||
DockManager->addDockWidget(ads::TopDockWidgetArea, createLongTextLabelDockWidget(ViewMenu), RighDockArea);
|
||||
auto BottomDockArea = DockManager->addDockWidget(ads::BottomDockWidgetArea, createLongTextLabelDockWidget(ViewMenu), RighDockArea);
|
||||
DockManager->addDockWidget(ads::RightDockWidgetArea, createLongTextLabelDockWidget(ViewMenu), RighDockArea);
|
||||
DockManager->addDockWidget(ads::CenterDockWidgetArea, createLongTextLabelDockWidget(ViewMenu), BottomDockArea);
|
||||
DockManager->addDockWidget(ads::CenterDockWidgetArea, createLongTextLabelDockWidget(ViewMenu), BottomDockArea);*/
|
||||
}
|
||||
|
||||
|
||||
@ -321,7 +321,6 @@ void CMainWindow::on_actionRestoreState_triggered(bool)
|
||||
//============================================================================
|
||||
void CMainWindow::savePerspective()
|
||||
{
|
||||
std::cout << "savePerspective" << std::endl;
|
||||
QString PerspectiveName = QInputDialog::getText(this, "Save Perspective", "Enter unique name:");
|
||||
if (PerspectiveName.isEmpty())
|
||||
{
|
||||
|
@ -38,7 +38,7 @@ int main(int argc, char *argv[])
|
||||
std::shared_ptr<int> b;
|
||||
QApplication a(argc, argv);
|
||||
a.setQuitOnLastWindowClosed(true);
|
||||
qInstallMessageHandler(myMessageOutput);
|
||||
//qInstallMessageHandler(myMessageOutput);
|
||||
qDebug() << "Message handler test";
|
||||
|
||||
CMainWindow mw;
|
||||
|
@ -136,7 +136,6 @@ void CDockAreaTabBar::wheelEvent(QWheelEvent* Event)
|
||||
//============================================================================
|
||||
void CDockAreaTabBar::mousePressEvent(QMouseEvent* ev)
|
||||
{
|
||||
std::cout << "CDockAreaTabBar::mousePressEvent" << std::endl;
|
||||
if (ev->button() == Qt::LeftButton)
|
||||
{
|
||||
ev->accept();
|
||||
@ -232,7 +231,6 @@ void CDockAreaTabBar::startFloating(const QPoint& Pos)
|
||||
//============================================================================
|
||||
void CDockAreaTabBar::setCurrentIndex(int index)
|
||||
{
|
||||
std::cout << "CDockAreaTabBar::setCurrentIndex " << index << std::endl;
|
||||
if (index == d->CurrentIndex)
|
||||
{
|
||||
return;
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include "DockAreaTitleBar.h"
|
||||
|
||||
#include <QPushButton>
|
||||
#include <QToolButton>
|
||||
#include <QBoxLayout>
|
||||
#include <QStyle>
|
||||
#include <QMenu>
|
||||
@ -31,14 +32,15 @@
|
||||
|
||||
namespace ads
|
||||
{
|
||||
using tTileBarButton = QPushButton;
|
||||
/**
|
||||
* Private data class of CDockAreaTitleBar class (pimpl)
|
||||
*/
|
||||
struct DockAreaTitleBarPrivate
|
||||
{
|
||||
CDockAreaTitleBar* _this;
|
||||
QPushButton* TabsMenuButton;
|
||||
QPushButton* CloseButton;
|
||||
tTileBarButton* TabsMenuButton;
|
||||
tTileBarButton* CloseButton;
|
||||
QBoxLayout* TopLayout;
|
||||
CDockAreaWidget* DockArea;
|
||||
CDockAreaTabBar* TabBar;
|
||||
@ -74,7 +76,7 @@ DockAreaTitleBarPrivate::DockAreaTitleBarPrivate(CDockAreaTitleBar* _public) :
|
||||
//============================================================================
|
||||
void DockAreaTitleBarPrivate::createButtons()
|
||||
{
|
||||
TabsMenuButton = new QPushButton();
|
||||
TabsMenuButton = new tTileBarButton();
|
||||
TabsMenuButton->setObjectName("tabsMenuButton");
|
||||
TabsMenuButton->setFlat(true);
|
||||
TabsMenuButton->setIcon(_this->style()->standardIcon(QStyle::SP_TitleBarUnshadeButton));
|
||||
@ -88,10 +90,18 @@ void DockAreaTitleBarPrivate::createButtons()
|
||||
_this->connect(TabsMenuButton->menu(), SIGNAL(triggered(QAction*)),
|
||||
SLOT(onTabsMenuActionTriggered(QAction*)));
|
||||
|
||||
CloseButton = new QPushButton();
|
||||
CloseButton = new tTileBarButton();
|
||||
CloseButton->setObjectName("closeButton");
|
||||
CloseButton->setFlat(true);
|
||||
CloseButton->setIcon(_this->style()->standardIcon(QStyle::SP_TitleBarCloseButton));
|
||||
QPixmap ClosePixmap = _this->style()->standardPixmap(QStyle::SP_TitleBarCloseButton);
|
||||
QIcon CloseIcon;
|
||||
QStyleOptionButton option;
|
||||
option.initFrom(CloseButton);
|
||||
QPixmap ClosePixmapDisabled = _this->style()->generatedIconPixmap(QIcon::Disabled, ClosePixmap, &option);
|
||||
CloseIcon.addPixmap(ClosePixmap, QIcon::Active);
|
||||
CloseIcon.addPixmap(ClosePixmapDisabled, QIcon::Disabled);
|
||||
CloseButton->setIcon(CloseIcon);
|
||||
//CloseButton->setIcon(QIcon(":/ads/close.svg"));
|
||||
CloseButton->setToolTip(QObject::tr("Close"));
|
||||
CloseButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
|
||||
TopLayout->addWidget(CloseButton, 0);
|
||||
@ -201,7 +211,7 @@ void CDockAreaTitleBar::onTabsMenuActionTriggered(QAction* Action)
|
||||
void CDockAreaTitleBar::onCurrentTabChanged(int Index)
|
||||
{
|
||||
CDockWidget* DockWidget = d->TabBar->tab(Index)->dockWidget();
|
||||
d->CloseButton->setVisible(DockWidget->features().testFlag(CDockWidget::DockWidgetClosable));
|
||||
d->CloseButton->setEnabled(DockWidget->features().testFlag(CDockWidget::DockWidgetClosable));
|
||||
}
|
||||
|
||||
|
||||
|
@ -132,12 +132,10 @@ public:
|
||||
|
||||
void setCurrentIndex(int index)
|
||||
{
|
||||
std::cout << "CDockAreaLayout::setCurrentIndex " << index << std::endl;
|
||||
QWidget *prev = currentWidget();
|
||||
QWidget *next = widget(index);
|
||||
if (!next || (next == prev && !m_CurrentWidget))
|
||||
{
|
||||
std::cout << "return" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
@ -150,7 +148,6 @@ public:
|
||||
parent->setUpdatesEnabled(false);
|
||||
}
|
||||
|
||||
std::cout << "m_ParentLayout->addWidget(next)" << std::endl;
|
||||
auto LayoutItem = m_ParentLayout->takeAt(1);
|
||||
if (LayoutItem)
|
||||
{
|
||||
|
@ -927,7 +927,7 @@ int CDockContainerWidget::visibleDockAreaCount() const
|
||||
int Result = 0;
|
||||
for (auto DockArea : d->DockAreas)
|
||||
{
|
||||
Result += DockArea->isVisibleTo(this) ? 1 : 0;
|
||||
Result += DockArea->isHidden() ? 0 : 1;
|
||||
}
|
||||
|
||||
return Result;
|
||||
@ -982,9 +982,6 @@ void CDockContainerWidget::dropFloatingWidget(CFloatingDockContainer* FloatingWi
|
||||
{
|
||||
TopLevelDockWidget->emitTopLevelChanged(false);
|
||||
}
|
||||
|
||||
std::cout << "CDockContainerWidget::dropFloatingWidget " <<
|
||||
Timer.restart() << std::endl;
|
||||
}
|
||||
|
||||
|
||||
@ -994,7 +991,7 @@ QList<CDockAreaWidget*> CDockContainerWidget::openedDockAreas() const
|
||||
QList<CDockAreaWidget*> Result;
|
||||
for (auto DockArea : d->DockAreas)
|
||||
{
|
||||
if (DockArea->isVisibleTo(this))
|
||||
if (!DockArea->isHidden())
|
||||
{
|
||||
Result.append(DockArea);
|
||||
}
|
||||
|
@ -262,13 +262,10 @@ bool DockManagerPrivate::restoreState(const QByteArray &state, int version)
|
||||
// Now all dock areas are properly restored and we setup the index of
|
||||
// The dock areas because the previous toggleView() action has changed
|
||||
// the dock area index
|
||||
std::cout << "Restoring dock container indexes" << std::endl;
|
||||
int Count = 0;
|
||||
for (auto DockContainer : Containers)
|
||||
{
|
||||
Count++;
|
||||
std::cout << "Restoring container " << Count << " floating: "
|
||||
<< DockContainer->isFloating() << " DockAreaCount " << DockContainer->dockAreaCount() << std::endl;
|
||||
for (int i = 0; i < DockContainer->dockAreaCount(); ++i)
|
||||
{
|
||||
CDockAreaWidget* DockArea = DockContainer->dockArea(i);
|
||||
@ -481,8 +478,8 @@ bool CDockManager::restoreState(const QByteArray &state, int version)
|
||||
// dock manager. Because there will be no processing of application
|
||||
// events until this function is finished, the user will not see this
|
||||
// hiding
|
||||
bool IsVisible = this->isVisibleTo(parentWidget());
|
||||
if (IsVisible)
|
||||
bool IsHidden = this->isHidden();
|
||||
if (!IsHidden)
|
||||
{
|
||||
hide();
|
||||
}
|
||||
@ -491,12 +488,11 @@ bool CDockManager::restoreState(const QByteArray &state, int version)
|
||||
bool Result = d->restoreState(state, version);
|
||||
d->RestoringState = false;
|
||||
emit stateRestored();
|
||||
if (IsVisible)
|
||||
if (!IsHidden)
|
||||
{
|
||||
show();
|
||||
}
|
||||
|
||||
std::cout << "CDockManager::restoreState " << Timer.restart() << std::endl;
|
||||
return Result;
|
||||
}
|
||||
|
||||
|
@ -435,14 +435,16 @@ void CDockWidget::toggleViewInternal(bool Open)
|
||||
{
|
||||
CDockContainerWidget* DockContainer = dockContainer();
|
||||
CDockWidget* TopLevelDockWidget = nullptr;
|
||||
CDockWidget* TopLevelDockWidgetBefore = nullptr;
|
||||
|
||||
if (Open && DockContainer)
|
||||
if (DockContainer)
|
||||
{
|
||||
TopLevelDockWidget = DockContainer->topLevelDockWidget();
|
||||
TopLevelDockWidgetBefore = DockContainer->topLevelDockWidget();
|
||||
}
|
||||
|
||||
if (Open)
|
||||
{
|
||||
TopLevelDockWidget = TopLevelDockWidgetBefore;
|
||||
d->showDockWidget();
|
||||
}
|
||||
else
|
||||
@ -468,6 +470,22 @@ void CDockWidget::toggleViewInternal(bool Open)
|
||||
CDockWidget::emitTopLevelEventForWidget(TopLevelDockWidget, !Open);
|
||||
}
|
||||
|
||||
CDockWidget* TopLevelDockWidgetAfter = nullptr;
|
||||
if (DockContainer)
|
||||
{
|
||||
TopLevelDockWidgetAfter = DockContainer->topLevelDockWidget();
|
||||
}
|
||||
|
||||
if (TopLevelDockWidgetAfter != TopLevelDockWidgetBefore)
|
||||
{
|
||||
CFloatingDockContainer* FloatingContainer = qobject_cast<CFloatingDockContainer*>(DockContainer->parentWidget());
|
||||
if (FloatingContainer)
|
||||
{
|
||||
FloatingContainer->updateWindowTitle(TopLevelDockWidgetAfter ? TopLevelDockWidgetAfter->windowTitle() : "");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!Open)
|
||||
{
|
||||
emit closed();
|
||||
|
@ -500,6 +500,20 @@ void CFloatingDockContainer::onDockAreasAddedOrRemoved()
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CFloatingDockContainer::updateWindowTitle(const QString& Title)
|
||||
{
|
||||
if (Title.isEmpty())
|
||||
{
|
||||
this->setWindowTitle(qApp->applicationDisplayName());
|
||||
}
|
||||
else
|
||||
{
|
||||
this->setWindowTitle(Title);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CFloatingDockContainer::onDockAreaCurrentChanged(int Index)
|
||||
{
|
||||
|
@ -68,6 +68,7 @@ private:
|
||||
friend class CDockWidgetTab;
|
||||
friend class CDockAreaTitleBar;
|
||||
friend struct DockAreaTitleBarPrivate;
|
||||
friend class CDockWidget;
|
||||
|
||||
private slots:
|
||||
void onDockAreasAddedOrRemoved();
|
||||
@ -95,6 +96,11 @@ protected:
|
||||
*/
|
||||
bool restoreState(QXmlStreamReader& Stream, bool Testing);
|
||||
|
||||
/**
|
||||
* Call this function to update the window title
|
||||
*/
|
||||
void updateWindowTitle(const QString& Title ="");
|
||||
|
||||
|
||||
protected: // reimplements QWidget
|
||||
virtual void changeEvent(QEvent *event) override;
|
||||
|
@ -1,5 +1,6 @@
|
||||
<RCC>
|
||||
<qresource prefix="/ads">
|
||||
<file>stylesheets/default.css</file>
|
||||
<file>close.svg</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
Loading…
Reference in New Issue
Block a user