From kde-commits Fri Apr 04 14:29:37 2008 From: Henry de Valence Date: Fri, 04 Apr 2008 14:29:37 +0000 To: kde-commits Subject: playground/base/plasma/applets/worldclock Message-Id: <1207319377.358763.3544.nullmailer () svn ! kde ! org> X-MARC-Message: https://marc.info/?l=kde-commits&m=120731938914980 SVN commit 793597 by hdevalence: Added semi-working checkbox on the lat/lon box and eliminated qt3 support flags from the CMakeLists.txt M +0 -2 CMakeLists.txt M +160 -73 latlonbox.cpp M +20 -2 latlonbox.h --- trunk/playground/base/plasma/applets/worldclock/CMakeLists.txt #793596:793597 @@ -6,8 +6,6 @@ # I don't know how. - hdevalence ##### -add_definitions (-DQT3_SUPPORT -DQT3_SUPPORT_WARNINGS) - project(worldclock) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/ ) --- trunk/playground/base/plasma/applets/worldclock/latlonbox.cpp #793596:793597 @@ -19,32 +19,50 @@ #include #include +#include #include #include #include #include +#include + #include "latlonbox.h" -LatLonBox::LatLonBox(QWidget *parent) : QWidget( parent ), +LatLonBox::LatLonBox(QWidget *parent, Marble::Dimension dimension ) : QWidget( parent ), m_layout(0), m_degreesSpin(0), m_minutesSpin(0), m_secondsSpin(0), m_degreesLabel(0), m_minutesLabel(0), - m_secondsLabel(0) + m_secondsLabel(0), + m_comboBox(0) { m_value = 0; + m_dimension = dimension; m_layout = new QHBoxLayout; setLayout( m_layout ); m_degreesSpin = new QSpinBox; - m_degreesSpin->setMinimum( -180 ); - m_degreesSpin->setMaximum( 180 ); + m_comboBox = new QComboBox; + if( m_dimension == Marble::Longitude ) { + m_degreesSpin->setMinimum( -180 ); + m_degreesSpin->setMaximum( 180 ); + m_comboBox->addItem( tr("E", "East, the direction" ) ); + m_comboBox->addItem( tr("W", "West, the direction" ) ); + } else if( m_dimension == Marble::Latitude ) { + m_degreesSpin->setMinimum( -90 ); + m_degreesSpin->setMaximum( 90 ); + m_comboBox->addItem( tr("N", "North, the direction" ) ); + m_comboBox->addItem( tr("S", "East, the direction" ) ); + } else { + qDebug() << "Unrecognized dimension"; + } m_degreesSpin->show(); + m_comboBox->show(); m_minutesSpin = new QSpinBox; //minimum value is -1 so we can @@ -68,6 +86,8 @@ m_layout->addWidget( m_minutesLabel ); m_layout->addWidget( m_secondsSpin ); m_layout->addWidget( m_secondsLabel ); + m_layout->addWidget( m_secondsLabel ); + m_layout->addWidget( m_comboBox ); connect( m_secondsSpin, SIGNAL( valueChanged( int ) ), this, SLOT( secondsOverflow( ) ) ); @@ -77,8 +97,75 @@ connect( m_degreesSpin, SIGNAL( valueChanged( int ) ), this, SLOT( recalculate( ) ) ); + + connect( m_comboBox, SIGNAL( currentIndexChanged( const QString & ) ), + this, SLOT( comboBoxChanged( const QString & ) ) ); } +void LatLonBox::checkComboBox() +{ + if( m_value < 0 ) { + m_comboBox->setEnabled(true); + if( m_dimension == Marble::Longitude && m_comboBox->currentText() == tr("N", "North, the direction" ) ) { + m_comboBox->setCurrentIndex( m_comboBox->findText( tr("S", "South, the direction" ) ) ); + } + if( m_dimension == Marble::Latitude && m_comboBox->currentText() == tr("E", "East, the direction" ) ) { + m_comboBox->setCurrentIndex( m_comboBox->findText( tr("W", "West, the direction" ) ) ); + } + } else if( m_value > 0 ) { + m_comboBox->setEnabled(true); + if( m_dimension == Marble::Longitude && m_comboBox->currentText() == tr("S", "South, the direction" ) ) { + m_comboBox->setCurrentIndex( m_comboBox->findText( tr("N", "North, the direction" ) ) ); + } + if( m_dimension == Marble::Latitude && m_comboBox->currentText() == tr("W", "West, the direction" ) ) { + m_comboBox->setCurrentIndex( m_comboBox->findText( tr("E", "East, the direction" ) ) ); + } + } else { + //m_value is zero, so long/lat do not apply + m_comboBox->setEnabled(false); + } +} + +void LatLonBox::comboBoxChanged( const QString &text ) +{ + if( ( text == tr("N", "North, the direction" ) || text == tr("E", "East, the direction" ) ) && + m_value < 0 ) { + m_value -= m_value * 2; + reverseRecalculate(); + } else if( ( text == tr("S", "South, the direction" ) || text == tr("W", "West, the direction" ) ) && + m_value > 0 ) { + m_value -= m_value * 2; + reverseRecalculate(); + } +} + +void LatLonBox::setDimension( Marble::Dimension dimension ) +{ + //don't do anything + if( m_dimension == dimension ) { + return; + } + + if( m_dimension == Marble::Longitude ) { + m_comboBox->removeItem( m_comboBox->findText( tr("W", "West, the direction" ) ) ); + m_comboBox->removeItem( m_comboBox->findText( tr("E", "East, the direction" ) ) ); + + m_comboBox->addItem( tr("N", "North, the direction" ) ); + m_comboBox->addItem( tr("S", "South, the direction" ) ); + } else if( m_dimension == Marble::Latitude ) { + m_comboBox->removeItem( m_comboBox->findText( tr("N", "North, the direction" ) ) ); + m_comboBox->removeItem( m_comboBox->findText( tr("S", "South, the direction" ) ) ); + + m_comboBox->addItem( tr("E", "East, the direction" ) ); + m_comboBox->addItem( tr("W", "West, the direction" ) ); + } else { + //unknown dimension + qDebug() << "unknown dimension, not changing"; + } + m_dimension = dimension; + +} + void LatLonBox::secondsOverflow() { if( m_secondsSpin->value() == 60 ) { @@ -121,101 +208,101 @@ void LatLonBox::recalculate() { + double newvalue = m_degreesSpin->value(); + double minsfract = m_minutesSpin->value(); + double secsfract = m_secondsSpin->value(); + + minsfract = minsfract / 60; + secsfract = secsfract / 3600; + + qDebug() << "newvalue = " << newvalue; + qDebug() << "minsfract = " << minsfract; + qDebug() << "secsfract = " << secsfract; + //we need two because if the degrees is neg, //the mins/secs *subtract* from the value - /* if( m_degreesSpin->value() >= 0 ) { - double newvalue = m_degreesSpin->value(); - newvalue += ( m_minutesSpin->value() / 60 ); - newvalue += ( m_secondsSpin->value() / 3600 ); - m_value = newvalue; - qDebug() << "valueChanged: now " << m_value; - emit valueChanged( m_value ); - } else { - double newvalue = m_degreesSpin->value(); - newvalue -= ( m_minutesSpin->value() / 60 ); - newvalue -= ( m_secondsSpin->value() / 3600 ); - m_value = newvalue; - qDebug() << "valueChanged: now " << m_value; - emit valueChanged( m_value ); - } - */ - if( m_degreesSpin->value() >= 0 ) { - double newvalue = m_degreesSpin->value(); - double minsfract = m_minutesSpin->value(); - double secsfract = m_secondsSpin->value(); - minsfract = minsfract / 60; - secsfract = secsfract / 3600; - qDebug() << "newvalue = " << newvalue; - qDebug() << "minsfract = " << minsfract; - qDebug() << "secsfract = " << secsfract; newvalue += minsfract; newvalue += secsfract; - m_value = newvalue; - qDebug() << "valueChanged: now " << m_value; - emit valueChanged( m_value ); } else { - double newvalue = m_degreesSpin->value(); - double minsfract = m_minutesSpin->value(); - double secsfract = m_secondsSpin->value(); - minsfract = minsfract / 60; - secsfract = secsfract / 3600; - qDebug() << "newvalue = " << newvalue; - qDebug() << "minsfract = " << minsfract; - qDebug() << "secsfract = " << secsfract; newvalue -= minsfract; newvalue -= secsfract; - m_value = newvalue; - qDebug() << "valueChanged: now " << m_value; - emit valueChanged( m_value ); } + + m_value = newvalue; + //you can't have 180*59'59" , only 180. - if( m_degreesSpin->value() == 180 || - m_degreesSpin->value() == -180 ) { + //but lat. & lon. have different maximums, so we check + if( m_degreesSpin->value() == m_degreesSpin->maximum() || + m_degreesSpin->value() == m_degreesSpin->minimum() ) { m_minutesSpin->setValue( 0 ); m_secondsSpin->setValue( 0 ); - } + } + + if( m_degreesSpin->value() < m_degreesSpin->minimum() ) { + m_degreesSpin->setValue( m_degreesSpin->minimum() ); + m_minutesSpin->setValue( 0 ); + m_secondsSpin->setValue( 0 ); + } + + if( m_degreesSpin->value() > m_degreesSpin->maximum() ) { + m_degreesSpin->setValue( m_degreesSpin->maximum() ); + m_minutesSpin->setValue( 0 ); + m_secondsSpin->setValue( 0 ); + } + qDebug() << "valueChanged: now " << m_value; + + checkComboBox(); + + //put this last so combobox &c will be correct + //for stuff that needs it + emit valueChanged( m_value ); + } + void LatLonBox::reverseRecalculate() { int degreesvalue = 0; int minutesvalue = 0; int secondsvalue = 0; + + //degreesvalue is the whole degree part if( m_value >= 0 ) { - //degreesvalue is the whole degree part degreesvalue = floor( m_value ); - //minutesremainder is the fraction of a degree that - //is left over - double minutesremainder = m_value - degreesvalue; - //multipy the fraction of a degree by 60 to - //turn it into minutes - minutesremainder = minutesremainder * 60; - //minutesvalue is the whole minutes part + } else { + degreesvalue = ceil( m_value ); + } + + //minutesremainder is the fraction of a degree that + //is left over + double minutesremainder = m_value - degreesvalue; + //multipy the fraction of a degree by 60 to + //turn it into minutes + minutesremainder = minutesremainder * 60; + //minutesvalue is the whole minutes part + if( m_value >= 0 ) { minutesvalue = floor( minutesremainder ); - //secondsremainder is the fraction of a minute - //that is left over - double secondsremainder = minutesremainder - minutesvalue; - //multiply the fraction of a minute by 60 to - //turn it into seconds - secondsvalue = secondsremainder * 60; - //now we have all the values, we - //put them on the boxes. - m_degreesSpin->setValue( degreesvalue ); - m_minutesSpin->setValue( minutesvalue ); - m_secondsSpin->setValue( secondsvalue ); } else { - degreesvalue = ceil( m_value ); - double minutesremainder = m_value - degreesvalue; - minutesremainder = minutesremainder * 60; minutesvalue = ceil( minutesremainder ); - double secondsremainder = minutesremainder - minutesvalue; - secondsvalue = secondsremainder * 60; - m_degreesSpin->setValue( degreesvalue ); - m_minutesSpin->setValue( minutesvalue ); - m_secondsSpin->setValue( secondsvalue ); } + + //secondsremainder is the fraction of a minute + //that is left over + double secondsremainder = minutesremainder - minutesvalue; + //multiply the fraction of a minute by 60 to + //turn it into seconds + secondsvalue = secondsremainder * 60; + + //now we have all the values, we + //put them on the boxes. + m_degreesSpin->setValue( degreesvalue ); + m_minutesSpin->setValue( minutesvalue ); + m_secondsSpin->setValue( secondsvalue ); + + checkComboBox(); } + --- trunk/playground/base/plasma/applets/worldclock/latlonbox.h #793596:793597 @@ -22,25 +22,42 @@ #include #include +#include #include #include +#include + class LatLonBox : public QWidget { Q_OBJECT + //Q_PROPERTY( double m_value READ value WRITE setValue ) + //Q_PROPERTY( Marble::Dimension m_dimension READ dimension WRITE setDimension ) public: - LatLonBox(QWidget *parent = 0); - double value() { return m_value; }; + LatLonBox(QWidget *parent = 0, Marble::Dimension dimension = Marble::Longitude ); + double value(); + Marble::Dimension dimension(); public slots: void setValue(double newvalue); + void setDimension( Marble::Dimension ); private slots: + // changes value based on combobox + void comboBoxChanged( const QString &text ); + // recalculates m_value based on spinboxes void recalculate(); + // recalculates spinboxes based on m_value void reverseRecalculate(); + // chnges combobox based on value + void checkComboBox(); void secondsOverflow(); void minutesOverflow(); private: QHBoxLayout *m_layout; + Marble::Dimension m_dimension; + + QComboBox *m_comboBox; + QSpinBox *m_degreesSpin; QSpinBox *m_minutesSpin; QSpinBox *m_secondsSpin; @@ -51,6 +68,7 @@ double m_value; signals: + void dimensionChanged( Marble::Dimension dimension ); void valueChanged( double value ); }; #endif