diff options
Diffstat (limited to 'Swift/QtUI/Trellis/QtDynamicGridLayout.cpp')
-rw-r--r-- | Swift/QtUI/Trellis/QtDynamicGridLayout.cpp | 40 |
1 files changed, 34 insertions, 6 deletions
diff --git a/Swift/QtUI/Trellis/QtDynamicGridLayout.cpp b/Swift/QtUI/Trellis/QtDynamicGridLayout.cpp index 5600cc8..53e2733 100644 --- a/Swift/QtUI/Trellis/QtDynamicGridLayout.cpp +++ b/Swift/QtUI/Trellis/QtDynamicGridLayout.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2016 Isode Limited. + * Copyright (c) 2014-2019 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ @@ -23,7 +23,7 @@ namespace Swift { -QtDynamicGridLayout::QtDynamicGridLayout(QWidget* parent, bool enableDND) : QWidget(parent), dndEnabled_(enableDND), movingTab_(nullptr) { +QtDynamicGridLayout::QtDynamicGridLayout(bool future, QWidget* parent, bool enableDND) : QWidget(parent), dndEnabled_(enableDND), movingTab_(nullptr), future_(future) { gridLayout_ = new QGridLayout(this); setContentsMargins(0,0,0,0); setDimensions(QSize(1,1)); @@ -49,6 +49,9 @@ int QtDynamicGridLayout::addTab(QtTabbable* tab, const QString& title) { tabWidget->addTab(tab, title); } tab->setEmphasiseFocus(getDimension().width() > 1 || getDimension().height() > 1); + if (future_) { + showHideFirstTabs(); // FIXME: Putting it here as a workaround until I work out why it doesn't work initially + } return tabWidget ? indexOf(tab) : -1; } @@ -144,7 +147,9 @@ void QtDynamicGridLayout::removeTab(int index) { int tabIndex = -1; QtTabWidget* tabWidget = indexToTabWidget(index, tabIndex); if (tabWidget) { + QWidget* tab = tabWidget->widget(tabIndex); tabWidget->removeTab(tabIndex); + tab->setParent(nullptr); } } @@ -290,7 +295,12 @@ void QtDynamicGridLayout::setDimensions(const QSize& dim) { while(oldTabWidget->count()) { QIcon icon = oldTabWidget->tabIcon(0); QString text = oldTabWidget->tabText(0); - newTabWidget->addTab(oldTabWidget->widget(0), icon, text); + QWidget* movingTab = oldTabWidget->widget(0); + //If handling was allowed, QtChatTabs::handleWidgetShown() would be triggered when newTabWidget has no tabs. + //That would access indices of the gridLayout_ that are null because they have been migrated to the newLayout. + movingTab->blockSignals(true); + newTabWidget->addTab(movingTab, icon, text); + movingTab->blockSignals(false); } delete oldTabWidget; } @@ -321,6 +331,24 @@ void QtDynamicGridLayout::setDimensions(const QSize& dim) { setCurrentWidget(restoredWidget); updateEmphasiseFocusOnTabs(); + + if (future_) { + showHideFirstTabs(); + } +} + +void QtDynamicGridLayout::showHideFirstTabs() { + int tmp; + auto firstTabs = indexToTabWidget(0, tmp); + + if (firstTabs) { + if (gridLayout_->columnCount() == 1 && gridLayout_->rowCount() == 1) { + firstTabs->tabBar()->hide(); + } + else { + firstTabs->tabBar()->show(); + } + } } void QtDynamicGridLayout::updateEmphasiseFocusOnTabs() { @@ -486,9 +514,9 @@ void QtDynamicGridLayout::updateTabPositions() { void QtDynamicGridLayout::moveTab(QtTabWidget* tabWidget, int oldIndex, int newIndex) { #if QT_VERSION >= 0x040500 - SWIFT_LOG_ASSERT(movingTab_ == nullptr, error) << std::endl; + SWIFT_LOG_ASSERT(movingTab_ == nullptr, error); movingTab_ = qobject_cast<QtTabbable*>(tabWidget->widget(oldIndex)); - SWIFT_LOG_ASSERT(movingTab_ != nullptr, error) << std::endl; + SWIFT_LOG_ASSERT(movingTab_ != nullptr, error); if (movingTab_) { // Install event filter that filters out events issued during the internal movement of the @@ -498,7 +526,7 @@ void QtDynamicGridLayout::moveTab(QtTabWidget* tabWidget, int oldIndex, int newI tabWidget->tabBar()->moveTab(oldIndex, newIndex); qApp->removeEventFilter(this); - SWIFT_LOG_ASSERT(movingTab_ == tabWidget->widget(newIndex), error) << std::endl; + SWIFT_LOG_ASSERT(movingTab_ == tabWidget->widget(newIndex), error); } movingTab_ = nullptr; tabWidget->widget(newIndex)->setFocus(); |