Changeset View
Changeset View
Standalone View
Standalone View
src/tm/tmview.cpp
Show All 40 Lines | |||||
41 | #include <kpassivepopup.h> | 41 | #include <kpassivepopup.h> | ||
42 | 42 | | |||
43 | #include <QTime> | 43 | #include <QTime> | ||
44 | #include <QDragEnterEvent> | 44 | #include <QDragEnterEvent> | ||
45 | #include <QMimeData> | 45 | #include <QMimeData> | ||
46 | #include <QFileInfo> | 46 | #include <QFileInfo> | ||
47 | #include <QFile> | 47 | #include <QFile> | ||
48 | #include <QDir> | 48 | #include <QDir> | ||
49 | #include <QSignalMapper> | | |||
50 | #include <QTimer> | 49 | #include <QTimer> | ||
51 | #include <QToolTip> | 50 | #include <QToolTip> | ||
52 | #include <QMenu> | 51 | #include <QMenu> | ||
53 | #include <QStringBuilder> | 52 | #include <QStringBuilder> | ||
54 | 53 | | |||
55 | #ifdef NDEBUG | 54 | #ifdef NDEBUG | ||
56 | #undef NDEBUG | 55 | #undef NDEBUG | ||
57 | #endif | 56 | #endif | ||
▲ Show 20 Lines • Show All 106 Lines • ▼ Show 20 Line(s) | 162 | while (--i >= 0) | |||
164 | TM::threadPool()->cancel(m_jobs.at(i)); | 163 | TM::threadPool()->cancel(m_jobs.at(i)); | ||
165 | #endif | 164 | #endif | ||
166 | } | 165 | } | ||
167 | 166 | | |||
168 | void TMView::initLater() | 167 | void TMView::initLater() | ||
169 | { | 168 | { | ||
170 | setAcceptDrops(true); | 169 | setAcceptDrops(true); | ||
171 | 170 | | |||
172 | QSignalMapper* signalMapper_insert = new QSignalMapper(this); | | |||
173 | QSignalMapper* signalMapper_remove = new QSignalMapper(this); | | |||
174 | int i = m_actions_insert.size(); | 171 | int i = m_actions_insert.size(); | ||
175 | while (--i >= 0) { | 172 | while (--i >= 0) { | ||
176 | connect(m_actions_insert.at(i), &QAction::triggered, signalMapper_insert, QOverload<>::of(&QSignalMapper::map)); | 173 | connect(m_actions_insert.at(i), &QAction::triggered, this, [this, i] { slotUseSuggestion(i); }); | ||
177 | signalMapper_insert->setMapping(m_actions_insert.at(i), i); | | |||
178 | } | 174 | } | ||
179 | 175 | | |||
180 | i = m_actions_remove.size(); | 176 | i = m_actions_remove.size(); | ||
181 | while (--i >= 0) { | 177 | while (--i >= 0) { | ||
182 | connect(m_actions_remove.at(i), &QAction::triggered, signalMapper_remove, QOverload<>::of(&QSignalMapper::map)); | 178 | connect(m_actions_remove.at(i), &QAction::triggered, this, [this, i] { slotRemoveSuggestion(i); }); | ||
183 | signalMapper_remove->setMapping(m_actions_remove.at(i), i); | | |||
184 | } | 179 | } | ||
185 | connect(signalMapper_insert, QOverload<int>::of(&QSignalMapper::mapped), this, &TMView::slotUseSuggestion); | | |||
186 | connect(signalMapper_remove, QOverload<int>::of(&QSignalMapper::mapped), this, &TMView::slotRemoveSuggestion); | | |||
187 | 180 | | |||
188 | setToolTip(i18nc("@info:tooltip", "Double-click any word to insert it into translation")); | 181 | setToolTip(i18nc("@info:tooltip", "Double-click any word to insert it into translation")); | ||
189 | 182 | | |||
190 | DBFilesModel::instance(); | 183 | DBFilesModel::instance(); | ||
191 | 184 | | |||
192 | connect(m_browser, &TM::TextBrowser::textInsertRequested, this, &TMView::textInsertRequested); | 185 | connect(m_browser, &TM::TextBrowser::textInsertRequested, this, &TMView::textInsertRequested); | ||
193 | connect(m_browser, &TM::TextBrowser::customContextMenuRequested, this, &TMView::contextMenu); | 186 | connect(m_browser, &TM::TextBrowser::customContextMenuRequested, this, &TMView::contextMenu); | ||
194 | //TODO ? kdisplayPaletteChanged | 187 | //TODO ? kdisplayPaletteChanged | ||
▲ Show 20 Lines • Show All 209 Lines • ▼ Show 20 Line(s) | 385 | { | |||
404 | 397 | | |||
405 | 398 | | |||
406 | //BEGIN query other DBs handling | 399 | //BEGIN query other DBs handling | ||
407 | Project* project = Project::instance(); | 400 | Project* project = Project::instance(); | ||
408 | const QString& projectID = project->projectID(); | 401 | const QString& projectID = project->projectID(); | ||
409 | //check if this is an additional query, from secondary DBs | 402 | //check if this is an additional query, from secondary DBs | ||
410 | if (job.m_dbName != projectID) { | 403 | if (job.m_dbName != projectID) { | ||
411 | job.m_entries += m_entries; | 404 | job.m_entries += m_entries; | ||
412 | qSort(job.m_entries.begin(), job.m_entries.end(), qGreater<TMEntry>()); | 405 | std::sort(job.m_entries.begin(), job.m_entries.end(), qGreater<TMEntry>()); | ||
413 | const int limit = qMin(Settings::suggCount(), job.m_entries.size()); | 406 | const int limit = qMin(Settings::suggCount(), job.m_entries.size()); | ||
414 | const int minScore = Settings::suggScore() * 100; | 407 | const int minScore = Settings::suggScore() * 100; | ||
415 | int i = job.m_entries.size() - 1; | 408 | int i = job.m_entries.size() - 1; | ||
416 | while (i >= 0 && (i >= limit || job.m_entries.last().score < minScore)) { | 409 | while (i >= 0 && (i >= limit || job.m_entries.last().score < minScore)) { | ||
417 | job.m_entries.removeLast(); | 410 | job.m_entries.removeLast(); | ||
418 | i--; | 411 | i--; | ||
419 | } | 412 | } | ||
420 | } else if (job.m_entries.isEmpty() || job.m_entries.first().score < 8500) { | 413 | } else if (job.m_entries.isEmpty() || job.m_entries.first().score < 8500) { | ||
▲ Show 20 Lines • Show All 609 Lines • Show Last 20 Lines |