From ce599e4f9f94b4eb00c1b5edb85bce5431ab3df2 Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdeedu@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- keduca/keducabuilder/Makefile.am | 39 + keduca/keducabuilder/kcontroladdedit.cpp | 303 +++++++ keduca/keducabuilder/kcontroladdedit.h | 93 +++ keduca/keducabuilder/kcontroladdeditbase.ui | 877 +++++++++++++++++++++ keduca/keducabuilder/kcontrolheader.cpp | 376 +++++++++ keduca/keducabuilder/kcontrolheader.h | 86 ++ keduca/keducabuilder/kcontrolheaderbase.ui | 472 +++++++++++ keduca/keducabuilder/keducabuilder.cpp | 600 ++++++++++++++ keduca/keducabuilder/keducabuilder.h | 126 +++ keduca/keducabuilder/keducabuilderui.rc | 28 + keduca/keducabuilder/keducaeditorstartdialog.cpp | 114 +++ keduca/keducabuilder/keducaeditorstartdialog.h | 59 ++ .../keducabuilder/keducaeditorstartdialogbase.ui | 320 ++++++++ keduca/keducabuilder/klangcombo.cpp | 51 ++ keduca/keducabuilder/klangcombo.h | 47 ++ keduca/keducabuilder/ktagcombobox.cpp | 229 ++++++ keduca/keducabuilder/ktagcombobox.h | 94 +++ keduca/keducabuilder/main.cpp | 67 ++ 18 files changed, 3981 insertions(+) create mode 100644 keduca/keducabuilder/Makefile.am create mode 100644 keduca/keducabuilder/kcontroladdedit.cpp create mode 100644 keduca/keducabuilder/kcontroladdedit.h create mode 100644 keduca/keducabuilder/kcontroladdeditbase.ui create mode 100644 keduca/keducabuilder/kcontrolheader.cpp create mode 100644 keduca/keducabuilder/kcontrolheader.h create mode 100644 keduca/keducabuilder/kcontrolheaderbase.ui create mode 100644 keduca/keducabuilder/keducabuilder.cpp create mode 100644 keduca/keducabuilder/keducabuilder.h create mode 100644 keduca/keducabuilder/keducabuilderui.rc create mode 100644 keduca/keducabuilder/keducaeditorstartdialog.cpp create mode 100644 keduca/keducabuilder/keducaeditorstartdialog.h create mode 100644 keduca/keducabuilder/keducaeditorstartdialogbase.ui create mode 100644 keduca/keducabuilder/klangcombo.cpp create mode 100644 keduca/keducabuilder/klangcombo.h create mode 100644 keduca/keducabuilder/ktagcombobox.cpp create mode 100644 keduca/keducabuilder/ktagcombobox.h create mode 100644 keduca/keducabuilder/main.cpp (limited to 'keduca/keducabuilder') diff --git a/keduca/keducabuilder/Makefile.am b/keduca/keducabuilder/Makefile.am new file mode 100644 index 00000000..39fcb8d6 --- /dev/null +++ b/keduca/keducabuilder/Makefile.am @@ -0,0 +1,39 @@ +bin_PROGRAMS = keducabuilder +keducabuilder_SOURCES = kcontroladdeditbase.ui keducaeditorstartdialogbase.ui keducaeditorstartdialog.cpp ktagcombobox.cpp klangcombo.cpp kcontrolheader.cpp keducabuilder.cpp kcontroladdedit.cpp main.cpp +keducabuilder_LDADD = $(LIB_KFILE) ../libkeduca/libkeduca.la + +EXTRA_DIST = main.cpp kcontroladdedit.cpp kcontroladdedit.h keducabuilder.cpp keducabuilder.h kcontrolheader.cpp kcontrolheader.h keducabuilderui.rc klangcombo.cpp klangcombo.h ktagcombobox.cpp ktagcombobox.h keducaeditorstartdialog.cpp keducaeditorstartdialog.h + +# this 10 paths are KDE specific. Use them: +# kde_htmldir Where your docs should go to. (contains lang subdirs) +# kde_appsdir Where your application file (.kdelnk) should go to. +# kde_icondir Where your icon should go to. +# kde_minidir Where your mini icon should go to. +# kde_datadir Where you install application data. (Use a subdir) +# kde_locale Where translation files should go to.(contains lang subdirs) +# kde_cgidir Where cgi-bin executables should go to. +# kde_confdir Where config files should go to. +# kde_mimedir Where mimetypes should go to. +# kde_toolbardir Where general toolbar icons should go to. +# kde_wallpaperdir Where general wallpapers should go to. + +# set the include path for X, qt and KDE +INCLUDES= -I../libkeduca $(all_includes) + +METASOURCES = AUTO + +# the library search path. +keducabuilder_LDFLAGS = $(all_libraries) $(KDE_RPATH) + +# Uncomment the following two lines if you add a ui.rc file for your application to make use of +# KDE´s XML GUI builing +rcdir = $(kde_datadir)/keduca +rc_DATA = keducabuilderui.rc + +messages: rc.cpp + LIST=`find . -name \*.h -o -name \*.hh -o -name \*.H -o -name \*.hxx -o -name \*.hpp -o -name \*.cpp -o -name \*.cc -o -name \*.cxx -o -name \*.ecpp -o -name \*.C`; \ + if test -n "$$LIST"; then \ + $(XGETTEXT) $$LIST -o $(podir)/keduca.pot; \ + fi + +include ../../admin/Doxyfile.am diff --git a/keduca/keducabuilder/kcontroladdedit.cpp b/keduca/keducabuilder/kcontroladdedit.cpp new file mode 100644 index 00000000..76715e27 --- /dev/null +++ b/keduca/keducabuilder/kcontroladdedit.cpp @@ -0,0 +1,303 @@ +/*************************************************************************** + kcontroladdedit.cpp - description + ------------------- + begin : Sun May 27 2001 + copyright : (C) 2001 by Javier Campos + email : javi@asyris.org +***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#include "kcontroladdedit.h" +#include "kcontroladdedit.moc" + +// KDE includes +#include +#include +#include +#include +#include +#include +//#include <.h> + +// Qt includes +#include +#include + +KControlAddEdit::KControlAddEdit(QWidget *parent, const char *name, bool modal, WFlags f) + : KControlAddEditBase(parent, name, modal, f), + _currentAnswerItem(0) +{ + configRead(); +} + +KControlAddEdit::~KControlAddEdit() +{ +} + +/** Init _keducaFile pointer and EditMode */ +void KControlAddEdit::init(FileRead *keducaFile, bool edit) +{ + setCurrentAnswerItem(0); + _keducaFile = keducaFile; + _editMode = edit; + + _listAnswers->setSorting(-1); + + if( _editMode ) + { + setCaption(i18n("Modify Question")); + fillPage(); + }else{ + setCaption(i18n("Add Questions")); + slotQuestionTypeChanged( 0 ); + } + + // settings for Question page + setHelpEnabled ( _pageQuestion, false ); + setNextEnabled( _pageQuestion, false ); + + // settings for Answer page + setHelpEnabled ( _pageAnswer, false ); + setFinishEnabled( _pageAnswer, true ); +} + +/** Fill page of current record */ +void KControlAddEdit::fillPage() +{ + _questionText->setText( _keducaFile->getQuestion( FileRead::QF_TEXT ) ); + if( !_keducaFile->getQuestion( FileRead::QF_PICTURE ).isEmpty() ) + { + _questionPreview->setPixmap(_keducaFile->getQuestion(FileRead::QF_PICTURE)); + _answerPreview->setPixmap(_keducaFile->getQuestion(FileRead::QF_PICTURE)); + _questionPicture->setURL( _keducaFile->getQuestion( FileRead::QF_PICTURE ) ); + } + _questionType->setCurrentItem( _keducaFile->getQuestionInt( FileRead::QF_TYPE )-1 ); + slotQuestionTypeChanged( _questionType->currentItem() ); + _questionPoint->setValue( _keducaFile->getQuestionInt( FileRead::QF_POINTS ) ); + _questionTip->setText( _keducaFile->getQuestion( FileRead::QF_TIP ) ); + _questionExplain->setText( _keducaFile->getQuestion( FileRead::QF_EXPLAIN ) ); + _questionTime->setValue( _keducaFile->getQuestionInt( FileRead::QF_TIME ) ); + + _listAnswers->clear(); + _keducaFile->recordAnswerFirst(); + while( !_keducaFile->recordAnswerEOF() ) + { + QListViewItem *newItem = new QListViewItem(_listAnswers); + newItem->setText(0,_keducaFile->getAnswer( FileRead::AF_TEXT )); + newItem->setText(1,_keducaFile->getAnswerValue()?i18n("True"):i18n("False")); + newItem->setText(2,QString::number(_keducaFile->getAnswerPoints())); + + _keducaFile->recordAnswerNext(); + }; +} + +void KControlAddEdit::setCurrentAnswerItem(QListViewItem *item) +{ + _currentAnswerItem = item; + if (item) + _buttonInsert->setText(i18n("&Apply")); + else + _buttonInsert->setText(i18n("&Add")); +} + +/** Button insert */ +void KControlAddEdit::slotAddAnswer() +{ + if( !_answerText->text().isEmpty() ) + { + // add new listview item + QListViewItem *newItem = _currentAnswerItem + ? _currentAnswerItem + : new QListViewItem(_listAnswers,_listAnswers->lastItem()); + newItem->setText(0,_answerText->text()); + newItem->setText(1,_answerValue->currentItem() == 1 ?i18n("True"):i18n("False")); + newItem->setText(2,QString::number(_answerPoints->value())); + + // reset values + newItem->setSelected(false); + resetAnswerValues(); + } +} + +void KControlAddEdit::resetAnswerValues() +{ + _answerText->setText(""); + _answerValue->setCurrentItem( 0 ); + _answerPoints->setValue(0); + _answerText->setFocus(); + setCurrentAnswerItem(0); + _buttonUp->setEnabled(false); + _buttonDown->setEnabled(false); + _buttonRemove->setEnabled(false); + _buttonInsert->setEnabled(false); +} + +/** Remove answer */ +void KControlAddEdit::slotRemoveAnswer() +{ + delete _listAnswers->currentItem(); + resetAnswerValues(); +} + +/** Button Up */ +void KControlAddEdit::slotMoveUpAnswer() +{ + QListViewItem *item = _listAnswers->currentItem(); + + if (item && item->itemAbove()) + item->itemAbove()->moveItem(item); + + _buttonUp->setEnabled(item->itemAbove()!=0); + _buttonDown->setEnabled(item->itemBelow()!=0); +} + +/** Button Down */ +void KControlAddEdit::slotMoveDownAnswer() +{ + QListViewItem *item = _listAnswers->currentItem(); + + if (item) + item->moveItem(item->itemBelow()); + + _buttonUp->setEnabled(item->itemAbove()!=0); + _buttonDown->setEnabled(item->itemBelow()!=0); +} + +void KControlAddEdit::slotAnswerSelected(QListViewItem *item) +{ + if (!item) + return; + + setCurrentAnswerItem(item); + + // set the answer fields to the value of the selected answer + _answerText->setText(item->text(0)); + _answerValue->setCurrentItem(item->text(1) == i18n("True")?1:0); + _answerPoints->setValue(item->text(2).toInt()); + + // enable/disable the buttons as appropriate + _buttonRemove->setEnabled(true); + _buttonInsert->setEnabled(true); + _buttonDown->setEnabled(item->itemBelow()!=0); + _buttonUp->setEnabled(item->itemAbove()!=0); +} + +/** Accept changes */ +void KControlAddEdit::accept() +{ + if( !_editMode ) + _keducaFile->insertQuestion(); + + addQuestion(); + configWrite(); + done( QDialog::Accepted ); +} + +/** Add question with form data */ +void KControlAddEdit::addQuestion() +{ + _keducaFile->setQuestion( FileRead::QF_TEXT, _questionText->text() ); + _keducaFile->setQuestion( FileRead::QF_TYPE, _questionType->currentItem()+1 ); + _keducaFile->setQuestion( FileRead::QF_PICTURE, _questionPicture->url() ); + _keducaFile->setQuestion( FileRead::QF_POINTS, _questionPoint->value() ); + _keducaFile->setQuestion( FileRead::QF_TIME, _questionTime->value() ); + _keducaFile->setQuestion( FileRead::QF_TIP, _questionTip->text() ); + _keducaFile->setQuestion( FileRead::QF_EXPLAIN, _questionExplain->text() ); + + _keducaFile->clearAnswers(); + QListViewItem *item = _listAnswers->firstChild(); + while (item) { + _keducaFile->setAnswer( + item->text(0), // The Answer text + item->text(1)==i18n("True"), // the validity of the answer + item->text(2).toInt()); // the points + item = item->nextSibling(); + } +} +/** Read config settings */ +void KControlAddEdit::configRead() +{ + KConfig *config = KGlobal::config(); + config->setGroup("AddModify Window"); + QSize defaultSize(500,400); + resize( config->readSizeEntry("Geometry", &defaultSize ) ); +} + +/** Write config settings */ +void KControlAddEdit::configWrite() +{ + KConfig *config = KGlobal::config(); + config->setGroup("AddModify Window"); + config->writeEntry("Geometry", size() ); + config->sync(); +} + +/** Question data changed */ +void KControlAddEdit::slotDataChanged() +{ + if( _pageQuestion == currentPage() ) + { + nextButton()->setEnabled( !_questionText->text().isEmpty() ); + } + if( _pageAnswer == currentPage() ) + { + _buttonInsert->setEnabled( !_answerText->text().isEmpty() ); + } +} + + +/** Preview image */ +void KControlAddEdit::slotPreviewImage( const QString &text) +{ + if( text.isEmpty() ) { _questionPreview->setText(""); _answerPreview->setText(""); return; } + + _questionPreview->setPixmap( QPixmap( text ) ); + _answerPreview->setPixmap( QPixmap( text ) ); +} + +/** show current Page */ +void KControlAddEdit::showPage(QWidget *page) +{ + QWizard::showPage(page); + slotDataChanged(); + + if ( page == _pageQuestion ) { + _questionText->setFocus(); + } else if ( page == _pageAnswer ) { + _answerText->setFocus(); + } +} + +/** Change question type */ +void KControlAddEdit::slotQuestionTypeChanged( int index ) +{ + switch( index+1 ) + { + case 1: + _questionPoint->setEnabled( false ); + _answerPoints->setEnabled( false ); + _questionPoint->setValue(0); + _answerPoints->setValue(0); + break; + case 2: + _questionPoint->setEnabled( true ); + _answerPoints->setEnabled( false ); + _answerPoints->setValue(0); + break; + case 3: + _questionPoint->setEnabled( false ); + _answerPoints->setEnabled( true ); + _questionPoint->setValue(0); + break; + default: + break; + } +} diff --git a/keduca/keducabuilder/kcontroladdedit.h b/keduca/keducabuilder/kcontroladdedit.h new file mode 100644 index 00000000..d700ec43 --- /dev/null +++ b/keduca/keducabuilder/kcontroladdedit.h @@ -0,0 +1,93 @@ +/*************************************************************************** + kcontroladdedit.h - description + ------------------- + begin : Sun May 27 2001 + copyright : (C) 2001 by Javier Campos + email : javi@asyris.org +***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#ifndef KCONTROLADDEDIT_H +#define KCONTROLADDEDIT_H + +#include "../libkeduca/fileread.h" +#include "kcontroladdeditbase.h" + +// Qt forward declarations +class QListViewItem; + +/**Add or edit questions + * This is the Wizard that allows adding and editing of + * Questions (and corresponding possible answers) to the + * KEduca Document. + * This will be called from the Editor (class KEducaBuilder) + *@author Javier Campos + * @author Klas Kalass (2003) + */ + +class KControlAddEdit : public KControlAddEditBase { + Q_OBJECT + +public: + KControlAddEdit(QWidget *parent = 0, const char *name = 0, bool modal = true, WFlags f = 0); + ~KControlAddEdit(); + /** Init keducaFile pointer and EditMode */ + void init(FileRead *keducaFile, bool editMode); + /** show current Page */ + void showPage(QWidget *page); + +private: + + // Private methods + + /** Init graphical interface */ +// void initGUI(); + /** Fill page of current record */ + void fillPage(); + /** Add question with form data */ + void addQuestion(); + /** Write config settings */ + void configWrite(); + /** Read config settings */ + void configRead(); + void setCurrentAnswerItem(QListViewItem *item); + void resetAnswerValues(); + + // Private attributes + /** Pointer to keduca of kcontrol page */ + FileRead *_keducaFile; + /** The currently selected answer item, important for editing of the answer*/ + QListViewItem *_currentAnswerItem; + /** Is a edit modify? */ + bool _editMode; + +private slots: + /** Accept changes */ + void accept(); + /** An Answer has been selected */ + void slotAnswerSelected(QListViewItem *item); + /** Remove answer */ + void slotRemoveAnswer(); + /** Button insert */ + void slotAddAnswer(); + /** Button Down */ + void slotMoveDownAnswer(); + /** Button Up */ + void slotMoveUpAnswer(); + /** Question or Answer data changed */ + void slotDataChanged(); + /** Preview image */ + void slotPreviewImage( const QString & ); + /** Change question type */ + void slotQuestionTypeChanged( int index ); +}; + +#endif diff --git a/keduca/keducabuilder/kcontroladdeditbase.ui b/keduca/keducabuilder/kcontroladdeditbase.ui new file mode 100644 index 00000000..0292edf2 --- /dev/null +++ b/keduca/keducabuilder/kcontroladdeditbase.ui @@ -0,0 +1,877 @@ + +KControlAddEditBase + + + KControlAddEditBase + + + + 0 + 0 + 600 + 480 + + + + + _pageQuestion + + + Question + + + + unnamed + + + 0 + + + + frame3 + + + + 125 + 0 + + + + + 125 + 32767 + + + + editbase_image0 + + + Box + + + Plain + + + + unnamed + + + + _questionPreview + + + + 100 + 100 + + + + + 100 + 100 + + + + + 255 + 255 + 255 + + + + Box + + + Plain + + + + + + true + + + + + spacer1 + + + Vertical + + + Expanding + + + + 20 + 21 + + + + + + textLabel1 + + + <span style="color:black"> + <p><b>Question</b></p> +<hr> + <p>Only the question and type is required.</p> +</span> + + + + + spacer2 + + + Vertical + + + Expanding + + + + 20 + 41 + + + + + + + + frame5 + + + Box + + + Sunken + + + + unnamed + + + + textLabel2 + + + &Question: + + + AlignTop|AlignRight + + + _questionText + + + + + textLabel4 + + + &Type: + + + AlignVCenter|AlignRight + + + _questionType + + + + + textLabel3 + + + &Picture: + + + AlignVCenter|AlignRight + + + _questionPicture + + + + + _questionPicture + + + + + + Test + + + + + Test with Question Points + + + + + Test with Answers Points + + + + _questionType + + + + + textLabel5 + + + P&oint: + + + AlignVCenter|AlignRight + + + _questionPoint + + + + + textLabel6 + + + Ti&me: + + + AlignVCenter|AlignRight + + + _questionTime + + + + + textLabel7 + + + T&ip: + + + AlignVCenter|AlignRight + + + _questionTip + + + + + _questionTip + + + + + textLabel8 + + + &Explain: + + + AlignTop|AlignRight + + + _questionExplain + + + + + _questionText + + + + + _questionExplain + + + + + layout1 + + + + unnamed + + + + _questionTime + + + + + spacer4 + + + Horizontal + + + Expanding + + + + 81 + 20 + + + + + + + + layout2 + + + + unnamed + + + + _questionPoint + + + + + spacer3 + + + Horizontal + + + Expanding + + + + 131 + 20 + + + + + + + + + + + + _pageAnswer + + + Answer + + + + unnamed + + + 0 + + + + frame3_2 + + + + 125 + 0 + + + + + 125 + 32767 + + + + editbase_image0 + + + Box + + + Plain + + + + unnamed + + + + _answerPreview + + + + 100 + 100 + + + + + 100 + 100 + + + + + 255 + 255 + 255 + + + + Box + + + Plain + + + + + + true + + + + + spacer1_2 + + + Vertical + + + Expanding + + + + 20 + 21 + + + + + + textLabel2_2 + + + <span style="color:black"> + <p><b>Answers</b></p> +<hr> + <p>Only the answer and value is required.</p> +</span> + + + + + spacer2_2 + + + Vertical + + + Expanding + + + + 20 + 41 + + + + + + + + frame6 + + + Box + + + Sunken + + + + unnamed + + + + layout11 + + + + unnamed + + + + layout3 + + + + unnamed + + + + _answerPoints + + + + + spacer9 + + + Horizontal + + + Expanding + + + + 31 + 20 + + + + + + + + _answerText + + + + + textLabel1_2 + + + &Answer: + + + AlignTop|AlignRight + + + _answerText + + + + + textLabel2_3 + + + &Value: + + + AlignVCenter|AlignRight + + + _answerValue + + + + + layout7 + + + + unnamed + + + + + False + + + + + True + + + + _answerValue + + + + + + + textLabel3_2 + + + &Points: + + + AlignVCenter|AlignRight + + + _answerPoints + + + + + + + line2 + + + HLine + + + Sunken + + + Horizontal + + + + + layout17 + + + + unnamed + + + + + Answer + + + true + + + true + + + + + Value + + + true + + + true + + + + + Points + + + true + + + true + + + + _listAnswers + + + true + + + + + layout16 + + + + unnamed + + + + _buttonInsert + + + false + + + &Add + + + + + _buttonRemove + + + false + + + &Remove + + + + + spacer11 + + + Vertical + + + Fixed + + + + 20 + 10 + + + + + + _buttonUp + + + false + + + Move &Up + + + + + _buttonDown + + + false + + + Move &Down + + + + + spacer12 + + + Vertical + + + Expanding + + + + 20 + 21 + + + + + + + + + + + + + + + 789ced95bd6e83301485f73c8515b6a84a14a4b0547d844a1d2b551d8cb181947fdca1aafaeec5f75e830d51105397de230f9f50823987634e07f6faf2cc0ea75dafb9ce051319efd821f92ccbafb7f7a7efddfe1c5ed8f9c2c2909df70fbb7dc5040b642443a50c968411e21551291919ac01a5bdda1072c48e50227e200ebf95065b832ab2577b4445f7d584f4cf05a15270df0050c910b7c10923c4e38870a39890230a42899858c47f9688c33600156184988e08bbca08e979734285780c0671d231e6f1114423e2045622ac6422cd4ae4384aa646ca2a53590a1a27472d07c232f301cbd3620a5f052c6772589e725877065e9eaaaeead2aaa91bb3ea86a66dba610deaacfaae6f41e3a4bd1e56aaad8667d71b1c0838c8c981430e3c8ea71c2889290701393829284cc2cf414dbbc86fee02de79dff785f7c5dcfd85f70be7577c9f6da02a2b9342e9e650420ee374a0450edd94828614b49b83ce308b550766eedb1ed050077cf713bf05e9dcfd947ab0a105373a705d496291c3f60ee0066ab705b603f5e47e3b77bfa51e38fea77e0bf4a673803ac0fd16f029056c8158e620fc1640126e0b308bd577e07ad7fb1bcedfe840b1d9fb790b66a7119e475e0b2009b7059d9f829e9f46f63c5a75e0ff5bf0b7df829fc7dd2faa1761dd + + + + + _questionText + textChanged() + KControlAddEditBase + slotDataChanged() + + + _questionPicture + urlSelected(const QString&) + KControlAddEditBase + slotPreviewImage(const QString&) + + + _questionType + activated(int) + KControlAddEditBase + slotQuestionTypeChanged(int) + + + _buttonInsert + clicked() + KControlAddEditBase + slotAddAnswer() + + + _buttonRemove + clicked() + KControlAddEditBase + slotRemoveAnswer() + + + _buttonUp + clicked() + KControlAddEditBase + slotMoveUpAnswer() + + + _buttonDown + clicked() + KControlAddEditBase + slotMoveDownAnswer() + + + _listAnswers + selectionChanged(QListViewItem*) + KControlAddEditBase + slotAnswerSelected(QListViewItem*) + + + _answerText + textChanged() + KControlAddEditBase + slotDataChanged() + + + + _answerText + _answerValue + _answerPoints + _listAnswers + _buttonInsert + _buttonRemove + _buttonUp + _buttonDown + _questionText + _questionPicture + _questionType + _questionPoint + _questionTime + _questionTip + _questionExplain + + + slotAddAnswer() + slotRemoveAnswer() + slotMoveUpAnswer() + slotMoveDownAnswer() + slotPreviewImage(const QString &) + slotQuestionTypeChanged(int index) + slotDataChanged() + slotAnswerSelected(QListViewItem *) + + + + kurlrequester.h + klineedit.h + kpushbutton.h + kcombobox.h + knuminput.h + knuminput.h + knuminput.h + knuminput.h + knuminput.h + knuminput.h + klistview.h + + diff --git a/keduca/keducabuilder/kcontrolheader.cpp b/keduca/keducabuilder/kcontrolheader.cpp new file mode 100644 index 00000000..d7a2090a --- /dev/null +++ b/keduca/keducabuilder/kcontrolheader.cpp @@ -0,0 +1,376 @@ +/*************************************************************************** + kcontrolheader.cpp - description + ------------------- + begin : Tue May 29 2001 + copyright : (C) 2001 by Javier Campos + email : javi@asyris.org +***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#include "kcontrolheader.h" +#include "kcontrolheader.moc" + +#include +#include +#include +#include +#include + +#include +#include + +KControlHeader::KControlHeader(FileRead *keducaFile, QWidget *parent, const char *name ) : KDialogBase(Swallow, i18n("Document Information"), Ok|Cancel, Ok, parent, name, true, true) +{ + _keducaFile = keducaFile; + init(); + configRead(); +} + +KControlHeader::~KControlHeader(){} + +/** Init graphical interface */ +void KControlHeader::init() +{ + QWidget *mainView = new QWidget(this); + + QVBoxLayout *Form2Layout = new QVBoxLayout( mainView ); + Form2Layout->setSpacing( 6 ); + Form2Layout->setMargin( 0 ); + + QFrame *Frame16 = new QFrame( mainView, "Frame16" ); + Frame16->setMinimumSize( QSize( 0, 50 ) ); + Frame16->setMaximumSize( QSize( 32767, 50 ) ); + Frame16->setFrameShape( QFrame::Box ); + Frame16->setFrameShadow( QFrame::Plain ); + Frame16->setPalette( QPalette( QColor(255, 255, 255) ) ); + QHBoxLayout *Frame16Layout = new QHBoxLayout( Frame16 ); + Frame16Layout->setSpacing( 6 ); + Frame16Layout->setMargin( 1 ); + + QFrame *Frame17 = new QFrame( Frame16, "Frame17" ); + Frame17->setMinimumSize( QSize( 125, 0 ) ); + Frame17->setMaximumSize( QSize( 125, 32767 ) ); + Frame17->setFrameShape( QFrame::NoFrame ); + Frame17->setFrameShadow( QFrame::Raised ); + Frame17->setBackgroundPixmap( QPixmap(locate("appdata","pics/bk_frame.png") ) ); + QVBoxLayout *Frame17Layout = new QVBoxLayout( Frame17 ); + Frame17Layout->setSpacing( 6 ); + Frame17Layout->setMargin( 11 ); + + QLabel *TextLabel1 = new QLabel( Frame17, "TextLabel1" ); + TextLabel1->setText( ""+i18n("Information")+"" ); + TextLabel1->setBackgroundPixmap( QPixmap(locate("appdata","pics/bk_frame.png") ) ); + Frame17Layout->addWidget( TextLabel1 ); + Frame16Layout->addWidget( Frame17 ); + QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ); + Frame16Layout->addItem( spacer ); + + QLabel *TextLabel2 = new QLabel( Frame16, "TextLabel2" ); + TextLabel2->setText( i18n( "Description and rules of the project." ) ); + TextLabel2->setPalette( QPalette( QColor(255, 255, 255) ) ); + Frame16Layout->addWidget( TextLabel2 ); + Form2Layout->addWidget( Frame16 ); + + QGroupBox *GroupBox7 = new QGroupBox( mainView, "GroupBox7" ); + GroupBox7->setTitle( i18n( "Description" ) ); + GroupBox7->setColumnLayout(0, Qt::Vertical ); + GroupBox7->layout()->setSpacing( 0 ); + GroupBox7->layout()->setMargin( 0 ); + QVBoxLayout *GroupBox7Layout = new QVBoxLayout( GroupBox7->layout() ); + GroupBox7Layout->setAlignment( Qt::AlignTop ); + GroupBox7Layout->setSpacing( 6 ); + GroupBox7Layout->setMargin( 11 ); + + QGridLayout *Layout13 = new QGridLayout; + Layout13->setSpacing( 6 ); + Layout13->setMargin( 0 ); + + QLabel *TextLabel10 = new QLabel( GroupBox7, "TextLabel10" ); + TextLabel10->setText( i18n( "Type:" )); + TextLabel10->setAlignment( int( QLabel::AlignVCenter | QLabel::AlignRight ) ); + + Layout13->addWidget( TextLabel10, 2, 0 ); + + QHBoxLayout *Layout12 = new QHBoxLayout; + Layout12->setSpacing( 6 ); + Layout12->setMargin( 0 ); + + _headerType = new KComboBox( FALSE, GroupBox7, "_headerType" ); + Layout12->addWidget( _headerType ); + + QLabel *TextLabel11 = new QLabel( GroupBox7, "TextLabel11" ); + TextLabel11->setText( i18n( "Level:" )); + TextLabel11->setAlignment( int( QLabel::AlignVCenter | QLabel::AlignRight ) ); + Layout12->addWidget( TextLabel11 ); + + _headerLevel = new KComboBox( FALSE, GroupBox7, "_headerLevel" ); + Layout12->addWidget( _headerLevel ); + Layout13->addLayout( Layout12, 2, 1 ); + + QLabel *TextLabel12 = new QLabel( GroupBox7, "TextLabel12" ); + TextLabel12->setText( i18n( "Language:" )); + TextLabel12->setAlignment( int( QLabel::AlignVCenter | QLabel::AlignRight ) ); + Layout13->addWidget( TextLabel12, 3, 0 ); + + _headerLang = new KLanguageCombo( GroupBox7, "_headerLang" ); + loadCountryList( _headerLang ); + Layout13->addWidget( _headerLang, 3, 1 ); + + QLabel *TextLabel9 = new QLabel( GroupBox7, "TextLabel9" ); + TextLabel9->setText( i18n( "Category:" )); + TextLabel9->setAlignment( int( QLabel::AlignVCenter | QLabel::AlignRight ) ); + + Layout13->addWidget( TextLabel9, 1, 0 ); + + _headerCategory = new KComboBox( true, GroupBox7, "_headerCategory" ); + Layout13->addWidget( _headerCategory, 1, 1 ); + + _headerTitle = new QLineEdit( GroupBox7, "_headerTitle" ); + Layout13->addWidget( _headerTitle, 0, 1 ); + + QLabel *TextLabel8 = new QLabel( GroupBox7, "TextLabel8" ); + TextLabel8->setText( i18n( "Title:" )); + TextLabel8->setAlignment( int( QLabel::AlignVCenter | QLabel::AlignRight ) ); + + Layout13->addWidget( TextLabel8, 0, 0 ); + GroupBox7Layout->addLayout( Layout13 ); + Form2Layout->addWidget( GroupBox7 ); + + QGroupBox *GroupBox8 = new QGroupBox( mainView, "GroupBox8" ); + GroupBox8->setTitle( i18n( "Picture" ) ); + GroupBox8->setColumnLayout(0, Qt::Vertical ); + GroupBox8->layout()->setSpacing( 0 ); + GroupBox8->layout()->setMargin( 0 ); + QHBoxLayout *GroupBox8Layout = new QHBoxLayout( GroupBox8->layout() ); + GroupBox8Layout->setAlignment( Qt::AlignTop ); + GroupBox8Layout->setSpacing( 6 ); + GroupBox8Layout->setMargin( 11 ); + + QLabel *TextLabel13 = new QLabel( GroupBox8, "TextLabel13" ); + TextLabel13->setText( i18n( "Default picture:" )); + GroupBox8Layout->addWidget( TextLabel13 ); + + _headerPicture = new KURLRequester( GroupBox8, "_headerPicture" ); + GroupBox8Layout->addWidget( _headerPicture ); + Form2Layout->addWidget( GroupBox8 ); + + QGroupBox *GroupBox6 = new QGroupBox( mainView, "GroupBox6" ); + GroupBox6->setTitle( i18n( "Author" ) ); + GroupBox6->setColumnLayout(0, Qt::Vertical ); + GroupBox6->layout()->setSpacing( 0 ); + GroupBox6->layout()->setMargin( 0 ); + QGridLayout *GroupBox6Layout = new QGridLayout( GroupBox6->layout() ); + GroupBox6Layout->setAlignment( Qt::AlignTop ); + GroupBox6Layout->setSpacing( 6 ); + GroupBox6Layout->setMargin( 11 ); + + _headerName = new QLineEdit( GroupBox6, "_headerName" ); + + GroupBox6Layout->addWidget( _headerName, 0, 1 ); + + _headerEmail = new QLineEdit( GroupBox6, "_headerEmail" ); + + GroupBox6Layout->addWidget( _headerEmail, 1, 1 ); + + QLabel *TextLabel7 = new QLabel( GroupBox6, "TextLabel7" ); + TextLabel7->setText( i18n( "Web page:" )); + TextLabel7->setAlignment( int( QLabel::AlignVCenter | QLabel::AlignRight ) ); + + GroupBox6Layout->addWidget( TextLabel7, 2, 0 ); + + QLabel *TextLabel6 = new QLabel( GroupBox6, "TextLabel6" ); + TextLabel6->setText( i18n( "Email:" )); + TextLabel6->setAlignment( int( QLabel::AlignVCenter | QLabel::AlignRight ) ); + + GroupBox6Layout->addWidget( TextLabel6, 1, 0 ); + + QLabel *TextLabel5 = new QLabel( GroupBox6, "TextLabel5" ); + TextLabel5->setText( i18n( "Name:" )); + TextLabel5->setAlignment( int( QLabel::AlignVCenter | QLabel::AlignRight ) ); + + GroupBox6Layout->addWidget( TextLabel5, 0, 0 ); + + _headerWWW = new QLineEdit( GroupBox6, "_headerWWW" ); + + GroupBox6Layout->addWidget( _headerWWW, 2, 1 ); + Form2Layout->addWidget( GroupBox6 ); + + // tab order + setTabOrder( _headerTitle, _headerCategory ); + setTabOrder( _headerCategory, _headerType ); + setTabOrder( _headerType, _headerLevel ); + setTabOrder( _headerLevel, _headerLang ); + setTabOrder( _headerLang, _headerPicture->lineEdit() ); + setTabOrder( _headerPicture->lineEdit(), _headerPicture->comboBox() ); + setTabOrder( _headerPicture->comboBox(), _headerName ); + setTabOrder( _headerName, _headerEmail ); + setTabOrder( _headerEmail, _headerWWW ); + + // set a sensible focus + _headerTitle->setFocus(); + + setMainWidget(mainView); +} + +/** Insert header */ +void KControlHeader::insertHeader() +{ + QStringList tmpResult = _defaultCategories.grep( _headerCategory->currentText() ); + if( tmpResult.count() == 0 ) + { + KConfig *appconfig = KGlobal::config(); + _defaultCategories.append( _headerCategory->currentText() ); + appconfig->setGroup("General"); + appconfig->writeEntry( "Categories", _defaultCategories); + appconfig->sync(); + } + _keducaFile->setHeader( "category", _headerCategory->currentText() ); + _keducaFile->setHeader( "title", _headerTitle->text() ); + _keducaFile->setHeader( "image", _headerPicture->url() ); + _keducaFile->setHeader( "type", QString().setNum( _headerType->currentItem() + 1 ) ); + _keducaFile->setHeader( "level", QString().setNum( _headerLevel->currentItem() + 1 ) ); + _keducaFile->setHeader( "language", _headerLang->currentTag() ); + _keducaFile->setHeader( "name", _headerName->text() ); + _keducaFile->setHeader( "email", _headerEmail->text() ); + _keducaFile->setHeader( "www", _headerWWW->text() ); +} + +/** Load country list */ +void KControlHeader::loadCountryList(KLanguageCombo *combo) +{ + QString sub = QString::fromLatin1("l10n/"); + + // clear the list + combo->clear(); + + QStringList regionlist = KGlobal::dirs()->findAllResources("locale", sub + QString::fromLatin1("*.desktop")); + regionlist.sort(); + + for ( QStringList::ConstIterator it = regionlist.begin(); + it != regionlist.end(); + ++it ) + { + QString tag = *it; + int index; + + index = tag.findRev('/'); + if (index != -1) tag = tag.mid(index + 1); + + index = tag.findRev('.'); + if (index != -1) tag.truncate(index); + + KSimpleConfig entry(*it); + entry.setGroup(QString::fromLatin1("KCM Locale")); + QString name = entry.readEntry(QString::fromLatin1("Name")); + + combo->insertSubmenu( name, '-' + tag, sub ); + } + + // add all languages to the list + QStringList countrylist = KGlobal::dirs()->findAllResources("locale", sub + QString::fromLatin1("*/entry.desktop")); + countrylist.sort(); + + for ( QStringList::ConstIterator it = countrylist.begin(); + it != countrylist.end(); ++it ) + { + KSimpleConfig entry(*it); + entry.setGroup(QString::fromLatin1("KCM Locale")); + QString name = entry.readEntry(QString::fromLatin1("Name")); + QString submenu = '-' + entry.readEntry(QString::fromLatin1("Region")); + + QString tag = *it; + int index = tag.findRev('/'); + tag.truncate(index); + index = tag.findRev('/'); + tag = tag.mid(index+1); + combo->insertLanguage(tag, name, sub, submenu); + } +} + +/** Ok push */ +void KControlHeader::slotOk() +{ + insertHeader(); + configWrite(); + accept(); +} + +/** Read settings */ +void KControlHeader::configRead() +{ + KConfig *config = new KConfig("emaildefaults"); + KConfig *appconfig = KGlobal::config(); + + config->setGroup("UserInfo"); + + if( _keducaFile->getHeader( "name" ).isEmpty() ) + _headerName->setText(config->readEntry("FullName", QString::null )); + else + _headerName->setText( _keducaFile->getHeader("name") ); + + if( _keducaFile->getHeader( "email" ).isEmpty() ) + _headerEmail->setText(config->readEntry("EmailAddress", QString::null )); + else + _headerEmail->setText( _keducaFile->getHeader("email") ); + + _headerWWW->setText( _keducaFile->getHeader("www") ); + + if( !_keducaFile->getHeader("language").isEmpty() ) + { + _headerLang->setCurrentItem( _keducaFile->getHeader("language") ); + } + else + { + config->setGroup("Locale"); + _headerLang->setCurrentItem( config->readEntry("Country") ); + } + + appconfig->setGroup("General"); + _defaultCategories = appconfig->readListEntry("Categories"); + if( _defaultCategories.count() == 0 ) + { + _defaultCategories.append(i18n("Computers")); + } + _defaultCategories.sort(); + _headerCategory->insertStringList( _defaultCategories ); + if( !_keducaFile->getHeader( "category" ).isEmpty() ) _headerCategory->setEditText( _keducaFile->getHeader("category") ); + + _headerType->insertItem( i18n("Test") ); + _headerType->insertItem( i18n("Test with Question Points") ); + _headerType->insertItem( i18n("Test with Answers Points") ); + _headerType->insertItem( i18n("Slidershow") ); + _headerType->insertItem( i18n("Exam") ); + _headerType->insertItem( i18n("Psychotechnic Test") ); + if( QString(_keducaFile->getHeader("type")).toInt() > 0 ) _headerType->setCurrentItem( QString(_keducaFile->getHeader("type")).toInt() -1 ); + + _headerLevel->insertItem( i18n("Easy") ); + _headerLevel->insertItem( i18n("Normal") ); + _headerLevel->insertItem( i18n("Expert") ); + _headerLevel->insertItem( i18n("Supreme") ); + if( QString(_keducaFile->getHeader("level")).toInt() >0 ) _headerLevel->setCurrentItem( QString(_keducaFile->getHeader("level")).toInt() -1 ); + + _headerPicture->setURL( _keducaFile->getHeader("image") ); + _headerTitle->setText( _keducaFile->getHeader("title") ); + + appconfig->setGroup("kcontrolheader"); + QSize *defaultSize = new QSize(500,400); + resize( appconfig->readSizeEntry("Geometry", defaultSize ) ); + delete config; +} + +/** Write settings */ +void KControlHeader::configWrite() +{ + KConfig *config = KGlobal::config(); + config->setGroup("kcontrolheader"); + config->writeEntry("Geometry", size() ); + config->sync(); +} diff --git a/keduca/keducabuilder/kcontrolheader.h b/keduca/keducabuilder/kcontrolheader.h new file mode 100644 index 00000000..86752ae0 --- /dev/null +++ b/keduca/keducabuilder/kcontrolheader.h @@ -0,0 +1,86 @@ +/*************************************************************************** + kcontrolheader.h - description + ------------------- + begin : Tue May 29 2001 + copyright : (C) 2001 by Javier Campos + email : javi@asyris.org +***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#ifndef KCONTROLHEADER_H +#define KCONTROLHEADER_H + +#include "../libkeduca/fileread.h" +#include "klangcombo.h" + +#include +#include + + +/**Information header + * Options Dialog for KEduca Document. + * Will be called for each new KEduca Document and from the Editor (class KEducaBuilder) + *@author Javier Campos + */ + +class KControlHeader : public KDialogBase { + Q_OBJECT + +public: + KControlHeader(FileRead *keducaFile, QWidget *parent=0, const char *name=0); + ~KControlHeader(); + +private: + + // Private attributes + + /** Keduca pointer */ + FileRead *_keducaFile; + /** Title */ + QLineEdit *_headerTitle; + /** Header type */ + KComboBox *_headerType; + /** Header category */ + KComboBox *_headerCategory; + /** Header level */ + KComboBox *_headerLevel; + /** Header lang */ + KLanguageCombo *_headerLang; + /** Header picture */ + KURLRequester *_headerPicture; + /** Header name */ + QLineEdit *_headerName; + /** Header email */ + QLineEdit *_headerEmail; + /** Header www */ + QLineEdit *_headerWWW; + /** Default categories */ + QStringList _defaultCategories; + + // Private methods + + /** Init graphical interface */ + void init(); + /** Insert header */ + void insertHeader(); + /** Load country list */ + void loadCountryList(KLanguageCombo *combo); + /** Write settings */ + void configWrite(); + /** Read settings */ + void configRead(); + +private slots: + /** Ok push */ + void slotOk(); +}; + +#endif diff --git a/keduca/keducabuilder/kcontrolheaderbase.ui b/keduca/keducabuilder/kcontrolheaderbase.ui new file mode 100644 index 00000000..04f2411b --- /dev/null +++ b/keduca/keducabuilder/kcontrolheaderbase.ui @@ -0,0 +1,472 @@ + +MyDialog + + + MyDialog + + + + 0 + 0 + 512 + 534 + + + + true + + + + unnamed + + + + frame3 + + + + 0 + 50 + + + + + 32767 + 50 + + + + + 255 + 255 + 255 + + + + Box + + + Sunken + + + + unnamed + + + 2 + + + + frame4 + + + + 125 + 0 + + + + + 125 + 32767 + + + + image0 + + + NoFrame + + + Raised + + + + unnamed + + + + textLabel1 + + + <b style="text-decoration:underline;">Information</b> + + + + + + + spacer2 + + + Horizontal + + + Expanding + + + + 60 + 21 + + + + + + textLabel6 + + + Description and rules of the project. + + + + + + + groupBox1 + + + Description + + + + unnamed + + + + textLabel11 + + + Title: + + + AlignVCenter|AlignRight + + + + + textLabel9 + + + Language: + + + AlignVCenter|AlignRight + + + + + textLabel10 + + + Category: + + + AlignVCenter|AlignRight + + + + + textLabel7 + + + Type: + + + AlignVCenter|AlignRight + + + + + _headerLang + + + + + _headerTitle + + + + + layout2 + + + + unnamed + + + + _headerType + + + + + spacer4 + + + Horizontal + + + Expanding + + + + 61 + 21 + + + + + + textLabel8 + + + Level: + + + AlignVCenter|AlignRight + + + + + _headerLevel + + + + + + + _headerCategory + + + true + + + + + + + groupBox2 + + + Picture + + + + unnamed + + + + textLabel2 + + + Default picture: + + + AlignJustify|AlignVCenter + + + + + _headerPicture + + + + + + + groupBox3 + + + Author + + + + unnamed + + + + textLabel3 + + + Name: + + + AlignVCenter|AlignRight + + + + + _headerName + + + + + _headerWWW + + + + + _headerEmail + + + + + textLabel5 + + + Web page: + + + AlignVCenter|AlignRight + + + + + textLabel4 + + + Email: + + + AlignVCenter|AlignRight + + + + + + + spacer3 + + + Vertical + + + Expanding + + + + 31 + 40 + + + + + + line1 + + + HLine + + + Sunken + + + Horizontal + + + + + Layout1 + + + + unnamed + + + 0 + + + 6 + + + + Horizontal Spacing2 + + + Horizontal + + + Expanding + + + + 20 + 20 + + + + + + buttonOk + + + &OK + + + true + + + true + + + + + buttonCancel + + + &Cancel + + + true + + + + + + + + + + + 789ced95bd6e83301485f73c8515b6a84a14a4b0547d844a1d2b551d8cb181947fdca1aafaeec5f75e830d51105397de230f9f50823987634e07f6faf2cc0ea75dafb9ce051319efd821f92ccbafb7f7a7efddfe1c5ed8f9c2c2909df70fbb7dc5040b642443a50c968411e21551291919ac01a5bdda1072c48e50227e200ebf95065b832ab2577b4445f7d584f4cf05a15270df0050c910b7c10923c4e38870a39890230a42899858c47f9688c33600156184988e08bbca08e979734285780c0671d231e6f1114423e2045622ac6422cd4ae4384aa646ca2a53590a1a27472d07c232f301cbd3620a5f052c6772589e725877065e9eaaaeead2aaa91bb3ea86a66dba610deaacfaae6f41e3a4bd1e56aaad8667d71b1c0838c8c981430e3c8ea71c2889290701393829284cc2cf414dbbc86fee02de79dff785f7c5dcfd85f70be7577c9f6da02a2b9342e9e650420ee374a0450edd94828614b49b83ce308b550766eedb1ed050077cf713bf05e9dcfd947ab0a105373a705d496291c3f60ee0066ab705b603f5e47e3b77bfa51e38fea77e0bf4a673803ac0fd16f029056c8158e620fc1640126e0b308bd577e07ad7fb1bcedfe840b1d9fb790b66a7119e475e0b2009b7059d9f829e9f46f63c5a75e0ff5bf0b7df829fc7dd2faa1761dd + + + + + buttonOk + clicked() + MyDialog + accept() + + + buttonCancel + clicked() + MyDialog + reject() + + + + _headerTitle + _headerCategory + _headerType + _headerLevel + _headerLang + _headerPicture + _headerName + _headerEmail + _headerWWW + buttonOk + buttonCancel + + + + klineedit.h + klineedit.h + klineedit.h + kpushbutton.h + klineedit.h + klineedit.h + klineedit.h + + diff --git a/keduca/keducabuilder/keducabuilder.cpp b/keduca/keducabuilder/keducabuilder.cpp new file mode 100644 index 00000000..08487cc9 --- /dev/null +++ b/keduca/keducabuilder/keducabuilder.cpp @@ -0,0 +1,600 @@ +/*************************************************************************** + keducabuilder.cpp - description + ------------------- + begin : Sat May 26 2001 + copyright : (C) 2001 by Javier Campos + email : javi@asyris.org +***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#include "keducabuilder.h" +#include "keducabuilder.moc" + +#include "kcontroladdedit.h" +#include "kcontrolheader.h" +#include "keducaeditorstartdialog.h" +#include "../libkeduca/kgallerydialog.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +static const char* const keducabuilder_data[] = { + "15 16 4 1", + "a c #0000ff", + "# c #008183", + "b c #c5c2c5", + ". c #ffffff", + "...............", + ".#############.", + ".#...........#.", + ".#...aaaa....#.", + ".#..aa.baa...#.", + ".#......aa...#.", + ".#.....aab...#.", + ".#....aab....#.", + ".#....aab....#.", + ".#.....b.....#.", + ".#....aa.....#.", + ".#....aa.....#.", + ".#...........#.", + ".#...........#.", + ".#############.", + "..............."}; + +KEducaBuilder::KEducaBuilder(QWidget* parent, const char *name, WFlags f ) + : KMainWindow(parent,name,f), + _nativeFormat("application/x-edu") +{ + _keducaFile = new FileRead(); + initMenuBar(); + init(); + configRead(); + setIcon( KGlobal::iconLoader()->loadIcon("control.png", + KIcon::Small) ); + _isOpenFile = false; +} + +KEducaBuilder::~KEducaBuilder() +{ + delete _keducaFile; +} + +/** Init graphical interface */ +void KEducaBuilder::init() +{ + QWidget *mainView = new QWidget(this, "mainview"); + + QVBoxLayout *form2Layout = new QVBoxLayout( mainView ); + form2Layout->setSpacing( 2 ); + form2Layout->setMargin( 0 ); + + _split = new QSplitter( mainView ); + _split->setOrientation( QSplitter::Vertical ); + + _listAnswer = new KListBox( _split, "_listAnswer" ); + _listAnswer->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)7, (QSizePolicy::SizeType)7, _listAnswer->sizePolicy().hasHeightForWidth() ) ); + connect( _listAnswer, SIGNAL( highlighted(QListBoxItem *) ), this, SLOT( slotPreview(QListBoxItem *) ) ); + connect( _listAnswer, SIGNAL( doubleClicked(QListBoxItem *) ), this, SLOT( slotEditbyList(QListBoxItem *) ) ); + + _preview = new QTextView( _split, "_preview" ); + _preview->setFrameShape( QTextView::NoFrame ); + _preview->setLineWidth( 1 ); + + form2Layout->addWidget( _split ); + + setCentralWidget( mainView ); + if (!initialGeometrySet()) + resize( QSize(500, 400).expandedTo(minimumSizeHint())); + setupGUI( ToolBar | Keys | StatusBar | Create, "keducabuilderui.rc" ); + setAutoSaveSettings(); +} + +/** Init menu bar settings */ +void KEducaBuilder::initMenuBar() +{ + KStdAction::openNew(this, SLOT( slotFileOpenNew() ), actionCollection()); + KStdAction::open (this, SLOT( slotFileOpen() ), actionCollection()); + (void)new KAction(i18n("Open &Gallery..."), 0, 0, this, SLOT( slotGallery() ), actionCollection(), "open_gallery"); + _recentFiles = KStdAction::openRecent(this, SLOT ( slotFileOpenURL(const KURL &)), actionCollection()); + KStdAction::save (this, SLOT( slotFileSave() ), actionCollection()); + KStdAction::saveAs (this, SLOT( slotFileSaveAs() ), actionCollection()); + KStdAction::print (this, SLOT( slotFilePrint() ), actionCollection()); + (void)new KAction(i18n("Document Info"), "info", 0, this, SLOT( slotHeader() ), actionCollection(), "info_doc"); + KStdAction::quit(this, SLOT( close() ), actionCollection()); + + (void)new KAction(i18n("&Add..."), "addquestion", 0, this, SLOT( slotAdd() ), actionCollection(), "question_add"); + (void)new KAction(i18n("&Edit..."), "editquestion", 0, this, SLOT( slotEdit() ), actionCollection(), "question_edit"); + (void)new KAction(i18n("&Remove"), "delquestion", 0, this, SLOT( slotRemove() ), actionCollection(), "question_remove"); + (void)new KAction(i18n("&Up"), "up", 0, this, SLOT( slotUp() ), actionCollection(), "question_up"); + (void)new KAction(i18n("&Down"), "down", 0, this, SLOT( slotDown() ), actionCollection(), "question_down"); +} + +/** Delete current document and start new */ +void KEducaBuilder::slotFileOpenNew() +{ + if (!currentFileMayBeReplaced()) + return; + + if( _keducaFile ) delete _keducaFile; + _listAnswer->clear(); + _preview->setText("

"+i18n("Welcome To KEduca!")+"

"+ + i18n("Add a new Question by using the Edit Menu or by choosing one of the icons above.")+ + "
"); + _keducaFile = new FileRead(); + _isOpenFile = false; + // ask for meta information + slotHeader(); +} + +/** Open new document. */ +void KEducaBuilder::slotFileOpen() +{ + KURL url = KFileDialog::getOpenURL( QString::null, _nativeFormat, this, i18n("Open Educa File") ); + + if( !url.isEmpty() ) + slotFileOpenURL( url ); +} + +/** Open new file */ +void KEducaBuilder::slotFileOpenURL( const KURL &url ) +{ + if (!currentFileMayBeReplaced()) + return; + + QPixmap image0( ( const char** ) keducabuilder_data ); + delete _keducaFile; + _keducaFile = new FileRead(); + if( !_keducaFile->openFile(url) ) { return; } + _recentFiles->addURL( url ); + _listAnswer->clear(); + _isOpenFile = true; + + _keducaFile->recordFirst(); + while( !_keducaFile->recordEOF() ) + { + _listAnswer->insertItem( image0, _keducaFile->getQuestion( FileRead::QF_TEXT ) ); + _keducaFile->recordNext(); + } +} + +/** Item select */ +void KEducaBuilder::slotPreview( QListBoxItem *item ) +{ +// bool match = false; + QString tmpListanswer; + + // FIND THE SELECT RECORD + if( !item ) return; + +// kdDebug() << "Item : " << _listAnswer->currentItem() <recordAt( _listAnswer->currentItem() ); + + // START THE PREVIEW VALUES + tmpListanswer = "

" + i18n("Answers") + "


"; + tmpListanswer += "

"; + + tmpListanswer +=""; + _keducaFile->recordAnswerFirst(); + while( !_keducaFile->recordAnswerEOF() ) + { + tmpListanswer += ""; + tmpListanswer += ""; + tmpListanswer += ""; + _keducaFile->recordAnswerNext(); + }; + tmpListanswer += "
" : tmpListanswer += "#b84747>"; + if( _keducaFile->getQuestionInt( FileRead::QF_TYPE ) == 3 ) + { + tmpListanswer += "" + + _keducaFile->getAnswer( FileRead::AF_POINT ) + + ""; + } + tmpListanswer += "" : tmpListanswer += "#eadada>"; + tmpListanswer += ""+_keducaFile->getAnswer( FileRead::AF_TEXT )+""; + tmpListanswer += "
"; + + if( !_keducaFile->getQuestion( FileRead::QF_PICTURE ).isEmpty() ) + { + tmpListanswer += ""; + tmpListanswer += "
" + i18n("Question Image") + "
"; + tmpListanswer += _keducaFile->getQuestion( FileRead::QF_PICTURE ) + "
"; + }; + + if( _keducaFile->getQuestionInt( FileRead::QF_POINTS ) > 0 ) + { + tmpListanswer += "

" + i18n("Question point") + ": "; + tmpListanswer += _keducaFile->getQuestion( FileRead::QF_POINTS ); + } + + if( _keducaFile->getQuestionInt( FileRead::QF_TIME ) > 0 ) + { + tmpListanswer += "

"+i18n("Time")+": "; + tmpListanswer += _keducaFile->getQuestion( FileRead::QF_TIME ); + tmpListanswer += i18n(" seconds

"); + } + + if( !_keducaFile->getQuestion( FileRead::QF_TIP ).isEmpty() ) + { + tmpListanswer += "

" + i18n("Tip") +": "; + tmpListanswer += _keducaFile->getQuestion( FileRead::QF_TIP ); + tmpListanswer += "

"; + } + + if( !_keducaFile->getQuestion( FileRead::QF_EXPLAIN ).isEmpty() ) + { + tmpListanswer += "

" + + i18n("Explain") + ":" + + _keducaFile->getQuestion( FileRead::QF_EXPLAIN ) + + "

"; + } + + _preview->setText( tmpListanswer ); +} + +/** Read config data */ +void KEducaBuilder::configRead() +{ + KConfig *config = KGlobal::config(); + + config->setGroup( "keducacontrol" ); + applyMainWindowSettings( config, "keducacontrol" ); + _split->setSizes( config->readIntListEntry("Splitter_size") ); + _recentFiles->loadEntries(config); +} + +/** Write settings */ +void KEducaBuilder::configWrite() +{ + KConfig *config = KGlobal::config(); + + config->setGroup( "keducacontrol" ); + saveMainWindowSettings( config, "keducacontrol" ); + config->writeEntry("Splitter_size", _split->sizes() ); + _recentFiles->saveEntries(config); + config->sync(); +} + +bool KEducaBuilder::currentFileMayBeReplaced() +{ + if (_keducaFile->changed()) + { + int res = KMessageBox::warningYesNoCancel( widget(), + // ask the user to save + i18n( "The document \"%1\" has been modified.\n" + "Do you want to save it?" ).arg( _keducaFile->getCurrentURL().fileName() ), + i18n( "Save Document?" ), KStdGuiItem::save(), KStdGuiItem::discard() ); + switch (res) + { + case KMessageBox::Yes: + // If the saving was successful, then the file may be replaced + return fileSave(); + break; + case KMessageBox::Cancel: + // User cancels operation, do not replace the file + return false; + break; + default: ; + } + } + + // file was not changed, it may be replaced + return true; +} + +/** Close the window */ +bool KEducaBuilder::queryClose () +{ + if (_keducaFile) { + if (!currentFileMayBeReplaced()) + return false; + } + configWrite(); + return( TRUE ); +} + +/** Add question */ +void KEducaBuilder::slotAdd() +{ + QPixmap image0( ( const char** ) keducabuilder_data ); + + KControlAddEdit edit(this); + edit.init( _keducaFile, false ); + if( !edit.exec() ) return; + + _listAnswer->insertItem( image0, _keducaFile->getQuestion( FileRead::QF_TEXT ) ); + _listAnswer->setCurrentItem( _listAnswer->count()-1 ); + slotPreview( _listAnswer->item(_listAnswer->currentItem()) ); +} + +/** Edit question */ +void KEducaBuilder::slotEdit() +{ + if( _listAnswer->currentItem() == -1 ) return; + + QPixmap image0( ( const char** ) keducabuilder_data ); + + KControlAddEdit edit(this); + edit.init( _keducaFile, true ); + if( edit.exec() ) + { + _listAnswer->changeItem( image0, _keducaFile->getQuestion( FileRead::QF_TEXT ), _listAnswer->currentItem() ); + slotPreview( _listAnswer->item(_listAnswer->currentItem()) ); + } +} + +/** Edit question */ +void KEducaBuilder::slotRemove() +{ + if( _listAnswer->currentItem() == -1 ) return; + _keducaFile->recordDelete(); + _listAnswer->removeItem( _listAnswer->currentItem() ); +} + +/** Up record */ +void KEducaBuilder::slotUp() +{ + int current = _listAnswer->currentItem(); + + if( current < 1 ) return; + QPixmap image0( ( const char** ) keducabuilder_data ); + + _keducaFile->recordSwap( true ); + QString tmpString = _listAnswer->text( current-1 ); + _listAnswer->changeItem( image0, _listAnswer->text( current ), current-1 ); + _listAnswer->changeItem( image0, tmpString, current ); + _listAnswer->setCurrentItem( current-1 ); +} + +/** Down record */ +void KEducaBuilder::slotDown() +{ + int current = _listAnswer->currentItem(); + + if( current == -1 || current == (signed)(_listAnswer->count()-1) ) return; + QPixmap image0( ( const char** ) keducabuilder_data ); + + _keducaFile->recordSwap( true ); + QString tmpString = _listAnswer->text( current+1 ); + _listAnswer->changeItem( image0, _listAnswer->text( current ), current+1 ); + _listAnswer->changeItem( image0, tmpString, current ); + _listAnswer->setCurrentItem( current+1 ); +} + +/** Save file */ +void KEducaBuilder::slotFileSave() +{ + fileSave(); +} +bool KEducaBuilder::fileSave() +{ + if( !_isOpenFile ) { return fileSaveAs(); } + + if( checkSave() ) return _keducaFile->saveFile(); + return false; +} + +/** Save As... */ +void KEducaBuilder::slotFileSaveAs() +{ + fileSaveAs(); +} + +bool KEducaBuilder::fileSaveAs() +{ + if( !checkSave() ) return false; + + QCheckBox *saveCompressedCheckBox = new QCheckBox( i18n( "Compress the file" ), 0 ); + saveCompressedCheckBox->setChecked( true ); + + KFileDialog *dialog=new KFileDialog(QString::null, QString::null, this, "file dialog", true, saveCompressedCheckBox); + dialog->setCaption( i18n("Save Document As") ); + dialog->setKeepLocation( true ); + dialog->setOperationMode( KFileDialog::Saving ); + QStringList mimeFilter(_nativeFormat); + dialog->setMimeFilter( mimeFilter, _nativeFormat ); + KURL newURL; + QString outputFormat (_nativeFormat); + + bool bOk; + do { + bOk=true; + if(dialog->exec()==QDialog::Accepted) { + newURL=dialog->selectedURL(); + outputFormat=dialog->currentMimeFilter(); + } + else + { + bOk = false; + break; + } + kdDebug()<<"Requested saving to file "<property( "X-KDE-NativeExtension" ).toString(); + kdDebug() << "KEducaBuilder::slotFileSaveAs outputFormat=" << outputFormat << " extension=" << extension << endl; + newURL.setPath( newURL.path() + extension ); + } + + if ( KIO::NetAccess::exists( newURL, false, this ) ) { // this file exists => ask for confirmation + bOk = KMessageBox::warningContinueCancel( this, + i18n("A document with this name already exists.\n"\ + "Do you want to overwrite it?"), + i18n("Warning"), i18n("Overwrite") ) == KMessageBox::Continue; + } + } while ( !bOk ); + + bool saveCompressed = saveCompressedCheckBox->isChecked(); + + delete dialog; + + if (bOk) { + bool copyImages = KMessageBox::questionYesNo( this, + i18n("If you want to share this document, it is better to copy the images to the same folder as the document.\n"\ + "Do you want to copy images?"), + i18n("Warning"), i18n("Copy Images"), i18n("Do Not Copy") ) == KMessageBox::Yes; + if (_keducaFile->saveFile( newURL, copyImages, saveCompressed ) ) { + _recentFiles->addURL(newURL); + // we saved the file, so the internal representation is now present as a file + _isOpenFile=true; + return true; + }else { + kdDebug()<< "saving of file failed" <getCurrentURL().fileName(); + if (file.isEmpty()) + file = i18n("Test"); + if(printer->setup(this, i18n("Print %1").arg(file))) + { + QPaintDeviceMetrics metrics(printer); + QPainter p; + + const int margin=20; + int yPos=0; + QString text; + + p.begin(printer); + p.setFont( QFont(font().family(), 12, QFont::Bold) ); + QFontMetrics fm = p.fontMetrics(); + + _keducaFile->recordFirst(); + while(!_keducaFile->recordEOF()) + { + p.drawText( 10, yPos+margin, metrics.width(), fm.lineSpacing(), + ExpandTabs | DontClip, _keducaFile->getQuestion(FileRead::QF_TEXT) ); + yPos += fm.lineSpacing(); + + p.drawLine(10, yPos+margin, metrics.width(), yPos+margin); + yPos += 2*fm.lineSpacing(); + + _keducaFile->recordNext(); + } + + p.end(); + } + + delete printer; + +} + +/** Header info */ +int KEducaBuilder::slotHeader() { + KControlHeader infoDoc(_keducaFile); + return infoDoc.exec(); +} + +/** Check if the current document can save */ +bool KEducaBuilder::checkSave() +{ + if( _keducaFile->getHeader("title").isEmpty() || + _keducaFile->getHeader("category").isEmpty() || + _keducaFile->getHeader("type").isEmpty() || + _keducaFile->getHeader("level").isEmpty() || + _keducaFile->getHeader("language").isEmpty() ) + { + if (KMessageBox::warningContinueCancel(this, i18n("Unable to save file.\n\nYou must complete the Document Info\n(Only the description is necessary)"), QString::null, i18n("Complete Document Info...")) + == KMessageBox::Continue) { + if (slotHeader()!=KControlHeader::Accepted) + return false; + }else + return false; + } + + if( _listAnswer->count() < 1 ) + { + if (KMessageBox::warningContinueCancel(this, i18n("Unable to save file.\n\nYou must insert a question."), + QString::null, i18n("Insert Question"))==KMessageBox::Continue) + slotAdd(); + else + return false; + } + + return true; +} + +bool KEducaBuilder::startChooser() { + KEducaEditorStartDialog startDialog(this, "KEducaEditorStartDialog", true); + + switch (startDialog.exec()) { + case KEducaEditorStartDialog::OpenDoc: + case KEducaEditorStartDialog::OpenRecentDoc: + slotFileOpenURL(startDialog.getURL()); + break; + case KEducaEditorStartDialog::NewDoc: + slotFileOpenNew(); + break; + case KEducaEditorStartDialog::Gallery: + initGallery(); + break; + default: + close(); + break; + } + + return true; +} +/** Init Internet Gallery Servers */ +void KEducaBuilder::initGallery(const KURL &urlFile) +{ + KGalleryDialog galleries; + + if( !urlFile.url().isEmpty() ) + galleries.putURL( urlFile ); + + if( galleries.exec() == QDialog::Accepted ) + slotFileOpenURL( galleries.getURL() ); +} + +/** Init Gallery */ +void KEducaBuilder::slotGallery() +{ + initGallery(); +} + +/** Double click in list, edit question */ +void KEducaBuilder::slotEditbyList(QListBoxItem *item) +{ + if( item ) + slotEdit(); +} diff --git a/keduca/keducabuilder/keducabuilder.h b/keduca/keducabuilder/keducabuilder.h new file mode 100644 index 00000000..74c5eb58 --- /dev/null +++ b/keduca/keducabuilder/keducabuilder.h @@ -0,0 +1,126 @@ +/*************************************************************************** + keducabuilder.h - description + ------------------- + begin : Sat May 26 2001 + copyright : (C) 2001 by Javier Campos + email : javi@asyris.org +***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#ifndef KEDUCABUILDER_H +#define KEDUCABUILDER_H + +#include "../libkeduca/fileread.h" + +#include + +#include +#include + +#include +#include + +/**Main control documents + * The Editor. This is the new main window of KEduca. + * You can edit a KEduca Document (i.e. Test/Examen) here. + *@author Javier Campos + */ + +class KEducaBuilder : public KMainWindow { + Q_OBJECT + +public: + KEducaBuilder(QWidget* parent=0, const char *name=0, WFlags f = WType_TopLevel | WDestructiveClose); + ~KEducaBuilder(); + /** start a dialog that asks the user what he wants to do to start*/ + bool startChooser(); + /** Init Internet Gallery Servers */ + void initGallery(const KURL &urlFile = KURL()); + +private: + + // Private methods + + /** Init graphical interface */ + void init(); + /** Init menu bar settings */ + void initMenuBar(); + /** Write settings */ + void configWrite(); + /** Read config data */ + void configRead(); + /** Check if the current document can save */ + bool checkSave(); + + /** Save the file, return false if save failed for any reason */ + bool fileSave(); + /** Save the file under a user-chosen filename, return false if save as + failed for any reason */ + bool fileSaveAs(); + + /** Ask the user if he wants to save the file if it has been changed. + Returns true if the file may be replaced (that is when he successfully saved it or said "Discard") */ + bool currentFileMayBeReplaced(); + + // Private attributes + + /** KEDUCA file */ + FileRead *_keducaFile; + /** Recent files */ + KRecentFilesAction *_recentFiles; + /** List of answers */ + KListBox *_listAnswer; + /** Preview */ + QTextView *_preview; + /** Main splitter */ + QSplitter *_split; + /** I open a file */ + bool _isOpenFile; + QString _nativeFormat; + +public slots: + /** Open new file */ + void slotFileOpenURL( const KURL &url ); + /** Delete current document and start new */ + void slotFileOpenNew(); + +private slots: + /** Open new document. */ + void slotFileOpen(); + /** Item select */ + void slotPreview( QListBoxItem *item ); + /** Close the window */ + bool queryClose(); + /** Edit question */ + void slotEdit(); + /** Add question */ + void slotAdd(); + /** Remove question */ + void slotRemove(); + /** Down record */ + void slotDown(); + /** Up record */ + void slotUp(); + /** Save As... */ + void slotFileSaveAs(); + /** Save file */ + void slotFileSave(); + /** Print file */ + void slotFilePrint(); + /** Header info */ + int slotHeader(); + /** Init Gallery */ + void slotGallery(); + /** Double click in list, edit question */ + void slotEditbyList(QListBoxItem *item); +}; + +#endif diff --git a/keduca/keducabuilder/keducabuilderui.rc b/keduca/keducabuilder/keducabuilderui.rc new file mode 100644 index 00000000..0942cea9 --- /dev/null +++ b/keduca/keducabuilder/keducabuilderui.rc @@ -0,0 +1,28 @@ + + + + &File + + + + &Edit + + + + + + + + + + + + + + + + + + + + diff --git a/keduca/keducabuilder/keducaeditorstartdialog.cpp b/keduca/keducabuilder/keducaeditorstartdialog.cpp new file mode 100644 index 00000000..88cf9305 --- /dev/null +++ b/keduca/keducabuilder/keducaeditorstartdialog.cpp @@ -0,0 +1,114 @@ +/*************************************************************************** + keducaeditorstartdialog.cpp - description + ------------------- + begin : Fri May 10 2002 + copyright : (C) 2002 by Klas Kalass + email : klas@kde.org +***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "keducaeditorstartdialog.h" +#include "keducabuilder.h" + +/** + */ +KEducaEditorStartDialog::KEducaEditorStartDialog(KEducaBuilder * parent, const char* name, bool modal, WFlags fl) + :KEducaEditorStartDialogBase(parent, name, modal, fl), + _choice(NewDoc), + _maxRecentDocumentItems(20) +{ + newDocumentRB->setFocus(); + + // read recent files + buildRecentFilesList(); + +// setup connections + urlRequester->setFilter( "application/x-edu"); + + connect( startChoiceBtnGrp, SIGNAL( clicked(int) ), + this, SLOT( slotChoiceChanged(int) ) ); +} + +/** based on code in kaction.cpp + */ +void KEducaEditorStartDialog::buildRecentFilesList() +{ + QString key; + QString value; + QString oldGroup; + KConfig *config = KGlobal::config(); + + oldGroup = config->group(); + + config->setGroup( "RecentFiles" ); + + // read file list + for( unsigned int i = 1 ; i <= _maxRecentDocumentItems ; i++ ) + { + key = QString( "File%1" ).arg( i ); + value = config->readEntry( key, QString::null ); + + if (!value.isNull()) + recentDocumentCB->insertURL( KURL(value) ); + } + + config->setGroup( oldGroup ); +} + +KEducaEditorStartDialog::~KEducaEditorStartDialog() { + +} + +void KEducaEditorStartDialog::slotChoiceChanged(int id) { + _choice = id+1; +} + +KURL KEducaEditorStartDialog::getURL()const{ + switch(_choice) { + case OpenDoc: + return KURL(urlRequester->url()); + break; + case OpenRecentDoc: + return KURL(recentDocumentCB->currentText()); + break; + default: + break; + } + + return KURL(); +} + +int KEducaEditorStartDialog::exec() { + int ret = KEducaEditorStartDialogBase::exec(); + if ( ret == KEducaEditorStartDialogBase::Rejected ) + _choice = KEducaEditorStartDialog::Rejected; + + return _choice; +} + +void KEducaEditorStartDialog::accept() { + if (((_choice == OpenDoc || _choice == OpenRecentDoc) + && getURL().isEmpty())) { + KMessageBox::sorry(this, i18n("You need to specify the file to open!")); + }else + KEducaEditorStartDialogBase::accept(); +} + +#include "keducaeditorstartdialog.moc" diff --git a/keduca/keducabuilder/keducaeditorstartdialog.h b/keduca/keducabuilder/keducaeditorstartdialog.h new file mode 100644 index 00000000..dd163848 --- /dev/null +++ b/keduca/keducabuilder/keducaeditorstartdialog.h @@ -0,0 +1,59 @@ +/*************************************************************************** + keducaeditorstartdialog.h - description + ------------------- + begin : Fri May 10 2002 + copyright : (C) 2002 by Klas Kalass + email : klas@kde.org +***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#ifndef KEDUCAEDITORSTARTDIALOG_H +#define KEDUCAEDITORSTARTDIALOG_H + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include "keducaeditorstartdialogbase.h" + +// forward declarations +class KEducaBuilder; + +/** + */ +class KEducaEditorStartDialog : public KEducaEditorStartDialogBase{ + Q_OBJECT +public: + enum {Rejected=0, OpenDoc=1, OpenRecentDoc=2, Gallery=3, NewDoc=4}StartChoice; + /** Constructor. + */ + KEducaEditorStartDialog(KEducaBuilder * parent = 0, const char* name = 0, bool modal = FALSE, WFlags fl = 0 ); + /** Destructor. + */ + virtual ~KEducaEditorStartDialog(); + + KURL getURL()const; + int exec(); + +private: + KURL _selectedURL; + int _choice; + unsigned int const _maxRecentDocumentItems; + void buildRecentFilesList(); + +protected slots: + void accept(); + +private slots: + void slotChoiceChanged(int id); + +}; +#endif diff --git a/keduca/keducabuilder/keducaeditorstartdialogbase.ui b/keduca/keducabuilder/keducaeditorstartdialogbase.ui new file mode 100644 index 00000000..0cb69e39 --- /dev/null +++ b/keduca/keducabuilder/keducaeditorstartdialogbase.ui @@ -0,0 +1,320 @@ + +KEducaEditorStartDialogBase + + + KEducaEditorStartDialogBase + + + + 0 + 0 + 511 + 311 + + + + Editor - Getting Started + + + true + + + + unnamed + + + 11 + + + 6 + + + + startChoiceBtnGrp + + + NoFrame + + + Plain + + + + + + + unnamed + + + 11 + + + 6 + + + + Layout13 + + + + unnamed + + + 0 + + + 6 + + + + openDocumentRB + + + NoFocus + + + Open an &existing document: + + + + + Layout4 + + + + unnamed + + + 0 + + + 6 + + + + Spacer4 + + + Horizontal + + + Fixed + + + + 20 + 20 + + + + + + urlRequester + + + + + + + + + openRecentDocumentRB + + + NoFocus + + + Open a &recent document: + + + false + + + + + Layout15 + + + + unnamed + + + 0 + + + 6 + + + + Spacer3 + + + Horizontal + + + Fixed + + + + 20 + 21 + + + + + + recentDocumentCB + + + + + + + radioButton4 + + + Open with Internet gallery browser + + + + + newDocumentRB + + + Start a &new document + + + true + + + + + + + Line1 + + + HLine + + + Sunken + + + Horizontal + + + + + Layout1 + + + + unnamed + + + 0 + + + 6 + + + + buttonHelp + + + &Help + + + true + + + + + Horizontal Spacing2 + + + Horizontal + + + Expanding + + + + 20 + 20 + + + + + + buttonOk + + + &OK + + + true + + + true + + + + + buttonCancel + + + &Cancel + + + true + + + + + + + + + + + buttonOk + clicked() + KEducaEditorStartDialogBase + accept() + + + buttonCancel + clicked() + KEducaEditorStartDialogBase + reject() + + + urlRequester + urlSelected(const QString&) + openDocumentRB + animateClick() + + + recentDocumentCB + activated(int) + openRecentDocumentRB + animateClick() + + + + newDocumentRB + urlRequester + recentDocumentCB + buttonHelp + buttonOk + buttonCancel + openDocumentRB + openRecentDocumentRB + + + + klineedit.h + kpushbutton.h + + diff --git a/keduca/keducabuilder/klangcombo.cpp b/keduca/keducabuilder/klangcombo.cpp new file mode 100644 index 00000000..ebedd9dd --- /dev/null +++ b/keduca/keducabuilder/klangcombo.cpp @@ -0,0 +1,51 @@ +/* + * klangcombo.cpp - Adds some methods for inserting languages. + * + * Copyright (c) 1999-2000 Hans Petter Bieker + * + * Requires the Qt widget libraries, available at no cost at + * http://www.troll.no/ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + + +#include + +#include "klangcombo.h" +#include "klangcombo.moc" + +KLanguageCombo::~KLanguageCombo () +{ +} + +KLanguageCombo::KLanguageCombo (QWidget * parent, const char *name) + : KTagComboBox(parent, name) +{ +} + +void KLanguageCombo::insertLanguage(const QString& path, const QString& name, const QString& sub, const QString &submenu) +{ + QString output = name + QString::fromLatin1(" (") + path + QString::fromLatin1(")"); + QPixmap flag(locate("locale", sub + path + QString::fromLatin1("/flag.png"))); + insertItem(QIconSet(flag), output, path, submenu); +} + +void KLanguageCombo::changeLanguage(const QString& name, int i) +{ + if (i < 0 || i >= count()) return; + QString output = name + QString::fromLatin1(" (") + tag(i) + QString::fromLatin1(")"); + changeItem(output, i); +} diff --git a/keduca/keducabuilder/klangcombo.h b/keduca/keducabuilder/klangcombo.h new file mode 100644 index 00000000..4c9fb801 --- /dev/null +++ b/keduca/keducabuilder/klangcombo.h @@ -0,0 +1,47 @@ +/* + * klangcombo.h - Adds some methods for inserting languages. + * + * Copyright (c) 1999-2000 Hans Petter Bieker + * + * Requires the Qt widget libraries, available at no cost at + * http://www.troll.no/ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + + +#ifndef __KLANGCOMBO_H__ +#define __KLANGCOMBO_H__ + +#include "ktagcombobox.h" + +/* + * Extends KTagCombo to support adding and changing languages. + * + * It has also support for sub menues. + */ +class KLanguageCombo : public KTagComboBox +{ + Q_OBJECT + +public: + KLanguageCombo(QWidget *parent=0, const char *name=0); + ~KLanguageCombo(); + + void insertLanguage(const QString& path, const QString& name, const QString& sub = QString::null, const QString &submenu = QString::null); + void changeLanguage(const QString& name, int i); +}; + +#endif diff --git a/keduca/keducabuilder/ktagcombobox.cpp b/keduca/keducabuilder/ktagcombobox.cpp new file mode 100644 index 00000000..9b7e969e --- /dev/null +++ b/keduca/keducabuilder/ktagcombobox.cpp @@ -0,0 +1,229 @@ +/* + * ktagcombobox.cpp - A combobox with support for submenues, icons and tags + * + * Copyright (c) 1999-2000 Hans Petter Bieker + * + * Requires the Qt widget libraries, available at no cost at + * http://www.troll.no/ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#define INCLUDE_MENUITEM_DEF 1 +#include +#include +#include + + +#include "ktagcombobox.h" +#include "ktagcombobox.moc" + +KTagComboBox::~KTagComboBox () +{ + delete _popup; + delete _tags; +} + +KTagComboBox::KTagComboBox (QWidget * parent, const char *name) + : QComboBox(parent, name) +{ + _popup = new QPopupMenu(this); + _tags = new QStringList; + connect( _popup, SIGNAL(activated(int)), + SLOT(internalActivate(int)) ); + connect( _popup, SIGNAL(highlighted(int)), + SLOT(internalHighlight(int)) ); +} + +void KTagComboBox::popupMenu() +{ + _popup->popup( mapToGlobal( QPoint(0,0) ), _current ); +} + +void KTagComboBox::keyPressEvent( QKeyEvent *e ) +{ + int c; + + if ( ( e->key() == Key_F4 && e->state() == 0 ) || + ( e->key() == Key_Down && (e->state() & AltButton) ) || + ( e->key() == Key_Space ) ) { + if ( count() ) { + _popup->setActiveItem( _current ); + popupMenu(); + } + return; + } else { + e->ignore(); + return; + } + + c = currentItem(); + emit highlighted( c ); + emit activated( c ); +} + +void KTagComboBox::mousePressEvent( QMouseEvent * ) +{ + popupMenu(); +} + +void KTagComboBox::internalActivate( int index ) +{ + if (_current == index) return; + _current = index; + emit activated( index ); + repaint(); +} + +void KTagComboBox::internalHighlight( int index ) +{ + emit highlighted( index ); +} + +void KTagComboBox::clear() +{ + _popup->clear(); + _tags->clear(); +} + +int KTagComboBox::count() const +{ + return _tags->count(); +} + +static inline QPopupMenu *checkInsertIndex(QPopupMenu *popup, const QStringList *tags, const QString &submenu, int *index) +{ + int pos = tags->findIndex(submenu); + + QPopupMenu *pi = 0; + if (pos != -1) + { + QMenuItem *p = popup->findItem(popup->idAt(pos)); + pi = p?p->popup():0; + } + if (!pi) pi = popup; + + if (*index > (int)pi->count()) + *index = -1; + + return pi; +} + +void KTagComboBox::insertItem(const QIconSet& icon, const QString &text, const QString &tag, const QString &submenu, int index ) +{ + QPopupMenu *pi = checkInsertIndex(_popup, _tags, submenu, &index); + pi->insertItem(icon, text, count(), index); + _tags->append(tag); +} + +void KTagComboBox::insertItem(const QString &text, const QString &tag, const QString &submenu, int index ) +{ + QPopupMenu *pi = checkInsertIndex(_popup, _tags, submenu, &index); + pi->insertItem(text, count(), index); + _tags->append(tag); +} + +void KTagComboBox::insertSeparator(const QString &submenu, int index) +{ + QPopupMenu *pi = checkInsertIndex(_popup, _tags, submenu, &index); + pi->insertSeparator(index); + _tags->append(QString::null); +} + +void KTagComboBox::insertSubmenu(const QString &text, const QString &tag, const QString &submenu, int index) +{ + QPopupMenu *pi = checkInsertIndex(_popup, _tags, submenu, &index); + QPopupMenu *p = new QPopupMenu(pi); + pi->insertItem(text, p, count(), index); + _tags->append(tag); + connect( p, SIGNAL(activated(int)), + SLOT(internalActivate(int)) ); + connect( p, SIGNAL(highlighted(int)), + SLOT(internalHighlight(int)) ); +} + +void KTagComboBox::changeItem( const QString &text, int index ) +{ + _popup->changeItem( text, index); + if (index == _current) + repaint(); +} + +void KTagComboBox::paintEvent( QPaintEvent * ev) +{ + QComboBox::paintEvent(ev); + + QPainter p (this); + + // Text + QRect clip(2, 2, width() - 4, height() - 4); + if ( hasFocus()) + p.setPen( colorGroup().highlightedText() ); + p.drawText(clip, AlignCenter | SingleLine, _popup->text( _current )); + + // Icon + QIconSet *icon = _popup->iconSet( _current ); + if (icon) { + QPixmap pm = icon->pixmap(); + p.drawPixmap( 4, (height()-pm.height())/2, pm ); + } +} + +bool KTagComboBox::containsTag( const QString &str ) const +{ + return _tags->contains(str) > 0; +} + +QString KTagComboBox::currentTag() const +{ + return *_tags->at(currentItem()); +} + +QString KTagComboBox::tag(int i) const +{ + if (i < 0 || i >= count()) + { + kdDebug() << "KTagComboBox::tag(), unknown tag " << i << endl; + return QString::null; + } + return *_tags->at(i); +} + +int KTagComboBox::currentItem() const +{ + return _current; +} + +void KTagComboBox::setCurrentItem(int i) +{ + if (i < 0 || i >= count()) return; + _current = i; + repaint(); +} + +void KTagComboBox::setCurrentItem(const QString &code) +{ + int i = _tags->findIndex(code); + if (code.isNull()) + i = 0; + if (i != -1) + setCurrentItem(i); +} + +void KTagComboBox::setFont( const QFont &font ) +{ + QComboBox::setFont( font ); + _popup->setFont( font ); +} diff --git a/keduca/keducabuilder/ktagcombobox.h b/keduca/keducabuilder/ktagcombobox.h new file mode 100644 index 00000000..099c6561 --- /dev/null +++ b/keduca/keducabuilder/ktagcombobox.h @@ -0,0 +1,94 @@ +/* + * ktagcombobox.h - A combobox with support for submenues, icons and tags + * + * Copyright (c) 1999-2000 Hans Petter Bieker + * + * Requires the Qt widget libraries, available at no cost at + * http://www.troll.no/ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + + +#ifndef __KTAGCOMBOBOX_H__ +#define __KTAGCOMBOBOX_H__ + +#include +#include +class QPopupMenu; +class QStringList; + +/* + * This class should be just like qcombobox, but it should be possible + * to have have a QIconSet for each entry, and each entry should have a tag. + * + * It has also support for sub menues. + */ +class KTagComboBox : public QComboBox +{ + Q_OBJECT + +public: + KTagComboBox(QWidget *parent=0, const char *name=0); + ~KTagComboBox(); + + void insertItem(const QIconSet& icon, const QString &text, const QString &tag, const QString &submenu = QString::null, int index=-1 ); + void insertItem(const QString &text, const QString &tag, const QString &submenu = QString::null, int index=-1 ); + void insertSeparator(const QString &submenu = QString::null, int index=-1 ); + void insertSubmenu(const QString &text, const QString &tag, const QString &submenu = QString::null, int index=-1); + void changeItem( const QString &text, int index ); + + int count() const; + void clear(); + + /* + * Tag of the selected item + */ + QString currentTag() const; + QString tag ( int i ) const; + bool containsTag (const QString &str ) const; + + /* + * Set the current item + */ + int currentItem() const; + void setCurrentItem(int i); + void setCurrentItem(const QString &code); + + // widget stuff + virtual void setFont( const QFont & ); + +signals: + void activated( int index ); + void highlighted( int index ); + +private slots: + void internalActivate( int ); + void internalHighlight( int ); + +protected: + void paintEvent( QPaintEvent * ); + void mousePressEvent( QMouseEvent * ); + void keyPressEvent( QKeyEvent *e ); + void popupMenu(); + +private: + // work space for the new class + QStringList *_tags; + QPopupMenu *_popup; + int _current; +}; + +#endif diff --git a/keduca/keducabuilder/main.cpp b/keduca/keducabuilder/main.cpp new file mode 100644 index 00000000..93a49cdf --- /dev/null +++ b/keduca/keducabuilder/main.cpp @@ -0,0 +1,67 @@ +/*************************************************************************** + main.cpp - description + ------------------- + begin : mié may 23 20:36:15 CEST 2001 + copyright : (C) 2001 by Javier Campos + email : javi@asyris.org +***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#include +#include +#include +#include + +#include +#include "keducabuilder.h" + +static const char description[] = I18N_NOOP("Form-based tests and exams builder"); +static const char version[] = "1.2.0"; + +static KCmdLineOptions options[] = +{ + { "+file", I18N_NOOP("File to load"), 0 }, + KCmdLineLastOption +}; + +int main(int argc, char *argv[]) +{ + KAboutData aboutData( "keduca", I18N_NOOP("KEducaBuilder"), + version, description, KAboutData::License_GPL, + "(c) 2001, Javier Campos", 0, "http://keduca.sourceforge.net", "submit@bugs.kde.org"); + aboutData.addAuthor("Javier Campos",I18N_NOOP("Original Author"), "javi@asyris.org"); + aboutData.addAuthor("Klas Kalass",I18N_NOOP("Maintainer 2002-2004"), "klas@kde.org"); + aboutData.addAuthor("Anne-Marie Mahfouf",I18N_NOOP("Various fixes and cleanups"), "annma@kde.org"); + aboutData.addCredit("Nenad Grujicic", I18N_NOOP("Icons"), "mengele@linuxo.org"); + KCmdLineArgs::init( argc, argv, &aboutData ); + KCmdLineArgs::addCmdLineOptions( options ); // Add our own options. + + KApplication a; + KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); + + // start as KEduca Builder + KEducaBuilder *keducaEditor = new KEducaBuilder(); + a.setMainWidget(keducaEditor); + keducaEditor->show(); + + if ( args->count() > 0 ){ + if( QFileInfo( KURL(args->url(0)).url() ).extension() == "edugallery" ) + keducaEditor->initGallery( args->url(0) ); + else + keducaEditor->slotFileOpenURL( args->url(0) ); + }else + keducaEditor->startChooser(); + + + args->clear(); + + return a.exec(); +} -- cgit v1.2.1