File indexing completed on 2024-05-12 05:21:06

0001 /*******************************************************************
0002  KNotes -- Notes for the KDE project
0003 
0004  SPDX-FileCopyrightText: 1997-2013 The KNotes Developers
0005 
0006  SPDX-License-Identifier: GPL-2.0-or-later
0007 *******************************************************************/
0008 
0009 #pragma once
0010 
0011 #include "knotes_export.h"
0012 #include <QTextCharFormat>
0013 #include <QWidget>
0014 
0015 #include <KTextEdit>
0016 class QFont;
0017 
0018 class QAction;
0019 class KActionCollection;
0020 class KFontAction;
0021 class KFontSizeAction;
0022 class KToggleAction;
0023 class KNote;
0024 namespace PimCommon
0025 {
0026 class KActionMenuChangeCase;
0027 }
0028 class KNOTES_EXPORT KNoteEdit : public KTextEdit
0029 {
0030     Q_OBJECT
0031 public:
0032     explicit KNoteEdit(KActionCollection *actions, QWidget *parent = nullptr);
0033     ~KNoteEdit() override;
0034 
0035     void setNote(KNote *_note);
0036 
0037     void setText(const QString &text);
0038     QString text() const;
0039 
0040     void setTextFont(const QFont &font);
0041     void setTabStop(int tabs);
0042     void setAutoIndentMode(bool newmode);
0043 
0044     void setColor(const QColor &fg, const QColor &bg);
0045     void setCursorPositionFromStart(int pos);
0046     int cursorPositionFromStart() const;
0047     QMenu *mousePopupMenu() override;
0048 public Q_SLOTS:
0049     void setRichText(bool);
0050 
0051     void textBold(bool);
0052     void textStrikeOut(bool);
0053 
0054     void slotTextColor();
0055 
0056     void textAlignLeft();
0057     void textAlignCenter();
0058     void textAlignRight();
0059     void textAlignBlock();
0060 
0061     void textList();
0062 
0063     void textSuperScript();
0064     void textSubScript();
0065 
0066     void textIncreaseIndent();
0067     void textDecreaseIndent();
0068     void setTextFontSize(int);
0069 
0070     void slotTextBackgroundColor();
0071     void slotInsertDate();
0072 
0073 protected:
0074     void keyPressEvent(QKeyEvent *) override;
0075     void focusInEvent(QFocusEvent *) override;
0076     void focusOutEvent(QFocusEvent *) override;
0077 
0078 private Q_SLOTS:
0079     void slotCurrentCharFormatChanged(const QTextCharFormat &);
0080     void slotCursorPositionChanged();
0081     void slotUpperCase();
0082     void slotLowerCase();
0083     void slotSentenceCase();
0084     void slotInsertCheckMark();
0085     void slotReverseCase();
0086 
0087 private:
0088     void autoIndent();
0089 
0090     void enableRichTextActions(bool enabled);
0091 
0092 private:
0093     QColor mDefaultBackgroundColor;
0094     QColor mDefaultForegroundColor;
0095 
0096     KToggleAction *m_textBold = nullptr;
0097     KToggleAction *m_textItalic = nullptr;
0098     KToggleAction *m_textUnderline = nullptr;
0099     KToggleAction *m_textStrikeOut = nullptr;
0100 
0101     KToggleAction *m_textAlignLeft = nullptr;
0102     KToggleAction *m_textAlignCenter = nullptr;
0103     KToggleAction *m_textAlignRight = nullptr;
0104     KToggleAction *m_textAlignBlock = nullptr;
0105 
0106     KToggleAction *m_textList = nullptr;
0107     KToggleAction *m_textSuper = nullptr;
0108     KToggleAction *m_textSub = nullptr;
0109 
0110     QAction *m_textIncreaseIndent = nullptr;
0111     QAction *m_textDecreaseIndent = nullptr;
0112 
0113     QAction *m_textColor = nullptr;
0114     KFontAction *m_textFont = nullptr;
0115     KFontSizeAction *m_textSize = nullptr;
0116     KNote *m_note = nullptr;
0117     KActionCollection *m_actions = nullptr;
0118     PimCommon::KActionMenuChangeCase *mChangeCaseActionMenu = nullptr;
0119     bool m_autoIndentMode = false;
0120 };