From ae2a03c2941bf92573f89b88ef73f8aa842bea0a Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdetoys@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- kodo/ChangeLog | 42 ++++ kodo/Makefile.am | 22 ++ kodo/configure.in.in | 3 + kodo/hi16-app-kodo.png | Bin 0 -> 226 bytes kodo/hi32-app-kodo.png | Bin 0 -> 1698 bytes kodo/hi48-app-kodo.png | Bin 0 -> 2865 bytes kodo/kimagenumber.cpp | 79 +++++++ kodo/kimagenumber.h | 53 +++++ kodo/kodo.desktop | 69 ++++++ kodo/kodometer.cpp | 600 +++++++++++++++++++++++++++++++++++++++++++++++++ kodo/kodometer.h | 163 ++++++++++++++ kodo/main.cpp | 100 +++++++++ kodo/numbers.png | Bin 0 -> 2372 bytes 13 files changed, 1131 insertions(+) create mode 100644 kodo/ChangeLog create mode 100644 kodo/Makefile.am create mode 100644 kodo/configure.in.in create mode 100644 kodo/hi16-app-kodo.png create mode 100644 kodo/hi32-app-kodo.png create mode 100644 kodo/hi48-app-kodo.png create mode 100644 kodo/kimagenumber.cpp create mode 100644 kodo/kimagenumber.h create mode 100644 kodo/kodo.desktop create mode 100644 kodo/kodometer.cpp create mode 100644 kodo/kodometer.h create mode 100644 kodo/main.cpp create mode 100644 kodo/numbers.png (limited to 'kodo') diff --git a/kodo/ChangeLog b/kodo/ChangeLog new file mode 100644 index 0000000..b7b93bc --- /dev/null +++ b/kodo/ChangeLog @@ -0,0 +1,42 @@ + Modification History + -------------------- + 19 Mar 1993 mhg v1.0 Initial release. + 3 Aug 1993 mhg v1.2 Added automatic trip reset feature. + 5 Jan 1994 mhg v1.3 Ported to Alpha; moved mi/km button into popup + menu; removed 'Trip' fixed label; added font + resource. + 6 Jan 1994 mhg x1.4 Main window no longer grabs input focus when + realized. + 21 Nov 1994 mhg x1.4 Added saveFile resource to make location and + name of odometer save file customizable. + 6 Mar 1995 mhg x1.5 Added automatic html generation. + 9 Mar 1995 mhg x1.6 Converted file to format with verion info! + Changed .format resource to .units. + Improved measurement unit handling and update + accuracy. Removed unneccesary label updates. + 19 Apr 1995 mhg V2.0 Removed OpenVMS-specific AST code in favor of + XtAppAddTimeout. (Works a lot better now, too.) + 26 Apr 1995 mhg X2.1-1 Fix trip reset so units is also reset. + 27 Apr 1995 mhg X2.1-2 Changed AutoReset timer to be its own timeout + on a relative timer based on seconds until + midnight. + 28 Apr 1995 mhg X2.1-3 Added pollInterval and saveFrequency resources. + 1 May 1995 mhg X2.1-4 Make disk writing (data, html) deferred so as + to allow for "continuous" display update while + mouse is in motion. + 27 Oct 1995 mhg V2.1 Final cleanup for this version and public + release. + + 18 May 1998 asn V3.0 Broke the code in all sorts of ways to turn + the mild-mannered Motif version into a + modern KDE program. Code turned into C++, + all Xm references were removed, and VMS + support was dumped! + + 22 Aug 1998 asn V3.1 Minor updates to make it compile more + gracefully on modern C++ compilers, + and updated things to KDE 1.0 specs. + Added a proper About Box. + + 16 May 2001 gb V3.2 Code cleanups, more KDE 2.0 compatible. + diff --git a/kodo/Makefile.am b/kodo/Makefile.am new file mode 100644 index 0000000..38bfbd5 --- /dev/null +++ b/kodo/Makefile.am @@ -0,0 +1,22 @@ + +# set the include path for X, qt and KDE +INCLUDES= $(all_includes) + +bin_PROGRAMS = kodo +kodo_SOURCES = main.cpp kodometer.cpp kimagenumber.cpp +METASOURCES = AUTO + +# the library search path. +kodo_LDFLAGS = $(all_libraries) $(KDE_RPATH) +kodo_LDADD = $(LIB_KDEUI) + +messages: + $(XGETTEXT) $(kodo_SOURCES) -o $(podir)/kodo.pot + +KDE_ICON = kodo + +xdg_apps_DATA = kodo.desktop + +pics_DATA = numbers.png +picsdir = $(kde_datadir)/kodo + diff --git a/kodo/configure.in.in b/kodo/configure.in.in new file mode 100644 index 0000000..0f2e0e3 --- /dev/null +++ b/kodo/configure.in.in @@ -0,0 +1,3 @@ +if test "x$kde_use_qt_mac" = "xyes"; then + DO_NOT_COMPILE="$DO_NOT_COMPILE kodo" +fi diff --git a/kodo/hi16-app-kodo.png b/kodo/hi16-app-kodo.png new file mode 100644 index 0000000..cd7b929 Binary files /dev/null and b/kodo/hi16-app-kodo.png differ diff --git a/kodo/hi32-app-kodo.png b/kodo/hi32-app-kodo.png new file mode 100644 index 0000000..3bcf97a Binary files /dev/null and b/kodo/hi32-app-kodo.png differ diff --git a/kodo/hi48-app-kodo.png b/kodo/hi48-app-kodo.png new file mode 100644 index 0000000..905c795 Binary files /dev/null and b/kodo/hi48-app-kodo.png differ diff --git a/kodo/kimagenumber.cpp b/kodo/kimagenumber.cpp new file mode 100644 index 0000000..391fb97 --- /dev/null +++ b/kodo/kimagenumber.cpp @@ -0,0 +1,79 @@ +/* + * Mouspedometa + * Based on the original Xodometer VMS/Motif sources. + * + * Written by Armen Nakashian + * Compaq Computer Corporation + * Houston TX + * 22 May 1998 + * + * If you make improvements or enhancements to Mouspedometa, please send + * them back to the author at any of the following addresses: + * + * armen@nakashian.com + * + * Thanks to Mark Granoff for writing the original Xodometer, and + * the whole KDE team for making such a nice environment to write + * programs in. + * + * + * This software is provided as is with no warranty of any kind, + * expressed or implied. Neither Digital Equipment Corporation nor + * Armen Nakashian will be held accountable for your use of this + * software. + */ + +#include "kimagenumber.h" + +KImageNumber::KImageNumber(const QString& font, QWidget* parent,const char* name) : + QFrame(parent,name), + m_value(0) +{ + fontPix = new QPixmap(font); + resize(sizeHint()); +} + +KImageNumber::~KImageNumber() +{ + delete fontPix; +} + +void KImageNumber::paintEvent(QPaintEvent*) +{ + int w = fontPix->width(); + int each = w/11; + + QString data; + data.sprintf("%06.1f", m_value); + + for(unsigned int i=0; i < data.length(); i++) { + int wl = data.at(i).latin1() - '0'; + if(data.at(i) == '.') + wl = 10; + bitBlt(this, i*each, 0, fontPix, wl*each, 0, each, fontPix->height()); + } +} + +void KImageNumber::setValue(double v) +{ + m_value = v; + repaint(false); +} + +double KImageNumber::value() const +{ + return m_value; +} + +QSize KImageNumber::sizeHint() const +{ + int w = fontPix->width(); + int each = w/11; + + QString data; + data.sprintf("%06.1f", m_value); + + return QSize(data.length()*each, fontPix->height()); +} + +#include "kimagenumber.moc" diff --git a/kodo/kimagenumber.h b/kodo/kimagenumber.h new file mode 100644 index 0000000..57f96e2 --- /dev/null +++ b/kodo/kimagenumber.h @@ -0,0 +1,53 @@ +/* + * Mouspedometa + * Based on the original Xodometer VMS/Motif sources. + * + * Written by Armen Nakashian + * Compaq Computer Corporation + * Houston TX + * 22 May 1998 + * + * If you make improvements or enhancements to Mouspedometa, please send + * them back to the author at any of the following addresses: + * + * armen@nakashian.com + * + * Thanks to Mark Granoff for writing the original Xodometer, and + * the whole KDE team for making such a nice environment to write + * programs in. + * + * + * This software is provided as is with no warranty of any kind, + * expressed or implied. Neither Digital Equipment Corporation nor + * Armen Nakashian will be held accountable for your use of this + * software. + */ + +#ifndef KIMGNUM_H +#define KIMGNUM_H + +#include +#include + +class KImageNumber : public QFrame +{ + Q_OBJECT + Q_PROPERTY( double m_value READ value WRITE setValue ) +public: + KImageNumber(const QString& font, QWidget* parent=0, const char* name=0); + + virtual ~KImageNumber(); + + void paintEvent(QPaintEvent*); + virtual QSize sizeHint() const; + double value() const; + +public slots: + void setValue(double v); + +protected: + double m_value; + QPixmap* fontPix; +}; + +#endif diff --git a/kodo/kodo.desktop b/kodo/kodo.desktop new file mode 100644 index 0000000..d577c8d --- /dev/null +++ b/kodo/kodo.desktop @@ -0,0 +1,69 @@ +[Desktop Entry] +Type=Application +Exec=kodo +Icon=kodo +DocPath=kodo/index.html +GenericName=Mouse Odometer +GenericName[be]=Мышыны адоматр +GenericName[bg]=Одометър за мишката +GenericName[bn]=মাউসের গতিমাপক যন্ত্র +GenericName[ca]=Ratometratge +GenericName[cs]=Rychlost myši +GenericName[cy]=Camfesurydd Llygoden +GenericName[da]=Musehastighedsmåler +GenericName[de]=Entfernungsmesser für die Maus +GenericName[el]=Χιλιομετρομετρητής ποντικιού +GenericName[eo]=Musomezurilo +GenericName[es]=Odómetro del ratón +GenericName[et]=Hiire odomeeter +GenericName[eu]=Mouspedometa +GenericName[fa]=کیلومترشمار موشی +GenericName[fi]=Hiirimittari +GenericName[fr]=Odomètre pour souris +GenericName[ga]=Odaiméadar Luiche +GenericName[gl]=Odómetro +GenericName[he]=מד־מרחק העכבר +GenericName[hr]=Brojač prijeđenog puta miša +GenericName[hu]=Egérmozgás-figyelő +GenericName[is]=Músametrateljari +GenericName[it]=Contachilometri mouse +GenericName[ja]=マウス走行計 +GenericName[km]=Odometer កណ្ដុរ +GenericName[ko]=마우스 거리 측정 도구 +GenericName[lv]=Peles odometrs +GenericName[mk]=Километража на глушецот +GenericName[mt]=Odometru tal-maws +GenericName[nb]=Muselengdemåler +GenericName[nds]=Muus-Wegmeter +GenericName[ne]=माउस ओडोमिटर +GenericName[nl]=Muismeter +GenericName[nn]=Musefartsmålar +GenericName[pa]=ਮਾਊਂਸ ਓਡੋਮੀਟਰ +GenericName[pl]=Licznik przebiegu dla myszki +GenericName[pt]=Ratómetro +GenericName[pt_BR]=Odômetro Para o Mouse +GenericName[ro]=Mouse-metru +GenericName[ru]=Мышеспидометр +GenericName[sk]=Merač myši +GenericName[sl]=Miškomer +GenericName[sr]=Мишометар +GenericName[sr@Latn]=Mišometar +GenericName[sv]=Vägmätaren +GenericName[ta]=சுட்டி ஓட்ட அளவி +GenericName[tg]=Спидометри Муш +GenericName[tr]=Fare Mesafe Ölçer +GenericName[uk]=Одометр для мишки +GenericName[zh_CN]=鼠标里程计 +GenericName[zh_TW]=滑鼠里程表 +Terminal=false +Name=Kodo +Name[bn]=কোডো +Name[de]=KOdometer +Name[km]=កូដូ (Kodo) +Name[ne]=कोडो +Name[pa]=ਕੋਡੋ +Name[ta]=கேஓட்ட அளவி +Name[tg]=Кодо +X-KDE-StartupNotify=true +X-DCOP-ServiceType=Unique +Categories=Qt;KDE;Utility;Amusement; diff --git a/kodo/kodometer.cpp b/kodo/kodometer.cpp new file mode 100644 index 0000000..aea6f47 --- /dev/null +++ b/kodo/kodometer.cpp @@ -0,0 +1,600 @@ +/* + * Mouspedometa + * Based on the original Xodometer VMS/Motif sources. + * + * Written by Armen Nakashian + * Compaq Computer Corporation + * Houston TX + * 22 May 1998 + * + * If you make improvements or enhancements to Mouspedometa, please send + * them back to the author at any of the following addresses: + * + * armen@nakashian.com + * + * Thanks to Mark Granoff for writing the original Xodometer, and + * the whole KDE team for making such a nice environment to write + * programs in. + * + * + * This software is provided as is with no warranty of any kind, + * expressed or implied. Neither Digital Equipment Corporation nor + * Armen Nakashian will be held accountable for your use of this + * software. + */ + +#include "kodometer.h" + +const double speedInterval = 500.0; +const double distanceInterval = 10.0; +const int speedSamples = 10; + +static struct conversionEntry ConversionTable[MAX_UNIT] = { + {inch, I18N_NOOP("inch"), I18N_NOOP("inches"), 12.0, 2.54, + I18N_NOOP("cm"), I18N_NOOP("cm"), 100.0, 3}, + {foot, I18N_NOOP("foot"), I18N_NOOP("feet"), 5280.0, 0.3048, + I18N_NOOP("meter"), I18N_NOOP("meters"), 1000.0, 4}, + {mile, I18N_NOOP("mile"), I18N_NOOP("miles"), -1.0, 1.609344, + I18N_NOOP("km"), I18N_NOOP("km"), -1.0, 5}}; + +/* + * Set the program up, do lots of ugly initialization. + * Note that we use installEventFilter on the two KImageNumber's + * to make clicks on them bring up the context-menu. + */ +Kodometer::Kodometer(QWidget* parent, const char* name) + : QFrame(parent, name), + dontRefresh(false), + speed(0.0), + lastDistance(0.0), + XCoord(0), YCoord(0), + lastXCoord(0), lastYCoord(0), + pointerScreen(-1), + lastPointerScreen(-1), + Enabled(true), + cyclesSinceLastSave(0), + pollInterval(10), + saveFrequency(10) +{ + display = KApplication::kApplication()->getDisplay(); + FindAllScreens(); + + root = RootWindow(display, DefaultScreen(display)); + + readSettings(); + if(AutoReset) { + dontRefresh = true; + resetTrip(); + dontRefresh = false; + } + + lastDistance = Distance; + + lastDUnit = distanceUnit; + lastTUnit = tripDistanceUnit; + + totalLabel = new KImageNumber(locate("appdata", "numbers.png"), this); + tripLabel = new KImageNumber(locate("appdata", "numbers.png"), this); + + totalLabel->installEventFilter(this); + tripLabel->installEventFilter(this); + + // setup help menu + help = new KHelpMenu(this, KGlobal::instance()->aboutData(), false); + KPopupMenu* helpMnu = help->menu(); + + // Make the popup menu + menu = new KPopupMenu(); + + menu->insertTitle(kapp->miniIcon(), KGlobal::instance()->aboutData()->programName()); + + enabledID = menu->insertItem(i18n("&Enable"), this, SLOT(toggleEnabled())); + metricID = menu->insertItem(i18n("&Metric Display"), this, + SLOT(toggleUnits())); + autoResetID = menu->insertItem(i18n("Auto &Reset Trip"), this, + SLOT(toggleAutoReset())); + menu->insertItem(i18n("Reset &Trip"), this, SLOT(resetTrip())); + menu->insertItem(i18n("Reset &Odometer"), this, SLOT(resetTotal())); + menu->insertSeparator(); + + menu->insertItem(SmallIconSet("help"), i18n("&Help"), helpMnu); + + menu->insertItem(SmallIconSet("exit"), i18n("&Quit"), this, SLOT(quit())); + menu->setCheckable(true); + + menu->setItemChecked(enabledID, Enabled); + menu->setItemChecked(metricID, UseMetric); + menu->setItemChecked(autoResetID, AutoReset); + + //start the timers that will rifresh the counter + distanceID = startTimer((int)distanceInterval); + speedID = startTimer((int)speedInterval); + + tripLabel->move(0, totalLabel->height()); + setFixedSize(tripLabel->width(), + totalLabel->height() + tripLabel->height()); + + UseMetric =! UseMetric; + toggleUnits(); + + refresh(); +} + +/* + * Now I'm not really sure what this does. I assume its here to find + * all the displays on your system, and measure them. During the mouse + * tracking phase, we use the information stored here to determine how + * far the mouse moved on a given screen. + * + * The point is, since you might have one 17" screen and on 21" screen, + * lets measure them differently. Surely this level of accurasy is + * only provide to prove that the original author was a man's man. + */ +void Kodometer::FindAllScreens(void) +{ + int Dh, DhMM, Dw, DwMM; + double vPixelsPerMM, hPixelsPerMM; + + screenCount = ScreenCount(display); +// kdDebug() << "Display has " << screenCount << +// " screen" << (screenCount == 1 ? "" : "s") << endl; + + for(int i = 0; i < screenCount; i++) { +// kdDebug() << "Screen " << i << endl; + screenInfo[i].root = RootWindow(display, i); + screenInfo[i].scr = XScreenOfDisplay(display, i); + + screenInfo[i].height = Dh = HeightOfScreen(screenInfo[i].scr); + DhMM = HeightMMOfScreen(screenInfo[i].scr); + screenInfo[i].width = Dw = WidthOfScreen(screenInfo[i].scr); + DwMM = WidthMMOfScreen(screenInfo[i].scr); +// kdDebug() << " Height is " << Dh << " pixels (" << DhMM << +// "mm)" << endl; +// kdDebug() << " Width is " << Dw << " pixels (" << DwMM << +// "mm)" << endl; + + vPixelsPerMM = (double)Dh / (double)DhMM; + hPixelsPerMM = (double)Dw / (double)DwMM; + screenInfo[i].PixelsPerMM = (vPixelsPerMM + hPixelsPerMM) / 2.0; +// kdDebug() << " Vertical pixels/mm are " << vPixelsPerMM << +// "mm" << endl; +// kdDebug() << " Horizontal pixels/mm are " << hPixelsPerMM << +// "mm" << endl; +// kdDebug() << " Average pixels/mm are " << +// screenInfo[i].PixelsPerMM << "mm" << endl; + } +} + +/* + * Here's where we override events to the KImgNum's to display + * the context menu + */ +bool Kodometer::eventFilter( QObject *, QEvent *e ) +{ + if ( e->type() == QEvent::MouseButtonPress ) { + mousePressEvent((QMouseEvent*)e); + return true; + } + return false; +} + +/* + * Show the context menu + */ +void Kodometer::mousePressEvent(QMouseEvent* e) +{ + //FIXME fix this! + //dontRefresh = true; + menu->popup(mapToGlobal(e->pos())); +} + +/* + * Called when the timer expires to query the pointer position, + * compare it to the last known position, and then to calculate + * the distance moved. + */ +void Kodometer::timerEvent(QTimerEvent* e) +{ + if (Enabled) { + if(e->timerId() == distanceID) { + lastPointerScreen = pointerScreen; + lastXCoord = XCoord; + lastYCoord = YCoord; + XQueryPointer (display, root, &RootIDRet, &ChildIDRet, &XCoord, + &YCoord, &WinX, &WinY, &StateMask); + if (CalcDistance()) { +// kdDebug() << "Mouse moved" << endl; + if (!dontRefresh) { + refresh(); + cyclesSinceLastSave++; + } + } + } + } +} + +// Guess! +void Kodometer::toggleEnabled() +{ + Enabled = !Enabled; + menu->setItemChecked(enabledID,Enabled); + refresh(); +} + +// Try again! +void Kodometer::toggleAutoReset() +{ + AutoReset = !AutoReset; + menu->setItemChecked(autoResetID,AutoReset); + refresh(); +} + + +// You're getting warm! +void Kodometer::toggleUnits() +{ + UseMetric =! UseMetric; + + menu->setItemChecked(metricID, UseMetric); + + QToolTip::remove(totalLabel); + QToolTip::remove(tripLabel); + if(!UseMetric) { + QToolTip::add(totalLabel, + i18n(ConversionTable[distanceUnit].fromUnitTagPlural)); + QToolTip::add(tripLabel, + i18n(ConversionTable[tripDistanceUnit].fromUnitTagPlural)); + } else { + QToolTip::add(totalLabel, + i18n(ConversionTable[distanceUnit].toUnitTagPlural)); + QToolTip::add(tripLabel, + i18n(ConversionTable[tripDistanceUnit].toUnitTagPlural)); + } + refresh(); +} + + +// Were you dropped on your head as a child? +void Kodometer::resetTrip() +{ + TripDistance = 0.0; + tripDistanceUnit = inch; + if (!dontRefresh) + refresh(); +} + +// I was! +void Kodometer::resetTotal() +{ + resetTrip(); + + Distance = 0.0; + distanceUnit = inch; + + TripDistance = 0.0; + tripDistanceUnit = inch; + refresh(); +} + +/* + * Set the values in all the KImgNums, do metric conversions, + * and make the screen look like reality. + */ +void Kodometer::refresh(void) +{ + if(distanceUnit != lastDUnit) { + lastDUnit = distanceUnit; + QToolTip::remove(totalLabel); + if(!UseMetric) + QToolTip::add(totalLabel, + i18n(ConversionTable[distanceUnit].fromUnitTagPlural)); + else + QToolTip::add(totalLabel, + i18n(ConversionTable[distanceUnit].toUnitTagPlural)); + } + + if(tripDistanceUnit != lastTUnit) { + lastTUnit = tripDistanceUnit; + QToolTip::remove(tripLabel); + if(!UseMetric) + QToolTip::add(tripLabel, + i18n(ConversionTable[tripDistanceUnit].fromUnitTagPlural)); + else + QToolTip::add(tripLabel, + i18n(ConversionTable[tripDistanceUnit].toUnitTagPlural)); + } + + //now draw everything + QString distance_s; + QString trip_s; + double distance_d = 0; + double trip_d = 0; + + if (Enabled) { + distance_d = Distance; + distance_s = FormatDistance(distance_d, distanceUnit); + trip_d = TripDistance; + trip_s = FormatDistance(trip_d, tripDistanceUnit); + } else { + distance_s = "------"; + trip_s = "------"; + } + + totalLabel->setValue(distance_d); + tripLabel->setValue(trip_d); +} + +/* + * Not sure what this does, its from the original program. + */ +double Kodometer::multiplier(Units unit) +{ + double m = 10; + + switch (unit) { + case mile : m *= 10.0; + case foot : m *= 10.0; + case inch : m *= 10.0; break; + } + return m; +} + +/* + * This is the bitch function where the _real_ work is done. I + * could have re-invented the query_pointer code, but this one is a best. + * + * This is code from the original program, responsible for converting the + * number of pixels traveled into a real-world coordinates. + */ +int Kodometer::CalcDistance(void) +{ + double dist, sum; + int X, Y; + double distMM, distInches, finalNewDist; + double oldDistance, oldTripDistance; + double newDistance, newTripDistance; + int i, j, finalScreen, increment; + Units oldDistanceUnit, oldTripDistanceUnit, currentUnit; + int distanceChanged, tripDistanceChanged; + + int screenOrientation = K_Left; + + i = j = finalScreen = increment = 0; + + if ((lastXCoord == 0) && (lastYCoord == 0)) + return false; + + if ((lastXCoord == XCoord) && (lastYCoord == YCoord)) + return false; + + //Figure out which screen the pointer is on + if (screenCount > 1) { + while (i < screenCount) + if (RootIDRet == screenInfo[i].root) + break; + else + i++; + } + + pointerScreen = i; + +// kdDebug() << "CalcDistance: screen: " << pointerScreen << +// " x: " << XCoord << " y: " << YCoord << endl; + + // Adjust XCoord or YCoord for the screen its on, relative to screen 0 + // and screenOrientation. + + if (lastPointerScreen != -1 && pointerScreen != lastPointerScreen) { + switch (screenOrientation) { + case K_Left: + case K_Top: + finalScreen = 0; + j = QMAX(pointerScreen,lastPointerScreen) - 1; + increment = -1; + break; + case K_Right: + case K_Bottom: + finalScreen = QMAX(pointerScreen,lastPointerScreen) - 1; + j = 0; + increment = 1; + break; + } + do { + switch (screenOrientation) { + case K_Left: + case K_Right: + if (pointerScreen > lastPointerScreen) + XCoord += screenInfo[j].width; + else + lastXCoord += screenInfo[j].width; + break; + case K_Top: + case K_Bottom: + if (pointerScreen > lastPointerScreen) + YCoord += screenInfo[j].height; + else + lastYCoord += screenInfo[j].height; + break; + } + if (j != finalScreen) + j += increment; + } while (j != finalScreen); +// kdDebug() << " Adjusted for screen ch: x: " << XCoord << +// " y: " << YCoord << endl; + } + +// kdDebug() << "In: Distance: " << Distance << +// " Trip Distance: " << TripDistance << endl; + + // Calculate distance in pixels first + // using Pitagora + + X = XCoord - lastXCoord; + X = X*X; + + Y = YCoord - lastYCoord; + Y = Y*Y; + + sum = (double)X + (double)Y; + dist = sqrt(sum); + + // Convert to millimeters + distMM = dist / screenInfo[pointerScreen].PixelsPerMM; + + // Convert to inches + distInches = distMM * 0.04; + + // Add an appropriate value to Distance, which may be + // in a unit other than inches + currentUnit = inch; + finalNewDist = distInches; + + while (currentUnit < distanceUnit) { + finalNewDist = + finalNewDist / ConversionTable[currentUnit].maxFromBeforeNext; + currentUnit++; +// kdDebug() << " New dist: " << dist << "p, " << distMM << "mm, " << +// distInches << "in, " << finalNewDist << " " << +// ConversionTable[currentUnit+1].fromUnitTagPlural << endl; + } + +// kdDebug() << " Next part" << endl; + + oldDistance = Distance * multiplier(distanceUnit); + + Distance += finalNewDist; + oldDistanceUnit = distanceUnit; + + if (ConversionTable[distanceUnit].maxFromBeforeNext != -1.0 && + Distance >= ConversionTable[distanceUnit].maxFromBeforeNext) + { + Distance = Distance / ConversionTable[distanceUnit].maxFromBeforeNext; + distanceUnit++; + } + + newDistance = Distance * multiplier(distanceUnit); + distanceChanged = (distanceUnit != oldDistanceUnit || + (unsigned int)oldDistance != (unsigned int)newDistance); + + // Add an appropriate value to TripDistance, which may be + // in a unit other than inches + currentUnit = inch; + finalNewDist = distInches; + + while (currentUnit < tripDistanceUnit) { + finalNewDist = finalNewDist / + ConversionTable[currentUnit].maxFromBeforeNext; + currentUnit++; + } + + oldTripDistance = TripDistance * multiplier(tripDistanceUnit); + TripDistance += finalNewDist; + oldTripDistanceUnit = tripDistanceUnit; + + if (ConversionTable[tripDistanceUnit].maxFromBeforeNext != -1.0 && + TripDistance >= ConversionTable[tripDistanceUnit].maxFromBeforeNext) + { + TripDistance = TripDistance / + ConversionTable[tripDistanceUnit].maxFromBeforeNext; + tripDistanceUnit++; + } + + newTripDistance = TripDistance * multiplier(tripDistanceUnit); + tripDistanceChanged = ((tripDistanceUnit != oldTripDistanceUnit) || + ((unsigned int)oldTripDistance != (unsigned int)newTripDistance)); + + +// kdDebug() << "Out: Distance: " << Distance << +// "Trip Distance: " << TripDistance << endl; + + if ((distanceChanged) || (tripDistanceChanged)) + return true; + else + return false; +} + +/* + * This code can probably go away. Its doing conversions from inches to + * other units. Its ugly C-style stuff, that should't be done in a + * pretty OO world. + */ +#define THERE_IS_A_NEXT (ConversionTable[unit].maxToBeforeNext != -1.0) +QString Kodometer::FormatDistance(double &dist, Units unit) +{ + QString string; + const char *tag; + int precision; + + if (UseMetric) { + dist = dist * ConversionTable[unit].conversionFactor; + if ((THERE_IS_A_NEXT) && + (dist > ConversionTable[unit].maxToBeforeNext)) + { + dist = dist / ConversionTable[unit].maxToBeforeNext; + unit++; + } + if (dist == 1.0) + tag = ConversionTable[unit].toUnitTag; + else + tag = ConversionTable[unit].toUnitTagPlural; + } else { + if (dist == 1.0) + tag = ConversionTable[unit].fromUnitTag; + else + tag = ConversionTable[unit].fromUnitTagPlural; + } + precision = ConversionTable[unit].printPrecision; + + string.sprintf ("%.*f %s", precision, dist, tag); + return string; +} + +/* + * Use KConfig to read all settings from disk. Note that whatever + * happens here overrides the defaults, but there's not much + * sanity-checking. + */ +void Kodometer::readSettings(void) +{ + KConfig* config = KGlobal::config(); + config->setGroup("Settings"); + + UseMetric = config->readNumEntry("UseMetric", false); + AutoReset = config->readNumEntry("AutoReset", true); + + TripDistance = config->readDoubleNumEntry("Trip", 0.0); + Distance = config->readDoubleNumEntry("Distance", 0.0); + + distanceUnit = config->readNumEntry("DistanceUnit", inch); + tripDistanceUnit = config->readNumEntry("TripUnit", inch); +} + + +/* + * Save reality for use in the next session. + */ +void Kodometer::saveSettings(void) +{ + KConfig* config = KGlobal::config(); + config->setGroup("Settings"); + + config->writeEntry("UseMetric", UseMetric); + config->writeEntry("AutoReset", AutoReset); + + config->writeEntry("Trip", TripDistance); + config->writeEntry("Distance", Distance); + + config->writeEntry("TripUnit", tripDistanceUnit); + config->writeEntry("DistanceUnit", distanceUnit); + + config->sync(); +} + +// What in the world can this do? +void Kodometer::quit() +{ + saveSettings(); + kapp->quit(); +} + +#include "kodometer.moc" diff --git a/kodo/kodometer.h b/kodo/kodometer.h new file mode 100644 index 0000000..3d5544c --- /dev/null +++ b/kodo/kodometer.h @@ -0,0 +1,163 @@ +/* + * Mouspedometa + * Based on the original Xodometer VMS/Motif sources. + * + * Written by Armen Nakashian + * Compaq Computer Corporation + * Houston TX + * 22 May 1998 + * + * If you make improvements or enhancements to Mouspedometa, please send + * them back to the author at any of the following addresses: + * + * armen@nakashian.com + * + * Thanks to Mark Granoff for writing the original Xodometer, and + * the whole KDE team for making such a nice environment to write + * programs in. + * + * + * This software is provided as is with no warranty of any kind, + * expressed or implied. Neither Digital Equipment Corporation nor + * Armen Nakashian will be held accountable for your use of this + * software. + */ + +// -*-C++-*-; + +#ifndef KODOMETER_H +#define KODOMETER_H + +#include + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "kimagenumber.h" + +#define MAXARGS 25 +#define K_Left 1 +#define K_Right 2 +#define K_Top 3 +#define K_Bottom 4 +#define MAX_SCREEN 16 +#define MAJOR_VERSION 3 +#define MINOR_VERSION 0 + +const int inch = 0; +const int foot = 1; +const int mile = 2; +const int MAX_UNIT = 3; +typedef int Units; + + +typedef struct { + Window root; + Screen *scr; + int height, width; + double PixelsPerMM; +} _screenInfo; + + +typedef struct conversionEntry { + Units fromUnit; + const char *fromUnitTag; + const char *fromUnitTagPlural; + double maxFromBeforeNext; + double conversionFactor; + const char *toUnitTag; + const char *toUnitTagPlural; + double maxToBeforeNext; + int printPrecision; +} conversionEntry; + +class Kodometer : public QFrame +{ + Q_OBJECT + +public: + Kodometer(QWidget* = 0, const char* = 0); + ~Kodometer() {} + void refresh(void); + void readSettings(void); + void saveSettings(void); + + void timerEvent(QTimerEvent*); + void mousePressEvent(QMouseEvent*); + bool eventFilter( QObject *, QEvent *e ); + +public slots: + void toggleEnabled(); + void toggleUnits(); + void toggleAutoReset(); + void resetTrip(); + void resetTotal(); + void quit(); + +protected: + int dontRefresh; + + double multiplier(Units); + int CalcDistance(void); + QString FormatDistance(double &dist, Units); + void FindAllScreens(); + + KImageNumber* tripLabel; + KImageNumber* totalLabel; + KImageNumber* speedLabel; + + KPopupMenu* menu; + KHelpMenu* help; + int metricID; + int autoResetID; + int enabledID; + + double speed; + QPtrList speeds; + double lastDistance; + int distanceID; + int speedID; + + Display *display; + Window root, RootIDRet, ChildIDRet; + int WinX, WinY; + unsigned int StateMask; + int XCoord, YCoord; + int lastXCoord, lastYCoord; + + Units lastDUnit, lastTUnit; + + int pointerScreen, lastPointerScreen; + int Enabled; + int UseMetric; + int AutoReset; + double Distance, TripDistance; + Units distanceUnit, tripDistanceUnit; + char startDate_s[128]; + int cyclesSinceLastSave; + int pollInterval; + int saveFrequency; + + _screenInfo screenInfo[MAX_SCREEN]; + int screenCount; +}; + +#endif diff --git a/kodo/main.cpp b/kodo/main.cpp new file mode 100644 index 0000000..72f8802 --- /dev/null +++ b/kodo/main.cpp @@ -0,0 +1,100 @@ +/* + * Mouspedometa + * Based on the original Xodometer VMS/Motif sources. + * + * Written by Armen Nakashian + * Compaq Computer Corporation + * Houston TX + * 22 May 1998 + * + * If you make improvements or enhancements to Mouspedometa, please send + * them back to the author at any of the following addresses: + * + * armen@nakashian.com + * + * Thanks to Mark Granoff for writing the original Xodometer, and + * the whole KDE team for making such a nice environment to write + * programs in. + * + * + * This software is provided as is with no warranty of any kind, + * expressed or implied. Neither Digital Equipment Corporation nor + * Armen Nakashian will be held accountable for your use of this + * software. + */ + +/* +** Xodometer +** Written by Mark H. Granoff/mhg +** Digital Equipment Corporation +** Littleton, MA, USA +** 17 March 1993 +** +** If you make improvements or enhancements to Xodometer, please send them +** back to the author at any of the following addresses: +** +** granoff@keptin.lkg.dec.com +** granoff@UltraNet.com +** 72301.1177@CompuServe.com +** +** Thanks to my friend and colleague Bob Harris for his suggestions and help. +** +** This software is provided as is with no warranty of any kind, expressed or +** implied. Neither Digital Equipment Corporation nor Mark Granoff will be +** held accountable for your use of this software. +** +** This software is released into the public domain and may be redistributed +** freely provided that all source module headers remain intact in their +** entirety, and that all components of this kit are redistributed together. +** +** Modification History +** -------------------- +** See ChangeLog +*/ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include "kodometer.h" +#include + +int main(int argc, char *argv[]) +{ + /* Top level details */ + + KAboutData *aboutData = new KAboutData("kodo", + I18N_NOOP("KOdometer"), "3.2", + I18N_NOOP("KOdometer measures your desktop mileage"), + KAboutData::License_GPL, + "(c) 1998, Armen Nakashian", + I18N_NOOP("A mouse odometer"), 0, + "dev@gioelebarabucci.com"); + aboutData->addAuthor("Armen Nakashian", 0, + "armen@tourismo.com", + "http://yawara.anime.net/kodo/"); + aboutData->addCredit("Gioele Barabucci", + I18N_NOOP("KDE 2 porting and some code cleanups"), + "dev@gioelebarabucci.com", "http://www.gioelebarabucci.com"); + KCmdLineArgs::init( argc, argv, aboutData ); + + if (!KUniqueApplication::start()) + exit(0); + + KUniqueApplication a; + + Kodometer *o = new Kodometer(); + + // Get rid of the title bar. + KWin::setType(o->winId(), NET::Override ); + KWin::setState(o->winId(), NET::Sticky); + // FIXME is this a hack? +// o->setGeometry(0, 0, 0, 0); + a.setMainWidget(o); + // is the following this needed? + // a.setTopWidget(o); + + o->show(); + + return a.exec(); +} diff --git a/kodo/numbers.png b/kodo/numbers.png new file mode 100644 index 0000000..27fd81f Binary files /dev/null and b/kodo/numbers.png differ -- cgit v1.2.1