How to make an auto hiding menu bar with Qt4 - animation

I am trying to make a Qt application which has an auto hiding menu bar. How can i do that?

That's an interesting task ! Ok, lets see... I'd suggest you putting a code that keeps track of mouse cursor movement in QMainWindow::centralWidget(). You need to call QWidget::setMouseTracking(true) first to be able to keep track of your mouse movement (they are turned off by default). The code can look like this:
QMainWindow *mainWindow = new QMainWindow;
MyWidget * myWidget = new MyWidget(mainWindow);
myWidget->setMouseTracking(true);
mainWindow->setCentralWidget(myWidget);
And then in your widget QWidget::mouseMove() event you need to detect whether you are in the correct area. The code can look like this:
void MyWidget::mouseMoveEvent(QMouseEvent * event) {
bool menuVisible = inCorrectArea(event->pos());
mainWindow->menuBar()->setVisible(menuVisible);
...
}
There are several ways to get access to "mainWindow" in your MyWidget. One of them is to store a pointer in MyWidget private variable when you pass MainWindow in its MyWidget constructor. You can also issue a signal from your MyWidget and handle it in MainWindow.
Hope this helps.

Related

How to create a "clicking effect" on a 3d-object (3d-cube) in Unity3d?

I have a 3d-object (cube), which I want to use as a button. I've written the code in order to detect, if the cube was pressed but it doesn't look like it was pressed, since it lacks the "clicking animation". How can I create a clicking animation on my 3d-object ?
A good idea is to play an aninimation which skrinks the cube a bit and releases it immediately afterwards. The handler code you want to execute on a click might block the game loop, e.g. when you load a level. Then it might be useful to load the level aysnchronously to be able to see the animation. Or you execute the handler code after the animation. Or you play the scale down animation on the press event and the scale up animation on the release event.
Technically you can use the build in animation editor, the Update() method, start a coroutine or use the assets iTween or HOTween.
http://docs.unity3d.com/ScriptReference/Transform-localScale.html
Let me know if you like the idea or questions arise.
Unity makes it easier now to do this using Unity Canvas UI. Instead of real 3d buttons, you could place a canvas UI in world space at the location where you want the buttons. Add a UI Panel to the canvas then add a UI Button.
Now, you have out of the box several clicking effects. The default it color tint, but you can choose sprite swap, or animation.
If you do want animation, when you select button animation it will create an animator for you. Click on your UI button Game Object in the scene hierarchy and open the animation window. You can choose Pressed animation from the drop down, and press RECORD button, then edit your buttons scale, say make it 0.75 for x,y,z. Now when you click on the button it will animate a cool scale down for you.
Sorry, I know that is a lot of information dumped! But you will find it pretty great once you start working with it in world space.
You can scale it down a tiny bit once click happen. For example:
void OnMouseDown() {
this.transform.localScale += new Vector3(0.05f, 0.05f, 0.05f);
}
Then after click scale it back to the original size.
Perhaps look into iTween (free on Unity Asset store).
Its very easy to use and you can produce some nice looking animations.
you can scale it when pressed or just change the color a little bit. On mouse up, rescale or recolor it.
void OnMouseDown()
{
transform.localScale -= new Vector3(0.05, 0.05 , 0);
//or
transform.GetComponent<SpriteRenderer>().color += new Color(40,40,40);
}
void OnMouseUp()
{
transform.localScale += new Vector3(0.05, 0.05 , 0);
//or
transform.GetComponent<SpriteRenderer>().color -= new Color(40,40,40);
}
You can implement your button using new Event system of unity. Here are the functions you can implement :
public class ExampleClass : MonoBehaviour, IPointerDownHandler, IPointerUpHandler, IPointerClickHandler, IPointerEnterHandler, IPointerExitHandler
{
public void OnPointerEnter(PointerEventData eventData)
{
//it is the function when you hover your mouse to the object
//You can change the color of your object to make your users
//understand that it is not just a cube but also a clickable item
}
public void OnPointerExit(PointerEventData eventData)
{
//You can revert your color back to its original
}
public void OnPointerDown (PointerEventData eventData)
{
//You can play with local scale as suggested by other answers here
}
public void OnPointerUp (PointerEventData eventData)
{
// Revert back the changes you made at onPointerDown
}
public void OnPointerClick (PointerEventData eventData)
{
//Use here for operations when your button is clicked
}
}

Group of buttons?

I have a question - is there any way to define a few buttons as a 1 group, and make 1 animation that will start for this group, instead of making an separate animation start for each of them?
Put them all in a ViewGroup and animate that. All children will be part of the animation. A ViewGroup is the base class for any layout class, that means you can use a LinearLayout, RelativeLayout or anything else that you find suitable.
You can try to set to all buttons same onTouchListener, like:
button1.setOnTouchListener(this);
button2.setOnTouchListener(this);
button3.setOnTouchListener(this);
Of course your app needs to implement onTouchListener, and then you can write your onTouchListener:
public void onClick(View v) {
// write your code what you want your buttons to do
// You can also write some different codes for buttons by using id
if(v.getId() == button1.getId())
{
//do something when button1 clicked...
}
}

