author | sandman <sandman> | 2002-11-01 18:13:18 (UTC) |
---|---|---|
committer | sandman <sandman> | 2002-11-01 18:13:18 (UTC) |
commit | 2259e3ab9f2e06a4ee4dbd633c17221a47fdb7ba (patch) (side-by-side diff) | |
tree | f3e6bb8ee6c0d8f2671a63c240d1145e710da82d | |
parent | 7b7b760ca3886d5b6562a88b5c2ef8e610b73eb8 (diff) | |
download | opie-2259e3ab9f2e06a4ee4dbd633c17221a47fdb7ba.zip opie-2259e3ab9f2e06a4ee4dbd633c17221a47fdb7ba.tar.gz opie-2259e3ab9f2e06a4ee4dbd633c17221a47fdb7ba.tar.bz2 |
- Completly reworked the backlight "preview":
every slider/control that relates to backlight levels, is now switching the
lcd to this level for 2 seconds - after that the backlight switches back to
the standard level (or light sensor control)
- Many bugfixes and usability improvements in light sensor calibration
-rw-r--r-- | core/settings/light-and-power/calibration.cpp | 111 | ||||
-rw-r--r-- | core/settings/light-and-power/calibration.h | 4 | ||||
-rw-r--r-- | core/settings/light-and-power/light-and-power.pro | 4 | ||||
-rw-r--r-- | core/settings/light-and-power/light.cpp | 57 | ||||
-rw-r--r-- | core/settings/light-and-power/lightsettingsbase.ui | 86 | ||||
-rw-r--r-- | core/settings/light-and-power/main.cpp | 2 | ||||
-rw-r--r-- | core/settings/light-and-power/sensor.cpp | 34 | ||||
-rw-r--r-- | core/settings/light-and-power/sensor.h | 8 |
8 files changed, 164 insertions, 142 deletions
diff --git a/core/settings/light-and-power/calibration.cpp b/core/settings/light-and-power/calibration.cpp index 6a3360f..aed2bc8 100644 --- a/core/settings/light-and-power/calibration.cpp +++ b/core/settings/light-and-power/calibration.cpp @@ -1,69 +1,72 @@ /* This file is part of the OPIE Project =. Copyright (c) 2002 Maximilian Reiss <harlekin@handhelds.org> .=l. Copyright (c) 2002 Robert Griebl <sandman@handhelds.org> .>+-= _;:, .> :=|. This file is free software; you can .> <`_, > . <= redistribute it and/or modify it under :`=1 )Y*s>-.-- : the terms of the GNU General Public .="- .-=="i, .._ License as published by the Free Software - . .-<_> .<> Foundation; either version 2 of the License, ._= =} : or (at your option) any later version. .%`+i> _;_. .i_,=:_. -<s. This file is distributed in the hope that + . -:. = it will be useful, but WITHOUT ANY WARRANTY; : .. .:, . . . without even the implied warranty of =_ + =;=|` MERCHANTABILITY or FITNESS FOR A _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General ..}^=.= = ; Public License for more details. ++= -. .` .: : = ...= . :.=- You should have received a copy of the GNU -. .:....=;==+<; General Public License along with this file; -_. . . )=. = see the file COPYING. If not, write to the -- :-=` Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "calibration.h" #include <qpainter.h> #include <qpalette.h> +#include <qpixmap.h> -#define BRD 2 +#define BRD 3 Calibration::Calibration ( QWidget *parent, const char *name, WFlags fl ) - : QWidget ( parent, name, fl ) + : QWidget ( parent, name, fl | WRepaintNoErase ) { + setBackgroundMode ( NoBackground ); + m_scale = QSize ( 256, 256 ); m_steps = 5; m_dragged = -1; m_interval = 5; m_p [0] = QPoint ( 0, 0 ); m_p [1] = QPoint ( 255, 255 ); } Calibration::~Calibration ( ) { } void Calibration::setScale ( const QSize &s ) { if ( s. width ( ) < 1 || s. height ( ) < 1 ) return; m_scale = s; checkPoints ( ); update ( ); } QSize Calibration::scale ( ) const { return m_scale; } void Calibration::setLineSteps ( int steps ) { if ( m_steps < 2 ) @@ -92,186 +95,252 @@ int Calibration::interval ( ) const return m_interval; } void Calibration::setStartPoint ( const QPoint &p ) { m_p [0] = QPoint ( p. x ( ), m_scale. height ( ) - p. y ( ) - 1 ); checkPoints ( ); update ( ); } QPoint Calibration::startPoint ( ) const { return QPoint ( m_p [0]. x ( ), m_scale. height ( ) - m_p [0]. y ( ) - 1 ); } void Calibration::setEndPoint ( const QPoint &p ) { m_p [1] = QPoint ( p. x ( ), m_scale. height ( ) - p. y ( ) - 1 ); checkPoints ( ); update ( ); } QPoint Calibration::endPoint ( ) const { return QPoint ( m_p [1]. x ( ), m_scale. height ( ) - m_p [1]. y ( ) - 1 ); } void Calibration::checkPoints ( ) { int dx = m_scale. width ( ); int dy = m_scale. height ( ); + if ( m_p [1]. x ( ) < 0 ) + m_p [1]. setX ( 0 ); if ( m_p [1]. x ( ) >= dx ) m_p [1]. setX ( dx - 1 ); + if ( m_p [0]. x ( ) < 0 ) + m_p [0]. setX ( 0 ); if ( m_p [0]. x ( ) > m_p [1]. x ( )) m_p [0]. setX ( m_p [1]. x ( )); + if ( m_p [1]. y ( ) < 0 ) + m_p [1]. setY ( 0 ); if ( m_p [1]. y ( ) >= dy ) m_p [1]. setY ( dy - 1 ); + if ( m_p [0]. y ( ) < 0 ) + m_p [0]. setY ( 0 ); if ( m_p [0]. y ( ) > m_p [1]. y ( )) m_p [0]. setY ( m_p [1]. y ( )); } -#define SCALEX(x) (BRD+x*(width()- 2*BRD)/m_scale.width()) -#define SCALEY(y) (BRD+y*(height()-2*BRD)/m_scale.height()) +#define SCALEX(x) (BRD+(x)*(width()- 2*BRD)/m_scale.width()) +#define SCALEY(y) (BRD+(y)*(height()-2*BRD)/m_scale.height()) static QRect around ( int x, int y ) { return QRect ( x - BRD, y - BRD, 2 * BRD + 1, 2 * BRD + 1 ); } void Calibration::mousePressEvent ( QMouseEvent *e ) { if ( e-> button ( ) != LeftButton ) return QWidget::mousePressEvent ( e ); int olddragged = m_dragged; int x [2], y [2]; m_dragged = -1; for ( int i = 0; i < 2; i++ ) { x [i] = SCALEX( m_p [i]. x ( )); y [i] = SCALEY( m_p [i]. y ( )); - if (( QABS( e-> x ( ) - x [i] ) <= BRD ) && - ( QABS( e-> y ( ) - y [i] ) <= BRD )) { + if (( QABS( e-> x ( ) - x [i] ) <= 2 * BRD ) && + ( QABS( e-> y ( ) - y [i] ) <= 2 * BRD )) { m_dragged = i; break; } } if ( m_dragged != olddragged ) { QRect r; if ( olddragged >= 0 ) r |= around ( x [olddragged], y [olddragged] ); if ( m_dragged >= 0 ) r |= around ( x [m_dragged], y [m_dragged] ); - repaint ( r ); + repaint ( r, false ); } } void Calibration::mouseMoveEvent ( QMouseEvent *e ) { if ( m_dragged < 0 ) return; QPoint n [2]; n [m_dragged]. setX (( e-> x ( ) - BRD ) * m_scale. width ( ) / ( width ( ) - 2 * BRD )); n [m_dragged]. setY (( e-> y ( ) - BRD ) * m_scale. height ( ) / ( height ( ) - 2 * BRD )); n [1 - m_dragged] = m_p [1 - m_dragged]; - if (( n [0]. x ( ) > n [1]. x ( )) || ( n [m_dragged]. x ( ) < 0 ) || ( n [m_dragged]. x ( ) >= m_scale. width ( ))) - n [m_dragged]. setX ( m_p [m_dragged]. x ( )); - if (( n [0]. y ( ) > n [1]. y ( )) || ( n [m_dragged]. y ( ) < 0 ) || ( n [m_dragged]. y ( ) >= m_scale. height ( ))) - n [m_dragged]. setY ( m_p [m_dragged]. y ( )); + if ( n [m_dragged]. x ( ) < 0 ) + n [m_dragged]. setX ( 0 ); + if ( n [m_dragged]. x ( ) >= m_scale. width ( )) + n [m_dragged]. setX ( m_scale. width ( ) - 1 ); + if ( n [0]. x ( ) > n [1]. x ( )) + n [m_dragged]. setX ( n [1 - m_dragged]. x ( )); + if ( n [m_dragged]. y ( ) < 0 ) + n [m_dragged]. setY ( 0 ); + if ( n [m_dragged]. y ( ) >= m_scale. height ( )) + n [m_dragged]. setY ( m_scale. height ( ) - 1 ); + if ( n [0]. y ( ) > n [1]. y ( )) + n [m_dragged]. setY ( n [1 - m_dragged]. y ( )); QRect r; int ox [2], oy [2], nx [2], ny [2]; for ( int i = 0; i < 2; i++ ) { nx [i] = SCALEX( n [i]. x ( )); ny [i] = SCALEY( n [i]. y ( )); ox [i] = SCALEX( m_p [i]. x ( )); oy [i] = SCALEY( m_p [i]. y ( )); if ( n [i] != m_p [i] ) { r |= around ( nx [i], ny [i] ); r |= around ( ox [i], oy [i] ); m_p [i] = n [i]; if ( i == 0 ) { r |= QRect ( 0, ny [0], nx [0] - 0 + 1, 1 ); r |= QRect ( 0, oy [0], ox [0] - 0 + 1, 1 ); + + emit startPointChanged ( startPoint ( )); } else if ( i == 1 ) { r |= QRect ( nx [1], ny [1], width ( ) - nx [1], 1 ); r |= QRect ( ox [1], oy [1], width ( ) - ox [1], 1 ); + + emit endPointChanged ( endPoint ( )); } } } if ( r. isValid ( )) { r |= QRect ( nx [0], ny [0], nx [1] - nx [0] + 1, ny [1] - ny [0] + 1 ); r |= QRect ( ox [0], oy [0], ox [1] - ox [0] + 1, oy [1] - oy [0] + 1 ); - repaint ( r ); + repaint ( r, false ); } } void Calibration::mouseReleaseEvent ( QMouseEvent *e ) { if ( e-> button ( ) != LeftButton ) return QWidget::mouseReleaseEvent ( e ); if ( m_dragged < 0 ) return; int x = SCALEX( m_p [m_dragged]. x ( )); int y = SCALEY( m_p [m_dragged]. y ( )); m_dragged = -1; - repaint ( around ( x, y )); + repaint ( around ( x, y ), false ); } -void Calibration::paintEvent ( QPaintEvent * ) +void Calibration::paintEvent ( QPaintEvent *pe ) { - QPainter p ( this ); - QColorGroup g = colorGroup ( ); - + QPixmap pix ( size ( )); + QPainter p ( &pix, this ); + QRect cr = pe-> rect ( ); + int x0 = SCALEX( m_p [0]. x ( )); int y0 = SCALEY( m_p [0]. y ( )); int x1 = SCALEX( m_p [1]. x ( )); int y1 = SCALEY( m_p [1]. y ( )); int dx = x1 - x0; int dy = y1 - y0; + // restrict steps to real x and y resolution + int st = QMIN( QMIN( m_steps, ( dx + 1 )), ( dy + 1 )); + + QString stepstr = tr( "%1 Steps" ). arg ( st ); + QRect tr = p. boundingRect ( BRD, BRD, width ( ) - 2*BRD, height() - 2*BRD, AlignTop | AlignRight, stepstr ); + tr. setLeft ( tr. left ( ) - 20 ); + if ( p. hasClipping ( )) + p. setClipRegion ( p. clipRegion ( ) | QRegion ( tr )); + + QColorGroup g = colorGroup ( ); + + p. fillRect ( cr, g. base ( )); + p. fillRect ( tr, g. base ( )); + int ex = x0, ey = y0; + p. setPen ( g. mid ( )); + + int gx0 = SCALEX( 0 ); + int gy0 = SCALEY( 0 ); + int gx1 = SCALEX( m_scale. width ( ) - 1 ); + int gy1 = SCALEY( m_scale. height ( ) - 1 ); + + int xdiv = QMIN( 4, m_scale. width ( )); + int ydiv = QMIN( 4, m_scale. height ( )); + + xdiv = ( gx1 - gx0 + 1 ) / xdiv; + ydiv = ( gy1 - gy0 + 1 ) / ydiv; + + for ( int i = gx0 + xdiv; i <= ( gx1 - xdiv ); i += xdiv ) + p. drawLine ( i, gy0, i, gy1 ); + + for ( int i = gy0 + ydiv; i <= ( gy1 - ydiv ); i += ydiv ) + p. drawLine ( gx0, i, gx1, i ); + p. setPen ( g. highlight ( )); p. drawLine ( BRD, ey, ex, ey ); - for ( int i = 1; i < m_steps; i++ ) { - int fx = x0 + dx * i / m_steps; - int fy = y0 + dy * i / ( m_steps - 1 ); + for ( int i = 1; i < st; i++ ) { + int fx = x0 + dx * i / st; + int fy = y0 + dy * i / ( st - 1 ); p. drawLine ( ex, ey, fx, ey ); p. drawLine ( fx, ey, fx, fy ); ex = fx; ey = fy; } + if ( st == 1 ) { + p. drawLine ( ex, ey, ex, y1 ); + ey = y1; + } p. drawLine ( ex, ey, width ( ) - 1 - BRD, ey ); + p. fillRect ( around ( x0, y0 ), m_dragged == 0 ? g. highlightedText ( ) : g. text ( )); + p. drawRect ( around ( x0, y0 )); p. fillRect ( around ( x1, y1 ), m_dragged == 1 ? g. highlightedText ( ) : g. text ( )); + p. drawRect ( around ( x1, y1 )); p. setPen ( g. text ( )); - p. drawText ( QRect ( BRD, BRD, width ( ) - 2*BRD, height() - 2*BRD ), AlignTop | AlignRight, tr( "%1 Steps" ). arg ( m_steps )); + p. drawText ( tr, AlignTop | AlignRight, stepstr ); + + p. end ( ); + bitBlt ( this, cr. topLeft ( ), &pix, cr ); + if ( !cr. contains ( tr )) + bitBlt ( this, tr. topLeft ( ), &pix, tr ); } diff --git a/core/settings/light-and-power/calibration.h b/core/settings/light-and-power/calibration.h index 2bff69a..ffa63b2 100644 --- a/core/settings/light-and-power/calibration.h +++ b/core/settings/light-and-power/calibration.h @@ -14,58 +14,62 @@ + . -:. = it will be useful, but WITHOUT ANY WARRANTY; : .. .:, . . . without even the implied warranty of =_ + =;=|` MERCHANTABILITY or FITNESS FOR A _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General ..}^=.= = ; Public License for more details. ++= -. .` .: : = ...= . :.=- You should have received a copy of the GNU -. .:....=;==+<; General Public License along with this file; -_. . . )=. = see the file COPYING. If not, write to the -- :-=` Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef __CALIBRATION_H__ #define __CALIBRATION_H__ #include <qwidget.h> class Calibration : public QWidget { Q_OBJECT public: Calibration ( QWidget *parent = 0, const char *name = 0, WFlags fl = 0 ); virtual ~Calibration ( ); QSize scale ( ) const; int lineSteps ( ) const; int interval ( ) const; QPoint startPoint ( ) const; QPoint endPoint ( ) const; +signals: + void startPointChanged ( const QPoint & ); + void endPointChanged ( const QPoint & ); + public slots: void setScale ( const QSize &s ); void setLineSteps ( int step ); void setInterval ( int iv ); void setStartPoint ( const QPoint &p ); void setEndPoint ( const QPoint &p ); protected: virtual void paintEvent ( QPaintEvent * ); virtual void mousePressEvent ( QMouseEvent * ); virtual void mouseMoveEvent ( QMouseEvent * ); virtual void mouseReleaseEvent ( QMouseEvent * ); void checkPoints ( ); private: QSize m_scale; QPoint m_p [2]; int m_dragged; int m_steps; int m_interval; }; #endif diff --git a/core/settings/light-and-power/light-and-power.pro b/core/settings/light-and-power/light-and-power.pro index c89a26d..80c6631 100644 --- a/core/settings/light-and-power/light-and-power.pro +++ b/core/settings/light-and-power/light-and-power.pro @@ -1,26 +1,26 @@ TEMPLATE = app -CONFIG += qt warn_on release +CONFIG += qt warn_on debug DESTDIR = $(OPIEDIR)/bin -HEADERS = settings.h sensor.h calibration.h +HEADERS = light.h sensor.h calibration.h SOURCES = light.cpp main.cpp sensor.cpp calibration.cpp INTERFACES = lightsettingsbase.ui sensorbase.ui INCLUDEPATH += $(OPIEDIR)/include DEPENDPATH += ../$(OPIEDIR)/include LIBS += -lqpe -lopie TARGET = light-and-power TRANSLATIONS = ../../../i18n/de/light-and-power.ts \ ../../../i18n/en/light-and-power.ts \ ../../../i18n/es/light-and-power.ts \ ../../../i18n/fr/light-and-power.ts \ ../../../i18n/hu/light-and-power.ts \ ../../../i18n/ja/light-and-power.ts \ ../../../i18n/ko/light-and-power.ts \ ../../../i18n/no/light-and-power.ts \ ../../../i18n/pl/light-and-power.ts \ ../../../i18n/pt/light-and-power.ts \ ../../../i18n/pt_BR/light-and-power.ts \ ../../../i18n/sl/light-and-power.ts \ ../../../i18n/zh_CN/light-and-power.ts \ ../../../i18n/zh_TW/light-and-power.ts \ ../../../i18n/it/light-and-power.ts diff --git a/core/settings/light-and-power/light.cpp b/core/settings/light-and-power/light.cpp index c0ba60b..21377b7 100644 --- a/core/settings/light-and-power/light.cpp +++ b/core/settings/light-and-power/light.cpp @@ -1,215 +1,222 @@ /* This file is part of the OPIE Project =. Copyright (c) 2002 Maximilian Reiss <harlekin@handhelds.org> .=l. Copyright (c) 2002 Robert Griebl <sandman@handhelds.org> .>+-= _;:, .> :=|. This file is free software; you can .> <`_, > . <= redistribute it and/or modify it under :`=1 )Y*s>-.-- : the terms of the GNU General Public .="- .-=="i, .._ License as published by the Free Software - . .-<_> .<> Foundation; either version 2 of the License, ._= =} : or (at your option) any later version. .%`+i> _;_. .i_,=:_. -<s. This file is distributed in the hope that + . -:. = it will be useful, but WITHOUT ANY WARRANTY; : .. .:, . . . without even the implied warranty of =_ + =;=|` MERCHANTABILITY or FITNESS FOR A _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General ..}^=.= = ; Public License for more details. ++= -. .` .: : = ...= . :.=- You should have received a copy of the GNU -. .:....=;==+<; General Public License along with this file; -_. . . )=. = see the file COPYING. If not, write to the -- :-=` Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#include "settings.h" +#include "light.h" #include <qpe/config.h> #include <qpe/qpeapplication.h> #include <qpe/power.h> #if defined(Q_WS_QWS) && !defined(QT_NO_COP) #include <qpe/qcopenvelope_qws.h> #endif #include <qcheckbox.h> #include <qtabwidget.h> #include <qslider.h> +#include <qtimer.h> #include <qspinbox.h> #include <qpushbutton.h> #include <opie/odevice.h> #include "sensor.h" using namespace Opie; LightSettings::LightSettings( QWidget* parent, const char* name, WFlags ) - : LightSettingsBase( parent, name, true, WStyle_ContextHelp ) + : LightSettingsBase( parent, name, false, WStyle_ContextHelp ) { m_res = ODevice::inst ( )-> displayBrightnessResolution ( ); if ( !ODevice::inst ( )-> hasLightSensor ( )) { auto_brightness-> hide ( ); CalibrateLightSensor-> hide ( ); auto_brightness_ac_3-> hide ( ); CalibrateLightSensorAC-> hide ( ); } Config config ( "apm" ); config. setGroup ( "Battery" ); // battery spinboxes - interval_dim-> setValue ( config. readNumEntry ( "Dim", 20 )); - interval_lightoff-> setValue ( config. readNumEntry ( "LightOff", 30 )); + interval_dim-> setValue ( config. readNumEntry ( "Dim", 30 )); + interval_lightoff-> setValue ( config. readNumEntry ( "LightOff", 20 )); interval_suspend-> setValue ( config. readNumEntry ( "Suspend", 60 )); // battery check and slider LcdOffOnly-> setChecked ( config. readBoolEntry ( "LcdOffOnly", false )); - int bright = config. readNumEntry ( "Brightness", 255 ); + int bright = config. readNumEntry ( "Brightness", 127 ); brightness-> setMaxValue ( m_res - 1 ); brightness-> setTickInterval ( QMAX( 1, m_res / 16 )); brightness-> setLineStep ( QMAX( 1, m_res / 16 )); brightness-> setPageStep ( QMAX( 1, m_res / 16 )); brightness-> setValue (( bright * ( m_res - 1 ) + 127 ) / 255 ); // light sensor auto_brightness-> setChecked ( config. readBoolEntry ( "LightSensor", false )); m_sensordata = config. readListEntry ( "LightSensorData", ';' ); config. setGroup ( "AC" ); // ac spinboxes - interval_dim_ac_3-> setValue ( config. readNumEntry ( "Dim", 20 )); - interval_lightoff_ac_3-> setValue ( config. readNumEntry ( "LightOff", 30 )); - interval_suspend_ac_3-> setValue ( config. readNumEntry ( "Suspend", 60 )); + interval_dim_ac_3-> setValue ( config. readNumEntry ( "Dim", 60 )); + interval_lightoff_ac_3-> setValue ( config. readNumEntry ( "LightOff", 120 )); + interval_suspend_ac_3-> setValue ( config. readNumEntry ( "Suspend", 0 )); // ac check and slider LcdOffOnly_2_3-> setChecked ( config. readBoolEntry ( "LcdOffOnly", false )); bright = config. readNumEntry ( "Brightness", 255 ); brightness_ac_3-> setMaxValue ( m_res - 1 ); brightness_ac_3-> setTickInterval ( QMAX( 1, m_res / 16 )); brightness_ac_3-> setLineStep ( QMAX( 1, m_res / 16 )); brightness_ac_3-> setPageStep ( QMAX( 1, m_res / 16 )); brightness_ac_3-> setValue (( bright * ( m_res - 1 ) + 127 ) / 255 ); // light sensor auto_brightness_ac_3-> setChecked ( config. readBoolEntry ( "LightSensor", false )); m_sensordata_ac = config. readListEntry ( "LightSensorData", ';' ); // advanced settings config. setGroup ( "Warnings" ); warnintervalBox-> setValue ( config. readNumEntry ( "checkinterval", 10000 ) / 1000 ); lowSpinBox-> setValue ( config. readNumEntry ( "powerverylow", 10 ) ); criticalSpinBox-> setValue ( config. readNumEntry ( "powercritical", 5 ) ); + m_resettimer = new QTimer ( this ); + connect ( m_resettimer, SIGNAL( timeout ( )), this, SLOT( resetBacklight ( ))); + if ( PowerStatusManager::readStatus ( ). acStatus ( ) != PowerStatus::Online ) { - connect ( brightness, SIGNAL( valueChanged ( int )), this, SLOT( setBacklight ( int ))); tabs-> setCurrentPage ( 0 ); } else { - connect ( brightness_ac_3, SIGNAL( valueChanged ( int )), this, SLOT( setBacklight ( int ))); tabs-> setCurrentPage ( 1 ); } + + connect ( brightness, SIGNAL( valueChanged ( int )), this, SLOT( setBacklight ( int ))); + connect ( brightness_ac_3, SIGNAL( valueChanged ( int )), this, SLOT( setBacklight ( int ))); } LightSettings::~LightSettings ( ) { } - void LightSettings::calibrateSensor ( ) { Sensor *s = new Sensor ( m_sensordata, this ); + connect ( s, SIGNAL( viewBacklight ( int )), this, SLOT( setBacklight ( int ))); s-> showMaximized ( ); s-> exec ( ); delete s; } void LightSettings::calibrateSensorAC ( ) { Sensor *s = new Sensor ( m_sensordata_ac, this ); + connect ( s, SIGNAL( viewBacklight ( int )), this, SLOT( setBacklight ( int ))); s-> showMaximized ( ); s-> exec ( ); delete s; } void LightSettings::setBacklight ( int bright ) { - bright = bright * 255 / ( m_res - 1 ); + if ( bright >= 0 ) + bright = bright * 255 / ( m_res - 1 ); + QCopEnvelope e ( "QPE/System", "setBacklight(int)" ); e << bright; + + if ( bright != -1 ) { + m_resettimer-> stop ( ); + m_resettimer-> start ( 2000, true ); + } } -void LightSettings::reject ( ) +void LightSettings::resetBacklight ( ) { - { - QCopEnvelope e ( "QPE/System", "setBacklight(int)" ); - e << -1; - } - QDialog::reject ( ); + setBacklight ( -1 ); } void LightSettings::accept ( ) { Config config ( "apm" ); // bat config. setGroup ( "Battery" ); config. writeEntry ( "LcdOffOnly", LcdOffOnly-> isChecked ( )); config. writeEntry ( "Dim", interval_dim-> value ( )); config. writeEntry ( "LightOff", interval_lightoff-> value ( )); config. writeEntry ( "Suspend", interval_suspend-> value ( )); config. writeEntry ( "Brightness", brightness-> value ( ) * 255 / ( m_res - 1 ) ); // ac config. setGroup ( "AC" ); config. writeEntry ( "LcdOffOnly", LcdOffOnly_2_3-> isChecked ( )); config. writeEntry ( "Dim", interval_dim_ac_3-> value ( )); config. writeEntry ( "LightOff", interval_lightoff_ac_3-> value ( )); config. writeEntry ( "Suspend", interval_suspend_ac_3-> value ( )); config. writeEntry ( "Brightness", brightness_ac_3-> value ( ) * 255 / ( m_res - 1 )); // only make light sensor stuff appear if the unit has a sensor if ( ODevice::inst ( )-> hasLightSensor ( )) { config. setGroup ( "Battery" ); config. writeEntry ( "LightSensor", auto_brightness->isChecked() ); config. writeEntry ( "LightSensorData", m_sensordata, ';' ); config. setGroup ( "AC" ); config. writeEntry ( "LightSensor", auto_brightness_ac_3->isChecked() ); config. writeEntry ( "LightSensorData", m_sensordata_ac, ';' ); } // advanced config. setGroup ( "Warnings" ); config. writeEntry ( "check_interval", warnintervalBox-> value ( ) * 1000 ); config. writeEntry ( "power_verylow", lowSpinBox-> value ( )); config. writeEntry ( "power_critical", criticalSpinBox-> value ( )); config. write ( ); // notify the launcher { QCopEnvelope e ( "QPE/System", "reloadPowerWarnSettings()" ); } { QCopEnvelope e ( "QPE/System", "setScreenSaverInterval(int)" ); e << -1; } - { - QCopEnvelope e ( "QPE/System", "setBacklight(int)" ); - e << -1; - } - - QDialog::accept ( ); + LightSettingsBase::accept ( ); } void LightSettings::done ( int r ) { - QDialog::done ( r ); + m_resettimer-> stop ( ); + resetBacklight ( ); + + LightSettingsBase::done ( r ); close ( ); } diff --git a/core/settings/light-and-power/lightsettingsbase.ui b/core/settings/light-and-power/lightsettingsbase.ui index 04c6726..309b95d 100644 --- a/core/settings/light-and-power/lightsettingsbase.ui +++ b/core/settings/light-and-power/lightsettingsbase.ui @@ -1,46 +1,46 @@ <!DOCTYPE UI><UI> <class>LightSettingsBase</class> <widget> <class>QDialog</class> <property stdset="1"> <name>name</name> <cstring>LightSettingsBase</cstring> </property> <property stdset="1"> <name>geometry</name> <rect> <x>0</x> <y>0</y> - <width>379</width> + <width>371</width> <height>532</height> </rect> </property> <property stdset="1"> <name>sizePolicy</name> <sizepolicy> <hsizetype>7</hsizetype> <vsizetype>5</vsizetype> </sizepolicy> </property> <property stdset="1"> <name>caption</name> <string>Light and Power Settings</string> </property> <property stdset="1"> <name>sizeGripEnabled</name> <bool>false</bool> </property> <property> <name>layoutMargin</name> </property> <property> <name>layoutSpacing</name> </property> <vbox> <property stdset="1"> <name>margin</name> <number>3</number> </property> <property stdset="1"> <name>spacing</name> <number>3</number> @@ -1160,148 +1160,64 @@ <name>sizeType</name> <enum>Expanding</enum> </property> <property> <name>sizeHint</name> <size> <width>20</width> <height>20</height> </size> </property> </spacer> </vbox> </widget> </widget> </vbox> </widget> <images> <image> <name>image0</name> <data format="XPM.GZ" length="424">789cd3d7528808f055d0d2e72a2e492cc94c5648ce482c52d04a29cdcdad8c8eb5ade6523234530022130543251d2e253d856405bffcbc54105b19c856360003103711c4354b324b364b06719340dcb434b36488ac1e1a2020a6acac8c2ea60cc54862606ea232b218541b5810452c3111432c510f550c22886a1e482c115d0c2c88e6168818babaa4a42462c48082cae8e68102011a06b5d65c004336518f</data> </image> <image> <name>image1</name> <data format="XPM.GZ" length="439">789c6d8ec10ac2300c86ef7b8ad0ff36a4730777111f41f1288887b4b3e8610a3a0f22bebb6dd3d54d0ca5cdffe54f9aaaa4dd764d6555dc7beecf96ec896f54b68fae7bee0fab57a1ea86fc5950ad6685d2646973bd1c43ce3ec73c46903648e79a5624443a27d20cd2b9382704747e124382f11a7c5e30b364b957b331866331b3800c38f70282121c7c628367c098c1e0eb03121ccd4b46fcb0f80b26bb4833987f76b6d6f274de5fe6a1a031d30969f55e161fe4715f7b</data> </image> <image> <name>image2</name> <data format="XPM.GZ" length="424">789cd3d7528808f055d0d2e72a2e492cc94c5648ce482c52d04a29cdcdad8c8eb5ade6523234530022130543251d2e253d856405bffcbc54105b19c856360003103711c4354b344b314b04719340dcb434b31488ac1e1a2020a6acac8c2ea60cc54862606ea232b218541b5810452c3111432c510f550c22886a1e482c115d0c2c88e6168818babaa4a42462c48082cae8e68102011a06b5d65c0041d3518e</data> </image> </images> <connections> <connection> - <sender>auto_brightness</sender> - <signal>toggled(bool)</signal> - <receiver>brightness</receiver> - <slot>setDisabled(bool)</slot> - </connection> - <connection> - <sender>auto_brightness_ac_3</sender> - <signal>toggled(bool)</signal> - <receiver>brightness_ac_3</receiver> - <slot>setDisabled(bool)</slot> - </connection> - <connection> - <sender>auto_brightness_ac_3</sender> - <signal>toggled(bool)</signal> - <receiver>TextLabel1_3_2</receiver> - <slot>setDisabled(bool)</slot> - </connection> - <connection> - <sender>auto_brightness</sender> - <signal>toggled(bool)</signal> - <receiver>TextLabel1_3</receiver> - <slot>setDisabled(bool)</slot> - </connection> - <connection> - <sender>auto_brightness</sender> - <signal>toggled(bool)</signal> - <receiver>interval_dim</receiver> - <slot>setDisabled(bool)</slot> - </connection> - <connection> - <sender>auto_brightness_ac_3</sender> - <signal>toggled(bool)</signal> - <receiver>interval_dim_ac_3</receiver> - <slot>setDisabled(bool)</slot> - </connection> - <connection> - <sender>auto_brightness</sender> - <signal>toggled(bool)</signal> - <receiver>PixmapLabel2</receiver> - <slot>setDisabled(bool)</slot> - </connection> - <connection> - <sender>auto_brightness</sender> - <signal>toggled(bool)</signal> - <receiver>TextLabel4</receiver> - <slot>setDisabled(bool)</slot> - </connection> - <connection> - <sender>auto_brightness</sender> - <signal>toggled(bool)</signal> - <receiver>TextLabel5</receiver> - <slot>setDisabled(bool)</slot> - </connection> - <connection> - <sender>auto_brightness</sender> - <signal>toggled(bool)</signal> - <receiver>PixmapLabel1</receiver> - <slot>setDisabled(bool)</slot> - </connection> - <connection> - <sender>auto_brightness_ac_3</sender> - <signal>toggled(bool)</signal> - <receiver>PixmapLabel2_2_3</receiver> - <slot>setDisabled(bool)</slot> - </connection> - <connection> - <sender>auto_brightness_ac_3</sender> - <signal>toggled(bool)</signal> - <receiver>TextLabel6</receiver> - <slot>setDisabled(bool)</slot> - </connection> - <connection> - <sender>auto_brightness_ac_3</sender> - <signal>toggled(bool)</signal> - <receiver>TextLabel7</receiver> - <slot>setDisabled(bool)</slot> - </connection> - <connection> - <sender>auto_brightness_ac_3</sender> - <signal>toggled(bool)</signal> - <receiver>PixmapLabel1_2_3</receiver> - <slot>setDisabled(bool)</slot> - </connection> - <connection> <sender>CalibrateLightSensor</sender> <signal>clicked()</signal> <receiver>LightSettingsBase</receiver> <slot>calibrateSensor()</slot> </connection> <connection> <sender>CalibrateLightSensorAC</sender> <signal>clicked()</signal> <receiver>LightSettingsBase</receiver> <slot>calibrateSensorAC()</slot> </connection> <slot access="public">calibrateSensor()</slot> <slot access="public">calibrateSensorAC()</slot> </connections> <tabstops> <tabstop>interval_dim</tabstop> <tabstop>interval_lightoff</tabstop> <tabstop>interval_suspend</tabstop> <tabstop>LcdOffOnly</tabstop> <tabstop>brightness</tabstop> <tabstop>auto_brightness</tabstop> <tabstop>CalibrateLightSensor</tabstop> <tabstop>tabs</tabstop> <tabstop>interval_lightoff_ac_3</tabstop> <tabstop>interval_suspend_ac_3</tabstop> <tabstop>interval_dim_ac_3</tabstop> <tabstop>LcdOffOnly_2_3</tabstop> <tabstop>brightness_ac_3</tabstop> <tabstop>auto_brightness_ac_3</tabstop> <tabstop>CalibrateLightSensorAC</tabstop> <tabstop>lowSpinBox</tabstop> <tabstop>warnintervalBox</tabstop> diff --git a/core/settings/light-and-power/main.cpp b/core/settings/light-and-power/main.cpp index 051fdec..ecacf69 100644 --- a/core/settings/light-and-power/main.cpp +++ b/core/settings/light-and-power/main.cpp @@ -1,38 +1,38 @@ /********************************************************************** ** Copyright (C) 2000 Trolltech AS. All rights reserved. ** ** This file is part of Qtopia Environment. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** **********************************************************************/ -#include "settings.h" +#include "light.h" #include <qpe/qpeapplication.h> #include <qpe/qcopenvelope_qws.h> #include <qpe/global.h> int main(int argc, char** argv) { QPEApplication a(argc,argv); LightSettings dlg; a.showMainWidget(&dlg); return a.exec(); } diff --git a/core/settings/light-and-power/sensor.cpp b/core/settings/light-and-power/sensor.cpp index c1df04d..5ca54d4 100644 --- a/core/settings/light-and-power/sensor.cpp +++ b/core/settings/light-and-power/sensor.cpp @@ -1,85 +1,103 @@ /* This file is part of the OPIE Project =. Copyright (c) 2002 Maximilian Reiss <harlekin@handhelds.org> .=l. Copyright (c) 2002 Robert Griebl <sandman@handhelds.org> .>+-= _;:, .> :=|. This file is free software; you can .> <`_, > . <= redistribute it and/or modify it under :`=1 )Y*s>-.-- : the terms of the GNU General Public .="- .-=="i, .._ License as published by the Free Software - . .-<_> .<> Foundation; either version 2 of the License, ._= =} : or (at your option) any later version. .%`+i> _;_. .i_,=:_. -<s. This file is distributed in the hope that + . -:. = it will be useful, but WITHOUT ANY WARRANTY; : .. .:, . . . without even the implied warranty of =_ + =;=|` MERCHANTABILITY or FITNESS FOR A _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General ..}^=.= = ; Public License for more details. ++= -. .` .: : = ...= . :.=- You should have received a copy of the GNU -. .:....=;==+<; General Public License along with this file; -_. . . )=. = see the file COPYING. If not, write to the -- :-=` Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include <qframe.h> #include <qlayout.h> #include <qslider.h> #include <qspinbox.h> +#include <opie/odevice.h> + +using namespace Opie; + #include "calibration.h" #include "sensor.h" Sensor::Sensor ( QStringList ¶ms, QWidget *parent, const char *name ) : SensorBase ( parent, name, true, WStyle_ContextHelp ), m_params ( params ) { int steps = 12; int inter = 2; int smin = 40; int smax = 215; int lmin = 1; int lmax = 255; switch ( params. count ( )) { case 6: lmax = params [5]. toInt ( ); case 5: lmin = params [4]. toInt ( ); case 4: smax = params [3]. toInt ( ); case 3: smin = params [2]. toInt ( ); case 2: steps = params [1]. toInt ( ); case 1: inter = params [0]. toInt ( ) / 1000; } + + int xscale = ODevice::inst ( )-> lightSensorResolution ( ); + int yscale = ODevice::inst ( )-> displayBrightnessResolution ( ); QVBoxLayout *lay = new QVBoxLayout ( frame ); lay-> setMargin ( 2 ); m_calib = new Calibration ( frame ); - lay-> add ( m_calib ); + lay-> add ( m_calib ); - m_calib-> setScale ( QSize ( 256, 256 )); + m_calib-> setScale ( QSize ( xscale, yscale )); m_calib-> setLineSteps ( steps ); m_calib-> setInterval ( inter ); - m_calib-> setStartPoint ( QPoint ( smin, lmax )); - m_calib-> setEndPoint ( QPoint ( smax, lmin )); + m_calib-> setStartPoint ( QPoint ( smin * xscale / 256, lmax * yscale / 256 )); + m_calib-> setEndPoint ( QPoint ( smax * xscale / 256, lmin * yscale / 256 )); interval-> setValue ( inter ); linesteps-> setValue ( steps ); connect ( interval, SIGNAL( valueChanged ( int )), m_calib, SLOT( setInterval ( int ))); connect ( linesteps, SIGNAL( valueChanged ( int )), m_calib, SLOT( setLineSteps ( int ))); + + connect ( m_calib, SIGNAL( startPointChanged ( const QPoint & )), this, SLOT( pointDrag ( const QPoint & ))); + connect ( m_calib, SIGNAL( endPointChanged ( const QPoint & )), this, SLOT( pointDrag ( const QPoint & ))); } void Sensor::accept ( ) { + int xscale = ODevice::inst ( )-> lightSensorResolution ( ); + int yscale = ODevice::inst ( )-> displayBrightnessResolution ( ); + m_params. clear ( ); m_params << QString::number ( m_calib-> interval ( ) * 1000 ) << QString::number ( m_calib-> lineSteps ( )) - << QString::number ( m_calib-> startPoint ( ). x ( )) - << QString::number ( m_calib-> endPoint ( ). x ( )) - << QString::number ( m_calib-> endPoint ( ). y ( )) - << QString::number ( m_calib-> startPoint ( ). y ( )); + << QString::number ( m_calib-> startPoint ( ). x ( ) * 256 / xscale ) + << QString::number ( m_calib-> endPoint ( ). x ( ) * 256 / xscale ) + << QString::number ( m_calib-> endPoint ( ). y ( ) * 256 / yscale ) + << QString::number ( m_calib-> startPoint ( ). y ( ) * 256 / yscale ); QDialog::accept ( ); } + +void Sensor::pointDrag ( const QPoint &p ) +{ + emit viewBacklight ( p. y ( )); +} diff --git a/core/settings/light-and-power/sensor.h b/core/settings/light-and-power/sensor.h index 7a26d81..b484519 100644 --- a/core/settings/light-and-power/sensor.h +++ b/core/settings/light-and-power/sensor.h @@ -5,43 +5,51 @@ .>+-= _;:, .> :=|. This file is free software; you can .> <`_, > . <= redistribute it and/or modify it under :`=1 )Y*s>-.-- : the terms of the GNU General Public .="- .-=="i, .._ License as published by the Free Software - . .-<_> .<> Foundation; either version 2 of the License, ._= =} : or (at your option) any later version. .%`+i> _;_. .i_,=:_. -<s. This file is distributed in the hope that + . -:. = it will be useful, but WITHOUT ANY WARRANTY; : .. .:, . . . without even the implied warranty of =_ + =;=|` MERCHANTABILITY or FITNESS FOR A _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General ..}^=.= = ; Public License for more details. ++= -. .` .: : = ...= . :.=- You should have received a copy of the GNU -. .:....=;==+<; General Public License along with this file; -_. . . )=. = see the file COPYING. If not, write to the -- :-=` Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef __SENSOR_H__ #define __SENSOR_H__ #include "sensorbase.h" class Calibration; class QStringList; class Sensor : public SensorBase { + Q_OBJECT + public: Sensor ( QStringList ¶ms, QWidget *parent = 0, const char *name = 0 ); virtual void accept ( ); + +signals: + void viewBacklight ( int ); + +private slots: + void pointDrag ( const QPoint & ); private: QStringList &m_params; Calibration *m_calib; }; #endif
\ No newline at end of file |