1
/* ****************************************************************************
2
This file is part of KAider
4
Copyright (C) 2007 by Nick Shaforostoff <shafff@ukr.net>
6
This program is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; either version 2 of the License, or
9
(at your option) any later version.
11
This program is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
GNU General Public License for more details.
16
You should have received a copy of the GNU General Public License
17
along with this program; if not, write to the Free Software
18
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20
In addition, as a special exception, the copyright holders give
21
permission to link the code of this program with any edition of
22
the Qt library by Trolltech AS, Norway (or with modified versions
23
of Qt that use the same license as Qt), and distribute linked
24
combinations including the two. You must obey the GNU General
25
Public License in all respects for all of the code used other than
26
Qt. If you modify this file, you may extend this exception to
27
your version of the file, but you are not obligated to do so. If
28
you do not wish to do so, delete this exception statement from
31
**************************************************************************** */
33
#include "glossaryview.h"
37
#include "flowlayout.h"
39
#include "glossarywindow.h"
42
#include <klineedit.h>
48
#include <QDragEnterEvent>
52
// #include <QShortcutEvent>
56
GlossaryView::GlossaryView(QWidget* parent,Catalog* catalog,const QVector<QAction*>& actions)
57
: QDockWidget ( i18nc("@title:window","Glossary"), parent)
58
, m_browser(new QWidget(this))
60
, m_flowLayout(new FlowLayout(FlowLayout::glossary,m_browser,this,actions,0,10))
61
, m_glossary(Project::instance()->glossary())
62
, m_rxClean(Project::instance()->markup()+'|'+Project::instance()->accel())//cleaning regexp; NOTE isEmpty()?
63
, m_rxSplit("\\W|\\d")//splitting regexp
65
, m_normTitle(i18nc("@title:window","Glossary"))
66
, m_hasInfoTitle(m_normTitle+" [*]")
70
setObjectName("glossaryView");
72
m_browser->setLayout(m_flowLayout);
73
setToolTip(i18nc("@info:tooltip","Translations to common terms appear here. Press displayed shortcut to insert term translation. Use context menu to add new entry (tip: select words in original and translation fields before calling <interface>Define new term</interface>)."));
75
m_browser->setAutoFillBackground(true);
76
m_browser->setBackgroundRole(QPalette::Background);
78
m_rxClean.setMinimal(true);
79
connect (m_glossary,SIGNAL(changed()),this,SLOT(slotNewEntryDisplayed()));
82
GlossaryView::~GlossaryView()
87
//TODO define new term by dragging some text.
88
// void GlossaryView::dragEnterEvent(QDragEnterEvent* event)
90
// /* if(event->mimeData()->hasUrls() && event->mimeData()->urls().first().path().endsWith(".po"))
92
// event->acceptProposedAction();
96
// void GlossaryView::dropEvent(QDropEvent *event)
98
// event->acceptProposedAction();*/
101
void GlossaryView::slotNewEntryDisplayed(uint entry)
103
QTime time;time.start();
104
if (entry==0xffffffff)
105
entry=m_currentIndex;
107
m_currentIndex=entry;
109
if (m_catalog->numberOfEntries()<=(int)entry)
110
return;//because of Qt::QueuedConnection
111
//kWarning()<<"m_catalog->numberOfEntries()"<<m_catalog->numberOfEntries()<<entry;
112
// if (!toggleViewAction()->isChecked())
114
Glossary& glossary=*m_glossary;
118
QString msg(m_catalog->msgid(entry).toLower());
119
msg.remove(m_rxClean);
121
// QRegExp accel(Project::instance()->accel());
122
// kWarning()<<endl<<endl<<"valvalvalvalval " <<Project::instance()->accel()<<endl;
124
// while ((pos=accel.indexIn(msg,pos))!=-1)
126
// msg.remove(accel.pos(1),accel.cap(1).size());
130
QStringList words(msg.split(m_rxSplit,QString::SkipEmptyParts));
135
m_flowLayout->clearTerms();
137
setWindowTitle(m_normTitle);
143
QList<int> termIndexes;
145
for (;i<words.size();++i)
147
if (glossary.wordHash.contains(words.at(i))
148
// && MULTI hash!! instead, we generate QSet later
149
// !termIndexes.contains(glossary.wordHash.value(words.at(i)))
152
// kWarning()<<"val " <<glossary.wordHash.values(words.at(i));
153
termIndexes+=glossary.wordHash.values(words.at(i));
156
if (termIndexes.isEmpty())
160
m_flowLayout->clearTerms();
162
setWindowTitle(m_normTitle);
166
// we found entries that contain words from msgid
167
setUpdatesEnabled(false);
170
m_flowLayout->clearTerms();
173
m_flowLayout->setEnabled(false);
174
int j; //INTJ haha! socionics!
175
QSet<int> termIndexesSet(termIndexes.toSet());
176
// kWarning()<<"found";
177
QSet<int>::const_iterator it = termIndexesSet.constBegin();
179
while (it != termIndexesSet.constEnd())
181
// now check which of them are really hits...
182
int lim=glossary.termList.at(*it).english.size();
185
// ...and if so, which part of termEn list we must thank for match ...
187
glossary.termList.at(*it).english.at(j)//,
188
//Qt::CaseInsensitive //we lowered terms on load
192
//insert it into label
194
m_flowLayout->addTerm(
195
glossary.termList.at(*it).english.at(j),
203
m_flowLayout->setEnabled(true);
210
setWindowTitle(m_hasInfoTitle);
216
setWindowTitle(m_hasInfoTitle);
219
setUpdatesEnabled(true);
220
kWarning()<<"ELA "<<time.elapsed();
225
#include "glossaryview.moc"