Qt screensaver settings

Source: Internet
Author: User

To sum up, set screen saver in the embedded ARM Board:

There are two qwsscreensaver classes in QT.

The definition of this class is as follows:

Define pathQwindowsystem_qws.h

class
Q_GUI_EXPORT QWSScreenSaver
086 {
087 public:
088     virtual
~QWSScreenSaver();
089     virtual
void restore()=0;
090     virtual
bool save(int
level)=0;
091 };

Yes classMembers of the qwsserverprivate class, which are also related to the screen saver settings.

QTime screensavertime;

097     QTimer* screensavertimer;
098     int* screensaverintervals;
099     int
screensavereventblocklevel;
100     bool
screensaverblockevents;
101     bool
screensaverblockevent( int
index, int
*screensaverinterval,
bool
isDown );
102     QWSScreenSaver* saver;

void screenSave(int
level);

When setting screen saver, the QT program should be run as the server. The virtual function virtual in qwsscreensaver
void Restore () and virtual
bool save(int
Level) is used for overloading,

Set the processing in the screen saver status to reload in the subsequent functions. Set the processing to restore the screen saver to be executed in the previous virtual function. To save power consumption, I turn off the screen Backlight in the screen saver status, enable Backlight in the recovery status.

I use this method to perform a simple test to achieve dynamic Screen Saver time settings. Let's talk about the debugging process of this test.

Defines a screensaver class, inherited from qwsscreensaver

The class definition and implementation code is as follows:

# Ifndef screensaver_h
# Define screensaver_h
# Include <qwidget>
# Include <qwsserver>

Class screensaver: Public qwsscreensaver
{
Public:
Screensaver ();
Virtual void restore ();

Virtual bool save (INT level );

PRIVATE:
Int freq;
Int dutycycle;
Public slots:
Void screensaver_parameter_changed (INT );

};

# Endif // screensaver_h

The implementation file is as follows:

# Include "screensaver. H"
# Include <qdebug>
# Include <qtcore>
# Include <stdio. h>
# Include <stdlib. h>
# Include <unistd. h>
# Include <sys/IOCTL. h>
# Include <sys/STAT. h>
# Include <fcntl. h>
# Define ioctl_frequency 0
# Define ioctl_dutycycle 1
Static int FD;

Screensaver: Screensaver ()
: Qwsscreensaver ()
{
// Window = new qmainwindow ();

Qdebug () <"inlize ";

Qsettings * readini = new qsettings ("/home/config. ini", qsettings: iniformat, 0); // initialize the system to read the current backlight value and store it
Readini-> begingroup ("Backlight ");
Dutycycle = readini-> value ("backlight_duty"). toint ();
Qdebug ("dutycycle = % d", dutycycle );
Readini-> endgroup ();
Delete readini;

Freq = 6500;

}

Void screensaver: Restore ()
{
Qdebug ("Enter screen restore ");
// Open PWM
If (FD = open ("/dev/pwm9", o_rdwr) <0)
{
Printf ("open device gptimer8 error \ n ");
Exit (1); // close ();
}

Printf ("the frequecy is % d Hz \ n", freq );
Printf ("the duty cycle is % d percent \ n", dutycycle );

IOCTL (FD, ioctl_frequency, freq );
IOCTL (FD, ioctl_dutycycle, dutycycle );
: Close (FD );
}
Bool screensaver: Save (INT level)
{
// Close PWM anti-Logic

If (FD = open ("/dev/pwm9", o_rdwr) <0)
{
Printf ("open device gptimer8 error \ n ");
Exit (1); // close ();
}

Printf ("the frequecy is % d Hz \ n", freq );
Printf ("the duty cycle is 90 \ n ");

IOCTL (FD, ioctl_frequency, freq );
IOCTL (FD, ioctl_dutycycle, 100 );
: Close (FD );

Qdebug () <"window show ";
Return true;

 

}

Void screensaver: screensaver_parameter_changed (INT interval)
{
Qwsserver: setscreensaverinterval (interval * 1000 );
// Ignore the key/mouse event that turns on the screen

}

Some other settings are required for Screen Saver settings.

I create two other classes: input and mainwindow,

The mainwindow class is defined as follows:

Class mainwindos: Public qmainwindow
{
Q_object
Public:
Explicit mainwindos (qwidget * parent = 0 );
Qpushbutton * button;
Qpushbutton * screensaver_set;
Input * time_set;
Test * tes;
Screensaver * saver;
Qpushbutton * mousecalibration;
Calibration Cal;
Signals:

Public slots:
Void screeasaver_time_set ();
Void mouseclibration_set ();
};

Two member functions are defined, namely, saver and time_set, which are an object of ScreenSaver. time_set is an input window and the input time is used to change the hunger interval of screen saver,

Screensaver is set in the mainwindow constructor.

Saver = new screensaver;
Qwsserver: setscreensaver (qwsscreensaver *) saver );
Qwsserver: setscreensaverinterval (10000); // read the configuration file to get the Initial Value
Qwsserver: screensaveractivate (true );
// Int blocklevel = 1;

// Qwsserver: setscreensaverblocklevel (blocklevel );

I made a mistake, so this program has been called for a long time. I defined a connection in the mainwindows implementation function.

