2019-06-29 08:46:31 +05:30
|
|
|
#include "qtcommon.h"
|
2019-01-22 14:35:34 -05:00
|
|
|
#include "extension.h"
|
|
|
|
#include <QKeyEvent>
|
|
|
|
|
2019-02-27 11:33:17 -05:00
|
|
|
extern const char* THREAD_LINKER;
|
|
|
|
extern const char* LINK;
|
|
|
|
extern const char* THREAD_LINK_FROM;
|
|
|
|
extern const char* THREAD_LINK_TO;
|
2019-06-13 04:01:29 -04:00
|
|
|
extern const char* HEXADECIMAL;
|
2019-02-27 11:33:17 -05:00
|
|
|
|
2019-01-22 14:35:34 -05:00
|
|
|
std::unordered_map<int64_t, std::unordered_multiset<int64_t>> linkedTextHandles;
|
2019-06-21 01:29:48 -04:00
|
|
|
std::shared_mutex m;
|
2019-01-22 14:35:34 -05:00
|
|
|
|
2020-03-16 02:56:04 -06:00
|
|
|
class Window : public QDialog
|
2019-01-22 14:35:34 -05:00
|
|
|
{
|
2019-06-21 01:29:48 -04:00
|
|
|
public:
|
|
|
|
Window()
|
2020-03-16 02:56:04 -06:00
|
|
|
: QDialog(nullptr, Qt::WindowMinMaxButtonsHint)
|
2019-01-22 14:35:34 -05:00
|
|
|
{
|
2021-01-15 06:07:23 -07:00
|
|
|
Localize();
|
2019-06-21 01:29:48 -04:00
|
|
|
connect(&linkButton, &QPushButton::clicked, this, &Window::Link);
|
2019-01-22 14:35:34 -05:00
|
|
|
|
2019-06-21 01:29:48 -04:00
|
|
|
layout.addWidget(&linkList);
|
|
|
|
layout.addWidget(&linkButton);
|
2019-01-22 14:35:34 -05:00
|
|
|
|
|
|
|
setWindowTitle(THREAD_LINKER);
|
2019-06-21 01:29:48 -04:00
|
|
|
QMetaObject::invokeMethod(this, &QWidget::show, Qt::QueuedConnection);
|
2019-01-22 14:35:34 -05:00
|
|
|
}
|
|
|
|
|
2019-06-21 01:29:48 -04:00
|
|
|
private:
|
|
|
|
void Link()
|
2019-01-22 14:35:34 -05:00
|
|
|
{
|
2019-06-21 01:29:48 -04:00
|
|
|
bool ok1, ok2, ok3, ok4;
|
|
|
|
int from = QInputDialog::getText(this, THREAD_LINK_FROM, HEXADECIMAL, QLineEdit::Normal, "", &ok1, Qt::WindowCloseButtonHint).toInt(&ok2, 16);
|
|
|
|
int to = QInputDialog::getText(this, THREAD_LINK_TO, HEXADECIMAL, QLineEdit::Normal, "", &ok3, Qt::WindowCloseButtonHint).toInt(&ok4, 16);
|
|
|
|
if (ok1 && ok2 && ok3 && ok4)
|
2019-01-22 14:35:34 -05:00
|
|
|
{
|
2021-01-15 06:07:23 -07:00
|
|
|
std::scoped_lock lock(m);
|
2019-06-21 01:29:48 -04:00
|
|
|
linkedTextHandles[from].insert(to);
|
|
|
|
linkList.addItem(QString::number(from, 16) + "->" + QString::number(to, 16));
|
|
|
|
}
|
2019-01-22 14:35:34 -05:00
|
|
|
}
|
2019-06-21 01:29:48 -04:00
|
|
|
|
|
|
|
void keyPressEvent(QKeyEvent* event) override
|
2019-01-22 14:35:34 -05:00
|
|
|
{
|
2019-06-21 01:29:48 -04:00
|
|
|
if (event->key() == Qt::Key_Delete && linkList.currentItem())
|
2019-01-22 14:35:34 -05:00
|
|
|
{
|
2019-06-21 01:29:48 -04:00
|
|
|
QStringList link = linkList.currentItem()->text().split("->");
|
|
|
|
linkList.takeItem(linkList.currentRow());
|
2021-01-15 06:07:23 -07:00
|
|
|
std::scoped_lock lock(m);
|
2019-06-21 01:29:48 -04:00
|
|
|
linkedTextHandles[link[0].toInt(nullptr, 16)].erase(link[1].toInt(nullptr, 16));
|
2019-01-22 14:35:34 -05:00
|
|
|
}
|
|
|
|
}
|
2019-06-21 01:29:48 -04:00
|
|
|
|
2020-03-16 02:56:04 -06:00
|
|
|
QHBoxLayout layout{ this };
|
|
|
|
QListWidget linkList{ this };
|
|
|
|
QPushButton linkButton{ LINK, this };
|
2019-06-21 01:29:48 -04:00
|
|
|
} window;
|
2019-01-22 14:35:34 -05:00
|
|
|
|
|
|
|
bool ProcessSentence(std::wstring& sentence, SentenceInfo sentenceInfo)
|
|
|
|
{
|
2019-06-21 01:29:48 -04:00
|
|
|
std::shared_lock l(m);
|
2019-06-16 22:57:41 -04:00
|
|
|
int64_t textHandle = sentenceInfo["text number"];
|
2019-01-22 14:35:34 -05:00
|
|
|
|
2019-06-16 22:57:41 -04:00
|
|
|
for (auto linkedHandle : linkedTextHandles[textHandle])
|
2020-04-25 20:34:53 -06:00
|
|
|
((void(*)(int64_t, const wchar_t*))sentenceInfo["void (*AddText)(int64_t number, const wchar_t* text)"])(linkedHandle, sentence.c_str());
|
2019-01-22 14:35:34 -05:00
|
|
|
|
2019-06-16 22:57:41 -04:00
|
|
|
return false;
|
2019-01-22 14:35:34 -05:00
|
|
|
}
|