~ubuntu-branches/ubuntu/precise/kalzium/precise

« back to all changes in this revision

Viewing changes to src/detailinfodlg.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Philip Muškovac
  • Date: 2011-07-03 12:28:58 UTC
  • Revision ID: james.westby@ubuntu.com-20110703122858-q1yyxncs89e4w0hs
Tags: upstream-4.6.90+repack
Import upstream version 4.6.90+repack

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
    begin                : Tue Apr 8 2003
 
3
    copyright            : (C) 2003, 2004, 2005, 2006 by Carsten Niehaus
 
4
    email                : cniehaus@kde.org
 
5
 ***************************************************************************/
 
6
 
 
7
/***************************************************************************
 
8
 *                                                                         *
 
9
 *   This program is free software; you can redistribute it and/or modify  *
 
10
 *   it under the terms of the GNU General Public License as published by  *
 
11
 *   the Free Software Foundation; either version 2 of the License, or     *
 
12
 *   (at your option) any later version.                                   *
 
13
 *                                                                         *
 
14
 ***************************************************************************/
 
15
 
 
16
#include "detailinfodlg.h"
 
17
#include "isotope.h"
 
18
#include "kalziumdataobject.h"
 
19
 
 
20
#include <klocale.h>
 
21
#include <khtml_part.h>
 
22
#include <dom/html_base.h>
 
23
#include <dom/html_document.h>
 
24
#include <khtmlview.h>
 
25
#include <kstandarddirs.h>
 
26
#include <kactioncollection.h>
 
27
#include <kpagewidgetmodel.h>
 
28
#include <ktoolinvocation.h>
 
29
#include <krun.h>
 
30
 
 
31
#include "psetables.h"
 
32
 
 
33
#include <QFile>
 
34
#include <QLabel>
 
35
#include <QImage>
 
36
#include <QPushButton>
 
37
#include <QStackedWidget>
 
38
 
 
39
#include "element.h"
 
40
#include "orbitswidget.h"
 
41
#include "detailedgraphicaloverview.h"
 
42
#include "spectrumviewimpl.h"
 
43
#include "kalziumutils.h"
 
44
#include "prefs.h"
 
45
 
 
46
DetailedInfoDlg::DetailedInfoDlg( int el , QWidget *parent )
 
47
        : KPageDialog( parent ), m_tableTyp( 0 )
 
48
{
 
49
    setFaceType( List );
 
50
    setButtons( Help | User1 | User2 | Close );
 
51
    setDefaultButton( Close );
 
52
    setButtonGuiItem( User1, KGuiItem( i18nc( "Next element", "Next" ),
 
53
                                       ( layoutDirection() == Qt::LeftToRight ) ? "arrow-right" : "arrow-left", i18n( "Goes to the next element" ) ) );
 
54
    setButtonGuiItem( User2, KGuiItem( i18nc( "Previous element", "Previous" ),
 
55
                                       ( layoutDirection() == Qt::LeftToRight ) ? "arrow-left" : "arrow-right", i18n( "Goes to the previous element" ) ) );
 
56
    resize(820, 580);
 
57
    m_baseHtml = KGlobal::dirs()->findResourceDir( "appdata", "data/" ) + "data/htmlview/";
 
58
    m_baseHtml2 = KGlobal::dirs()->findResourceDir( "appdata", "data/" ) + "data/hazardsymbols/";
 
59
 
 
60
//X     m_picsdir = KGlobal::dirs()->findResourceDir( "appdata", "elempics/" ) + "elempics/";
 
61
 
 
62
    // creating the tabs but not the contents, as that will be done when setting the element
 
63
    createContent();
 
64
 
 
65
    m_actionCollection = new KActionCollection(this);
 
66
    KStandardAction::quit(this, SLOT(close()), m_actionCollection);
 
67
 
 
68
    connect( this, SIGNAL( user1Clicked() ), this, SLOT( slotUser1() ) );
 
69
    connect( this, SIGNAL( user2Clicked() ), this, SLOT( slotUser2() ) );
 
70
    connect( this, SIGNAL( helpClicked() ), this, SLOT( slotHelp() ) );
 
71
 
 
72
    // setting the element and updating the whole dialog
 
73
    setElement( el );
 
74
}
 
75
 
 
76
DetailedInfoDlg::~DetailedInfoDlg()
 
77
{
 
78
    qDeleteAll(m_htmlpages);
 
79
}
 
80
 
 
81
void DetailedInfoDlg::setElement( int el )
 
82
{
 
83
    Element *element = KalziumDataObject::instance()->element( el );
 
84
    if ( !element ) return;
 
85
 
 
86
    m_element = element;
 
87
    m_elementNumber = el;
 
88
 
 
89
    emit elementChanged( m_elementNumber );
 
90
 
 
91
    reloadContent();
 
92
 
 
93
    enableButton( User1, true );
 
94
    enableButton( User2, true );
 
95
    if ( m_elementNumber == 1 )
 
96
        enableButton( User2, false );
 
97
    else if ( m_elementNumber == KalziumDataObject::instance()->numberOfElements() )
 
98
        enableButton( User1, false );
 
99
}
 
100
 
 
101
// void DetailedInfoDlg::setOverviewBackgroundColor( const QColor &bgColor )
 
102
// {
 
103
// //     dTab->setBackgroundColor( bgColor );
 
104
// }
 
105
 
 
106
void DetailedInfoDlg::setTableType( int tableTyp )
 
107
{
 
108
    m_tableTyp = tableTyp;
 
109
}
 
110
 
 
111
KHTMLPart* DetailedInfoDlg::addHTMLTab( const QString& title, const QString& icontext, const QString& iconname )
 
112
{
 
113
    QWidget* frame = new QWidget(this);
 
114
    KPageWidgetItem *item = addPage( frame, title );
 
115
    item->setHeader( icontext );
 
116
    item->setIcon( KIcon( iconname ) );
 
117
    QVBoxLayout *layout = new QVBoxLayout( frame );
 
118
    layout->setMargin( 0 );
 
119
 
 
120
    KHTMLPart *w = new KHTMLPart( frame, frame );
 
121
    w->setJScriptEnabled(false);
 
122
    w->setJavaEnabled(false);
 
123
    w->setMetaRefreshEnabled(false);
 
124
    w->setPluginsEnabled(false);
 
125
    connect(w->browserExtension(), SIGNAL(openUrlRequest(KUrl)), this, SLOT(slotLinkClicked(KUrl)));
 
126
    layout->addWidget( w->view() );
 
127
 
 
128
    return w;
 
129
}
 
130
 
 
131
void DetailedInfoDlg::fillHTMLTab( KHTMLPart* htmlpart, const QString& htmlcode )
 
132
{
 
133
    if ( !htmlpart ) return;
 
134
 
 
135
    htmlpart->begin();
 
136
    htmlpart->write( htmlcode );
 
137
 
 
138
    // set the background color of the document to match that of the dialog
 
139
    DOM::HTMLElement element = htmlpart->htmlDocument().body();
 
140
    if ( element.tagName() == "body" ) {
 
141
        const QColor backgroundColor = palette().background().color();
 
142
        ((DOM::HTMLBodyElement)element).setBgColor( backgroundColor.name() );
 
143
    }
 
144
 
 
145
    htmlpart->end();
 
146
}
 
147
 
 
148
QString DetailedInfoDlg::getHtml( DATATYPE type )
 
149
{
 
150
 
 
151
    QString html =
 
152
        "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">"
 
153
        "<html><head><title>Chemical data</title>"
 
154
        "<link rel=\"stylesheet\" type=\"text/css\" href=\"" + m_baseHtml + "style.css\" />"
 
155
        "<base href=\"" + m_baseHtml + "\"/></head><body>"
 
156
        "<div class=\"chemdata\"><div><table summary=\"header\" class=\"header\">"
 
157
        "<tr><td>" + m_element->dataAsString( ChemicalDataObject::symbol ) + "</td><td>"
 
158
        + createWikiLink( m_element->dataAsString( ChemicalDataObject::name ) ) + "</td><td>"
 
159
        + i18n( "Block: %1", m_element->dataAsString( ChemicalDataObject::periodTableBlock ) ) +
 
160
        "</td></tr></table></div>"
 
161
        "<table summary=\"characteristics\" class=\"characterstics\">";
 
162
 
 
163
    switch ( type )
 
164
    {
 
165
    case MISC:
 
166
    {
 
167
        // discovery date and discoverers
 
168
        html.append( "<tr><td><img src=\"discovery.png\" alt=\"icon\"/></td><td>" );
 
169
        html += KalziumUtils::prettyUnit( m_element, ChemicalDataObject::date );
 
170
        QString discoverers = m_element->dataAsString( ChemicalDataObject::discoverers );
 
171
        if ( !discoverers.isEmpty() ) {
 
172
            discoverers = discoverers.replace( ';', ", " );
 
173
            html += "<br />" + i18n( "It was discovered by %1.", discoverers );
 
174
        }
 
175
        html.append( "</td></tr>" );
 
176
        // origin of the name
 
177
        QString nameorigin = m_element->dataAsString( ChemicalDataObject::nameOrigin );
 
178
        if ( !nameorigin.isEmpty() ) {
 
179
            html.append( "<tr><td><img src=\"book.png\" alt=\"icon\"/></td><td>" );
 
180
            html.append( i18n( "Origin of the name:<br/>%1", nameorigin ) );
 
181
            html.append( "</td></tr>" );
 
182
        }
 
183
        //X                     if ( m_element->artificial() || m_element->radioactive() )
 
184
        //X                     {
 
185
        //X                             html.append( "<tr><td><img src=\"structure.png\" alt=\"icon\"/></td><td>" );
 
186
        //X                             if ( !m_element->radioactive() )
 
187
        //X                                     html.append( i18n( "This element is artificial" ));
 
188
        //X                             else if ( !m_element->artificial() )
 
189
        //X                                     html.append( i18n( "This element is radioactive" ));
 
190
        //X                             else
 
191
        //X                                     html.append( i18n( "This element is radioactive and artificial" ));
 
192
        //X                             html.append( "</td></tr>" );
 
193
        //X                     }
 
194
        break;
 
195
    }
 
196
    case ISOTOPES:
 
197
    {
 
198
        html.append( "<tr><td>" );
 
199
        html.append( isotopeTable() );
 
200
        html.append( "</td></tr>" );
 
201
        break;
 
202
    }
 
203
    case DATA:
 
204
    {
 
205
        // melting point
 
206
        html.append( "<tr><td><img src=\"meltingpoint.png\" alt=\"icon\"/></td><td>" );
 
207
        html.append( createWikiLink( i18n( "Melting Point") ) );
 
208
        html.append( "</td><td>" );
 
209
        html.append( KalziumUtils::prettyUnit( m_element, ChemicalDataObject::meltingpoint ) ) ;
 
210
        html.append( "</td></tr>" );
 
211
 
 
212
        // boiling point
 
213
        html.append( "<tr><td><img src=\"boilingpoint.png\" alt=\"icon\"/></td><td>" );
 
214
        html.append( createWikiLink( i18n( "Boiling Point") ) );
 
215
        html.append( "</td><td>" );
 
216
        html.append( KalziumUtils::prettyUnit( m_element, ChemicalDataObject::boilingpoint )  ) ;
 
217
        html.append( "</td></tr>" );
 
218
 
 
219
        // electro affinity
 
220
        html.append( "<tr><td><img src=\"electronaffinity.png\" alt=\"icon\"/></td><td>" );
 
221
        html.append( createWikiLink( i18n( "Electron Affinity") ) );
 
222
        html.append( "</td><td>" );
 
223
        html.append( KalziumUtils::prettyUnit( m_element, ChemicalDataObject::electronAffinity )  ) ;
 
224
        html.append( "</td></tr>" );
 
225
 
 
226
        //Electronic configuration
 
227
        html.append( "<tr><td><img src=\"structure.png\" alt=\"icon\"/></td><td>" );
 
228
        html.append( createWikiLink( i18n( "Electronic configuration") ) );
 
229
        html.append( "</td><td>" );
 
230
        html.append( KalziumUtils::prettyUnit(m_element, ChemicalDataObject::electronicConfiguration ) ) ;
 
231
        html.append( "</td></tr>" );
 
232
 
 
233
        // covalent radius
 
234
        html.append( "<tr><td><img src=\"radius.png\" alt=\"icon\"/></td><td>" );
 
235
        html.append( createWikiLink( i18n( "Covalent Radius") ) );
 
236
        html.append( "</td><td>" );
 
237
        html.append( KalziumUtils::prettyUnit( m_element, ChemicalDataObject::radiusCovalent ) ) ;
 
238
        html.append( "</td></tr>" );
 
239
 
 
240
        // van der Waals radius
 
241
        html.append( "<tr><td><img src=\"radius.png\" alt=\"icon\"/></td><td>" );
 
242
        html.append( createWikiLink( i18n( "van der Waals Radius") ) );
 
243
        html.append( "</td><td>" );
 
244
        html.append( KalziumUtils::prettyUnit( m_element, ChemicalDataObject::radiusVDW ) ) ;
 
245
        html.append( "</td></tr>" );
 
246
 
 
247
        // mass
 
248
        html.append( "<tr><td><img src=\"mass.png\" alt=\"icon\"/></td><td>" );
 
249
        html.append( createWikiLink( i18n( "Atomic mass") ) );
 
250
        html.append( "</td><td>" );
 
251
        html.append( KalziumUtils::prettyUnit( m_element, ChemicalDataObject::mass ) ) ;
 
252
        html.append( "</td></tr>" );
 
253
 
 
254
        // 1st ionization energy
 
255
        html.append( "<tr><td><img src=\"ionization.png\" alt=\"icon\"/></td><td>" );
 
256
        html.append( createWikiLink( i18n( "Ionization energy"), i18n("First Ionization energy") ) );
 
257
        html.append( "</td><td>" );
 
258
        html.append( KalziumUtils::prettyUnit( m_element, ChemicalDataObject::ionization ) ) ;
 
259
        html.append( "</td></tr>" );
 
260
 
 
261
        // electro negativity
 
262
        html.append( "<tr><td><img src=\"structure.png\" alt=\"icon\"/></td><td>" );
 
263
        html.append( createWikiLink( i18n( "Electronegativity") ) );
 
264
        html.append( "</td><td>" );
 
265
        html.append( KalziumUtils::prettyUnit( m_element, ChemicalDataObject::electronegativityPauling ) ) ;
 
266
        html.append( "</td></tr>" );
 
267
 
 
268
        // Oxidation numbers
 
269
        html.append( "<tr><td><img src=\"ionization.png\" alt=\"icon\"/></td><td>" );
 
270
        html.append( createWikiLink( i18n( "Oxidation numbers") ) );
 
271
        html.append( "</td><td>" );
 
272
        html.append( KalziumUtils::prettyUnit( m_element, ChemicalDataObject::oxidation ) ) ;
 
273
        html.append( "</td></tr>" );
 
274
        break;
 
275
    }
 
276
    case EXTRA:
 
277
    {
 
278
        QString language( KGlobal::locale()->languageCodeToName( KGlobal::locale()->language() ));
 
279
 
 
280
        //Wikipedia.org
 
281
//         html.append ( "<tr><td><img src=\"wiki.png\" alt=\"icon\"/></td><td>" );
 
282
        html.append ( "<tr><td>" );
 
283
        html.append ( createWikiLink(m_element->dataAsString( ChemicalDataObject::name ), "Wikipedia " + language) );
 
284
        html.append ( "</td></tr>" );
 
285
 
 
286
        //http://education.jlab.org/itselemental/ele001.html
 
287
        html.append ( "<tr><td>" );
 
288
        html.append ( "<a href=\"http://" );        // http://
 
289
        html.append ( "education.jlab.org/itselemental/ele" );
 
290
        html.append ( QString("%1").arg(m_element->dataAsString( ChemicalDataObject::atomicNumber ), 3, '0' ));
 
291
        html.append ( ".html" );
 
292
        html.append ( "\" target=\"_blank\" > ");
 
293
        html.append ( "Jefferson Lab" );
 
294
        html.append ( "</a>" );
 
295
        html.append ( "</td></tr>" );
 
296
 
 
297
        // FIXME only works with english locals
 
298
        html.append ( "<tr><td>" );
 
299
        html.append ( "<a href=\"http://");        // http://
 
300
        html.append ("www.webelements.com/");
 
301
        if ( KGlobal::locale()->language().split("_").at(0) == "en" ) {
 
302
            html.append ( m_element->dataAsString( ChemicalDataObject::name ).toLower() ); // hydrogen
 
303
        }
 
304
        html.append ( "\" target=\"_blank\" >");
 
305
        html.append ( "Webelements");
 
306
        html.append ( "</a></td></tr>" );
 
307
 
 
308
        //chemipedia.org
 
309
        //html.append( "<tr><td><img src=\"chemi.png\" alt=\"icon\"/></td><td>" );
 
310
 
 
311
        //html.append( "</td></tr>" );
 
312
        //physics.nist.gov
 
313
        //html.append( "<tr><td><img src=\"nist.png\" alt=\"icon\"/></td><td>" );
 
314
 
 
315
        //html.append( "</td></tr>" );
 
316
    }
 
317
    }
 
318
 
 
319
    html += "</table></div></body></html>";
 
320
 
 
321
    return html;
 
322
}
 
