summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Markmann <tm@ayena.de>2015-08-04 19:13:00 (GMT)
committerKevin Smith <kevin.smith@isode.com>2015-08-11 10:28:58 (GMT)
commitd376c5a7ef5463094b83993d58be58d69b467c4d (patch)
tree5591d7d8e2e2ae6088775bcae69de97f67ee53ae
parent88dbda0ca538b30e0b001344fbcf8a36ff1abe1a (diff)
downloadswift-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
-rw-r--r--Swift/QtUI/Trellis/QtDynamicGridLayout.cpp140
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
@@ -313,98 +313,106 @@ void QtDynamicGridLayout::setDimensions(const QSize& dim) {
313 gridLayout_ = newLayout; 313 gridLayout_ = newLayout;
314} 314}
315 315
316void QtDynamicGridLayout::moveCurrentTabRight() { 316void QtDynamicGridLayout::moveCurrentTabRight() {
317 int index = currentIndex(); 317 int index = currentIndex();
318 int tabIndex = -1; 318 if (index >= 0) {
319 QtTabWidget* tabWidget = indexToTabWidget(index, tabIndex); 319 int tabIndex = -1;
320 assert(tabWidget); 320 QtTabWidget* tabWidget = indexToTabWidget(index, tabIndex);
321 int newTabIndex = (tabIndex + 1) % tabWidget->count(); 321 assert(tabWidget);
322 moveTab(tabWidget, tabIndex, newTabIndex); 322 int newTabIndex = (tabIndex + 1) % tabWidget->count();
323 moveTab(tabWidget, tabIndex, newTabIndex);
324 }
323} 325}
324 326
325void QtDynamicGridLayout::moveCurrentTabLeft() { 327void QtDynamicGridLayout::moveCurrentTabLeft() {
326 int index = currentIndex(); 328 int index = currentIndex();
327 int tabIndex = -1; 329 if (index >= 0) {
328 QtTabWidget* tabWidget = indexToTabWidget(index, tabIndex); 330 int tabIndex = -1;
329 assert(tabWidget); 331 QtTabWidget* tabWidget = indexToTabWidget(index, tabIndex);
330 int newTabIndex = (tabWidget->count() + tabIndex - 1) % tabWidget->count(); 332 assert(tabWidget);
331 moveTab(tabWidget, tabIndex, newTabIndex); 333 int newTabIndex = (tabWidget->count() + tabIndex - 1) % tabWidget->count();
334 moveTab(tabWidget, tabIndex, newTabIndex);
335 }
332} 336}
333 337
334void QtDynamicGridLayout::moveCurrentTabToNextGroup() { 338void QtDynamicGridLayout::moveCurrentTabToNextGroup() {
335 int index = currentIndex(); 339 int index = currentIndex();
336 int tabIndex = -1; 340 if (index >= 0) {
337 QtTabWidget* tabWidget = indexToTabWidget(index, tabIndex); 341 int tabIndex = -1;
338 342 QtTabWidget* tabWidget = indexToTabWidget(index, tabIndex);
339 int row = -1; 343
340 int col = -1; 344 int row = -1;
341 int tmp; 345 int col = -1;
342 gridLayout_->getItemPosition(gridLayout_->indexOf(tabWidget), &row, &col, &tmp, &tmp); 346 int tmp;
343 347 gridLayout_->getItemPosition(gridLayout_->indexOf(tabWidget), &row, &col, &tmp, &tmp);
344 // calculate next cell 348
345 col++; 349 // calculate next cell
346 if (!(col < gridLayout_->columnCount())) { 350 col++;
347 col = 0; 351 if (!(col < gridLayout_->columnCount())) {
348 row++; 352 col = 0;
349 if (!(row < gridLayout_->rowCount())) { 353 row++;
350 row = 0; 354 if (!(row < gridLayout_->rowCount())) {
355 row = 0;
356 }
351 } 357 }
352 }
353 358
354 QtTabWidget* targetTabWidget = dynamic_cast<QtTabWidget*>(gridLayout_->itemAtPosition(row, col)->widget()); 359 QtTabWidget* targetTabWidget = dynamic_cast<QtTabWidget*>(gridLayout_->itemAtPosition(row, col)->widget());
355 assert(tabWidget); 360 assert(tabWidget);
356 assert(targetTabWidget); 361 assert(targetTabWidget);
357 362
358 // fetch tab information 363 // fetch tab information
359 QWidget* tab = tabWidget->widget(tabIndex); 364 QWidget* tab = tabWidget->widget(tabIndex);
360 QString tabText = tabWidget->tabText(tabIndex); 365 QString tabText = tabWidget->tabText(tabIndex);
361 366
362 // move tab 367 // move tab
363 tab->blockSignals(true); 368 tab->blockSignals(true);
364 targetTabWidget->addTab(tab, tabText); 369 targetTabWidget->addTab(tab, tabText);
365 tab->blockSignals(false); 370 tab->blockSignals(false);
366 tab->setFocus(Qt::TabFocusReason); 371 tab->setFocus(Qt::TabFocusReason);
367 372
368 updateTabPositions(); 373 updateTabPositions();
374 }
369} 375}
370 376
371void QtDynamicGridLayout::moveCurrentTabToPreviousGroup() { 377void QtDynamicGridLayout::moveCurrentTabToPreviousGroup() {
372 int index = currentIndex(); 378 int index = currentIndex();
373 int tabIndex = -1; 379 if (index >= 0) {
374 QtTabWidget* tabWidget = indexToTabWidget(index, tabIndex); 380 int tabIndex = -1;
375 381 QtTabWidget* tabWidget = indexToTabWidget(index, tabIndex);
376 int row = -1; 382
377 int col = -1; 383 int row = -1;
378 int tmp; 384 int col = -1;
379 gridLayout_->getItemPosition(gridLayout_->indexOf(tabWidget), &row, &col, &tmp, &tmp); 385 int tmp;
380 386 gridLayout_->getItemPosition(gridLayout_->indexOf(tabWidget), &row, &col, &tmp, &tmp);
381 // calculate next cell 387
382 col--; 388 // calculate next cell
383 if (col < 0) { 389 col--;
384 col = gridLayout_->columnCount() - 1; 390 if (col < 0) {
385 row--; 391 col = gridLayout_->columnCount() - 1;
386 if (row < 0) { 392 row--;
387 row = gridLayout_->rowCount() - 1; 393 if (row < 0) {
394 row = gridLayout_->rowCount() - 1;
395 }
388 } 396 }
389 }
390 397
391 QtTabWidget* targetTabWidget = dynamic_cast<QtTabWidget*>(gridLayout_->itemAtPosition(row, col)->widget()); 398 QtTabWidget* targetTabWidget = dynamic_cast<QtTabWidget*>(gridLayout_->itemAtPosition(row, col)->widget());
392 assert(tabWidget); 399 assert(tabWidget);
393 assert(targetTabWidget); 400 assert(targetTabWidget);
394 401
395 // fetch tab information 402 // fetch tab information
396 QWidget* tab = tabWidget->widget(tabIndex); 403 QWidget* tab = tabWidget->widget(tabIndex);
397 QString tabText = tabWidget->tabText(tabIndex); 404 QString tabText = tabWidget->tabText(tabIndex);
398 405
399 // move tab 406 // move tab
400 tab->blockSignals(true); 407 tab->blockSignals(true);
401 targetTabWidget->addTab(tab, tabText); 408 targetTabWidget->addTab(tab, tabText);
402 tab->blockSignals(false); 409 tab->blockSignals(false);
403 tab->setFocus(Qt::TabFocusReason); 410 tab->setFocus(Qt::TabFocusReason);
404 411
405 updateTabPositions(); 412 updateTabPositions();
413 }
406} 414}
407 415
408void QtDynamicGridLayout::handleTabCloseRequested(int index) { 416void QtDynamicGridLayout::handleTabCloseRequested(int index) {
409 updateTabPositions(); 417 updateTabPositions();
410 QtTabWidget* tabWidgetSender = dynamic_cast<QtTabWidget*>(sender()); 418 QtTabWidget* tabWidgetSender = dynamic_cast<QtTabWidget*>(sender());