• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdesdk API Reference
  • KDE Home
  • Contact Us
 

lokalize

  • sources
  • kde-4.14
  • kdesdk
  • lokalize
  • src
noteeditor.cpp
Go to the documentation of this file.
1 /* ****************************************************************************
2  This file is part of Lokalize
3 
4  Copyright (C) 2009 by Nick Shaforostoff <shafff@ukr.net>
5 
6  This program is free software; you can redistribute it and/or
7  modify it under the terms of the GNU General Public License as
8  published by the Free Software Foundation; either version 2 of
9  the License or (at your option) version 3 or any later version
10  accepted by the membership of KDE e.V. (or its successor approved
11  by the membership of KDE e.V.), which shall act as a proxy
12  defined in Section 14 of version 3 of the license.
13 
14  This program is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with this program. If not, see <http://www.gnu.org/licenses/>.
21 
22 **************************************************************************** */
23 
24 #include "noteeditor.h"
25 
26 #include "catalog.h"
27 #include "cmd.h"
28 #include "prefs_lokalize.h"
29 
30 #include <klocale.h>
31 #include <kdebug.h>
32 #include <ktextedit.h>
33 #include <ktextbrowser.h>
34 #include <kcombobox.h>
35 #include <kpushbutton.h>
36 
37 #include <QBoxLayout>
38 #include <QStackedLayout>
39 #include <QLabel>
40 #include <QStringListModel>
41 #include <QLineEdit>
42 #include <QKeyEvent>
43 
44 void TextEdit::keyPressEvent(QKeyEvent* keyEvent)
45 {
46  if (keyEvent->modifiers()& Qt::ControlModifier
47  && keyEvent->key()==Qt::Key_Return)
48  emit accepted();
49  else if (keyEvent->key()==Qt::Key_Escape)
50  emit rejected();
51  else
52  QPlainTextEdit::keyPressEvent(keyEvent);
53 }
54 
55 NoteEditor::NoteEditor(QWidget* parent)
56  : QWidget(parent)
57  , m_from(new KComboBox(this))
58  , m_fromLabel(new QLabel(i18nc("@info:label","From:"),this))
59  , m_authors(new QStringListModel(this))
60  , m_edit(new TextEdit(this))
61 {
62  setToolTip(i18nc("@info:tooltip","Save empty note to remove it"));
63  m_from->setToolTip(i18nc("@info:tooltip","Author of this note"));
64  m_from->setEditable(true);
65  m_from->setModel(m_authors);
66  m_from->setAutoCompletion(true);
67  m_from->completionObject(true);
68 
69  QVBoxLayout* main=new QVBoxLayout(this);
70  QHBoxLayout* prop=new QHBoxLayout;
71  main->addLayout(prop);
72  prop->addWidget(m_fromLabel);
73  prop->addWidget(m_from,42);
74  main->addWidget(m_edit);
75 
76  KPushButton* ok=new KPushButton(KStandardGuiItem::save(), this);
77  KPushButton* cancel=new KPushButton(KStandardGuiItem::discard(), this);
78  ok->setToolTip(i18n("Ctrl+Enter"));
79  cancel->setToolTip(i18n("Esc"));
80 
81  connect(m_edit,SIGNAL(accepted()),this,SIGNAL(accepted()));
82  connect(m_edit,SIGNAL(rejected()),this,SIGNAL(rejected()));
83  connect(ok,SIGNAL(clicked()),this,SIGNAL(accepted()));
84  connect(cancel,SIGNAL(clicked()),this,SIGNAL(rejected()));
85 
86  QHBoxLayout* btns=new QHBoxLayout;
87  main->addLayout(btns);
88  btns->addStretch(42);
89  btns->addWidget(ok);
90  btns->addWidget(cancel);
91 }
92 
93 void NoteEditor::setFromFieldVisible(bool v)
94 {
95  m_fromLabel->setVisible(v);
96  m_from->setVisible(v);
97 }
98 
99 Note NoteEditor::note()
100 {
101  m_note.content=m_edit->toPlainText();
102  m_note.from=m_from->currentText();
103  return m_note;
104 }
105 
106 void NoteEditor::setNote(const Note& note, int idx)
107 {
108  m_note=note;
109  m_edit->setPlainText(note.content);
110  QString from=note.from;
111  if (from.isEmpty()) from=Settings::authorName();
112  m_from->setCurrentItem(from,/*insert*/true);
113  m_idx=idx;
114  m_edit->setFocus();
115 }
116 
117 void NoteEditor::setNoteAuthors(const QStringList& authors)
118 {
119  m_authors->setStringList(authors);
120  m_from->completionObject()->insertItems(authors);
121 }
122 
123 
124 int displayNotes(KTextBrowser* browser, const QVector<Note>& notes, int active, bool multiple)
125 {
126  QTextCursor t=browser->textCursor();
127  t.movePosition(QTextCursor::End);
128  int realOffset=0;
129 
130  if (!notes.isEmpty())
131  {
132  t.insertHtml(i18nc("@info XLIFF notes representation","<b>Notes:</b>")+"<br />");
133  int i=0;
134  foreach(const Note& note, notes)
135  {
136  if (!note.from.isEmpty())
137  t.insertHtml("<i>"+note.from+":</i> ");
138 
139  if (i==active)
140  realOffset=t.position();
141  QString content=Qt::escape(note.content);
142  if (!multiple && content.contains('\n')) content+='\n';
143  content.replace('\n',"<br />");
144  content+=QString(" (<a href=\"note:/%1\">").arg(i)+i18nc("link to edit note","edit...")+"</a>)<br />";
145  t.insertHtml(content);
146  i++;
147  }
148  if (multiple)
149  t.insertHtml("<a href=\"note:/add\">"+i18nc("link to add a note","Add...")+"</a> ");
150  }
151  else
152  browser->insertHtml("<a href=\"note:/add\">"+i18nc("link to add a note","Add a note...")+"</a> ");
153 
154  return realOffset;
155 }
156 
157 #include "noteeditor.moc"
QTextCursor::position
int position() const
QWidget
QKeyEvent::modifiers
Qt::KeyboardModifiers modifiers() const
NoteEditor::rejected
void rejected()
QTextCursor
QTextCursor::insertHtml
void insertHtml(const QString &html)
main
int main(int argc, char **argv)
Definition: main.cpp:58
QWidget::setVisible
virtual void setVisible(bool visible)
Note
Definition: note.h:29
QHBoxLayout
cmd.h
QTextCursor::movePosition
bool movePosition(MoveOperation operation, MoveMode mode, int n)
Settings::authorName
static QString authorName()
Get authorName.
Definition: prefs_lokalize.h:25
QBoxLayout::addWidget
void addWidget(QWidget *widget, int stretch, QFlags< Qt::AlignmentFlag > alignment)
TextEdit::accepted
void accepted()
content
static QString content(QDomElement elem, ContentEditingData *data=0)
walks through XLIFF XML and performs actions depending on ContentEditingData:
Definition: tsstorage.cpp:170
QWidget::setFocus
void setFocus()
catalog.h
QString::isEmpty
bool isEmpty() const
NoteEditor::NoteEditor
NoteEditor(QWidget *parent)
Definition: noteeditor.cpp:55
QVBoxLayout
QString
QStringListModel
QPlainTextEdit::keyPressEvent
virtual void keyPressEvent(QKeyEvent *e)
QStringList
QKeyEvent::key
int key() const
QString::contains
bool contains(QChar ch, Qt::CaseSensitivity cs) const
KTextBrowser
displayNotes
int displayNotes(KTextBrowser *browser, const QVector< Note > &notes, int active, bool multiple)
Definition: noteeditor.cpp:124
NoteEditor::accepted
void accepted()
Note::content
QString content
Definition: note.h:33
QString::replace
QString & replace(int position, int n, QChar after)
QKeyEvent
QVector
prefs_lokalize.h
QBoxLayout::addStretch
void addStretch(int stretch)
Qt::escape
QString escape(const QString &plain)
QVector::isEmpty
bool isEmpty() const
NoteEditor::setNoteAuthors
void setNoteAuthors(const QStringList &)
Definition: noteeditor.cpp:117
TextEdit::keyPressEvent
void keyPressEvent(QKeyEvent *e)
Definition: noteeditor.cpp:44
NoteEditor::setFromFieldVisible
void setFromFieldVisible(bool)
Definition: noteeditor.cpp:93
NoteEditor::note
Note note()
Definition: noteeditor.cpp:99
TextEdit::rejected
void rejected()
Note::from
QString from
Definition: note.h:36
QWidget::setToolTip
void setToolTip(const QString &)
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QPlainTextEdit::toPlainText
QString toPlainText() const
NoteEditor::setNote
void setNote(const Note &, int idx)
Definition: noteeditor.cpp:106
noteeditor.h
QLabel
QString::arg
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
QStringListModel::setStringList
void setStringList(const QStringList &strings)
TextEdit
Definition: noteeditor.h:67
QBoxLayout::addLayout
void addLayout(QLayout *layout, int stretch)
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:40:07 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

lokalize

Skip menu "lokalize"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdesdk API Reference

Skip menu "kdesdk API Reference"
  • kapptemplate
  • kcachegrind
  • kompare
  • lokalize
  • umbrello
  •   umbrello

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal