Commit 2cb598d2 authored by Nikita Sirgienko's avatar Nikita Sirgienko
Browse files

[T9024] New features:

  - WorksheetControlItem: special element, for better UX, while user interact with cell. Now, this element handle drag-and-drop and cell selection (details below)
  - Multiple cells selection: now user can select not one, but many sells via Ctrl+LeftClick. Selection also visualizate on control elements
  - Actions on selection (first version): now user can apply some actions on selected cells, for example evaulating, deleting, moving.

Differential Revision: https://phabricator.kde.org/D27094
parent f4050ec6
......@@ -79,6 +79,7 @@ set(cantor_PART_SRCS
mathrender.cpp
mathrendertask.cpp
extended_document.cpp
worksheetcontrolitem.cpp
)
ki18n_wrap_ui(cantor_PART_SRCS imagesettings.ui)
......
......@@ -31,7 +31,7 @@ ActionBar::ActionBar(WorksheetEntry* parent)
m_pos = 0;
m_height = 0;
QPointF p = worksheet()->worksheetView()->viewRect().topRight();
qreal w = qMin(parent->size().width(),
qreal w = qMin(parent->size().width() - WorksheetEntry::RightMargin,
parent->mapFromScene(p).x());
setPos(w, 0);
connect(worksheet()->worksheetView(), SIGNAL(viewRectChanged(QRectF)),
......@@ -64,7 +64,7 @@ void ActionBar::updatePosition()
if (!parentEntry())
return;
QPointF p = worksheet()->worksheetView()->viewRect().topRight();
qreal w = qMin(parentEntry()->size().width(),
qreal w = qMin(parentEntry()->size().width() - WorksheetEntry::RightMargin,
parentEntry()->mapFromScene(p).x());
setPos(w, 0);
const qreal scale = worksheet()->renderer()->scale();
......
......@@ -98,6 +98,8 @@ CommandEntry::CommandEntry(Worksheet* worksheet) : WorksheetEntry(worksheet),
m_promptItem->setDoubleClickBehaviour(WorksheetTextItem::DoubleClickEventBehaviour::Simple);
connect(m_promptItem, &WorksheetTextItem::doubleClick, this, &CommandEntry::changeResultCollapsingAction);
connect(&m_controlElement, &WorksheetControlItem::doubleClick, this, &CommandEntry::changeResultCollapsingAction);
connect(m_commandItem, &WorksheetTextItem::tabPressed, this, &CommandEntry::showCompletion);
connect(m_commandItem, &WorksheetTextItem::backtabPressed, this, &CommandEntry::selectPreviousCompletion);
connect(m_commandItem, &WorksheetTextItem::applyCompletion, this, &CommandEntry::applySelectedCompletion);
......@@ -751,6 +753,9 @@ void CommandEntry::updateEntry()
for (ResultItem* item: m_resultItems)
item->update();
}
m_controlElement.isCollapsable = m_resultItems.size() > 0;
animateSizeChange();
}
......@@ -1234,25 +1239,27 @@ void CommandEntry::layOutForWidth(qreal w, bool force)
if (w == size().width() && !force)
return;
m_promptItem->setPos(0,0);
m_promptItem->setPos(0, 0);
double x = 0 + m_promptItem->width() + HorizontalSpacing;
double y = 0;
double width = 0;
m_commandItem->setGeometry(x,y, w-x);
width = qMax(width, m_commandItem->width());
const qreal margin = worksheet()->isPrinting() ? 0 : RightMargin;
m_commandItem->setGeometry(x, y, w - x - margin);
width = qMax(width, m_commandItem->width()+margin);
y += qMax(m_commandItem->height(), m_promptItem->height());
foreach(WorksheetTextItem* information, m_informationItems) {
y += VerticalSpacing;
y += information->setGeometry(x,y,w-x);
width = qMax(width, information->width());
y += information->setGeometry(x, y, w - x - margin);
width = qMax(width, information->width() + margin);
}
if (m_errorItem) {
y += VerticalSpacing;
y += m_errorItem->setGeometry(x,y,w-x);
width = qMax(width, m_errorItem->width());
y += m_errorItem->setGeometry(x,y,w - x - margin);
width = qMax(width, m_errorItem->width() + margin);
}
for (auto* resultItem : m_resultItems)
......@@ -1260,8 +1267,8 @@ void CommandEntry::layOutForWidth(qreal w, bool force)
if (!resultItem || !resultItem->graphicsObject()->isVisible())
continue;
y += VerticalSpacing;
y += resultItem->setGeometry(x, y, w-x);
width = qMax(width, resultItem->width());
y += resultItem->setGeometry(x, y, w - x - margin);
width = qMax(width, resultItem->width() + margin);
}
y += VerticalMargin;
......@@ -1301,6 +1308,7 @@ void CommandEntry::collapseResults()
else
setHidePrompt();
m_controlElement.isCollapsed = true;
animateSizeChange();
}
......@@ -1321,6 +1329,7 @@ void CommandEntry::expandResults()
else
this->updatePrompt();
m_controlElement.isCollapsed = false;
animateSizeChange();
}
......
......@@ -358,16 +358,19 @@ void ImageEntry::layOutForWidth(qreal w, bool force)
if (size().width() == w && !force)
return;
//TODO somethinkg wrong with geometry and control element: control element appears in wrong place
const qreal margin = worksheet()->isPrinting() ? 0 : RightMargin;
double width;
if (m_imageItem && m_imageItem->isVisible()) {
m_imageItem->setGeometry(0, 0, w, true);
m_imageItem->setGeometry(0, 0, w - margin, true);
width = m_imageItem->width();
} else {
m_textItem->setGeometry(0, 0, w, true);
m_textItem->setGeometry(0, 0, w - margin, true);
width = m_textItem->width();
}
setSize(QSizeF(width, height() + VerticalMargin));
setSize(QSizeF(width + margin, height() + VerticalMargin));
}
bool ImageEntry::wantToEvaluate()
......
......@@ -503,8 +503,10 @@ void LatexEntry::layOutForWidth(qreal w, bool force)
if (size().width() == w && !force)
return;
m_textItem->setGeometry(0, 0, w);
setSize(QSizeF(m_textItem->width(), m_textItem->height() + VerticalMargin));
const qreal margin = worksheet()->isPrinting() ? 0 : RightMargin;
m_textItem->setGeometry(0, 0, w - margin);
setSize(QSizeF(m_textItem->width() + margin, m_textItem->height() + VerticalMargin));
}
bool LatexEntry::wantToEvaluate()
......
......@@ -444,8 +444,10 @@ void MarkdownEntry::layOutForWidth(qreal w, bool force)
if (size().width() == w && !force)
return;
m_textItem->setGeometry(0, 0, w);
setSize(QSizeF(m_textItem->width(), m_textItem->height() + VerticalMargin));
const qreal margin = worksheet()->isPrinting() ? 0 : RightMargin;
m_textItem->setGeometry(0, 0, w - margin);
setSize(QSizeF(m_textItem->width() + margin, m_textItem->height() + VerticalMargin));
}
bool MarkdownEntry::eventFilter(QObject* object, QEvent* event)
......
......@@ -133,10 +133,12 @@ void PageBreakEntry::layOutForWidth(qreal w, bool force)
if (size().width() == w && !force)
return;
const qreal margin = worksheet()->isPrinting() ? 0 : RightMargin;
if (m_msgItem->isVisible()) {
m_msgItem->setGeometry(0, 0, w, true);
m_msgItem->setGeometry(0, 0, w - margin, true);
setSize(QSizeF(m_msgItem->width(), m_msgItem->height() + VerticalMargin));
setSize(QSizeF(m_msgItem->width() + margin, m_msgItem->height() + VerticalMargin));
} else {
setSize(QSizeF(w, 0));
}
......
......@@ -26,6 +26,7 @@
PlaceHolderEntry::PlaceHolderEntry(Worksheet* worksheet, QSizeF s)
: WorksheetEntry(worksheet)
{
m_controlElement.hide();
setSize(s);
}
......
......@@ -26,6 +26,7 @@ set(worksheettest_SRCS
../mathrender.cpp
../mathrendertask.cpp
../extended_document.cpp
../worksheetcontrolitem.cpp
worksheet_test.cpp)
ki18n_wrap_ui(worksheettest_SRCS ../imagesettings.ui)
......
......@@ -490,8 +490,10 @@ void TextEntry::layOutForWidth(qreal w, bool force)
if (size().width() == w && !force)
return;
m_textItem->setGeometry(0, 0, w);
setSize(QSizeF(m_textItem->width(), m_textItem->height() + VerticalMargin));
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));
}
bool TextEntry::wantToEvaluate()
......
......@@ -1536,81 +1536,93 @@ QMenu* Worksheet::createContextMenu()
void Worksheet::populateMenu(QMenu *menu, QPointF pos)
{
WorksheetEntry* entry = entryAt(pos);
if (entry && !entry->isAncestorOf(m_lastFocusedTextItem)) {
WorksheetTextItem* item =
qgraphicsitem_cast<WorksheetTextItem*>(itemAt(pos, QTransform()));
if (item && item->isEditable())
m_lastFocusedTextItem = item;
}
// Two menu: for particular entry and for selection (multiple entry)
if (m_selectedEntries.isEmpty())
{
WorksheetEntry* entry = entryAt(pos);
if (entry && !entry->isAncestorOf(m_lastFocusedTextItem)) {
WorksheetTextItem* item =
qgraphicsitem_cast<WorksheetTextItem*>(itemAt(pos, QTransform()));
if (item && item->isEditable())
m_lastFocusedTextItem = item;
}
if (!isRunning())
menu->addAction(QIcon::fromTheme(QLatin1String("system-run")), i18n("Evaluate Worksheet"),
this, SLOT(evaluate()), 0);
if (!isRunning())
menu->addAction(QIcon::fromTheme(QLatin1String("system-run")), i18n("Evaluate Worksheet"),
this, SLOT(evaluate()), 0);
else
menu->addAction(QIcon::fromTheme(QLatin1String("process-stop")), i18n("Interrupt"), this,
SLOT(interrupt()), 0);
menu->addSeparator();
if (entry) {
QMenu* convertTo = new QMenu(menu);
QMenu* insert = new QMenu(menu);
QMenu* insertBefore = new QMenu(menu);
convertTo->addAction(QIcon::fromTheme(QLatin1String("run-build")), i18n("Command Entry"), entry, &WorksheetEntry::convertToCommandEntry);
convertTo->addAction(QIcon::fromTheme(QLatin1String("draw-text")), i18n("Text Entry"), entry, &WorksheetEntry::convertToTextEntry);
#ifdef Discount_FOUND
convertTo->addAction(QIcon::fromTheme(QLatin1String("text-x-markdown")), i18n("Markdown Entry"), entry, &WorksheetEntry::convertToMarkdownEntry);
#endif
#ifdef WITH_EPS
convertTo->addAction(QIcon::fromTheme(QLatin1String("text-x-tex")), i18n("LaTeX Entry"), entry, &WorksheetEntry::convertToLatexEntry);
#endif
convertTo->addAction(QIcon::fromTheme(QLatin1String("image-x-generic")), i18n("Image"), entry, &WorksheetEntry::convertToImageEntry);
convertTo->addAction(QIcon::fromTheme(QLatin1String("go-next-view-page")), i18n("Page Break"), entry, &WorksheetEntry::converToPageBreakEntry);
insert->addAction(QIcon::fromTheme(QLatin1String("run-build")), i18n("Command Entry"), entry, SLOT(insertCommandEntry()));
insert->addAction(QIcon::fromTheme(QLatin1String("draw-text")), i18n("Text Entry"), entry, SLOT(insertTextEntry()));
#ifdef Discount_FOUND
insert->addAction(QIcon::fromTheme(QLatin1String("text-x-markdown")), i18n("Markdown Entry"), entry, SLOT(insertMarkdownEntry()));
#endif
#ifdef WITH_EPS
insert->addAction(QIcon::fromTheme(QLatin1String("text-x-tex")), i18n("LaTeX Entry"), entry, SLOT(insertLatexEntry()));
#endif
insert->addAction(QIcon::fromTheme(QLatin1String("image-x-generic")), i18n("Image"), entry, SLOT(insertImageEntry()));
insert->addAction(QIcon::fromTheme(QLatin1String("go-next-view-page")), i18n("Page Break"), entry, SLOT(insertPageBreakEntry()));
insertBefore->addAction(QIcon::fromTheme(QLatin1String("run-build")), i18n("Command Entry"), entry, SLOT(insertCommandEntryBefore()));
insertBefore->addAction(QIcon::fromTheme(QLatin1String("draw-text")), i18n("Text Entry"), entry, SLOT(insertTextEntryBefore()));
#ifdef Discount_FOUND
insertBefore->addAction(QIcon::fromTheme(QLatin1String("text-x-markdown")), i18n("Markdown Entry"), entry, SLOT(insertMarkdownEntryBefore()));
#endif
#ifdef WITH_EPS
insertBefore->addAction(QIcon::fromTheme(QLatin1String("text-x-tex")), i18n("LaTeX Entry"), entry, SLOT(insertLatexEntryBefore()));
#endif
insertBefore->addAction(QIcon::fromTheme(QLatin1String("image-x-generic")), i18n("Image"), entry, SLOT(insertImageEntryBefore()));
insertBefore->addAction(QIcon::fromTheme(QLatin1String("go-next-view-page")), i18n("Page Break"), entry, SLOT(insertPageBreakEntryBefore()));
convertTo->setTitle(i18n("Convert Entry To"));
convertTo->setIcon(QIcon::fromTheme(QLatin1String("gtk-convert")));
insert->setTitle(i18n("Insert Entry After"));
insert->setIcon(QIcon::fromTheme(QLatin1String("edit-table-insert-row-below")));
insertBefore->setTitle(i18n("Insert Entry Before"));
insertBefore->setIcon(QIcon::fromTheme(QLatin1String("edit-table-insert-row-above")));
menu->addMenu(convertTo);
menu->addMenu(insert);
menu->addMenu(insertBefore);
} else {
menu->addAction(QIcon::fromTheme(QLatin1String("run-build")), i18n("Insert Command Entry"), this, SLOT(appendCommandEntry()));
menu->addAction(QIcon::fromTheme(QLatin1String("draw-text")), i18n("Insert Text Entry"), this, SLOT(appendTextEntry()));
#ifdef Discount_FOUND
menu->addAction(QIcon::fromTheme(QLatin1String("text-x-markdown")), i18n("Insert Markdown Entry"), this, SLOT(appendMarkdownEntry()));
#endif
#ifdef WITH_EPS
menu->addAction(QIcon::fromTheme(QLatin1String("text-x-tex")), i18n("Insert LaTeX Entry"), this, SLOT(appendLatexEntry()));
#endif
menu->addAction(QIcon::fromTheme(QLatin1String("image-x-generic")), i18n("Insert Image"), this, SLOT(appendImageEntry()));
menu->addAction(QIcon::fromTheme(QLatin1String("go-next-view-page")), i18n("Insert Page Break"), this, SLOT(appendPageBreakEntry()));
}
}
else
menu->addAction(QIcon::fromTheme(QLatin1String("process-stop")), i18n("Interrupt"), this,
SLOT(interrupt()), 0);
menu->addSeparator();
if (entry) {
QMenu* convertTo = new QMenu(menu);
QMenu* insert = new QMenu(menu);
QMenu* insertBefore = new QMenu(menu);
convertTo->addAction(QIcon::fromTheme(QLatin1String("run-build")), i18n("Command Entry"), entry, &WorksheetEntry::convertToCommandEntry);
convertTo->addAction(QIcon::fromTheme(QLatin1String("draw-text")), i18n("Text Entry"), entry, &WorksheetEntry::convertToTextEntry);
#ifdef Discount_FOUND
convertTo->addAction(QIcon::fromTheme(QLatin1String("text-x-markdown")), i18n("Markdown Entry"), entry, &WorksheetEntry::convertToMarkdownEntry);
#endif
#ifdef WITH_EPS
convertTo->addAction(QIcon::fromTheme(QLatin1String("text-x-tex")), i18n("LaTeX Entry"), entry, &WorksheetEntry::convertToLatexEntry);
#endif
convertTo->addAction(QIcon::fromTheme(QLatin1String("image-x-generic")), i18n("Image"), entry, &WorksheetEntry::convertToImageEntry);
convertTo->addAction(QIcon::fromTheme(QLatin1String("go-next-view-page")), i18n("Page Break"), entry, &WorksheetEntry::converToPageBreakEntry);
insert->addAction(QIcon::fromTheme(QLatin1String("run-build")), i18n("Command Entry"), entry, SLOT(insertCommandEntry()));
insert->addAction(QIcon::fromTheme(QLatin1String("draw-text")), i18n("Text Entry"), entry, SLOT(insertTextEntry()));
#ifdef Discount_FOUND
insert->addAction(QIcon::fromTheme(QLatin1String("text-x-markdown")), i18n("Markdown Entry"), entry, SLOT(insertMarkdownEntry()));
#endif
#ifdef WITH_EPS
insert->addAction(QIcon::fromTheme(QLatin1String("text-x-tex")), i18n("LaTeX Entry"), entry, SLOT(insertLatexEntry()));
#endif
insert->addAction(QIcon::fromTheme(QLatin1String("image-x-generic")), i18n("Image"), entry, SLOT(insertImageEntry()));
insert->addAction(QIcon::fromTheme(QLatin1String("go-next-view-page")), i18n("Page Break"), entry, SLOT(insertPageBreakEntry()));
insertBefore->addAction(QIcon::fromTheme(QLatin1String("run-build")), i18n("Command Entry"), entry, SLOT(insertCommandEntryBefore()));
insertBefore->addAction(QIcon::fromTheme(QLatin1String("draw-text")), i18n("Text Entry"), entry, SLOT(insertTextEntryBefore()));
#ifdef Discount_FOUND
insertBefore->addAction(QIcon::fromTheme(QLatin1String("text-x-markdown")), i18n("Markdown Entry"), entry, SLOT(insertMarkdownEntryBefore()));
#endif
#ifdef WITH_EPS
insertBefore->addAction(QIcon::fromTheme(QLatin1String("text-x-tex")), i18n("LaTeX Entry"), entry, SLOT(insertLatexEntryBefore()));
#endif
insertBefore->addAction(QIcon::fromTheme(QLatin1String("image-x-generic")), i18n("Image"), entry, SLOT(insertImageEntryBefore()));
insertBefore->addAction(QIcon::fromTheme(QLatin1String("go-next-view-page")), i18n("Page Break"), entry, SLOT(insertPageBreakEntryBefore()));
convertTo->setTitle(i18n("Convert Entry To"));
convertTo->setIcon(QIcon::fromTheme(QLatin1String("gtk-convert")));
insert->setTitle(i18n("Insert Entry After"));
insert->setIcon(QIcon::fromTheme(QLatin1String("edit-table-insert-row-below")));
insertBefore->setTitle(i18n("Insert Entry Before"));
insertBefore->setIcon(QIcon::fromTheme(QLatin1String("edit-table-insert-row-above")));
menu->addMenu(convertTo);
menu->addMenu(insert);
menu->addMenu(insertBefore);
} else {
menu->addAction(QIcon::fromTheme(QLatin1String("run-build")), i18n("Insert Command Entry"), this, SLOT(appendCommandEntry()));
menu->addAction(QIcon::fromTheme(QLatin1String("draw-text")), i18n("Insert Text Entry"), this, SLOT(appendTextEntry()));
#ifdef Discount_FOUND
menu->addAction(QIcon::fromTheme(QLatin1String("text-x-markdown")), i18n("Insert Markdown Entry"), this, SLOT(appendMarkdownEntry()));
#endif
#ifdef WITH_EPS
menu->addAction(QIcon::fromTheme(QLatin1String("text-x-tex")), i18n("Insert LaTeX Entry"), this, SLOT(appendLatexEntry()));
#endif
menu->addAction(QIcon::fromTheme(QLatin1String("image-x-generic")), i18n("Insert Image"), this, SLOT(appendImageEntry()));
menu->addAction(QIcon::fromTheme(QLatin1String("go-next-view-page")), i18n("Insert Page Break"), this, SLOT(appendPageBreakEntry()));
{
menu->clear();
menu->addAction(QIcon::fromTheme(QLatin1String("go-up")), i18n("Move Entries Up"), this, SLOT(selectionMoveUp()), 0);
menu->addAction(QIcon::fromTheme(QLatin1String("go-down")), i18n("Move Entries Down"), this, SLOT(selectionMoveDown()), 0);
menu->addAction(QIcon::fromTheme(QLatin1String("media-playback-start")), i18n("Evaluate Entries"), this, SLOT(selectionEvaluate()), 0);
menu->addAction(QIcon::fromTheme(QLatin1String("edit-delete")), i18n("Remove Entries"), this, SLOT(selectionRemove()), 0);
}
}
......@@ -1633,14 +1645,62 @@ void Worksheet::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
void Worksheet::mousePressEvent(QGraphicsSceneMouseEvent* event)
{
QGraphicsScene::mousePressEvent(event);
/*
if (event->button() == Qt::LeftButton && !focusItem() && lastEntry() &&
event->scenePos().y() > lastEntry()->y() + lastEntry()->size().height())
lastEntry()->focusEntry(WorksheetTextItem::BottomRight);
*/
if (!m_readOnly)
updateEntryCursor(event);
if (!m_readOnly && event->buttons() & Qt::LeftButton)
{
WorksheetEntry* selectedEntry = entryAt(event->scenePos());
if (event->modifiers() & Qt::ControlModifier)
{
clearFocus();
resetEntryCursor();
if (selectedEntry)
{
selectedEntry->setCellSelected(!selectedEntry->isCellSelected());
selectedEntry->update();
WorksheetEntry* lastSelectedEntry = m_circularFocusBuffer.size() > 0 ? m_circularFocusBuffer.last() : nullptr;
if (lastSelectedEntry)
{
lastSelectedEntry->setCellSelected(!lastSelectedEntry->isCellSelected());
lastSelectedEntry->update();
m_circularFocusBuffer.clear();
}
for (WorksheetEntry* entry : {selectedEntry, lastSelectedEntry})
if (entry)
{
if (entry->isCellSelected())
m_selectedEntries.append(entry);
else if (!entry->isCellSelected())
m_selectedEntries.removeOne(entry);
}
}
}
else
{
for (WorksheetEntry* entry : m_selectedEntries)
{
if(isValidEntry(entry))
{
entry->setCellSelected(false);
entry->update();
}
}
m_selectedEntries.clear();
if (selectedEntry)
notifyEntryFocus(selectedEntry);
updateEntryCursor(event);
}
}
QGraphicsScene::mousePressEvent(event);
}
void Worksheet::keyPressEvent(QKeyEvent *keyEvent)
......@@ -2359,3 +2419,62 @@ void Worksheet::changeEntryType(WorksheetEntry* target, int newType)
m_animationsEnabled = animation_state;
}
}
bool Worksheet::isValidEntry(WorksheetEntry* entry)
{
for (WorksheetEntry* iter = firstEntry(); iter; iter = iter->next())
if (entry == iter)
return true;
return false;
}
void Worksheet::selectionRemove()
{
for (WorksheetEntry* entry : m_selectedEntries)
if (isValidEntry(entry))
entry->startRemoving();
m_selectedEntries.clear();
}
void Worksheet::selectionEvaluate()
{
// run entries in worksheet order: from top to down
for (WorksheetEntry* entry = firstEntry(); entry; entry = entry->next())
if (m_selectedEntries.indexOf(entry) != -1)
entry->evaluate();
}
void Worksheet::selectionMoveUp()
{
// movement up should have an order from top to down.
for(WorksheetEntry* entry = firstEntry(); entry; entry = entry->next())
if(m_selectedEntries.indexOf(entry) != -1)
if (entry->previous() && m_selectedEntries.indexOf(entry->previous()) == -1)
entry->moveToPrevious(false);
updateLayout();
}
void Worksheet::selectionMoveDown()
{
// movement up should have an order from down to top.
for(WorksheetEntry* entry = lastEntry(); entry; entry = entry->previous())
if(m_selectedEntries.indexOf(entry) != -1)
if (entry->next() && m_selectedEntries.indexOf(entry->next()) == -1)
entry->moveToNext(false);
updateLayout();
}
void Worksheet::notifyEntryFocus(WorksheetEntry* entry)
{
if (entry)
{
m_circularFocusBuffer.enqueue(entry);
if (m_circularFocusBuffer.size() > 2)
m_circularFocusBuffer.dequeue();
}
else
m_circularFocusBuffer.clear();
}
......@@ -22,11 +22,14 @@
#ifndef WORKSHEET_H
#define WORKSHEET_H
#include <QGraphicsScene>
#include <QDomElement>
#include <QGraphicsLinearLayout>
#include <QSyntaxHighlighter>
#include <QGraphicsRectItem>
#include <QVector>
#include <QQueue>
#include <KZip>
#include <QMenu>
......@@ -127,6 +130,8 @@ class Worksheet : public QGraphicsScene
void setType(Worksheet::Type type);
Worksheet::Type type() const;
void notifyEntryFocus(WorksheetEntry* entry);
// richtext
struct RichTextInfo {
bool bold;
......@@ -258,6 +263,8 @@ class Worksheet : public QGraphicsScene
QJsonDocument toJupyterJson();
bool isValidEntry(WorksheetEntry*);
private Q_SLOTS:
void showCompletion();
//void checkEntriesForSanity();
......@@ -266,6 +273,12 @@ class Worksheet : public QGraphicsScene
WorksheetEntry* insertEntry(int type, WorksheetEntry* current = nullptr);
WorksheetEntry* insertEntryBefore(int type, WorksheetEntry* current = nullptr);
//Actions for selection
void selectionRemove();
void selectionEvaluate();
void selectionMoveUp();
void selectionMoveDown();
void animateEntryCursor();
private:
......@@ -335,6 +348,9 @@ class Worksheet : public QGraphicsScene
QString m_backendName;
QJsonObject* m_jupyterMetadata{nullptr};
QVector<WorksheetEntry*> m_selectedEntries;
QQueue<WorksheetEntry*> m_circularFocusBuffer;
};
#endif // WORKSHEET_H
/*
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
---
Copyright (C) 2020 Sirgienko Nikita <warquark@gmail.com>
*/
#include "worksheetcontrolitem.h"
#include <KColorScheme>
#include <QApplication>
#include <QDebug>
#include "worksheet.h"
#include "worksheetentry.h"
WorksheetControlItem::WorksheetControlItem(Worksheet* worksheet, WorksheetEntry* parent): QGraphicsRectItem(parent)
{
setAcceptDrops(true);
setAcceptHoverEvents(true);
setFlags(flags() | QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsFocusable);
m_worksheet = worksheet;
}
void WorksheetControlItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option,