Qt5.4/QML: How to determine wether the orientation of the screen is inverted or not - c++

I'm creating a iOS video camera app using Qt5.4.
For this I need to determine the current orientation of the device to rotate the video in the VideoOutput element.
As we can see there's a autoOrientation property but it doesn't work as I expect: if I keep switching the orientation it starts to have a weird behaviour i.e. setting the wrong orientation.
Then I tried to apply the rotation based on the Screen.primaryOrientation property:
Copying the function defined in this example, I've a created a similar version, which you can find here.
I call it every time width or height changes, like this:
onWidthChanged: { video.orientation = changeOrientation(); }
onHeightChanged: { video.orientation = changeOrientation(); }
However, it seems that the Inverted orientations are completely ignored, which is strange since they are listed in the documentation.
Anyone has any idea about why it's happening?
UPDATE:
I could isolate the problem when using autoOrientation, basically there's a menu on top of the VideoOutput, the menu is a RowLayout, it's visible only if the user clicks on the menu icon, and only if the user clicks on the menu icon the orientation gets messy.
However, in any situation the InvertedPortrait is not recognized.

Related

Selected objects on Mac show background highlight instead of bounding rectangle highlight

I have a Qt application that I am porting to mac.
There are some objects (images) shown in QListView or QTableView, in IconMode, that, when selected, in Windows and Linux get highlighted (a rectangle holding the object, which has colored background - gray if the item is selected but no focus, light blue if the item has focus, slightly more intense blue if the item is selected and has focus - this is probably the default behavior for selection, based on selected color scheme).
On mac the only thing that shows is a tiny dot under the object, and if the object in the view is transparent, light blue shows inside the object - but no selection rectangle. Nothing changes if the object has focus, and if the object is not transparent, only the tiny dot under the object shows.
Once objects are moved on the canvas, mac shows selection as needed, on a bounding rectangle, only inside the listview and tableview the bounding rectangle is invisible.
The form was created using the Designer... the listView property QListView.selectionRectVisible is checked.
I can't see what makes that happen... but I have tried
#if defined (Q_OS_MACX)
m_ui->lv1->setAttribute(Qt::WA_MacShowFocusRect, true);
m_ui->lv1->UseCustomSelectionColors(true); // documentation shows this but it doesn't build
m_ui->lv1->setSelectionRectVisible(true);
#endif
for the mac, and it does not make any difference.
What else can I try, to show selection of objects ?
Qt 4.8
Edit: found a site that has an example for a tiled list view... among other things it draws a visible rectangle around the selected items...
It seems like a very complicated way to do something that seems to be already implemented - highlighting a selected object - I will do it if I have to but I am hoping that I do not have to add something too complicated for the mac version, that will not be used in any other platforms...
There has to be a way to use the normal properties and methods of listview and tableview to make sure that the background of the bounding rectangle, not just the background of the item, shows when a selection is made ?
I don't know if this is a typical mac behavior...
Update
While I really try not to overwrite the desired default system behavior, I tried to force list behavior...
#if defined (Q_OS_MACX)
QString stylesheet = "";
stylesheet += "QListView::item:selected:active:hover{background-color:red;}";
stylesheet += "QListView::item:selected:active:!hover{background-color:blue;}";
stylesheet += "QListView::item:selected:!active{background-color:yellow;}";
stylesheet += "QListView::item:!selected:hover{background-color:green;}";
setStyleSheet(stylesheet);
#endif
The problem is, I need the system colors, I cannot define my own since they will not match the rest of the app window...
What are the names of the system colors for hover, select (strong), select (but no focus), select (but not active) ?
I have tried using
stylesheet += "QListView::item:selected:active:hover{background-color:Highlight;}";
In windows, this looks ok - because it probably is not recognized so it is ignored... On mac, still ignored. And I have not seen any other names for backgrounds. I tried it with lowercase as well.
I ended up using a style sheet - as in the update to my question - with hard-coded color values for the osx blue theme.

How do you make a clickable sprite in SFML?

I've been looking through the SFML documentation for making clickable sprites, but so far I haven't found anything.
Do you guys think you could help me out?
There is nothing like sf::ClickableSprite in SFML so far, and probably there will never be. (Current list of classes in SFML)
However, you can obtain this behavior with the sf::Sprite object and the events. The idea is simple - as soon as you get the sf::Mouse::isButtonPressed(sf::Mouse::Left) event, check if the mouse is in the sprite. If it is, perform the action. You can perform another action (maybe undo) when button is released.
There is sf::Sprite::getGlobalBounds() function which returns you the position and the dimensions of the sprite. There's also sf::Mouse::getPosition() function, which returns the current position of the mouse. You can use sprite.getGlobalBounds().contains(mousePos) to check whether the mouse is in the sprite.
If you're using views, you'll need to add the view's position to sf::Mouse::getPosition(window), since it gets the mouse position relative to window coordinates.
(thanks to Chaosed0 for additional notes.)

OpenGL Detect clicking on object inside another object

I am pretty new to openGL programming and I encountered a problem I just need some advice on. Basically I have a button which has a simple function to just print something out on the console when it is clicked and that works fine on its own. However I also have a rectangle which I use as mini window or a container to hold buttons.
The problem I have is when the button is on top of the rectangle, the clicking functions for that button isn't detected, instead the clicking functions for the rectangle which is printing a message on the console saying the rectangle was clicked, is detected. On the other hand, if I drag the rectangle away and just leave the button on its own on the window, the clicking functions will work for the button.
Is there any advice you guys can give me or tell me what to research to aid me with detecting the button click while my button is inside of the rectangle? by the way I am not using Glut on my project.
A good start would be, if you told us, how you're actually getting the user input and how you're processing it. Whatever you do, it got nothing to do with OpenGL though, because OpenGL doesn't deal with user input and OpenGL doesn't deal with scene management.
OpenGL draws things. One point, line or triangle at a time. After it pushed some pixels to the framebuffer canvas it forgets about what it just did. There's no scene in OpenGL. There are no models in OpenGL. So whatever you do, it's using something else.

Cocos2d-iphone 2.0 set AutoRotate for landscape,but the view position is wrong when first loaded

The app is set up for only landscape.
In Project->target->Summary->Supported Interface Orientations, I enabled the 2 landscape icons (both left and right).
And in AppDelegate.m, the below code is written:
- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation
{
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
When the app is running on the device, the view showed at the beginning after the default cocos2d icon, all the positions are wrong which were all moved to the right-down side. When I rotate the screen, everything goes right, all in right position.
What's wrong?
I also tried the method below:
I disable all the icons in In Project->target->Summary->Supported Interface Orientations.
The code in AppDelegate still in use.
Then the view at the very beginning is ok but the screen can be rotated to protrait.
....
Any one can help?
Also put these two for iOS6 orientation, in AppDelegate.
-(NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscape;
}
- (NSUInteger)application:(UIApplication*)application supportedInterfaceOrientationsForWindow:(UIWindow*)window
{
return UIInterfaceOrientationMaskLandscape;
}
Look at this question and answer once.

how to scene restart with restart button after sprite falls below certain hight?

I am struggling with my first semi basic game for iPhone. The game operates well but I want a button to display saying restart and then when clicked it restarts the scene. This button should only appear when my sprite (called sprite) falls below the bottom of the iphone screen. I am using both cocos 2d and box 2d if that makes a difference.
Thank you for the help in advanced, it is greatly appreciated!
Quick answer for having the button appear once the sprite falls below a certain point: When you create the button, set its state to not visible. resetButton.isVisible = NO; Then write an if statement about your sprite's position and enable the button once that happens.
if (sprite.position.y >= 0)
{
resetButton.isVisible = YES;
}
This should get you started on that aspect. I'm not at my Mac right now, but if memory serves, a non-visible button is not enabled, so clicking on its location won't matter. If that's incorrect, just add in resetButton.isEnabled = NO; and YES appropriately.
As for resetting the scene, this can get a little tricky depending on what exactly you want to accomplish. You need to essentially replace the scene with itself, but this can cause undesirable flashes. A quick google search found a bunch of forum posts on this. If you can elaborate on what you've already tried and where you're getting caught up, I can try and get more specific.