History

Merge upstream/master into andrew/inertia

Andrew Meadows committed 12 years ago

Commit 5ffd3072 parents 301c3c5 5f2f3db159 files · +8117 −1301Browse files

Showing the changes to interface/src/Menu.cpp (1 of 159 files). Show all

Unified · Split

interface/src/Menu.cpp+53−73
@@ -40,6 +40,7 @@ · 39 unmodified lines
40#include "ui/InfoView.h"40#include "ui/InfoView.h"
41#include "ui/MetavoxelEditor.h"41#include "ui/MetavoxelEditor.h"
42#include "ui/ModelsBrowser.h"42#include "ui/ModelsBrowser.h"
43#include "ui/LoginDialog.h"
43 44
44 45
45Menu* Menu::_instance = NULL;46Menu* Menu::_instance = NULL;
@@ -169,12 +170,12 @@ Menu::Menu() : · 123 unmodified lines
169 170
170 171
171 QMenu* editMenu = addMenu("Edit");172 QMenu* editMenu = addMenu("Edit");
172 173
173 QUndoStack* undoStack = Application::getInstance()->getUndoStack();174 QUndoStack* undoStack = Application::getInstance()->getUndoStack();
174 QAction* undoAction = undoStack->createUndoAction(editMenu);175 QAction* undoAction = undoStack->createUndoAction(editMenu);
175 undoAction->setShortcut(Qt::CTRL | Qt::Key_Z);176 undoAction->setShortcut(Qt::CTRL | Qt::Key_Z);
176 addActionToQMenuAndActionHash(editMenu, undoAction);177 addActionToQMenuAndActionHash(editMenu, undoAction);
177 178
178 QAction* redoAction = undoStack->createRedoAction(editMenu);179 QAction* redoAction = undoStack->createRedoAction(editMenu);
179 redoAction->setShortcut(Qt::CTRL | Qt::SHIFT | Qt::Key_Z);180 redoAction->setShortcut(Qt::CTRL | Qt::SHIFT | Qt::Key_Z);
180 addActionToQMenuAndActionHash(editMenu, redoAction);181 addActionToQMenuAndActionHash(editMenu, redoAction);
@@ -279,8 +280,9 @@ Menu::Menu() : · 98 unmodified lines
279 280
280 addCheckableActionToQMenuAndActionHash(renderOptionsMenu, MenuOption::Shadows, 0, false);281 addCheckableActionToQMenuAndActionHash(renderOptionsMenu, MenuOption::Shadows, 0, false);
281 addCheckableActionToQMenuAndActionHash(renderOptionsMenu, MenuOption::Metavoxels, 0, true);282 addCheckableActionToQMenuAndActionHash(renderOptionsMenu, MenuOption::Metavoxels, 0, true);
282 addCheckableActionToQMenuAndActionHash(renderOptionsMenu, MenuOption::BuckyBalls, 0, true);283 addCheckableActionToQMenuAndActionHash(renderOptionsMenu, MenuOption::BuckyBalls, 0, false);
283 addCheckableActionToQMenuAndActionHash(renderOptionsMenu, MenuOption::Particles, 0, true);284 addCheckableActionToQMenuAndActionHash(renderOptionsMenu, MenuOption::Particles, 0, true);
285 addCheckableActionToQMenuAndActionHash(renderOptionsMenu, MenuOption::Models, 0, true);
284 addActionToQMenuAndActionHash(renderOptionsMenu, MenuOption::LodTools, Qt::SHIFT | Qt::Key_L, this, SLOT(lodTools()));286 addActionToQMenuAndActionHash(renderOptionsMenu, MenuOption::LodTools, Qt::SHIFT | Qt::Key_L, this, SLOT(lodTools()));
285 287
286 QMenu* voxelOptionsMenu = developerMenu->addMenu("Voxel Options");288 QMenu* voxelOptionsMenu = developerMenu->addMenu("Voxel Options");
@@ -320,7 +322,7 @@ Menu::Menu() : · 33 unmodified lines
320 addCheckableActionToQMenuAndActionHash(avatarOptionsMenu, MenuOption::Visage, 0, true,322 addCheckableActionToQMenuAndActionHash(avatarOptionsMenu, MenuOption::Visage, 0, true,
321 appInstance->getVisage(), SLOT(updateEnabled()));323 appInstance->getVisage(), SLOT(updateEnabled()));
322#endif324#endif
323 325
324 addCheckableActionToQMenuAndActionHash(avatarOptionsMenu, MenuOption::GlowWhenSpeaking, 0, true);326 addCheckableActionToQMenuAndActionHash(avatarOptionsMenu, MenuOption::GlowWhenSpeaking, 0, true);
325 addCheckableActionToQMenuAndActionHash(avatarOptionsMenu, MenuOption::ChatCircling, 0, false);327 addCheckableActionToQMenuAndActionHash(avatarOptionsMenu, MenuOption::ChatCircling, 0, false);
326 328
@@ -334,7 +336,6 @@ Menu::Menu() : · 7 unmodified lines
334 SLOT(setFilter(bool)));336 SLOT(setFilter(bool)));
335 addCheckableActionToQMenuAndActionHash(handOptionsMenu, MenuOption::DisplayHands, 0, true);337 addCheckableActionToQMenuAndActionHash(handOptionsMenu, MenuOption::DisplayHands, 0, true);
336 addCheckableActionToQMenuAndActionHash(handOptionsMenu, MenuOption::DisplayHandTargets, 0, false);338 addCheckableActionToQMenuAndActionHash(handOptionsMenu, MenuOption::DisplayHandTargets, 0, false);
337 addCheckableActionToQMenuAndActionHash(handOptionsMenu, MenuOption::PlaySlaps, 0, false);
338 addCheckableActionToQMenuAndActionHash(handOptionsMenu, MenuOption::HandsCollideWithSelf, 0, false);339 addCheckableActionToQMenuAndActionHash(handOptionsMenu, MenuOption::HandsCollideWithSelf, 0, false);
339 addCheckableActionToQMenuAndActionHash(handOptionsMenu, MenuOption::ShowIKConstraints, 0, false);340 addCheckableActionToQMenuAndActionHash(handOptionsMenu, MenuOption::ShowIKConstraints, 0, false);
340 addCheckableActionToQMenuAndActionHash(handOptionsMenu, MenuOption::AlignForearmsWithWrists, 0, true);341 addCheckableActionToQMenuAndActionHash(handOptionsMenu, MenuOption::AlignForearmsWithWrists, 0, true);
@@ -723,31 +724,31 @@ QAction* Menu::addActionToQMenuAndActionHash(QMenu* destinationMenu, · 382 unmodified lines
723 QAction::MenuRole role,724 QAction::MenuRole role,
724 int menuItemLocation) {725 int menuItemLocation) {
725 QAction* actionBefore = NULL;726 QAction* actionBefore = NULL;
726 727
727 if (menuItemLocation >= 0 && destinationMenu->actions().size() > menuItemLocation) {728 if (menuItemLocation >= 0 && destinationMenu->actions().size() > menuItemLocation) {
728 actionBefore = destinationMenu->actions()[menuItemLocation];729 actionBefore = destinationMenu->actions()[menuItemLocation];
729 }730 }
730 731
731 if (!actionName.isEmpty()) {732 if (!actionName.isEmpty()) {
732 action->setText(actionName);733 action->setText(actionName);
733 }734 }
734 735
735 if (shortcut != 0) {736 if (shortcut != 0) {
736 action->setShortcut(shortcut);737 action->setShortcut(shortcut);
737 }738 }
738 739
739 if (role != QAction::NoRole) {740 if (role != QAction::NoRole) {
740 action->setMenuRole(role);741 action->setMenuRole(role);
741 }742 }
742 743
743 if (!actionBefore) {744 if (!actionBefore) {
744 destinationMenu->addAction(action);745 destinationMenu->addAction(action);
745 } else {746 } else {
746 destinationMenu->insertAction(actionBefore, action);747 destinationMenu->insertAction(actionBefore, action);
747 }748 }
748 749
749 _actionHash.insert(action->text(), action);750 _actionHash.insert(action->text(), action);
750 751
751 return action;752 return action;
752}753}
753 754
@@ -813,42 +814,12 @@ void sendFakeEnterEvent() { · 59 unmodified lines
813 QCoreApplication::sendEvent(glWidget, &enterEvent);814 QCoreApplication::sendEvent(glWidget, &enterEvent);
814}815}
815 816
816const int QLINE_MINIMUM_WIDTH = 400;
817const float DIALOG_RATIO_OF_WINDOW = 0.30f;817const float DIALOG_RATIO_OF_WINDOW = 0.30f;
818 818
819void Menu::loginForCurrentDomain() {819void Menu::loginForCurrentDomain() {
820 QDialog loginDialog(Application::getInstance()->getWindow());820 LoginDialog* loginDialog = new LoginDialog(Application::getInstance()->getWindow());
821 loginDialog.setWindowTitle("Login");821 loginDialog->show();
822 822 loginDialog->resizeAndPosition(false);
823 QBoxLayout* layout = new QBoxLayout(QBoxLayout::TopToBottom);
824 loginDialog.setLayout(layout);
825 loginDialog.setWindowFlags(Qt::Sheet);
826
827 QFormLayout* form = new QFormLayout();
828 layout->addLayout(form, 1);
829
830 QLineEdit* loginLineEdit = new QLineEdit();
831 loginLineEdit->setMinimumWidth(QLINE_MINIMUM_WIDTH);
832 form->addRow("Login:", loginLineEdit);
833
834 QLineEdit* passwordLineEdit = new QLineEdit();
835 passwordLineEdit->setMinimumWidth(QLINE_MINIMUM_WIDTH);
836 passwordLineEdit->setEchoMode(QLineEdit::Password);
837 form->addRow("Password:", passwordLineEdit);
838
839 QDialogButtonBox* buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
840 loginDialog.connect(buttons, SIGNAL(accepted()), SLOT(accept()));
841 loginDialog.connect(buttons, SIGNAL(rejected()), SLOT(reject()));
842 layout->addWidget(buttons);
843
844 int dialogReturn = loginDialog.exec();
845
846 if (dialogReturn == QDialog::Accepted && !loginLineEdit->text().isEmpty() && !passwordLineEdit->text().isEmpty()) {
847 // attempt to get an access token given this username and password
848 AccountManager::getInstance().requestAccessToken(loginLineEdit->text(), passwordLineEdit->text());
849 }
850
851 sendFakeEnterEvent();
852}823}
853 824
854void Menu::editPreferences() {825void Menu::editPreferences() {
@@ -927,42 +898,51 @@ void Menu::goTo() { · 72 unmodified lines
927 int dialogReturn = gotoDialog.exec();898 int dialogReturn = gotoDialog.exec();
928 if (dialogReturn == QDialog::Accepted && !gotoDialog.textValue().isEmpty()) {899 if (dialogReturn == QDialog::Accepted && !gotoDialog.textValue().isEmpty()) {
929 QString desiredDestination = gotoDialog.textValue();900 QString desiredDestination = gotoDialog.textValue();
901 if (!goToURL(desiredDestination)) {;
902 goTo(desiredDestination);
903 }
904 }
905 sendFakeEnterEvent();
906}
930 907
931 if (desiredDestination.startsWith(CUSTOM_URL_SCHEME + "//")) {908bool Menu::goToURL(QString location) {
932 QStringList urlParts = desiredDestination.remove(0, CUSTOM_URL_SCHEME.length() + 2).split('/', QString::SkipEmptyParts);909 if (location.startsWith(CUSTOM_URL_SCHEME + "//")) {
910 QStringList urlParts = location.remove(0, CUSTOM_URL_SCHEME.length() + 2).split('/', QString::SkipEmptyParts);
933 911
934 if (urlParts.count() > 1) {912 if (urlParts.count() > 1) {
935 // if url has 2 or more parts, the first one is domain name913 // if url has 2 or more parts, the first one is domain name
936 QString domain = urlParts[0];914 QString domain = urlParts[0];
937 915
938 // second part is either a destination coordinate or916 // second part is either a destination coordinate or
939 // a place name917 // a place name
940 QString destination = urlParts[1];918 QString destination = urlParts[1];
941 919
942 // any third part is an avatar orientation.920 // any third part is an avatar orientation.
943 QString orientation = urlParts.count() > 2 ? urlParts[2] : QString();921 QString orientation = urlParts.count() > 2 ? urlParts[2] : QString();
944 922
945 goToDomain(domain);923 goToDomain(domain);
946
947 // goto either @user, #place, or x-xx,y-yy,z-zz
948 // style co-ordinate.
949 goTo(destination);
950 924
951 if (!orientation.isEmpty()) {925 // goto either @user, #place, or x-xx,y-yy,z-zz
952 // location orientation926 // style co-ordinate.
953 goToOrientation(orientation);927 goTo(destination);
954 }928
955 } else if (urlParts.count() == 1) {929 if (!orientation.isEmpty()) {
956 // location coordinates or place name930 // location orientation
957 QString destination = urlParts[0];931 goToOrientation(orientation);
958 goTo(destination);
959 }932 }
933 } else if (urlParts.count() == 1) {
934 QString destination = urlParts[0];
960 935
961 } else {936 // If this starts with # or @, treat it as a user/location, otherwise treat it as a domain
962 goToUser(gotoDialog.textValue());937 if (destination[0] == '#' || destination[0] == '@') {
938 goTo(destination);
939 } else {
940 goToDomain(destination);
941 }
963 }942 }
943 return true;
964 }944 }
965 sendFakeEnterEvent();945 return false;
966}946}
967 947
968void Menu::goToUser(const QString& user) {948void Menu::goToUser(const QString& user) {
@@ -1119,7 +1099,7 @@ void Menu::toggleLoginMenuItem() { · 150 unmodified lines
1119 1099
1120 if (accountManager.isLoggedIn()) {1100 if (accountManager.isLoggedIn()) {
1121 // change the menu item to logout1101 // change the menu item to logout
1122 _loginAction->setText("Logout " + accountManager.getUsername());1102 _loginAction->setText("Logout " + accountManager.getAccountInfo().getUsername());
1123 connect(_loginAction, &QAction::triggered, &accountManager, &AccountManager::logout);1103 connect(_loginAction, &QAction::triggered, &accountManager, &AccountManager::logout);
1124 } else {1104 } else {
1125 // change the menu item to login1105 // change the menu item to login
@@ -1274,7 +1254,7 @@ void Menu::autoAdjustLOD(float currentFPS) { · 148 unmodified lines
1274 _avatarLODDistanceMultiplier - DISTANCE_DECREASE_RATE);1254 _avatarLODDistanceMultiplier - DISTANCE_DECREASE_RATE);
1275 }1255 }
1276 }1256 }
1277 1257
1278 bool changed = false;1258 bool changed = false;
1279 quint64 elapsed = now - _lastAdjust;1259 quint64 elapsed = now - _lastAdjust;
1280 1260