Commit 1c193b46 authored by Alexander Semke's avatar Alexander Semke
Browse files

New signal-slot syntax, member initialisation in the header and code cleanup...

New signal-slot syntax, member initialisation in the header and code cleanup in worksheettextitem.h/cpp and cantor.h/cpp.
parent 7786c20a
Pipeline #67786 passed with stage
in 20 minutes and 20 seconds
......@@ -42,7 +42,7 @@
#include "backendchoosedialog.h"
#include <QMetaObject>
CantorShell::CantorShell() : KParts::MainWindow(), m_part(nullptr), m_panelHandler(nullptr)
CantorShell::CantorShell() : KParts::MainWindow(), m_tabWidget(new QTabWidget(this))
{
// set the shell's ui resource file
setXMLFile(QLatin1String("cantor_shell.rc"));
......@@ -52,7 +52,6 @@ CantorShell::CantorShell() : KParts::MainWindow(), m_part(nullptr), m_panelHandl
createGUI(nullptr);
m_tabWidget=new QTabWidget(this);
m_tabWidget->setTabsClosable(true);
m_tabWidget->setMovable(true);
m_tabWidget->setDocumentMode(true);
......@@ -856,7 +855,6 @@ void CantorShell::saveDockPanelsState(KParts::ReadWritePart* part)
{
if (m_parts2Backends.contains(part))
{
QStringList visiblePanelNames;
if (part == m_part)
{
......@@ -895,7 +893,5 @@ void CantorShell::updateBackendForPart(const QString& backend)
void CantorShell::pluginCommandRunRequested(const QString& cmd)
{
if (m_part)
{
QMetaObject::invokeMethod(m_part, "runCommand", Qt::QueuedConnection, Q_ARG(QString, cmd));
}
}
......@@ -73,20 +73,20 @@ Q_SIGNALS:
void requestDocumentation(const QString&);
public Q_SLOTS:
void addWorksheet(const QString& backendName);
void addWorksheet(const QString&);
/// Use this method/slot to load whatever file/URL you have
void load(const QUrl& url);
void load(const QUrl&);
private Q_SLOTS:
void fileNew();
void fileOpen();
void onWorksheetSave(const QUrl& url);
void onWorksheetSave(const QUrl&);
void optionsConfigureKeys();
void activateWorksheet(int index);
void setTabCaption(const QString& tab, const QIcon& icon);
void updateBackendForPart(const QString& backend);
void setTabCaption(const QString&, const QIcon&);
void updateBackendForPart(const QString&);
void closeTab(int index = -1);
void showSettings();
......@@ -99,29 +99,29 @@ private Q_SLOTS:
void updateNewSubmenu();
void pluginVisibilityRequested();
void pluginCommandRunRequested(const QString& cmd);
void pluginCommandRunRequested(const QString&);
private:
void setupActions();
void closeEvent(QCloseEvent*) override;
bool reallyClose(bool checkAllParts = true);
bool reallyCloseThisPart(KParts::ReadWritePart* part);
void updateWindowTitle(const QString& fileName);
void saveDockPanelsState(KParts::ReadWritePart* part);
KParts::ReadWritePart* findPart(QWidget* widget);
bool reallyCloseThisPart(KParts::ReadWritePart*);
void updateWindowTitle(const QString&);
void saveDockPanelsState(KParts::ReadWritePart*);
KParts::ReadWritePart* findPart(QWidget*);
private:
QMap<KParts::ReadWritePart*, QStringList> m_pluginsVisibility;
QMap<KParts::ReadWritePart*, Cantor::PanelPluginHandler::PanelStates> m_pluginsStates;
QList<KParts::ReadWritePart *> m_parts;
QList<KParts::ReadWritePart*> m_parts;
QMap<KParts::ReadWritePart*, QString> m_parts2Backends;
KParts::ReadWritePart* m_part;
KParts::ReadWritePart* m_part{nullptr};
QTabWidget* m_tabWidget;
QList<QDockWidget*> m_panels;
QList<QAction*> m_newBackendActions;
KRecentFilesAction* m_recentProjectsAction;
Cantor::PanelPluginHandler m_panelHandler;
Cantor::PanelPluginHandler m_panelHandler{nullptr};
// For better UX: set previous used filter in "Open" action as default filter
QString m_previousFilter;
......
......@@ -23,7 +23,7 @@
#include <KStandardAction>
#include <KLocalizedString>
TextResultItem::TextResultItem(QGraphicsObject* parent, Cantor::Result* result)
TextResultItem::TextResultItem(WorksheetEntry* parent, Cantor::Result* result)
: WorksheetTextItem(parent), ResultItem(result)
{
connect(this, SIGNAL(collapseActionSizeChanged()), parent, SLOT(recalculateSize()));
......
......@@ -8,25 +8,26 @@
#include "resultitem.h"
#include "worksheettextitem.h"
#include "worksheetentry.h"
#include "lib/latexresult.h"
namespace Cantor {
class LatexResult;
}
class TextResultItem : public WorksheetTextItem, public ResultItem
{
Q_OBJECT
public:
explicit TextResultItem(QGraphicsObject* parent, Cantor::Result* result);
explicit TextResultItem(WorksheetEntry*, Cantor::Result*);
~TextResultItem() override = default;
using WorksheetTextItem::setGeometry;
double setGeometry(double x, double y, double w) override;
void populateMenu(QMenu* menu, QPointF pos) override;
void populateMenu(QMenu*, QPointF) override;
void update() override;
void setLatex(Cantor::LatexResult* result);
QTextImageFormat toFormat(const QImage& image, const QString& latex);
void setLatex(Cantor::LatexResult*);
QTextImageFormat toFormat(const QImage&, const QString& latex);
double width() const override;
double height() const override;
......@@ -44,7 +45,7 @@ class TextResultItem : public WorksheetTextItem, public ResultItem
void saveResult();
protected:
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) override;
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent*) override;
int visibleLineCount();
void collapseExtraLines();
......
......@@ -12,6 +12,7 @@
#include <QApplication>
#include <QClipboard>
#include <QDebug>
#include <QMimeData>
#include <QTextDocument>
#include <QAbstractTextDocumentLayout>
......@@ -20,28 +21,22 @@
#include <QTextLine>
#include <QGraphicsSceneResizeEvent>
#include <QPainter>
#include <QtGlobal>
#include <QDebug>
#include <KStandardAction>
#include <QAction>
#include <QColorDialog>
#include <KColorScheme>
#include <QFontDatabase>
WorksheetTextItem::WorksheetTextItem(QGraphicsObject* parent, Qt::TextInteractionFlags ti)
WorksheetTextItem::WorksheetTextItem(WorksheetEntry* parent, Qt::TextInteractionFlags ti)
: QGraphicsTextItem(parent)
{
setTextInteractionFlags(ti);
if (ti & Qt::TextEditable) {
setCursor(Qt::IBeamCursor);
connect(this, SIGNAL(sizeChanged()), parent,
SLOT(recalculateSize()));
connect(this, &WorksheetTextItem::sizeChanged, parent, &WorksheetEntry::recalculateSize);
}
m_completionEnabled = false;
m_completionActive = false;
m_itemDragable = false;
m_richTextEnabled = false;
m_size = document()->size();;
setAcceptDrops(true);
setFont(QFontDatabase::systemFont(QFontDatabase::FixedFont));
......@@ -53,15 +48,12 @@ WorksheetTextItem::WorksheetTextItem(QGraphicsObject* parent, Qt::TextInteractio
QApplication::restoreOverrideCursor();
});
connect(document(), SIGNAL(contentsChanged()), this, SLOT(testSize()));
connect(this, SIGNAL(menuCreated(QMenu*,QPointF)), parent,
SLOT(populateMenu(QMenu*,QPointF)), Qt::DirectConnection);
connect(this, SIGNAL(deleteEntry()), parent, SLOT(startRemoving()));
connect(document(), &QTextDocument::contentsChanged, this, &WorksheetTextItem::testSize);
connect(document(), &QTextDocument::undoAvailable, this, &WorksheetTextItem::undoAvailable);
connect(document(), &QTextDocument::redoAvailable, this, &WorksheetTextItem::redoAvailable);
connect(this, &WorksheetTextItem::menuCreated, parent, &WorksheetEntry::populateMenu, Qt::DirectConnection);
connect(this, &WorksheetTextItem::deleteEntry, parent, &WorksheetEntry::startRemoving);
connect(this, &WorksheetTextItem::cursorPositionChanged, this, &WorksheetTextItem::updateRichTextActions);
connect(document(), SIGNAL(undoAvailable(bool)),
this, SIGNAL(undoAvailable(bool)));
connect(document(), SIGNAL(redoAvailable(bool)),
this, SIGNAL(redoAvailable(bool)));
}
WorksheetTextItem::~WorksheetTextItem()
......@@ -124,10 +116,9 @@ qreal WorksheetTextItem::setGeometry(qreal x, qreal y, qreal w, bool centered)
void WorksheetTextItem::populateMenu(QMenu* menu, QPointF pos)
{
qDebug() << "populate Menu";
QAction * cut = KStandardAction::cut(this, SLOT(cut()), menu);
QAction * copy = KStandardAction::copy(this, SLOT(copy()), menu);
QAction * paste = KStandardAction::paste(this, SLOT(paste()), menu);
auto* cut = KStandardAction::cut(this, &WorksheetTextItem::cut, menu);
auto* copy = KStandardAction::copy(this, &WorksheetTextItem::copy, menu);
auto* paste = KStandardAction::paste(this, &WorksheetTextItem::paste, menu);
if (!textCursor().hasSelection()) {
cut->setEnabled(false);
copy->setEnabled(false);
......@@ -157,7 +148,7 @@ void WorksheetTextItem::populateMenu(QMenu* menu, QPointF pos)
QKeyEvent* WorksheetTextItem::eventForStandardAction(KStandardAction::StandardAction actionID)
{
// there must be a better way to get the shortcut...
QAction * action = KStandardAction::create(actionID, this, SLOT(copy()), this);
auto* action = KStandardAction::create(actionID, this, &WorksheetTextItem::copy, this);
QKeySequence keySeq = action->shortcut();
// we do not support key sequences with multiple keys here
int code = keySeq[0];
......@@ -262,7 +253,7 @@ QString WorksheetTextItem::resolveImages(const QTextCursor& cursor)
return result;
}
void WorksheetTextItem::setCursorPosition(const QPointF& pos)
void WorksheetTextItem::setCursorPosition(QPointF pos)
{
QTextCursor cursor = cursorForPosition(pos);
setTextCursor(cursor);
......@@ -275,7 +266,7 @@ QPointF WorksheetTextItem::cursorPosition() const
return mapToParent(localCursorPosition());
}
void WorksheetTextItem::setLocalCursorPosition(const QPointF& pos)
void WorksheetTextItem::setLocalCursorPosition(QPointF pos)
{
int p = document()->documentLayout()->hitTest(pos, Qt::FuzzyHit);
QTextCursor cursor = textCursor();
......@@ -330,7 +321,7 @@ QRectF WorksheetTextItem::cursorRect(QTextCursor cursor) const
qMax(r1.y() + r1.height(), r2.y() + r2.height()));
}
QTextCursor WorksheetTextItem::cursorForPosition(const QPointF& pos) const
QTextCursor WorksheetTextItem::cursorForPosition(QPointF pos) const
{
QPointF lpos = mapFromParent(pos);
int p = document()->documentLayout()->hitTest(lpos, Qt::FuzzyHit);
......@@ -519,8 +510,8 @@ void WorksheetTextItem::focusInEvent(QFocusEvent *event)
if (event->reason() != Qt::ActiveWindowFocusReason)
worksheet()->makeVisible(c);
worksheet()->updateFocusedTextItem(this);
connect(QApplication::clipboard(), SIGNAL(dataChanged()), this,
SLOT(clipboardChanged()));
connect(QApplication::clipboard(), &QClipboard::dataChanged, this,
&WorksheetTextItem::clipboardChanged);
emit receivedFocus(this);
emit cursorPositionChanged(textCursor());
}
......@@ -671,6 +662,7 @@ void WorksheetTextItem::wheelEvent(QGraphicsSceneWheelEvent* event)
QApplication::restoreOverrideCursor();
QGraphicsItem::wheelEvent(event);
}
void WorksheetTextItem::insertTab()
{
QTextCursor cursor = textCursor();
......@@ -816,7 +808,6 @@ void WorksheetTextItem::updateRichTextActions(QTextCursor cursor)
void WorksheetTextItem::mergeFormatOnWordOrSelection(const QTextCharFormat &format)
{
qDebug() << format;
QTextCursor cursor = textCursor();
QTextCursor wordStart(cursor);
QTextCursor wordEnd(cursor);
......@@ -898,7 +889,6 @@ void WorksheetTextItem::setAlignment(Qt::Alignment a)
setTextCursor(cursor);
}
void WorksheetTextItem::setFontFamily(const QString& font)
{
if (!richTextEnabled())
......
......@@ -15,6 +15,7 @@
#include <KStandardAction>
class Worksheet;
class WorksheetEntry;
class WorksheetView;
class WorksheetCursor;
......@@ -30,13 +31,13 @@ class WorksheetTextItem : public QGraphicsTextItem
public:
enum DoubleClickEventBehaviour {Simple, ImageReplacement};
explicit WorksheetTextItem(QGraphicsObject* parent,
explicit WorksheetTextItem(WorksheetEntry* parent,
Qt::TextInteractionFlags ti = Qt::NoTextInteraction);
~WorksheetTextItem() override;
void setCursorPosition(const QPointF& pos);
void setCursorPosition(QPointF);
QPointF cursorPosition() const;
QTextCursor cursorForPosition(const QPointF& pos) const;
QTextCursor cursorForPosition(QPointF) const;
QRectF sceneCursorRect(QTextCursor cursor = QTextCursor()) const;
QRectF cursorRect(QTextCursor cursor = QTextCursor()) const;
......@@ -52,8 +53,8 @@ class WorksheetTextItem : public QGraphicsTextItem
void setItemDragable(bool b);
void enableRichText(bool b);
virtual void populateMenu(QMenu* menu, QPointF pos);
QString resolveImages(const QTextCursor& cursor);
virtual void populateMenu(QMenu*, QPointF);
QString resolveImages(const QTextCursor&);
bool isEditable();
void allowEditing();
......@@ -76,23 +77,23 @@ class WorksheetTextItem : public QGraphicsTextItem
bool isCopyAvailable();
bool isPasteAvailable();
// richtext stuff
// richtext
void setTextForegroundColor();
void setTextBackgroundColor();
void setTextBold(bool b);
void setTextItalic(bool b);
void setTextUnderline(bool b);
void setTextStrikeOut(bool b);
void setAlignment(Qt::Alignment a);
void setFontFamily(const QString& font);
void setFontSize(int size);
void setTextBold(bool);
void setTextItalic(bool);
void setTextUnderline(bool);
void setTextStrikeOut(bool);
void setAlignment(Qt::Alignment);
void setFontFamily(const QString&);
void setFontSize(int);
QTextCursor search(QString pattern,
QTextDocument::FindFlags qt_flags,
const WorksheetCursor& pos);
DoubleClickEventBehaviour doubleClickBehaviour();
void setDoubleClickBehaviour(DoubleClickEventBehaviour behaviour);
void setDoubleClickBehaviour(DoubleClickEventBehaviour);
Q_SIGNALS:
void moveToPrevious(int pos, qreal xCoord);
......@@ -106,8 +107,8 @@ class WorksheetTextItem : public QGraphicsTextItem
void execute();
void deleteEntry();
void sizeChanged();
void menuCreated(QMenu*, const QPointF&);
void drag(const QPointF&, const QPointF&);
void menuCreated(QMenu*, QPointF);
void drag(const QPointF&, QPointF);
void undoAvailable(bool);
void redoAvailable(bool);
void cutAvailable(bool);
......@@ -126,42 +127,42 @@ class WorksheetTextItem : public QGraphicsTextItem
void testSize();
protected:
void keyPressEvent(QKeyEvent *event) override;
void focusInEvent(QFocusEvent *event) override;
void focusOutEvent(QFocusEvent *event) override;
void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) override;
void mouseMoveEvent(QGraphicsSceneMouseEvent* event) override;
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override;
void dragEnterEvent(QGraphicsSceneDragDropEvent* event) override;
//void dragLeaveEvent(QGraphicsSceneDragDropEvent* event);
void dragMoveEvent(QGraphicsSceneDragDropEvent* event) override;
void dropEvent(QGraphicsSceneDragDropEvent* event) override;
bool sceneEvent(QEvent *event) override;
void keyPressEvent(QKeyEvent*) override;
void focusInEvent(QFocusEvent*) override;
void focusOutEvent(QFocusEvent*) override;
void mousePressEvent(QGraphicsSceneMouseEvent*) override;
void mouseReleaseEvent(QGraphicsSceneMouseEvent*) override;
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent*) override;
void mouseMoveEvent(QGraphicsSceneMouseEvent*) override;
void contextMenuEvent(QGraphicsSceneContextMenuEvent*) override;
void dragEnterEvent(QGraphicsSceneDragDropEvent*) override;
//void dragLeaveEvent(QGraphicsSceneDragDropEvent*);
void dragMoveEvent(QGraphicsSceneDragDropEvent*) override;
void dropEvent(QGraphicsSceneDragDropEvent*) override;
bool sceneEvent(QEvent*) override;
void wheelEvent(QGraphicsSceneWheelEvent*) override;
void paint(QPainter* painter, const QStyleOptionGraphicsItem* o, QWidget* w) override;
void paint(QPainter*, const QStyleOptionGraphicsItem*, QWidget*) override;
private Q_SLOTS:
//void setHeight();
void updateRichTextActions(QTextCursor cursor);
private:
void setLocalCursorPosition(const QPointF& pos);
void setLocalCursorPosition(QPointF);
QPointF localCursorPosition() const;
QKeyEvent* eventForStandardAction(KStandardAction::StandardAction actionID);
QKeyEvent* eventForStandardAction(KStandardAction::StandardAction);
Cantor::Session* session();
// richtext
void mergeFormatOnWordOrSelection(const QTextCharFormat &format);
void mergeFormatOnWordOrSelection(const QTextCharFormat&);
private:
QSizeF m_size;
bool m_completionEnabled;
bool m_completionActive;
bool m_itemDragable;
bool m_richTextEnabled;
bool m_completionEnabled{false};
bool m_completionActive{false};
bool m_itemDragable{false};
bool m_richTextEnabled{false};
QColor m_backgroundColor;
DoubleClickEventBehaviour m_eventBehaviour{DoubleClickEventBehaviour::ImageReplacement};
};
......
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