File indexing completed on 2024-11-10 11:07:48

0001 
0002 /***************************************************************************
0003  *   Copyright (C) 2006 by David Saxton - david@bluehaze.org               *
0004  *                                                                         *
0005  *   This program is free software; you can redistribute it and/or modify  *
0006  *   it under the terms of the GNU General Public License as published by  *
0007  *   the Free Software Foundation; either version 2 of the License, or     *
0008  *   (at your option) any later version.                                   *
0009  ***************************************************************************/
0010 
0011 #ifndef RICHTEXTEDITOR_H
0012 #define RICHTEXTEDITOR_H
0013 
0014 #include <QDialog>
0015 
0016 class QTextEdit;
0017 class KToggleAction;
0018 class KToolBarPopupAction;
0019 class QFont;
0020 class QTextCharFormat;
0021 
0022 /**
0023 @author David Saxton
0024 */
0025 class RichTextEditor : public QWidget
0026 {
0027     Q_OBJECT
0028 public:
0029     RichTextEditor(QWidget *parent = nullptr);
0030 
0031     ~RichTextEditor() override;
0032     /**.
0033      * @return the text in the editor (tidied up).
0034      */
0035     QString text() const;
0036     /**
0037      * Sets the text.
0038      */
0039     void setText(QString text);
0040     /**
0041      * Inserts formatting into the body tag that will ensure the text used
0042      * is the default for the system. If the text does not have a body tag,
0043      * it will be given one.
0044      */
0045     static void makeUseStandardFont(QString *html);
0046     /**
0047      * These are the paths that are used for to search for images, etc.
0048      */
0049     void setResourcePaths(const QStringList &paths);
0050 
0051     QWidget *editorViewport() const;
0052 
0053 signals:
0054     void textChanged();
0055 
0056 public slots:
0057     /**
0058      * Inserts a url in the editor at the current cursor position with the
0059      * given location and text.
0060      */
0061     void insertURL(const QString &url, const QString &text);
0062     /**
0063      * Inserts the given HTML code at the current cursor position (this
0064      * function is required as QTextEdit will try to format any inserted
0065      * HTML code, replacing less-thans, etc.
0066      */
0067     void insertHTML(const QString &html);
0068 
0069 protected slots:
0070     void slotSetBold(bool);
0071     void slotSetItalic(bool);
0072     void slotSetUnderline(bool);
0073     void slotSetAlignment(QAction *);
0074     /**
0075      * Called when a vertical alignment is selected (subscript, normal or
0076      * superscript).
0077      */
0078     void slotSetVerticalAlignment(QAction *a);
0079     void slotSetList(bool set);
0080     void slotCurrentCharFormatChanged(const QTextCharFormat &f);
0081     void fontChanged(const QFont &f);
0082     void colorChanged(const QColor &c);
0083     void alignmentChanged(int a);
0084     void verticalAlignmentChanged();
0085     void textColor();
0086 
0087 protected:
0088     KToggleAction *m_pTextBold;
0089     KToggleAction *m_pTextItalic;
0090     KToggleAction *m_pTextUnderline;
0091     KToggleAction *m_pTextList;
0092     KToolBarPopupAction *m_pTextAlignment;
0093     KToolBarPopupAction *m_pTextVerticalAlignment;
0094     QAction *m_pTextColor;
0095     QTextEdit *m_pEditor;
0096 };
0097 
0098 /**
0099 Popup dialog for editing rich text
0100 @author David Saxton
0101 */
0102 class RichTextEditorDlg : public QDialog
0103 {
0104 public:
0105     RichTextEditorDlg(QWidget *parent = nullptr, const QString &caption = QString());
0106 
0107     /**
0108      * Sets the text being edited (passes it to RichTextEditor).
0109      */
0110     void setText(const QString &text)
0111     {
0112         m_pEditor->setText(text);
0113     }
0114     /**
0115      * @return the text in the RichTextEditor.
0116      */
0117     QString text() const
0118     {
0119         return m_pEditor->text();
0120     }
0121 
0122 protected:
0123     RichTextEditor *m_pEditor;
0124 };
0125 
0126 #endif