-rw-r--r-- | noncore/applets/brightnessapplet/brightnessapplet.cpp | 16 | ||||
-rw-r--r-- | noncore/applets/brightnessapplet/brightnessapplet.h | 2 | ||||
-rw-r--r-- | noncore/applets/brightnessapplet/brightnessapplet.pro | 2 |
3 files changed, 13 insertions, 7 deletions
diff --git a/noncore/applets/brightnessapplet/brightnessapplet.cpp b/noncore/applets/brightnessapplet/brightnessapplet.cpp index 1ade35e..5aaa27e 100644 --- a/noncore/applets/brightnessapplet/brightnessapplet.cpp +++ b/noncore/applets/brightnessapplet/brightnessapplet.cpp @@ -118,83 +118,94 @@ BrightnessAppletControl::BrightnessAppletControl( OTaskbarApplet* parent, const slider->setPageStep(QMAX(1, maxbright / 16)); gl->addMultiCellWidget( slider, 0, 2, 0, 0 ); QPixmap onPm( (const char **)light_on_xpm ); QLabel *l = new QLabel( this ); l->setPixmap( onPm ); gl->addWidget( l, 0, 1 ); QPixmap offPm( (const char **)light_off_xpm ); l = new QLabel( this ); l->setPixmap( offPm ); gl->addWidget( l, 2, 1 ); setFixedHeight( 100 ); setFixedWidth( gl->sizeHint().width() ); setFocusPolicy(QWidget::NoFocus); } BrightnessAppletControl::~BrightnessAppletControl() { } +void BrightnessAppletControl::hideEvent( QHideEvent* e ) +{ + BrightnessApplet* applet = static_cast<BrightnessApplet*>( parent() ); + applet->writeSystemBrightness( applet->calcBrightnessValue() ); + QFrame::hideEvent( e ); +} + BrightnessApplet::BrightnessApplet( QWidget *parent, const char *name ) :OTaskbarApplet( parent, name ) { setFixedHeight( AppLnk::smallIconSize() ); setFixedWidth( AppLnk::smallIconSize() ); _pixmap.convertFromImage( Resource::loadImage( "brightnessapplet/icon" ).smoothScale( height(), width() ) ); _control = new BrightnessAppletControl( this, "control" ); } void BrightnessApplet::writeSystemBrightness(int brightness) { PowerStatus ps = PowerStatusManager::readStatus(); Config cfg("qpe"); if (ps.acStatus() == PowerStatus::Online) { cfg.setGroup("AC"); } else { cfg.setGroup("Battery"); } cfg.writeEntry("Brightness", brightness); + odebug << "writing brightness " << brightness << oendl; + cfg.write(); } int BrightnessApplet::readSystemBrightness(void) { PowerStatus ps = PowerStatusManager::readStatus(); Config cfg("qpe"); if (ps.acStatus() == PowerStatus::Online) { cfg.setGroup("AC"); } else { cfg.setGroup("Battery"); } + odebug << "reading brightness " << cfg.readNumEntry("Brightness", 128) << oendl; + return cfg.readNumEntry("Brightness", 128); } BrightnessApplet::~BrightnessApplet() { } int BrightnessApplet::position() { return 7; } void BrightnessApplet::paintEvent( QPaintEvent* ) { QPainter p(this); p.drawPixmap(0, 0, _pixmap ); } int BrightnessApplet::calcBrightnessValue() { @@ -202,34 +213,29 @@ int BrightnessApplet::calcBrightnessValue() return (v * 255 + _control->slider->maxValue() / 2) / _control->slider->maxValue(); } void BrightnessApplet::sliderMoved( int value ) { #ifndef QT_NO_COP QCopEnvelope e("QPE/System", "setBacklight(int)"); e << calcBrightnessValue(); #else #error This Applet makes no sense without QCOP #endif // QT_NO_COP } void BrightnessApplet::mousePressEvent( QMouseEvent* ) { if ( !_control->isVisible() ) { int v = 255 - readSystemBrightness(); popup( _control ); _control->slider->setValue((_control->slider->maxValue() * v + 128) / 255); connect(_control->slider, SIGNAL(valueChanged(int)), this, SLOT(sliderMoved(int))); } - else - { - _control->hide(); - writeSystemBrightness( calcBrightnessValue() ); - } } EXPORT_OPIE_APPLET_v1( BrightnessApplet ) diff --git a/noncore/applets/brightnessapplet/brightnessapplet.h b/noncore/applets/brightnessapplet/brightnessapplet.h index 8b88bd1..6d6d369 100644 --- a/noncore/applets/brightnessapplet/brightnessapplet.h +++ b/noncore/applets/brightnessapplet/brightnessapplet.h @@ -26,49 +26,49 @@ Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef NETWORKAPPLET_H #define NETWORKAPPLET_H #include <opie2/otaskbarapplet.h> #include <qframe.h> #include <qstring.h> #include <qtoolbutton.h> #include <qlineedit.h> #include <qpixmap.h> class QShowEvent; class QHideEvent; class QSlider; class BrightnessAppletControl : public QFrame { public: BrightnessAppletControl( Opie::Ui::OTaskbarApplet* parent, const char* name = 0 ); ~BrightnessAppletControl(); - + virtual void hideEvent( QHideEvent* ); QSlider* slider; }; class BrightnessApplet : public Opie::Ui::OTaskbarApplet { Q_OBJECT public: BrightnessApplet( QWidget* parent = 0, const char* name = 0 ); ~BrightnessApplet(); void writeSystemBrightness( int brightness ); int readSystemBrightness(); int calcBrightnessValue(); static int position(); public slots: void sliderMoved( int value ); protected: virtual void paintEvent( QPaintEvent* ); virtual void mousePressEvent( QMouseEvent* ); diff --git a/noncore/applets/brightnessapplet/brightnessapplet.pro b/noncore/applets/brightnessapplet/brightnessapplet.pro index 5044f38..8c65120 100644 --- a/noncore/applets/brightnessapplet/brightnessapplet.pro +++ b/noncore/applets/brightnessapplet/brightnessapplet.pro @@ -1,13 +1,13 @@ TEMPLATE = lib CONFIG += qt plugin warn_on HEADERS = brightnessapplet.h SOURCES = brightnessapplet.cpp TARGET = brightnessapplet DESTDIR = $(OPIEDIR)/plugins/applets INCLUDEPATH += $(OPIEDIR)/include DEPENDPATH += $(OPIEDIR)/include LIBS += -lqpe -lopiecore2 -lopieui2 -VERSION = 0.1.0 +VERSION = 0.1.1 include ( $(OPIEDIR)/include.pro ) |