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

lokalize

glossaryview.cpp

Go to the documentation of this file.
00001 /* ****************************************************************************
00002   This file is part of KAider
00003 
00004   Copyright (C) 2007 by Nick Shaforostoff <shafff@ukr.net>
00005 
00006   This program is free software; you can redistribute it and/or modify
00007   it under the terms of the GNU General Public License as published by
00008   the Free Software Foundation; either version 2 of the License, or
00009   (at your option) any later version.
00010 
00011   This program is distributed in the hope that it will be useful,
00012   but WITHOUT ANY WARRANTY; without even the implied warranty of
00013   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014   GNU General Public License for more details.
00015 
00016   You should have received a copy of the GNU General Public License
00017   along with this program; if not, write to the Free Software
00018   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00019 
00020   In addition, as a special exception, the copyright holders give
00021   permission to link the code of this program with any edition of
00022   the Qt library by Trolltech AS, Norway (or with modified versions
00023   of Qt that use the same license as Qt), and distribute linked
00024   combinations including the two.  You must obey the GNU General
00025   Public License in all respects for all of the code used other than
00026   Qt. If you modify this file, you may extend this exception to
00027   your version of the file, but you are not obligated to do so.  If
00028   you do not wish to do so, delete this exception statement from
00029   your version.
00030 
00031 **************************************************************************** */
00032 
00033 #include "glossaryview.h"
00034 #include "glossary.h"
00035 #include "project.h"
00036 #include "catalog.h"
00037 #include "flowlayout.h"
00038 
00039 #include "glossarywindow.h"
00040 
00041 
00042 #include <klineedit.h>
00043 #include <kdialog.h>
00044 #include <klocale.h>
00045 #include <kdebug.h>
00046 #include <kurl.h>
00047 #include <kaction.h>
00048 
00049 #include <QDragEnterEvent>
00050 #include <QTime>
00051 #include <QSet>
00052 #include <QScrollArea>
00053 // #include <QShortcutEvent>
00054 
00055 
00056 using namespace GlossaryNS;
00057 
00058 GlossaryView::GlossaryView(QWidget* parent,Catalog* catalog,const QVector<KAction*>& actions)
00059         : QDockWidget ( i18nc("@title:window","Glossary"), parent)
00060         , m_browser(new QScrollArea(this))
00061         , m_catalog(catalog)
00062         , m_flowLayout(new FlowLayout(FlowLayout::glossary,m_browser,this,actions,0,10))
00063         , m_glossary(Project::instance()->glossary())
00064         , m_rxClean(Project::instance()->markup()+'|'+Project::instance()->accel())//cleaning regexp; NOTE isEmpty()?
00065         , m_rxSplit("\\W|\\d")//splitting regexp
00066         , m_currentIndex(-1)
00067         , m_normTitle(i18nc("@title:window","Glossary"))
00068         , m_hasInfoTitle(m_normTitle+" [*]")
00069         , m_hasInfo(false)
00070 
00071 {
00072     setObjectName("glossaryView");
00073     setWidget(m_browser);
00074     QWidget* w=new QWidget(m_browser);
00075     m_browser->setWidget(w);
00076     w->setLayout(m_flowLayout);
00077     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>)."));
00078 
00079     m_browser->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
00080     m_browser->setAutoFillBackground(true);
00081     m_browser->setBackgroundRole(QPalette::Background);
00082 
00083     m_rxClean.setMinimal(true);
00084     connect (m_glossary,SIGNAL(changed()),this,SLOT(slotNewEntryDisplayed()));
00085 }
00086 
00087 GlossaryView::~GlossaryView()
00088 {
00089 }
00090 
00091 
00092 //TODO define new term by dragging some text.
00093 // void GlossaryView::dragEnterEvent(QDragEnterEvent* event)
00094 // {
00095 //     /*    if(event->mimeData()->hasUrls() && event->mimeData()->urls().first().path().endsWith(".po"))
00096 //         {
00097 //             event->acceptProposedAction();
00098 //         };*/
00099 // }
00100 // 
00101 // void GlossaryView::dropEvent(QDropEvent *event)
00102 // {
00103 //         event->acceptProposedAction();*/
00104 // }
00105 
00106 void GlossaryView::slotNewEntryDisplayed(DocPosition pos)
00107 {
00108     //kWarning()<<"\n\n\n\nstart"<<pos.entry<<m_currentIndex;
00109     QTime time;time.start();
00110     if (pos.entry==-1)
00111         pos.entry=m_currentIndex;
00112     else
00113         m_currentIndex=pos.entry;
00114 
00115     if (pos.entry==-1 || m_catalog->numberOfEntries()<=pos.entry)
00116         return;//because of Qt::QueuedConnection
00117     //kWarning()<<"m_catalog->numberOfEntries()"<<m_catalog->numberOfEntries()<<entry;
00118 //     if (!toggleViewAction()->isChecked())
00119 //         return;
00120 
00121     Glossary& glossary=*m_glossary;
00122 
00123 
00124 
00125     QString msg(m_catalog->source(pos).toLower());
00126     msg.remove(m_rxClean);
00127 
00128 //     QRegExp accel(Project::instance()->accel());
00129 //     kWarning()<<endl<<endl<<"valvalvalvalval " <<Project::instance()->accel()<<endl;
00130 //     int pos=0;
00131 //     while ((pos=accel.indexIn(msg,pos))!=-1)
00132 //     {
00133 //         msg.remove(accel.pos(1),accel.cap(1).size());
00134 //         pos=accel.pos(1);
00135 //     }
00136 
00137     QStringList words(msg.split(m_rxSplit,QString::SkipEmptyParts));
00138     if (words.isEmpty())
00139     {
00140         if (m_hasInfo)
00141         {
00142             m_flowLayout->clearTerms();
00143             m_hasInfo=false;
00144             setWindowTitle(m_normTitle);
00145         }
00146         return;
00147     }
00148 
00149     QList<int> termIndexes;
00150     int i=0;
00151     for (;i<words.size();++i)
00152     {
00153         if (glossary.wordHash.contains(words.at(i))
00154 //             && MULTI hash!! instead, we generate QSet later
00155 //             !termIndexes.contains(glossary.wordHash.value(words.at(i)))
00156            )
00157         {
00158 //             kWarning()<<"val " <<glossary.wordHash.values(words.at(i));
00159             termIndexes+=glossary.wordHash.values(words.at(i));
00160         }
00161     }
00162     if (termIndexes.isEmpty())
00163     {
00164         if (m_hasInfo)
00165         {
00166             m_flowLayout->clearTerms();
00167             m_hasInfo=false;
00168             setWindowTitle(m_normTitle);
00169         }
00170         return;
00171     }
00172     // we found entries that contain words from msgid
00173     setUpdatesEnabled(false);
00174 
00175     if (m_hasInfo)
00176         m_flowLayout->clearTerms();
00177 
00178     bool found=false;
00179     m_flowLayout->setEnabled(false);
00180     int j; //INTJ haha! socionics!
00181     QSet<int> termIndexesSet(termIndexes.toSet());
00182 //     kWarning()<<"found";
00183     QSet<int>::const_iterator it = termIndexesSet.constBegin();
00184     kDebug()<<"2";
00185     while (it != termIndexesSet.constEnd())
00186     {
00187         // now check which of them are really hits...
00188         int lim=glossary.termList.at(*it).english.size();
00189         for (j=0;j<lim;++j)
00190         {
00191             // ...and if so, which part of termEn list we must thank for match ...
00192             if (msg.contains(
00193                 glossary.termList.at(*it).english.at(j)//,
00194                 //Qt::CaseInsensitive  //we lowered terms on load 
00195                         )
00196                 )
00197             {
00198                 //insert it into label
00199                 found=true;
00200                 m_flowLayout->addTerm(
00201                         glossary.termList.at(*it).english.at(j),
00202                         *it
00203                                );
00204                 break;
00205             }
00206         }
00207         ++it;
00208     }
00209     m_flowLayout->setEnabled(true);
00210 
00211     if (found)
00212     {
00213         if (!m_hasInfo)
00214         {
00215             m_hasInfo=true;
00216             setWindowTitle(m_hasInfoTitle);
00217         }
00218     }
00219     else if (m_hasInfo)
00220     {
00221         m_hasInfo=true;
00222         setWindowTitle(m_hasInfoTitle);
00223     }
00224 
00225     setUpdatesEnabled(true);
00226     kWarning()<<"ELA "<<time.elapsed();
00227 }
00228 
00229 
00230 
00231 #include "glossaryview.moc"

lokalize

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

kdesdk

Skip menu "kdesdk"
  • kapptemplate
  • kate
  •     kate
  • kbugbuster
  • kcachegrind
  • kompare
  • lokalize
  • umbrello
  •   umbrello
Generated for kdesdk by doxygen 1.5.7
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal