• 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
  • common
termlabel.cpp
Go to the documentation of this file.
1 /* ****************************************************************************
2  This file is part of Lokalize
3 
4  Copyright (C) 2007 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 "termlabel.h"
25 
26 #include "glossarywindow.h"
27 
28 #include <klineedit.h>
29 #include <kdialog.h>
30 
31 #include <kdebug.h>
32 #include <klocale.h>
33 #include <kaction.h>
34 #include <QMenu>
35 #include <QMouseEvent>
36 
37 using namespace GlossaryNS;
38 //#include <QShortcutEvent>
39 
40 
41 // TermLabel::TermLabel(QAction* action/*const QString& shortcutQWidget* parent,Qt::Key key,const QString& termTransl*/)
42 // : m_action(action)
43 // //: m_shortcut(shortcut)
44 // // : QLabel(/*parent*/)
45 // //, m_termTransl(termTransl)
46 // {
47 // // setFlat(true);
48 // // grabShortcut(Qt::ALT+Qt::CTRL+key);
49 // // kWarning() << "dsds " << grabShortcut(Qt::ALT+key);
50 // }
51 // //~TermLabel(){}
52 // // bool TermLabel::event(QEvent *event)
53 // // {
54 // // if (event->type() != QEvent::Shortcut)
55 // // return QLabel::event(event);
56 // //
57 // // // kWarning() << "dsds " << m_termTransl;
58 // // emit insertTerm(m_termTransl);
59 // // return true;
60 // // }
61 
62 void TermLabel::insert()
63 {
64  GlossaryNS::Glossary* glossary=Project::instance()->glossary();
65  if (m_entryId.isEmpty())
66  return;
67  QString termTrans;
68  const QStringList& termTarget=glossary->terms(m_entryId, Project::instance()->targetLangCode());
69  if( termTarget.count()>1)
70  {
71  QMenu menu;
72 
73  int limit=termTarget.count();
74  menu.setActiveAction(menu.addAction(termTarget.at(0)));
75  int i=1;
76  for (;i<limit;++i)
77  menu.addAction(termTarget.at(i));
78 
79  QAction* txt=menu.exec(mapToGlobal(QPoint(0,0)));
80  if (!txt)
81  return;
82  termTrans=txt->text();
83  }
84  else if (termTarget.count() == 1)
85  termTrans=termTarget.first();
86 
87  if (m_capFirst && !termTrans.isEmpty())
88  termTrans[0]=termTrans.at(0).toUpper();
89 
90  emit insertTerm(termTrans);
91 }
92 
93 void TermLabel::mousePressEvent (QMouseEvent* event)
94 {
95  if (event->button()==Qt::RightButton)
96  {
97  QMenu menu;
98 
99  menu.addAction(i18nc("@action:inmenu Edit term","Edit"));
100 
101  QAction* txt=menu.exec(event->globalPos());
102  if (txt)
103  {
104  GlossaryNS::GlossaryWindow* glossaryWindow=Project::instance()->showGlossary();
105  if (glossaryWindow)
106  glossaryWindow->selectEntry(m_entryId);
107  }
108  }
109  else
110  insert();
111 }
112 
113 void TermLabel::setText(const QString& term, const QByteArray& entryId, bool capFirst)
114 {
115  m_entryId=entryId;
116  m_capFirst=capFirst;
117  QLabel::setText(QString(term + QString(m_action?QString(" [" + m_action->shortcut().toString()+"] \n "):" \n ")//m_shortcut
118  + Project::instance()->glossary()->terms(m_entryId, Project::instance()->targetLangCode()).join(" \n ")
119  + " \n "));
120 }
121 
122 
123 #if 0
124 void QueryResultBtn::insert()
125 {
126 // kWarning()<<"ins "<<text();
127  emit insertText(m_text);
128 }
129 
130 QueryResultBtn::QueryResultBtn(QAction* a)
131  : QLabel()
132  , m_action(a)
133 {
134  setWordWrap(true);
135 // kWarning()<<"ctor";
136  //connect(this,SIGNAL(clicked(bool)),this,SLOT(insert()));
137 }
138 
139 void QueryResultBtn::mousePressEvent (QMouseEvent*/* event*/)
140 {
141  emit insertText(m_text);
142 }
143 
144 #endif
145 
146 #include "termlabel.moc"
QAction::text
text
GlossaryNS::GlossaryWindow
Definition: glossarywindow.h:69
QByteArray
QMenu::setActiveAction
void setActiveAction(QAction *act)
QList::at
const T & at(int i) const
Project::instance
static Project * instance()
Definition: project.cpp:67
QMenu::addAction
void addAction(QAction *action)
QByteArray::isEmpty
bool isEmpty() const
QWidget::mapToGlobal
QPoint mapToGlobal(const QPoint &pos) const
term
static const QString term
Definition: glossary.cpp:48
QPoint
QMouseEvent
QStringList::join
QString join(const QString &separator) const
GlossaryNS::TermLabel::insertTerm
void insertTerm(const QString &)
termlabel.h
QList::count
int count(const T &value) const
QMouseEvent::globalPos
const QPoint & globalPos() const
GlossaryNS::Glossary
Internal representation of glossary.
Definition: glossary.h:95
GlossaryNS::TermLabel::insert
void insert()
Definition: termlabel.cpp:62
Project::showGlossary
GlossaryNS::GlossaryWindow * showGlossary()
Definition: project.cpp:206
Project::glossary
GlossaryNS::Glossary * glossary() const
Definition: project.h:73
QMouseEvent::button
Qt::MouseButton button() const
GlossaryNS::TermLabel::mousePressEvent
void mousePressEvent(QMouseEvent *)
Definition: termlabel.cpp:93
glossarywindow.h
QString::isEmpty
bool isEmpty() const
QList::first
T & first()
QLabel::setText
void setText(const QString &)
QString
QMenu::exec
QAction * exec()
QStringList
QMenu
QAction::shortcut
shortcut
GlossaryNS::Glossary::terms
QStringList terms(const QByteArray &id, const QString &lang) const
Definition: glossary.cpp:337
GlossaryNS::TermLabel::setText
void setText(const QString &term, const QByteArray &entryId, bool capFirst)
Definition: termlabel.cpp:113
QChar::toUpper
QChar toUpper() const
QString::at
const QChar at(int position) const
QAction
QLabel
GlossaryNS::GlossaryWindow::selectEntry
void selectEntry(const QByteArray &id)
Definition: glossarywindow.cpp:430
QLabel::setWordWrap
void setWordWrap(bool on)
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