Пример #1
0
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;
}
Пример #2
0
void TabBar::setTabHighlighted(int index)
{
    const QByteArray propertyName = highlightPropertyName(index);
    const QColor highlightColor = KColorScheme(QPalette::Active, KColorScheme::Window).foreground(KColorScheme::PositiveText).color();

    if (tabTextColor(index) != highlightColor)
    {
        if (ReKonfig::animatedTabHighlighting())
        {
            m_tabHighlightEffect->setEnabled(true);
            m_tabHighlightEffect->setProperty(propertyName, qreal(0.9));
            QPropertyAnimation *anim = new QPropertyAnimation(m_tabHighlightEffect, propertyName);
            m_highlightAnimation.insert(propertyName, anim);

            //setup the animation
            anim->setStartValue(0.9);
            anim->setEndValue(0.0);
            anim->setDuration(500);
            anim->setLoopCount(2);
            anim->start(QAbstractAnimation::DeleteWhenStopped);

            m_animationMapper->setMapping(anim, index);
            connect(anim, SIGNAL(finished()), m_animationMapper, SLOT(map()));
        }

        setTabTextColor(index, highlightColor);
    }
}
Пример #3
0
void TabBar::overrideTabTextColor(int index, QColor color)
{
    if (!m_originalTabTextColor.isValid()) {
        m_originalTabTextColor = tabTextColor(index);
    }

    setTabTextColor(index, color);
}
Пример #4
0
void pTabBar::dropEvent( QDropEvent* event )
{
    if ( !event->mimeData()->hasUrls() )
    {
        // get drop tab
        int ni = tabAt( event->pos() );
        
        // if get it
        if ( ni != -1 )
        {
            // get original tab infos
            int oi = event->mimeData()->data( "x-tabindex" ).toInt();
            QVariant otd = tabData( oi );
            QIcon oti = tabIcon( oi );
            QString ott = tabText( oi );
            QColor ottc = tabTextColor( oi );
            QString ottt = tabToolTip( oi );
            QString otwt = tabWhatsThis( oi );
            
            // remove original tab
            removeTab( oi );
            
            // insert new one with correct infos
            int i = insertTab( ni, oti, ott );
            setTabData( i, otd );
            setTabTextColor( i, ottc );
            setTabToolTip( i, ottt );
            setTabWhatsThis( i, otwt );
            
            //accept
            event->acceptProposedAction();
            
            // emit signal
            emit tabDropped( oi, i );
            
            // set new current index
            setCurrentIndex( i );
        }
    }
    else
        emit urlsDropped( event->mimeData()->urls () );
    
    // default event
    QTabBar::dropEvent( event );
}