Skip to content

Commit

Permalink
Make layer tree layer mark just a thin line; remove context menu action
Browse files Browse the repository at this point in the history
  • Loading branch information
dakcarto committed Jun 20, 2019
1 parent ebd4f0d commit 2fd24d1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 44 deletions.
2 changes: 1 addition & 1 deletion src/gui/layertree/qgslayertreeview.cpp
Expand Up @@ -58,7 +58,7 @@ QgsLayerTreeView::QgsLayerTreeView( QWidget *parent )
setItemDelegate( new QgsLayerTreeViewItemDelegate( this ) );
setStyle( new QgsLayerTreeViewProxyStyle( this ) );

setLayerMarkWidth( static_cast< int >( QFontMetricsF( font() ).width( 'X' ) * 1.75 * Qgis::UI_SCALE_FACTOR ) );
setLayerMarkWidth( static_cast< int >( QFontMetricsF( font() ).width( 'l' ) * Qgis::UI_SCALE_FACTOR ) );

connect( this, &QTreeView::collapsed, this, &QgsLayerTreeView::updateExpandedStateToNode );
connect( this, &QTreeView::expanded, this, &QgsLayerTreeView::updateExpandedStateToNode );
Expand Down
51 changes: 8 additions & 43 deletions src/gui/layertree/qgslayertreeviewitemdelegate.cpp
Expand Up @@ -49,7 +49,7 @@ QRect QgsLayerTreeViewProxyStyle::subElementRect( QStyle::SubElement element, co
QRect r = QProxyStyle::subElementRect( SE_ItemViewItemText, option, widget );
int indiWidth = r.height() * count;
int spacing = r.height() / 10;
int vpIndiWidth = vpr.width() - indiWidth - spacing - mLayerTreeView->layerMarkWidth() - spacing;
int vpIndiWidth = vpr.width() - indiWidth - spacing - mLayerTreeView->layerMarkWidth();
return QRect( vpIndiWidth, r.top(), indiWidth, r.height() );
}
}
Expand Down Expand Up @@ -82,28 +82,15 @@ void QgsLayerTreeViewItemDelegate::paint( QPainter *painter, const QStyleOptionV
initStyleOption( &opt, index );

QRect tRect = mLayerTreeView->style()->subElementRect( QStyle::SE_ItemViewItemText, &opt, mLayerTreeView );
int tSpacing = tRect.height() / 6;
int tPadding = tRect.height() / 10;

// Draw layer context menu mark
QRect mRect( mLayerTreeView->viewport()->rect().right() - mLayerTreeView->layerMarkWidth(), tRect.top() + tPadding, mLayerTreeView->layerMarkWidth(), tRect.height() - tPadding * 2 );
qreal ex = mRect.x() + 0.5 + mRect.width() / 2;
qreal eradius = tSpacing * 0.5;
qreal bradius = tPadding;
QBrush pb = painter->brush();
QPen pp = painter->pen();
painter->setPen( QPen( QBrush( opt.palette.mid() ), 0.25 ) );
// background
painter->setBrush( QBrush( opt.palette.midlight() ) );
painter->drawRoundedRect( mRect, bradius, bradius );
// mark
painter->setPen( QPen( Qt::NoPen ) );
painter->setBrush( QBrush( Qt::darkGray ) );
painter->drawEllipse( QPointF( ex, mRect.top() + tSpacing * 1.25 ), eradius, eradius );
painter->drawEllipse( QPointF( ex, mRect.top() + tSpacing * 2.75 ), eradius, eradius );
painter->drawEllipse( QPointF( ex, mRect.top() + tSpacing * 4.25 ), eradius, eradius );
painter->setBrush( pb );
painter->setPen( pp );
painter->setBrush( QBrush( opt.palette.mid() ) );
painter->drawRect( mRect );

const QList<QgsLayerTreeViewIndicator *> indicators = mLayerTreeView->indicators( node );
if ( indicators.isEmpty() )
Expand Down Expand Up @@ -194,40 +181,18 @@ void QgsLayerTreeViewItemDelegate::onClicked( const QModelIndex &index )
if ( !node )
return;

const QList<QgsLayerTreeViewIndicator *> indicators = mLayerTreeView->indicators( node );
if ( indicators.isEmpty() )
return;

QStyleOptionViewItem opt( mLayerTreeView->viewOptions() );
opt.rect = mLayerTreeView->visualRect( index );
initStyleOption( &opt, index );
_fixStyleOption( opt );

QPoint pos = mLayerTreeView->mLastReleaseMousePos;

QRect tRect = mLayerTreeView->style()->subElementRect( QStyle::SE_ItemViewItemText, &opt, mLayerTreeView );
int spacing = tRect.height() / 10;
QRect mRect( mLayerTreeView->viewport()->rect().right() - mLayerTreeView->layerMarkWidth() - spacing * 2, tRect.top(), mLayerTreeView->layerMarkWidth(), tRect.height() );

if ( mRect.contains( pos ) )
{
QgsLayerTreeViewMenuProvider *menuProvider = mLayerTreeView->menuProvider();
if ( !menuProvider )
{
return;
}

QMenu *menu = menuProvider->createContextMenu();
if ( menu && menu->actions().count() != 0 )
{
menu->exec( mLayerTreeView->viewport()->mapToGlobal( pos ) );
}
delete menu;
return;
}

const QList<QgsLayerTreeViewIndicator *> indicators = mLayerTreeView->indicators( node );
if ( indicators.isEmpty() )
return;

QRect indRect = mLayerTreeView->style()->subElementRect( static_cast<QStyle::SubElement>( QgsLayerTreeViewProxyStyle::SE_LayerTreeItemIndicator ), &opt, mLayerTreeView );

QPoint pos = mLayerTreeView->mLastReleaseMousePos;
if ( indRect.contains( pos ) )
{
int indicatorIndex = ( pos.x() - indRect.left() ) / indRect.height();
Expand Down

0 comments on commit 2fd24d1

Please sign in to comment.