⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 etorch.cpp

📁 This file may be distributed and/or modified under the terms of the ** GNU General Public License v
💻 CPP
字号:
/*    This file is part of ETorch.    ETorch is free software; you can redistribute it and/or modify    it under the terms of the GNU General Public License as published by    the Free Software Foundation; either version 2 of the License, or    (at your option) any later version.    ETorch 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 ETorch; if not, write to the Free Software    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA	Copyright (C) 2006 Ketut P. Kumajaya*/#include <zapplication.h>#include <zglobal.h>#include <qwallpaper.h>#include <qwidget.h>#include <qtimer.h>#include <sys/ioctl.h>#include <fcntl.h>#include <unistd.h>#include <stdlib.h>#include <stdio.h>#include <errno.h>//#include <linux/fb.h> // Stolen from Motorola EZX kernel header.#define FBIOSETBKLIGHT          0x4619#define FBIOGETBKLIGHT          0x461A#define FBIOSETBRIGHTNESS       0x461B#define FBIOGETBRIGHTNESS       0x461C#define FBIOENABLE2BFS          0x4620#define FBIODISABLE2BFS         0x4621#define FBIOCHECK2BFS           0x4622#define BKLIGHT_OFF             0#define BKLIGHT_ON              1#define DEVEL                   0class ETorch : public QWidget{    Q_OBJECTpublic:    ETorch( QWidget * parent = 0, const char * name = 0, WFlags f = 0 )    {        // default to a white torch        setBackgroundColor( Qt::white );        // turn on LCD backlight        setBacklight( BKLIGHT_ON );        // save user setting LCD brightness        brightness = getBrightness();                // set LCD brightness to maximum value        setBrightness( 50 );        // create the timer used for resetting the inactivity time and start it        timer = new QTimer( this );        connect( timer, SIGNAL(timeout()), SLOT(timeout()) );        timer->start( 0, FALSE );        }        ~ETorch()    {    }    protected:    virtual void keyPressEvent( QKeyEvent *e ) {        switch ( e->key() ) {            case Qt::Key_F11:                timer->stop();                delete timer;                // restore user setting LCD brightness                setBrightness( brightness );                QApplication::exit();                break;            case Qt::Key_Left:                setBackgroundColor( Qt::cyan );                break;            case Qt::Key_Up:                setBackgroundColor( Qt::magenta );                break;            case Qt::Key_Right:                setBackgroundColor( Qt::yellow );                break;            case Qt::Key_Down:                setBackgroundColor( Qt::white );                break;            default:                break;        }    }private:    void setBrightness( unsigned int val )    {        int fd;        if (( fd = ::open ( "/dev/fb0", O_RDWR )) >= 0 ) {            if( ::ioctl( fd, FBIOSETBRIGHTNESS, val ) == -1 )                perror( "::ioctl(\"FBIOSETBRIGHTNESS\")" );            else {                      if (DEVEL) fprintf( stderr, "Set brightness = %d\n", val );            }            ::close ( fd );        }    }        unsigned int getBrightness()    {        int fd;        unsigned int val;        if (( fd = ::open ( "/dev/fb0", O_RDWR )) >= 0 ) {            if( ::ioctl( fd, FBIOGETBRIGHTNESS, &val ) == -1 ) {                val = 0;                perror( "::ioctl(\"FBIOGETBRIGHTNESS\")" );            } else {                val = val & 0x00FF;                if (DEVEL) fprintf( stderr, "Get brightness = %d\n", val );            }            ::close ( fd );        }        return val;    }        void setBacklight( int val )    {        int fd;        if (( fd = ::open ( "/dev/fb0", O_RDWR )) >= 0 ) {            if( ::ioctl( fd, FBIOSETBKLIGHT, val ) == -1 )                perror( "::ioctl(\"FBIOSETBKLIGHT\")" );            else {                if (DEVEL) fprintf( stderr, "Set backlight = %d\n", val );            }            ::close ( fd );        }    }private slots:    void timeout()    {        setBacklight( BKLIGHT_ON );        setBrightness( 50 );    }    private:    QTimer *timer;    unsigned int brightness;};int main( int argc, char** argv ){    ZApplication app( argc, argv );    app.enableHardKeyEventFilter(FALSE);    QWallpaper wp;    wp.setAppWallpaperMode( QWallpaper::Off );        ETorch etorch;    app.setMainWidget( &etorch );    etorch.setGeometry( ZGlobal::mapFromGlobalR(&etorch, ZGlobal::getDesktopRect()) );    etorch.show();    return app.exec();} #include "etorch.moc"

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -