mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Style sheet now applied to PdmUiTreeViewEditor.
Move some classes from PdmUiTreeViewEditor.cpp to the header file in order to make them available in RiuGuiTheme to adjust the style of tree views and keep the drag&drop styling. Removed getStyleSheet function.
This commit is contained in:
committed by
Magne Sjaastad
parent
a68598fd16
commit
0f92ad13ad
@@ -64,87 +64,78 @@
|
||||
|
||||
namespace caf
|
||||
{
|
||||
class PdmUiTreeViewStyle : public QProxyStyle
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void PdmUiTreeViewStyle::drawPrimitive( QStyle::PrimitiveElement element,
|
||||
const QStyleOption* option,
|
||||
QPainter* painter,
|
||||
const QWidget* widget ) const
|
||||
{
|
||||
public:
|
||||
void drawPrimitive( PrimitiveElement element, const QStyleOption* option, QPainter* painter, const QWidget* widget ) const override
|
||||
if ( element == QStyle::PE_IndicatorItemViewItemDrop )
|
||||
{
|
||||
if ( element == QStyle::PE_IndicatorItemViewItemDrop )
|
||||
painter->setRenderHint( QPainter::Antialiasing, true );
|
||||
|
||||
if ( option->rect.height() == 0 )
|
||||
{
|
||||
painter->setRenderHint( QPainter::Antialiasing, true );
|
||||
QPalette palette;
|
||||
QColor c = QApplication::palette().color( QPalette::Highlight ).darker( 150 );
|
||||
QPen pen( c );
|
||||
pen.setWidth( 2 );
|
||||
QBrush brush( c );
|
||||
|
||||
if ( option->rect.height() == 0 )
|
||||
{
|
||||
QPalette palette;
|
||||
QColor c = QApplication::palette().color( QPalette::Highlight ).darker( 150 );
|
||||
QPen pen( c );
|
||||
pen.setWidth( 2 );
|
||||
QBrush brush( c );
|
||||
painter->setPen( pen );
|
||||
painter->setBrush( brush );
|
||||
|
||||
painter->setPen( pen );
|
||||
painter->setBrush( brush );
|
||||
|
||||
painter->drawEllipse( option->rect.topLeft(), 3, 3 );
|
||||
painter->drawLine( QPoint( option->rect.topLeft().x() + 3, option->rect.topLeft().y() ),
|
||||
option->rect.topRight() );
|
||||
}
|
||||
else
|
||||
{
|
||||
QPalette palette;
|
||||
QColor c = QApplication::palette().color( QPalette::Highlight ).darker( 150 );
|
||||
QPen pen( c );
|
||||
pen.setWidth( 2 );
|
||||
|
||||
painter->setPen( pen );
|
||||
|
||||
painter->drawRoundedRect( option->rect, 4, 4 );
|
||||
}
|
||||
painter->drawEllipse( option->rect.topLeft(), 3, 3 );
|
||||
painter->drawLine( QPoint( option->rect.topLeft().x() + 3, option->rect.topLeft().y() ),
|
||||
option->rect.topRight() );
|
||||
}
|
||||
else
|
||||
{
|
||||
QProxyStyle::drawPrimitive( element, option, painter, widget );
|
||||
QPalette palette;
|
||||
QColor c = QApplication::palette().color( QPalette::Highlight ).darker( 150 );
|
||||
QPen pen( c );
|
||||
pen.setWidth( 2 );
|
||||
|
||||
painter->setPen( pen );
|
||||
|
||||
painter->drawRoundedRect( option->rect, 4, 4 );
|
||||
}
|
||||
}
|
||||
};
|
||||
else
|
||||
{
|
||||
QProxyStyle::drawPrimitive( element, option, painter, widget );
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
class PdmUiTreeViewWidget : public QTreeView
|
||||
void PdmUiTreeViewWidget::dragMoveEvent( QDragMoveEvent* event )
|
||||
{
|
||||
public:
|
||||
explicit PdmUiTreeViewWidget( QWidget* parent = nullptr )
|
||||
: QTreeView( parent )
|
||||
caf::PdmUiTreeViewQModel* treeViewModel = dynamic_cast<caf::PdmUiTreeViewQModel*>( model() );
|
||||
if ( treeViewModel && treeViewModel->dragDropInterface() )
|
||||
{
|
||||
setStyle( new PdmUiTreeViewStyle );
|
||||
};
|
||||
~PdmUiTreeViewWidget() override{};
|
||||
|
||||
bool isTreeItemEditWidgetActive() const { return state() == QAbstractItemView::EditingState; }
|
||||
|
||||
protected:
|
||||
void dragMoveEvent( QDragMoveEvent* event ) override
|
||||
{
|
||||
caf::PdmUiTreeViewQModel* treeViewModel = dynamic_cast<caf::PdmUiTreeViewQModel*>( model() );
|
||||
if ( treeViewModel && treeViewModel->dragDropInterface() )
|
||||
{
|
||||
treeViewModel->dragDropInterface()->onProposedDropActionUpdated( event->proposedAction() );
|
||||
}
|
||||
|
||||
QTreeView::dragMoveEvent( event );
|
||||
treeViewModel->dragDropInterface()->onProposedDropActionUpdated( event->proposedAction() );
|
||||
}
|
||||
|
||||
void dragLeaveEvent( QDragLeaveEvent* event ) override
|
||||
{
|
||||
caf::PdmUiTreeViewQModel* treeViewModel = dynamic_cast<caf::PdmUiTreeViewQModel*>( model() );
|
||||
if ( treeViewModel && treeViewModel->dragDropInterface() )
|
||||
{
|
||||
treeViewModel->dragDropInterface()->onDragCanceled();
|
||||
}
|
||||
QTreeView::dragMoveEvent( event );
|
||||
}
|
||||
|
||||
QTreeView::dragLeaveEvent( event );
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void PdmUiTreeViewWidget::dragLeaveEvent( QDragLeaveEvent* event )
|
||||
{
|
||||
caf::PdmUiTreeViewQModel* treeViewModel = dynamic_cast<caf::PdmUiTreeViewQModel*>( model() );
|
||||
if ( treeViewModel && treeViewModel->dragDropInterface() )
|
||||
{
|
||||
treeViewModel->dragDropInterface()->onDragCanceled();
|
||||
}
|
||||
};
|
||||
|
||||
QTreeView::dragLeaveEvent( event );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
|
||||
@@ -46,6 +46,7 @@
|
||||
#include <QColor>
|
||||
#include <QItemSelectionModel>
|
||||
#include <QPointer>
|
||||
#include <QProxyStyle>
|
||||
#include <QStyledItemDelegate>
|
||||
#include <QTreeView>
|
||||
#include <QWidget>
|
||||
@@ -68,6 +69,35 @@ class PdmUiTreeViewEditor;
|
||||
class PdmUiTreeViewQModel;
|
||||
class PdmUiTreeViewWidget;
|
||||
|
||||
class PdmUiTreeViewStyle : public QProxyStyle
|
||||
{
|
||||
public:
|
||||
void drawPrimitive( QStyle::PrimitiveElement element,
|
||||
const QStyleOption* option,
|
||||
QPainter* painter,
|
||||
const QWidget* widget ) const override;
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
class PdmUiTreeViewWidget : public QTreeView
|
||||
{
|
||||
public:
|
||||
explicit PdmUiTreeViewWidget( QWidget* parent = nullptr )
|
||||
: QTreeView( parent )
|
||||
{
|
||||
setStyle( new PdmUiTreeViewStyle );
|
||||
};
|
||||
~PdmUiTreeViewWidget() override{};
|
||||
|
||||
bool isTreeItemEditWidgetActive() const { return state() == QAbstractItemView::EditingState; }
|
||||
|
||||
protected:
|
||||
void dragMoveEvent( QDragMoveEvent* event ) override;
|
||||
void dragLeaveEvent( QDragLeaveEvent* event ) override;
|
||||
};
|
||||
|
||||
class PdmUiTreeViewItemAttribute : public PdmUiEditorAttribute
|
||||
{
|
||||
public:
|
||||
|
||||
Reference in New Issue
Block a user