~ubuntu-branches/ubuntu/trusty/bibletime/trusty

« back to all changes in this revision

Viewing changes to src/frontend/display/cplainwritedisplay.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Marsden
  • Date: 2009-11-18 17:30:00 UTC
  • mfrom: (1.3.4 upstream) (5.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20091118173000-endkhjz5qai88tvr
Tags: 2.4-1
* New upstream version 2.4
* debian/control: 
  - Replace incorrect bibletime-data Depends on lib4qt-gui
    with bibletime Depends on libqtgui4 (>= 4.4.0). (Closes: #556209).
  - Add Build-depends: on zlib1g-dev and libcurl4-gnutls-dev 
    (Closes: #556805).

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
*
8
8
**********/
9
9
 
10
 
#include "cplainwritedisplay.h"
11
 
#include "frontend/displaywindow/btactioncollection.h"
12
 
#include "frontend/cdragdrop.h"
13
 
#include "frontend/displaywindow/cdisplaywindow.h"
14
 
#include "frontend/displaywindow/cwritewindow.h"
15
 
 
16
 
#include "backend/keys/cswordkey.h"
 
10
#include "frontend/display/cplainwritedisplay.h"
17
11
 
18
12
#include <boost/scoped_ptr.hpp>
19
 
 
20
 
//Qt includes
21
13
#include <QDragEnterEvent>
 
14
#include <QDragMoveEvent>
22
15
#include <QDropEvent>
23
 
#include <QDragMoveEvent>
24
16
#include <QMenu>
 
17
#include <QDebug>
 
18
 
 
19
#include "backend/keys/cswordkey.h"
 
20
#include "frontend/cdragdrop.h"
 
21
#include "frontend/displaywindow/btactioncollection.h"
 
22
#include "frontend/displaywindow/cdisplaywindow.h"
 
23
#include "frontend/displaywindow/cwritewindow.h"
25
24
 
26
25
 
27
26
CPlainWriteDisplay::CPlainWriteDisplay(CWriteWindow* parentWindow, QWidget* parent) : QTextEdit(parentWindow ? parentWindow : parent), CWriteDisplay(parentWindow) {
28
 
        setAcceptRichText(false);
29
 
        setAcceptDrops(true);
30
 
        viewport()->setAcceptDrops(true);
 
27
    setAcceptRichText(false);
 
28
    setAcceptDrops(true);
 
29
    viewport()->setAcceptDrops(true);
31
30
 
32
 
        connect(this, SIGNAL(textChanged()),
33
 
                        connectionsProxy(), SLOT(emitTextChanged()));
 
31
    connect(this, SIGNAL(textChanged()),
 
32
            connectionsProxy(), SLOT(emitTextChanged()));
34
33
}
35
34
 
36
35
CPlainWriteDisplay::~CPlainWriteDisplay() {}
37
36
 
38
37
/** Reimplementation. */
39
38
void CPlainWriteDisplay::selectAll() {
40
 
        QTextEdit::selectAll();
 
39
    QTextEdit::selectAll();
41
40
}
42
41
 
43
42
void CPlainWriteDisplay::setText( const QString& newText ) {
44
 
        //make sure the text has been converted to show \n instead of <br/>
45
 
        QString text = newText;
 
43
    //make sure the text has been converted to show \n instead of <br/>
 
44
    QString text = newText;
46
45
//      text.replace("\n<br /><!-- BT newline -->\n", "\n");
47
 
        text.replace("<br />", "\n"); //inserted by BT or the Qt textedit widget
 
46
    text.replace("<br />", "\n"); //inserted by BT or the Qt textedit widget
48
47
 
49
 
        QTextEdit::setText(text);
 
48
    QTextEdit::setText(text);
50
49
}
51
50
 
52
51
bool CPlainWriteDisplay::hasSelection() {
53
 
        //TODO: test this
54
 
        return textCursor().hasSelection();
 
52
    /// \todo test this
 
53
    return textCursor().hasSelection();
55
54
}
56
55
 
57
56
QWidget* CPlainWriteDisplay::view() {
58
 
        qDebug("CPlainWriteDisplay::view()");
59
 
        return this;
 
57
    qDebug() << "CPlainWriteDisplay::view()";
 
58
    return this;
60
59
}
61
60
 
62
61
const QString CPlainWriteDisplay::text( const CDisplay::TextType /*format*/, const CDisplay::TextPart /*part*/) {
63
 
        return QString::null;
 
62
    return QString::null;
64
63
}
65
64
 
66
65
void CPlainWriteDisplay::print( const CDisplay::TextPart, CSwordBackend::DisplayOptions, CSwordBackend::FilterOptions) {
68
67
 
69
68
/** Sets the current status of the edit widget. */
70
69
void CPlainWriteDisplay::setModified( const bool modified ) {
71
 
        document()->setModified(modified);
 
70
    document()->setModified(modified);
72
71
}
73
72
 
74
73
/** Reimplementation. */
75
74
bool CPlainWriteDisplay::isModified() const {
76
 
        return document()->isModified();
 
75
    return document()->isModified();
77
76
}
78
77
 
79
78
 
80
79
/** Returns the text of this edit widget. */
81
80
const QString CPlainWriteDisplay::plainText() {
82
 
        QString ret = QTextEdit::toPlainText();
83
 
 
84
 
        //in plain text mode the text just contains newlines, convert them into <br/> before we return the text for display in a HTML widget
85
 
        ret.replace("\n", "<br />");
86
 
 
87
 
        return ret;
 
81
    QString ret = QTextEdit::toPlainText();
 
82
 
 
83
    //in plain text mode the text just contains newlines, convert them into <br/> before we return the text for display in a HTML widget
 
84
    ret.replace("\n", "<br />");
 
85
 
 
86
    return ret;
88
87
}
89
88
 
90
89
/** Reimplementation from QTextEdit. Provides an popup menu for the given position. */
91
90
QMenu* CPlainWriteDisplay::createPopupMenu( const QPoint& /*pos*/ ) {
92
 
        return installedPopup();
 
91
    return installedPopup();
93
92
}
94
93
//
95
94
///** Reimplementation from QTextEdit. Provides an popup menu for the given position. */
102
101
 
103
102
/** Reimplementation to insert the text of a dragged reference into the edit view. */
104
103
void CPlainWriteDisplay::dragEnterEvent( QDragEnterEvent* e ) {
105
 
        //if (CDragDropMgr::canDecode(e)) {
106
 
        if (e->mimeData()->hasFormat("BibleTime/Bookmark") || e->mimeData()->hasFormat("text/plain")) {
107
 
                e->acceptProposedAction();
108
 
        }
109
 
        else {
110
 
                //e->accept(false);
111
 
                e->ignore();
112
 
        }
 
104
    //if (CDragDropMgr::canDecode(e)) {
 
105
    if (e->mimeData()->hasFormat("BibleTime/Bookmark") || e->mimeData()->hasFormat("text/plain")) {
 
106
        e->acceptProposedAction();
 
107
    }
 
108
    else {
 
109
        //e->accept(false);
 
110
        e->ignore();
 
111
    }
113
112
}
114
113
 
115
114
/** Reimplementation to insert the text of a dragged reference into the edit view. */
116
115
void CPlainWriteDisplay::dragMoveEvent( QDragMoveEvent* e ) {
117
 
        if (e->mimeData()->hasFormat("BibleTime/Bookmark") || e->mimeData()->hasFormat("text/plain")) {
118
 
                //placeCursor(e->pos());
119
 
                setTextCursor(cursorForPosition(e->pos()));
120
 
                ensureCursorVisible();
121
 
                e->acceptProposedAction();
122
 
        }
123
 
        else {
124
 
                //e->accept(false);
125
 
                e->ignore();
126
 
        }
 
116
    if (e->mimeData()->hasFormat("BibleTime/Bookmark") || e->mimeData()->hasFormat("text/plain")) {
 
117
        //placeCursor(e->pos());
 
118
        setTextCursor(cursorForPosition(e->pos()));
 
119
        ensureCursorVisible();
 
120
        e->acceptProposedAction();
 
121
    }
 
122
    else {
 
123
        //e->accept(false);
 
124
        e->ignore();
 
125
    }
127
126
}
128
127
 
129
128
/** Reimplementation to manage drops of our drag and drop objects. */
130
 
void CPlainWriteDisplay::dropEvent( QDropEvent* e )
131
 
{
132
 
        //qDebug("CPlainWriteDisplay::dropEvent");
133
 
        const BTMimeData* mimedata = qobject_cast<const BTMimeData*>(e->mimeData());
134
 
 
135
 
        if ( mimedata && mimedata->hasFormat("BibleTime/Bookmark") ) {
136
 
                //qDebug("format was bookmark");
137
 
                e->acceptProposedAction();
138
 
 
139
 
                BTMimeData::ItemList items = mimedata->bookmarks();
140
 
                BTMimeData::ItemList::iterator it;
141
 
                for (it = items.begin(); it != items.end(); ++it) {
142
 
 
143
 
                        CSwordModuleInfo* module = backend()->findModuleByName((*it).module());
144
 
                        boost::scoped_ptr<CSwordKey> key( CSwordKey::createInstance(module) );
145
 
                        key->key( (*it).key() );
146
 
                        QString moduleText = key->strippedText();
147
 
 
148
 
                        const QString text = QString::fromLatin1("%1\n(%2, %3)\n").arg(moduleText).arg((*it).key()).arg((*it).module());
149
 
 
150
 
                        setTextCursor(cursorForPosition(e->pos()));
151
 
                        textCursor().insertText( text );
152
 
                }
153
 
        }
154
 
        else if ( e->mimeData()->hasFormat("text/plain")) {
155
 
                //qDebug("format was plain text");
156
 
                e->acceptProposedAction();
157
 
                setTextCursor(cursorForPosition(e->pos()));
158
 
                textCursor().insertText( e->mimeData()->text() );
159
 
        }
 
129
void CPlainWriteDisplay::dropEvent( QDropEvent* e ) {
 
130
    //qDebug() << "CPlainWriteDisplay::dropEvent";
 
131
    const BTMimeData* mimedata = qobject_cast<const BTMimeData*>(e->mimeData());
 
132
 
 
133
    if ( mimedata && mimedata->hasFormat("BibleTime/Bookmark") ) {
 
134
        //qDebug() << "format was bookmark";
 
135
        e->acceptProposedAction();
 
136
 
 
137
        BTMimeData::ItemList items = mimedata->bookmarks();
 
138
        BTMimeData::ItemList::iterator it;
 
139
        for (it = items.begin(); it != items.end(); ++it) {
 
140
 
 
141
            CSwordModuleInfo* module = backend()->findModuleByName((*it).module());
 
142
            boost::scoped_ptr<CSwordKey> key( CSwordKey::createInstance(module) );
 
143
            key->key( (*it).key() );
 
144
            QString moduleText = key->strippedText();
 
145
 
 
146
            const QString text = QString::fromLatin1("%1\n(%2, %3)\n").arg(moduleText).arg((*it).key()).arg((*it).module());
 
147
 
 
148
            setTextCursor(cursorForPosition(e->pos()));
 
149
            textCursor().insertText( text );
 
150
        }
 
151
    }
 
152
    else if ( e->mimeData()->hasFormat("text/plain")) {
 
153
        //qDebug() << "format was plain text";
 
154
        e->acceptProposedAction();
 
155
        setTextCursor(cursorForPosition(e->pos()));
 
156
        textCursor().insertText( e->mimeData()->text() );
 
157
    }
160
158
}