Skip to content

Commit

Permalink
Implement raw command for the Qt interface
Browse files Browse the repository at this point in the history
  • Loading branch information
kovzol committed Feb 26, 2024
1 parent c6c1252 commit 9acc52a
Showing 1 changed file with 32 additions and 12 deletions.
44 changes: 32 additions & 12 deletions qt/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,37 @@ void MainWindow::lookup2()

void MainWindow::raw()
{
QInputDialog inputDialog(this);
inputDialog.setWindowTitle(tr("Raw"));
inputDialog.setLabelText(tr("Parameters:"));
inputDialog.setTextValue(rawText.c_str());
if (inputDialog.exec() != QDialog::Accepted)
return;
const QString value = inputDialog.textValue().trimmed();
if (value.isEmpty())
return;
rawText = value.toStdString();
string rest = rawText;

// Mostly taken from cli:
vector<string> tokens;
boost::split(tokens, rest, boost::is_any_of(" "));
int restSize = tokens.size();
if (restSize == 4) { // e.g. raw LXX Genesis 1 10
string module = tokens[0]; // LXX
string book = tokens[1]; // Genesis
int startPos = stoi(tokens[2]); // 1
int length = stoi(tokens[3]); // 10
string text = getRaw(module, book, startPos - 1, length);
passageInfos->append(("<b>Raw " + rest + "</b>" + "<br>" + text).c_str());

QTextCursor tc = passageInfos->textCursor();
tc.setPosition(passageInfos->document()->characterCount() - 1);
passageInfos->setTextCursor(tc); // Move cursor to the end.
} else {
QString message = "Wrong amount of parameters.";
statusBar()->showMessage(message);
}
}

void MainWindow::rawN(int index)
Expand Down Expand Up @@ -373,9 +403,6 @@ void MainWindow::raw2()
this->rawN(1);
}




QStringList getModuleNames()
{
QStringList items;
Expand Down Expand Up @@ -448,14 +475,6 @@ void MainWindow::findN(int index)
inputDialog.setLabelText("Select a Bible edition:");
inputDialog.setFixedSize(60,3);

/*
* Alternative way for selection: typing.
QInputDialog inputDialog(this);
inputDialog.setWindowTitle(tr("Find " + QString::number(index + 1)));
inputDialog.setLabelText(tr("Bible edition:"));
inputDialog.setTextValue(findText.c_str());
*/

if (inputDialog.exec() != QDialog::Accepted)
return;
const QString value = inputDialog.textValue().trimmed();
Expand Down Expand Up @@ -716,14 +735,15 @@ void MainWindow::createActions()
rawAct = new QAction(tr("&Raw…"), this);
rawAct->setStatusTip(tr("Show the a-y transcription of a positioned text in a given book"));
connect(rawAct, &QAction::triggered, this, &MainWindow::raw);
rawAct->setDisabled(true);

raw1Act = new QAction(tr("Raw &1…"), this);
raw1Act->setStatusTip(tr("Put the a-y transcription of a positioned text in a given book in clipboard 1"));
connect(raw1Act, &QAction::triggered, this, &MainWindow::raw1);
raw1Act->setDisabled(true);

raw2Act = new QAction(tr("Raw &2…"), this);
raw2Act->setStatusTip(tr("Put the a-y transcription of a positioned text in a given book in clipboard 1"));
raw2Act->setStatusTip(tr("Put the a-y transcription of a positioned text in a given book in clipboard 2"));
connect(raw2Act, &QAction::triggered, this, &MainWindow::raw2);
raw2Act->setDisabled(true);

Expand Down

0 comments on commit 9acc52a

Please sign in to comment.