From 4c26f025ac89fce9bfc526131caec6bf06a16003 Mon Sep 17 00:00:00 2001 From: Dimitar Dobrev Date: Wed, 12 Mar 2014 19:58:08 +0200 Subject: [PATCH] Enabled 'Enter' to open the chat. Deleted the now obsolete ChatEntry. --- interface/interface_en.ts | 16 +++--- interface/src/Application.cpp | 31 +--------- interface/src/Application.h | 4 -- interface/src/Menu.cpp | 6 +- interface/src/ui/ChatEntry.cpp | 102 --------------------------------- interface/src/ui/ChatEntry.h | 35 ----------- 6 files changed, 14 insertions(+), 180 deletions(-) delete mode 100644 interface/src/ui/ChatEntry.cpp delete mode 100644 interface/src/ui/ChatEntry.h diff --git a/interface/interface_en.ts b/interface/interface_en.ts index a8f78cd36e..685c6e3f67 100644 --- a/interface/interface_en.ts +++ b/interface/interface_en.ts @@ -4,22 +4,22 @@ Application - + Export Voxels - + Sparse Voxel Octree Files (*.svo) - + Open Script - + JavaScript Files (*.js) @@ -113,18 +113,18 @@ Menu - + Open .ini config file - - + + Text files (*.ini) - + Save .ini config file diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 032e849f0a..13e3d36fad 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -153,7 +153,6 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : _touchAvgY(0.0f), _isTouchPressed(false), _mousePressed(false), - _chatEntryOn(false), _audio(&_audioScope, STARTUP_JITTER_SAMPLES), _enableProcessVoxelsThread(true), _voxelProcessor(), @@ -698,21 +697,6 @@ void Application::keyPressEvent(QKeyEvent* event) { } if (activeWindow() == _window) { - if (_chatEntryOn) { - if (_chatEntry.keyPressEvent(event)) { - _myAvatar->setKeyState(event->key() == Qt::Key_Backspace || event->key() == Qt::Key_Delete ? - DELETE_KEY_DOWN : INSERT_KEY_DOWN); - _myAvatar->setChatMessage(string(_chatEntry.getContents().size(), SOLID_BLOCK_CHAR)); - - } else { - _myAvatar->setChatMessage(_chatEntry.getContents()); - _chatEntry.clear(); - _chatEntryOn = false; - setMenuShortcutsEnabled(true); - } - return; - } - bool isShifted = event->modifiers().testFlag(Qt::ShiftModifier); bool isMeta = event->modifiers().testFlag(Qt::ControlModifier); switch (event->key()) { @@ -793,10 +777,7 @@ void Application::keyPressEvent(QKeyEvent* event) { case Qt::Key_Return: case Qt::Key_Enter: - _chatEntryOn = true; - _myAvatar->setKeyState(NO_KEY_DOWN); - _myAvatar->setChatMessage(string()); - setMenuShortcutsEnabled(false); + Menu::getInstance()->triggerOption(MenuOption::Chat); break; case Qt::Key_Up: @@ -939,11 +920,6 @@ void Application::keyReleaseEvent(QKeyEvent* event) { if (activeWindow() == _window) { - if (_chatEntryOn) { - _myAvatar->setKeyState(NO_KEY_DOWN); - return; - } - switch (event->key()) { case Qt::Key_E: _myAvatar->setDriveKeys(UP, 0); @@ -2483,11 +2459,6 @@ void Application::displayOverlay() { } } - // Show chat entry field - if (_chatEntryOn) { - _chatEntry.render(_glWidget->width(), _glWidget->height()); - } - // Show on-screen msec timer if (Menu::getInstance()->isOptionChecked(MenuOption::FrameTimer)) { char frameTimer[10]; diff --git a/interface/src/Application.h b/interface/src/Application.h index 234f264447..70b7347654 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -64,7 +64,6 @@ #include "renderer/TextureCache.h" #include "renderer/VoxelShader.h" #include "ui/BandwidthDialog.h" -#include "ui/ChatEntry.h" #include "ui/OctreeStatsDialog.h" #include "ui/RearMirrorTools.h" #include "ui/LodToolsDialog.h" @@ -426,9 +425,6 @@ private: bool _mousePressed; // true if mouse has been pressed (clear when finished) - ChatEntry _chatEntry; // chat entry field - bool _chatEntryOn; // Whether to show the chat entry - GeometryCache _geometryCache; TextureCache _textureCache; diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index 5f6c541bc5..f0d4d8c133 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -163,7 +163,11 @@ Menu::Menu() : addActionToQMenuAndActionHash(toolsMenu, MenuOption::MetavoxelEditor, 0, this, SLOT(showMetavoxelEditor())); addActionToQMenuAndActionHash(toolsMenu, MenuOption::FstUploader, 0, Application::getInstance(), SLOT(uploadFST())); - _chatAction = addActionToQMenuAndActionHash(toolsMenu, MenuOption::Chat, 0, this, SLOT(showChat())); + _chatAction = addActionToQMenuAndActionHash(toolsMenu, + MenuOption::Chat, + Qt::Key_Return, + this, + SLOT(showChat())); #ifdef HAVE_QXMPP const QXmppClient& xmppClient = XmppClient::getInstance().getXMPPClient(); toggleChat(); diff --git a/interface/src/ui/ChatEntry.cpp b/interface/src/ui/ChatEntry.cpp deleted file mode 100644 index 470b62542b..0000000000 --- a/interface/src/ui/ChatEntry.cpp +++ /dev/null @@ -1,102 +0,0 @@ -// -// ChatEntry.cpp -// interface -// -// Created by Andrzej Kapolka on 4/24/13. -// Copyright (c) 2013 High Fidelity, Inc. All rights reserved. - -#include - -#include "ChatEntry.h" -#include "InterfaceConfig.h" -#include "Util.h" - -using namespace std; - -const int MAX_CONTENT_LENGTH = 80; - -ChatEntry::ChatEntry() : _cursorPos(0) { -} - -void ChatEntry::clear() { - _contents.clear(); - _cursorPos = 0; -} - -bool ChatEntry::keyPressEvent(QKeyEvent* event) { - event->accept(); - switch (event->key()) { - case Qt::Key_Return: - case Qt::Key_Enter: - return false; - - case Qt::Key_Escape: - clear(); - return false; - - case Qt::Key_Backspace: - if (_cursorPos != 0) { - _contents.erase(_cursorPos - 1, 1); - _cursorPos--; - } - return true; - - case Qt::Key_Delete: - if (_cursorPos < (int)_contents.size()) { - _contents.erase(_cursorPos, 1); - } - return true; - - case Qt::Key_Left: - if (_cursorPos != 0) { - _cursorPos--; - } - return true; - - case Qt::Key_Right: - if (_cursorPos != _contents.size()) { - _cursorPos++; - } - return true; - - default: - QString text = event->text(); - if (text.isEmpty()) { - event->ignore(); - return true; - } - if (_contents.size() < MAX_CONTENT_LENGTH) { - _contents.insert(_cursorPos, 1, text.at(0).toLatin1()); - _cursorPos++; - } - return true; - } -} - -const float ALL_WHITE[] = { 1.0f, 1.0f, 1.0f }; - -void ChatEntry::render(int screenWidth, int screenHeight) { - // draw a gray background so that we can actually see what we're typing - int bottom = screenHeight - 150, top = screenHeight - 165; - int left = 20, right = left + 600; - - glColor3f(0.2f, 0.2f, 0.2f); - glBegin(GL_QUADS); - glVertex2f(left - 5, bottom + 7); - glVertex2f(right + 5, bottom + 7); - glVertex2f(right + 5, top - 3); - glVertex2f(left - 5, top - 3); - glEnd(); - - drawText(left, bottom, 0.10f, 0, 2, _contents.c_str(), ALL_WHITE); - - float width = 0; - for (string::iterator it = _contents.begin(), end = it + _cursorPos; it != end; it++) { - width += widthChar(0.10f, 0, *it); - } - glDisable(GL_LINE_SMOOTH); - glBegin(GL_LINE_STRIP); - glVertex2f(left + width, top + 2); - glVertex2f(left + width, bottom + 2); - glEnd(); -} diff --git a/interface/src/ui/ChatEntry.h b/interface/src/ui/ChatEntry.h deleted file mode 100644 index 478641325d..0000000000 --- a/interface/src/ui/ChatEntry.h +++ /dev/null @@ -1,35 +0,0 @@ -// -// ChatEntry.h -// interface -// -// Created by Andrzej Kapolka on 4/24/13. -// Copyright (c) 2013 High Fidelity, Inc. All rights reserved. -// - -#ifndef __interface__ChatEntry__ -#define __interface__ChatEntry__ - -#include - -class QKeyEvent; - -class ChatEntry { -public: - - ChatEntry(); - - const std::string& getContents() const { return _contents; } - - void clear(); - - bool keyPressEvent(QKeyEvent* event); - - void render(int screenWidth, int screenHeight); - -private: - - std::string _contents; - int _cursorPos; -}; - -#endif /* defined(__interface__ChatEntry__) */