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

Add possibility to change result collapsing via double click on '>>>' prompt element

parent f6d04cce
......@@ -95,6 +95,9 @@ CommandEntry::CommandEntry(Worksheet* worksheet) : WorksheetEntry(worksheet),
m_promptItemAnimation->setEndValue(1);
connect(m_promptItemAnimation, &QPropertyAnimation::finished, this, &CommandEntry::animatePromptItem);
m_promptItem->setDoubleClickBehaviour(WorksheetTextItem::DoubleClickEventBehaviour::Simple);
connect(m_promptItem, &WorksheetTextItem::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);
......@@ -1330,3 +1333,14 @@ void CommandEntry::setMidPrompt()
{
updatePrompt(MidPrompt);
}
void CommandEntry::changeResultCollapsingAction()
{
if (m_resultItems.size() == 0)
return;
if (m_resultsCollapsed)
expandResults();
else
collapseResults();
}
......@@ -142,6 +142,7 @@ class CommandEntry : public WorksheetEntry
void replaceResultItem(int index);
void updateCompletions();
void completeCommandTo(const QString& completion, CommandEntry::CompletionMode mode = PreliminaryCompletion);
void changeResultCollapsingAction();
void backgroundColorChanged(QAction*);
void textColorChanged(QAction*);
......
......@@ -598,18 +598,26 @@ void WorksheetTextItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
QTextCursor cursor = textCursor();
const QChar repl = QChar::ObjectReplacementCharacter;
if (!cursor.hasSelection()) {
// We look at the current cursor and the next cursor for a
// ObjectReplacementCharacter
for (int i = 2; i; --i) {
if (document()->characterAt(cursor.position()-1) == repl) {
setTextCursor(cursor);
emit doubleClick();
return;
if (m_eventBehaviour == DoubleClickEventBehaviour::ImageReplacement)
{
if (!cursor.hasSelection()) {
// We look at the current cursor and the next cursor for a
// ObjectReplacementCharacter
for (int i = 2; i; --i) {
if (document()->characterAt(cursor.position()-1) == repl) {
setTextCursor(cursor);
emit doubleClick();
return;
}
cursor.movePosition(QTextCursor::NextCharacter);
}
cursor.movePosition(QTextCursor::NextCharacter);
} else if (cursor.selectedText().contains(repl)) {
emit doubleClick();
return;
}
} else if (cursor.selectedText().contains(repl)) {
}
else if (m_eventBehaviour == DoubleClickEventBehaviour::Simple)
{
emit doubleClick();
return;
}
......@@ -923,3 +931,13 @@ void WorksheetTextItem::denyEditing()
{
setTextInteractionFlags(Qt::TextBrowserInteraction | Qt::TextSelectableByKeyboard);
}
WorksheetTextItem::DoubleClickEventBehaviour WorksheetTextItem::doubleClickBehaviour()
{
return m_eventBehaviour;
}
void WorksheetTextItem::setDoubleClickBehaviour(WorksheetTextItem::DoubleClickEventBehaviour behaviour)
{
m_eventBehaviour = behaviour;
}
......@@ -43,6 +43,8 @@ class WorksheetTextItem : public QGraphicsTextItem
{
Q_OBJECT
public:
enum DoubleClickEventBehaviour {Simple, ImageReplacement};
explicit WorksheetTextItem(QGraphicsObject* parent,
Qt::TextInteractionFlags ti = Qt::NoTextInteraction);
~WorksheetTextItem() override;
......@@ -104,6 +106,9 @@ class WorksheetTextItem : public QGraphicsTextItem
QTextDocument::FindFlags qt_flags,
const WorksheetCursor& pos);
DoubleClickEventBehaviour doubleClickBehaviour();
void setDoubleClickBehaviour(DoubleClickEventBehaviour behaviour);
Q_SIGNALS:
void moveToPrevious(int pos, qreal xCoord);
void moveToNext(int pos, qreal xCoord);
......@@ -173,6 +178,7 @@ class WorksheetTextItem : public QGraphicsTextItem
bool m_itemDragable;
bool m_richTextEnabled;
QColor m_backgroundColor;
DoubleClickEventBehaviour m_eventBehaviour{DoubleClickEventBehaviour::ImageReplacement};
};
#endif // WORKSHEET_TEXT_ITEM_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