323
 
 
324
QString DetailedInfoDlg::isotopeTable() const
 
325
{
 
326
    QList<Isotope*> list = KalziumDataObject::instance()->isotopes( m_elementNumber );
 
327
 
 
328
    QString html;
 
329
 
 
330
    html = "<table class=\"isotopes\" cellspacing=\"0\"><tr><td colspan=\"7\">";
 
331
    html += i18n( "Isotope-Table" );
 
332
    html += "</tr></td><tr><td><b>";
 
333
    html += i18n( "Mass" );
 
334
    html += "</b></td><td><b>";
 
335
    html += i18n( "Neutrons" );
 
336
    html += "</b></td><td><b>";
 
337
    html += i18n( "Percentage" );
 
338
    html += "</b></td><td><b>";
 
339
    html += i18n( "Half-life period" );
 
340
    html += "</b></td><td><b>";
 
341
    html += i18n( "Energy and Mode of Decay" );
 
342
    html += "</b></td><td><b>";
 
343
    html += i18n( "Spin and Parity" );
 
344
    html += "</b></td><td><b>";
 
345
    html += i18n( "Magnetic Moment" );
 
346
    html += "</b></td></tr>";
 
347
 
 
348
    foreach( Isotope * isotope , list )
 
349
    {
 
350
        html.append( "<tr><td align=\"right\">" );
 
351
        if ( isotope->mass() > 0.0 )
 
352
            html.append( i18n( "%1 u", isotope->mass() ) );
 
353
        html.append( "</td><td>" );
 
354
        html.append( QString::number( (( isotope )->nucleons()-( isotope )->parentElementNumber()) ) );
 
355
        html.append( "</td><td>" );
 
356
        if ( !( isotope )->abundance().isEmpty() )
 
357
            html.append( i18nc( "this can for example be '24%'", "%1%", ( isotope )->abundance() ) );
 
358
        html.append( "</td><td>" );
 
359
        if ( ( isotope )->halflife() > 0.0 )
 
360
            html.append( i18nc( "The first argument is the value, the second is the unit. For example '17 s' for '17 seconds',.", "%1 %2", ( isotope )->halflife(), ( isotope )->halflifeUnit( ) ) );
 
361
        html.append( "</td><td>" );
 
362
        if ( ( isotope )->alphalikeliness() > 0.0) {
 
363
            if ( ( isotope )->alphadecay() > 0.0 )
 
364
                html.append( i18n( "%1 MeV", ( isotope )->alphadecay() ));
 
365
            html.append( i18n( " %1",  QChar( 945 ) ));
 
366
            if ( ( isotope )->alphalikeliness() < 100.0)
 
367
                html.append( i18n( "(%1%)", ( isotope )->alphalikeliness()));
 
368
            if ( ( isotope )->betaminuslikeliness() > 0.0 || ( isotope )->betapluslikeliness() > 0.0 || ( isotope )->eclikeliness() > 0.0)
 
369
                html.append( i18n( ", " ) );
 
370
        }
 
371
        if ( ( isotope )->betaminuslikeliness() > 0.0) {
 
372
            if ( ( isotope )->betaminusdecay() > 0.0 )
 
373
                html.append( i18n( "%1 MeV", ( isotope )->betaminusdecay() ));
 
374
            html.append( i18n( " %1<sup>-</sup>", QChar( 946 )  ));
 
375
            if ( ( isotope )->betaminuslikeliness() < 100.0)
 
376
                html.append( i18n( "(%1%)", ( isotope )->betaminuslikeliness() ));
 
377
 
 
378
            if ( ( isotope )->betapluslikeliness() > 0.0 || ( isotope )->eclikeliness() > 0.0 )
 
379
                html.append( i18n( ", " ) );
 
380
        }
 
381
        if ( ( isotope )->betapluslikeliness() > 0.0)   {
 
382
            if ( ( isotope )->betaplusdecay() > 0.0 )
 
383
                html.append( i18n( "%1 MeV", ( isotope )->betaplusdecay() ));
 
384
            html.append( i18n( " %1<sup>+</sup>", QChar( 946 ) ));
 
385
            if ( ( isotope )->betapluslikeliness() == ( isotope )->eclikeliness() ) {
 
386
                if ( ( isotope )->ecdecay() > 0.0 ) {
 
387
                    html.append( i18n( "%1 MeV", ( isotope )->ecdecay() ));
 
388
                }
 
389
                html.append( i18nc( "Acronym of Electron Capture"," EC" ) );
 
390
            }
 
391
            if ( ( isotope )->betapluslikeliness() < 100.0)
 
392
                html.append( i18n( "(%1%)", ( isotope )->betapluslikeliness() ));
 
393
            html += ' ';
 
394
        }
 
395
        if ( ( isotope )->eclikeliness() > 0.0 ) {
 
396
            if ( ( isotope )->ecdecay() > 0.0 )
 
397
                html.append( i18n( "%1 MeV", ( isotope )->ecdecay()  ));
 
398
            html.append( i18nc( "Acronym of Electron Capture"," EC" ) );
 
399
            if ( ( isotope )->eclikeliness() < 100.0 )
 
400
                html.append( i18n( "(%1%)", ( isotope )->eclikeliness() ));
 
401
        }
 
402
        html.append( "</td><td>" );
 
403
        html.append( ( isotope )->spin() );
 
404
        html.append( "</td><td>" );
 
405
        if ( !( isotope )->magmoment().isEmpty() )
 
406
            html.append( i18n( "%1 %2<sub>n</sub>", ( isotope )->magmoment(), QChar( 956 ) ) );
 
407
        html.append( "</td></tr>" );
 
408
 
 
409
    }
 
410
 
 
411
    html += "</table>";
 
412
 
 
413
    return html;
 
414
}
 
415
 
 
416
void DetailedInfoDlg::createContent()
 
417
{
 
418
    KPageWidgetItem *item = 0;
 
419
 
 
420
 
 
421
   // Removed the overview Tab, because its an Dockwidget and dosn't show much information.
 
422
    // overview tab
 
423
//     QWidget *m_pOverviewTab = new QWidget();
 
424
//     item = addPage( m_pOverviewTab, i18n( "Overview" ) );
 
425
//     item->setHeader( i18n( "Overview" ) );
 
426
//     item->setIcon( KIcon( "overview" ) );
 
427
//     QVBoxLayout *overviewLayout = new QVBoxLayout( m_pOverviewTab );
 
428
//     overviewLayout->setMargin( 0 );
 
429
//     dTab = new DetailedGraphicalOverview( m_pOverviewTab );
 
430
//     dTab->setObjectName( "DetailedGraphicalOverview" );
 
431
//     overviewLayout->addWidget( dTab );
 
432
 
 
433
//X     // picture tab
 
434
//X     QWidget *m_pPictureTab = new QWidget();
 
435
//X     item = addPage( m_pPictureTab, i18n( "Picture" ) );
 
436
//X     item->setHeader( i18n( "What does this element look like?" ) );
 
437
//X     item->setIcon( KIcon( "elempic" ) );
 
438
//X     QVBoxLayout *mainLayout = new QVBoxLayout( m_pPictureTab );
 
439
//X     mainLayout->setMargin( 0 );
 
440
//X     piclabel = new QLabel( m_pPictureTab );
 
441
//X     piclabel->setMinimumSize( 400, 350 );
 
442
//X     mainLayout->addWidget( piclabel );
 
443
 
 
444
    // html tab
 
445
    m_htmlpages["new"] = addHTMLTab( i18n( "Data Overview" ), i18n( "Data Overview" ), "applications-science" );
 
446
 
 
447
    // atomic model tab
 
448
    QWidget *m_pModelTab = new QWidget(this);
 
449
    item = addPage( m_pModelTab, i18n( "Atom Model" ) );
 
450
    item->setHeader( i18n( "Atom Model" ) );
 
451
    item->setIcon( KIcon( "orbits" ) );
 
452
    QVBoxLayout *modelLayout = new QVBoxLayout( m_pModelTab );
 
453
    modelLayout->setMargin( 0 );
 
454
    wOrbits = new OrbitsWidget( m_pModelTab );
 
455
    modelLayout->addWidget( wOrbits );
 
456
 
 
457
    // html tabs
 
458
    m_htmlpages["isotopes"] = addHTMLTab( i18n( "Isotopes" ), i18n( "Isotopes" ), "isotopemap" );
 
459
    m_htmlpages["misc"] = addHTMLTab( i18n( "Miscellaneous" ), i18n( "Miscellaneous" ), "misc" );
 
460
 
 
461
 
 
462
    // spectrum widget tab
 
463
    QWidget *m_pSpectrumTab = new QWidget(this);
 
464
    item = addPage( m_pSpectrumTab, i18n( "Spectrum" ) );
 
465
    item->setHeader( i18n( "Spectrum" ) );
 
466
    item->setIcon( KIcon( "spectrum" ) );
 
467
    QVBoxLayout *spectrumLayout = new QVBoxLayout( m_pSpectrumTab );
 
468
    spectrumLayout->setMargin( 0 );
 
469
    m_spectrumStack = new QStackedWidget( m_pSpectrumTab );
 
470
    spectrumLayout->addWidget( m_spectrumStack );
 
471
    m_spectrumview = new SpectrumViewImpl( m_spectrumStack );
 
472
    m_spectrumview->setObjectName( "spectrumwidget" );
 
473
    m_spectrumStack->addWidget( m_spectrumview );
 
474
    m_spectrumLabel = new QLabel( m_spectrumStack );
 
475
    m_spectrumStack->addWidget( m_spectrumLabel );
 
476
 
 
477
    // html extra tab
 
478
    m_htmlpages["extra"] = addHTMLTab( i18n( "Extra information" ), i18n( "Extra Information" ), "applications-internet" );
 
479
}
 
480
 
 
481
void DetailedInfoDlg::reloadContent()
 
482
{
 
483
    // reading the most common data
 
484
    const QString element_name = m_element->dataAsString( ChemicalDataObject::name );
 
485
//     const QString element_symbol = m_element->dataAsString( ChemicalDataObject::symbol );
 
486
 
 
487
    // updating caption
 
488
    setCaption( i18nc( "For example Carbon (6)" , "%1 (%2)", element_name, m_elementNumber ) );
 
489
 
 
490
    // updating overview tab
 
491
//     dTab->setElement( m_elementNumber );
 
492
 
 
493
    //X         // updating picture tab
 
494
    //X         QString picpath = m_picsdir + element_symbol + ".jpg";
 
495
    //X         if ( QFile::exists( picpath ) )
 
496
    //X         {
 
497
    //X                 QImage img( picpath, "JPEG" );
 
498
    //X                 img = img.scaled( 400, 400, Qt::KeepAspectRatio );
 
499
    //X                 piclabel->setPixmap( QPixmap::fromImage( img ) );
 
500
    //X         }
 
501
    //X         else
 
502
    //X                 piclabel->setText( i18n( "No picture of %1 found.", element_name ) );
 
503
 
 
504
    // updating atomic model tab
 
505
    wOrbits->setElementNumber( m_elementNumber );
 
506
    /*
 
507
       wOrbits->setWhatsThis(
 
508
       i18n( "Here you can see the atomic hull of %1. %2 has the configuration %3." )
 
509
       .arg( m_element->dataAsString( ChemicalDataObject::name ) )
 
510
       .arg( m_element->dataAsString( ChemicalDataObject::name ) )
 
511
       .arg( "" ));//m_element->parsedOrbits() ) );
 
512
       */
 
513
 
 
514
    // updating html tabs
 
515
    fillHTMLTab( m_htmlpages["new"], getHtml( DATA ) );
 
516
    fillHTMLTab( m_htmlpages["misc"], getHtml( MISC ) );
 
517
    fillHTMLTab( m_htmlpages["isotopes"], getHtml( ISOTOPES ) );
 
518
    fillHTMLTab( m_htmlpages["extra"], getHtml( EXTRA ) );
 
519
 
 
520
    Spectrum * spec =  KalziumDataObject::instance()->spectrum( m_elementNumber );
 
521
 
 
522
    // updating spectrum widget
 
523
    if ( spec )
 
524
    {
 
525
        m_spectrumview->setSpectrum( spec );
 
526
        m_spectrumStack->setCurrentWidget( m_spectrumview );
 
527
    }
 
528
    else
 
529
    {
 
530
        m_spectrumLabel->setText( i18n( "No spectrum of %1 found.", element_name ) );
 
531
        m_spectrumStack->setCurrentWidget( m_spectrumLabel );
 
532
    }
 
533
 
 
534
}
 
535
 
 
536
QString DetailedInfoDlg::createWikiLink(QString link)
 
537
{
 
538
        return createWikiLink(link, link);
 
539
}
 
540
 
 
541
 
 
542
QString DetailedInfoDlg::createWikiLink(QString link, QString displayString)
 
543
{
 
544
        QString html;
 
545
        QString language( KGlobal::locale()->language() );
 
546
 
 
547
        //Wikipedia.org
 
548
        html.append ( "<a href=\"http://" );        // http://
 
549
        html.append ( language.split("_").at(0) );                        // en.
 
550
        html.append ( ".wikipedia.org/wiki/" );      // wikipedia.org
 
551
        html.append ( link );             // /hydrogen
 
552
        html.append ( "\" target=\"_blank\" > ");
 
553
        html.append ( displayString );
 
554
        html.append ( "</a>" );
 
555
        // Example from the comment "http://en.wikipedia.org/wiki/hydrogen"
 
556
 
 
557
        return html;
 
558
}
 
559
 
 
560
void DetailedInfoDlg::slotLinkClicked(const KUrl &url)
 
561
{
 
562
  if(!url.isEmpty() && url.isValid()) {
 
563
      KRun *krun = new KRun(url, 0);
 
564
      krun->setAutoDelete(true);
 
565
  }
 
566
}
 
