Verified Commit 4b6c77b1 authored by ita1024's avatar ita1024

Enable newlines on most diagram objects

parent a9af0cf0
......@@ -3,6 +3,7 @@ Semantik 1.2.1
* Fix duplicate reference values
* Fix double prompts for overwriting files
* Fix invisible map variables immediately after opening a map
* Fix the tab navigation on the document generator dialog
* Add global settings for commands to execute after a template is called
Semantik 1.2.0
......
......@@ -3,4 +3,3 @@ Z-index in diagrams
Half-broken diagram links routing with sequences
Serialize undo operations
Arbitrary SVG shapes
Enable html in floating text boxes
......@@ -50,7 +50,7 @@
int grid_int(int x);
int fceil(qreal l_fInput, int l_iBase);
#define mu(x) #x
......
......@@ -185,6 +185,7 @@ config_editor::config_editor(QWidget *i_oParent) : QTextEdit(i_oParent)
{
new config_highlighter(document());
setStyleSheet("QTextEdit { font-family: monospace;}");
setTabChangesFocus(true);
}
config_highlighter::config_highlighter(QTextDocument *p): QSyntaxHighlighter(p)
......
......@@ -13,6 +13,7 @@ class QComboBox;
class QSpinBox;
class QTreeWidgetItem;
class QPushButton;
class QKeyEvent;
class config_highlighter_rule
{
......@@ -31,7 +32,6 @@ class config_highlighter: public QSyntaxHighlighter
class config_editor : public QTextEdit
{
Q_OBJECT
public:
config_editor(QWidget *i_oParent);
};
......
......@@ -479,7 +479,7 @@ void box_class::properties()
}
props.m_oClassDefinition->setText(l_oS.join(notr("")));
props.m_oClassDefinition->selectAll();
props.exec();
}
......@@ -25,76 +25,7 @@
#include <QtDebug>
#include "box_class_properties.h"
class_editor::class_editor(QWidget *i_oParent) : QTextEdit(i_oParent)
{
new class_highlighter(document());
setStyleSheet("QTextEdit { font-family: monospace;}");
m_oCompleter = NULL;
startup = true;
}
void class_editor::init_completer()
{
m_oCompleterAll = new QCompleter(this);
m_oCompleterItem = new QCompleter(this);
QTreeView *l_oTreeView = NULL;
QStandardItemModel *l_oModelItem = new QStandardItemModel(this);
fillloc(l_oModelItem);
l_oTreeView = new QTreeView;
m_oCompleterItem->setPopup(l_oTreeView);
m_oCompleterItem->setModel(l_oModelItem);
m_oCompleterItem->setWidget(this);
m_oCompleterItem->setCompletionMode(QCompleter::PopupCompletion);
m_oCompleterItem->setModelSorting(QCompleter::CaseInsensitivelySortedModel);
m_oCompleterItem->setCaseSensitivity(Qt::CaseInsensitive);
l_oTreeView->header()->hide();
l_oTreeView->header()->setStretchLastSection(false);
l_oTreeView->header()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
l_oTreeView->header()->setSectionResizeMode(1, QHeaderView::Stretch);
l_oTreeView->setRootIsDecorated(false);
QObject::connect(m_oCompleterItem, SIGNAL(activated(const QString&)), this, SLOT(do_complete(const QString&)));
QStandardItemModel *l_oModelAll = new QStandardItemModel(this);
fillglo(l_oModelAll)
l_oTreeView = new QTreeView;
m_oCompleterAll->setPopup(l_oTreeView);
m_oCompleterAll->setModel(l_oModelAll);
m_oCompleterAll->setWidget(this);
m_oCompleterAll->setCompletionMode(QCompleter::PopupCompletion);
m_oCompleterAll->setModelSorting(QCompleter::CaseInsensitivelySortedModel);
m_oCompleterAll->setCaseSensitivity(Qt::CaseInsensitive);
l_oTreeView->header()->setStretchLastSection(false);
l_oTreeView->header()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
l_oTreeView->header()->setSectionResizeMode(1, QHeaderView::Stretch);
l_oTreeView->setRootIsDecorated(false);
l_oTreeView->header()->hide();
QObject::connect(m_oCompleterAll, SIGNAL(activated(const QString&)), this, SLOT(do_complete(const QString&)));
// initialize
m_oCompleter = m_oCompleterAll;
m_oCompleteAction = new QAction(i18n("Code complete"), this);
m_oCompleteAction->setShortcut(i18n("Ctrl+space"));
connect(m_oCompleteAction, SIGNAL(triggered()), this, SLOT(try_complete()));
addAction(m_oCompleteAction);
#if 0
QPalette l_oPalette = palette();
l_oPalette.setBrush(QPalette::Inactive, QPalette::Base, QColor(230, 230, 230));
l_oPalette.setBrush(QPalette::Disabled, QPalette::Base, QColor(230, 230, 230));
setPalette(l_oPalette);
#endif
}
#include "special_edit.h"
class_highlighter::class_highlighter(QTextDocument *p): QSyntaxHighlighter(p)
{
......@@ -132,110 +63,6 @@ void class_highlighter::highlightBlock(const QString &i_sText)
}
}
void class_editor::do_complete(const QString& i_s)
{
QTextCursor l_oCursor = textCursor();
int i_i = i_s.length() - m_oCompleter->completionPrefix().length();
if (m_oCompleter->completionPrefix().length()>0)
{
l_oCursor.movePosition(QTextCursor::Left);
l_oCursor.movePosition(QTextCursor::EndOfWord);
}
else
{
l_oCursor.movePosition(QTextCursor::StartOfWord);
}
l_oCursor.insertText(i_s.right(i_i));
setTextCursor(l_oCursor);
}
void class_editor::keyPressEvent(QKeyEvent *i_oEv)
{
// FIXME
QTextEdit::keyPressEvent(i_oEv);
return;
if (m_oCompleter->popup()->isVisible())
{
switch (i_oEv->key())
{
case Qt::Key_Enter:
case Qt::Key_Return:
case Qt::Key_Escape:
case Qt::Key_Tab:
case Qt::Key_Backtab:
i_oEv->ignore();
return; // let the completer do default behavior
default:
break;
}
}
QTextEdit::keyPressEvent(i_oEv);
bool l_oCtrlOrShift = i_oEv->modifiers() & (Qt::ControlModifier | Qt::ShiftModifier);
if (l_oCtrlOrShift && i_oEv->text().isEmpty())
{
return;
}
static QString eow("~!@#$%^&*()_+{}|:\"<>?,./;'[]\\-="); // end of word
//bool hasModifier = (e->modifiers() != Qt::NoModifier) && !l_oCtrlOrShift;
QTextCursor l_oCursor = textCursor();
l_oCursor.select(QTextCursor::WordUnderCursor);
QString l_sPrefix = l_oCursor.selectedText();
if (
l_sPrefix.length() < 1 or
i_oEv->text().isEmpty() or
eow.contains(i_oEv->text().right(1)) or
(i_oEv->modifiers() != Qt::NoModifier && !l_oCtrlOrShift)
)
{
m_oCompleter->popup()->hide();
return;
}
try_complete();
}
void class_editor::try_complete()
{
QTextCursor l_oCursor = textCursor();
l_oCursor.select(QTextCursor::WordUnderCursor);
QString l_sPrefix = l_oCursor.selectedText();
int l_iSave = l_oCursor.position();
l_oCursor.movePosition(QTextCursor::StartOfWord);
int l_iWord = l_oCursor.position();
l_oCursor.movePosition(QTextCursor::StartOfLine);
bool l_b = l_oCursor.position() == l_iWord;
l_oCursor.setPosition(l_iSave);
if (!l_b) return;
if (l_sPrefix != m_oCompleter->completionPrefix())
{
m_oCompleter->setCompletionPrefix(l_sPrefix);
m_oCompleter->popup()->setCurrentIndex(m_oCompleter->completionModel()->index(0, 0));
}
QRect l_oRect = cursorRect();
l_oRect.setWidth(width());
//m_oCompleter->popup()->sizeHintForColumn(0) +
// m_oCompleter->popup()->sizeHintForColumn(1) +
// m_oCompleter->popup()->verticalScrollBar()->sizeHint().width() +
// 20
QTreeView *l_oTreeView = (QTreeView*) m_oCompleter->popup();
l_oTreeView->resizeColumnToContents(0);
l_oTreeView->resizeColumnToContents(1);
m_oCompleter->complete(l_oRect);
}
box_class_properties::box_class_properties(QWidget *i_oParent, box_class *i_oClass):
KDialog(i_oParent), m_oClass(i_oClass)
{
......@@ -247,7 +74,9 @@ box_class_properties::box_class_properties(QWidget *i_oParent, box_class *i_oCla
QGridLayout *l_oGridLayout = new QGridLayout(widget);
m_oClassDefinition = new class_editor(widget);
m_oClassDefinition = new special_edit(widget);
new class_highlighter(m_oClassDefinition->document());
l_oGridLayout->addWidget(m_oClassDefinition, 0, 0);
setMainWidget(widget);
QSize size(700, 320);
......
......@@ -8,7 +8,6 @@
#include <KDE/KDialog>
#include "box_class.h"
class QCompleter;
class class_highlighter_rule
{
public:
......@@ -24,32 +23,13 @@ class class_highlighter: public QSyntaxHighlighter
QVector<class_highlighter_rule> m_oRules;
};
class class_editor : public QTextEdit
{
Q_OBJECT
public:
class_editor(QWidget *i_oParent);
QCompleter *m_oCompleter;
QCompleter *m_oCompleterItem;
QCompleter *m_oCompleterAll;
QAction *m_oCompleteAction;
void keyPressEvent(QKeyEvent*);
void init_completer();
bool startup;
public slots:
void do_complete(const QString &);
void try_complete();
};
class box_class_properties : public KDialog
{
Q_OBJECT
public:
box_class_properties(QWidget*, box_class*);
box_class *m_oClass;
class_editor *m_oClassDefinition;
QTextEdit *m_oClassDefinition;
public slots:
void apply();
......
......@@ -29,16 +29,6 @@
//#define DEBUG
int fceil(qreal l_fInput, int l_iBase)
{
int l_iCal = ceil(l_fInput);
if (l_iCal % l_iBase == 0)
{
return l_iCal;
}
return l_iBase * (1 + l_iCal / l_iBase);
}
box_entity::box_entity(box_view* view, int id) : box_item(view, id)
{
......@@ -301,7 +291,7 @@ void box_entity::properties()
l_oS<<notr("\n");
props.m_oEntityDefinition->setText(l_oS.join(notr("")));
props.m_oEntityDefinition->selectAll();
props.exec();
}
......@@ -20,18 +20,11 @@
#include <QFont>
#include "mem_box.h"
#include "box_view.h"
#include "special_edit.h"
#include <QtDebug>
#include "box_entity_properties.h"
entity_editor::entity_editor(QWidget *i_oParent) : QTextEdit(i_oParent)
{
new entity_highlighter(document());
setStyleSheet("QTextEdit { font-family: monospace;}");
}
entity_highlighter::entity_highlighter(QTextDocument *p): QSyntaxHighlighter(p)
{
entity_highlighter_rule l_oRule;
......@@ -75,11 +68,12 @@ box_entity_properties::box_entity_properties(QWidget *i_oParent, box_entity *i_o
setCaption(i18n("Entity properties"));
setButtons(KDialog::Ok | KDialog::Apply | KDialog::Cancel);
enableButtonApply(false);
m_oEntity = i_oEntity;
QGridLayout *l_oGridLayout = new QGridLayout(widget);
m_oEntityDefinition = new entity_editor(widget);
m_oEntityDefinition = new special_edit(widget);
new entity_highlighter(m_oEntityDefinition->document());
l_oGridLayout->addWidget(m_oEntityDefinition, 0, 0);
setMainWidget(widget);
QSize size(700, 320);
......
......@@ -24,21 +24,13 @@ class entity_highlighter: public QSyntaxHighlighter
QVector<entity_highlighter_rule> m_oRules;
};
class entity_editor : public QTextEdit
{
Q_OBJECT
public:
entity_editor(QWidget *i_oParent);
};
class box_entity_properties : public KDialog
{
Q_OBJECT
public:
box_entity_properties(QWidget*, box_entity*);
box_entity *m_oEntity;
entity_editor *m_oEntityDefinition;
QTextEdit *m_oEntityDefinition;
public slots:
void apply();
......
......@@ -84,10 +84,10 @@ void box_frame_properties::apply() {
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.setPlainText(mem->newText);
doc.setTextWidth(m_oFrame->m_oBox->m_iWW - 2 * OFF);
mem->newHeight = GRID * (((int) (doc.size().height() + 2 * OFF + GRID - 1)) / GRID);
mem->newHeight = fceil(doc.size().height() + 2 * OFF, GRID);
if (mem->newHeight < m_oFrame->m_oBox->m_iHH)
mem->newHeight = m_oFrame->m_oBox->m_iHH;
......
......@@ -20,6 +20,7 @@
#include "data_item.h"
#include "sem_mediator.h"
#include "mem_box.h"
#include "special_edit.h"
box_item::box_item(box_view* i_oParent, int i_iId) : QGraphicsRectItem(), connectable(), editable(), resizable(), m_oView(i_oParent),
m_oItem(m_oView->m_oMediator->m_oItems[m_oView->m_iId])
......@@ -129,28 +130,8 @@ void box_item::update_size() {
void box_item::properties()
{
bool ok = false;
QString text = QInputDialog::getText(m_oView, i18n("Diagram box properties"),
i18n("Text:"), QLineEdit::Normal, m_oBox->m_sText, &ok);
if (ok && text != m_oBox->m_sText)
{
mem_edit_box *ed = new mem_edit_box(m_oView->m_oMediator, m_oView->m_iId, m_iId);
ed->newText = text;
QTextDocument doc;
QTextOption l_oOption = doc.defaultTextOption();
l_oOption.setAlignment(m_oBox->m_iAlign);
doc.setDefaultTextOption(l_oOption);
doc.setPlainText(m_oBox->m_sText);
doc.setTextWidth(m_oBox->m_iWW - 2 * OFF);
ed->newHeight = GRID * (((int) (doc.size().height() + 2 * OFF + GRID - 1)) / GRID);
if (ed->newHeight < m_oBox->m_iHH)
ed->newHeight = m_oBox->m_iHH;
ed->apply();
}
special_edit_properties l_oDlg(m_oView, this);
l_oDlg.exec();
}
QVariant box_item::itemChange(GraphicsItemChange i_oChange, const QVariant &i_oValue)
......
......@@ -175,6 +175,20 @@ bool box_reader::characters(const QString &i_s)
return true;
}
int fceil(qreal l_fInput, int l_iBase)
{
int l_iCal = ceil(l_fInput);
if (l_iCal % l_iBase == 0)
{
return l_iCal;
}
return l_iBase * (1 + l_iCal / l_iBase);
}
int grid_int(int x) {
return GRID * (x / GRID);
}
box_view::box_view(QWidget *i_oWidget, sem_mediator *i_oControl) : QGraphicsView(i_oWidget)
{
m_oMediator = i_oControl;
......
......@@ -19,10 +19,6 @@
static const char description[] = "A tool for editing and organizing Semantik diagrams";
static const char version[] = VERSION;
int grid_int(int x) {
return GRID * (x / GRID);
}
int main(int i_iArgc, char **i_iArgv)
{
KCmdLineOptions options;
......
// Thomas Nagy 2018 GPLV3
#include <QLabel>
#include <QGridLayout>
#include "box_item.h"
#include "mem_box.h"
#include <special_edit.h>
#include <QDebug>
void special_edit::keyPressEvent(QKeyEvent *i_oEv)
{
if (i_oEv->key() == Qt::Key_Enter || i_oEv->key() == Qt::Key_Return)
{
if (i_oEv->modifiers() & Qt::AltModifier)
{
i_oEv->setModifiers(Qt::NoModifier);
QTextEdit::keyPressEvent(i_oEv);
}
else
{
i_oEv->ignore();
}
}
else
{
QTextEdit::keyPressEvent(i_oEv);
}
}
special_edit::special_edit(QWidget *i_oParent) : QTextEdit(i_oParent)
{
setStyleSheet("QTextEdit { font-family: monospace;}");
setTabChangesFocus(true);
}
special_edit_properties::special_edit_properties(QWidget *i_oParent, box_item *i_oItem):
KDialog(i_oParent), m_oItem(i_oItem)
{
QWidget *widget = new QWidget(this);
setCaption(i18n("Diagram box properties:"));
setButtons(KDialog::Ok | KDialog::Apply | KDialog::Cancel);
enableButtonApply(false);
QGridLayout *l_oGridLayout = new QGridLayout(widget);
QLabel *l_sLabel = new QLabel(widget);
l_sLabel->setText(i18n("Text:"));
l_oGridLayout->addWidget(l_sLabel, 0, 0);
m_oTextEdit = new special_edit(widget);
l_oGridLayout->addWidget(m_oTextEdit, 1, 0);
setMainWidget(widget);
QSize size(400, 220);
resize(size.expandedTo(minimumSizeHint()));
connect(m_oTextEdit, SIGNAL(textChanged()), this, SLOT(enable_apply()));
connect(this, SIGNAL(applyClicked()), this, SLOT(apply()));
connect(this, SIGNAL(okClicked()), this, SLOT(apply()));
m_oTextEdit->setFocus();
m_oTextEdit->setPlainText(i_oItem->m_oBox->m_sText);
m_oTextEdit->selectAll();
}
void special_edit_properties::enable_apply(int) {
enableButtonApply(m_oTextEdit->toPlainText() != m_oItem->m_oBox->m_sText);
}
void special_edit_properties::enable_apply() {
enableButtonApply(m_oTextEdit->toPlainText() != m_oItem->m_oBox->m_sText);
}
void special_edit_properties::apply()
{
if (!isButtonEnabled(KDialog::Apply)) {
return;
}
if (m_oTextEdit->toPlainText() != m_oItem->m_oBox->m_sText)
{
mem_edit_box *ed = new mem_edit_box(m_oItem->m_oView->m_oMediator, m_oItem->m_oView->m_iId, m_oItem->m_oBox->m_iId);
ed->newText = m_oTextEdit->toPlainText();
QTextDocument doc;
QTextOption l_oOption = doc.defaultTextOption();
l_oOption.setAlignment(m_oItem->m_oBox->m_iAlign);
doc.setDefaultTextOption(l_oOption);
doc.setPlainText(ed->newText);
doc.setTextWidth(m_oItem->m_oBox->m_iWW - 2 * OFF);
ed->newHeight = fceil(doc.size().height() + 2 * OFF, GRID);
if (ed->newHeight < m_oItem->m_oBox->m_iHH)
ed->newHeight = m_oItem->m_oBox->m_iHH;
ed->apply();
}
enableButtonApply(false);
}
// Thomas Nagy 2018 GPLV3
#ifndef SPECIAL_EDIT_H
#define SPECIAL_EDIT_H
#include <QTextEdit>
#include <QKeyEvent>
#include "con.h"
#include <KDE/KDialog>
class box_item;
#define OFF 3
class special_edit : public QTextEdit
{
public:
special_edit(QWidget *i_oParent);
void keyPressEvent(QKeyEvent *i_oEv);
};
class special_edit_properties : public KDialog
{
Q_OBJECT
public:
special_edit_properties(QWidget*, box_item*);
special_edit *m_oTextEdit;
box_item *m_oItem;
public slots:
void apply();
void enable_apply(int);
void enable_apply();
};
#endif // SPECIAL_EDIT_H
......@@ -44,7 +44,6 @@ generator_dialog::generator_dialog(QWidget *i_oParent, QList<template_entry> i_o
m_oTree = new QTreeWidget(widget);
m_oTree->header()->hide();
l_oGridLayout->addWidget(m_oTree, 1, 0, 1, 2);
m_oTree->setFocusPolicy(Qt::NoFocus);
m_oTextEdit = new QTextEdit(widget);
m_oTextEdit->setReadOnly(true);
......@@ -81,27 +80,29 @@ generator_dialog::generator_dialog(QWidget *i_oParent, QList<template_entry> i_o
l_oItem->setData(0, Qt::UserRole+4, l_o.m_sTip);
}
connect(m_oTree, SIGNAL(itemClicked(QTreeWidgetItem *, int)), this, SLOT(selection_changed(QTreeWidgetItem *, int)));
connect(m_oTree, SIGNAL(itemSelectionChanged()), this, SLOT(selection_changed()));
setMainWidget(widget);
m_oTree->setFocus();
QSize size(421, 250);
size = size.expandedTo(minimumSizeHint());
resize(size);
}
void generator_dialog::selection_changed(QTreeWidgetItem * i_oItem, int i_oCol)
void generator_dialog::selection_changed()
{
if (!i_oItem)
QList<QTreeWidgetItem*> l_oSel = m_oTree->selectedItems();
if (l_oSel.isEmpty())
{
m_oTextEdit->clear();
}
else
{
m_oTextEdit->setText(i_oItem->data(0, Qt::UserRole+4).toString());
m_sCurrent = i_oItem->data(0, Qt::UserRole+3).toString();
m_sShortName = i_oItem->text(0);
QTreeWidgetItem *l_oItem = l_oSel.at(0);
m_oTextEdit->setText(l_oItem->data(0, Qt::UserRole+4).toString());
m_sCurrent = l_oItem->data(0, Qt::UserRole+3).toString();
m_sShortName = l_oItem->text(0);
}
}
......@@ -135,7 +136,6 @@ void generator_dialog::activate_from_name(const QString &i_s)
{
m_sShortName = i_s;
m_oTree->setCurrentItem(l_o[0]);
selection_changed(l_o[0], 0);
}
}
......@@ -26,7 +26,7 @@ class generator_dialog : public KDialog
QString m_sShortName;
public slots:
void selection_changed(QTreeWidgetItem *i_o, int i_oCol);
void selection_changed();
void slotButtonClicked(int button);
void activate_from_name(const QString &i_s);
};
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -52,6 +52,6 @@ echo "Cleaning up"
cd ${WDIR}
rm rcfiles.list
rm infiles.list
rm -f rc.cpp src/data/tips.cpp
rm -f rc.cpp ../data/tips.cpp
echo "Done"
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -27,6 +27,7 @@ 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/special_edit.h
src/fig/matrix_dialog.h
src/fig/box_document_properties.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