Verified Commit 3b0ec1d9 authored by ita1024's avatar ita1024

Position diagram boundary captions to top or bottom

parent efc0b9a5
Semantik 1.0.8
--------------
* Add new formatting actions to the Rich Text editor: text color, hyperlink, list, clear formatting
* Position diagram boundary captions to top or bottom
Semantik 1.0.7
--------------
......
Manual positioning of diagram link labels (and better default positioning)
Improve diagram link labels positioning
Z-index in diagrams
Crossing diagram arrows for the one with higher z-index
Display pictures on the map
......@@ -6,4 +6,3 @@ Half-broken diagram links routing with sequences
Serialize undo operations
Arbitrary SVG shapes
Enable html in floating text boxes
Position frame labels up or down
......@@ -153,6 +153,7 @@ data_box::data_box(int id) : diagram_item(), node()
m_iHH = 40;
m_iAlign = Qt::AlignCenter;
m_oCustom.m_oInnerColor = QColor("#a7e89b");
m_iLabelPosition = Qt::TopEdge;
m_bAbstract = false;
m_bStatic = false;
......@@ -164,6 +165,7 @@ data_box& data_box::operator=(const data_box & i_o)
m_iId = i_o.m_iId;
m_sText = i_o.m_sText;
m_iAlign = i_o.m_iAlign;
m_iLabelPosition = i_o.m_iLabelPosition;
m_bIsEnd = i_o.m_bIsEnd;
m_bIsEnd = i_o.m_bIsEnd;
......@@ -205,12 +207,13 @@ void data_box::dump_xml(QStringList & i_oS)
QString::number(m_iHH),
m_oCustom.m_oInnerColor.name(),
QString::number((int) m_iType),
QString(" v=\"%1\" e=\"%2\" seq=\"%3\" version=\"2\" color_id=\"%4\" align=\"%5\"").arg(
QString(" v=\"%1\" e=\"%2\" seq=\"%3\" version=\"3\" color_id=\"%4\" align=\"%5\" label_position=\"%6\"").arg(
QString::number((int) m_bIsVertical),
QString::number((int) m_bIsEnd),
QString::number((int) m_iBoxHeight),
QString::number((int) m_iColor),
QString::number((int) m_iAlign)
QString::number((int) m_iAlign),
QString::number((int) m_iLabelPosition)
)
);
......@@ -249,6 +252,11 @@ void data_box::read_data(const QString& i_sTag, const QXmlAttributes& i_oAttrs)
m_iWW = i_oAttrs.value(notr("w")).toFloat();
m_iHH = i_oAttrs.value(notr("h")).toFloat();
m_iType = (data_box::IType) i_oAttrs.value(notr("t")).toInt();
m_iLabelPosition = (Qt::Edge) i_oAttrs.value(notr("label_position")).toInt();
if (m_iLabelPosition == 0)
{
m_iLabelPosition = Qt::TopEdge;
}
m_bIsVertical = i_oAttrs.value(notr("v")).toInt();
m_bIsEnd = i_oAttrs.value(notr("e")).toInt();
m_iBoxHeight = i_oAttrs.value(notr("seq")).toInt();
......
......@@ -160,6 +160,9 @@ class data_box : public diagram_item, public node
int m_iBoxHeight;
// frame
Qt::Edge m_iLabelPosition;
// class
bool m_bStatic;
bool m_bAbstract;
......
......@@ -4,6 +4,8 @@
#include <QAbstractTextDocumentLayout>
#include <QTextDocument>
#include <QTextDocumentFragment>
#include <box_frame_properties.h>
#include <QComboBox>
#include <QTextList>
#include <QClipboard>
#include <QPainter>
......@@ -46,11 +48,29 @@ void box_frame::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
painter->drawRect(l_oRect);
}
void box_frame::update_links() {
void box_frame::update_links()
{
m_oCaption->setFont(scene()->font());
m_oCaption->setPlainText(m_oBox->m_sText);
m_oCaption->setPos((m_iWW - m_oCaption->boundingRect().width()) / 2., 0);
//m_oCaption->setPos((m_iWW - m_oCaption->boundingRect().width()) / 2., m_iHH - m_oCaption->boundingRect().height());
QRectF l_oR = boundingRect();
if (m_oBox->m_iLabelPosition == Qt::TopEdge) m_oCaption->setPos((l_oR.width() - m_oCaption->boundingRect().width()) / 2., 0);
else
{
m_oCaption->setPos((l_oR.width() - m_oCaption->boundingRect().width()) / 2., l_oR.height() - m_oCaption->boundingRect().height());
}
box_item::update_links();
}
void box_frame::update_data()
{
box_item::update_data();
update_links();
}
void box_frame::properties()
{
box_frame_properties props(m_oView, this);
props.exec();
}
......@@ -19,6 +19,8 @@ class box_frame : public box_item
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *);
box_frame(box_view*, int i_iId);
void update_links();
void update_data();
void properties();
QGraphicsTextItem *m_oCaption;
};
......
// Thomas Nagy 2007-2018 GPLV3
#include <QComboBox>
#include <QTreeWidget>
#include <QTextEdit>
#include <QGridLayout>
#include <QLabel>
#include <QHeaderView>
#include <QLineEdit>
#include <QDirModel>
#include <QCompleter>
#include "mem_box.h"
#include "box_view.h"
#include "sem_mediator.h"
#include <QtDebug>
#include "box_frame_properties.h"
box_frame_properties::box_frame_properties(QWidget *i_oParent, box_frame *i_oFrame):
KDialog(i_oParent)
{
QWidget *l_oWidget = new QWidget(this);
setCaption(i18n("Boundary properties"));
setButtons(KDialog::Ok | KDialog::Apply | KDialog::Cancel);
enableButtonApply(false);
m_oFrame = i_oFrame;
QGridLayout *l_oGridLayout = new QGridLayout(l_oWidget);
QLabel *l_sLabel;
l_sLabel = new QLabel(l_oWidget);
l_sLabel->setText(i18n("Text position"));
l_oGridLayout->addWidget(l_sLabel, 1, 0);
l_sLabel = new QLabel(l_oWidget);
l_sLabel->setText(i18n("Text"));
l_oGridLayout->addWidget(l_sLabel, 0, 0);
m_oEdit = new QLineEdit(l_oWidget);
m_oEdit->setText(i_oFrame->m_oBox->m_sText);
l_oGridLayout->addWidget(m_oEdit, 0, 1);
m_oLabelPosition = new QComboBox(l_oWidget);
m_oLabelPosition->addItem(i18n("Up"), Qt::TopEdge);
m_oLabelPosition->addItem(i18n("Down"), Qt::BottomEdge);
m_oLabelPosition->setCurrentIndex(i_oFrame->m_oBox->m_iLabelPosition == Qt::TopEdge ? 0 : 1);
l_oGridLayout->addWidget(m_oLabelPosition, 1, 1);
l_oWidget->setTabOrder(m_oEdit, m_oLabelPosition);
setMainWidget(l_oWidget);
QSize size(350, 120);
resize(size.expandedTo(minimumSizeHint()));
connect(this, SIGNAL(applyClicked()), this, SLOT(apply()));
connect(this, SIGNAL(okClicked()), this, SLOT(apply()));
connect(m_oLabelPosition, SIGNAL(currentIndexChanged(int)), this, SLOT(enable_apply(int)));
connect(m_oEdit, SIGNAL(textChanged(const QString&)), this, SLOT(enable_apply(const QString&)));
m_oEdit->setFocus();
}
void box_frame_properties::enable_apply(int) {
enableButtonApply(true);
}
void box_frame_properties::enable_apply(const QString &) {
enableButtonApply(true);
}
void box_frame_properties::apply() {
if (!isButtonEnabled(KDialog::Apply)) {
return;
}
mem_edit_box *mem = new mem_edit_box(m_oFrame->m_oView->m_oMediator, m_oFrame->m_oView->m_iId, m_oFrame->m_iId);
mem->newText = m_oEdit->text();
QTextDocument doc;
QTextOption l_oOption = doc.defaultTextOption();
l_oOption.setAlignment(m_oFrame->m_oBox->m_iAlign);
doc.setDefaultTextOption(l_oOption);
doc.setPlainText(m_oFrame->m_oBox->m_sText);
doc.setTextWidth(m_oFrame->m_oBox->m_iWW - 2 * OFF);
mem->newHeight = GRID * (((int) (doc.size().height() + 2 * OFF + GRID - 1)) / GRID);
if (mem->newHeight < m_oFrame->m_oBox->m_iHH)
mem->newHeight = m_oFrame->m_oBox->m_iHH;
mem->m_iOldLabelPosition = m_oFrame->m_oBox->m_iLabelPosition;
mem->m_iNewLabelPosition = (Qt::Edge) m_oLabelPosition->currentData().toInt();
mem->apply();
enableButtonApply(false);
}
// Thomas Nagy 2012 GPLV3
#ifndef BOX_FRAME_PROPERTIES_H
#define BOX_FRAME_PROPERTIES_H
#include <KDE/KDialog>
#include "box_frame.h"
class QComboBox;
class QTextEdit;
class box_frame_properties : public KDialog
{
Q_OBJECT
public:
box_frame_properties(QWidget*, box_frame*);
QComboBox *m_oLabelPosition;
QLineEdit *m_oEdit;
box_frame *m_oFrame;
public slots:
void apply();
void enable_apply(int);
void enable_apply(const QString &);
};
#endif
......@@ -88,6 +88,7 @@ void mem_edit_box::redo()
{
box->m_sText = newText;
box->m_iHH = newHeight;
box->m_iLabelPosition = m_iNewLabelPosition;
model->notify_edit_box(item.m_iId, box->m_iId);
redo_dirty();
}
......@@ -96,6 +97,7 @@ void mem_edit_box::undo()
{
box->m_sText = oldText;
box->m_iHH = oldHeight;
box->m_iLabelPosition = m_iOldLabelPosition;
model->notify_edit_box(item.m_iId, box->m_iId);
undo_dirty();
}
......
......@@ -56,6 +56,10 @@ class mem_edit_box: public mem_command {
QString oldText;
QString newText;
Qt::Edge m_iOldLabelPosition;
Qt::Edge m_iNewLabelPosition;
IType type() { return EDIT_BOX; }
};
......
......@@ -23,6 +23,7 @@ def build(bld):
moc = '''src/base/flag_scheme.h src/base/sem_mediator.h
src/fig/box_class_properties.h
src/fig/box_link_properties.h
src/fig/box_frame_properties.h
src/fig/export_fig_dialog.h
src/fig/box_view.h
src/fig/matrix_dialog.h
......
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