Programmatically slide to next Panorama item

Is it possible to programmatically move from one panorama page/item to the next and get the same kind of animated sliding effect you get when sliding with a finger?
I can use the PanoramaControl.DefaultItem property to move to the expected item/page, but you won't get the animated sliding effect. Any ideas here?
Its possible, just put the setting of the DefaultItem between a SlideTransition Completed event and you are done:
public static class PanoramaExtensions
{
public static void SlideToPage(this Panorama self, int item)
{
var slide_transition = new SlideTransition() { };
slide_transition.Mode = SlideTransitionMode.SlideLeftFadeIn;
ITransition transition = slide_transition.GetTransition(self);
transition.Completed += delegate
{
self.DefaultItem = self.Items[item];
transition.Stop();
};
transition.Begin();
}
}
Use my_panorama.SlideToPage(1) to slide to the second page.
You can use below code :
panoramaRoot.DefaultItem = (PanoramaItem)panoramaRoot.Items[1];
it is not programatically possible to change the selected index of a panorama control. As you mention the only way of setting the index is using the DefaultItem property which is only useful when navigationg to the page which contains the panorama.
Here is another post that discusses it.
I think the easiest way to achieve this would be to create separate visual states for each item and create animated slide transitions for transitioning to each state. Then you can use VisualStateManager.GoToState(<page>, <state>, true); to initiate the state change.
No - the panorama control doesn't support programmatic manipulation like this.
If you want an experience like this, then you could try a hand-written panorama control - e.g. http://phone.codeplex.com/

Creating Dialogs with Silverlight Prism

I'm new to creating Silverlight applications. I have inherited a code-base that I've been told is using Prism. Based upon what I've seen in the code-base, this looks to be true. My problem is, I am just trying to open a dialog window and close a dialog window.
To open the dialog window, I'm using the following:
UserControl myDialog = new MyDialog();
IRegion region = myRegionManager.Regions["DIALOG_AREA"];
IRegionManager popupRegionManager = region.Add(myDialog, null, true);
region.Activate(myDialog);
The dialog I have designed appears. It has two buttons: "OK" and "Cancel". When a user clicks on of these dialogs, I want to close the dialog. My problem is, I have no idea how to do this. Because the dialog is not a ChildWindow, I cannot call this.Close(). But, when I change MyDialog to a ChildWindow, it is wrapped in some custom window chrome that i can't figure out how to get rid of.
How do I close a dialog in Prism? Thank you!
Instead of putting in a different region, you should make your ViewModel call a service where you call your dialog window.
public MainPageViewModel(IMainPage view,
ILoginBox loginBox )
: base(view)
{
this.view = view;
this.loginBox = loginBox;
}
public interface ILoginBox
{
void Show();
}
remember to use the IOC container and declare on your ModuleClass:
protected override void RegierTypes()
{
base.Container.RegisterType<ILoginBox , LoginBox>();
}
I hope it helps.
If you are still looking for an example, check:
another Stackoverflow sample

How to attach CFormView derived class to CMFCTabCrtl?

I have created MFC MDI project with base class CFormView, ribbon, caption bar etc.
In CMainFrame, OnCreate() calls EnableMDITabbedGroups() which automatically adds one tab
and attaches CMyProjectView view. Now I want to add second tab and attach second view to that tab. I created new dialog and added CFormView derived class to it.
Here is the code:
void CMainFrame::CreateViews()
{
const CObList &tabGroups = GetMDITabGroups();
CMFCTabCtrl *wndTab = (CMFCTabCtrl*)tabGroups.GetHead();
wndTab->m_bEnableWrapping = TRUE;
CRect dummyRect;
CNewFormView *pNewView = (CNewFormView*)RUNTIME_CLASS(CNewFormView)->CreateObject();
((CWnd*)pNewView)->Create(NULL, NULL, WS_CHILD, dummyRect, wndTab, IDD_NEWFORMVIEW);
wndTab->AddTab(pNewView, _T("NewTab"), -1, TRUE);
}
Now, I'm pretty sure I missed something trivial or went in wrong direction all together,
but I can't get new view to show up. Also, I can't catch AFX_WM_CHANGE_ACTIVE_TAB or AFX_WM_CHANGING_ACTIVE_TAB in CMainFrame. Message gets send from CMFCBaseTabCtrl::FireChangingActiveTab but nothing happens.
WS_VISIBLE is missing from the view's styles?
You may want to set the active view for the frame too.

Resources