Skip to content

Commit

Permalink
fix: revert tab style and add fix for mac (#327,#192)
Browse files Browse the repository at this point in the history
  • Loading branch information
variar committed Aug 1, 2021
1 parent 5c2402d commit 663d0f2
Showing 1 changed file with 53 additions and 2 deletions.
55 changes: 53 additions & 2 deletions src/ui/src/tabbedcrawlerwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,57 @@ TabbedCrawlerWidget::TabbedCrawlerWidget()
, newdata_icon_( ":/images/newdata_icon.png" )
, newfiltered_icon_( ":/images/newfiltered_icon.png" )
{

QString tabStyle = "QTabBar::tab { height: 24px; }";
QString tabCloseButtonStyle = " QTabBar::close-button {\
height: 12px; width: 12px;\
subcontrol-origin: padding;\
subcontrol-position: right;\
%1}";
QString tabCloseButtonHoverStyle = " QTabBar::close-button:hover { %1 }";
const QString backgroundImageTemplate = " image: url(%1);";

QString backgroundImage;
QString backgroundHoverImage;

const auto& config = Configuration::get();
if ( config.style() == StyleManager::DarkStyleKey ) {
backgroundImage = ":/images/icons8-close-window-16_inverse.png";
backgroundHoverImage = ":/images/icons8-close-window-hover-16_inverse.png";
}

#if defined( Q_OS_MAC )
// work around Qt MacOSX bug missing tab close icons
// see: https://bugreports.qt.io/browse/QTBUG-61092
// still broken in document mode in Qt.5.12.2 !!!!

const auto& config = Configuration::get();
if ( config.style() != StyleManager::DarkStyleKey ) {
backgroundImage
= ":/qt-project.org/styles/commonstyle/images/standardbutton-closetab-16.png";
backgroundHoverImage
= ":/qt-project.org/styles/commonstyle/images/standardbutton-closetab-hover-16.png";
}
#elif defined( Q_OS_WIN )
if ( config.style() == StyleManager::FusionKey ) {
backgroundImage = ":/images/icons8-close-window-16.png";
backgroundHoverImage = ":/images/icons8-close-window-hover-16.png";
}
#endif

if ( !backgroundImage.isEmpty() ) {
backgroundImage = backgroundImageTemplate.arg( backgroundImage );
backgroundHoverImage = backgroundImageTemplate.arg( backgroundHoverImage );
tabCloseButtonHoverStyle = tabCloseButtonHoverStyle.arg( backgroundHoverImage );
tabCloseButtonStyle = tabCloseButtonStyle.arg( backgroundImage );
tabCloseButtonStyle.append( tabCloseButtonHoverStyle );
}
else {
tabCloseButtonStyle = tabCloseButtonStyle.arg( "" );
}

myTabBar_.setStyleSheet( tabStyle.append( tabCloseButtonStyle ) );

setTabBar( &myTabBar_ );
myTabBar_.hide();

Expand Down Expand Up @@ -81,7 +132,7 @@ void TabbedCrawlerWidget::addTabBarItem( int index, const QString& fileName )
const auto tabLabel = QFileInfo( fileName ).fileName();
const auto tabName = TabNameMapping::getSynced().tabName( fileName );

myTabBar_.setTabIcon(index, olddata_icon_);
myTabBar_.setTabIcon( index, olddata_icon_ );
myTabBar_.setTabText( index, tabName.isEmpty() ? tabLabel : tabName );
myTabBar_.setTabToolTip( index, QDir::toNativeSeparators( fileName ) );

Expand Down Expand Up @@ -269,7 +320,7 @@ void TabbedCrawlerWidget::updateIcon( int index )
return;
}

myTabBar_.setTabIcon(index, *icon);
myTabBar_.setTabIcon( index, *icon );
}

void TabbedCrawlerWidget::setTabDataStatus( int index, DataStatus status )
Expand Down

0 comments on commit 663d0f2

Please sign in to comment.