Changeset View
Changeset View
Standalone View
Standalone View
src/commandentry.cpp
Show All 29 Lines | |||||
30 | #include "lib/session.h" | 30 | #include "lib/session.h" | ||
31 | 31 | | |||
32 | #include <QApplication> | 32 | #include <QApplication> | ||
33 | #include <QDebug> | 33 | #include <QDebug> | ||
34 | #include <QDesktopWidget> | 34 | #include <QDesktopWidget> | ||
35 | #include <QFontDialog> | 35 | #include <QFontDialog> | ||
36 | #include <QTimer> | 36 | #include <QTimer> | ||
37 | #include <QToolTip> | 37 | #include <QToolTip> | ||
38 | #include <QPropertyAnimation> | ||||
38 | 39 | | |||
39 | #include <KLocalizedString> | 40 | #include <KLocalizedString> | ||
40 | #include <KColorScheme> | 41 | #include <KColorScheme> | ||
41 | 42 | | |||
42 | const QString CommandEntry::Prompt=QLatin1String(">>> "); | 43 | const QString CommandEntry::Prompt=QLatin1String(">>> "); | ||
43 | const double CommandEntry::HorizontalSpacing = 4; | 44 | const double CommandEntry::HorizontalSpacing = 4; | ||
44 | const double CommandEntry::VerticalSpacing = 4; | 45 | const double CommandEntry::VerticalSpacing = 4; | ||
45 | 46 | | |||
Show All 27 Lines | 73 | { | |||
73 | 74 | | |||
74 | m_promptItem->setPlainText(Prompt); | 75 | m_promptItem->setPlainText(Prompt); | ||
75 | m_promptItem->setItemDragable(true); | 76 | m_promptItem->setItemDragable(true); | ||
76 | m_commandItem->enableCompletion(true); | 77 | m_commandItem->enableCompletion(true); | ||
77 | 78 | | |||
78 | KColorScheme scheme = KColorScheme(QPalette::Normal, KColorScheme::View); | 79 | KColorScheme scheme = KColorScheme(QPalette::Normal, KColorScheme::View); | ||
79 | m_commandItem->setBackgroundColor(scheme.background(KColorScheme::AlternateBackground).color()); | 80 | m_commandItem->setBackgroundColor(scheme.background(KColorScheme::AlternateBackground).color()); | ||
80 | 81 | | |||
81 | m_promtItemTimer = new QTimer(this); | 82 | m_promptItemAnimation = new QPropertyAnimation(m_promptItem, "opacity"); | ||
82 | connect(m_promtItemTimer, &QTimer::timeout, this, &CommandEntry::animatePromptItem); | 83 | m_promptItemAnimation->setDuration(600); | ||
84 | m_promptItemAnimation->setStartValue(1); | ||||
85 | m_promptItemAnimation->setKeyValueAt(0.5, 0); | ||||
86 | m_promptItemAnimation->setEndValue(1); | ||||
87 | connect(m_promptItemAnimation, &QPropertyAnimation::finished, this, &CommandEntry::animatePromptItem); | ||||
83 | 88 | | |||
84 | connect(m_commandItem, &WorksheetTextItem::tabPressed, this, &CommandEntry::showCompletion); | 89 | connect(m_commandItem, &WorksheetTextItem::tabPressed, this, &CommandEntry::showCompletion); | ||
85 | connect(m_commandItem, &WorksheetTextItem::backtabPressed, this, &CommandEntry::selectPreviousCompletion); | 90 | connect(m_commandItem, &WorksheetTextItem::backtabPressed, this, &CommandEntry::selectPreviousCompletion); | ||
86 | connect(m_commandItem, &WorksheetTextItem::applyCompletion, this, &CommandEntry::applySelectedCompletion); | 91 | connect(m_commandItem, &WorksheetTextItem::applyCompletion, this, &CommandEntry::applySelectedCompletion); | ||
87 | connect(m_commandItem, SIGNAL(execute()), this, SLOT(evaluate())); | 92 | connect(m_commandItem, SIGNAL(execute()), this, SLOT(evaluate())); | ||
88 | connect(m_commandItem, &WorksheetTextItem::moveToPrevious, this, &CommandEntry::moveToPreviousItem); | 93 | connect(m_commandItem, &WorksheetTextItem::moveToPrevious, this, &CommandEntry::moveToPreviousItem); | ||
89 | connect(m_commandItem, &WorksheetTextItem::moveToNext, this, &CommandEntry::moveToNextItem); | 94 | connect(m_commandItem, &WorksheetTextItem::moveToNext, this, &CommandEntry::moveToNextItem); | ||
90 | connect(m_commandItem, SIGNAL(receivedFocus(WorksheetTextItem*)), worksheet, SLOT(highlightItem(WorksheetTextItem*))); | 95 | connect(m_commandItem, SIGNAL(receivedFocus(WorksheetTextItem*)), worksheet, SLOT(highlightItem(WorksheetTextItem*))); | ||
▲ Show 20 Lines • Show All 524 Lines • ▼ Show 20 Line(s) | |||||
615 | { | 620 | { | ||
616 | switch (status) | 621 | switch (status) | ||
617 | { | 622 | { | ||
618 | case Cantor::Expression::Computing: | 623 | case Cantor::Expression::Computing: | ||
619 | { | 624 | { | ||
620 | //change the background of the promt item and start animating it (fade in/out). | 625 | //change the background of the promt item and start animating it (fade in/out). | ||
621 | //don't start the animation immediately in order to avoid unwanted flickering for "short" commands, | 626 | //don't start the animation immediately in order to avoid unwanted flickering for "short" commands, | ||
622 | //start the animation after 1 second passed. | 627 | //start the animation after 1 second passed. | ||
623 | QTimer::singleShot(1000, this, [=] () { | 628 | if (worksheet()->animationsEnabled()) | ||
624 | KColorScheme scheme = KColorScheme(QPalette::Normal, KColorScheme::View); | | |||
625 | m_promptItem->setBackgroundColor(scheme.decoration(KColorScheme::HoverColor).color()); | | |||
626 | m_promtItemTimer->start(100); | | |||
627 | }); | | |||
628 | break; | | |||
629 | } | | |||
630 | case Cantor::Expression::Queued: | | |||
631 | { | 629 | { | ||
632 | QTimer::singleShot(1000, this, [=] () { | 630 | const int id = m_expression->id(); | ||
633 | if (m_expression->status() == Cantor::Expression::Queued) | 631 | QTimer::singleShot(1000, this, [this, id] () { | ||
634 | { | 632 | if(m_expression->status() == Cantor::Expression::Computing && m_expression->id() == id) | ||
635 | KColorScheme scheme = KColorScheme(QPalette::Normal, KColorScheme::View); | 633 | m_promptItemAnimation->start(); | ||
636 | m_promptItem->setBackgroundColor(scheme.decoration(KColorScheme::HoverColor).color()); | | |||
637 | } | | |||
638 | }); | 634 | }); | ||
635 | } | ||||
639 | break; | 636 | break; | ||
640 | } | 637 | } | ||
641 | case Cantor::Expression::Error: | 638 | case Cantor::Expression::Error: | ||
642 | case Cantor::Expression::Interrupted: | 639 | case Cantor::Expression::Interrupted: | ||
643 | m_promtItemTimer->stop(); | 640 | m_promptItemAnimation->stop(); | ||
644 | m_promptItem->setBackgroundColor(QColor()); | | |||
645 | m_promptItem->setOpacity(1.); | 641 | m_promptItem->setOpacity(1.); | ||
646 | 642 | | |||
647 | m_commandItem->setFocusAt(WorksheetTextItem::BottomRight, 0); | 643 | m_commandItem->setFocusAt(WorksheetTextItem::BottomRight, 0); | ||
648 | 644 | | |||
649 | if(!m_errorItem) | 645 | if(!m_errorItem) | ||
650 | { | 646 | { | ||
651 | m_errorItem = new WorksheetTextItem(this, Qt::TextSelectableByMouse); | 647 | m_errorItem = new WorksheetTextItem(this, Qt::TextSelectableByMouse); | ||
652 | } | 648 | } | ||
653 | 649 | | |||
654 | if (status == Cantor::Expression::Error) | 650 | if (status == Cantor::Expression::Error) | ||
655 | m_errorItem->setHtml(m_expression->errorMessage()); | 651 | m_errorItem->setHtml(m_expression->errorMessage()); | ||
656 | else | 652 | else | ||
657 | m_errorItem->setHtml(i18n("Interrupted")); | 653 | m_errorItem->setHtml(i18n("Interrupted")); | ||
658 | 654 | | |||
659 | recalculateSize(); | 655 | recalculateSize(); | ||
660 | break; | 656 | break; | ||
661 | case Cantor::Expression::Done: | 657 | case Cantor::Expression::Done: | ||
662 | m_promtItemTimer->stop(); | 658 | m_promptItemAnimation->stop(); | ||
663 | m_promptItem->setBackgroundColor(QColor()); | | |||
664 | m_promptItem->setOpacity(1.); | 659 | m_promptItem->setOpacity(1.); | ||
665 | evaluateNext(m_evaluationOption); | 660 | evaluateNext(m_evaluationOption); | ||
666 | m_evaluationOption = DoNothing; | 661 | m_evaluationOption = DoNothing; | ||
667 | break; | 662 | break; | ||
668 | default: | 663 | default: | ||
669 | break; | 664 | break; | ||
670 | } | 665 | } | ||
671 | } | 666 | } | ||
672 | 667 | | |||
673 | void CommandEntry::animatePromptItem() { | 668 | void CommandEntry::animatePromptItem() { | ||
674 | if (m_expression->status() != Cantor::Expression::Computing) | 669 | if(m_expression->status() == Cantor::Expression::Computing) | ||
675 | { | 670 | m_promptItemAnimation->start(); | ||
676 | //the expression is not being computed anymore, reset the promt item and leave | | |||
677 | m_promptItem->setBackgroundColor(QColor()); | | |||
678 | m_promptItem->setOpacity(1.); | | |||
679 | m_promtItemTimer->stop(); | | |||
680 | return; | | |||
681 | } | | |||
682 | | ||||
683 | static bool fadeOut = true; | | |||
684 | qreal newOpacity = m_promptItem->opacity(); | | |||
685 | if (fadeOut) | | |||
686 | { | | |||
687 | newOpacity -= 0.1; | | |||
688 | if (newOpacity < 0.0) | | |||
689 | { | | |||
690 | fadeOut = false; | | |||
691 | return; | | |||
692 | } | | |||
693 | } | | |||
694 | else | | |||
695 | { | | |||
696 | newOpacity += 0.1; | | |||
697 | if (newOpacity > 1.0) | | |||
698 | { | | |||
699 | fadeOut = true; | | |||
700 | return; | | |||
701 | } | | |||
702 | } | | |||
703 | | ||||
704 | m_promptItem->setOpacity(newOpacity); | | |||
705 | } | 671 | } | ||
706 | 672 | | |||
707 | bool CommandEntry::isEmpty() | 673 | bool CommandEntry::isEmpty() | ||
708 | { | 674 | { | ||
709 | if (m_commandItem->toPlainText().trimmed().isEmpty()) { | 675 | if (m_commandItem->toPlainText().trimmed().isEmpty()) { | ||
710 | if (!m_resultItems.isEmpty()) | 676 | if (!m_resultItems.isEmpty()) | ||
711 | return false; | 677 | return false; | ||
712 | return true; | 678 | return true; | ||
▲ Show 20 Lines • Show All 206 Lines • ▼ Show 20 Line(s) | 882 | { | |||
919 | { | 885 | { | ||
920 | m_expression->clearResult(); | 886 | m_expression->clearResult(); | ||
921 | } | 887 | } | ||
922 | 888 | | |||
923 | //fade out all result graphic objects | 889 | //fade out all result graphic objects | ||
924 | for(auto* item : m_resultItems) | 890 | for(auto* item : m_resultItems) | ||
925 | fadeOutItem(item->graphicsObject()); | 891 | fadeOutItem(item->graphicsObject()); | ||
926 | 892 | | |||
927 | //delete all result graphic objects | | |||
928 | qDeleteAll(m_resultItems); | | |||
929 | m_resultItems.clear(); | 893 | m_resultItems.clear(); | ||
930 | } | 894 | } | ||
931 | 895 | | |||
932 | void CommandEntry::removeContextHelp() | 896 | void CommandEntry::removeContextHelp() | ||
933 | { | 897 | { | ||
934 | disconnect(m_commandItem->document(), SIGNAL(contentsChanged()), this, SLOT(completedLineChanged())); | 898 | disconnect(m_commandItem->document(), SIGNAL(contentsChanged()), this, SLOT(completedLineChanged())); | ||
935 | 899 | | |||
936 | m_commandItem->activateCompletion(false); | 900 | m_commandItem->activateCompletion(false); | ||
Show All 18 Lines | 918 | if(m_expression && worksheet()->showExpressionIds()&&m_expression->id()!=-1) | |||
955 | c.insertText(QString::number(m_expression->id()),cformat); | 919 | c.insertText(QString::number(m_expression->id()),cformat); | ||
956 | 920 | | |||
957 | //detect the correct color for the prompt, depending on the | 921 | //detect the correct color for the prompt, depending on the | ||
958 | //Expression state | 922 | //Expression state | ||
959 | if(m_expression) | 923 | if(m_expression) | ||
960 | { | 924 | { | ||
961 | if(m_expression ->status() == Cantor::Expression::Computing&&worksheet()->isRunning()) | 925 | if(m_expression ->status() == Cantor::Expression::Computing&&worksheet()->isRunning()) | ||
962 | cformat.setForeground(color.foreground(KColorScheme::PositiveText)); | 926 | cformat.setForeground(color.foreground(KColorScheme::PositiveText)); | ||
927 | else if(m_expression ->status() == Cantor::Expression::Queued) | ||||
928 | cformat.setForeground(color.foreground(KColorScheme::InactiveText)); | ||||
963 | else if(m_expression ->status() == Cantor::Expression::Error) | 929 | else if(m_expression ->status() == Cantor::Expression::Error) | ||
964 | cformat.setForeground(color.foreground(KColorScheme::NegativeText)); | 930 | cformat.setForeground(color.foreground(KColorScheme::NegativeText)); | ||
965 | else if(m_expression ->status() == Cantor::Expression::Interrupted) | 931 | else if(m_expression ->status() == Cantor::Expression::Interrupted) | ||
966 | cformat.setForeground(color.foreground(KColorScheme::NeutralText)); | 932 | cformat.setForeground(color.foreground(KColorScheme::NeutralText)); | ||
967 | else | 933 | else | ||
968 | cformat.setFontWeight(QFont::Normal); | 934 | cformat.setFontWeight(QFont::Normal); | ||
969 | } | 935 | } | ||
970 | 936 | | |||
▲ Show 20 Lines • Show All 153 Lines • Show Last 20 Lines |