Verified Commit 24fcddf2 authored by ita1024's avatar ita1024

Preview diagrams on the main map

parent da799ac2
Semantik 1.0.9
--------------
* Display pictures and diagrams on the main map
Semantik 1.0.8
--------------
* Add new formatting actions to the Rich Text editor: text color, hyperlink, list, clear formatting
......
Improve diagram link labels positioning
Z-index in diagrams
Crossing diagram arrows for the one with higher z-index
Display pictures on the map
Half-broken diagram links routing with sequences
Serialize undo operations
Arbitrary SVG shapes
......
......@@ -82,7 +82,18 @@ data_item::data_item(int i_iId)
const QPixmap data_item::getPix(sem_mediator* i_oMediator) const
{
return i_oMediator->getPix(m_iPicId);
if (m_iDataType == VIEW_IMG)
{
return i_oMediator->getPix(m_iPicId);
}
else if (m_iDataType == VIEW_DIAG)
{
return i_oMediator->getPix(m_iId);
}
else
{
return QPixmap();
}
}
const QPixmap data_item::getThumb(sem_mediator* i_oMediator) const
......
......@@ -10,7 +10,7 @@
#include "mem_base.h"
inline uint qHash(const QPoint &p) {
return p.x() + p.y();
return p.x() + 100000 * p.y();
}
......
......@@ -56,7 +56,6 @@ canvas_item::canvas_item(canvas_view *i_oGraphWidget, int i_iId) : QGraphicsText
m_oPic = new canvas_pic(i_oGraphWidget, i_iId);
m_oPic->setParentItem(this);
m_oPic->setRect(QRectF(0, 0, 100, 100));
m_oPic->setPos(boundingRect().bottomLeft() + QPointF(0, 5));
m_oSort = new canvas_sort(i_oGraphWidget, this);
m_oChain = new canvas_chain(i_oGraphWidget);
......@@ -80,6 +79,7 @@ canvas_item::canvas_item(canvas_view *i_oGraphWidget, int i_iId) : QGraphicsText
update_flags();
document()->setDefaultFont(scene()->font());
m_oPic->setPos(boundingRect().bottomLeft() + QPointF(0, 5));
}
// (i_oEv == QKeySequence::DeleteEndOfWord)
......@@ -129,7 +129,7 @@ void canvas_item::update_data()
l_oItem.m_iYY = m_oGraph->m_oLastPoint.y();
}
if (l_oItem.m_iDataType == VIEW_IMG)
if (l_oItem.m_iDataType == VIEW_IMG || l_oItem.m_iDataType == VIEW_DIAG)
{
m_oPic->setVisible(true);
}
......@@ -162,6 +162,7 @@ void canvas_item::update_links()
{
l_oLink->update_pos();
}
m_oPic->setPos(boundingRect().bottomLeft() + QPointF(0, 5));
}
void canvas_item::update_flags()
......@@ -228,6 +229,7 @@ void canvas_item::keyPressEvent(QKeyEvent* e) {
QGraphicsTextItem::keyPressEvent(e);
adjustSize();
update_links();
m_oPic->setPos(boundingRect().bottomLeft() + QPointF(0, 5));
}
void canvas_item::adjustSize() {
......
......@@ -24,6 +24,7 @@
#include "sem_mediator.h"
#include "con.h"
#include "data_item.h"
#include "box_view.h"
#include "canvas_pic.h"
#include "canvas_view.h"
......@@ -31,38 +32,46 @@
canvas_pic::canvas_pic(canvas_view *i_oGraphWidget, int i_iId) : QGraphicsRectItem(), m_oGraph(i_oGraphWidget)
{
m_oBoxView = NULL;
m_iId = i_iId;
setZValue(99);
setZValue(98);
setFlags(QGraphicsItem::ItemStacksBehindParent);
setVisible(false);
i_oGraphWidget->scene()->addItem(this);
}
canvas_pic::~canvas_pic()
{
delete m_oBoxView;
//m_oBoxView = NULL;
}
void canvas_pic::paint(QPainter *i_oPainter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
QRectF l_o = boundingRect().adjusted(pad, pad, -pad, -pad);
data_item& l_oData = m_oGraph->m_oMediator->m_oItems[m_iId];
if (l_oData.m_iDataType == VIEW_IMG)
{
const QPixmap& l_oPix = l_oData.getPix(m_oGraph->m_oMediator);
if (!l_oPix.isNull())
QRect l_oPixRect = l_oPix.rect();
if (l_oPixRect.width() > l_oPixRect.height())
{
QRectF l_o = boundingRect().adjusted(pad, pad, -pad, -pad);
QRect l_oPixRect = l_oPix.rect();
if (l_oPixRect.width() > l_oPixRect.height())
{
l_o.setHeight(l_o.height() * (1. * l_oPixRect.height() / l_oPixRect.width()));
}
else
{
l_o.setWidth(l_o.width() * (1. * l_oPixRect.width() / l_oPixRect.height()));
}
i_oPainter->drawPixmap(l_o, l_oPix, l_oPixRect);
l_o.setHeight(l_o.height() * (1. * l_oPixRect.height() / l_oPixRect.width()));
}
else
{
l_o.setWidth(l_o.width() * (1. * l_oPixRect.width() / l_oPixRect.height()));
}
i_oPainter->drawPixmap(l_o, l_oPix, l_oPixRect);
}
else if (l_oData.m_iDataType == VIEW_DIAG)
{
if (m_oBoxView == NULL)
{
m_oBoxView = new box_view(m_oGraph, m_oGraph->m_oMediator);
}
m_oBoxView->drawThumb(i_oPainter, l_o, m_iId);
}
}
......@@ -22,18 +22,21 @@ class canvas_link;
class canvas_sort;
class canvas_flag;
class canvas_chain;
class box_view;
class canvas_sort_toggle;
class canvas_pic: public QGraphicsRectItem
{
public:
canvas_pic(canvas_view *i_oGraphWidget, int i_iId);
~canvas_pic();
int type() const { return CANVAS_PIC_T; }
void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget);
canvas_view * m_oGraph;
QPixmap m_oPixmap;
box_view *m_oBoxView;
int m_iId;
......
......@@ -1926,6 +1926,60 @@ bool box_view::slot_save() {
return false;
}
void box_view::drawThumb(QPainter* i_oPainter, QRectF& i_oRect, int i_iId)
{
clear_diagram();
m_iId = i_iId;
Q_ASSERT(m_oMediator->m_oItems.contains(m_iId));
data_item& l_oData = m_oMediator->m_oItems[m_iId];
if (l_oData.m_iDataType == VIEW_DIAG)
{
if (!l_oData.m_sDiag.isEmpty())
{
from_string(l_oData.m_sDiag);
l_oData.m_sDiag = notr("");
}
sync_view();
check_canvas_size();
}
else
{
return;
}
QRectF l_oRect = scene()->itemsBoundingRect();
foreach (QGraphicsItem*it, scene()->items())
{
it->setCacheMode(QGraphicsItem::NoCache); // the magic happens here
}
l_oRect = l_oRect.adjusted(-15, -15, 15, 15);
QRectF l_oR(0, 0, l_oRect.width(), l_oRect.height());
QRectF l_oDrawRect(i_oRect);
if (l_oRect.width() > l_oRect.height())
{
l_oDrawRect.setHeight(l_oDrawRect.height() * (1. * l_oRect.height() / l_oRect.width()));
}
else
{
l_oDrawRect.setWidth(l_oDrawRect.width() * (1. * l_oRect.width() / l_oRect.height()));
}
i_oPainter->save();
QPen l_oPen;
l_oPen.setCosmetic(true);
i_oPainter->setPen(l_oPen);
i_oPainter->setBrush(Qt::white);
i_oPainter->drawRect(l_oDrawRect);
i_oPainter->restore();
scene()->render(i_oPainter, i_oRect, l_oRect, Qt::KeepAspectRatio);
}
int box_view::batch_print_map(const QUrl& i_oUrl, QPair<int, int> & p)
{
QString url = i_oUrl.path();
......
......@@ -118,6 +118,9 @@ class box_view : public QGraphicsView
int next_seq();
int num_seq;
const QPixmap getPix(int i_iId);
void drawThumb(QPainter* i_oPainter, QRectF& l_o, int m_iId);
void message(const QString &, int);
bool m_bDisableGradient;
bool m_bShowFileMenu;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment