Logo Search packages:      
Sourcecode: kalzium version File versions  Download package

QGraphicsWidget * nuclearCalculator::graphicsWidget (  ) [virtual]

FIXME

Definition at line 126 of file nuclearCalculator.cpp.

References elementChanged(), finalAmtChanged(), halfLifeChanged(), initAmtChanged(), KalziumDataObject::instance(), isotopeChanged(), ChemicalDataObject::name, reset(), and timeChanged().

{
//FIXME:
// Currently the spin boxes are integer, please convert them into double after
// doubleSpinBoxes are available

    if (!m_widget) {
        // Position all UI elements
        m_widget = new QGraphicsWidget(this);
        Plasma::Frame *pHeader = new Plasma::Frame(this);
        pHeader->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum);
        pHeader->setText(i18n("Nuclear Calculator"));

        Plasma::GroupBox *pGroupBox1 = new Plasma::GroupBox(this);
        Plasma::GroupBox *pGroupBox2 = new Plasma::GroupBox(this);

        QGraphicsGridLayout *pGridLayout = new QGraphicsGridLayout(pGroupBox1);
        QGraphicsGridLayout *pGridLayout2 = new QGraphicsGridLayout(pGroupBox2);
        QGraphicsLinearLayout *pVLayout = new QGraphicsLinearLayout(Qt::Vertical,m_widget);
        pVLayout->addItem(pGroupBox1);
        pVLayout->addItem(pGroupBox2);
        // pVLayout->addItem(new Plasma::)

        // here comes the element - isotope and halfLife info part
        Plasma::Label *eleLabel = new Plasma::Label(this);
        eleLabel->nativeWidget()->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
        eleLabel->setText(i18n("Element name:"));
        Plasma::Label *isoLabel = new Plasma::Label(this);
        isoLabel->nativeWidget()->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
        isoLabel->setText(i18n("Isotope mass:"));
        Plasma::Label *hLifeLabel = new Plasma::Label(this);
        hLifeLabel->nativeWidget()->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
        hLifeLabel->setText(i18n("Half-Life"));

        m_element = new Plasma::ComboBox(this);
        m_element->setZValue(2);
        m_isotope = new Plasma::ComboBox(this);
        m_isotope->setZValue(1);

        m_halfLife = new Plasma::SpinBox(this);
        m_halfLife->nativeWidget()->setMinimumWidth(100);
        m_halfLife->nativeWidget()->setMaximum(1000000000);
        //m_halfLife->setDecimals(4);
        m_halfLife->setMaximum(1e+09);

        m_halfLifeUnit = new Plasma::ComboBox(this);
        m_halfLifeUnit->nativeWidget()->insertItems(0, QStringList()
         << i18n("year")
         << i18n("seconds")
         << i18n("minutes")
         << i18n("hours")
         << i18n("days")
         << i18n("weeks"));
        m_halfLifeUnit->setZValue(6);

        pGridLayout->addItem(pHeader, 0, 0, 1, 4);
        pGridLayout->addItem(eleLabel, 1, 0);
        pGridLayout->addItem(m_element, 1, 1);
        pGridLayout->addItem(isoLabel, 2, 0);
        pGridLayout->addItem(m_isotope, 2, 1);
        pGridLayout->addItem(hLifeLabel, 3, 0);
        pGridLayout->addItem(m_halfLifeUnit, 3, 2);
        pGridLayout->addItem(m_halfLife, 3, 1);

        // Here comes the amount and time part

        // Calculation mode
        Plasma::Label *calcModeLabel = new Plasma::Label(this);
        calcModeLabel->nativeWidget()->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
        calcModeLabel->setText(i18n("Calculation Mode:"));

        m_calculationMode = new Plasma::ComboBox(this);
        m_calculationMode->setZValue(3);
        m_calculationMode->nativeWidget()->insertItems(0, QStringList()
            << i18n("Initial amount")
            << i18n("Final amount")
            << i18n("Time")
        );

        Plasma::Label *initLabel = new Plasma::Label(this);
        initLabel->nativeWidget()->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
        initLabel->setText(i18n("Initial amount:"));
        Plasma::Label *finalLabel = new Plasma::Label(this);
        finalLabel->nativeWidget()->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
        finalLabel->setText(i18n("Final amount:"));
        Plasma::Label *timeLabel = new Plasma::Label(this);
        timeLabel->nativeWidget()->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
        timeLabel->setText(i18n("Time"));
/*x   Plasma::Label *m_sliderLabel = new Plasma::Label(this);
        m_sliderLabel->nativeWidget()->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
        m_sliderLabel->setText(i18n("Time in Half-Lives"));*/

        m_numHalfLives = new Plasma::Label(this);
        m_numHalfLives->nativeWidget()->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
        m_numHalfLives->setText(i18n("0 seconds"));
        m_initAmt = new Plasma::SpinBox(this);
        m_initAmt->nativeWidget()->setMinimumWidth(200);
        m_initAmt->nativeWidget()->setMaximum(1000000000);
        //m_initAmt->setDecimals(4);
        m_initAmt->setMaximum(1e+09);
        m_finalAmt = new Plasma::SpinBox(this);
        m_finalAmt->nativeWidget()->setMinimumWidth(200);
        m_finalAmt->nativeWidget()->setMaximum(1000000000);
        //m_finalAmt->setDecimals(4);
        m_finalAmt->setMaximum(1e+09);
        m_time = new Plasma::SpinBox(this);
        m_time->nativeWidget()->setMinimumWidth(200);
        m_time->nativeWidget()->setMaximum(1000000000);
        //m_time->setDecimals(4);
        m_time->setMaximum(1e+09);

        m_initUnit = new Plasma::ComboBox(this);
        m_initUnit->setZValue(2);
        m_initUnit->nativeWidget()->insertItems(0, QStringList()
         << i18n("grams")
         << i18n("tons")
         << i18n("carats")
         << i18n("pounds")
         << i18n("ounces")
         << i18n("troy ounces"));
        m_initUnit->setZValue(3);

        m_finalUnit = new Plasma::ComboBox(this);
        m_finalUnit->setZValue(2);
        m_finalUnit->nativeWidget()->insertItems(0, QStringList()
         << i18n("grams")
         << i18n("tons")
         << i18n("carats")
         << i18n("pounds")
         << i18n("ounces")
         << i18n("troy ounces"));
        m_finalUnit->setZValue(2);

        m_timeUnit = new Plasma::ComboBox(this);
        m_timeUnit->setZValue(2);
        m_timeUnit->nativeWidget()->insertItems(0, QStringList()
         << i18n("year")
         << i18n("seconds")
         << i18n("minutes")
         << i18n("hours")
         << i18n("days")
         << i18n("weeks"));
        m_timeUnit->setZValue(1);

        m_initType = new Plasma::ComboBox(this);
        m_initType->setZValue(2);
        m_initType->nativeWidget()->insertItems(0, QStringList()
         << i18n("Mass")
         << i18n("moles"));
        m_initType->setZValue(2);

        m_finalType = new Plasma::ComboBox(this);
        m_finalType->setZValue(2);
        m_finalType->nativeWidget()->insertItems(0, QStringList()
         << i18n("Mass")
         << i18n("moles"));
            m_finalType->setZValue(1);

        /*m_slider = new Plasma::Slider(this);
        m_slider->setRange(0, 100);
        m_slider->setOrientation(Qt::Horizontal);
        m_slider->setMaximum(100); */

        m_error = new Plasma::Label(this);

        m_reset = new Plasma::PushButton(this);
        m_reset->setText(i18n("Reset"));

        pGridLayout2->addItem(calcModeLabel, 5, 0);
        pGridLayout2->addItem(initLabel, 6, 0);
        pGridLayout2->addItem(finalLabel, 7, 0);
        pGridLayout2->addItem(timeLabel, 8, 0);
//        pGridLayout2->addItem(m_sliderLabel, 9, 0);
        pGridLayout2->addItem(m_error, 10, 1, 1, 3);
        pGridLayout2->addItem(m_reset, 10, 0);

        pGridLayout2->addItem(m_calculationMode, 5, 1);
        pGridLayout2->addItem(m_initAmt, 6, 1);
        pGridLayout2->addItem(m_finalAmt, 7, 1);
        pGridLayout2->addItem(m_time, 8, 1);
//        pGridLayout2->addItem(m_slider , 9, 1);

        pGridLayout2->addItem(m_initType, 6, 3);
        pGridLayout2->addItem(m_finalType, 7, 3);
        pGridLayout2->addItem(m_numHalfLives, 9, 2);

        pGridLayout2->addItem(m_initUnit, 6, 2);
        pGridLayout2->addItem(m_finalUnit, 7, 2);
        pGridLayout2->addItem(m_timeUnit, 8, 2);

        // Positioning of UI elements done
        // Now add required properties to the UI widgets

        /**************************************************************************/
        //                       Nuclear Calculator set up                        //
        /**************************************************************************/
        KalziumDataObject *kdo = KalziumDataObject::instance();

        // add all element names to the comboBox in the user interface
        foreach(Element * e, kdo -> ElementList) {
            m_element->nativeWidget()->addItem(e -> dataAsString(ChemicalDataObject::name));
        }
            ///FIXME
        /* The last three elements will be removed because information is not available
            and causes the program to crash when selected. */
        int count = m_element->nativeWidget()->count();
        m_element->nativeWidget()->removeItem(count - 1);
        m_element->nativeWidget()->removeItem(count - 2);
        m_element->nativeWidget()->removeItem(count - 3);
        // Add all isotope names of Uranium ( by default )to the isotope comboBox
        reset();

        // Connect signals with slots
        connect(m_element->nativeWidget(), SIGNAL(activated(int)),
                this, SLOT(elementChanged(int)));
        connect(m_isotope->nativeWidget(), SIGNAL(activated(int)),
                this, SLOT(isotopeChanged(int)));
//FIXME change int to double in the following signals after finding doubleSpinBox
        connect(m_halfLife, SIGNAL(valueChanged(int)),
                    this, SLOT(halfLifeChanged()));
        connect(m_halfLifeUnit->nativeWidget(), SIGNAL(activated(int)),
                this, SLOT(halfLifeChanged()));
        connect(m_initAmt, SIGNAL(valueChanged(int)),
                this, SLOT(initAmtChanged()));
        connect(m_initUnit->nativeWidget(), SIGNAL(activated(int)),
                this, SLOT(initAmtChanged()));
        connect(m_initType->nativeWidget(), SIGNAL(activated(int)),
                this, SLOT(initAmtChanged()));
        connect(m_finalAmt, SIGNAL(valueChanged(int)),
                this, SLOT(finalAmtChanged()));
        connect(m_finalUnit->nativeWidget(), SIGNAL(activated(int)),
                this, SLOT(finalAmtChanged()));
        connect(m_finalType->nativeWidget(), SIGNAL(activated(int)),
                this, SLOT(finalAmtChanged()));
        connect(m_time, SIGNAL(valueChanged(int)),
                this, SLOT(timeChanged()));
        connect(m_timeUnit->nativeWidget(), SIGNAL(activated(int)),
                this, SLOT(timeChanged()));
/*        connect(m_slider, SIGNAL(valueChanged(int)),
                this, SLOT(sliderMoved(int)));*/
        connect(m_calculationMode->nativeWidget(), SIGNAL(activated(int)),
                        this, SLOT(setMode(int)));
        connect(m_reset, SIGNAL(clicked()),
                        this, SLOT(reset()));
        /**************************************************************************/
        // Nuclear Calculator setup complete
        /**************************************************************************/
      }
    return m_widget;
}

Here is the call graph for this function:


Generated by  Doxygen 1.6.0   Back to index