moved kdeaccessibility kdeaddons kdeadmin kdeartwork kdebindings kdeedu kdegames...
[kdeedu.git] / keduca / keducabuilder / kcontrolheader.cpp
blobd7a2090a69336a47be4adb46a392540e996f9fb3
1 /***************************************************************************
2 kcontrolheader.cpp - description
3 -------------------
4 begin : Tue May 29 2001
5 copyright : (C) 2001 by Javier Campos
6 email : javi@asyris.org
7 ***************************************************************************/
9 /***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
18 #include "kcontrolheader.h"
19 #include "kcontrolheader.moc"
21 #include <klocale.h>
22 #include <kstandarddirs.h>
23 #include <ksimpleconfig.h>
24 #include <klineedit.h>
25 #include <kcombobox.h>
27 #include <qlayout.h>
28 #include <qlabel.h>
30 KControlHeader::KControlHeader(FileRead *keducaFile, QWidget *parent, const char *name ) : KDialogBase(Swallow, i18n("Document Information"), Ok|Cancel, Ok, parent, name, true, true)
32 _keducaFile = keducaFile;
33 init();
34 configRead();
37 KControlHeader::~KControlHeader(){}
39 /** Init graphical interface */
40 void KControlHeader::init()
42 QWidget *mainView = new QWidget(this);
44 QVBoxLayout *Form2Layout = new QVBoxLayout( mainView );
45 Form2Layout->setSpacing( 6 );
46 Form2Layout->setMargin( 0 );
48 QFrame *Frame16 = new QFrame( mainView, "Frame16" );
49 Frame16->setMinimumSize( QSize( 0, 50 ) );
50 Frame16->setMaximumSize( QSize( 32767, 50 ) );
51 Frame16->setFrameShape( QFrame::Box );
52 Frame16->setFrameShadow( QFrame::Plain );
53 Frame16->setPalette( QPalette( QColor(255, 255, 255) ) );
54 QHBoxLayout *Frame16Layout = new QHBoxLayout( Frame16 );
55 Frame16Layout->setSpacing( 6 );
56 Frame16Layout->setMargin( 1 );
58 QFrame *Frame17 = new QFrame( Frame16, "Frame17" );
59 Frame17->setMinimumSize( QSize( 125, 0 ) );
60 Frame17->setMaximumSize( QSize( 125, 32767 ) );
61 Frame17->setFrameShape( QFrame::NoFrame );
62 Frame17->setFrameShadow( QFrame::Raised );
63 Frame17->setBackgroundPixmap( QPixmap(locate("appdata","pics/bk_frame.png") ) );
64 QVBoxLayout *Frame17Layout = new QVBoxLayout( Frame17 );
65 Frame17Layout->setSpacing( 6 );
66 Frame17Layout->setMargin( 11 );
68 QLabel *TextLabel1 = new QLabel( Frame17, "TextLabel1" );
69 TextLabel1->setText( "<b style=\"text-decoration:underline;\">"+i18n("Information")+"</b>" );
70 TextLabel1->setBackgroundPixmap( QPixmap(locate("appdata","pics/bk_frame.png") ) );
71 Frame17Layout->addWidget( TextLabel1 );
72 Frame16Layout->addWidget( Frame17 );
73 QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
74 Frame16Layout->addItem( spacer );
76 QLabel *TextLabel2 = new QLabel( Frame16, "TextLabel2" );
77 TextLabel2->setText( i18n( "Description and rules of the project." ) );
78 TextLabel2->setPalette( QPalette( QColor(255, 255, 255) ) );
79 Frame16Layout->addWidget( TextLabel2 );
80 Form2Layout->addWidget( Frame16 );
82 QGroupBox *GroupBox7 = new QGroupBox( mainView, "GroupBox7" );
83 GroupBox7->setTitle( i18n( "Description" ) );
84 GroupBox7->setColumnLayout(0, Qt::Vertical );
85 GroupBox7->layout()->setSpacing( 0 );
86 GroupBox7->layout()->setMargin( 0 );
87 QVBoxLayout *GroupBox7Layout = new QVBoxLayout( GroupBox7->layout() );
88 GroupBox7Layout->setAlignment( Qt::AlignTop );
89 GroupBox7Layout->setSpacing( 6 );
90 GroupBox7Layout->setMargin( 11 );
92 QGridLayout *Layout13 = new QGridLayout;
93 Layout13->setSpacing( 6 );
94 Layout13->setMargin( 0 );
96 QLabel *TextLabel10 = new QLabel( GroupBox7, "TextLabel10" );
97 TextLabel10->setText( i18n( "Type:" ));
98 TextLabel10->setAlignment( int( QLabel::AlignVCenter | QLabel::AlignRight ) );
100 Layout13->addWidget( TextLabel10, 2, 0 );
102 QHBoxLayout *Layout12 = new QHBoxLayout;
103 Layout12->setSpacing( 6 );
104 Layout12->setMargin( 0 );
106 _headerType = new KComboBox( FALSE, GroupBox7, "_headerType" );
107 Layout12->addWidget( _headerType );
109 QLabel *TextLabel11 = new QLabel( GroupBox7, "TextLabel11" );
110 TextLabel11->setText( i18n( "Level:" ));
111 TextLabel11->setAlignment( int( QLabel::AlignVCenter | QLabel::AlignRight ) );
112 Layout12->addWidget( TextLabel11 );
114 _headerLevel = new KComboBox( FALSE, GroupBox7, "_headerLevel" );
115 Layout12->addWidget( _headerLevel );
116 Layout13->addLayout( Layout12, 2, 1 );
118 QLabel *TextLabel12 = new QLabel( GroupBox7, "TextLabel12" );
119 TextLabel12->setText( i18n( "Language:" ));
120 TextLabel12->setAlignment( int( QLabel::AlignVCenter | QLabel::AlignRight ) );
121 Layout13->addWidget( TextLabel12, 3, 0 );
123 _headerLang = new KLanguageCombo( GroupBox7, "_headerLang" );
124 loadCountryList( _headerLang );
125 Layout13->addWidget( _headerLang, 3, 1 );
127 QLabel *TextLabel9 = new QLabel( GroupBox7, "TextLabel9" );
128 TextLabel9->setText( i18n( "Category:" ));
129 TextLabel9->setAlignment( int( QLabel::AlignVCenter | QLabel::AlignRight ) );
131 Layout13->addWidget( TextLabel9, 1, 0 );
133 _headerCategory = new KComboBox( true, GroupBox7, "_headerCategory" );
134 Layout13->addWidget( _headerCategory, 1, 1 );
136 _headerTitle = new QLineEdit( GroupBox7, "_headerTitle" );
137 Layout13->addWidget( _headerTitle, 0, 1 );
139 QLabel *TextLabel8 = new QLabel( GroupBox7, "TextLabel8" );
140 TextLabel8->setText( i18n( "Title:" ));
141 TextLabel8->setAlignment( int( QLabel::AlignVCenter | QLabel::AlignRight ) );
143 Layout13->addWidget( TextLabel8, 0, 0 );
144 GroupBox7Layout->addLayout( Layout13 );
145 Form2Layout->addWidget( GroupBox7 );
147 QGroupBox *GroupBox8 = new QGroupBox( mainView, "GroupBox8" );
148 GroupBox8->setTitle( i18n( "Picture" ) );
149 GroupBox8->setColumnLayout(0, Qt::Vertical );
150 GroupBox8->layout()->setSpacing( 0 );
151 GroupBox8->layout()->setMargin( 0 );
152 QHBoxLayout *GroupBox8Layout = new QHBoxLayout( GroupBox8->layout() );
153 GroupBox8Layout->setAlignment( Qt::AlignTop );
154 GroupBox8Layout->setSpacing( 6 );
155 GroupBox8Layout->setMargin( 11 );
157 QLabel *TextLabel13 = new QLabel( GroupBox8, "TextLabel13" );
158 TextLabel13->setText( i18n( "Default picture:" ));
159 GroupBox8Layout->addWidget( TextLabel13 );
161 _headerPicture = new KURLRequester( GroupBox8, "_headerPicture" );
162 GroupBox8Layout->addWidget( _headerPicture );
163 Form2Layout->addWidget( GroupBox8 );
165 QGroupBox *GroupBox6 = new QGroupBox( mainView, "GroupBox6" );
166 GroupBox6->setTitle( i18n( "Author" ) );
167 GroupBox6->setColumnLayout(0, Qt::Vertical );
168 GroupBox6->layout()->setSpacing( 0 );
169 GroupBox6->layout()->setMargin( 0 );
170 QGridLayout *GroupBox6Layout = new QGridLayout( GroupBox6->layout() );
171 GroupBox6Layout->setAlignment( Qt::AlignTop );
172 GroupBox6Layout->setSpacing( 6 );
173 GroupBox6Layout->setMargin( 11 );
175 _headerName = new QLineEdit( GroupBox6, "_headerName" );
177 GroupBox6Layout->addWidget( _headerName, 0, 1 );
179 _headerEmail = new QLineEdit( GroupBox6, "_headerEmail" );
181 GroupBox6Layout->addWidget( _headerEmail, 1, 1 );
183 QLabel *TextLabel7 = new QLabel( GroupBox6, "TextLabel7" );
184 TextLabel7->setText( i18n( "Web page:" ));
185 TextLabel7->setAlignment( int( QLabel::AlignVCenter | QLabel::AlignRight ) );
187 GroupBox6Layout->addWidget( TextLabel7, 2, 0 );
189 QLabel *TextLabel6 = new QLabel( GroupBox6, "TextLabel6" );
190 TextLabel6->setText( i18n( "Email:" ));
191 TextLabel6->setAlignment( int( QLabel::AlignVCenter | QLabel::AlignRight ) );
193 GroupBox6Layout->addWidget( TextLabel6, 1, 0 );
195 QLabel *TextLabel5 = new QLabel( GroupBox6, "TextLabel5" );
196 TextLabel5->setText( i18n( "Name:" ));
197 TextLabel5->setAlignment( int( QLabel::AlignVCenter | QLabel::AlignRight ) );
199 GroupBox6Layout->addWidget( TextLabel5, 0, 0 );
201 _headerWWW = new QLineEdit( GroupBox6, "_headerWWW" );
203 GroupBox6Layout->addWidget( _headerWWW, 2, 1 );
204 Form2Layout->addWidget( GroupBox6 );
206 // tab order
207 setTabOrder( _headerTitle, _headerCategory );
208 setTabOrder( _headerCategory, _headerType );
209 setTabOrder( _headerType, _headerLevel );
210 setTabOrder( _headerLevel, _headerLang );
211 setTabOrder( _headerLang, _headerPicture->lineEdit() );
212 setTabOrder( _headerPicture->lineEdit(), _headerPicture->comboBox() );
213 setTabOrder( _headerPicture->comboBox(), _headerName );
214 setTabOrder( _headerName, _headerEmail );
215 setTabOrder( _headerEmail, _headerWWW );
217 // set a sensible focus
218 _headerTitle->setFocus();
220 setMainWidget(mainView);
223 /** Insert header */
224 void KControlHeader::insertHeader()
226 QStringList tmpResult = _defaultCategories.grep( _headerCategory->currentText() );
227 if( tmpResult.count() == 0 )
229 KConfig *appconfig = KGlobal::config();
230 _defaultCategories.append( _headerCategory->currentText() );
231 appconfig->setGroup("General");
232 appconfig->writeEntry( "Categories", _defaultCategories);
233 appconfig->sync();
235 _keducaFile->setHeader( "category", _headerCategory->currentText() );
236 _keducaFile->setHeader( "title", _headerTitle->text() );
237 _keducaFile->setHeader( "image", _headerPicture->url() );
238 _keducaFile->setHeader( "type", QString().setNum( _headerType->currentItem() + 1 ) );
239 _keducaFile->setHeader( "level", QString().setNum( _headerLevel->currentItem() + 1 ) );
240 _keducaFile->setHeader( "language", _headerLang->currentTag() );
241 _keducaFile->setHeader( "name", _headerName->text() );
242 _keducaFile->setHeader( "email", _headerEmail->text() );
243 _keducaFile->setHeader( "www", _headerWWW->text() );
246 /** Load country list */
247 void KControlHeader::loadCountryList(KLanguageCombo *combo)
249 QString sub = QString::fromLatin1("l10n/");
251 // clear the list
252 combo->clear();
254 QStringList regionlist = KGlobal::dirs()->findAllResources("locale", sub + QString::fromLatin1("*.desktop"));
255 regionlist.sort();
257 for ( QStringList::ConstIterator it = regionlist.begin();
258 it != regionlist.end();
259 ++it )
261 QString tag = *it;
262 int index;
264 index = tag.findRev('/');
265 if (index != -1) tag = tag.mid(index + 1);
267 index = tag.findRev('.');
268 if (index != -1) tag.truncate(index);
270 KSimpleConfig entry(*it);
271 entry.setGroup(QString::fromLatin1("KCM Locale"));
272 QString name = entry.readEntry(QString::fromLatin1("Name"));
274 combo->insertSubmenu( name, '-' + tag, sub );
277 // add all languages to the list
278 QStringList countrylist = KGlobal::dirs()->findAllResources("locale", sub + QString::fromLatin1("*/entry.desktop"));
279 countrylist.sort();
281 for ( QStringList::ConstIterator it = countrylist.begin();
282 it != countrylist.end(); ++it )
284 KSimpleConfig entry(*it);
285 entry.setGroup(QString::fromLatin1("KCM Locale"));
286 QString name = entry.readEntry(QString::fromLatin1("Name"));
287 QString submenu = '-' + entry.readEntry(QString::fromLatin1("Region"));
289 QString tag = *it;
290 int index = tag.findRev('/');
291 tag.truncate(index);
292 index = tag.findRev('/');
293 tag = tag.mid(index+1);
294 combo->insertLanguage(tag, name, sub, submenu);
298 /** Ok push */
299 void KControlHeader::slotOk()
301 insertHeader();
302 configWrite();
303 accept();
306 /** Read settings */
307 void KControlHeader::configRead()
309 KConfig *config = new KConfig("emaildefaults");
310 KConfig *appconfig = KGlobal::config();
312 config->setGroup("UserInfo");
314 if( _keducaFile->getHeader( "name" ).isEmpty() )
315 _headerName->setText(config->readEntry("FullName", QString::null ));
316 else
317 _headerName->setText( _keducaFile->getHeader("name") );
319 if( _keducaFile->getHeader( "email" ).isEmpty() )
320 _headerEmail->setText(config->readEntry("EmailAddress", QString::null ));
321 else
322 _headerEmail->setText( _keducaFile->getHeader("email") );
324 _headerWWW->setText( _keducaFile->getHeader("www") );
326 if( !_keducaFile->getHeader("language").isEmpty() )
328 _headerLang->setCurrentItem( _keducaFile->getHeader("language") );
330 else
332 config->setGroup("Locale");
333 _headerLang->setCurrentItem( config->readEntry("Country") );
336 appconfig->setGroup("General");
337 _defaultCategories = appconfig->readListEntry("Categories");
338 if( _defaultCategories.count() == 0 )
340 _defaultCategories.append(i18n("Computers"));
342 _defaultCategories.sort();
343 _headerCategory->insertStringList( _defaultCategories );
344 if( !_keducaFile->getHeader( "category" ).isEmpty() ) _headerCategory->setEditText( _keducaFile->getHeader("category") );
346 _headerType->insertItem( i18n("Test") );
347 _headerType->insertItem( i18n("Test with Question Points") );
348 _headerType->insertItem( i18n("Test with Answers Points") );
349 _headerType->insertItem( i18n("Slidershow") );
350 _headerType->insertItem( i18n("Exam") );
351 _headerType->insertItem( i18n("Psychotechnic Test") );
352 if( QString(_keducaFile->getHeader("type")).toInt() > 0 ) _headerType->setCurrentItem( QString(_keducaFile->getHeader("type")).toInt() -1 );
354 _headerLevel->insertItem( i18n("Easy") );
355 _headerLevel->insertItem( i18n("Normal") );
356 _headerLevel->insertItem( i18n("Expert") );
357 _headerLevel->insertItem( i18n("Supreme") );
358 if( QString(_keducaFile->getHeader("level")).toInt() >0 ) _headerLevel->setCurrentItem( QString(_keducaFile->getHeader("level")).toInt() -1 );
360 _headerPicture->setURL( _keducaFile->getHeader("image") );
361 _headerTitle->setText( _keducaFile->getHeader("title") );
363 appconfig->setGroup("kcontrolheader");
364 QSize *defaultSize = new QSize(500,400);
365 resize( appconfig->readSizeEntry("Geometry", defaultSize ) );
366 delete config;
369 /** Write settings */
370 void KControlHeader::configWrite()
372 KConfig *config = KGlobal::config();
373 config->setGroup("kcontrolheader");
374 config->writeEntry("Geometry", size() );
375 config->sync();