Qt how to properly do a screensaver function windows C++ - c++

I have to do an touchscreen app for windows, and if the customer hasnt click for 60sec on the screen, a little video or advertsing appears (and leave right after the customer's clik).
I've already made my own thread function for that (a simple loop with a usleep), but i dont think its a good way.
I'm seeking for an obj or something else with Qt that could be better, any ideas?

I'm not sure I fully understand your question but it sounds like you want to listen to QTMouseEvents. Specifically it sounds like you'll be interested in events of type QEvent::MouseButtonPress. Start a timer on a click, once it reaches 60 seconds (note: reset the timer on each click) then start playing the video. Another event of that type will then allow you to 'restore' the main window app (if the video is playing)

Related

How to know if the Gtk::ComboBoxText is popup

I am writing a simple GUI, in which I have a ComboBoxText. I write a log message when ever the user clicks on the ComboBoxText.
I have tried almost all the button release and popup signals but no results. The only thing which works is signal_changed() but I don't not need that. Please help me, below is my sample code :
myCombo->signal_button_release_event().connect(sigc::mem_fun(this,&ComboBoxText::ComboInput),false);
and here is the call back function:
bool ComboBoxText::ComboInput(GdkEventButton *pEvt) {
// Here do the desired stuffs !!
return false; }
Use GTK+ property popup-shown. Not sure about Gtkmm syntax, probably property_popup_shown().get_value().
If you need a signal to listen to, connect to popdown or notify::popup-shown (the latter is invoked when property value changes; again, I'm not sure about Gtkmm syntax).
The idea here was to fire an event when the ComboBoxText is clicked. After some readings I figured it out that the ComboBoxText does not fire any on_click event as such.
One could mask a key press event (which by the way gets fired) and call the signal handler. This might not be handy for people who specifically looking for a on_click event but for those who are working with a keyboard or touch screen device. Here is a small chunk of code :`
mCombo.add_events(Gdk::KEY_PRESS_MASK);
mCombo.signal_event().connect(sigc::mem_fun(this,&ClassName::Handler),false);
cheers :)

How to check if Phonon sound is already playing?

I'm relatively new to Qt so I'll explain this question and what I hope to achieve as clear as possible.
Currently I have buttons that, when clicked, play a sound file located in the applications directory.
I did a little research and found many users say using Phonon is better than QSound. This application is just for the Windows platform so nothing special is required.
Here's the code I have in mainwindow.cpp:
void MainWindow::on_obj_button_gandalf_clicked()
{
Phonon::MediaObject *music =
Phonon::createPlayer(Phonon::MusicCategory,Phonon::MediaSource("sound_file.mp3"));
music->play();
}
The sound plays perfectly. However, if the user had to click the button a second time whilst the sound is still playing from the first click it plays one over the other.
Is there some sort of isplaying() function or something to determine if the same sound is indeed playing already? If so it shouldn't play it again, if not it should then play the song as requested.
I'm using Qt 4.7.0 32bit
Reading the documentation, it appears it's as simple as calling music->state() and ... checking the state.
if (music->state() == Phonon::PlayingState) {
...
You'll also note there's a number of Signals that would let you manage this in your application, specifically the stateChanged signal.

Application not starting until form is displayed to user for the first time

This is a weird question. I have written a .NET application that starts a process. This process is a MFC application written in c++. For some reason the process does not start doing anything until the form is displayed to the user for the first time. For example, if the process starts minimized I have to un-minimize it (click on it) before it will start doing whatever it's supposed to do. Also, if my application is running and starting this process while the screen is locked the process behaves the same as if it's minimized. It doesn't start doing anything until I unlock the screen and it is displayed to the user for the first time. Like I said, this is a weird question so I hope I'm conveying the problem properly.
Sounds like your functionality is embedded in MFC Windows' load event. If you want the application to be more reactive, move that code to your application class.

How to make a loading/intro animation popup while waiting for program to start up clutter/GTK+

My program takes a few seconds to start up. I am using clutter for the GUI, and I decided to try and make something pop up to indicate that the program is starting up. I wanted to just have a logo pop up and rotate, then disappear when the program starts.
So in clutter, I figured I could just make a new stage (window) add an actor to it, make the and actor spin, in the first section of the main function. The window will pop up right away, but with no content, but the content wont show until you launch the clutter main loop.
So I was just wondering how I might be able to achieve this using clutter or GTK+.
If you are familar with reaper 4, the audio recording program, this program does something similar to what I want to mine to do.
What you want is called a splash screen. I'm unfamiliar with clutter, but I found this GTK splash screen example.
However, I think you're taking the problem the wrong way. Splash screens are a bad idea because you just add overhead. What you need is improving your startup performance, by doing some CPU and/or IO profiling. Loading stuff on-demand, and not all at once will help.
Unfortunately I'm unfamiliar with Clutter. But I'm pretty sure it will be difficult to render an animation without a main loop running in any high level library.
I'd try to put the code that causes the delay into a separate thread and inform the main loop when the startup is done.
Something like this is what i use:
string splashfile = path_templ + "/splashimg.png";
GtkWidget *image=gtk_image_new_from_file(splashfile.c_str());
gtk_container_add(GTK_CONTAINER(SplashWindow), image);
gtk_widget_show_all(SplashWindow);
//Cycle through all iterations (refresh everything in the GUI)
while (gtk_events_pending()){
gtk_main_iteration();
}
sleep(1);
(... rest of code ...)
gtk_main ();
gdk_threads_leave ();
Especially that last part of while events pending is the key

Passing the "enter key" event to flash player in an ATL Window?

I have a Flash player (flash9.ocx) embedded in an ATL window and have coded functionality into the swf to respond to the return/enter key being pressed.
Works fine from the standalone swf player but as soon as its played from within my embedded player it doesn't execute. It's as if my window is getting in the way somehow?
Is there any way to pass the keypress through to the player?
FYI, there isn't anything to weird in place on the form.
Thanks!
I'm not VC++ developer, but I use Flash a lot.
Though not sure, it seems that the embedded player doesn't have the focus. Make sure you've got this part covered on the Flash side of things:
the stage exists ( you movie is properly initialized)
you set the KeyboardEvent listener to the stage.
You could use the FocusManager to make sure you've got the focus.
I don't know if you can pass the focus from you app to the SWF OLE through some tabIndex or something.
If still this doesn't work you can try using the External Interface to add callbacks from your app to flash player ( basically call and actionscript function from your app ).
This was achieved through fscommand before, but External Interface seems to be the thing to use now.
Good luck!
I don't use flash a lot but i'm a C++ programmer. =)
Let's see if I can help you.
I believe that your application is catching all the events before your flash movie. I don't know if there is a better way to do this but you could listen for any keyboard event on your form and use the SetVariable of your ActiveX component to set a variable inside Flash. Then, in the Flash Movie you could set a watch for any changes on this variable and trigger your Enter event.
Hope this helps.