]> Git trees. - qtvoc.git/commitdiff
add file chooser dialog version-0.0.5
authorReto Zingg <g.d0b3rm4n@gmail.com>
Sat, 27 Mar 2010 17:29:07 +0000 (19:29 +0200)
committerReto Zingg <g.d0b3rm4n@gmail.com>
Sat, 27 Mar 2010 17:29:07 +0000 (19:29 +0200)
TinyVocTrainer/main.cpp
TinyVocTrainer/mainwindow.cpp
TinyVocTrainer/mainwindow.h
TinyVocTrainer/tinyvoctrainer.cpp
TinyVocTrainer/tinyvoctrainer.h
TinyVocTrainer/tinyvoctrainersettings.cpp
TinyVocTrainer/tinyvoctrainersettings.h

index a6b982f044639770aecf8bd59e9157900cb39bd8..e22e6a8b9031df0d0ea8a6ac3dff451569ea5a64 100644 (file)
@@ -1,4 +1,5 @@
 #include <QtGui/QApplication>
+#include <QtDebug>
 #include "mainwindow.h"
 
 int main(int argc, char *argv[])
@@ -8,6 +9,7 @@ int main(int argc, char *argv[])
 //    w.show();
 
     MainWindow *mainWin = new MainWindow;
+
     mainWin->show();
     return a.exec();
 }
index a4fe458b9d75740e1e6d86b6b59d6a1cc1b12235..48d3fe5ce1406417b947589a3fa5b67c9601eaac 100644 (file)
@@ -1,4 +1,5 @@
 #include <QtGui>
+#include <QFlags>
 
 #include "mainwindow.h"
 #include "tinyvoctrainer.h"
@@ -6,7 +7,30 @@
 
 MainWindow::MainWindow()
 {
-    trainer = new TinyVocTrainer;
+
+
+    curFile = "";
+    // setCurrentFile("");
+
+    QStringList args = QApplication::arguments();
+    args.removeFirst();
+
+    if (args.count() > 0){
+        if ( ! QString(args.at(0)).isEmpty() ){
+            qDebug() << "curFile is gonna be: " << args.at(0);
+            curFile = args.at(0);
+        }
+        else{
+            qDebug() << "something went wrong, lets the user choose for a file... args.at0: " << args.at(0);
+            open();
+        }
+    }
+    else{
+        qDebug() << "not enough arguments";
+        open();
+    }
+
+    trainer = new TinyVocTrainer(this, curFile);
 
     createActions();
     createMenus();
@@ -23,3 +47,12 @@ void MainWindow::createMenus(){
     mainMenu = menuBar()->addMenu("Main");
     mainMenu->addAction(settingAction);
 }
+
+void MainWindow::open(){
+    curFile = QFileDialog::getOpenFileName(this, QString("Open kvmtl file"),
+                                                 QString(""),
+                                                 QString("kvtml file (*.kvtml)") );
+    if ( curFile.isEmpty() ){
+        open();
+    }
+}
index 141f51bae53906bada08b457b8eca80d280cf413..70a2fb0f3c7fe5ce2c8cd4631f6d288eee37ed9b 100644 (file)
@@ -16,8 +16,11 @@ private:
     QMenu *mainMenu;
     void createActions();
     void createMenus();
-
     TinyVocTrainer *trainer;
+    // bool loadFile(const QString &fileName);
+    // void setCurrentFile(const QString &fileName);
+    QString curFile;
+    void open();
 };
 
 #endif // MAINWINDOW_H
index f2137512f42a85942ff88c74772b6ddf2681a055..a7dc10b6747c481d1b1cc94e274596137365b6a6 100644 (file)
 #include <QPushButton>
 #include <QComboBox>
 
