void MainTab::closeTab() { if(m_index >= FIXED_TAB_COUNT) { QWidget* w; w = widget(m_index); if(m_index == currentIndex()) { int start; if(getSettingsValue("tab_onclose").toInt() == 1) start = m_lastIndex; else start = m_index - 1; for(int i=start; i>=0; i--) { if(isTabEnabled(i)) { setCurrentIndex(i); break; } } } removeTab(m_index); delete w; } }
void KTabBar::wheelEvent( QWheelEvent *event ) { if ( !( event->orientation() == Qt::Horizontal ) ) { if ( receivers( SIGNAL(wheelDelta(int)) ) ) { emit( wheelDelta( event->delta() ) ); return; } int lastIndex = count() - 1; //Set an invalid index as base case int targetIndex = -1; bool forward = event->delta() < 0; if ( forward && lastIndex == currentIndex() ) { targetIndex = 0; } else if ( !forward && 0 == currentIndex() ) { targetIndex = lastIndex; } //Will not move when targetIndex is invalid setCurrentIndex( targetIndex ); //If it has not moved yet (targetIndex == -1), or if it moved but current tab is disabled if ( targetIndex != currentIndex() || !isTabEnabled( targetIndex ) ) { QTabBar::wheelEvent( event ); } event->accept(); } else {
bool QcrTabWidget::anyEnabled() const { for (int i=0; i<count(); ++i) if (isTabEnabled(i)) return true; return false; }
void FancyTabBar::setCurrentIndex(int index) { if (isTabEnabled(index)) { m_currentIndex = index; update(); emit currentChanged(m_currentIndex); } }
QStyleOptionTabV2 YaTabBarBase::getStyleOption(int tab) const { QStyleOptionTabV2 opt; opt.init(this); opt.state &= ~(QStyle::State_HasFocus | QStyle::State_MouseOver); opt.rect = tabRect(tab); bool isCurrent = tab == currentIndex(); opt.row = 0; // if (tab == pressedIndex) // opt.state |= QStyle::State_Sunken; if (isCurrent) opt.state |= QStyle::State_Selected; if (isCurrent && hasFocus()) opt.state |= QStyle::State_HasFocus; if (isTabEnabled(tab)) opt.state &= ~QStyle::State_Enabled; if (isActiveWindow()) opt.state |= QStyle::State_Active; // if (opt.rect == hoverRect) // opt.state |= QStyle::State_MouseOver; opt.shape = shape(); opt.text = tabText(tab); if (tabTextColor(tab).isValid()) opt.palette.setColor(foregroundRole(), tabTextColor(tab)); opt.icon = tabIcon(tab); opt.iconSize = opt.icon.actualSize(QSize(32, 32)); // Will get the default value then. int totalTabs = count(); if (tab > 0 && tab - 1 == currentIndex()) opt.selectedPosition = QStyleOptionTab::PreviousIsSelected; else if (tab < totalTabs - 1 && tab + 1 == currentIndex()) opt.selectedPosition = QStyleOptionTab::NextIsSelected; else opt.selectedPosition = QStyleOptionTab::NotAdjacent; if (tab == 0) { if (totalTabs > 1) opt.position = QStyleOptionTab::Beginning; else opt.position = QStyleOptionTab::OnlyOneTab; } else if (tab == totalTabs - 1) { opt.position = QStyleOptionTab::End; } else { opt.position = QStyleOptionTab::Middle; } if (const QTabWidget *tw = qobject_cast<const QTabWidget *>(parentWidget())) { if (tw->cornerWidget(Qt::TopLeftCorner) || tw->cornerWidget(Qt::BottomLeftCorner)) opt.cornerWidgets |= QStyleOptionTab::LeftCornerWidget; if (tw->cornerWidget(Qt::TopRightCorner) || tw->cornerWidget(Qt::BottomRightCorner)) opt.cornerWidgets |= QStyleOptionTab::RightCornerWidget; } return opt; }
void ComboTabBar::setCurrentNextEnabledIndex(int offset) { for (int index = currentIndex() + offset; validIndex(index); index += offset) { if (isTabEnabled(index)) { setCurrentIndex(index); break; } } }
void ModeTabBar::mousePressEvent(QMouseEvent *event) { QPoint pressPos = event->pos(); for(int i = 0; i < count(); ++i) { if(tabRect(i).contains(pressPos) && isTabEnabled(i)) { setCurrentIndex(i); break; } } }
void FancyTabBar::mousePressEvent(QMouseEvent *e) { e->accept(); for (int index = 0; index < m_tabs.count(); ++index) { if (tabRect(index).contains(e->pos())) { if (isTabEnabled(index)) { m_currentIndex = index; update(); m_triggerTimer.start(0); } break; } } }
bool TabBar::eventFilter(QObject *obj, QEvent *event) { bool result = QObject::eventFilter(obj, event); if (obj == this) { if (event->type() == QEvent::MouseButtonPress) { //see if the user is trying to move away from the editing by clicking another tab QMouseEvent* me = static_cast<QMouseEvent*>(event); int clickedTabId = tabAt(me->pos()); if (renamingIndex_ != -1 && renamingIndex_ != clickedTabId) editFinished(); return false; } if (event->type() == QEvent::MouseButtonDblClick) { //perhaps we need to start a new name editing action... QMouseEvent* me = static_cast<QMouseEvent*>(event); if (me->button() != Qt::LeftButton) return result; int clickedTabId = tabAt(me->pos()); if (clickedTabId == -1) return result; if (!isTabEnabled(clickedTabId)) return result; triggerRename(clickedTabId); return true; //no further handling of this event is required } } //handle some events on the line edit to make it behave itself nicely as a rename editor if (obj == lineEdit_) { if (event->type() == QEvent::KeyPress) { QKeyEvent* ke = static_cast<QKeyEvent*>(event); if (ke->key() == Qt::Key_Escape) { lineEdit_->deleteLater(); lineEdit_ = nullptr; return true; //no further handling of this event is required } else if (ke->key() == Qt::Key_Return) { editFinished(); } } } return result; }
void pTabBar::paintEvent( QPaintEvent* event ) { // draw tabs QTabBar::paintEvent( event ); // update button close if ( !aToggleTabsHaveCloseButton->isChecked() ) return; // get tab int i = tabAt( mapFromGlobal( QCursor::pos() ) ); if ( i != -1 ) { // get close button rect QRect ir = iconRectForTab( i ); // if mouse in close button rect if ( ir.contains( mapFromGlobal( QCursor::pos() ) ) ) { // draw button QPainter p( this ); p.drawPixmap( ir.topLeft(), QIcon( ":/file/icons/file/closeall.png" ).pixmap( iconSize(), QIcon::Active, isTabEnabled( i ) ? QIcon::On : QIcon::Off ) ); } } }
void FancyTabBar::paintTab(QPainter *painter, int tabIndex) const { if (!validIndex(tabIndex)) { qWarning("invalid index"); return; } painter->save(); QRect rect = tabRect(tabIndex); bool selected = (tabIndex == m_currentIndex); bool enabled = isTabEnabled(tabIndex); if (selected) { //jassuncao:if (creatorTheme()->widgetStyle() == Theme::StyleFlat) { if(true) { // background color of a fancy tab that is active painter->fillRect(rect.adjusted(0, 0, 0, -1), QColor(0x90,0x90,0x90,0xFF)); } else { //background painter->save(); QLinearGradient grad(rect.topLeft(), rect.topRight()); grad.setColorAt(0, QColor(255, 255, 255, 140)); grad.setColorAt(1, QColor(255, 255, 255, 210)); painter->fillRect(rect.adjusted(0, 0, 0, -1), grad); painter->restore(); //shadows painter->setPen(QColor(0, 0, 0, 110)); painter->drawLine(rect.topLeft() + QPoint(1,-1), rect.topRight() - QPoint(0,1)); painter->drawLine(rect.bottomLeft(), rect.bottomRight()); painter->setPen(QColor(0, 0, 0, 40)); painter->drawLine(rect.topLeft(), rect.bottomLeft()); //highlights painter->setPen(QColor(255, 255, 255, 50)); painter->drawLine(rect.topLeft() + QPoint(0, -2), rect.topRight() - QPoint(0,2)); painter->drawLine(rect.bottomLeft() + QPoint(0, 1), rect.bottomRight() + QPoint(0,1)); painter->setPen(QColor(255, 255, 255, 40)); painter->drawLine(rect.topLeft() + QPoint(0, 0), rect.topRight()); painter->drawLine(rect.topRight() + QPoint(0, 1), rect.bottomRight() - QPoint(0, 1)); painter->drawLine(rect.bottomLeft() + QPoint(0,-1), rect.bottomRight()-QPoint(0,1)); } } QString tabText(this->tabText(tabIndex)); QRect tabTextRect(rect); const bool drawIcon = rect.height() > 36; QRect tabIconRect(tabTextRect); tabTextRect.translate(0, drawIcon ? -2 : 1); QFont boldFont(painter->font()); //jassuncao boldFont.setPointSizeF(StyleHelper::sidebarFontSize()); boldFont.setPointSizeF(8); boldFont.setBold(true); painter->setFont(boldFont); painter->setPen(selected ? QColor(255, 255, 255, 160) : QColor(0, 0, 0, 110)); const int textFlags = Qt::AlignCenter | (drawIcon ? Qt::AlignBottom : Qt::AlignVCenter) | Qt::TextWordWrap; #if defined(Q_OS_MAC) bool isMacHost = true; #else bool isMacHost = false; #endif if (!isMacHost && !selected && enabled) { painter->save(); int fader = int(m_tabs[tabIndex]->fader()); //jassuncaoif (creatorTheme()->widgetStyle() == Theme::StyleFlat) { if(true) { //QColor c = creatorTheme()->color(Theme::BackgroundColorHover); QColor c(0x51,0x51,0x51,0xFF); c.setAlpha(int(255 * fader/40.0)); // FIXME: hardcoded end value 40 painter->fillRect(rect, c); } else { QLinearGradient grad(rect.topLeft(), rect.topRight()); grad.setColorAt(0, Qt::transparent); grad.setColorAt(0.5, QColor(255, 255, 255, fader)); grad.setColorAt(1, Qt::transparent); painter->fillRect(rect, grad); painter->setPen(QPen(grad, 1.0)); painter->drawLine(rect.topLeft(), rect.topRight()); painter->drawLine(rect.bottomLeft(), rect.bottomRight()); } painter->restore(); } if (!enabled) painter->setOpacity(0.7); if (drawIcon) { int textHeight = painter->fontMetrics().boundingRect(QRect(0, 0, width(), height()), Qt::TextWordWrap, tabText).height(); tabIconRect.adjust(0, 4, 0, -textHeight); //jassuncao StyleHelper::drawIconWithShadow(tabIcon(tabIndex), tabIconRect, painter, enabled ? QIcon::Normal : QIcon::Disabled); drawIconWithShadow(tabIcon(tabIndex), tabIconRect, painter, enabled ? QIcon::Normal : QIcon::Disabled); } painter->setOpacity(1.0); //FIXME: was 0.7 before? /*jassuncao if (enabled) { painter->setPen(selected ? creatorTheme()->color(Theme::FancyTabWidgetEnabledSelectedTextColor) : creatorTheme()->color(Theme::FancyTabWidgetEnabledUnselectedTextColor)); } else { painter->setPen(selected ? creatorTheme()->color(Theme::FancyTabWidgetDisabledSelectedTextColor) : creatorTheme()->color(Theme::FancyTabWidgetDisabledUnselectedTextColor)); } */ if (enabled) { painter->setPen(selected ? QColor(0x3C,0x3C,0x3C,0xFF) : QColor(0xFF,0xFF,0xFF,0xFF)); } else { painter->setPen(selected ? QColor(0xFF,0xFF,0xFF,0xFF) : QColor(0xFF,0xFF,0xFF,0x78)); } painter->translate(0, -1); painter->drawText(tabTextRect, textFlags, tabText); painter->restore(); }
void FancyTabBar::paintTab(QPainter *painter, int tabIndex) const { if (!validIndex(tabIndex)) { qWarning("invalid index"); return; } painter->save(); QRect rect = tabRect(tabIndex); bool selected = (tabIndex == m_currentIndex); bool enabled = isTabEnabled(tabIndex); if (selected) { //background painter->save(); QLinearGradient grad(rect.topLeft(), rect.topRight()); grad.setColorAt(0, QColor(255, 255, 255, 140)); grad.setColorAt(1, QColor(255, 255, 255, 210)); painter->fillRect(rect.adjusted(0, 0, 0, -1), grad); painter->restore(); //shadows painter->setPen(QColor(0, 0, 0, 110)); painter->drawLine(rect.topLeft() + QPoint(1,-1), rect.topRight() - QPoint(0,1)); painter->drawLine(rect.bottomLeft(), rect.bottomRight()); painter->setPen(QColor(0, 0, 0, 40)); painter->drawLine(rect.topLeft(), rect.bottomLeft()); //highlights painter->setPen(QColor(255, 255, 255, 50)); painter->drawLine(rect.topLeft() + QPoint(0, -2), rect.topRight() - QPoint(0,2)); painter->drawLine(rect.bottomLeft() + QPoint(0, 1), rect.bottomRight() + QPoint(0,1)); painter->setPen(QColor(255, 255, 255, 40)); painter->drawLine(rect.topLeft() + QPoint(0, 0), rect.topRight()); painter->drawLine(rect.topRight() + QPoint(0, 1), rect.bottomRight() - QPoint(0, 1)); painter->drawLine(rect.bottomLeft() + QPoint(0,-1), rect.bottomRight()-QPoint(0,1)); } QString tabText(this->tabText(tabIndex)); QRect tabTextRect(tabRect(tabIndex)); QRect tabIconRect(tabTextRect); tabTextRect.translate(0, -2); QFont boldFont(painter->font()); boldFont.setPointSizeF(StyleHelper::sidebarFontSize()); boldFont.setBold(true); painter->setFont(boldFont); painter->setPen(selected ? QColor(255, 255, 255, 160) : QColor(0, 0, 0, 110)); int textFlags = Qt::AlignCenter | Qt::AlignBottom | Qt::TextWordWrap; if (enabled) { painter->drawText(tabTextRect, textFlags, tabText); painter->setPen(selected ? QColor(60, 60, 60) : StyleHelper::panelTextColor()); } else { painter->setPen(selected ? StyleHelper::panelTextColor() : QColor(255, 255, 255, 120)); } #ifndef Q_WS_MAC if (!selected && enabled) { painter->save(); int fader = int(m_tabs[tabIndex]->fader()); QLinearGradient grad(rect.topLeft(), rect.topRight()); grad.setColorAt(0, Qt::transparent); grad.setColorAt(0.5, QColor(255, 255, 255, fader)); grad.setColorAt(1, Qt::transparent); painter->fillRect(rect, grad); painter->setPen(QPen(grad, 1.0)); painter->drawLine(rect.topLeft(), rect.topRight()); painter->drawLine(rect.bottomLeft(), rect.bottomRight()); painter->restore(); } #endif if (!enabled) painter->setOpacity(0.7); int textHeight = painter->fontMetrics().boundingRect(QRect(0, 0, width(), height()), Qt::TextWordWrap, tabText).height(); tabIconRect.adjust(0, 4, 0, -textHeight); StyleHelper::drawIconWithShadow(tabIcon(tabIndex), tabIconRect, painter, enabled ? QIcon::Normal : QIcon::Disabled); painter->translate(0, -1); painter->drawText(tabTextRect, textFlags, tabText); painter->restore(); }
void ModeTabBar::paintEvent(QPaintEvent *event) { QPainter p(this); IconManager *iconManager = IconManager::instance(); QLinearGradient bgGrad(rect().topLeft(), rect().topRight()); bgGrad.setColorAt(0.5, palette().color(QPalette::Window)); bgGrad.setColorAt(1.0, palette().color(QPalette::Midlight)); p.fillRect(rect(), bgGrad); p.setPen(palette().color(QPalette::Shadow)); p.drawLine(width() - 1, 0, width() - 1, height()); for(int i = 0; i < count(); ++i) { p.save(); QFont labelFont = font(); labelFont.setBold(true); p.setFont(labelFont); QRect rect = tabRect(i); int textHeight = p.fontMetrics().boundingRect(QRect(0, 0, width(), height()), 0, tabLabel(i)).height(); QRect labelRect(QPoint(rect.left() + tabPadding, rect.bottom() - textHeight - tabPadding), QSize(rect.width() - (tabPadding * 2), textHeight)); int iconSize = rect.height() - textHeight - (3 * tabPadding); QRect iconRect(QPoint((rect.width() - iconSize) / 2, rect.top() + tabPadding), QSize(iconSize, iconSize)); bool isSelected = (i == m_currentIndex); bool isEnabled = isTabEnabled(i); bool isHovered = (i == m_hoverIndex); if(isHovered && isEnabled) { p.fillRect(rect.adjusted(0, 0, -1, 0), QColor(0, 0, 0, 24)); } if(isSelected) { p.save(); p.setPen(palette().color(QPalette::Shadow)); p.drawLine(rect.topLeft(), rect.topRight()); p.drawLine(rect.bottomLeft(), rect.bottomRight()); p.fillRect(rect.adjusted(0, 0, -1, 0), QColor(0, 0, 0, 32)); p.translate(rect.width() - 6, rect.top() + (rect.height() / 2) - 12); QPolygon arrowPoly; arrowPoly.append(QPoint(7, 0)); arrowPoly.append(QPoint(7, 24)); arrowPoly.append(QPoint(0, 12)); p.translate(0, 1); p.setBrush(palette().color(QPalette::Shadow)); p.setPen(palette().color(QPalette::Shadow)); p.setRenderHint(QPainter::Antialiasing); p.drawPolygon(arrowPoly); p.translate(0, -1); p.setBrush(palette().color(QPalette::Light)); p.drawPolygon(arrowPoly); p.restore(); } if(!isEnabled) p.setOpacity(0.6); QIcon icon(iconManager->icon(tabIcon(i))); QPixmap pixmap = icon.pixmap(iconSize, iconSize, isEnabled ? QIcon::Normal : QIcon::Disabled); p.drawPixmap(iconRect, pixmap); p.setPen(palette().color(QPalette::Text)); p.drawText(labelRect, Qt::AlignCenter, tabLabel(i)); p.restore(); } }