c2bTextEdit.h 2.5 KB
Newer Older
1
/***************************************************************************
2
 *   Copyright (C) 2004-2017 by Pere Constans
3
 *   constans@molspaces.com
4
 *   cb2Bib version 1.9.6. Licensed under the GNU GPL version 3.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
 *   See the LICENSE file that comes with this distribution.
 ***************************************************************************/
#ifndef C2BTEXTEDIT_H
#define C2BTEXTEDIT_H

#include <QPlainTextEdit>


class c2bSettings;


class c2bTextEdit : public QPlainTextEdit
{

    Q_OBJECT

public:
22
    explicit c2bTextEdit(QWidget* parentw = 0);
23 24 25 26 27 28 29
    ~c2bTextEdit();

    QAction* convertSelection2LaTeXAction;
    QAction* convertSelection2UnicodeAction;
    QAction* journalsToAbbreviatedAction;
    QAction* journalsToFullAction;
    QAction* pasteCurrentBibTeXAction;
30
    QAction* toggleWordWrappingAction;
31 32
    QAction* updateMetadataAction;
    void setBibTeXActions();
33
    void setLaTeXActions();
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
    void updatePlainText(const QString& text);

    inline const QString editorFilename() const
    {
        return _editor_filename;
    }

    void setEditorFilename(const QString& fn)
    {
        _editor_filename = fn;
    }


signals:
    void overwriteModeChanged();


public slots:
52
    void toggleWordWrapping();
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70


protected slots:
    void convert2LaTeX();
    void convert2Unicode();


protected:
    void contextMenuEvent(QContextMenuEvent* qevent);
    void keyPressEvent(QKeyEvent* qevent);
    void resizeEvent(QResizeEvent* qevent);


private:
    QColor _line_number_area_color;
    QColor* _line_number_color_p;
    QString _editor_filename;
    QWidget* _line_number_area;
71
    c2bSettings* _settingsP;
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
    int lineNumberAreaWidth();
    void lineNumberAreaPaintEvent(QPaintEvent* qevent);


private slots:
    void loadSettings();
    void updateLineNumberAreaWidth();
    void updateLineNumberArea(const QRect& qrect, int dy);


    friend class LineNumberArea;

};


/***************************************************************************
 *  Line number area (From CodeEditor Qt's example)
 ***************************************************************************/
class LineNumberArea : public QWidget
{

public:
94
    explicit LineNumberArea(c2bTextEdit* editor) : QWidget(editor)
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
    {
        _editor = editor;
    }
    ~LineNumberArea() {}

    QSize sizeHint() const
    {
        return QSize(_editor->lineNumberAreaWidth(), 0);
    }


protected:
    void paintEvent(QPaintEvent* qevent)
    {
        _editor->lineNumberAreaPaintEvent(qevent);
    }


private:
    c2bTextEdit* _editor;

};

#endif