Changeset View
Changeset View
Standalone View
Standalone View
app/tabbar.cpp
Context not available. | |||||
122 | 122 | | |||
---|---|---|---|---|---|
123 | void TabBar::readyTabContextMenu() | 123 | void TabBar::readyTabContextMenu() | ||
124 | { | 124 | { | ||
125 | if (m_tabContextMenu->isEmpty()) | 125 | if(m_tabContextMenu->isEmpty()) | ||
126 | { | 126 | { | ||
127 | m_tabContextMenu->addAction(m_mainWindow->actionCollection()->action(QStringLiteral("split-left-right"))); | 127 | m_tabContextMenu->addAction(m_mainWindow->actionCollection()->action(QStringLiteral("split-left-right"))); | ||
128 | m_tabContextMenu->addAction(m_mainWindow->actionCollection()->action(QStringLiteral("split-top-bottom"))); | 128 | m_tabContextMenu->addAction(m_mainWindow->actionCollection()->action(QStringLiteral("split-top-bottom"))); | ||
Context not available. | |||||
144 | 144 | | |||
145 | void TabBar::readySessionMenu() | 145 | void TabBar::readySessionMenu() | ||
146 | { | 146 | { | ||
147 | if (m_sessionMenu->isEmpty()) | 147 | if(m_sessionMenu->isEmpty()) | ||
148 | { | 148 | { | ||
149 | m_sessionMenu->addAction(m_mainWindow->actionCollection()->action(QStringLiteral("new-session"))); | 149 | m_sessionMenu->addAction(m_mainWindow->actionCollection()->action(QStringLiteral("new-session"))); | ||
150 | m_sessionMenu->addSeparator(); | 150 | m_sessionMenu->addSeparator(); | ||
Context not available. | |||||
156 | 156 | | |||
157 | void TabBar::updateMoveActions(int index) | 157 | void TabBar::updateMoveActions(int index) | ||
158 | { | 158 | { | ||
159 | if (index == -1) return; | 159 | if(index == -1) return; | ||
160 | 160 | | |||
161 | m_mainWindow->actionCollection()->action(QStringLiteral("move-session-left"))->setEnabled(false); | 161 | m_mainWindow->actionCollection()->action(QStringLiteral("move-session-left"))->setEnabled(false); | ||
162 | m_mainWindow->actionCollection()->action(QStringLiteral("move-session-right"))->setEnabled(false); | 162 | m_mainWindow->actionCollection()->action(QStringLiteral("move-session-right"))->setEnabled(false); | ||
163 | 163 | | |||
164 | if (index != m_tabs.indexOf(m_tabs.first())) | 164 | if(index != m_tabs.indexOf(m_tabs.first())) | ||
165 | m_mainWindow->actionCollection()->action(QStringLiteral("move-session-left"))->setEnabled(true); | 165 | m_mainWindow->actionCollection()->action(QStringLiteral("move-session-left"))->setEnabled(true); | ||
166 | 166 | | |||
167 | if (index != m_tabs.indexOf(m_tabs.last())) | 167 | if(index != m_tabs.indexOf(m_tabs.last())) | ||
168 | m_mainWindow->actionCollection()->action(QStringLiteral("move-session-right"))->setEnabled(true); | 168 | m_mainWindow->actionCollection()->action(QStringLiteral("move-session-right"))->setEnabled(true); | ||
169 | } | 169 | } | ||
170 | 170 | | |||
171 | void TabBar::updateToggleActions(int sessionId) | 171 | void TabBar::updateToggleActions(int sessionId) | ||
172 | { | 172 | { | ||
173 | if (sessionId == -1) return; | 173 | if(sessionId == -1) return; | ||
174 | 174 | | |||
175 | KActionCollection* actionCollection = m_mainWindow->actionCollection(); | 175 | KActionCollection* actionCollection = m_mainWindow->actionCollection(); | ||
176 | SessionStack* sessionStack = m_mainWindow->sessionStack(); | 176 | SessionStack* sessionStack = m_mainWindow->sessionStack(); | ||
Context not available. | |||||
190 | 190 | | |||
191 | void TabBar::updateToggleKeyboardInputMenu(int sessionId) | 191 | void TabBar::updateToggleKeyboardInputMenu(int sessionId) | ||
192 | { | 192 | { | ||
193 | if (!m_tabs.contains(sessionId)) return; | 193 | if(!m_tabs.contains(sessionId)) return; | ||
194 | 194 | | |||
195 | QAction* toggleKeyboardInputAction = m_mainWindow->actionCollection()->action(QStringLiteral("toggle-session-keyboard-input")); | 195 | QAction* toggleKeyboardInputAction = m_mainWindow->actionCollection()->action(QStringLiteral("toggle-session-keyboard-input")); | ||
196 | QAction* anchor = m_toggleKeyboardInputMenu->menuAction(); | 196 | QAction* anchor = m_toggleKeyboardInputMenu->menuAction(); | ||
Context not available. | |||||
201 | 201 | | |||
202 | m_toggleKeyboardInputMenu->clear(); | 202 | m_toggleKeyboardInputMenu->clear(); | ||
203 | 203 | | |||
204 | if (terminalIds.count() <= 1) | 204 | if(terminalIds.count() <= 1) | ||
205 | { | 205 | { | ||
206 | toggleKeyboardInputAction->setText(xi18nc("@action", "Disable Keyboard Input")); | 206 | toggleKeyboardInputAction->setText(xi18nc("@action", "Disable Keyboard Input")); | ||
207 | m_tabContextMenu->insertAction(anchor, toggleKeyboardInputAction); | 207 | m_tabContextMenu->insertAction(anchor, toggleKeyboardInputAction); | ||
Context not available. | |||||
238 | 238 | | |||
239 | void TabBar::updateToggleMonitorActivityMenu(int sessionId) | 239 | void TabBar::updateToggleMonitorActivityMenu(int sessionId) | ||
240 | { | 240 | { | ||
241 | if (!m_tabs.contains(sessionId)) return; | 241 | if(!m_tabs.contains(sessionId)) return; | ||
242 | 242 | | |||
243 | QAction* toggleMonitorActivityAction = m_mainWindow->actionCollection()->action(QStringLiteral("toggle-session-monitor-activity")); | 243 | QAction* toggleMonitorActivityAction = m_mainWindow->actionCollection()->action(QStringLiteral("toggle-session-monitor-activity")); | ||
244 | QAction* anchor = m_toggleMonitorActivityMenu->menuAction(); | 244 | QAction* anchor = m_toggleMonitorActivityMenu->menuAction(); | ||
Context not available. | |||||
249 | 249 | | |||
250 | m_toggleMonitorActivityMenu->clear(); | 250 | m_toggleMonitorActivityMenu->clear(); | ||
251 | 251 | | |||
252 | if (terminalIds.count() <= 1) | 252 | if(terminalIds.count() <= 1) | ||
253 | { | 253 | { | ||
254 | toggleMonitorActivityAction->setText(xi18nc("@action", "Monitor for Activity")); | 254 | toggleMonitorActivityAction->setText(xi18nc("@action", "Monitor for Activity")); | ||
255 | m_tabContextMenu->insertAction(anchor, toggleMonitorActivityAction); | 255 | m_tabContextMenu->insertAction(anchor, toggleMonitorActivityAction); | ||
Context not available. | |||||
286 | 286 | | |||
287 | void TabBar::updateToggleMonitorSilenceMenu(int sessionId) | 287 | void TabBar::updateToggleMonitorSilenceMenu(int sessionId) | ||
288 | { | 288 | { | ||
289 | if (!m_tabs.contains(sessionId)) return; | 289 | if(!m_tabs.contains(sessionId)) return; | ||
290 | 290 | | |||
291 | QAction* toggleMonitorSilenceAction = m_mainWindow->actionCollection()->action(QStringLiteral("toggle-session-monitor-silence")); | 291 | QAction* toggleMonitorSilenceAction = m_mainWindow->actionCollection()->action(QStringLiteral("toggle-session-monitor-silence")); | ||
292 | QAction* anchor = m_toggleMonitorSilenceMenu->menuAction(); | 292 | QAction* anchor = m_toggleMonitorSilenceMenu->menuAction(); | ||
Context not available. | |||||
297 | 297 | | |||
298 | m_toggleMonitorSilenceMenu->clear(); | 298 | m_toggleMonitorSilenceMenu->clear(); | ||
299 | 299 | | |||
300 | if (terminalIds.count() <= 1) | 300 | if(terminalIds.count() <= 1) | ||
301 | { | 301 | { | ||
302 | toggleMonitorSilenceAction->setText(xi18nc("@action", "Monitor for Silence")); | 302 | toggleMonitorSilenceAction->setText(xi18nc("@action", "Monitor for Silence")); | ||
303 | m_tabContextMenu->insertAction(anchor, toggleMonitorSilenceAction); | 303 | m_tabContextMenu->insertAction(anchor, toggleMonitorSilenceAction); | ||
Context not available. | |||||
336 | { | 336 | { | ||
337 | bool ok = false; | 337 | bool ok = false; | ||
338 | 338 | | |||
339 | if (!action->data().isNull()) | 339 | if(!action->data().isNull()) | ||
340 | { | 340 | { | ||
341 | int terminalId = action->data().toInt(&ok); | 341 | int terminalId = action->data().toInt(&ok); | ||
342 | 342 | | |||
343 | if (ok) emit requestTerminalHighlight(terminalId); | 343 | if(ok) emit requestTerminalHighlight(terminalId); | ||
344 | } | 344 | } | ||
345 | else if (!ok) | 345 | else if(!ok) | ||
346 | emit requestRemoveTerminalHighlight(); | 346 | emit requestRemoveTerminalHighlight(); | ||
347 | } | 347 | } | ||
348 | 348 | | |||
349 | void TabBar::contextMenuEvent(QContextMenuEvent* event) | 349 | void TabBar::contextMenuEvent(QContextMenuEvent* event) | ||
350 | { | 350 | { | ||
351 | if (event->x() < 0) return; | 351 | if(event->x() < 0) return; | ||
352 | 352 | | |||
353 | int index = tabAt(event->x()); | 353 | int index = tabAt(event->x()); | ||
354 | 354 | | |||
355 | if (index == -1) | 355 | if(index == -1) | ||
356 | m_sessionMenu->exec(QCursor::pos()); | 356 | m_sessionMenu->exec(QCursor::pos()); | ||
357 | else | 357 | else | ||
358 | { | 358 | { | ||
Context not available. | |||||
372 | 372 | | |||
373 | emit tabContextMenuClosed(); | 373 | emit tabContextMenuClosed(); | ||
374 | 374 | | |||
375 | if (action) | 375 | if(action) | ||
376 | { | 376 | { | ||
377 | if (action->isCheckable()) | 377 | if(action->isCheckable()) | ||
378 | m_mainWindow->handleContextDependentToggleAction(action->isChecked(), action, sessionId); | 378 | m_mainWindow->handleContextDependentToggleAction(action->isChecked(), action, sessionId); | ||
379 | else | 379 | else | ||
380 | m_mainWindow->handleContextDependentAction(action, sessionId); | 380 | m_mainWindow->handleContextDependentAction(action, sessionId); | ||
Context not available. | |||||
402 | void TabBar::moveNewTabButton() | 402 | void TabBar::moveNewTabButton() | ||
403 | { | 403 | { | ||
404 | int newTabButtonX = m_skin->tabBarNewTabButtonPosition().x(); | 404 | int newTabButtonX = m_skin->tabBarNewTabButtonPosition().x(); | ||
405 | if (m_skin->tabBarNewTabButtonIsAtEndOfTabs()) { | 405 | if(m_skin->tabBarNewTabButtonIsAtEndOfTabs()) { | ||
406 | newTabButtonX += m_tabWidths.last(); | 406 | newTabButtonX += m_tabWidths.last(); | ||
407 | } | 407 | } | ||
408 | m_newTabButton->move(newTabButtonX, m_skin->tabBarNewTabButtonPosition().y()); | 408 | m_newTabButton->move(newTabButtonX, m_skin->tabBarNewTabButtonPosition().y()); | ||
Context not available. | |||||
454 | 454 | | |||
455 | painter.end(); | 455 | painter.end(); | ||
456 | 456 | | |||
457 | if (m_skin->tabBarNewTabButtonIsAtEndOfTabs()) { | 457 | if(m_skin->tabBarNewTabButtonIsAtEndOfTabs()) { | ||
458 | moveNewTabButton(); | 458 | moveNewTabButton(); | ||
459 | } | 459 | } | ||
460 | } | 460 | } | ||
Context not available. | |||||
471 | selected = (sessionId == m_selectedSessionId); | 471 | selected = (sessionId == m_selectedSessionId); | ||
472 | title = m_tabTitles[sessionId]; | 472 | title = m_tabTitles[sessionId]; | ||
473 | 473 | | |||
474 | if (selected) | 474 | if(selected) | ||
475 | { | 475 | { | ||
476 | painter.drawPixmap(x, y, m_skin->tabBarSelectedLeftCornerImage()); | 476 | painter.drawPixmap(x, y, m_skin->tabBarSelectedLeftCornerImage()); | ||
477 | x += m_skin->tabBarSelectedLeftCornerImage().width(); | 477 | x += m_skin->tabBarSelectedLeftCornerImage().width(); | ||
478 | } | 478 | } | ||
479 | else if (!m_skin->tabBarUnselectedLeftCornerImage().isNull()) | 479 | else if(!m_skin->tabBarUnselectedLeftCornerImage().isNull()) | ||
480 | { | 480 | { | ||
481 | painter.drawPixmap(x, y, m_skin->tabBarUnselectedLeftCornerImage()); | 481 | painter.drawPixmap(x, y, m_skin->tabBarUnselectedLeftCornerImage()); | ||
482 | x += m_skin->tabBarUnselectedLeftCornerImage().width(); | 482 | x += m_skin->tabBarUnselectedLeftCornerImage().width(); | ||
483 | } | 483 | } | ||
484 | else if (index != m_tabs.indexOf(m_selectedSessionId) + 1) | 484 | else if(index != m_tabs.indexOf(m_selectedSessionId) + 1) | ||
485 | { | 485 | { | ||
486 | painter.drawPixmap(x, y, m_skin->tabBarSeparatorImage()); | 486 | painter.drawPixmap(x, y, m_skin->tabBarSeparatorImage()); | ||
487 | x += m_skin->tabBarSeparatorImage().width(); | 487 | x += m_skin->tabBarSeparatorImage().width(); | ||
488 | } | 488 | } | ||
489 | 489 | | |||
490 | if (selected) font.setBold(m_skin->tabBarSelectedTextBold()); | 490 | if(selected) font.setBold(m_skin->tabBarSelectedTextBold()); | ||
491 | else font.setBold(false); | 491 | else font.setBold(false); | ||
492 | 492 | | |||
493 | painter.setFont(font); | 493 | painter.setFont(font); | ||
Context not available. | |||||
496 | textWidth = fontMetrics.width(title) + 10; | 496 | textWidth = fontMetrics.width(title) + 10; | ||
497 | 497 | | |||
498 | // Draw the Prevent Closing image in the tab button. | 498 | // Draw the Prevent Closing image in the tab button. | ||
499 | if (m_mainWindow->sessionStack()->isSessionClosable(sessionId) == false) | 499 | if(m_mainWindow->sessionStack()->isSessionClosable(sessionId) == false) | ||
500 | { | 500 | { | ||
501 | if (selected) | 501 | if(selected) | ||
502 | painter.drawTiledPixmap(x, y, | 502 | painter.drawTiledPixmap(x, y, | ||
503 | m_skin->tabBarPreventClosingImagePosition().x() + | 503 | m_skin->tabBarPreventClosingImagePosition().x() + | ||
504 | m_skin->tabBarPreventClosingImage().width(), height(), | 504 | m_skin->tabBarPreventClosingImage().width(), height(), | ||
Context not available. | |||||
517 | x += m_skin->tabBarPreventClosingImage().width(); | 517 | x += m_skin->tabBarPreventClosingImage().width(); | ||
518 | } | 518 | } | ||
519 | 519 | | |||
520 | if (selected) | 520 | if(selected) | ||
521 | painter.drawTiledPixmap(x, y, textWidth, height(), m_skin->tabBarSelectedBackgroundImage()); | 521 | painter.drawTiledPixmap(x, y, textWidth, height(), m_skin->tabBarSelectedBackgroundImage()); | ||
522 | else | 522 | else | ||
523 | painter.drawTiledPixmap(x, y, textWidth, height(), m_skin->tabBarUnselectedBackgroundImage()); | 523 | painter.drawTiledPixmap(x, y, textWidth, height(), m_skin->tabBarUnselectedBackgroundImage()); | ||
Context not available. | |||||
526 | 526 | | |||
527 | x += textWidth; | 527 | x += textWidth; | ||
528 | 528 | | |||
529 | if (selected) | 529 | if(selected) | ||
530 | { | 530 | { | ||
531 | painter.drawPixmap(x, m_skin->tabBarPosition().y(), m_skin->tabBarSelectedRightCornerImage()); | 531 | painter.drawPixmap(x, m_skin->tabBarPosition().y(), m_skin->tabBarSelectedRightCornerImage()); | ||
532 | x += m_skin->tabBarSelectedRightCornerImage().width(); | 532 | x += m_skin->tabBarSelectedRightCornerImage().width(); | ||
533 | } | 533 | } | ||
534 | else if (!m_skin->tabBarUnselectedRightCornerImage().isNull()) | 534 | else if(!m_skin->tabBarUnselectedRightCornerImage().isNull()) | ||
535 | { | 535 | { | ||
536 | painter.drawPixmap(x, m_skin->tabBarPosition().y(), m_skin->tabBarUnselectedRightCornerImage()); | 536 | painter.drawPixmap(x, m_skin->tabBarPosition().y(), m_skin->tabBarUnselectedRightCornerImage()); | ||
537 | x += m_skin->tabBarUnselectedRightCornerImage().width(); | 537 | x += m_skin->tabBarUnselectedRightCornerImage().width(); | ||
538 | } | 538 | } | ||
539 | else if (index != m_tabs.indexOf(m_selectedSessionId) - 1) | 539 | else if(index != m_tabs.indexOf(m_selectedSessionId) - 1) | ||
540 | { | 540 | { | ||
541 | painter.drawPixmap(x, m_skin->tabBarPosition().y(), m_skin->tabBarSeparatorImage()); | 541 | painter.drawPixmap(x, m_skin->tabBarPosition().y(), m_skin->tabBarSeparatorImage()); | ||
542 | x += m_skin->tabBarSeparatorImage().width(); | 542 | x += m_skin->tabBarSeparatorImage().width(); | ||
Context not available. | |||||
549 | { | 549 | { | ||
550 | for (int index = 0; index < m_tabWidths.count(); ++index) | 550 | for (int index = 0; index < m_tabWidths.count(); ++index) | ||
551 | { | 551 | { | ||
552 | if (x > m_skin->tabBarPosition().x() && x < m_tabWidths.at(index)) | 552 | if(x > m_skin->tabBarPosition().x() && x < m_tabWidths.at(index)) | ||
553 | return index; | 553 | return index; | ||
554 | } | 554 | } | ||
555 | 555 | | |||
Context not available. | |||||
558 | 558 | | |||
559 | void TabBar::wheelEvent(QWheelEvent* event) | 559 | void TabBar::wheelEvent(QWheelEvent* event) | ||
560 | { | 560 | { | ||
561 | if (event->angleDelta().y() < 0) | 561 | if(event->angleDelta().y() < 0) | ||
562 | selectNextTab(); | 562 | selectNextTab(); | ||
563 | else | 563 | else | ||
564 | selectPreviousTab(); | 564 | selectPreviousTab(); | ||
Context not available. | |||||
566 | 566 | | |||
567 | void TabBar::keyPressEvent(QKeyEvent* event) | 567 | void TabBar::keyPressEvent(QKeyEvent* event) | ||
568 | { | 568 | { | ||
569 | if (event->key() == Qt::Key_Escape && m_lineEdit->isVisible()) | 569 | if(event->key() == Qt::Key_Escape && m_lineEdit->isVisible()) | ||
570 | m_lineEdit->hide(); | 570 | m_lineEdit->hide(); | ||
571 | 571 | | |||
572 | QWidget::keyPressEvent(event); | 572 | QWidget::keyPressEvent(event); | ||
Context not available. | |||||
574 | 574 | | |||
575 | void TabBar::mousePressEvent(QMouseEvent* event) | 575 | void TabBar::mousePressEvent(QMouseEvent* event) | ||
576 | { | 576 | { | ||
577 | if (QWhatsThis::inWhatsThisMode()) return; | 577 | if(QWhatsThis::inWhatsThisMode()) return; | ||
578 | 578 | | |||
579 | if (event->x() < m_skin->tabBarPosition().x()) return; | 579 | if(event->x() < m_skin->tabBarPosition().x()) return; | ||
580 | 580 | | |||
581 | int index = tabAt(event->x()); | 581 | int index = tabAt(event->x()); | ||
582 | 582 | | |||
583 | if (index == -1) return; | 583 | if(index == -1) return; | ||
584 | 584 | | |||
585 | if (event->button() == Qt::LeftButton || event->button() == Qt::MidButton) | 585 | if(event->button() == Qt::LeftButton || event->button() == Qt::MidButton) | ||
586 | { | 586 | { | ||
587 | m_startPos = event->pos(); | 587 | m_startPos = event->pos(); | ||
588 | if (index != m_tabs.indexOf(m_selectedSessionId) || event->button() == Qt::MidButton) | 588 | if(index != m_tabs.indexOf(m_selectedSessionId) || event->button() == Qt::MidButton) | ||
589 | { | 589 | { | ||
590 | m_mousePressed = true; | 590 | m_mousePressed = true; | ||
591 | m_mousePressedIndex = index; | 591 | m_mousePressedIndex = index; | ||
Context not available. | |||||
598 | 598 | | |||
599 | void TabBar::mouseReleaseEvent(QMouseEvent* event) | 599 | void TabBar::mouseReleaseEvent(QMouseEvent* event) | ||
600 | { | 600 | { | ||
601 | if (QWhatsThis::inWhatsThisMode()) return; | 601 | if(QWhatsThis::inWhatsThisMode()) return; | ||
602 | 602 | | |||
603 | if (event->x() < m_skin->tabBarPosition().x()) return; | 603 | if(event->x() < m_skin->tabBarPosition().x()) return; | ||
604 | 604 | | |||
605 | int index = tabAt(event->x()); | 605 | int index = tabAt(event->x()); | ||
606 | 606 | | |||
607 | if (m_mousePressed && m_mousePressedIndex == index) | 607 | if(m_mousePressed && m_mousePressedIndex == index) | ||
608 | { | 608 | { | ||
609 | if (event->button() == Qt::LeftButton && index != m_tabs.indexOf(m_selectedSessionId)) | 609 | if(event->button() == Qt::LeftButton && index != m_tabs.indexOf(m_selectedSessionId)) | ||
610 | emit tabSelected(m_tabs.at(index)); | 610 | emit tabSelected(m_tabs.at(index)); | ||
611 | 611 | | |||
612 | if (event->button() == Qt::MidButton) | 612 | if(event->button() == Qt::MidButton) | ||
613 | emit tabClosed(m_tabs.at(index)); | 613 | emit tabClosed(m_tabs.at(index)); | ||
614 | } | 614 | } | ||
615 | 615 | | |||
Context not available. | |||||
623 | 623 | | |||
624 | void TabBar::mouseMoveEvent(QMouseEvent* event) | 624 | void TabBar::mouseMoveEvent(QMouseEvent* event) | ||
625 | { | 625 | { | ||
626 | if (!m_startPos.isNull() && ((event->buttons() & Qt::LeftButton) || (event->buttons() & Qt::MidButton))) | 626 | if(!m_startPos.isNull() && ((event->buttons() & Qt::LeftButton) || (event->buttons() & Qt::MidButton))) | ||
627 | { | 627 | { | ||
628 | int distance = (event->pos() - m_startPos).manhattanLength(); | 628 | int distance = (event->pos() - m_startPos).manhattanLength(); | ||
629 | 629 | | |||
630 | if (distance >= QApplication::startDragDistance()) | 630 | if(distance >= QApplication::startDragDistance()) | ||
631 | { | 631 | { | ||
632 | int index = tabAt(m_startPos.x()); | 632 | int index = tabAt(m_startPos.x()); | ||
633 | 633 | | |||
634 | if (index >= 0 && !m_lineEdit->isVisible()) | 634 | if(index >= 0 && !m_lineEdit->isVisible()) | ||
635 | startDrag(index); | 635 | startDrag(index); | ||
636 | } | 636 | } | ||
637 | } | 637 | } | ||
Context not available. | |||||
643 | { | 643 | { | ||
644 | TabBar* eventSource = qobject_cast<TabBar*>(event->source()); | 644 | TabBar* eventSource = qobject_cast<TabBar*>(event->source()); | ||
645 | 645 | | |||
646 | if (eventSource) | 646 | if(eventSource) | ||
647 | { | 647 | { | ||
648 | event->setDropAction(Qt::MoveAction); | 648 | event->setDropAction(Qt::MoveAction); | ||
649 | event->acceptProposedAction(); | 649 | event->acceptProposedAction(); | ||
Context not available. | |||||
661 | { | 661 | { | ||
662 | TabBar* eventSource = qobject_cast<TabBar*>(event->source()); | 662 | TabBar* eventSource = qobject_cast<TabBar*>(event->source()); | ||
663 | 663 | | |||
664 | if (eventSource && event->pos().x() > m_skin->tabBarPosition().x() && event->pos().x() < m_closeTabButton->x()) | 664 | if(eventSource && event->pos().x() > m_skin->tabBarPosition().x() && event->pos().x() < m_closeTabButton->x()) | ||
665 | { | 665 | { | ||
666 | int index = dropIndex(event->pos()); | 666 | int index = dropIndex(event->pos()); | ||
667 | 667 | | |||
668 | if (index == -1) | 668 | if(index == -1) | ||
669 | index = m_tabs.count(); | 669 | index = m_tabs.count(); | ||
670 | 670 | | |||
671 | drawDropIndicator(index, isSameTab(event)); | 671 | drawDropIndicator(index, isSameTab(event)); | ||
Context not available. | |||||
696 | 696 | | |||
697 | int x = event->pos().x(); | 697 | int x = event->pos().x(); | ||
698 | 698 | | |||
699 | if (isSameTab(event) || x < m_skin->tabBarPosition().x() || x > m_closeTabButton->x()) | 699 | if(isSameTab(event) || x < m_skin->tabBarPosition().x() || x > m_closeTabButton->x()) | ||
700 | event->ignore(); | 700 | event->ignore(); | ||
701 | else | 701 | else | ||
702 | { | 702 | { | ||
Context not available. | |||||
704 | int sourceSessionId = event->mimeData()->text().toInt(); | 704 | int sourceSessionId = event->mimeData()->text().toInt(); | ||
705 | int sourceIndex = m_tabs.indexOf(sourceSessionId); | 705 | int sourceIndex = m_tabs.indexOf(sourceSessionId); | ||
706 | 706 | | |||
707 | if (targetIndex == -1) | 707 | if(targetIndex == -1) | ||
708 | targetIndex = m_tabs.count() - 1; | 708 | targetIndex = m_tabs.count() - 1; | ||
709 | else if (targetIndex < 0) | 709 | else if(targetIndex < 0) | ||
710 | targetIndex = 0; | 710 | targetIndex = 0; | ||
711 | else if (sourceIndex < targetIndex) | 711 | else if(sourceIndex < targetIndex) | ||
712 | --targetIndex; | 712 | --targetIndex; | ||
713 | 713 | | |||
714 | m_tabs.move(sourceIndex, targetIndex); | 714 | m_tabs.move(sourceIndex, targetIndex); | ||
Context not available. | |||||
722 | 722 | | |||
723 | void TabBar::mouseDoubleClickEvent(QMouseEvent* event) | 723 | void TabBar::mouseDoubleClickEvent(QMouseEvent* event) | ||
724 | { | 724 | { | ||
725 | if (QWhatsThis::inWhatsThisMode()) return; | 725 | if(QWhatsThis::inWhatsThisMode()) return; | ||
726 | 726 | | |||
727 | m_lineEdit->hide(); | 727 | m_lineEdit->hide(); | ||
728 | 728 | | |||
729 | if (event->x() < 0) return; | 729 | if(event->x() < 0) return; | ||
730 | 730 | | |||
731 | int index = tabAt(event->x()); | 731 | int index = tabAt(event->x()); | ||
732 | 732 | | |||
733 | if (event->button() == Qt::LeftButton) | 733 | if(event->button() == Qt::LeftButton) | ||
734 | { | 734 | { | ||
735 | if (event->x() <= m_tabWidths.last()) | 735 | if(event->x() <= m_tabWidths.last()) | ||
736 | interactiveRename(m_tabs.at(index)); | 736 | interactiveRename(m_tabs.at(index)); | ||
737 | else if (event->x() > m_tabWidths.last()) | 737 | else if(event->x() > m_tabWidths.last()) | ||
738 | emit newTabRequested(); | 738 | emit newTabRequested(); | ||
739 | } | 739 | } | ||
740 | 740 | | |||
Context not available. | |||||
754 | { | 754 | { | ||
755 | m_tabs.append(sessionId); | 755 | m_tabs.append(sessionId); | ||
756 | 756 | | |||
757 | if (title.isEmpty()) | 757 | if(title.isEmpty()) | ||
758 | m_tabTitles.insert(sessionId, standardTabTitle()); | 758 | m_tabTitles.insert(sessionId, standardTabTitle()); | ||
759 | else | 759 | else | ||
760 | m_tabTitles.insert(sessionId, title); | 760 | m_tabTitles.insert(sessionId, title); | ||
Context not available. | |||||
764 | 764 | | |||
765 | void TabBar::removeTab(int sessionId) | 765 | void TabBar::removeTab(int sessionId) | ||
766 | { | 766 | { | ||
767 | if (sessionId == -1) sessionId = m_selectedSessionId; | 767 | if(sessionId == -1) sessionId = m_selectedSessionId; | ||
768 | if (sessionId == -1) return; | 768 | if(sessionId == -1) return; | ||
769 | if (!m_tabs.contains(sessionId)) return; | 769 | if(!m_tabs.contains(sessionId)) return; | ||
770 | 770 | | |||
771 | int index = m_tabs.indexOf(sessionId); | 771 | int index = m_tabs.indexOf(sessionId); | ||
772 | 772 | | |||
773 | if (m_lineEdit->isVisible() && sessionId == m_renamingSessionId) | 773 | if(m_lineEdit->isVisible() && sessionId == m_renamingSessionId) | ||
774 | m_lineEdit->hide(); | 774 | m_lineEdit->hide(); | ||
775 | 775 | | |||
776 | m_tabs.removeAt(index); | 776 | m_tabs.removeAt(index); | ||
777 | m_tabTitles.remove(sessionId); | 777 | m_tabTitles.remove(sessionId); | ||
778 | 778 | | |||
779 | if (m_tabs.isEmpty()) | 779 | if(m_tabs.isEmpty()) | ||
780 | emit lastTabClosed(); | 780 | emit lastTabClosed(); | ||
781 | else | 781 | else | ||
782 | emit tabSelected(m_tabs.last()); | 782 | emit tabSelected(m_tabs.last()); | ||
Context not available. | |||||
784 | 784 | | |||
785 | void TabBar::interactiveRename(int sessionId) | 785 | void TabBar::interactiveRename(int sessionId) | ||
786 | { | 786 | { | ||
787 | if (sessionId == -1) return; | 787 | if(sessionId == -1) return; | ||
788 | if (!m_tabs.contains(sessionId)) return; | 788 | if(!m_tabs.contains(sessionId)) return; | ||
789 | 789 | | |||
790 | m_renamingSessionId = sessionId; | 790 | m_renamingSessionId = sessionId; | ||
791 | 791 | | |||
Context not available. | |||||
812 | 812 | | |||
813 | void TabBar::selectTab(int sessionId) | 813 | void TabBar::selectTab(int sessionId) | ||
814 | { | 814 | { | ||
815 | if (!m_tabs.contains(sessionId)) return; | 815 | if(!m_tabs.contains(sessionId)) return; | ||
816 | 816 | | |||
817 | m_selectedSessionId = sessionId; | 817 | m_selectedSessionId = sessionId; | ||
818 | 818 | | |||
Context not available. | |||||
827 | int index = m_tabs.indexOf(m_selectedSessionId); | 827 | int index = m_tabs.indexOf(m_selectedSessionId); | ||
828 | int newSelectedSessionId = m_selectedSessionId; | 828 | int newSelectedSessionId = m_selectedSessionId; | ||
829 | 829 | | |||
830 | if (index == -1) | 830 | if(index == -1) | ||
831 | return; | 831 | return; | ||
832 | else if (index == m_tabs.count() - 1) | 832 | else if(index == m_tabs.count() - 1) | ||
833 | newSelectedSessionId = m_tabs.at(0); | 833 | newSelectedSessionId = m_tabs.at(0); | ||
834 | else | 834 | else | ||
835 | newSelectedSessionId = m_tabs.at(index + 1); | 835 | newSelectedSessionId = m_tabs.at(index + 1); | ||
Context not available. | |||||
842 | int index = m_tabs.indexOf(m_selectedSessionId); | 842 | int index = m_tabs.indexOf(m_selectedSessionId); | ||
843 | int newSelectedSessionId = m_selectedSessionId; | 843 | int newSelectedSessionId = m_selectedSessionId; | ||
844 | 844 | | |||
845 | if (index == -1) | 845 | if(index == -1) | ||
846 | return; | 846 | return; | ||
847 | else if (index == 0) | 847 | else if(index == 0) | ||
848 | newSelectedSessionId = m_tabs.at(m_tabs.count() - 1); | 848 | newSelectedSessionId = m_tabs.at(m_tabs.count() - 1); | ||
849 | else | 849 | else | ||
850 | newSelectedSessionId = m_tabs.at(index - 1); | 850 | newSelectedSessionId = m_tabs.at(index - 1); | ||
Context not available. | |||||
854 | 854 | | |||
855 | void TabBar::moveTabLeft(int sessionId) | 855 | void TabBar::moveTabLeft(int sessionId) | ||
856 | { | 856 | { | ||
857 | if (sessionId == -1) sessionId = m_selectedSessionId; | 857 | if(sessionId == -1) sessionId = m_selectedSessionId; | ||
858 | 858 | | |||
859 | int index = m_tabs.indexOf(sessionId); | 859 | int index = m_tabs.indexOf(sessionId); | ||
860 | 860 | | |||
861 | if (index < 1) return; | 861 | if(index < 1) return; | ||
862 | 862 | | |||
863 | m_tabs.swap(index, index - 1); | 863 | m_tabs.swap(index, index - 1); | ||
864 | 864 | | |||
Context not available. | |||||
869 | 869 | | |||
870 | void TabBar::moveTabRight(int sessionId) | 870 | void TabBar::moveTabRight(int sessionId) | ||
871 | { | 871 | { | ||
872 | if (sessionId == -1) sessionId = m_selectedSessionId; | 872 | if(sessionId == -1) sessionId = m_selectedSessionId; | ||
873 | 873 | | |||
874 | int index = m_tabs.indexOf(sessionId); | 874 | int index = m_tabs.indexOf(sessionId); | ||
875 | 875 | | |||
876 | if (index == -1 || index == m_tabs.count() - 1) return; | 876 | if(index == -1 || index == m_tabs.count() - 1) return; | ||
877 | 877 | | |||
878 | m_tabs.swap(index, index + 1); | 878 | m_tabs.swap(index, index + 1); | ||
879 | 879 | | |||
Context not available. | |||||
889 | 889 | | |||
890 | QString TabBar::tabTitle(int sessionId) | 890 | QString TabBar::tabTitle(int sessionId) | ||
891 | { | 891 | { | ||
892 | if (m_tabTitles.contains(sessionId)) | 892 | if(m_tabTitles.contains(sessionId)) | ||
893 | return m_tabTitles[sessionId]; | 893 | return m_tabTitles[sessionId]; | ||
894 | else | 894 | else | ||
895 | return QString(); | 895 | return QString(); | ||
Context not available. | |||||
897 | 897 | | |||
898 | void TabBar::setTabTitle(int sessionId, const QString& newTitle) | 898 | void TabBar::setTabTitle(int sessionId, const QString& newTitle) | ||
899 | { | 899 | { | ||
900 | if (sessionId == -1) return; | 900 | if(sessionId == -1) return; | ||
901 | if (!m_tabTitles.contains(sessionId)) return; | 901 | if(!m_tabTitles.contains(sessionId)) return; | ||
902 | if (m_tabTitlesSetInteractive.value(sessionId, false)) return; | 902 | if(m_tabTitlesSetInteractive.value(sessionId, false)) return; | ||
903 | 903 | | |||
904 | if (!newTitle.isEmpty()) | 904 | if(!newTitle.isEmpty()) | ||
905 | m_tabTitles[sessionId] = newTitle; | 905 | m_tabTitles[sessionId] = newTitle; | ||
906 | 906 | | |||
907 | update(); | 907 | update(); | ||
Context not available. | |||||
909 | 909 | | |||
910 | void TabBar::setTabTitleInteractive(int sessionId, const QString& newTitle) | 910 | void TabBar::setTabTitleInteractive(int sessionId, const QString& newTitle) | ||
911 | { | 911 | { | ||
912 | if (sessionId == -1) return; | 912 | if(sessionId == -1) return; | ||
913 | if (!m_tabTitles.contains(sessionId)) return; | 913 | if(!m_tabTitles.contains(sessionId)) return; | ||
914 | 914 | | |||
915 | if (!newTitle.isEmpty()) | 915 | if(!newTitle.isEmpty()) | ||
916 | { | 916 | { | ||
917 | m_tabTitles[sessionId] = newTitle; | 917 | m_tabTitles[sessionId] = newTitle; | ||
918 | m_tabTitlesSetInteractive[sessionId] = true; | 918 | m_tabTitlesSetInteractive[sessionId] = true; | ||
Context not available. | |||||
925 | 925 | | |||
926 | int TabBar::sessionAtTab(int index) | 926 | int TabBar::sessionAtTab(int index) | ||
927 | { | 927 | { | ||
928 | if (index < 0 || index > m_tabs.count() - 1) | 928 | if(index < 0 || index > m_tabs.count() - 1) | ||
929 | return -1; | 929 | return -1; | ||
930 | else | 930 | else | ||
931 | return m_tabs.at(index); | 931 | return m_tabs.at(index); | ||
Context not available. | |||||
948 | { | 948 | { | ||
949 | it.next(); | 949 | it.next(); | ||
950 | 950 | | |||
951 | if (newTitle == it.value()) | 951 | if(newTitle == it.value()) | ||
952 | { | 952 | { | ||
953 | nameOk = false; | 953 | nameOk = false; | ||
954 | break; | 954 | break; | ||
955 | } | 955 | } | ||
956 | } | 956 | } | ||
957 | 957 | | |||
958 | if (!nameOk) | 958 | if(!nameOk) | ||
959 | { | 959 | { | ||
960 | count++; | 960 | count++; | ||
961 | newTitle = makeTabTitle(count); | 961 | newTitle = makeTabTitle(count); | ||
Context not available. | |||||
968 | 968 | | |||
969 | QString TabBar::makeTabTitle(int id) | 969 | QString TabBar::makeTabTitle(int id) | ||
970 | { | 970 | { | ||
971 | if (id == 0) | 971 | if(id == 0) | ||
972 | { | 972 | { | ||
973 | return xi18nc("@title:tab", "Shell"); | 973 | return xi18nc("@title:tab", "Shell"); | ||
974 | } | 974 | } | ||
Context not available. | |||||
992 | QPixmap tab(tabWidth, height()); | 992 | QPixmap tab(tabWidth, height()); | ||
993 | QColor fillColor(Settings::backgroundColor()); | 993 | QColor fillColor(Settings::backgroundColor()); | ||
994 | 994 | | |||
995 | if (m_mainWindow->useTranslucency()) | 995 | if(m_mainWindow->useTranslucency()) | ||
996 | fillColor.setAlphaF(qreal(Settings::backgroundColorOpacity()) / 100); | 996 | fillColor.setAlphaF(qreal(Settings::backgroundColorOpacity()) / 100); | ||
997 | 997 | | |||
998 | tab.fill(fillColor); | 998 | tab.fill(fillColor); | ||
Context not available. | |||||
1019 | { | 1019 | { | ||
1020 | const int arrowSize = 16; | 1020 | const int arrowSize = 16; | ||
1021 | 1021 | | |||
1022 | if (!m_dropIndicator) | 1022 | if(!m_dropIndicator) | ||
1023 | { | 1023 | { | ||
1024 | m_dropIndicator = new QLabel(parentWidget()); | 1024 | m_dropIndicator = new QLabel(parentWidget()); | ||
1025 | m_dropIndicator->resize(arrowSize, arrowSize); | 1025 | m_dropIndicator->resize(arrowSize, arrowSize); | ||
Context not available. | |||||
1028 | QIcon::Mode drawMode = disabled ? QIcon::Disabled : QIcon::Normal; | 1028 | QIcon::Mode drawMode = disabled ? QIcon::Disabled : QIcon::Normal; | ||
1029 | m_dropIndicator->setPixmap(QIcon::fromTheme(QStringLiteral("arrow-down")).pixmap(arrowSize, arrowSize, drawMode)); | 1029 | m_dropIndicator->setPixmap(QIcon::fromTheme(QStringLiteral("arrow-down")).pixmap(arrowSize, arrowSize, drawMode)); | ||
1030 | 1030 | | |||
1031 | if (index < 0) | 1031 | if(index < 0) | ||
1032 | { | 1032 | { | ||
1033 | m_dropIndicator->hide(); | 1033 | m_dropIndicator->hide(); | ||
1034 | return; | 1034 | return; | ||
1035 | } | 1035 | } | ||
1036 | 1036 | | |||
1037 | int temp_index; | 1037 | int temp_index; | ||
1038 | if (index == m_tabs.count()) | 1038 | if(index == m_tabs.count()) | ||
1039 | temp_index = index - 1; | 1039 | temp_index = index - 1; | ||
1040 | else | 1040 | else | ||
1041 | temp_index = index; | 1041 | temp_index = index; | ||
Context not available. | |||||
1047 | m_dropRect = QRect(x, y - height(), tabWidth, height() - y); | 1047 | m_dropRect = QRect(x, y - height(), tabWidth, height() - y); | ||
1048 | QPoint pos; | 1048 | QPoint pos; | ||
1049 | 1049 | | |||
1050 | if (index < m_tabs.count()) | 1050 | if(index < m_tabs.count()) | ||
1051 | pos = m_dropRect.topLeft(); | 1051 | pos = m_dropRect.topLeft(); | ||
1052 | else | 1052 | else | ||
1053 | pos = m_dropRect.topRight(); | 1053 | pos = m_dropRect.topRight(); | ||
Context not available. | |||||
1063 | int TabBar::dropIndex(const QPoint pos) | 1063 | int TabBar::dropIndex(const QPoint pos) | ||
1064 | { | 1064 | { | ||
1065 | int index = tabAt(pos.x()); | 1065 | int index = tabAt(pos.x()); | ||
1066 | if (index < 0) | 1066 | if(index < 0) | ||
1067 | return index; | 1067 | return index; | ||
1068 | 1068 | | |||
1069 | int x = index ? m_tabWidths.at(index - 1) : m_skin->tabBarPosition().x(); | 1069 | int x = index ? m_tabWidths.at(index - 1) : m_skin->tabBarPosition().x(); | ||
Context not available. | |||||
1071 | int y = m_skin->tabBarPosition().y(); | 1071 | int y = m_skin->tabBarPosition().y(); | ||
1072 | m_dropRect = QRect(x, y - height(), tabWidth, height() - y); | 1072 | m_dropRect = QRect(x, y - height(), tabWidth, height() - y); | ||
1073 | 1073 | | |||
1074 | if ((pos.x()-m_dropRect.left()) > (m_dropRect.width()/2)) | 1074 | if((pos.x()-m_dropRect.left()) > (m_dropRect.width()/2)) | ||
1075 | ++index; | 1075 | ++index; | ||
1076 | 1076 | | |||
1077 | if (index == m_tabs.count()) | 1077 | if(index == m_tabs.count()) | ||
1078 | return -1; | 1078 | return -1; | ||
1079 | 1079 | | |||
1080 | return index; | 1080 | return index; | ||
Context not available. | |||||
1088 | 1088 | | |||
1089 | bool isLastTab = (sourceIndex == m_tabs.count()-1) && (index == -1); | 1089 | bool isLastTab = (sourceIndex == m_tabs.count()-1) && (index == -1); | ||
1090 | 1090 | | |||
1091 | if ((sourceIndex == index) || (sourceIndex == index-1) || isLastTab) | 1091 | if((sourceIndex == index) || (sourceIndex == index-1) || isLastTab) | ||
1092 | return true; | 1092 | return true; | ||
1093 | else | 1093 | else | ||
1094 | return false; | 1094 | return false; | ||
Context not available. |