24 #define KDE_NO_DEBUG_OUTPUT
36 #include <ktextbrowser.h>
37 #include <ktextedit.h>
38 #include <kcombobox.h>
39 #include <kpushbutton.h>
44 #include <QStackedLayout>
46 #include <QStringListModel>
50 :
QDockWidget (i18nc(
"@title toolview name",
"Unit metadata"), parent)
55 , m_hasErrorNotes(false)
57 setObjectName(
"msgCtxtView");
60 m_stackedLayout =
new QStackedLayout(main);
61 m_stackedLayout->addWidget(m_browser);
63 m_browser->viewport()->setBackgroundRole(QPalette::Background);
64 m_browser->setOpenLinks(
false);
65 connect(m_browser,SIGNAL(anchorClicked(QUrl)),
this,SLOT(anchorClicked(QUrl)));
74 m_unfinishedNotes.clear();
81 m_selection=selection;
83 QTimer::singleShot(0,
this,SLOT(process()));
86 void MsgCtxtView::process()
91 if (m_stackedLayout->currentIndex())
92 m_unfinishedNotes[m_prevEntry]=qMakePair(m_editor->
note(),m_editor->
noteIndex());
95 if (m_unfinishedNotes.contains(m_entry))
98 m_editor->
setNote(m_unfinishedNotes.value(m_entry).first,m_unfinishedNotes.value(m_entry).second);
101 m_stackedLayout->setCurrentIndex(0);
107 if (m_tempNotes.contains(m_entry.
entry))
109 QString html=i18nc(
"@info notes to translation unit which expire when the catalog is closed",
"<b>Temporary notes:</b>");
111 foreach(
const QString& note, m_tempNotes.values(m_entry.
entry))
114 m_browser->insertHtml(html.replace(
'\n',
"<br>"));
118 if (!phaseName.isEmpty())
121 QString html=i18nc(
"@info translation unit metadata",
"<b>Phase:</b><br>");
122 if (phase.
date.isValid())
123 html+=QString(
"%1: ").arg(phase.
date.toString(Qt::ISODate));
127 m_browser->insertHtml(html+
"<br>");
131 m_hasErrorNotes=
false;
132 foreach (
const Note& note, notes)
133 m_hasErrorNotes=m_hasErrorNotes||note.
content.contains(
"[ERROR]");
142 if (!sourceFiles.isEmpty())
144 html+=i18nc(
"@info PO comment parsing",
"<br><b>Files:</b><br>");
145 foreach(
const QString &sourceFile, sourceFiles)
146 html+=QString(
"<a href=\"src:/%1\">%2</a><br />").arg(sourceFile).arg(sourceFile);
150 QString msgctxt=m_catalog->
context(m_entry.
entry).first();
151 if (!msgctxt.isEmpty())
152 html+=i18nc(
"@info PO comment parsing",
"<br><b>Context:</b><br>")+
Qt::escape(msgctxt);
154 QTextCursor t=m_browser->textCursor();
155 t.movePosition(QTextCursor::End);
156 m_browser->setTextCursor(t);
157 m_browser->insertHtml(html);
159 t.movePosition(QTextCursor::Start);
160 t.movePosition(QTextCursor::NextCharacter,QTextCursor::MoveAnchor,realOffset+m_offset);
161 t.movePosition(QTextCursor::NextCharacter,QTextCursor::KeepAnchor,m_selection);
162 m_browser->setTextCursor(t);
168 anchorClicked(QUrl(
"note:/add"));
171 void MsgCtxtView::anchorClicked(
const QUrl& link)
173 QString path=link.path().mid(1);
175 if (link.scheme()==
"note")
181 m_stackedLayout->addWidget(m_editor);
182 connect(m_editor,SIGNAL(accepted()),
this,SLOT(noteEditAccepted()));
183 connect(m_editor,SIGNAL(rejected()),
this,SLOT(noteEditRejected()));
189 if (!path.endsWith(
"add"))
191 noteIndex=path.toInt();
192 note=notes.at(noteIndex);
199 m_editor->
setNote(note,noteIndex);
201 m_stackedLayout->setCurrentIndex(1);
203 else if (link.scheme()==
"src")
205 int pos=path.lastIndexOf(
':');
210 void MsgCtxtView::noteEditAccepted()
216 m_prevEntry.
entry=-1; process();
221 void MsgCtxtView::noteEditRejected()
223 m_stackedLayout->setCurrentIndex(0);
224 m_unfinishedNotes.remove(m_entry);
237 m_tempNotes.insertMulti(entry,text);
238 m_prevEntry.
entry=-1; process();
243 if (!m_hasErrorNotes)
return;
246 const QVector<Note> notes=m_catalog->
notes(p);
250 if (notes.at(p.
form).content.contains(
"[ERROR]"))
254 m_prevEntry.
entry=-1; process();
258 #include "msgctxtview.moc"
QStringList context(const DocPosition &pos) const
void gotoEntry(const DocPosition &, int selection=0)
void addNote(DocPosition, const QString &text)
int main(int argc, char **argv)
void push(QUndoCommand *cmd)
QVector< Note > developerNotes(const DocPosition &pos) const
This struct represents a position in a catalog.
void srcFileOpenRequested(const QString &srcPath, int line)
QStringList noteAuthors() const
static QString escape(QString str)
void addTemporaryEntryNote(int entry, const QString &text)
QString phase(const DocPosition &pos) const
int displayNotes(KTextBrowser *browser, const QVector< Note > ¬es, int active, bool multiple)
void setNoteAuthors(const QStringList &)
int numberOfEntries() const
simpler version of DocPosition for use in QMap
void setFromFieldVisible(bool)
This class represents a catalog It uses CatalogStorage interface to work with catalogs in different f...
QVector< Note > notes(const DocPosition &pos) const
QStringList sourceFiles(const DocPosition &pos) const
void setNote(const Note &, int idx)
Insert or remove (if content is empty) a note.
DocPosition toDocPosition()
MsgCtxtView(QWidget *, Catalog *)