From 886b09e5d997af17d1b0a9c7fad6e952a94bed45 Mon Sep 17 00:00:00 2001 From: Rahul Date: Fri, 13 Mar 2009 21:09:38 -0400 Subject: proverb --- proverb/src/mainwindow.cpp | 100 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 proverb/src/mainwindow.cpp (limited to 'proverb/src/mainwindow.cpp') diff --git a/proverb/src/mainwindow.cpp b/proverb/src/mainwindow.cpp new file mode 100644 index 0000000..e98f65c --- /dev/null +++ b/proverb/src/mainwindow.cpp @@ -0,0 +1,100 @@ +#include "mainwindow.h" +#include +#include +#include +#include +#include +#include +#include +// +QString tempFileName; +MainWindow::MainWindow( QWidget * parent, Qt::WFlags f) : QMainWindow(parent, f) +{ + setupUi(this); + connect(getButton, SIGNAL(clicked()), this, SLOT(getProverb())); + //connect(getButton, SIGNAL(returnPressed()), this, SLOT(getProverb())); + connect(aboutButton, SIGNAL(clicked()), this, SLOT(about())); + QTemporaryFile tempFile; + if (tempFile.open()) + { + tempFileName = tempFile.fileName(); + qDebug()<<"Temp file name" <text().toUtf8().data(); + if (command == "") + command = "fortune fortune-ml"+command+" >"+tempFileName.toUtf8().data(); // തിരയാന്‍ ഒരു വാക്കും തന്നില്ലെങ്കില്‍ ഏതെങ്കിലും പഴഞ്ചൊല്ല് കാണിക്കാനുള്ള വിദ്യ + else + command = "fortune fortune-ml -m "+command+" >"+tempFileName.toUtf8().data(); + //std::cout<setPlainText(in.readAll()); + QApplication::restoreOverrideCursor(); + + QTextDocument *document = textEdit->document(); + QTextCursor highlightCursor(document); + QTextCursor cursor(document); + QTextCursor startOfLine(document); + QTextCursor deletePercentage(document); + cursor.beginEditBlock(); + QTextCharFormat plainFormat(highlightCursor.charFormat()); + QTextCharFormat colorFormat = plainFormat; + colorFormat.setFontItalic(true); + colorFormat.setForeground(Qt::darkBlue); + while (!deletePercentage.isNull() && !deletePercentage.atEnd()) // % ചിഹ്നം നീക്കാന്‍ + { + deletePercentage = document->find("%", deletePercentage, QTextDocument::FindWholeWords); + if (!deletePercentage.isNull()) + { + deletePercentage.movePosition(QTextCursor::WordRight, QTextCursor::KeepAnchor); + deletePercentage.removeSelectedText(); + } + } + while (!startOfLine.isNull() && !startOfLine.atEnd()) // എല്ലാ വരിയുടെയും തുടക്കത്തില്‍ '* ' ചേര്‍ക്കാന്‍ + { + startOfLine.movePosition(QTextCursor::StartOfLine); + startOfLine.insertText("* "); + startOfLine.movePosition(QTextCursor::Down); + } + while (!highlightCursor.isNull() && !highlightCursor.atEnd()) // ആവശ്യപ്പെട്ട വാക്ക് നീലനിരത്തില്‍ ചരിച്ചെഴുതാന്‍ + { + highlightCursor = document->find(lineEdit->text(), highlightCursor); + if (!highlightCursor.isNull()) + { + highlightCursor.movePosition(QTextCursor::WordRight, QTextCursor::KeepAnchor); + highlightCursor.mergeCharFormat(colorFormat); + } + } + cursor.endEditBlock(); +} + +void MainWindow::about(void) +{ + /* QMessageBox::about(this, tr("About Kuttans"), + tr("

Proverb

GUI for fortune-ml

"));*/ +About tabdialog("."); +tabdialog.exec(); +} -- cgit