0
0
mirror of https://github.com/yse/easy_profiler.git synced 2024-12-27 00:31:02 +08:00

#0 [Gui] TreeView style fixes

This commit is contained in:
Victor Zarubkin 2018-02-25 21:04:32 +03:00
parent e3f1dfad10
commit b6b988e274
9 changed files with 42 additions and 114 deletions

View File

@ -50,8 +50,6 @@ if (Qt5Widgets_FOUND)
tree_widget_item.cpp
tree_widget_loader.h
tree_widget_loader.cpp
treeview_first_column_delegate.h
treeview_first_column_delegate.cpp
resources.qrc
resources.rc
)

View File

@ -75,7 +75,6 @@
#include <list>
#include <cmath>
#include "arbitrary_value_inspector.h"
#include "treeview_first_column_delegate.h"
#include "globals.h"
#include "easy_complexity_calculator.h"
@ -1744,7 +1743,6 @@ ArbitraryValuesWidget::ArbitraryValuesWidget(QWidget* _parent)
//m_treeWidget->setSortingEnabled(false);
m_treeWidget->setColumnCount(int_cast(ArbitraryColumns::Count));
m_treeWidget->setSelectionBehavior(QAbstractItemView::SelectRows);
m_treeWidget->setItemDelegateForColumn(0, new TreeViewFirstColumnItemDelegate(m_treeWidget));
auto headerItem = new QTreeWidgetItem();
headerItem->setText(int_cast(ArbitraryColumns::Type), "Type");

View File

@ -73,7 +73,6 @@
#include <thread>
#include "descriptors_tree_widget.h"
#include "arbitrary_value_inspector.h"
#include "treeview_first_column_delegate.h"
#include "globals.h"
#ifdef _WIN32
@ -276,8 +275,6 @@ DescriptorsTreeWidget::DescriptorsTreeWidget(QWidget* _parent)
connect(this, &Parent::currentItemChanged, this, &This::onCurrentItemChange);
loadSettings();
setItemDelegateForColumn(0, new TreeViewFirstColumnItemDelegate(this));
}
DescriptorsTreeWidget::~DescriptorsTreeWidget()

View File

@ -46,6 +46,7 @@
<file alias="arrow-down">images/default/arrow-down.svg</file>
<file alias="arrow-down-hover">images/default/arrow-down-hover.svg</file>
<file alias="arrow-down-disabled">images/default/arrow-down-disabled.svg</file>
<file alias="arrow-right">images/default/arrow-right.svg</file>
<file alias="yx-chart">images/default/yx.svg</file>
<file alias="big-o-chart">images/default/big-o.svg</file>
<file alias="csv">images/default/csv.svg</file>

View File

@ -143,6 +143,23 @@ QListView, QTableView, QTreeView {
selection-background-color: rgba(152, 222, 152, 0.8);
selection-color: #504040; }
QTreeView::branch {
selection-background-color: rgba(152, 222, 152, 0.8);
border-bottom: 1px solid #cccccc; }
QTreeView::branch:selected {
background-color: transparent; }
QTreeView::branch:open:has-children {
padding: 9px 0 9px 0;
border-image: none;
image: url(":/images/default/arrow-down"); }
QTreeView::branch:closed:has-children {
padding: 9px 0 9px 0;
border-image: none;
image: url(":/images/default/arrow-right"); }
QListView::item, QTableView::item, QTreeView::item {
height: 26px;
border-bottom: 1px solid #cccccc; }

View File

@ -160,6 +160,27 @@ QListView, QTableView, QTreeView {
selection-color: $TextColor;
}
QTreeView::branch {
selection-background-color: rgb_a(#98DE98, 0.8);
border-bottom: 1px solid $BorderColor;
}
QTreeView::branch:selected {
background-color: transparent;
}
QTreeView::branch:open:has-children {
padding: 9px 0 9px 0;
border-image: none;
image: url(":/images/default/arrow-down");
}
QTreeView::branch:closed:has-children {
padding: 9px 0 9px 0;
border-image: none;
image: url(":/images/default/arrow-right");
}
QListView::item, QTableView::item, QTreeView::item {
height: $DefaultHeight + 2px;
border-bottom: 1px solid $BorderColor;

View File

@ -350,57 +350,23 @@ TreeWidgetItemDelegate::~TreeWidgetItemDelegate()
void TreeWidgetItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
{
const auto colorBlockSize = option.rect.height() >> 1;
auto brushData = m_treeWidget->model()->data(index, BlockColorRole);
if (brushData.isNull())
{
#ifdef _WIN32
const auto currentTreeIndex = m_treeWidget->currentIndex();
if (index.parent() == currentTreeIndex.parent() && index.row() == currentTreeIndex.row())
{
// Draw selection background for selected row
painter->save();
painter->setBrush(QColor::fromRgba(0xCC98DE98));
painter->setPen(Qt::NoPen);
painter->drawRect(QRect(0, option.rect.top(), option.rect.left() + colorBlockSize, option.rect.height()));
painter->restore();
}
#endif
// Draw item as usual
QStyledItemDelegate::paint(painter, option, index);
// Draw line under tree indicator
const auto bottomLeft = option.rect.bottomLeft();
if (bottomLeft.x() > 0)
{
painter->save();
painter->setBrush(Qt::NoBrush);
painter->setPen(profiler_gui::SYSTEM_BORDER_COLOR);
painter->drawLine(QPoint(0, bottomLeft.y()), bottomLeft);
painter->restore();
}
return;
}
const auto colorBlockSize = option.rect.height() >> 1;
const auto currentTreeIndex = m_treeWidget->currentIndex();
if (index.parent() == currentTreeIndex.parent() && index.row() == currentTreeIndex.row())
{
// Draw selection background for selected row
painter->save();
painter->setBrush(QColor::fromRgba(0xCC98DE98));
painter->setPen(Qt::NoPen);
#ifdef _WIN32
painter->drawRect(QRect(0, option.rect.top(), option.rect.left() + colorBlockSize, option.rect.height()));
#else
painter->drawRect(QRect(option.rect.left(), option.rect.top(), colorBlockSize, option.rect.height()));
#endif
painter->restore();
}
@ -424,11 +390,8 @@ void TreeWidgetItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem
// Draw line under tree indicator
const auto bottomLeft = opt.rect.bottomLeft();
if (bottomLeft.x() > 0)
{
painter->setBrush(Qt::NoBrush);
painter->drawLine(QPoint(0, bottomLeft.y()), bottomLeft);
}
painter->drawLine(QPoint(bottomLeft.x() - colorBlockSize, bottomLeft.y()), bottomLeft);
painter->restore();
}

View File

@ -1,44 +0,0 @@
#include <QPainter>
#include <QPoint>
#include <QTreeWidget>
#include "treeview_first_column_delegate.h"
#include "globals.h"
TreeViewFirstColumnItemDelegate::TreeViewFirstColumnItemDelegate(QTreeWidget* parent) : QStyledItemDelegate(parent)
{
}
TreeViewFirstColumnItemDelegate::~TreeViewFirstColumnItemDelegate()
{
}
void TreeViewFirstColumnItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
{
// Draw item as usual
QStyledItemDelegate::paint(painter, option, index);
// Draw line under tree indicator
const auto bottomLeft = option.rect.bottomLeft();
if (bottomLeft.x() > 0)
{
painter->save();
if (static_cast<const QTreeWidget*>(parent())->currentIndex() == index)
{
// Draw selection background for current item
painter->setBrush(QColor::fromRgba(0xCC98DE98));
painter->setPen(Qt::NoPen);
painter->drawRect(QRectF(0, option.rect.top(), bottomLeft.x(), option.rect.height()));
}
painter->setBrush(Qt::NoBrush);
painter->setPen(::profiler_gui::SYSTEM_BORDER_COLOR);
painter->drawLine(QPoint(0, bottomLeft.y()), bottomLeft);
painter->restore();
}
}

View File

@ -1,23 +0,0 @@
#ifndef EASY_PROFILER_GUI_TREEVIEW_FIRST_COLUMN_DELEGATE_H
#define EASY_PROFILER_GUI_TREEVIEW_FIRST_COLUMN_DELEGATE_H
#include <QStyledItemDelegate>
class TreeViewFirstColumnItemDelegate : public QStyledItemDelegate
{
Q_OBJECT
public:
explicit TreeViewFirstColumnItemDelegate(class QTreeWidget* parent = nullptr);
~TreeViewFirstColumnItemDelegate() override;
void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const override;
}; // END of class TreeViewFirstColumnItemDelegate.
#endif // EASY_PROFILER_GUI_TREEVIEW_FIRST_COLUMN_DELEGATE_H