Skip to content

Commit

Permalink
minMode complete feature
Browse files Browse the repository at this point in the history
  • Loading branch information
wanhuz committed May 11, 2021
1 parent 03b96f6 commit bd0ccca
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 23 deletions.
6 changes: 1 addition & 5 deletions src/capturekey/maincontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
#include "../settings/config.h"





MainController::MainController() {
DictLoader* dictloader = new DictLoader();
dict = new Dict();
Expand All @@ -25,7 +22,6 @@ MainController::MainController() {
dictloader->setDict(dict);
dictloader->start();


connect(capturekeypress, SIGNAL(OCRkeyStateChanged()), this, SLOT(captureOCR()));
connect(capturekeypress, SIGNAL(TextkeyStateChanged()), this, SLOT(captureTextGeneric()));
}
Expand Down Expand Up @@ -80,7 +76,7 @@ void MainController::captureOCR() {
Pix *pix = Util::qPixMap2PIX(&screenshot);
QString text = ocr->recognize(pix);

//DUMB WORD PROCESSING TO REMOVE SPACE GET CORRECT RESULT, MAKE PROPER FUNCTION LATER
//Dumb word processing to only remove space get correct result, make proper processing function later
text = text.simplified();
text = text.replace(" ", "");

Expand Down
11 changes: 3 additions & 8 deletions src/ui/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ MainWindow::MainWindow(QWidget* parent)
QAction* frameVert = ui.actionVertical;
QAction* frameHort = ui.actionHorizontal;
QAction* settingsWindow = ui.Settings;

//This is not supposed to be at this class, but it is easier than refactoring everything
MainControl = new MainController();

QString fontPath = QDir::currentPath();
Expand All @@ -43,7 +45,6 @@ MainWindow::MainWindow(QWidget* parent)
int id = QFontDatabase::addApplicationFont(fontPath);

if (id < 0) {
qDebug() << "Failed to load Sans Mono JK font at " << fontPath;
QMessageBox err;
err.setText("Failed to load Sans Mono JK font at " + fontPath);
err.setIcon(QMessageBox::Warning);
Expand All @@ -56,7 +57,6 @@ MainWindow::MainWindow(QWidget* parent)


//UI customization

QStringList labels;
labels.insert(0, QString("Kanji"));
labels.insert(1, QString("Kana"));
Expand Down Expand Up @@ -106,7 +106,7 @@ MainWindow::MainWindow(QWidget* parent)
connect(textbox, SIGNAL(textChanged(QString)), this, SLOT(search()));
}


//Search from user-given string and display it either in normal mode or minimal mode, result are limited to 100 entry.
void MainWindow::search() {
dictmodel.clear();
QString searchText = textbox->text();
Expand Down Expand Up @@ -162,11 +162,8 @@ void MainWindow::search() {
}

minUi->shows();

}



}

//Refresh UI
Expand All @@ -175,8 +172,6 @@ void MainWindow::search() {
labels.insert(1, QString("Kana"));
labels.insert(2, QString("Meaning"));
dictmodel.setHorizontalHeaderLabels(labels);



}

Expand Down
27 changes: 19 additions & 8 deletions src/ui/popup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,17 @@ popup::popup(QWidget* parent)
QBoxLayout* hlayoutbottom = new QHBoxLayout;
QPushButton* btnPrev = new QPushButton("^");
QPushButton* btnNext = new QPushButton("v");
QBoxLayout* vlayout = new QVBoxLayout;

//Set theme
//Init theme
this->setTheme();
vlayout = new QVBoxLayout;

//Set widget properties
this->setWindowFlags(Qt::NoDropShadowWindowHint | Qt::FramelessWindowHint | Qt::Popup);
this->setContentsMargins(0, 0, 0, 0);
this->setLayout(vlayout);
this->setWindowFlags(Qt::NoDropShadowWindowHint | Qt::FramelessWindowHint | Qt::Popup);
gloss->setWordWrap(true);
gloss->setAlignment(Qt::AlignJustify);
this->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
gloss->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
this->setMinimumHeight(140);
Expand Down Expand Up @@ -61,7 +63,6 @@ void popup::addEntry(entry ent) {
return;
}

hasEntry = true;
entsize++;
entry newEnt = this->processEnt(ent);
topEntry.append(newEnt);
Expand Down Expand Up @@ -93,15 +94,17 @@ void popup::selectEntry() {
void popup::shows() {
QPoint curCurPos = QCursor::pos();
x = curCurPos.x() + 10;
y = curCurPos.y() - 210;
y = curCurPos.y() - (200 + 10);


this->selectEntry();
this->show();
}

void popup::setTheme() {
const QString style = "QDialog {background-color: white; border: 1px solid black;} QPushButton {border:none; background-color: #3f87f5; color: white;} QPushButton:hover {background-color: #3867db}";
const QString style("QDialog {background-color: white; border: 1px solid black;}"
"QPushButton {border:none; background-color: #3f87f5; color: white;}"
"QPushButton:hover {background-color: #3867db}");

QString fontPath = QDir::currentPath();
fontPath = "C:\\Users\\WanHuz\\Documents\\Shanachan\\res\\NotoSansMonoCJKjp-Regular.otf"; //For debugging purpose
Expand All @@ -123,13 +126,14 @@ void popup::setTheme() {

kanji->setContentsMargins(11, 5, 5, 5);
kana->setContentsMargins(11, 5, 5, 5);
gloss->setContentsMargins(11, 5, 5, 5);
gloss->setContentsMargins(11, 11, 11, 11);

kanji->setStyleSheet("font-size: 20px; font-weight: bold; background-color: #3867db; color: white;");
kana->setStyleSheet("font-size: 15px; font-weight: bold; background-color: #3f87f5; color: white;");
this->setStyleSheet(style);
}

//Process entry
entry popup::processEnt(entry ent) {

//Only take one kana reading
Expand All @@ -146,9 +150,16 @@ entry popup::processEnt(entry ent) {
gloss.remove(n, gloss.size());
gloss.append(" ... (more)");
}

//If there is no kanji entry, put kana in kanji
QString kanji = ent.getKanji();
if (kanji.isEmpty()) {
kanji = kana;
kana = "";
}

entry tempEnt(
ent.getKanji(),
kanji,
kana,
gloss,
ent.getFreq()
Expand Down
2 changes: 0 additions & 2 deletions src/ui/popup.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ class popup : public QDialog
void shows();

private:
bool hasEntry = false;
int ind = 0;
int entsize = 0;
int x, y;
Expand All @@ -25,7 +24,6 @@ class popup : public QDialog
QLabel* kana = new QLabel("kana");
QLabel* gloss = new QLabel("gloss");
QVector<entry> topEntry;
QBoxLayout* vlayout;
entry processEnt(entry ent);
void setTheme();

Expand Down

0 comments on commit bd0ccca

Please sign in to comment.