SearchPreferences::SearchPreferences(QWidget *parent) : QWidget(parent) { QGridLayout *mainLayout = new QGridLayout(this); setLayout(mainLayout); syncAttachments = new QCheckBox(tr("Index Attachments")); mainLayout->addWidget(syncAttachments,0,0); syncAttachments->setChecked(global.synchronizeAttachments()); weight = new QSpinBox(this); mainLayout->addWidget(new QLabel(tr("Minimum Image Recognition Weight")), 1,0); mainLayout->addWidget(weight,1,1); weight->setMinimum(1); weight->setMaximum(100); weight->setValue(global.getMinimumRecognitionWeight()); this->setFont(global.getGuiFont(font())); }
/* This function works the same as the addHighlight, but instead of highlighting text in a note, it highlights the text in an image. */ QString NoteFormatter::addImageHighlight(qint32 resLid, QString imgfile) { if (highlightWords.size() == 0) return ""; // Get the image resource recognition data. This tells where to highlight the image ResourceTable resTable(global.db); Resource recoResource; resTable.getResourceRecognition(recoResource, resLid); Data recognition; if (recoResource.recognition.isSet()) recognition = recoResource.recognition; if (!recognition.size.isSet() || !recognition.body.isSet() || recognition.size == 0) { return ""; } QString filename = global.fileManager.getTmpDirPath() + QString::number(resLid) + ".png"; // Now we have the recognition data. We need to go through it QByteArray recoData; if (recognition.body.isSet()) recoData = recognition.body; QString xml(recoData); // Create a transparent pixmap. The only non transparent piece is teh // highlight that will be overlaid on the old image imgfile = imgfile.replace("file:///", ""); QPixmap originalFile(imgfile); QPixmap overlayPix(originalFile.size()); overlayPix.fill(Qt::transparent); QPainter p2(&overlayPix); p2.setBackgroundMode(Qt::TransparentMode); p2.setRenderHint(QPainter::Antialiasing,true); QColor yellow(Qt::yellow); p2.setBrush(yellow); // Now, we have the image. We need to go through all the recognition data to highlight // what we've found. QDomDocument doc; doc.setContent(xml); // Go through the "item" nodes QDomNodeList anchors = doc.elementsByTagName("item"); for (unsigned int i=0; i<anchors.length(); i++) { QDomElement element = anchors.at(i).toElement(); int x = element.attribute("x").toInt(); int y = element.attribute("y").toInt(); int w = element.attribute("w").toInt(); int h = element.attribute("h").toInt(); // Get all children ("t" nodes) QDomNodeList children = element.childNodes(); for (unsigned int j=0; j<children.length(); j++) { QDomElement child = children.at(j).toElement(); if (child.nodeName().toLower() == "t") { QString text = child.text(); int weight = child.attribute("w").toInt(); // Image weight if (weight >= global.getMinimumRecognitionWeight()) { // Check to see if this word matches something we're looking for for (int k=0; k<highlightWords.size(); k++) { QString searchWord = highlightWords[k].toLower(); if (searchWord.endsWith("*")) searchWord.chop(1); if (text.toLower().contains(searchWord)) { p2.drawRect(x,y,w,h); } } } } } } // Paint the highlight onto the background & save over the original p2.setOpacity(0.4); p2.drawPixmap(0,0,overlayPix); p2.end(); // Create the actual overlay. We do this in two steps to avoid // constantly painting the same area QPixmap finalPix(originalFile.size()); finalPix.fill(Qt::transparent); QPainter p3(&finalPix); p3.setBackgroundMode(Qt::TransparentMode); p3.setRenderHint(QPainter::Antialiasing,true); p3.drawPixmap(0,0,originalFile); p3.setOpacity(0.4); p3.drawPixmap(0,0,overlayPix); p3.end(); finalPix.save(filename); return "this.src='file://"+filename+"';"; }