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 /core/settings | |
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 @@ -31,8 +31,11 @@ #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 ); @@ -123,4 +126,8 @@ void Calibration::checkPoints ( ) + 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 ( )) @@ -128,4 +135,8 @@ void Calibration::checkPoints ( ) + 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 ( )) @@ -135,4 +146,4 @@ void Calibration::checkPoints ( ) -#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()) @@ -157,4 +168,4 @@ void Calibration::mousePressEvent ( QMouseEvent *e ) - 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; @@ -171,3 +182,3 @@ void Calibration::mousePressEvent ( QMouseEvent *e ) r |= around ( x [m_dragged], y [m_dragged] ); - repaint ( r ); + repaint ( r, false ); } @@ -186,6 +197,14 @@ void Calibration::mouseMoveEvent ( QMouseEvent *e ) - 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 ( )); @@ -208,2 +227,4 @@ void Calibration::mouseMoveEvent ( QMouseEvent *e ) r |= QRect ( 0, oy [0], ox [0] - 0 + 1, 1 ); + + emit startPointChanged ( startPoint ( )); } @@ -212,2 +233,4 @@ void Calibration::mouseMoveEvent ( QMouseEvent *e ) r |= QRect ( ox [1], oy [1], width ( ) - ox [1], 1 ); + + emit endPointChanged ( endPoint ( )); } @@ -219,3 +242,3 @@ void Calibration::mouseMoveEvent ( QMouseEvent *e ) - repaint ( r ); + repaint ( r, false ); } @@ -235,10 +258,11 @@ void Calibration::mouseReleaseEvent ( QMouseEvent *e ) - 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 ( )); @@ -251,4 +275,37 @@ void Calibration::paintEvent ( QPaintEvent * ) + // 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 ( )); @@ -257,5 +314,5 @@ void Calibration::paintEvent ( QPaintEvent * ) - 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 ); @@ -267,2 +324,6 @@ void Calibration::paintEvent ( QPaintEvent * ) } + if ( st == 1 ) { + p. drawLine ( ex, ey, ex, y1 ); + ey = y1; + } @@ -270,7 +331,15 @@ void Calibration::paintEvent ( QPaintEvent * ) + 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 @@ -45,2 +45,6 @@ public: +signals: + void startPointChanged ( const QPoint & ); + void endPointChanged ( const QPoint & ); + public slots: 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,5 +1,5 @@ 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 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 @@ -28,3 +28,3 @@ -#include "settings.h" +#include "light.h" @@ -40,2 +40,3 @@ #include <qslider.h> +#include <qtimer.h> #include <qspinbox.h> @@ -50,3 +51,3 @@ using namespace Opie; LightSettings::LightSettings( QWidget* parent, const char* name, WFlags ) - : LightSettingsBase( parent, name, true, WStyle_ContextHelp ) + : LightSettingsBase( parent, name, false, WStyle_ContextHelp ) { @@ -65,4 +66,4 @@ LightSettings::LightSettings( QWidget* parent, const char* name, WFlags ) // 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 )); @@ -72,3 +73,3 @@ LightSettings::LightSettings( QWidget* parent, const char* name, WFlags ) - int bright = config. readNumEntry ( "Brightness", 255 ); + int bright = config. readNumEntry ( "Brightness", 127 ); brightness-> setMaxValue ( m_res - 1 ); @@ -86,5 +87,5 @@ LightSettings::LightSettings( QWidget* parent, const char* name, WFlags ) // 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 )); @@ -110,4 +111,6 @@ LightSettings::LightSettings( QWidget* parent, const char* name, WFlags ) + 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 ); @@ -115,5 +118,7 @@ LightSettings::LightSettings( QWidget* parent, const char* name, WFlags ) 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 ))); } @@ -124,3 +129,2 @@ LightSettings::~LightSettings ( ) - void LightSettings::calibrateSensor ( ) @@ -128,2 +132,3 @@ void LightSettings::calibrateSensor ( ) Sensor *s = new Sensor ( m_sensordata, this ); + connect ( s, SIGNAL( viewBacklight ( int )), this, SLOT( setBacklight ( int ))); s-> showMaximized ( ); @@ -136,2 +141,3 @@ void LightSettings::calibrateSensorAC ( ) Sensor *s = new Sensor ( m_sensordata_ac, this ); + connect ( s, SIGNAL( viewBacklight ( int )), this, SLOT( setBacklight ( int ))); s-> showMaximized ( ); @@ -143,14 +149,17 @@ 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 ); } @@ -202,8 +211,3 @@ void LightSettings::accept ( ) } - { - QCopEnvelope e ( "QPE/System", "setBacklight(int)" ); - e << -1; - } - - QDialog::accept ( ); + LightSettingsBase::accept ( ); } @@ -212,3 +216,6 @@ 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 @@ -13,3 +13,3 @@ <y>0</y> - <width>379</width> + <width>371</width> <height>532</height> @@ -1191,86 +1191,2 @@ <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> 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 @@ -20,3 +20,3 @@ -#include "settings.h" +#include "light.h" 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 @@ -32,2 +32,6 @@ +#include <opie/odevice.h> + +using namespace Opie; + #include "calibration.h" @@ -54,2 +58,5 @@ Sensor::Sensor ( QStringList ¶ms, QWidget *parent, const char *name ) } + + int xscale = ODevice::inst ( )-> lightSensorResolution ( ); + int yscale = ODevice::inst ( )-> displayBrightnessResolution ( ); @@ -58,9 +65,9 @@ Sensor::Sensor ( QStringList ¶ms, QWidget *parent, const char *name ) 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 )); @@ -71,2 +78,5 @@ Sensor::Sensor ( QStringList ¶ms, QWidget *parent, const char *name ) 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 & ))); } @@ -75,2 +85,5 @@ void Sensor::accept ( ) { + int xscale = ODevice::inst ( )-> lightSensorResolution ( ); + int yscale = ODevice::inst ( )-> displayBrightnessResolution ( ); + m_params. clear ( ); @@ -78,6 +91,6 @@ void Sensor::accept ( ) << 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 ); @@ -85 +98,6 @@ void Sensor::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 @@ -36,2 +36,4 @@ class QStringList; class Sensor : public SensorBase { + Q_OBJECT + public: @@ -40,2 +42,8 @@ public: virtual void accept ( ); + +signals: + void viewBacklight ( int ); + +private slots: + void pointDrag ( const QPoint & ); |