diff options
author | Tobias Markmann <tm@ayena.de> | 2015-08-04 19:13:00 (GMT) |
---|---|---|
committer | Kevin Smith <kevin.smith@isode.com> | 2015-08-11 10:28:58 (GMT) |
commit | d376c5a7ef5463094b83993d58be58d69b467c4d (patch) | |
tree | 5591d7d8e2e2ae6088775bcae69de97f67ee53ae /Swift/QtUI | |
parent | 88dbda0ca538b30e0b001344fbcf8a36ff1abe1a (diff) | |
download | swift-d376c5a7ef5463094b83993d58be58d69b467c4d.zip swift-d376c5a7ef5463094b83993d58be58d69b467c4d.tar.bz2 |
Fix crash on trellis shortcuts if no chat window is open
Test-Information:
Verified that using trellis shortcuts does not crash Swift
anymore if no chat window is open.
Change-Id: Ie5c7b4675c89c8481cad48f2a348e6520ac42b13
Diffstat (limited to 'Swift/QtUI')
-rw-r--r-- | Swift/QtUI/Trellis/QtDynamicGridLayout.cpp | 140 |
1 files changed, 74 insertions, 66 deletions
diff --git a/Swift/QtUI/Trellis/QtDynamicGridLayout.cpp b/Swift/QtUI/Trellis/QtDynamicGridLayout.cpp index e2b6e27..3f3e292 100644 --- a/Swift/QtUI/Trellis/QtDynamicGridLayout.cpp +++ b/Swift/QtUI/Trellis/QtDynamicGridLayout.cpp @@ -315,94 +315,102 @@ void QtDynamicGridLayout::setDimensions(const QSize& dim) { void QtDynamicGridLayout::moveCurrentTabRight() { int index = currentIndex(); - int tabIndex = -1; - QtTabWidget* tabWidget = indexToTabWidget(index, tabIndex); - assert(tabWidget); - int newTabIndex = (tabIndex + 1) % tabWidget->count(); - moveTab(tabWidget, tabIndex, newTabIndex); + if (index >= 0) { + int tabIndex = -1; + QtTabWidget* tabWidget = indexToTabWidget(index, tabIndex); + assert(tabWidget); + int newTabIndex = (tabIndex + 1) % tabWidget->count(); + moveTab(tabWidget, tabIndex, newTabIndex); + } } void QtDynamicGridLayout::moveCurrentTabLeft() { int index = currentIndex(); - int tabIndex = -1; - QtTabWidget* tabWidget = indexToTabWidget(index, tabIndex); - assert(tabWidget); - int newTabIndex = (tabWidget->count() + tabIndex - 1) % tabWidget->count(); - moveTab(tabWidget, tabIndex, newTabIndex); + if (index >= 0) { + int tabIndex = -1; + QtTabWidget* tabWidget = indexToTabWidget(index, tabIndex); + assert(tabWidget); + int newTabIndex = (tabWidget->count() + tabIndex - 1) % tabWidget->count(); + moveTab(tabWidget, tabIndex, newTabIndex); + } } void QtDynamicGridLayout::moveCurrentTabToNextGroup() { int index = currentIndex(); - int tabIndex = -1; - QtTabWidget* tabWidget = indexToTabWidget(index, tabIndex); - - int row = -1; - int col = -1; - int tmp; - gridLayout_->getItemPosition(gridLayout_->indexOf(tabWidget), &row, &col, &tmp, &tmp); - - // calculate next cell - col++; - if (!(col < gridLayout_->columnCount())) { - col = 0; - row++; - if (!(row < gridLayout_->rowCount())) { - row = 0; + if (index >= 0) { + int tabIndex = -1; + QtTabWidget* tabWidget = indexToTabWidget(index, tabIndex); + + int row = -1; + int col = -1; + int tmp; + gridLayout_->getItemPosition(gridLayout_->indexOf(tabWidget), &row, &col, &tmp, &tmp); + + // calculate next cell + col++; + if (!(col < gridLayout_->columnCount())) { + col = 0; + row++; + if (!(row < gridLayout_->rowCount())) { + row = 0; + } } - } - QtTabWidget* targetTabWidget = dynamic_cast<QtTabWidget*>(gridLayout_->itemAtPosition(row, col)->widget()); - assert(tabWidget); - assert(targetTabWidget); + QtTabWidget* targetTabWidget = dynamic_cast<QtTabWidget*>(gridLayout_->itemAtPosition(row, col)->widget()); + assert(tabWidget); + assert(targetTabWidget); - // fetch tab information - QWidget* tab = tabWidget->widget(tabIndex); - QString tabText = tabWidget->tabText(tabIndex); + // fetch tab information + QWidget* tab = tabWidget->widget(tabIndex); + QString tabText = tabWidget->tabText(tabIndex); - // move tab - tab->blockSignals(true); - targetTabWidget->addTab(tab, tabText); - tab->blockSignals(false); - tab->setFocus(Qt::TabFocusReason); + // move tab + tab->blockSignals(true); + targetTabWidget->addTab(tab, tabText); + tab->blockSignals(false); + tab->setFocus(Qt::TabFocusReason); - updateTabPositions(); + updateTabPositions(); + } } void QtDynamicGridLayout::moveCurrentTabToPreviousGroup() { int index = currentIndex(); - int tabIndex = -1; - QtTabWidget* tabWidget = indexToTabWidget(index, tabIndex); - - int row = -1; - int col = -1; - int tmp; - gridLayout_->getItemPosition(gridLayout_->indexOf(tabWidget), &row, &col, &tmp, &tmp); - - // calculate next cell - col--; - if (col < 0) { - col = gridLayout_->columnCount() - 1; - row--; - if (row < 0) { - row = gridLayout_->rowCount() - 1; + if (index >= 0) { + int tabIndex = -1; + QtTabWidget* tabWidget = indexToTabWidget(index, tabIndex); + + int row = -1; + int col = -1; + int tmp; + gridLayout_->getItemPosition(gridLayout_->indexOf(tabWidget), &row, &col, &tmp, &tmp); + + // calculate next cell + col--; + if (col < 0) { + col = gridLayout_->columnCount() - 1; + row--; + if (row < 0) { + row = gridLayout_->rowCount() - 1; + } } - } - QtTabWidget* targetTabWidget = dynamic_cast<QtTabWidget*>(gridLayout_->itemAtPosition(row, col)->widget()); - assert(tabWidget); - assert(targetTabWidget); + QtTabWidget* targetTabWidget = dynamic_cast<QtTabWidget*>(gridLayout_->itemAtPosition(row, col)->widget()); + assert(tabWidget); + assert(targetTabWidget); - // fetch tab information - QWidget* tab = tabWidget->widget(tabIndex); - QString tabText = tabWidget->tabText(tabIndex); + // fetch tab information + QWidget* tab = tabWidget->widget(tabIndex); + QString tabText = tabWidget->tabText(tabIndex); - // move tab - tab->blockSignals(true); - targetTabWidget->addTab(tab, tabText); - tab->blockSignals(false); - tab->setFocus(Qt::TabFocusReason); + // move tab + tab->blockSignals(true); + targetTabWidget->addTab(tab, tabText); + tab->blockSignals(false); + tab->setFocus(Qt::TabFocusReason); - updateTabPositions(); + updateTabPositions(); + } } void QtDynamicGridLayout::handleTabCloseRequested(int index) { |