567
 
 
568
 
 
569
void DetailedInfoDlg::slotHelp()
 
570
{
 
571
    //TODO fix this stuff...
 
572
#if 0
 
573
    QString chapter = "infodialog_overview";
 
574
    switch ( activePageIndex() )
 
575
    {
 
576
    case 0:
 
577
        chapter = "infodialog_overview";
 
578
        break;
 
579
    case 1:
 
580
        chapter = "infodialog_orbits";
 
581
        break;
 
582
    case 2:
 
583
        chapter = "infodialog_chemical";
 
584
        break;
 
585
    case 3:
 
586
        chapter = "infodialog_energies";
 
587
        break;
 
588
    case 4:
 
589
        chapter = "infodialog_misc";
 
590
        break;
 
591
    case 5:
 
592
        chapter = "infodialog_spectrum";
 
593
        break;
 
594
    case 6:
 
595
        chapter = "infodialog_warnings";
 
596
        break;
 
597
    }
 
598
#endif
 
599
    KToolInvocation::invokeHelp( "infodialog_spectrum", QLatin1String( "kalzium" ) );
 
600
}
 
601
 
 
602
void DetailedInfoDlg::slotUser1()
 
603
{
 
604
    setElement( pseTables::instance()->getTabletype(m_tableTyp)->nextOf( m_elementNumber ) );
 
605
}
 
606
 
 
607
void DetailedInfoDlg::slotUser2()
 
608
{
 
609
    setElement(  pseTables::instance()->getTabletype(m_tableTyp)->previousOf( m_elementNumber ) );
 
610
}
 
611
 
 
612
#include "detailinfodlg.moc"