summaryrefslogtreecommitdiffstats
path: root/proverb/src
diff options
context:
space:
mode:
authorRahul <rahulrs@gmx.com>2009-03-13 21:09:38 -0400
committerRahul <rahulrs@gmx.com>2009-03-13 21:09:38 -0400
commit886b09e5d997af17d1b0a9c7fad6e952a94bed45 (patch)
tree3deedb4643dd0a225830150ecec257d20c218194 /proverb/src
parent2cea4faae67f7ec777bd781b0f77bac0abc527a9 (diff)
downloadRachana.git-886b09e5d997af17d1b0a9c7fad6e952a94bed45.tar.gz
Rachana.git-886b09e5d997af17d1b0a9c7fad6e952a94bed45.tar.xz
Rachana.git-886b09e5d997af17d1b0a9c7fad6e952a94bed45.zip
proverb
Diffstat (limited to 'proverb/src')
-rw-r--r--proverb/src/main.cpp18
-rw-r--r--proverb/src/main.cpp~18
-rw-r--r--proverb/src/mainwindow.cpp100
-rw-r--r--proverb/src/mainwindow.h26
-rw-r--r--proverb/src/tabdialog.cpp8
-rw-r--r--proverb/src/tabdialog.h14
6 files changed, 184 insertions, 0 deletions
diff --git a/proverb/src/main.cpp b/proverb/src/main.cpp
new file mode 100644
index 0000000..33a960e
--- /dev/null
+++ b/proverb/src/main.cpp
@@ -0,0 +1,18 @@
+#include <QApplication>
+#include <QTranslator>
+#include "mainwindow.h"
+#include "tabdialog.h"
+//
+int main(int argc, char ** argv)
+{
+ QApplication app( argc, argv );
+
+ QTranslator translator;
+ translator.load("/usr/bin/proverb_ml");
+ app.installTranslator(&translator);
+
+ MainWindow win;
+ win.show();
+ app.connect( &app, SIGNAL( lastWindowClosed() ), &app, SLOT( quit() ) );
+ return app.exec();
+}
diff --git a/proverb/src/main.cpp~ b/proverb/src/main.cpp~
new file mode 100644
index 0000000..dd32b85
--- /dev/null
+++ b/proverb/src/main.cpp~
@@ -0,0 +1,18 @@
+#include <QApplication>
+#include <QTranslator>
+#include "mainwindow.h"
+#include "tabdialog.h"
+//
+int main(int argc, char ** argv)
+{
+ QApplication app( argc, argv );
+
+ QTranslator translator;
+ translator.load("proverb_ml");
+ app.installTranslator(&translator);
+
+ MainWindow win;
+ win.show();
+ app.connect( &app, SIGNAL( lastWindowClosed() ), &app, SLOT( quit() ) );
+ return app.exec();
+}
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 <QProcess>
+#include <iostream>
+#include <QTemporaryFile>
+#include <QTranslator>
+#include <QtDebug>
+#include <QString>
+#include <QMessageBox>
+//
+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" <<tempFileName;
+ }
+ else
+ qDebug()<<"Cannot open/create temporary file";
+}
+//
+
+void MainWindow::getProverb(void)
+{
+ const char* systemCommand;
+ std::string command;
+ command = lineEdit->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<<command<<"\n";
+ systemCommand = command.c_str();
+ system(systemCommand);
+ loadFile(tempFileName);
+}
+
+void MainWindow::loadFile(const QString &fileName)
+{
+ QFile file(fileName);
+
+ if (!file.open(QFile::ReadOnly | QFile::Text))
+ {
+ qDebug()<<"Cannot open temporary file";
+ return;
+ }
+ QTextStream in(&file);
+ QApplication::setOverrideCursor(Qt::WaitCursor);
+ textEdit->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("<h2 align=\"center\"><b>Proverb</h2><p><h4 align=\"center\">GUI for fortune-ml<p><h4 align=\"center\">"));*/
+About tabdialog(".");
+tabdialog.exec();
+}
diff --git a/proverb/src/mainwindow.h b/proverb/src/mainwindow.h
new file mode 100644
index 0000000..a4fa977
--- /dev/null
+++ b/proverb/src/mainwindow.h
@@ -0,0 +1,26 @@
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+//
+#include <QMainWindow>
+#include "ui_mainwindow.h"
+#include "tabdialog.h"
+//
+class MainWindow : public QMainWindow, public Ui::MainWindow
+{
+Q_OBJECT
+public:
+ MainWindow( QWidget * parent = 0, Qt::WFlags f = 0 );
+
+private slots:
+ void getProverb(void);
+ void about(void);
+
+private:
+ void loadFile(const QString &fileName);
+
+};
+#endif
+
+
+
+
diff --git a/proverb/src/tabdialog.cpp b/proverb/src/tabdialog.cpp
new file mode 100644
index 0000000..b8254b3
--- /dev/null
+++ b/proverb/src/tabdialog.cpp
@@ -0,0 +1,8 @@
+#include <QtGui>
+#include "tabdialog.h"
+
+About::About(const QString &fileName, QWidget *parent): QDialog(parent)
+{
+ setupUi(this);
+}
+
diff --git a/proverb/src/tabdialog.h b/proverb/src/tabdialog.h
new file mode 100644
index 0000000..0e1fb60
--- /dev/null
+++ b/proverb/src/tabdialog.h
@@ -0,0 +1,14 @@
+#ifndef TABDIALOG_H
+#define TABDIALOG_H
+#include <QDialog>
+#include "ui_about.h"
+
+class About : public QDialog, private Ui::aboutDialog
+{
+ Q_OBJECT
+public:
+ About(const QString &fileName, QWidget *parent = 0);
+private:
+};
+
+#endif