Changeset View
Changeset View
Standalone View
Standalone View
app/tabbar.cpp
Show First 20 Lines • Show All 109 Lines • ▼ Show 20 Line(s) | |||||
110 | 110 | | |||
111 | void TabBar::applySkin() | 111 | void TabBar::applySkin() | ||
112 | { | 112 | { | ||
113 | resize(width(), m_skin->tabBarBackgroundImage().height()); | 113 | resize(width(), m_skin->tabBarBackgroundImage().height()); | ||
114 | 114 | | |||
115 | m_newTabButton->setStyleSheet(m_skin->tabBarNewTabButtonStyleSheet()); | 115 | m_newTabButton->setStyleSheet(m_skin->tabBarNewTabButtonStyleSheet()); | ||
116 | m_closeTabButton->setStyleSheet(m_skin->tabBarCloseTabButtonStyleSheet()); | 116 | m_closeTabButton->setStyleSheet(m_skin->tabBarCloseTabButtonStyleSheet()); | ||
117 | 117 | | |||
118 | m_newTabButton->move( m_skin->tabBarNewTabButtonPosition().x(), m_skin->tabBarNewTabButtonPosition().y()); | 118 | moveNewTabButton(); | ||
119 | m_closeTabButton->move(width() - m_skin->tabBarCloseTabButtonPosition().x(), m_skin->tabBarCloseTabButtonPosition().y()); | 119 | m_closeTabButton->move(width() - m_skin->tabBarCloseTabButtonPosition().x(), m_skin->tabBarCloseTabButtonPosition().y()); | ||
120 | | ||||
121 | repaint(); | 120 | repaint(); | ||
122 | } | 121 | } | ||
123 | 122 | | |||
124 | void TabBar::readyTabContextMenu() | 123 | void TabBar::readyTabContextMenu() | ||
125 | { | 124 | { | ||
126 | if (m_tabContextMenu->isEmpty()) | 125 | if (m_tabContextMenu->isEmpty()) | ||
127 | { | 126 | { | ||
128 | m_tabContextMenu->addAction(m_mainWindow->actionCollection()->action(QStringLiteral("split-left-right"))); | 127 | m_tabContextMenu->addAction(m_mainWindow->actionCollection()->action(QStringLiteral("split-left-right"))); | ||
▲ Show 20 Lines • Show All 261 Lines • ▼ Show 20 Line(s) | 358 | { | |||
390 | updateToggleMonitorSilenceMenu(m_selectedSessionId); | 389 | updateToggleMonitorSilenceMenu(m_selectedSessionId); | ||
391 | } | 390 | } | ||
392 | 391 | | |||
393 | QWidget::contextMenuEvent(event); | 392 | QWidget::contextMenuEvent(event); | ||
394 | } | 393 | } | ||
395 | 394 | | |||
396 | void TabBar::resizeEvent(QResizeEvent* event) | 395 | void TabBar::resizeEvent(QResizeEvent* event) | ||
397 | { | 396 | { | ||
398 | m_newTabButton->move(m_skin->tabBarNewTabButtonPosition().x(), m_skin->tabBarNewTabButtonPosition().y()); | 397 | moveNewTabButton(); | ||
399 | m_closeTabButton->move(width() - m_skin->tabBarCloseTabButtonPosition().x(), m_skin->tabBarCloseTabButtonPosition().y()); | 398 | m_closeTabButton->move(width() - m_skin->tabBarCloseTabButtonPosition().x(), m_skin->tabBarCloseTabButtonPosition().y()); | ||
400 | | ||||
401 | QWidget::resizeEvent(event); | 399 | QWidget::resizeEvent(event); | ||
402 | } | 400 | } | ||
403 | 401 | | |||
402 | void TabBar::moveNewTabButton() | ||||
403 | { | ||||
404 | int newTabButtonX = m_skin->tabBarNewTabButtonPosition().x(); | ||||
405 | if (m_skin->tabBarNewTabButtonIsAtEndOfTabs()) { | ||||
406 | newTabButtonX += m_tabWidths.last(); | ||||
407 | } | ||||
408 | m_newTabButton->move(newTabButtonX, m_skin->tabBarNewTabButtonPosition().y()); | ||||
409 | } | ||||
410 | | ||||
404 | void TabBar::paintEvent(QPaintEvent*) | 411 | void TabBar::paintEvent(QPaintEvent*) | ||
405 | { | 412 | { | ||
406 | QPainter painter(this); | 413 | QPainter painter(this); | ||
407 | painter.setPen(m_skin->tabBarTextColor()); | 414 | painter.setPen(m_skin->tabBarTextColor()); | ||
408 | 415 | | |||
409 | int x = m_skin->tabBarPosition().x(); | 416 | int x = m_skin->tabBarPosition().x(); | ||
410 | int y = m_skin->tabBarPosition().y(); | 417 | int y = m_skin->tabBarPosition().y(); | ||
411 | m_tabWidths.clear(); | 418 | m_tabWidths.clear(); | ||
412 | 419 | | |||
413 | QRect tabsClipRect(x, y, m_closeTabButton->x() - x, height() - y); | 420 | QRect tabsClipRect(x, y, m_closeTabButton->x() - x, height() - y); | ||
414 | painter.setClipRect(tabsClipRect); | 421 | painter.setClipRect(tabsClipRect); | ||
415 | 422 | | |||
416 | for (int index = 0; index < m_tabs.count(); ++index) | 423 | for (int index = 0; index < m_tabs.count(); ++index) | ||
417 | { | 424 | { | ||
418 | x = drawButton(x, y, index, painter); | 425 | x = drawTab(x, y, index, painter); | ||
419 | m_tabWidths << x; | 426 | m_tabWidths << x; | ||
420 | } | 427 | } | ||
421 | 428 | | |||
422 | const QPixmap& backgroundImage = m_skin->tabBarBackgroundImage(); | 429 | const QPixmap& backgroundImage = m_skin->tabBarBackgroundImage(); | ||
423 | const QPixmap& leftCornerImage = m_skin->tabBarLeftCornerImage(); | 430 | const QPixmap& leftCornerImage = m_skin->tabBarLeftCornerImage(); | ||
424 | const QPixmap& rightCornerImage = m_skin->tabBarRightCornerImage(); | 431 | const QPixmap& rightCornerImage = m_skin->tabBarRightCornerImage(); | ||
425 | 432 | | |||
426 | x = x > tabsClipRect.right() ? tabsClipRect.right() + 1 : x; | 433 | x = x > tabsClipRect.right() ? tabsClipRect.right() + 1 : x; | ||
Show All 14 Lines | |||||
441 | QRect rightCornerImageRect(width() - rightCornerImage.width(), 0, rightCornerImage.width(), height()); | 448 | QRect rightCornerImageRect(width() - rightCornerImage.width(), 0, rightCornerImage.width(), height()); | ||
442 | backgroundClipRegion = backgroundClipRegion.subtracted(rightCornerImageRect); | 449 | backgroundClipRegion = backgroundClipRegion.subtracted(rightCornerImageRect); | ||
443 | 450 | | |||
444 | painter.setClipRegion(backgroundClipRegion); | 451 | painter.setClipRegion(backgroundClipRegion); | ||
445 | 452 | | |||
446 | painter.drawTiledPixmap(0, 0, width(), height(), backgroundImage); | 453 | painter.drawTiledPixmap(0, 0, width(), height(), backgroundImage); | ||
447 | 454 | | |||
448 | painter.end(); | 455 | painter.end(); | ||
456 | | ||||
457 | if (m_skin->tabBarNewTabButtonIsAtEndOfTabs()) { | ||||
458 | moveNewTabButton(); | ||||
459 | } | ||||
449 | } | 460 | } | ||
450 | 461 | | |||
451 | int TabBar::drawButton(int x, int y, int index, QPainter& painter) | 462 | int TabBar::drawTab(int x, int y, int index, QPainter& painter) | ||
452 | { | 463 | { | ||
453 | QString title; | 464 | QString title; | ||
454 | int sessionId; | 465 | int sessionId; | ||
455 | bool selected; | 466 | bool selected; | ||
456 | QFont font = QFontDatabase::systemFont(QFontDatabase::GeneralFont); | 467 | QFont font = QFontDatabase::systemFont(QFontDatabase::GeneralFont); | ||
457 | int textWidth = 0; | 468 | int textWidth = 0; | ||
458 | 469 | | |||
459 | sessionId = m_tabs.at(index); | 470 | sessionId = m_tabs.at(index); | ||
Show All 11 Lines | 480 | { | |||
471 | x += m_skin->tabBarUnselectedLeftCornerImage().width(); | 482 | x += m_skin->tabBarUnselectedLeftCornerImage().width(); | ||
472 | } | 483 | } | ||
473 | else if (index != m_tabs.indexOf(m_selectedSessionId) + 1) | 484 | else if (index != m_tabs.indexOf(m_selectedSessionId) + 1) | ||
474 | { | 485 | { | ||
475 | painter.drawPixmap(x, y, m_skin->tabBarSeparatorImage()); | 486 | painter.drawPixmap(x, y, m_skin->tabBarSeparatorImage()); | ||
476 | x += m_skin->tabBarSeparatorImage().width(); | 487 | x += m_skin->tabBarSeparatorImage().width(); | ||
477 | } | 488 | } | ||
478 | 489 | | |||
479 | if (selected) font.setBold(true); | 490 | if (selected) font.setBold(m_skin->tabBarSelectedTextBold()); | ||
480 | else font.setBold(false); | 491 | else font.setBold(false); | ||
481 | 492 | | |||
482 | painter.setFont(font); | 493 | painter.setFont(font); | ||
483 | 494 | | |||
484 | QFontMetrics fontMetrics(font); | 495 | QFontMetrics fontMetrics(font); | ||
485 | textWidth = fontMetrics.width(title) + 10; | 496 | textWidth = fontMetrics.width(title) + 10; | ||
486 | 497 | | |||
487 | // Draw the Prevent Closing image in the tab button. | 498 | // Draw the Prevent Closing image in the tab button. | ||
▲ Show 20 Lines • Show All 497 Lines • ▼ Show 20 Line(s) | 995 | if (m_mainWindow->useTranslucency()) | |||
985 | fillColor.setAlphaF(qreal(Settings::backgroundColorOpacity()) / 100); | 996 | fillColor.setAlphaF(qreal(Settings::backgroundColorOpacity()) / 100); | ||
986 | 997 | | |||
987 | tab.fill(fillColor); | 998 | tab.fill(fillColor); | ||
988 | 999 | | |||
989 | QPainter painter(&tab); | 1000 | QPainter painter(&tab); | ||
990 | painter.initFrom(this); | 1001 | painter.initFrom(this); | ||
991 | painter.setPen(m_skin->tabBarTextColor()); | 1002 | painter.setPen(m_skin->tabBarTextColor()); | ||
992 | 1003 | | |||
993 | drawButton(0, 0, index, painter); | 1004 | drawTab(0, 0, index, painter); | ||
994 | painter.end(); | 1005 | painter.end(); | ||
995 | 1006 | | |||
996 | QMimeData* mimeData = new QMimeData; | 1007 | QMimeData* mimeData = new QMimeData; | ||
997 | mimeData->setText(QVariant(sessionId).toString()); | 1008 | mimeData->setText(QVariant(sessionId).toString()); | ||
998 | 1009 | | |||
999 | QDrag* drag = new QDrag(this); | 1010 | QDrag* drag = new QDrag(this); | ||
1000 | drag->setMimeData(mimeData); | 1011 | drag->setMimeData(mimeData); | ||
1001 | drag->setPixmap(tab); | 1012 | drag->setPixmap(tab); | ||
▲ Show 20 Lines • Show All 83 Lines • Show Last 20 Lines |