menu polish

This commit is contained in:
Brad Davis 2015-04-29 02:42:57 -07:00
parent 75f6ad3b99
commit 87ef98005d
4 changed files with 152 additions and 155 deletions

View file

@ -107,6 +107,10 @@ Item {
}
MenuItem { action: animations }
}
Menu {
title: "Long menu name top menu"
MenuItem { action: aboutApp }
}
Menu {
title: "Help"
MenuItem { action: aboutApp }

View file

@ -5,6 +5,7 @@ import QtQuick.Controls.Styles 1.3
import "controls"
import "styles"
Hifi.VrMenu {
id: root
HifiConstants { id: hifi }
@ -12,15 +13,14 @@ Hifi.VrMenu {
anchors.fill: parent
objectName: "VrMenu"
enabled: false
opacity: 0.0
z: 10000
property int animationDuration: 200
property var models: []
property var columns: []
z: 10000
onEnabledChanged: {
if (enabled && columns.length == 0) {
@ -51,20 +51,22 @@ Hifi.VrMenu {
property var menuBuilder: Component {
Border {
HifiConstants { id: hifi }
property int menuDepth
Component.onCompleted: {
menuDepth = root.models.length - 1
if (menuDepth == 0) {
x = lastMousePosition.x - 20
y = lastMousePosition.y - 20
} else {
var lastColumn = root.columns[menuDepth - 1]
var lastColumn = root.columns[menuDepth - 1]
x = lastColumn.x + 64;
y = lastMousePosition.y - height / 2;
}
}
border.color: hifi.colors.hifiBlue
color: hifi.colors.window
property int menuDepth
implicitHeight: listView.implicitHeight + 16
implicitWidth: listView.implicitWidth + 16
@ -84,170 +86,27 @@ Hifi.VrMenu {
model: root.models[menuDepth]
delegate: Loader {
id: loader
sourceComponent: root.itemBuilder
source: "VrMenuItem.qml"
Binding {
target: loader.item
property: "root"
property: "menuContainer"
value: root
when: loader.status == Loader.Ready
}
}
Binding {
target: loader.item
property: "source"
value: modelData
when: loader.status == Loader.Ready
}
Binding {
target: loader.item
property: "border"
value: listView.parent
when: loader.status == Loader.Ready
}
}
Binding {
target: loader.item
property: "listView"
value: listView
when: loader.status == Loader.Ready
}
}
}
}
}
}
property var itemBuilder: Component {
Item {
property var source
property var root
property var listView
property var border
implicitHeight: row.implicitHeight + 4
implicitWidth: row.implicitWidth + label.height
// FIXME uncommenting this line results in menus that have blank spots
// rather than having the correct size
// visible: source.visible
Row {
id: row
spacing: 2
anchors {
top: parent.top
topMargin: 2
}
Spacer { size: 4 }
FontAwesome {
id: check
verticalAlignment: Text.AlignVCenter
size: row.height
text: checkText()
color: label.color
function checkText() {
if (!source || source.type != 1 || !source.checkable) {
return "";
}
// FIXME this works for native QML menus but I don't think it will
// for proxied QML menus
if (source.exclusiveGroup) {
return source.checked ? "\uF05D" : "\uF10C"
}
return source.checked ? "\uF046" : "\uF096"
}
}
Text {
id: label
// anchors.top: parent.top
// anchors.bottom: parent.bottom
text: typedText()
verticalAlignment: Text.AlignVCenter
color: source.enabled ? hifi.colors.text : hifi.colors.disabledText
enabled: source.enabled && source.visible
function typedText() {
if (source) {
switch(source.type) {
case 2:
return source.title;
case 1:
return source.text;
case 0:
return "-----"
}
}
return ""
}
}
} // row
FontAwesome {
anchors {
top: row.top
}
id: tag
size: label.height
width: implicitWidth
visible: source.type == 2
x: listView.width - width - 4
text: "\uF0DA"
color: label.color
}
MouseArea {
anchors.top: parent.top
anchors.bottom: parent.bottom
anchors.right: tag.right
anchors.left: parent.left
anchors.rightMargin: -4
acceptedButtons: Qt.LeftButton
hoverEnabled: true
Rectangle {
id: highlight
visible: false
anchors.fill: parent
color: "#7f0e7077"
}
Timer {
id: timer
interval: 1000
onTriggered: parent.select();
}
onEntered: {
/*
* Uncomment below to have menus auto-popup
*
* FIXME if we enabled timer based menu popup, either the timer has
* to be very very short or after auto popup there has to be a small
* amount of time, or a test if the mouse has moved before a click
* will be accepted, otherwise it's too easy to accidently click on
* something immediately after the auto-popup appears underneath your
* cursor
*
*/
//if (source.type == 2 && enabled) {
// timer.start()
//}
highlight.visible = source.enabled
}
onExited: {
timer.stop()
highlight.visible = false
}
onClicked: {
select();
}
function select() {
//timer.stop();
var popped = false;
while (columns.length - 1 > listView.parent.menuDepth) {
popColumn();
popped = true;
}
if (!popped || source.type != 1) {
parent.root.selectItem(parent.source);
}
}
}
}
}
@ -262,7 +121,7 @@ Hifi.VrMenu {
var oldColumn = lastColumn();
//oldColumn.enabled = false
}
var newColumn = menuBuilder.createObject(root);
var newColumn = menuBuilder.createObject(root);
columns.push(newColumn);
newColumn.forceActiveFocus();
}
@ -295,11 +154,11 @@ Hifi.VrMenu {
source.trigger()
enabled = false
break;
case 0:
case 0:
break;
}
}
function reset() {
while (columns.length > 0) {
popColumn();

View file

@ -0,0 +1,130 @@
import QtQuick 2.4
import QtQuick.Controls 1.3
import QtQuick.Controls.Styles 1.3
import "controls"
import "styles"
Item {
id: root
HifiConstants {
id: hifi
}
property var source
property var menuContainer
property var listView
MouseArea {
anchors.left: parent.left
anchors.right: tag.right
anchors.rightMargin: -4
anchors.top: parent.top
anchors.bottom: parent.bottom
acceptedButtons: Qt.LeftButton
hoverEnabled: true
Rectangle {
id: highlight
visible: false
anchors.fill: parent
color: "#7f0e7077"
}
onEntered: {
//if (source.type == 2 && enabled) {
// timer.start()
//}
highlight.visible = source.enabled
}
onExited: {
timer.stop()
highlight.visible = false
}
onClicked: {
select()
}
}
implicitHeight: label.implicitHeight + 4
implicitWidth: label.implicitWidth + label.height * 2
Timer {
id: timer
interval: 1000
onTriggered: parent.select()
}
FontAwesome {
clip: true
id: check
verticalAlignment: Text.AlignBottom
horizontalAlignment: Text.AlignHCenter
anchors.verticalCenter: parent.verticalCenter
color: label.color
text: checkText()
size: label.height
font.pixelSize: size - 4
function checkText() {
if (!source || source.type != 1 || !source.checkable) {
return ""
}
// FIXME this works for native QML menus but I don't think it will
// for proxied QML menus
if (source.exclusiveGroup) {
return source.checked ? "\uF05D" : "\uF10C"
}
return source.checked ? "\uF046" : "\uF096"
}
}
Text {
id: label
text: typedText()
anchors.left: check.right
anchors.leftMargin: 4
anchors.verticalCenter: parent.verticalCenter
verticalAlignment: Text.AlignVCenter
color: source.enabled ? hifi.colors.text : hifi.colors.disabledText
enabled: source.enabled && source.visible
function typedText() {
if (source) {
switch (source.type) {
case 2:
return source.title
case 1:
return source.text
case 0:
return "-----"
}
}
return ""
}
}
FontAwesome {
id: tag
x: listView.width - width - 4
size: label.height
width: implicitWidth
visible: source.type == 2
text: "\uF0DA"
anchors.verticalCenter: parent.verticalCenter
color: label.color
}
function select() {
//timer.stop();
var popped = false
while (columns.length - 1 > listView.parent.menuDepth) {
popColumn()
popped = true
}
if (!popped || source.type != 1) {
root.menuContainer.selectItem(source)
}
}
}

View file

@ -341,7 +341,11 @@ public:
offscreenUi->setProxyWindow(this);
QDesktopWidget* desktop = QApplication::desktop();
setGeometry(desktop->availableGeometry(desktop->screenCount()-1));
QRect rect = desktop->availableGeometry(desktop->screenCount() - 1);
int height = rect.height();
//rect.setHeight(height / 2);
rect.setY(rect.y() + height / 2);
setGeometry(rect);
// setFramePosition(QPoint(-1000, 0));
// resize(QSize(800, 600));