You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
tdeedu/libtdeedu/tdeeduui/tdeeduglossary.h

294 lines
6.3 KiB

#ifndef TDEEDUGLOSSARY_H
#define TDEEDUGLOSSARY_H
/***************************************************************************
copyright : (C) 2005 by Carsten Niehaus
email : cniehaus@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 <tdehtml_part.h>
#include <kdialogbase.h>
class TQChar;
class TQDomDocument;
class TQListViewItem;
class TDEListView;
class TDEListViewSearchLine;
class TDEActionCollection;
class GlossaryItem;
/**
* @class Glossary
* @author Carsten Niehaus
*
* This class stores all items to be displayed. It also
* has access-methods to the items
*/
class TDE_EXPORT Glossary
{
public:
Glossary();
virtual ~Glossary();
/**
* add the item @p item to the glossary
*/
void addItem( GlossaryItem* item ){
m_itemlist.append( item );
}
TQValueList<GlossaryItem*> itemlist()const{
return m_itemlist;
}
/**
* clear the Glossary
*/
void clear(){
m_itemlist.clear();
}
/**
* does this glossary have items?
*/
bool isEmpty() const;
/**
* Every glossary can have a name. It will be
* set to @p name
*/
void setName( const TQString& name ){
m_name = name;
}
/**
* @returns the name of the glossary
*/
TQString name()const{
return m_name;
}
/**
* sets the internal list of items to @p list
*/
void setItemlist( TQValueList<GlossaryItem*> list ){
m_itemlist = list;
}
/**
* Read a glossary from an XML file.
*
* @param url The path of the file to load
* @param path The path of the pictures. Will be used as m_picturepath
*
* @return a pointer to the loaded glossary. Even in case of
* error, this won't return 0 but an empty Glossary.
*/
static Glossary* readFromXML( const KURL& url, const TQString& path = 0 );
/**
* Every glossaryitem can show pictures. [img src="foo.png]
* will look for the file foo.png in the path defined be
* @p path
*/
void setPicturePath( const TQString& path ){
m_picturepath = path;
}
TQString picturePath()const{
return m_picturepath;
}
/**
* defines which picture to use as the background
* of the htmlview. The dialog
* will use the file specifiec by the @p filename
*/
void setBackgroundPicture( const TQString& filename ){
m_backgroundpicture = filename;
}
/**
* @return the picuture used as the background in
* this background
*/
TQString backgroundPicture()const{
return m_backgroundpicture;
}
private:
/**
* This methods parses the given xml-code. It will extract
* the information of the items and return them as a
* TQValueList<GlossaryItem*>
*/
virtual TQValueList<GlossaryItem*> readItems( TQDomDocument &itemDocument );
TQString m_backgroundpicture;
/**
* replaces the [img]-pseudocode with valid html. The path where
* the pictures are stored will be used for pictures
*/
void fixImagePath();
/**
* the path in which pictures of the glossary will be searched
*/
TQString m_picturepath;
/**
* Load the layout from an XML file.
*
* @param doc The TQDomDocument which will contain the read XML
* contents.
* @param url The path of the file to load
*
* @return a bool indicating whether the loading of the XML was
* successfull or not
*/
bool loadLayout( TQDomDocument& doc, const KURL& url );
TQValueList<GlossaryItem*> m_itemlist;
/**
* the name of the glossary
*/
TQString m_name;
};
/**
* @class GlossaryItem
* @author Carsten Niehaus
*
* A GlossaryItem stores the information of the content of
* the item and its name. Furthermore, every item can have
* a number of pictures or references associated to it.
* These are stored as TQStringLists.
*/
class TDE_EXPORT GlossaryItem
{
public:
GlossaryItem(){}
~GlossaryItem(){}
void setName( const TQString& s ){
m_name = s;
}
void setDesc( const TQString& s){
m_desc = s;
}
void setRef( const TQStringList& s){
m_ref = s;
}
void setPictures( const TQString& s ){
m_pic = s;
}
TQString name() const {
return m_name;
}
TQString desc() const {
return m_desc;
}
TQStringList ref() const {
return m_ref;
}
TQStringList pictures() const {
return m_pic;
}
/**
* @return the formated HTML code for current item.
**/
TQString toHtml() const;
/**
* This method parses the references.
* @return the HTML code with the references as HTML links
*/
TQString parseReferences() const;
private:
TQString m_name;
TQString m_desc;
TQStringList m_ref;
TQStringList m_pic;
};
/**
* @class GlossaryDialog
* @author Pino Toscano
* @author Carsten Niehaus
*/
class TDE_EXPORT GlossaryDialog : public KDialogBase
{
TQ_OBJECT
public:
GlossaryDialog( bool folded = true, TQWidget *parent=0, const char *name=0);
~GlossaryDialog();
void keyPressEvent(TQKeyEvent*);
/**
* add a new glossary
*
* @param newgloss the new glossary to add
*/
void addGlossary( Glossary* newgloss );
private:
TQValueList<Glossary*> m_glossaries;
/**
* if true the items will be displayed folded
*/
bool m_folded;
void updateTree();
TDEHTMLPart *m_htmlpart;
TDEListView *m_glosstree;
TQString m_htmlbasestring;
TDEActionCollection* m_actionCollection;
TQListViewItem* findTreeWithLetter( const TQChar&, TQListViewItem* );
TDEListViewSearchLine *m_search;
private slots:
void slotClicked( TQListViewItem * );
/**
* The user clicked on a href. Emit the corresponding item
*/
void displayItem( const KURL& url, const KParts::URLArgs& args );
protected slots:
virtual void slotClose();
signals:
void closed();
};
#endif // TDEEDUGLOSSARY_H