mirror of
https://bitbucket.org/smil3y/kde-extraapps.git
synced 2025-02-23 18:32:53 +00:00
kdeplasma-addons: do not mangle KUnitConversion into anonymous namespace
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
4d60260537
commit
49ba7dba8f
5 changed files with 75 additions and 84 deletions
|
@ -31,8 +31,6 @@
|
|||
#include <Plasma/Frame>
|
||||
#include <KUnitConversion/UnitCategory>
|
||||
|
||||
using namespace KUnitConversion;
|
||||
|
||||
ComboBox::ComboBox(QGraphicsWidget* parent)
|
||||
: Plasma::ComboBox(parent)
|
||||
{
|
||||
|
@ -44,8 +42,8 @@ void ComboBox::mousePressEvent(QGraphicsSceneMouseEvent* event)
|
|||
Plasma::ComboBox::mousePressEvent(event);
|
||||
}
|
||||
|
||||
Q_DECLARE_METATYPE(UnitPtr)
|
||||
Q_DECLARE_METATYPE(UnitCategory*)
|
||||
Q_DECLARE_METATYPE(KUnitConversion::UnitPtr)
|
||||
Q_DECLARE_METATYPE(KUnitConversion::UnitCategory*)
|
||||
|
||||
UnitConverter::UnitConverter(QObject *parent, const QVariantList &args)
|
||||
: Plasma::PopupApplet(parent, args)
|
||||
|
@ -73,14 +71,14 @@ void UnitConverter::init()
|
|||
void UnitConverter::sltCategoryChanged(int index)
|
||||
{
|
||||
Q_UNUSED(index);
|
||||
UnitCategory* category =
|
||||
m_pCmbCategory->nativeWidget()->itemData(index).value<UnitCategory*>();
|
||||
QList<UnitPtr> units = category->units();
|
||||
UnitPtr defaultUnit = category->defaultUnit();
|
||||
KUnitConversion::UnitCategory* category =
|
||||
m_pCmbCategory->nativeWidget()->itemData(index).value<KUnitConversion::UnitCategory*>();
|
||||
QList<KUnitConversion::UnitPtr> units = category->units();
|
||||
KUnitConversion::UnitPtr defaultUnit = category->defaultUnit();
|
||||
m_pCmbUnit1->clear();
|
||||
m_pCmbUnit2->clear();
|
||||
int i = 0;
|
||||
foreach (const UnitPtr& unit, units) {
|
||||
foreach (const KUnitConversion::UnitPtr& unit, units) {
|
||||
m_pCmbUnit1->nativeWidget()->addItem(QString("%1 (%2)")
|
||||
.arg(unit->description()).arg(unit->symbol()), QVariant::fromValue(unit));
|
||||
m_pCmbUnit2->nativeWidget()->addItem(QString("%1 (%2)")
|
||||
|
@ -130,13 +128,13 @@ void UnitConverter::sltValueChangedReverse(const QString &sNewValue)
|
|||
/// Calculates from left to right
|
||||
void UnitConverter::calculate()
|
||||
{
|
||||
UnitPtr in = m_pCmbUnit1->nativeWidget()->itemData(
|
||||
m_pCmbUnit1->nativeWidget()->currentIndex()).value<UnitPtr>();
|
||||
UnitPtr out = m_pCmbUnit2->nativeWidget()->itemData(
|
||||
m_pCmbUnit2->nativeWidget()->currentIndex()).value<UnitPtr>();
|
||||
KUnitConversion::UnitPtr in = m_pCmbUnit1->nativeWidget()->itemData(
|
||||
m_pCmbUnit1->nativeWidget()->currentIndex()).value<KUnitConversion::UnitPtr>();
|
||||
KUnitConversion::UnitPtr out = m_pCmbUnit2->nativeWidget()->itemData(
|
||||
m_pCmbUnit2->nativeWidget()->currentIndex()).value<KUnitConversion::UnitPtr>();
|
||||
if (!in.isNull() && !out.isNull()) {
|
||||
Value dblValueIn(m_pTxtValue1->text().toDouble(), in);
|
||||
Value dblValueOut = dblValueIn.convertTo(out->id());
|
||||
KUnitConversion::Value dblValueIn(m_pTxtValue1->text().toDouble(), in);
|
||||
KUnitConversion::Value dblValueOut = dblValueIn.convertTo(out->id());
|
||||
QRegExp decimalCheck("^\\d+\\.0$");
|
||||
QRegExp onlyDecimal("^\\d+$");
|
||||
if(decimalCheck.exactMatch(m_pTxtValue1->text()) && onlyDecimal.exactMatch(QString::number(dblValueOut.number()))) {
|
||||
|
@ -151,13 +149,13 @@ void UnitConverter::calculate()
|
|||
/// Calculates from right to left
|
||||
void UnitConverter::calculateReverse()
|
||||
{
|
||||
UnitPtr in = m_pCmbUnit2->nativeWidget()->itemData(
|
||||
m_pCmbUnit2->nativeWidget()->currentIndex()).value<UnitPtr>();
|
||||
UnitPtr out = m_pCmbUnit1->nativeWidget()->itemData(
|
||||
m_pCmbUnit1->nativeWidget()->currentIndex()).value<UnitPtr>();
|
||||
KUnitConversion::UnitPtr in = m_pCmbUnit2->nativeWidget()->itemData(
|
||||
m_pCmbUnit2->nativeWidget()->currentIndex()).value<KUnitConversion::UnitPtr>();
|
||||
KUnitConversion::UnitPtr out = m_pCmbUnit1->nativeWidget()->itemData(
|
||||
m_pCmbUnit1->nativeWidget()->currentIndex()).value<KUnitConversion::UnitPtr>();
|
||||
if (!in.isNull() && !out.isNull()) {
|
||||
Value dblValueIn(m_pTxtValue2->text().toDouble(), in);
|
||||
Value dblValueOut = dblValueIn.convertTo(out->id());
|
||||
KUnitConversion::Value dblValueIn(m_pTxtValue2->text().toDouble(), in);
|
||||
KUnitConversion::Value dblValueOut = dblValueIn.convertTo(out->id());
|
||||
QRegExp decimalCheck("^\\d+\\.0$");
|
||||
QRegExp onlyDecimal("^\\d+$");
|
||||
if(decimalCheck.exactMatch(m_pTxtValue2->text()) && onlyDecimal.exactMatch(QString::number(dblValueOut.number()))) {
|
||||
|
@ -207,7 +205,7 @@ QGraphicsWidget *UnitConverter::graphicsWidget()
|
|||
pGridLayout->addItem(m_pInfo, 4, 0, 1, 2);
|
||||
pGridLayout->setRowStretchFactor(5, 1);
|
||||
|
||||
foreach (UnitCategory* category, m_converter.categories()) {
|
||||
foreach (KUnitConversion::UnitCategory* category, m_converter.categories()) {
|
||||
m_pCmbCategory->nativeWidget()->addItem(category->name(), QVariant::fromValue(category));
|
||||
}
|
||||
m_pCmbCategory->nativeWidget()->model()->sort(0);
|
||||
|
|
|
@ -39,8 +39,6 @@
|
|||
|
||||
#include "lcd.h"
|
||||
|
||||
using namespace KUnitConversion;
|
||||
|
||||
WeatherStation::WeatherStation(QObject *parent, const QVariantList &args)
|
||||
: WeatherPopupApplet(parent, args)
|
||||
, m_declarativeWidget(0)
|
||||
|
@ -151,12 +149,12 @@ void WeatherStation::configChanged()
|
|||
WeatherPopupApplet::configChanged();
|
||||
}
|
||||
|
||||
Value WeatherStation::value(const QString& value, int unit)
|
||||
KUnitConversion::Value WeatherStation::value(const QString& value, int unit)
|
||||
{
|
||||
if (value.isEmpty() || value == "N/A") {
|
||||
return Value();
|
||||
return KUnitConversion::Value();
|
||||
}
|
||||
return Value(value.toDouble(), unit);
|
||||
return KUnitConversion::Value(value.toDouble(), unit);
|
||||
}
|
||||
|
||||
void WeatherStation::dataUpdated(const QString& source, const Plasma::DataEngine::Data &data)
|
||||
|
@ -167,7 +165,7 @@ void WeatherStation::dataUpdated(const QString& source, const Plasma::DataEngine
|
|||
return;
|
||||
|
||||
QString v = data["Temperature"].toString();
|
||||
Value temp = value(v, data["Temperature Unit"].toInt());
|
||||
KUnitConversion::Value temp = value(v, data["Temperature Unit"].toInt());
|
||||
setTemperature(temp, (v.indexOf('.') > -1));
|
||||
|
||||
setPressure(conditionIcon(), value(data["Pressure"].toString(),
|
||||
|
@ -187,7 +185,7 @@ void WeatherStation::dataUpdated(const QString& source, const Plasma::DataEngine
|
|||
setToolTip(data["Place"].toString());
|
||||
}
|
||||
|
||||
QString WeatherStation::fitValue(const Value& value, int digits)
|
||||
QString WeatherStation::fitValue(const KUnitConversion::Value& value, int digits)
|
||||
{
|
||||
if (!value.isValid()) {
|
||||
return "-";
|
||||
|
@ -248,11 +246,11 @@ QString WeatherStation::fromCondition(const QString& rawCondition)
|
|||
return id;
|
||||
}
|
||||
|
||||
void WeatherStation::setPressure(const QString& condition, const Value& pressure,
|
||||
void WeatherStation::setPressure(const QString& condition, const KUnitConversion::Value& pressure,
|
||||
const QString& tendencyString)
|
||||
{
|
||||
QString currentCondition = "weather:" + fromCondition(condition);
|
||||
Value value = pressure.convertTo(pressureUnit());
|
||||
KUnitConversion::Value value = pressure.convertTo(pressureUnit());
|
||||
QString s = fitValue(value, 5);
|
||||
|
||||
qreal t;
|
||||
|
@ -274,10 +272,10 @@ void WeatherStation::setPressure(const QString& condition, const Value& pressure
|
|||
emit pressureChanged(currentCondition, s, value.unit()->symbol(), direction);
|
||||
}
|
||||
|
||||
void WeatherStation::setTemperature(const Value& temperature, bool hasDigit)
|
||||
void WeatherStation::setTemperature(const KUnitConversion::Value& temperature, bool hasDigit)
|
||||
{
|
||||
hasDigit = hasDigit || (temperatureUnit() != temperature.unit());
|
||||
Value v = temperature.convertTo(temperatureUnit());
|
||||
KUnitConversion::Value v = temperature.convertTo(temperatureUnit());
|
||||
QString temp = hasDigit ? fitValue(v, 3) : QString::number(v.number());
|
||||
|
||||
m_lcdPanel->setLabel("temperature-unit-label", v.unit()->symbol());
|
||||
|
@ -305,9 +303,9 @@ void WeatherStation::setToolTip(const QString& place)
|
|||
Plasma::ToolTipManager::self()->setContent(this, ttc);
|
||||
}
|
||||
|
||||
void WeatherStation::setWind(const Value& speed, const QString& dir)
|
||||
void WeatherStation::setWind(const KUnitConversion::Value& speed, const QString& dir)
|
||||
{
|
||||
Value value = speed.convertTo(speedUnit());
|
||||
KUnitConversion::Value value = speed.convertTo(speedUnit());
|
||||
QString s = fitValue(value, 3);
|
||||
QString direction = dir;
|
||||
|
||||
|
|
|
@ -33,7 +33,6 @@
|
|||
#include "weathervalidator.h"
|
||||
#include "weatheri18ncatalog.h"
|
||||
#include "ui_weatherconfig.h"
|
||||
using namespace KUnitConversion;
|
||||
|
||||
class WeatherConfig::Private
|
||||
{
|
||||
|
@ -111,20 +110,20 @@ WeatherConfig::WeatherConfig(QWidget *parent)
|
|||
|
||||
d->dlg = qobject_cast<KDialog*>(parent);
|
||||
d->ui.setupUi(this);
|
||||
d->ui.temperatureComboBox->addItem(i18n("Celsius \302\260C"), Celsius);
|
||||
d->ui.temperatureComboBox->addItem(i18n("Fahrenheit \302\260F"), Fahrenheit);
|
||||
d->ui.temperatureComboBox->addItem(i18n("Kelvin K"), Kelvin);
|
||||
d->ui.pressureComboBox->addItem(i18n("Hectopascals hPa"), Hectopascal);
|
||||
d->ui.pressureComboBox->addItem(i18n("Kilopascals kPa"), Kilopascal);
|
||||
d->ui.pressureComboBox->addItem(i18n("Millibars mbar"), Millibar);
|
||||
d->ui.pressureComboBox->addItem(i18n("Inches of Mercury inHg"), InchesOfMercury);
|
||||
d->ui.speedComboBox->addItem(i18n("Meters per Second m/s"), MeterPerSecond);
|
||||
d->ui.speedComboBox->addItem(i18n("Kilometers per Hour km/h"), KilometerPerHour);
|
||||
d->ui.speedComboBox->addItem(i18n("Miles per Hour mph"), MilePerHour);
|
||||
d->ui.speedComboBox->addItem(i18n("Knots kt"), Knot);
|
||||
d->ui.speedComboBox->addItem(i18n("Beaufort scale bft"), Beaufort);
|
||||
d->ui.visibilityComboBox->addItem(i18n("Kilometers"), Kilometer);
|
||||
d->ui.visibilityComboBox->addItem(i18n("Miles"), Mile);
|
||||
d->ui.temperatureComboBox->addItem(i18n("Celsius \302\260C"), KUnitConversion::Celsius);
|
||||
d->ui.temperatureComboBox->addItem(i18n("Fahrenheit \302\260F"), KUnitConversion::Fahrenheit);
|
||||
d->ui.temperatureComboBox->addItem(i18n("Kelvin K"), KUnitConversion::Kelvin);
|
||||
d->ui.pressureComboBox->addItem(i18n("Hectopascals hPa"), KUnitConversion::Hectopascal);
|
||||
d->ui.pressureComboBox->addItem(i18n("Kilopascals kPa"), KUnitConversion::Kilopascal);
|
||||
d->ui.pressureComboBox->addItem(i18n("Millibars mbar"), KUnitConversion::Millibar);
|
||||
d->ui.pressureComboBox->addItem(i18n("Inches of Mercury inHg"), KUnitConversion::InchesOfMercury);
|
||||
d->ui.speedComboBox->addItem(i18n("Meters per Second m/s"), KUnitConversion::MeterPerSecond);
|
||||
d->ui.speedComboBox->addItem(i18n("Kilometers per Hour km/h"), KUnitConversion::KilometerPerHour);
|
||||
d->ui.speedComboBox->addItem(i18n("Miles per Hour mph"), KUnitConversion::MilePerHour);
|
||||
d->ui.speedComboBox->addItem(i18n("Knots kt"), KUnitConversion::Knot);
|
||||
d->ui.speedComboBox->addItem(i18n("Beaufort scale bft"), KUnitConversion::Beaufort);
|
||||
d->ui.visibilityComboBox->addItem(i18n("Kilometers"), KUnitConversion::Kilometer);
|
||||
d->ui.visibilityComboBox->addItem(i18n("Miles"), KUnitConversion::Mile);
|
||||
|
||||
connect(d->ui.changeButton, SIGNAL(clicked()), this, SLOT(changePressed()));
|
||||
|
||||
|
|
|
@ -30,8 +30,6 @@
|
|||
#include "weatherconfig.h"
|
||||
#include "weatherlocation.h"
|
||||
|
||||
using namespace KUnitConversion;
|
||||
|
||||
class WeatherPopupApplet::Private
|
||||
{
|
||||
public:
|
||||
|
@ -53,19 +51,19 @@ public:
|
|||
WeatherConfig *weatherConfig;
|
||||
Plasma::DataEngine *weatherEngine;
|
||||
Plasma::DataEngine *timeEngine;
|
||||
Converter converter;
|
||||
UnitPtr temperatureUnit;
|
||||
UnitPtr speedUnit;
|
||||
UnitPtr pressureUnit;
|
||||
UnitPtr visibilityUnit;
|
||||
KUnitConversion::Converter converter;
|
||||
KUnitConversion::UnitPtr temperatureUnit;
|
||||
KUnitConversion::UnitPtr speedUnit;
|
||||
KUnitConversion::UnitPtr pressureUnit;
|
||||
KUnitConversion::UnitPtr visibilityUnit;
|
||||
int updateInterval;
|
||||
QString source;
|
||||
WeatherLocation *location;
|
||||
|
||||
QString conditionIcon;
|
||||
QString tend;
|
||||
Value pressure;
|
||||
Value temperature;
|
||||
KUnitConversion::Value pressure;
|
||||
KUnitConversion::Value temperature;
|
||||
double latitude;
|
||||
double longitude;
|
||||
QTimer *busyTimer;
|
||||
|
@ -104,7 +102,7 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
qreal tendency(const Value& pressure, const QString& tendency)
|
||||
qreal tendency(const KUnitConversion::Value& pressure, const QString& tendency)
|
||||
{
|
||||
qreal t;
|
||||
|
||||
|
@ -113,7 +111,7 @@ public:
|
|||
} else if (tendency.toLower() == QLatin1String( "falling" )) {
|
||||
t = -0.75;
|
||||
} else {
|
||||
t = Value(tendency.toDouble(), pressure.unit()).convertTo(Kilopascal).number();
|
||||
t = KUnitConversion::Value(tendency.toDouble(), pressure.unit()).convertTo(KUnitConversion::Kilopascal).number();
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
@ -124,8 +122,8 @@ public:
|
|||
if (!pressure.isValid()) {
|
||||
return QLatin1String( "weather-none-available" );
|
||||
}
|
||||
qreal temp = temperature.convertTo(Celsius).number();
|
||||
qreal p = pressure.convertTo(Kilopascal).number();
|
||||
qreal temp = temperature.convertTo(KUnitConversion::Celsius).number();
|
||||
qreal p = pressure.convertTo(KUnitConversion::Kilopascal).number();
|
||||
qreal t = tendency(pressure, tend);
|
||||
|
||||
// This is completely unscientific so if anyone have a better formula for this :-)
|
||||
|
@ -178,7 +176,7 @@ public:
|
|||
return result;
|
||||
}
|
||||
|
||||
UnitPtr unit(const QString& unit)
|
||||
KUnitConversion::UnitPtr unit(const QString& unit)
|
||||
{
|
||||
if (!unit.isEmpty() && unit[0].isDigit()) {
|
||||
return converter.unit(unit.toInt());
|
||||
|
@ -305,12 +303,12 @@ void WeatherPopupApplet::dataUpdated(const QString& source,
|
|||
|
||||
d->conditionIcon = data[QLatin1String( "Condition Icon" )].toString();
|
||||
if (data[QLatin1String( "Pressure" )].toString() != QLatin1String( "N/A" )) {
|
||||
d->pressure = Value(data[QLatin1String( "Pressure" )].toDouble(), data[QLatin1String( "Pressure Unit" )].toInt());
|
||||
d->pressure = KUnitConversion::Value(data[QLatin1String( "Pressure" )].toDouble(), data[QLatin1String( "Pressure Unit" )].toInt());
|
||||
} else {
|
||||
d->pressure = Value();
|
||||
d->pressure = KUnitConversion::Value();
|
||||
}
|
||||
d->tend = data[QLatin1String( "Pressure Tendency" )].toString();
|
||||
d->temperature = Value(data[QLatin1String( "Temperature" )].toDouble(), data[QLatin1String( "Temperature Unit" )].toInt());
|
||||
d->temperature = KUnitConversion::Value(data[QLatin1String( "Temperature" )].toDouble(), data[QLatin1String( "Temperature Unit" )].toInt());
|
||||
d->latitude = data[QLatin1String( "Latitude" )].toDouble();
|
||||
d->longitude = data[QLatin1String( "Longitude" )].toDouble();
|
||||
setAssociatedApplicationUrls(KUrl(data.value(QLatin1String( "Credit Url" )).toString()));
|
||||
|
@ -320,22 +318,22 @@ void WeatherPopupApplet::dataUpdated(const QString& source,
|
|||
setBusy(false);
|
||||
}
|
||||
|
||||
UnitPtr WeatherPopupApplet::pressureUnit()
|
||||
KUnitConversion::UnitPtr WeatherPopupApplet::pressureUnit()
|
||||
{
|
||||
return d->pressureUnit;
|
||||
}
|
||||
|
||||
UnitPtr WeatherPopupApplet::temperatureUnit()
|
||||
KUnitConversion::UnitPtr WeatherPopupApplet::temperatureUnit()
|
||||
{
|
||||
return d->temperatureUnit;
|
||||
}
|
||||
|
||||
UnitPtr WeatherPopupApplet::speedUnit()
|
||||
KUnitConversion::UnitPtr WeatherPopupApplet::speedUnit()
|
||||
{
|
||||
return d->speedUnit;
|
||||
}
|
||||
|
||||
UnitPtr WeatherPopupApplet::visibilityUnit()
|
||||
KUnitConversion::UnitPtr WeatherPopupApplet::visibilityUnit()
|
||||
{
|
||||
return d->visibilityUnit;
|
||||
}
|
||||
|
|
|
@ -27,8 +27,6 @@
|
|||
|
||||
#define CONVERSION_CHAR QLatin1Char( '>' )
|
||||
|
||||
using namespace KUnitConversion;
|
||||
|
||||
class StringParser
|
||||
{
|
||||
public:
|
||||
|
@ -178,11 +176,11 @@ void ConverterRunner::match(Plasma::RunnerContext &context)
|
|||
}
|
||||
unit2 = cmd.rest();
|
||||
|
||||
Converter converter;
|
||||
UnitCategory* category = converter.categoryForUnit(unit1);
|
||||
KUnitConversion::Converter converter;
|
||||
KUnitConversion::UnitCategory* category = converter.categoryForUnit(unit1);
|
||||
bool found = false;
|
||||
if (category->id() == InvalidCategory) {
|
||||
foreach (const UnitCategory *cat, converter.categories()) {
|
||||
if (category->id() == KUnitConversion::InvalidCategory) {
|
||||
foreach (const KUnitConversion::UnitCategory *cat, converter.categories()) {
|
||||
foreach (const QString& s, cat->allUnits()) {
|
||||
if (s.compare(unit1, Qt::CaseInsensitive) == 0) {
|
||||
found = true;
|
||||
|
@ -198,16 +196,16 @@ void ConverterRunner::match(Plasma::RunnerContext &context)
|
|||
}
|
||||
}
|
||||
|
||||
QList<UnitPtr> units;
|
||||
QList<KUnitConversion::UnitPtr> units;
|
||||
|
||||
if (!unit2.isEmpty()) {
|
||||
UnitPtr u = category->unit(unit2);
|
||||
KUnitConversion::UnitPtr u = category->unit(unit2);
|
||||
if (!u.isNull() && u->isValid()) {
|
||||
units.append(u);
|
||||
config().writeEntry(category->name(), u->symbol());
|
||||
} else {
|
||||
const QStringList unitStrings = category->allUnits();
|
||||
QSet<UnitPtr> matchingUnits;
|
||||
QSet<KUnitConversion::UnitPtr> matchingUnits;
|
||||
foreach (const QString& s, unitStrings) {
|
||||
if (s.startsWith(unit2, Qt::CaseInsensitive)) {
|
||||
matchingUnits << category->unit(s);
|
||||
|
@ -220,18 +218,18 @@ void ConverterRunner::match(Plasma::RunnerContext &context)
|
|||
}
|
||||
} else {
|
||||
units = category->mostCommonUnits();
|
||||
UnitPtr u = category->unit(config().readEntry(category->name()));
|
||||
KUnitConversion::UnitPtr u = category->unit(config().readEntry(category->name()));
|
||||
if (!u.isNull() && units.indexOf(u) < 0) {
|
||||
units << u;
|
||||
}
|
||||
}
|
||||
|
||||
UnitPtr u1 = category->unit(unit1);
|
||||
foreach (const UnitPtr& u, units) {
|
||||
KUnitConversion::UnitPtr u1 = category->unit(unit1);
|
||||
foreach (const KUnitConversion::UnitPtr& u, units) {
|
||||
if (u1 == u) {
|
||||
continue;
|
||||
}
|
||||
Value v = category->convert(Value(value.toDouble(), u1), u);
|
||||
KUnitConversion::Value v = category->convert(KUnitConversion::Value(value.toDouble(), u1), u);
|
||||
Plasma::QueryMatch match(this);
|
||||
match.setType(Plasma::QueryMatch::InformationalMatch);
|
||||
match.setIcon(KIcon(QLatin1String( "edit-copy" )));
|
||||
|
|
Loading…
Add table
Reference in a new issue