• 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
  • webquery
webqueryview.cpp
Go to the documentation of this file.
1 /* ****************************************************************************
2  This file is part of KAider
3 
4  Copyright (C) 2007 by Nick Shaforostoff <shafff@ukr.net>
5 
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.
10 
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.
15 
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.
19 
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
29  your version.
30 
31 **************************************************************************** */
32 
33 #include "webqueryview.h"
34 #include "project.h"
35 #include "catalog.h"
36 #include "flowlayout.h"
37 
38 #include "ui_querycontrol.h"
39 
40 #include <kross/ui/view.h>
41 #include <kross/ui/model.h>
42 #include <kross/core/actioncollection.h>
43 #include <kross/core/manager.h>
44 
45 #include "webquerycontroller.h"
46 
47 #include <klocale.h>
48 #include <kdebug.h>
49 #include <kurl.h>
50 #include <ktextbrowser.h>
51 #include <kaction.h>
52 
53 #include <QDragEnterEvent>
54 #include <QTime>
55 #include <QSplitter>
56 #include <QSignalMapper>
57 #include <QTimer>
58 
59 // #include <QShortcutEvent>
60 #include "myactioncollectionview.h"
61 
62 using namespace Kross;
63 
64 WebQueryView::WebQueryView(QWidget* parent,Catalog* catalog,const QVector<KAction*>& actions)
65  : QDockWidget ( i18n("Web Queries"), parent)
66  , m_catalog(catalog)
67  , m_splitter(new QSplitter(this))
68  , m_browser(new KTextBrowser(m_splitter))
69  , ui_queryControl(new Ui_QueryControl)
70  , m_actions(actions)
71 
72 {
73  setObjectName("WebQueryView");
74  setWidget(m_splitter);
75 
76  hide();
77 
78  m_browser->viewport()->setBackgroundRole(QPalette::Background);
79 
80  m_browser->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
81  QWidget* w=new QWidget(m_splitter);
82  ui_queryControl->setupUi(w);
83 
84  QTimer::singleShot(0,this,SLOT(initLater()));
85 }
86 
87 WebQueryView::~WebQueryView()
88 {
89  delete ui_queryControl;
90 // delete m_flowLayout;
91 }
92 
93 void WebQueryView::initLater()
94 {
95  connect(ui_queryControl->queryBtn,SIGNAL(clicked()),ui_queryControl->actionzView,SLOT(triggerSelectedActions()));
96 
97 // connect(this,SIGNAL(addWebQueryResult(const QString&)),m_flowLayout,SLOT(addWebQueryResult(const QString&)));
98 // ActionCollectionModel::Mode mode(
99 // ActionCollectionModel::Icons
100 // | ActionCollectionModel::ToolTips | ActionCollectionModel::UserCheckable );*/
101  ActionCollectionModel* m = new ActionCollectionModel(ui_queryControl->actionzView, Manager::self().actionCollection()/*, mode*/);
102  ui_queryControl->actionzView->setModel(m);
103 // m_boxLayout->addWidget(w);
104  ui_queryControl->actionzView->data.webQueryView=this;
105 
106 
107  m_browser->setToolTip(i18nc("@info:tooltip","Double-click any word to insert it into translation"));
108 
109 
110  QSignalMapper* signalMapper=new QSignalMapper(this);
111  int i=m_actions.size();
112  while(--i>=0)
113  {
114  connect(m_actions.at(i),SIGNAL(triggered()),signalMapper,SLOT(map()));
115  signalMapper->setMapping(m_actions.at(i), i);
116  }
117  connect(signalMapper, SIGNAL(mapped(int)),
118  this, SLOT(slotUseSuggestion(int)));
119  connect(m_browser,SIGNAL(selectionChanged()),this,SLOT(slotSelectionChanged()));
120 
121 }
122 
123 void WebQueryView::slotSelectionChanged()
124 {
125  //NOTE works fine only for dbl-click word selection
126  //(actually, quick word insertion is exactly the purpose of this slot:)
127  QString sel(m_browser->textCursor().selectedText());
128  if (!sel.isEmpty())
129  {
130  emit textInsertRequested(sel);
131  }
132 }
133 
134 //TODO text may be dragged
135 // void WebQueryView::dragEnterEvent(QDragEnterEvent* event)
136 // {
137 // /* if(event->mimeData()->hasUrls() && event->mimeData()->urls().first().path().endsWith(".po"))
138 // {
139 // //kWarning() << " " <<;
140 // event->acceptProposedAction();
141 // };*/
142 // }
143 //
144 // void WebQueryView::dropEvent(QDropEvent *event)
145 // {
146 // /* emit mergeOpenRequested(KUrl(event->mimeData()->urls().first()));
147 // event->acceptProposedAction();*/
148 // }
149 
150 void WebQueryView::slotNewEntryDisplayed(const DocPosition& pos)
151 {
152  //m_flowLayout->clearWebQueryResult();
153  m_browser->clear();
154  m_suggestions.clear();
155 
156  ui_queryControl->actionzView->data.msg=m_catalog->msgid(pos);
157  //TODO pass DocPosition also, as tmview does
158 
159  if (ui_queryControl->autoQuery->isChecked())
160  ui_queryControl->actionzView->triggerSelectedActions();
161 }
162 
163 void WebQueryView::slotUseSuggestion(int i)
164 {
165  if (i>=m_suggestions.size())
166  return;
167  emit textInsertRequested(m_suggestions.at(i));
168 }
169 
170 
171 void WebQueryView::addWebQueryResult(const QString& name,const QString& str)
172 {
173  QString html(str);
174  html.replace('<',"&lt;");
175  html.replace('>',"&gt;");
176  html.append(QString("<br><br>"));
177  html.prepend(QString("[%2] /%1/ ").arg(name).arg(
178  (m_suggestions.size()<m_actions.size())?
179  m_actions.at(m_suggestions.size())->shortcut().toString():
180  " - "));
181 
182  m_browser->insertHtml(html);
183  //m_flowLayout->addWebQueryResult(str);
184 
185  m_suggestions.append(str);
186 }
187 
188 #include "webqueryview.moc"
project.h
QWidget
WebQueryView::slotSelectionChanged
void slotSelectionChanged()
Definition: webqueryview.cpp:123
QString::append
QString & append(QChar ch)
WebQueryView::initLater
void initLater()
Definition: webqueryview.cpp:93
QVector::append
void append(const T &value)
WebQueryView::slotNewEntryDisplayed
void slotNewEntryDisplayed(const DocPosition &)
Definition: webqueryview.cpp:150
QDockWidget
myactioncollectionview.h
QString::prepend
QString & prepend(QChar ch)
WebQueryView::~WebQueryView
virtual ~WebQueryView()
Definition: webqueryview.cpp:87
webqueryview.h
DocPosition
This struct represents a position in a catalog.
Definition: pos.h:38
QVector::clear
void clear()
QSignalMapper::setMapping
void setMapping(QObject *sender, int id)
catalog.h
QObject::setObjectName
void setObjectName(const QString &name)
QString
QWidget::hide
void hide()
WebQueryView::slotUseSuggestion
void slotUseSuggestion(int i)
Definition: webqueryview.cpp:163
KTextBrowser
QDockWidget::setWidget
void setWidget(QWidget *widget)
Catalog::msgid
QString msgid(const DocPosition &) const
Definition: catalog.cpp:187
QString::replace
QString & replace(int position, int n, QChar after)
QVector::at
const T & at(int i) const
QSplitter
QVector< KAction * >
WebQueryView::WebQueryView
WebQueryView(QWidget *, Catalog *, const QVector< KAction * > &)
Definition: webqueryview.cpp:64
QWidget::QWidget
QWidget(QWidget *parent, QFlags< Qt::WindowType > f)
webquerycontroller.h
Catalog
This class represents a catalog It uses CatalogStorage interface to work with catalogs in different f...
Definition: catalog.h:74
WebQueryView::addWebQueryResult
void addWebQueryResult(const QString &, const QString &)
Definition: webqueryview.cpp:171
flowlayout.h
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QVector::size
int size() const
QSignalMapper
WebQueryView::textInsertRequested
void textInsertRequested(const QString &)
QTimer::singleShot
singleShot
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