Core: Gui: DAGView: see following note:

Rework highlight rendering.
    Exception for topo sort.
This commit is contained in:
blobfish 2015-07-30 12:55:36 -04:00 committed by Stefan Tröger
parent e7a96ac26f
commit 03ad4d752c
3 changed files with 38 additions and 37 deletions

View File

@ -50,6 +50,7 @@
#include <unordered_set>
#include <Base/TimeInfo.h>
#include <Base/Console.h>
#include <Gui/Application.h>
#include <Gui/Document.h>
#include <Gui/ViewProviderDocumentObject.h>
@ -240,14 +241,6 @@ void Model::slotNewObject(const ViewProviderDocumentObject &VPDObjectIn)
//setup rectangle.
auto *rectangle = (*theGraph)[virginVertex].rectangle.get();
rectangle->setPen(Qt::NoPen);
QColor preSelectionColor = qApp->palette().highlight().color();
preSelectionColor.setAlphaF(0.25);
rectangle->setPreselectionBrush(QBrush(preSelectionColor));
rectangle->setSelectionBrush(qApp->palette().highlight());
QColor bothSelectionColor = qApp->palette().highlight().color();
bothSelectionColor.setAlphaF(0.75);
rectangle->setBothBrush(QBrush(bothSelectionColor));
rectangle->setEditingBrush(QBrush(Qt::yellow));
(*theGraph)[virginVertex].icon->setPixmap(VPDObjectIn.getIcon().pixmap(iconSize, iconSize));
@ -526,18 +519,17 @@ void Model::updateSlot()
this->removeItem((*theGraph)[currentEdge].connector.get());
}
indexVerticesEdges();
Path sorted;
try {
// this sort gives the execute
boost::topological_sort(*theGraph, std::back_inserter(sorted));
try
{
boost::topological_sort(*theGraph, std::back_inserter(sorted));
}
catch (const std::exception& e) {
std::cerr << "Document::recompute: " << e.what() << std::endl;
return;
catch(const boost::not_a_dag &)
{
Base::Console().Error("not a dag exception in DAGView::Model::updateSlot()\n");
return;
}
//index the vertices in sort order.
int tempIndex = 0;
for (const auto &currentVertex : sorted)

View File

@ -23,8 +23,11 @@
#include "PreCompiled.h"
#ifndef _PreComp_
#include <QPainter>
#include <QApplication>
#endif
#include <QStyleOptionViewItem>
#include "DAGRectItem.h"
using namespace Gui;
@ -39,25 +42,37 @@ RectItem::RectItem(QGraphicsItem* parent) : QGraphicsRectItem(parent)
void RectItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
{
//TODO figure out how to mimic painting of itemviews. QStyle, QStyledItemDelegate.
painter->save();
QBrush brush = backgroundBrush;
if (selected)
brush = selectionBrush;
if (preSelected)
brush = preSelectionBrush;
if (selected && preSelected)
brush = bothBrush;
QStyleOptionViewItemV4 styleOption;
styleOption.backgroundBrush = backgroundBrush;
if (editing)
brush = editBrush;
styleOption.backgroundBrush = editBrush;
else
{
styleOption.state |= QStyle::State_Enabled;
if (selected)
styleOption.state |= QStyle::State_Selected;
if (preSelected)
{
if (!selected)
{
styleOption.state |= QStyle::State_Selected;
QPalette palette = styleOption.palette;
QColor tempColor = palette.color(QPalette::Active, QPalette::Highlight);
tempColor.setAlphaF(0.15);
palette.setColor(QPalette::Inactive, QPalette::Highlight, tempColor);
styleOption.palette = palette;
}
styleOption.state |= QStyle::State_MouseOver;
}
}
styleOption.rect = this->rect().toRect();
//heights are negative.
float radius = std::min(this->rect().width(), std::fabs(this->rect().height())) * 0.1;
painter->setBrush(brush);
painter->setPen(this->pen()); //should be Qt::NoPen.
painter->drawRoundedRect(this->rect(), radius, radius);
QApplication::style()->drawControl(QStyle::CE_ItemViewItem, &styleOption, painter);
// QGraphicsRectItem::paint(painter, option, widget);
painter->restore();
}
#include <moc_DAGRectItem.cpp>

View File

@ -38,9 +38,6 @@ namespace Gui
public:
RectItem(QGraphicsItem* parent = 0);
void setBackgroundBrush(const QBrush &brushIn){backgroundBrush = brushIn;}
void setPreselectionBrush(const QBrush &brushIn){preSelectionBrush = brushIn;}
void setSelectionBrush(const QBrush &brushIn){selectionBrush = brushIn;}
void setBothBrush(const QBrush &brushIn){bothBrush = brushIn;}
void setEditingBrush(const QBrush &brushIn){editBrush = brushIn;}
void preHighlightOn(){preSelected = true;}
void preHighlightOff(){preSelected = false;}
@ -55,9 +52,6 @@ namespace Gui
virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0);
private:
QBrush backgroundBrush; //!< brush used for background. not used yet.
QBrush selectionBrush; //!< brush used when selected.
QBrush preSelectionBrush; //!< brush used when pre selected.
QBrush bothBrush; //!< brush for when both selected and preSelected.
QBrush editBrush; //!< brush used when object is in edit mode.
//start with booleans, may expand to state.
bool selected;