Commit e2408ace authored by Nikita Sirgienko's avatar Nikita Sirgienko
Browse files

Change default entries replacement logic and add option to use previous logic in Cantor settings

parent 90571de4
# Changelog
## 20.08
### New features
* Change entries replacement logic and add possibility to use previous logic via Cantor setting option.
## 20.04
### New features
......
......@@ -48,6 +48,10 @@
<label>Save rich text formatting of TextEntry, when save Worksheet in Jupyter notebook format</label>
<default>true</default>
</entry>
<entry name="UseOldCantorEntriesIndent" type="Bool">
<label>Use old style Cantor entries placement style</label>
<default>false</default>
</entry>
<entry name="ShowMathRenderError" type="Bool">
<label>Show embedded math render error</label>
<default>true</default>
......
......@@ -1238,13 +1238,13 @@ WorksheetCursor CommandEntry::search(const QString& pattern, unsigned flags,
return WorksheetCursor();
}
void CommandEntry::layOutForWidth(qreal w, bool force)
void CommandEntry::layOutForWidth(qreal entry_zone_x, qreal w, bool force)
{
if (w == size().width() && !force)
if (w == size().width() && m_commandItem->pos().x() == entry_zone_x && !force)
return;
m_promptItem->setPos(0, 0);
double x = 0 + m_promptItem->width() + HorizontalSpacing;
double x = std::max(0 + m_promptItem->width() + HorizontalSpacing, entry_zone_x);
double y = 0;
double width = 0;
......@@ -1357,3 +1357,8 @@ void CommandEntry::changeResultCollapsingAction()
else
collapseResults();
}
qreal CommandEntry::promptItemWidth()
{
return m_promptItem->width();
}
......@@ -82,7 +82,8 @@ class CommandEntry : public WorksheetEntry
bool focusEntry(int pos = WorksheetTextItem::TopLeft, qreal xCoord = 0) override;
void layOutForWidth(qreal w, bool force = false) override;
void layOutForWidth(qreal entry_zone_x, qreal w, bool force = false) override;
qreal promptItemWidth();
WorksheetTextItem* highlightItem() override;
......
......@@ -353,9 +353,9 @@ void ImageEntry::addActionsToBar(ActionBar* actionBar)
}
void ImageEntry::layOutForWidth(qreal w, bool force)
void ImageEntry::layOutForWidth(qreal entry_zone_x, qreal w, bool force)
{
if (size().width() == w && !force)
if (size().width() == w && m_textItem->pos().x() == entry_zone_x && !force)
return;
//TODO somethinkg wrong with geometry and control element: control element appears in wrong place
......@@ -363,14 +363,14 @@ void ImageEntry::layOutForWidth(qreal w, bool force)
double width;
if (m_imageItem && m_imageItem->isVisible()) {
m_imageItem->setGeometry(0, 0, w - margin, true);
m_imageItem->setGeometry(entry_zone_x, 0, w - margin - entry_zone_x, true);
width = m_imageItem->width();
} else {
m_textItem->setGeometry(0, 0, w - margin, true);
m_textItem->setGeometry(entry_zone_x, 0, w - margin - entry_zone_x, true);
width = m_textItem->width();
}
setSize(QSizeF(width + margin, height() + VerticalMargin));
setSize(QSizeF(width + margin + entry_zone_x, height() + VerticalMargin));
}
bool ImageEntry::wantToEvaluate()
......
......@@ -55,7 +55,7 @@ class ImageEntry : public WorksheetEntry
void interruptEvaluation() override;
void layOutForWidth(qreal w, bool force = false) override;
void layOutForWidth(qreal entry_zone_x, qreal w, bool force = false) override;
public Q_SLOTS:
bool evaluate(WorksheetEntry::EvaluationOption evalOp = FocusNext) override;
......
......@@ -514,15 +514,15 @@ WorksheetCursor LatexEntry::search(const QString& pattern, unsigned flags,
}
}
void LatexEntry::layOutForWidth(qreal w, bool force)
void LatexEntry::layOutForWidth(qreal entry_zone_x, qreal w, bool force)
{
if (size().width() == w && !force)
if (size().width() == w && m_textItem->pos().x() == entry_zone_x && !force)
return;
const qreal margin = worksheet()->isPrinting() ? 0 : RightMargin;
m_textItem->setGeometry(0, 0, w - margin);
setSize(QSizeF(m_textItem->width() + margin, m_textItem->height() + VerticalMargin));
m_textItem->setGeometry(entry_zone_x, 0, w - margin - entry_zone_x);
setSize(QSizeF(m_textItem->width() + margin + entry_zone_x, m_textItem->height() + VerticalMargin));
}
bool LatexEntry::wantToEvaluate()
......
......@@ -55,7 +55,7 @@ class LatexEntry : public WorksheetEntry
void interruptEvaluation() override;
void layOutForWidth(qreal w, bool force = false) override;
void layOutForWidth(qreal w, qreal entry_zone_x, bool force = false) override;
int searchText(const QString& text, const QString& pattern,
QTextDocument::FindFlags qt_flags);
......
......@@ -440,15 +440,15 @@ WorksheetCursor MarkdownEntry::search(const QString& pattern, unsigned flags,
return WorksheetCursor(this, m_textItem, textCursor);
}
void MarkdownEntry::layOutForWidth(qreal w, bool force)
void MarkdownEntry::layOutForWidth(qreal entry_zone_x, qreal w, bool force)
{
if (size().width() == w && !force)
if (size().width() == w && m_textItem->pos().x() == entry_zone_x && !force)
return;
const qreal margin = worksheet()->isPrinting() ? 0 : RightMargin;
m_textItem->setGeometry(0, 0, w - margin);
setSize(QSizeF(m_textItem->width() + margin, m_textItem->height() + VerticalMargin));
m_textItem->setGeometry(entry_zone_x, 0, w - margin - entry_zone_x);
setSize(QSizeF(m_textItem->width() + margin + entry_zone_x, m_textItem->height() + VerticalMargin));
}
bool MarkdownEntry::eventFilter(QObject* object, QEvent* event)
......
......@@ -61,7 +61,7 @@ class MarkdownEntry : public WorksheetEntry
void interruptEvaluation() override;
void layOutForWidth(qreal w, bool force = false) override;
void layOutForWidth(qreal entry_zone_x, qreal w, bool force = false) override;
WorksheetCursor search(const QString& pattern, unsigned flags,
QTextDocument::FindFlags qt_flags,
......
......@@ -128,17 +128,17 @@ void PageBreakEntry::interruptEvaluation()
return;
}
void PageBreakEntry::layOutForWidth(qreal w, bool force)
void PageBreakEntry::layOutForWidth(qreal entry_zone_x, qreal w, bool force)
{
if (size().width() == w && !force)
if (size().width() == w && m_msgItem->pos().x() == entry_zone_x && !force)
return;
const qreal margin = worksheet()->isPrinting() ? 0 : RightMargin;
if (m_msgItem->isVisible()) {
m_msgItem->setGeometry(0, 0, w - margin, true);
m_msgItem->setGeometry(entry_zone_x, 0, w - margin - entry_zone_x, true);
setSize(QSizeF(m_msgItem->width() + margin, m_msgItem->height() + VerticalMargin));
setSize(QSizeF(m_msgItem->width() + margin + entry_zone_x, m_msgItem->height() + VerticalMargin));
} else {
setSize(QSizeF(w, 0));
}
......
......@@ -48,7 +48,7 @@ class PageBreakEntry : public WorksheetEntry
void interruptEvaluation() override;
void layOutForWidth(qreal w, bool force = false) override;
void layOutForWidth(qreal entry_zone_x, qreal w, bool force = false) override;
//void paint(QPainter* painter, const QStyleOptionGraphicsItem * option,
// QWidget * widget = 0);
......
......@@ -85,8 +85,9 @@ void PlaceHolderEntry::interruptEvaluation()
return;
}
void PlaceHolderEntry::layOutForWidth(qreal w, bool force)
void PlaceHolderEntry::layOutForWidth(qreal entry_zone_x, qreal w, bool force)
{
Q_UNUSED(entry_zone_x);
Q_UNUSED(w);
Q_UNUSED(force);
}
......
......@@ -42,7 +42,7 @@ class PlaceHolderEntry : public WorksheetEntry
QString toPlain(const QString&, const QString&, const QString&) override;
void interruptEvaluation() override;
void layOutForWidth(qreal w, bool force = false) override;
void layOutForWidth(qreal entry_zone_x, qreal w, bool force = false) override;
public Q_SLOTS:
bool evaluate(WorksheetEntry::EvaluationOption evalOp = FocusNext) override;
......
......@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>845</width>
<height>631</height>
<height>724</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
......@@ -103,6 +103,13 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="kcfg_UseOldCantorEntriesIndent">
<property name="text">
<string>Use old Cantor entries indent style</string>
</property>
</widget>
</item>
<item>
<widget class="QSplitter" name="splitter">
<property name="orientation">
......@@ -164,7 +171,7 @@
</widget>
</item>
<item>
<widget class="KUrlRequester" name="kcfg_PathToCantorPluginsDir"/>
<widget class="KUrlRequester" name="kcfg_PathToCantorPluginsDir" native="true"/>
</item>
</layout>
</item>
......@@ -194,6 +201,11 @@
<extends>QComboBox</extends>
<header>kcombobox.h</header>
</customwidget>
<customwidget>
<class>KUrlRequester</class>
<extends>QWidget</extends>
<header>kurlrequester.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
......
......@@ -28,7 +28,6 @@
#include "settings.h"
#include <QScopedPointer>
#include <QGraphicsLinearLayout>
#include <QJsonValue>
......@@ -486,15 +485,15 @@ WorksheetCursor TextEntry::search(const QString& pattern, unsigned flags,
}
void TextEntry::layOutForWidth(qreal w, bool force)
void TextEntry::layOutForWidth(qreal entry_zone_x, qreal w, bool force)
{
if (size().width() == w && !force)
if (size().width() == w && m_textItem->pos().x() == entry_zone_x && !force)
return;
const qreal margin = worksheet()->isPrinting() ? 0 : RightMargin;
m_textItem->setGeometry(0, 0, w - margin);
setSize(QSizeF(0 + m_textItem->width() + margin, m_textItem->height() + VerticalMargin));
m_textItem->setGeometry(entry_zone_x, 0, w - margin - entry_zone_x);
setSize(QSizeF(m_textItem->width() + margin + entry_zone_x, m_textItem->height() + VerticalMargin));
}
bool TextEntry::wantToEvaluate()
......
......@@ -67,7 +67,7 @@ class TextEntry : public WorksheetEntry
void interruptEvaluation() override;
void layOutForWidth(qreal w, bool force = false) override;
void layOutForWidth(qreal entry_zone_x, qreal w, bool force = false) override;
int searchText(const QString& text, const QString& pattern,
QTextDocument::FindFlags qt_flags);
......
......@@ -214,11 +214,19 @@ void Worksheet::updateLayout()
cursorRectVisible = worksheetView()->isVisible(cursorRect);
}
qreal maxPromptWidth = 0;
if (Settings::useOldCantorEntriesIndent() == false)
{
for (WorksheetEntry *entry = firstEntry(); entry; entry = entry->next())
if (entry->type() == CommandEntry::Type)
maxPromptWidth = std::max(static_cast<CommandEntry*>(entry)->promptItemWidth(), maxPromptWidth);
}
const qreal w = m_viewWidth - LeftMargin - RightMargin;
qreal y = TopMargin;
const qreal x = LeftMargin;
for (WorksheetEntry *entry = firstEntry(); entry; entry = entry->next())
y += entry->setGeometry(x, y, w);
y += entry->setGeometry(x, x+maxPromptWidth, y, w);
setSceneRect(QRectF(0, 0, sceneRect().width(), y));
if (cursorRectVisible)
......@@ -912,6 +920,8 @@ void Worksheet::enableExpressionNumbering(bool enable)
{
m_showExpressionIds=enable;
emit updatePrompt();
if (views().size() != 0)
updateLayout();
}
QDomDocument Worksheet::toXML(KZip* archive)
......
......@@ -409,10 +409,10 @@ void WorksheetEntry::evaluateNext(EvaluationOption opt)
}
}
qreal WorksheetEntry::setGeometry(qreal x, qreal y, qreal w)
qreal WorksheetEntry::setGeometry(qreal x, qreal x1, qreal y, qreal w)
{
setPos(x, y);
layOutForWidth(w);
layOutForWidth(x1, w);
recalculateControlGeometry();
......
......@@ -89,8 +89,8 @@ class WorksheetEntry : public QGraphicsObject
virtual bool focusEntry(int pos = WorksheetTextItem::TopLeft, qreal xCoord = 0);
virtual qreal setGeometry(qreal x, qreal y, qreal w);
virtual void layOutForWidth(qreal w, bool force = false) = 0;
virtual qreal setGeometry(qreal x, qreal entry_zone_x, qreal y, qreal w);
virtual void layOutForWidth(qreal entry_zone_x, qreal w, bool force = false) = 0;
QPropertyAnimation* sizeChangeAnimation(QSizeF s = QSizeF());
virtual void populateMenu(QMenu* menu, QPointF pos);
......
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