-TinyVocTrainer::TinyVocTrainer(QWidget *parent)
+TinyVocTrainer::TinyVocTrainer(QWidget *parent, const QString &fileName)
     : QWidget(parent)
 {
     srand(time(NULL));
 
     QVBoxLayout *vbox = new QVBoxLayout();
-//    QHBoxLayout *hbox_less = new QHBoxLayout();
-//    QHBoxLayout *hbox_question_lang = new QHBoxLayout();
-//    QHBoxLayout *hbox_answer_lang = new QHBoxLayout();
     QVBoxLayout *vbox_label = new QVBoxLayout();
-//    QHBoxLayout *hbox_buttons = new QHBoxLayout();
 
-//    QPushButton *button = new QPushButton("Settings");
-//    hbox_buttons->addWidget(button);
-//    connect(button, SIGNAL(clicked(bool)), this, SLOT(slotSettings(bool)));
-
-//
-//    QComboBox *combox_lesson = new QComboBox();
-//    QComboBox *combox_question = new QComboBox();
-//    QComboBox *combox_answer = new QComboBox();
     bgroup_choice =  new QButtonGroup();
 
     QuestionLabel = new QLabel();
@@ -72,36 +60,11 @@ TinyVocTrainer::TinyVocTrainer(QWidget *parent)
     lessonID = 0;
     CorrectID = 0;
 
-//    QLabel *label_question = new QLabel("Question:");
-//    hbox_question_lang->addWidget(label_question);
-//
-//    QLabel *label_answer = new QLabel("Answer:");
-//    hbox_answer_lang->addWidget(label_answer);
-//
-//    QLabel *label_lesson = new QLabel("Lesson:");
-//    hbox_less->addWidget(label_lesson);
-
-    QStringList args = QApplication::arguments();
-    args.removeFirst();
-
     KEduVocDocument *docRead = new KEduVocDocument();
-    docRead->open(args.at(0));
+    docRead->open(fileName);
 
     lessons = docRead->lesson()->childContainers();
 
-//    for (int i = 0; i < docRead->identifierCount(); ++i)
-//    {
-//        combox_question->insertItem(i, docRead->identifier(i).name(), NULL);
-//        combox_answer->insertItem(i, docRead->identifier(i).name(), NULL);
-//    }
-
-//    connect(combox_question,SIGNAL(currentIndexChanged(int)),this,SLOT(reactToToggleQuestion(int)));
-//    connect(combox_answer,SIGNAL(currentIndexChanged(int)),this,SLOT(reactToToggleAnswer(int)));
-//    combox_question->setCurrentIndex(0);
-//    combox_answer->setCurrentIndex(1);
-//    hbox_question_lang->addWidget(combox_question);
-//    hbox_answer_lang->addWidget(combox_answer);
-
     int lessonId = 0;
     foreach(KEduVocContainer * c, lessons) {
         if (c->containerType() == KEduVocLesson::Lesson) {
@@ -109,24 +72,14 @@ TinyVocTrainer::TinyVocTrainer(QWidget *parent)
                 KEduVocLesson *m_lesson;
                 m_lesson = lessonsList.last() ;
                 qDebug () << "Lesson: " << m_lesson->name();
-
-//                combox_lesson->insertItem(lessonId, m_lesson->name(), NULL);
         }
         ++lessonId;
     }
 
-//    connect(combox_lesson,SIGNAL(currentIndexChanged(int)),this,SLOT(reactToToggleLesson(int)));
-//    combox_lesson->setCurrentIndex(0);
-//    hbox_less->addWidget(combox_lesson);
-
-    // vbox->addLayout(hbox_less);
-    // vbox->addLayout(hbox_question_lang);
-    // vbox->addLayout(hbox_answer_lang);
-//    vbox->addLayout(hbox_buttons);
     vbox->addLayout(vbox_label);
     setLayout(vbox);
 
-    dialog = new TinyVocTrainerSettings();
+    dialog = new TinyVocTrainerSettings(this, fileName);
 
     connect(dialog,SIGNAL(SignalToggleAnswer(int)),this,SLOT(reactToToggleAnswer(int)));
     connect(dialog,SIGNAL(SignalToggleLesson(int)),this,SLOT(reactToToggleLesson(int)));
index 1a91012ab5175c4a3687fca74ea29f14e61c65f9..70f65705169c7c319d81f8cb981dc728fada0533 100644 (file)
@@ -19,7 +19,7 @@ class TinyVocTrainer : public QWidget
     Q_OBJECT
 
 public:
-    TinyVocTrainer(QWidget *parent = 0);
+    TinyVocTrainer(QWidget *parent = 0, const QString &fileName = "");
     ~TinyVocTrainer();
     KEduVocExpression * getAnyEntryFromLesson(KEduVocLesson *lesson = 0, int language = 0);
 
index 226344b0dbba9af79fa4096aba5fcda542c7ac09..35c54432cd038b6d66b8bb33c4eda28716d0c1dd 100644 (file)
@@ -3,7 +3,7 @@
 #include <QApplication>
 #include <QtDebug>
 
-TinyVocTrainerSettings::TinyVocTrainerSettings(QWidget *parent)
+TinyVocTrainerSettings::TinyVocTrainerSettings(QWidget *parent, const QString &fileName)
     : QDialog(parent)
 {
     QVBoxLayout *vbox = new QVBoxLayout();
@@ -30,11 +30,8 @@ TinyVocTrainerSettings::TinyVocTrainerSettings(QWidget *parent)
     connect(buttons, SIGNAL(accepted()),this,SLOT(accept()));
     connect(buttons,SIGNAL(rejected()),this,SLOT(reject()));
 
-    QStringList args = QApplication::arguments();
-    args.removeFirst();
-
     KEduVocDocument *docRead = new KEduVocDocument();
-    docRead->open(args.at(0));
+    docRead->open(fileName);
 
     lessons = docRead->lesson()->childContainers();
 
@@ -76,14 +73,6 @@ TinyVocTrainerSettings::TinyVocTrainerSettings(QWidget *parent)
 
 }
 
-//void TinyVocTrainerSettings::accept(){
-//    return;
-//}
-//
-//void TinyVocTrainerSettings::reject(){
-//    return;
-//}
-
 void TinyVocTrainerSettings::reactToToggleQuestion(int id)
 {
     qDebug() << "TinyVocTrainerSettings Toggle Question: " << id;
index b32e28a5e69a0fcbec27c25e4ee35f74a9d4d42a..cde1cdf4f5871055e3642e92fa8f384549e7442e 100644 (file)
@@ -20,7 +20,7 @@ class TinyVocTrainerSettings : public QDialog
 Q_OBJECT
 
 public:
-    explicit TinyVocTrainerSettings(QWidget *parent = 0);
+    explicit TinyVocTrainerSettings(QWidget *parent = 0, const QString &fileName = "");
 
     QList<KEduVocContainer *>  lessons;
     QList<KEduVocLesson *> lessonsList;