Connect (time_set, signal (saver_interval (INT), saver, slot (screensaver_parameter_changed (INT )));

The mainwindos. CPP: 46: Error: no matching function for call to 'mainwindos: connect (input * &, const char [21], screensaver * &, const char [36])'

I have never realized that as long as the class in QT can communicate in such a signal slot, I have created another class inherited from qwidget, which is used to receive the input data in the input window,

Connect (time_set, signal (saver_interval (INT), Tes, slot (screensaver_parameter_changed (INT )));

The result is normal. I checked the definition of qwsscreensaver, which has been posted above. When the signal slot method cannot be implemented and the time is updated immediately, we began to consider using the inter-process communication method, but it was obviously troublesome. Later, with the help of my colleagues, I directly modify the time interval in the input function of the input class, avoiding the trouble of passing time parameters.

Void input: button_click_slot ()
{
Qpushbutton * buttontem = qobject_cast <qpushbutton *> (sender ());
If (buttontem = UI-> Pushbutton)
{
Number ++;

}
Else
{
Number = buttontem-> text (). toint ();
}
Qdebug ("num = % d", number );
Qwsserver: setscreensaverinterval (Number * 1000 );
Emit saver_interval (number );
}

If you notice which statement can be used anywhere in the program, it will not be a headache for passing the time parameter.

I also saw some screen saver programs on the Internet:

I think it is feasible.

Reference Web site http://qtcn.org/bbs/read-htm-tid-38469-page-2.html

Http://blog.chinaunix.net/uid-27170912-id-3305962.html

Reload the function bool qapplication: qwseventfilter (qwsevent * event ).

The reload method is basically like the following:
Application. h

Copy code
  1. # Ifndef application_h
  2. # Define application_h
  3. # Include <qapplication>
  4. # Include <qdebug>
  5. Class Application: Public qapplication
  6. {
  7. Public:
  8. Application (Int & argc, char ** argv );
  9. Bool notify (qobject *, qevent *);
  10. Bool qwseventfilter (qwsevent * event );
  11. };
  12. # Endif // application_h

Application. cpp

Copy code
  1. # Include "application. H"
  2. Application: Application (Int & argc, char ** argv ):
  3. Qapplication (argc, argv)
  4. {
  5. }
  6. Bool application: Notify (qobject * OBJ, qevent * E)
  7. {
  8. // Do something
  9. Return qapplication: Y (OBJ, e );
  10. }
  11. Bool application: qwseventfilter (qwsevent * event)
  12. {
  13. // Do something
  14. Return qapplication: qwseventfilter (event );
  15. }

Main. cpp

Copy code
  1. # Include "application. H"
  2. # Include "mainwindow. H"
  3. Int main (INT argc, char * argv [])
  4. {
  5. Application A (argc, argv );
  6. Mainwindow W;
  7. W. Show ();
  8. Return a.exe C ();
  9. }
According to cutemmll's practices, the younger brother can indeed catch all mouse events

Bool application: Notify (qobject * OBJ, qevent * E)
{
If (e-> type () = qevent: mousebuttonpress)
{
// Do something
}
Return qapplication: Y (OBJ, e );
}

  1. Class Application: Public qapplication
  2. {
  3. Public:
  4. Application (Int & argc, char ** argv );
  5. Bool notify (qobject *, qevent *);
  6. Void setwindowinstance (mainwindow * WND );
  7. PRIVATE:
  8. Mainwindow * window; // save a pointer to your form
  9. };
  10. CPP
Copy code
  1. Application: Application (Int & argc, char ** argv)
  2. : Qapplication (argc, argv)
  3. , Window (0)
  4. {
  5. }
  6. Void application: setwindowinstance (mainwindow * WND)
  7. {
  8. Window = WND;
  9. }
  10. Bool application: Notify (qobject * OBJ, qevent * E)
  11. {
  12. If (e-> type () = qevent: mousemove)
  13. {
  14. If (window)
  15. {
  16. Window-> dosomething (); // call the corresponding function of your form
  17. }
  18. }
  19. Return qapplication: Y (OBJ, e );
  20. }

  1. Int main (INT argc, char * argv [])
  2. {
  3. Application app (argc, argv );
  4. Mainwindow W;
  5. W. Show ();
  6. App. setwindowinstance (& W );
  7. Return app.exe C ();
  8. } Another method is to rewrite the qapplication function to monitor the entire program. The source is http://qtcn.org/bbs/read-htm-tid-38469-page-2.html#. the project is too large to be easily uploaded. Header file: Class Application: Public qapplication
    {Public:
    Application (Int & argc, char ** argv );
    Bool notify (qobject *, qevent *);
    Void setwindowinstance (mainwindow * WND); Private:
    Mainwindow * window; // save a pointer to your form}; CPP: Application (Int & argc, char ** argv)
    : Qapplication (argc, argv)
    , Window (0)
    {
    } Void application: setwindowinstance (mainwindow * WND)
    {
    Window = WND;
    } Bool application: Notify (qobject * OBJ, qevent * E)
    {
    If (e-> type () = qevent: mousemove)
    {
    If (window)
    {
    Window-> dosomething (); // call the corresponding function of your form
    }
    }
    Return qapplication: Y (OBJ, e );
    } Main. cppint main (INT argc, char * argv [])
    {
    Application app (argc, argv );
    Mainwindow W;
    W. Show ();
    App. setwindowinstance (& W );
    Return app.exe C ();
    } Another method is eventfilter: the function of bool qapplication: qwseventfilter (qwsevent * event) is not reloaded. # ifndef application_h
    # Define application_h # include <qapplication>
    # Include <qdebug> class application: Public qapplication
    {
    Public:
    Application (Int & argc, char ** argv );
    Bool notify (qobject *, qevent *);
    Bool qwseventfilter (qwsevent * event) ;};# endif // application_h # include "application. H" Application: Application (Int & argc, char ** argv ):
    Qapplication (argc, argv)
    {
    } Bool application: Notify (qobject * OBJ, qevent * E)
    {
    // Do something
    Return qapplication: Y (OBJ, e );
    } Bool application: qwseventfilter (qwsevent * event)
    {
    // Do something
    Return qapplication: qwseventfilter (event );
    } Main. PP: # include "application. H"
    # Include "mainwindow. H" int main (INT argc, char * argv [])
    {
    Application A (argc, argv );
    Mainwindow W;
    W. Show (); Return a.exe C ();
    }
  9. The Code on the internet is mainly implemented from the perspective of reload qapplication.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.