• Skip to content
  • Skip to link menu
KDE 3.5 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

keduca

kcontrolheader.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002                           kcontrolheader.cpp  -  description
00003                              -------------------
00004     begin                : Tue May 29 2001
00005     copyright            : (C) 2001 by Javier Campos
00006     email                : javi@asyris.org
00007 ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 #include "kcontrolheader.h"
00019 #include "kcontrolheader.moc"
00020 
00021 #include <klocale.h>
00022 #include <kstandarddirs.h>
00023 #include <ksimpleconfig.h>
00024 #include <klineedit.h>
00025 #include <kcombobox.h>
00026 
00027 #include <qlayout.h>
00028 #include <qlabel.h>
00029 
00030 KControlHeader::KControlHeader(FileRead *keducaFile, QWidget *parent, const char *name ) : KDialogBase(Swallow, i18n("Document Information"), Ok|Cancel, Ok, parent, name, true, true)
00031 {
00032     _keducaFile = keducaFile;
00033     init();
00034     configRead();
00035 }
00036 
00037 KControlHeader::~KControlHeader(){}
00038 
00040 void KControlHeader::init()
00041 {
00042     QWidget *mainView = new QWidget(this);
00043 
00044     QVBoxLayout *Form2Layout = new QVBoxLayout( mainView );
00045     Form2Layout->setSpacing( 6 );
00046     Form2Layout->setMargin( 0 );
00047 
00048     QFrame *Frame16 = new QFrame( mainView, "Frame16" );
00049     Frame16->setMinimumSize( QSize( 0, 50 ) );
00050     Frame16->setMaximumSize( QSize( 32767, 50 ) );
00051     Frame16->setFrameShape( QFrame::Box );
00052     Frame16->setFrameShadow( QFrame::Plain );
00053     Frame16->setPalette( QPalette( QColor(255, 255, 255) ) );
00054     QHBoxLayout *Frame16Layout = new QHBoxLayout( Frame16 );
00055     Frame16Layout->setSpacing( 6 );
00056     Frame16Layout->setMargin( 1 );
00057 
00058     QFrame *Frame17 = new QFrame( Frame16, "Frame17" );
00059     Frame17->setMinimumSize( QSize( 125, 0 ) );
00060     Frame17->setMaximumSize( QSize( 125, 32767 ) );
00061     Frame17->setFrameShape( QFrame::NoFrame );
00062     Frame17->setFrameShadow( QFrame::Raised );
00063     Frame17->setBackgroundPixmap( QPixmap(locate("appdata","pics/bk_frame.png") ) );
00064     QVBoxLayout *Frame17Layout = new QVBoxLayout( Frame17 );
00065     Frame17Layout->setSpacing( 6 );
00066     Frame17Layout->setMargin( 11 );
00067 
00068     QLabel *TextLabel1 = new QLabel( Frame17, "TextLabel1" );
00069     TextLabel1->setText( "<b style=\"text-decoration:underline;\">"+i18n("Information")+"</b>"  );
00070     TextLabel1->setBackgroundPixmap( QPixmap(locate("appdata","pics/bk_frame.png") ) );
00071     Frame17Layout->addWidget( TextLabel1 );
00072     Frame16Layout->addWidget( Frame17 );
00073     QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
00074     Frame16Layout->addItem( spacer );
00075 
00076     QLabel *TextLabel2 = new QLabel( Frame16, "TextLabel2" );
00077     TextLabel2->setText( i18n( "Description and rules of the project." ) );
00078     TextLabel2->setPalette( QPalette( QColor(255, 255, 255) ) );
00079     Frame16Layout->addWidget( TextLabel2 );
00080     Form2Layout->addWidget( Frame16 );
00081 
00082     QGroupBox *GroupBox7 = new QGroupBox( mainView, "GroupBox7" );
00083     GroupBox7->setTitle( i18n( "Description" ) );
00084     GroupBox7->setColumnLayout(0, Qt::Vertical );
00085     GroupBox7->layout()->setSpacing( 0 );
00086     GroupBox7->layout()->setMargin( 0 );
00087     QVBoxLayout *GroupBox7Layout = new QVBoxLayout( GroupBox7->layout() );
00088     GroupBox7Layout->setAlignment( Qt::AlignTop );
00089     GroupBox7Layout->setSpacing( 6 );
00090     GroupBox7Layout->setMargin( 11 );
00091 
00092     QGridLayout *Layout13 = new QGridLayout;
00093     Layout13->setSpacing( 6 );
00094     Layout13->setMargin( 0 );
00095 
00096     QLabel *TextLabel10 = new QLabel( GroupBox7, "TextLabel10" );
00097     TextLabel10->setText( i18n( "Type:" ));
00098     TextLabel10->setAlignment( int( QLabel::AlignVCenter | QLabel::AlignRight ) );
00099 
00100     Layout13->addWidget( TextLabel10, 2, 0 );
00101 
00102     QHBoxLayout *Layout12 = new QHBoxLayout;
00103     Layout12->setSpacing( 6 );
00104     Layout12->setMargin( 0 );
00105 
00106     _headerType = new KComboBox( FALSE, GroupBox7, "_headerType" );
00107     Layout12->addWidget( _headerType );
00108 
00109     QLabel *TextLabel11 = new QLabel( GroupBox7, "TextLabel11" );
00110     TextLabel11->setText( i18n( "Level:" ));
00111     TextLabel11->setAlignment( int( QLabel::AlignVCenter | QLabel::AlignRight ) );
00112     Layout12->addWidget( TextLabel11 );
00113 
00114     _headerLevel = new KComboBox( FALSE, GroupBox7, "_headerLevel" );
00115     Layout12->addWidget( _headerLevel );
00116     Layout13->addLayout( Layout12, 2, 1 );
00117 
00118     QLabel *TextLabel12 = new QLabel( GroupBox7, "TextLabel12" );
00119     TextLabel12->setText( i18n( "Language:" ));
00120     TextLabel12->setAlignment( int( QLabel::AlignVCenter | QLabel::AlignRight ) );
00121     Layout13->addWidget( TextLabel12, 3, 0 );
00122 
00123     _headerLang = new KLanguageCombo( GroupBox7, "_headerLang" );
00124     loadCountryList( _headerLang );
00125     Layout13->addWidget( _headerLang, 3, 1 );
00126 
00127     QLabel *TextLabel9 = new QLabel( GroupBox7, "TextLabel9" );
00128     TextLabel9->setText( i18n( "Category:" ));
00129     TextLabel9->setAlignment( int( QLabel::AlignVCenter | QLabel::AlignRight ) );
00130 
00131     Layout13->addWidget( TextLabel9, 1, 0 );
00132 
00133     _headerCategory = new KComboBox( true, GroupBox7, "_headerCategory" );
00134     Layout13->addWidget( _headerCategory, 1, 1 );
00135 
00136     _headerTitle = new QLineEdit( GroupBox7, "_headerTitle" );
00137     Layout13->addWidget( _headerTitle, 0, 1 );
00138 
00139     QLabel *TextLabel8 = new QLabel( GroupBox7, "TextLabel8" );
00140     TextLabel8->setText( i18n( "Title:" ));
00141     TextLabel8->setAlignment( int( QLabel::AlignVCenter | QLabel::AlignRight ) );
00142 
00143     Layout13->addWidget( TextLabel8, 0, 0 );
00144     GroupBox7Layout->addLayout( Layout13 );
00145     Form2Layout->addWidget( GroupBox7 );
00146 
00147     QGroupBox *GroupBox8 = new QGroupBox( mainView, "GroupBox8" );
00148     GroupBox8->setTitle( i18n( "Picture" ) );
00149     GroupBox8->setColumnLayout(0, Qt::Vertical );
00150     GroupBox8->layout()->setSpacing( 0 );
00151     GroupBox8->layout()->setMargin( 0 );
00152     QHBoxLayout *GroupBox8Layout = new QHBoxLayout( GroupBox8->layout() );
00153     GroupBox8Layout->setAlignment( Qt::AlignTop );
00154     GroupBox8Layout->setSpacing( 6 );
00155     GroupBox8Layout->setMargin( 11 );
00156 
00157     QLabel *TextLabel13 = new QLabel( GroupBox8, "TextLabel13" );
00158     TextLabel13->setText( i18n( "Default picture:" ));
00159     GroupBox8Layout->addWidget( TextLabel13 );
00160 
00161     _headerPicture = new KURLRequester( GroupBox8, "_headerPicture" );
00162     GroupBox8Layout->addWidget( _headerPicture );
00163     Form2Layout->addWidget( GroupBox8 );
00164 
00165     QGroupBox *GroupBox6 = new QGroupBox( mainView, "GroupBox6" );
00166     GroupBox6->setTitle( i18n( "Author" ) );
00167     GroupBox6->setColumnLayout(0, Qt::Vertical );
00168     GroupBox6->layout()->setSpacing( 0 );
00169     GroupBox6->layout()->setMargin( 0 );
00170     QGridLayout *GroupBox6Layout = new QGridLayout( GroupBox6->layout() );
00171     GroupBox6Layout->setAlignment( Qt::AlignTop );
00172     GroupBox6Layout->setSpacing( 6 );
00173     GroupBox6Layout->setMargin( 11 );
00174 
00175     _headerName = new QLineEdit( GroupBox6, "_headerName" );
00176 
00177     GroupBox6Layout->addWidget( _headerName, 0, 1 );
00178 
00179     _headerEmail = new QLineEdit( GroupBox6, "_headerEmail" );
00180 
00181     GroupBox6Layout->addWidget( _headerEmail, 1, 1 );
00182 
00183     QLabel *TextLabel7 = new QLabel( GroupBox6, "TextLabel7" );
00184     TextLabel7->setText( i18n( "Web page:" ));
00185     TextLabel7->setAlignment( int( QLabel::AlignVCenter | QLabel::AlignRight ) );
00186 
00187     GroupBox6Layout->addWidget( TextLabel7, 2, 0 );
00188 
00189     QLabel *TextLabel6 = new QLabel( GroupBox6, "TextLabel6" );
00190     TextLabel6->setText( i18n( "Email:" ));
00191     TextLabel6->setAlignment( int( QLabel::AlignVCenter | QLabel::AlignRight ) );
00192 
00193     GroupBox6Layout->addWidget( TextLabel6, 1, 0 );
00194 
00195     QLabel *TextLabel5 = new QLabel( GroupBox6, "TextLabel5" );
00196     TextLabel5->setText( i18n( "Name:" ));
00197     TextLabel5->setAlignment( int( QLabel::AlignVCenter | QLabel::AlignRight ) );
00198 
00199     GroupBox6Layout->addWidget( TextLabel5, 0, 0 );
00200 
00201     _headerWWW = new QLineEdit( GroupBox6, "_headerWWW" );
00202 
00203     GroupBox6Layout->addWidget( _headerWWW, 2, 1 );
00204     Form2Layout->addWidget( GroupBox6 );
00205 
00206     // tab order
00207     setTabOrder( _headerTitle, _headerCategory );
00208     setTabOrder( _headerCategory, _headerType );
00209     setTabOrder( _headerType, _headerLevel );
00210     setTabOrder( _headerLevel, _headerLang );
00211     setTabOrder( _headerLang, _headerPicture->lineEdit() );
00212     setTabOrder( _headerPicture->lineEdit(), _headerPicture->comboBox() );
00213     setTabOrder( _headerPicture->comboBox(), _headerName );
00214     setTabOrder( _headerName, _headerEmail );
00215     setTabOrder( _headerEmail, _headerWWW );
00216 
00217     // set a sensible focus
00218     _headerTitle->setFocus();
00219 
00220     setMainWidget(mainView);
00221 }
00222 
00224 void KControlHeader::insertHeader()
00225 {
00226     QStringList tmpResult = _defaultCategories.grep( _headerCategory->currentText() );
00227     if( tmpResult.count() == 0 )
00228     {
00229         KConfig *appconfig = KGlobal::config();
00230         _defaultCategories.append( _headerCategory->currentText() );
00231         appconfig->setGroup("General");
00232         appconfig->writeEntry( "Categories", _defaultCategories);
00233         appconfig->sync();
00234     }
00235     _keducaFile->setHeader( "category",     _headerCategory->currentText() );
00236     _keducaFile->setHeader( "title",            _headerTitle->text() );
00237     _keducaFile->setHeader( "image",            _headerPicture->url() );
00238     _keducaFile->setHeader( "type",             QString().setNum( _headerType->currentItem() + 1 ) );
00239     _keducaFile->setHeader( "level",            QString().setNum( _headerLevel->currentItem() + 1 ) );
00240     _keducaFile->setHeader( "language", _headerLang->currentTag() );
00241     _keducaFile->setHeader( "name",         _headerName->text() );
00242     _keducaFile->setHeader( "email",        _headerEmail->text() );
00243     _keducaFile->setHeader( "www",          _headerWWW->text() );
00244 }
00245 
00247 void KControlHeader::loadCountryList(KLanguageCombo *combo)
00248 {
00249     QString sub = QString::fromLatin1("l10n/");
00250 
00251     // clear the list
00252     combo->clear();
00253 
00254     QStringList regionlist = KGlobal::dirs()->findAllResources("locale", sub + QString::fromLatin1("*.desktop"));
00255     regionlist.sort();
00256 
00257     for ( QStringList::ConstIterator it = regionlist.begin();
00258           it != regionlist.end();
00259           ++it )
00260     {
00261         QString tag = *it;
00262         int index;
00263 
00264         index = tag.findRev('/');
00265         if (index != -1) tag = tag.mid(index + 1);
00266 
00267         index = tag.findRev('.');
00268         if (index != -1) tag.truncate(index);
00269 
00270         KSimpleConfig entry(*it);
00271         entry.setGroup(QString::fromLatin1("KCM Locale"));
00272         QString name = entry.readEntry(QString::fromLatin1("Name"));
00273 
00274         combo->insertSubmenu( name, '-' + tag, sub );
00275     }
00276 
00277     // add all languages to the list
00278     QStringList countrylist = KGlobal::dirs()->findAllResources("locale",  sub + QString::fromLatin1("*/entry.desktop"));
00279     countrylist.sort();
00280 
00281     for ( QStringList::ConstIterator it = countrylist.begin();
00282           it != countrylist.end(); ++it )
00283     {
00284         KSimpleConfig entry(*it);
00285         entry.setGroup(QString::fromLatin1("KCM Locale"));
00286         QString name = entry.readEntry(QString::fromLatin1("Name"));
00287         QString submenu = '-' + entry.readEntry(QString::fromLatin1("Region"));
00288 
00289         QString tag = *it;
00290         int index = tag.findRev('/');
00291         tag.truncate(index);
00292         index = tag.findRev('/');
00293         tag = tag.mid(index+1);
00294         combo->insertLanguage(tag, name, sub, submenu);
00295     }
00296 }
00297 
00299 void KControlHeader::slotOk()
00300 {
00301     insertHeader();
00302     configWrite();
00303     accept();
00304 }
00305 
00307 void KControlHeader::configRead()
00308 {
00309     KConfig *config = new KConfig("emaildefaults");
00310     KConfig *appconfig = KGlobal::config();
00311 
00312     config->setGroup("UserInfo");
00313 
00314     if( _keducaFile->getHeader( "name" ).isEmpty() )
00315         _headerName->setText(config->readEntry("FullName", QString::null ));
00316     else
00317         _headerName->setText( _keducaFile->getHeader("name") );
00318 
00319     if( _keducaFile->getHeader( "email" ).isEmpty() )
00320         _headerEmail->setText(config->readEntry("EmailAddress", QString::null ));
00321     else
00322         _headerEmail->setText( _keducaFile->getHeader("email") );
00323 
00324     _headerWWW->setText( _keducaFile->getHeader("www") );
00325 
00326     if( !_keducaFile->getHeader("language").isEmpty() )
00327     {
00328         _headerLang->setCurrentItem( _keducaFile->getHeader("language") );
00329     }
00330     else
00331     {
00332         config->setGroup("Locale");
00333         _headerLang->setCurrentItem( config->readEntry("Country") );
00334     }
00335 
00336     appconfig->setGroup("General");
00337     _defaultCategories = appconfig->readListEntry("Categories");
00338     if( _defaultCategories.count() == 0 )
00339     {
00340         _defaultCategories.append(i18n("Computers"));
00341     }
00342     _defaultCategories.sort();
00343     _headerCategory->insertStringList( _defaultCategories );
00344     if( !_keducaFile->getHeader( "category" ).isEmpty() ) _headerCategory->setEditText( _keducaFile->getHeader("category") );
00345 
00346     _headerType->insertItem( i18n("Test") );
00347     _headerType->insertItem( i18n("Test with Question Points") );
00348     _headerType->insertItem( i18n("Test with Answers Points") );
00349     _headerType->insertItem( i18n("Slidershow") );
00350     _headerType->insertItem( i18n("Exam") );
00351     _headerType->insertItem( i18n("Psychotechnic Test") );
00352     if( QString(_keducaFile->getHeader("type")).toInt() > 0 ) _headerType->setCurrentItem( QString(_keducaFile->getHeader("type")).toInt() -1 );
00353 
00354     _headerLevel->insertItem( i18n("Easy") );
00355     _headerLevel->insertItem( i18n("Normal") );
00356     _headerLevel->insertItem( i18n("Expert") );
00357     _headerLevel->insertItem( i18n("Supreme") );
00358     if( QString(_keducaFile->getHeader("level")).toInt() >0 ) _headerLevel->setCurrentItem( QString(_keducaFile->getHeader("level")).toInt() -1 );
00359 
00360     _headerPicture->setURL( _keducaFile->getHeader("image") );
00361     _headerTitle->setText( _keducaFile->getHeader("title") );
00362 
00363     appconfig->setGroup("kcontrolheader");
00364     QSize *defaultSize = new QSize(500,400);
00365     resize( appconfig->readSizeEntry("Geometry", defaultSize ) );
00366     delete config;
00367 }
00368 
00370 void KControlHeader::configWrite()
00371 {
00372     KConfig *config = KGlobal::config();
00373     config->setGroup("kcontrolheader");
00374     config->writeEntry("Geometry", size() );
00375     config->sync();
00376 }

keduca

Skip menu "keduca"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members

API Reference

Skip menu "API Reference"
  • keduca
  • kstars
Generated for API Reference by doxygen 1.5.9
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal