From: Reto Zingg Date: Sat, 27 Mar 2010 17:29:07 +0000 (+0200) Subject: add file chooser dialog X-Git-Tag: version-0.0.5 X-Git-Url: https://git.rmz.fi/?a=commitdiff_plain;h=77cc8df047fb6a29156cf8b31c5213417f9ab14e;p=qtvoc.git add file chooser dialog --- diff --git a/TinyVocTrainer/main.cpp b/TinyVocTrainer/main.cpp index a6b982f..e22e6a8 100644 --- a/TinyVocTrainer/main.cpp +++ b/TinyVocTrainer/main.cpp @@ -1,4 +1,5 @@ #include +#include #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(); } diff --git a/TinyVocTrainer/mainwindow.cpp b/TinyVocTrainer/mainwindow.cpp index a4fe458..48d3fe5 100644 --- a/TinyVocTrainer/mainwindow.cpp +++ b/TinyVocTrainer/mainwindow.cpp @@ -1,4 +1,5 @@ #include +#include #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(); + } +} diff --git a/TinyVocTrainer/mainwindow.h b/TinyVocTrainer/mainwindow.h index 141f51b..70a2fb0 100644 --- a/TinyVocTrainer/mainwindow.h +++ b/TinyVocTrainer/mainwindow.h @@ -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 diff --git a/TinyVocTrainer/tinyvoctrainer.cpp b/TinyVocTrainer/tinyvoctrainer.cpp index f213751..a7dc10b 100644 --- a/TinyVocTrainer/tinyvoctrainer.cpp +++ b/TinyVocTrainer/tinyvoctrainer.cpp @@ -11,26 +11,14 @@ #include #include -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))); diff --git a/TinyVocTrainer/tinyvoctrainer.h b/TinyVocTrainer/tinyvoctrainer.h index 1a91012..70f6570 100644 --- a/TinyVocTrainer/tinyvoctrainer.h +++ b/TinyVocTrainer/tinyvoctrainer.h @@ -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); diff --git a/TinyVocTrainer/tinyvoctrainersettings.cpp b/TinyVocTrainer/tinyvoctrainersettings.cpp index 226344b..35c5443 100644 --- a/TinyVocTrainer/tinyvoctrainersettings.cpp +++ b/TinyVocTrainer/tinyvoctrainersettings.cpp @@ -3,7 +3,7 @@ #include #include -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; diff --git a/TinyVocTrainer/tinyvoctrainersettings.h b/TinyVocTrainer/tinyvoctrainersettings.h index b32e28a..cde1cdf 100644 --- a/TinyVocTrainer/tinyvoctrainersettings.h +++ b/TinyVocTrainer/tinyvoctrainersettings.h @@ -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 lessons; QList lessonsList;